
! script name: vcontours.d/slotcontour
! var_topic: make a slot contour.

!A
!A NAME:
!A
!A 	Slot contour		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a slot contour.
!A
!A~ image location - images/slotcontour.jpg
!B INSTRUCTIONS:
!B
!B 	START POINT: Pick the start point of the slot.
!B
!B 	END POINT: Pick the end point of the slot.
!B
!B	RADIUS:  Input the radius.
!B
!C NOTES:
!C
!C	This csript can generate the following versions of a slot:
!C
!C		type= 1: Full slot, circle center to circle center.
!C		type= 2: Full slot, end to end.
!C		type= 3: Upper half, circle center to circle center.
!C		type= 4: Upper half, end to end.
!C		type= 5: Lower half, circle center to circle center.
!C		type= 6: Lower half, end to end.
!C		type= 7: Full slot, flat end to circle center.
!C		type= 8: Full slot, flat end to circle end.
!C		type= 9: Full slot, flat end to flat end.
!C
!C
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: slot contour ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Radius_var$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
DEG

ActivateUndo
Slot_type= 1


Rect_loop:!


Ask_radius:Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(Radius)
Radius=InputRadius("RADIUS ")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
	 IF NOT ValidDependency(C1) THEN Ask_radius
       	 No_radius_var=0
       	 Stat= EntityNameCheck(C1,Radius_var$)
END IF

Pick_point1:Stat=SetInputFormat("n4=","")
E1=PickEntity("START POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point1
Pick_para1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Point1$)
P1= ParameterReturnPt(E1,Pick_para1,Pick_return1)
Stat=SetLastPoint(P1)
Stat= DeleteEntity(P1)


Pick_point2:Stat=SetInputFormat("n4=","")
E2=PickEntity("END POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point2
Pick_para2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point2$)
P2= ParameterReturnPt(E2,Pick_para2,Pick_return2)
Stat=SetLastPoint(P2)
Stat= DeleteEntity(P2)



Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: Slot")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        P1= ParameterReturnPt(Point1$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
        P1= ParameterReturnPt(Point1$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
        P1= ParameterReturnPt(Point1$,Pick_para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        P2= ParameterReturnPt(Point2$,Pick_para2,WsGeometryEnd)
CASE WsGeometryMid
        P2= ParameterReturnPt(Point2$,Pick_para2,WsGeometryMid)
CASE WsGeomCenter
        P2= ParameterReturnPt(Point2$,Pick_para2,WsGeomCenter)
END SELECT
V1= FreeParameter("Type",Slot_type)
IF No_radius_var THEN
	V2= FreeParameter("Start radius",Radius)
	V3= FreeParameter("End radius",Radius)
	C1= SlotTwoPoints(P1,P2,V2,V3,V1)
ELSE
	C1= SlotTwoPoints(P1,P2,Radius_var$,Radius_var$,V1)
END IF
Stat= AutoNameGroup(C1,Name$)
Stat= DeleteEntityList(P1,P2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("slot")
	Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_point1

Leave:!
Stat= DeleteEntityList(P1,P2)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
