
! script name: vtypes.d/type441
! var_topic: type 441

!A
!A NAME:
!A
!A 	Type 441   Circle Circle(180+) with Corner Chamfer
!A
!A~ image location - images/type441.gif
!A
!A DESCRIPTION:
!A
!A      Type 441 is a modified Type 44.  A chamfer is created connecting the
!A      second circle to the next element. CHAMFER LENGTH is measured parallel
!A      to the chord of the circle.  Type 441 may not be used to end a contour
!A      description of an open contour.
!A
!# see also - htdocs/help.d/typeno.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: type 441 ")

DIM Answer$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM R1_var$[256]
DIM R2_var$[256]
DIM Length_var$[256]
DIM Name$[256]
DIM Destination$[256]
DEG

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

Start: !
FadeUndoButtons
Stat=SetPickMask(WsPickNoSurf)
Spoint:Last=FindLastType
Stat=SetInputFormat("n4=","")
IF NOT ValidGeometry(Last) THEN
	Ps=XyzInput("STARTING",WsXyOnly)
	IF ExitScript(Destination$) THEN Leave
	IF NOT ValidGeometry(Ps) THEN Spoint
	E1= LastPickEnt
	Para1= LastPickPara
	Pick_return1= CurrPickReturn
	IF NOT ValidDependency(E1) THEN
       		 E1= CopyEntity(Ps)
       		 Stat= EntityNameCheck(E1,Point1$)
       		 Ps_created=WsTrue
	ELSE
       		 Stat= EntityNameCheck(E1,Point1$)
       		 Ps_created=WsFalse
	END IF
	Stat=SetLastPoint(Ps,WsXyOnly)
	First=1
        R1=0
ELSE
	Ps=TypeEndPoint(Last,WsEnd)
	Stat=SetLastPoint(Ps,WsXyOnly)
	R1=TypeEndRadius(Last,WsEnd)
	First=0
END IF

Epoint:!
Stat=SetInputFormat("n4b=","")
Pe=XyzInput("ENDING",WsXyOnly)
IF (ExitScript(Destination$)) THEN
	Stat=DeleteEntity(Ps)
       	IF Ps_created THEN Stat=DeleteEntity(Point1$)
        IF Destination$= "BACKUP" THEN Spoint
        GOTO Leave
END IF
IF NOT ValidGeometry(Pe) THEN Epoint
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
IF NOT ValidDependency(E2) THEN
        E2= CopyEntity(Pe)
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created=WsTrue
ELSE
        Stat= EntityNameCheck(E2,Point2$)
        Pe_created=WsFalse
END IF
Stat=SetLastPoint(Pe,WsXyOnly)


Radius1:!
IF First THEN
	Stat=SetRadiusEquals(0)
	Stat=SetInputFormat("n4b=","")
	R1=InputRadius("R1",WsRadiusInput,WsSigned)
	IF (ExitScript(Destination$)) THEN
       		IF Destination$= "BACKUP" THEN 
       			Stat=DeleteEntity(Pe)
       			IF Pe_created THEN Stat=DeleteEntity(Point2$)
			GOTO Epoint
       		END IF
       		Stat=DeleteEntity(Ps)
       		IF Ps_created THEN Stat=DeleteEntity(Point1$)
       		Stat=DeleteEntity(Pe)
       		IF Pe_created THEN Stat=DeleteEntity(Point2$)
       		GOTO Leave
	END IF
	No_r1_var= LastVariableInput(R1_var$)
END IF

Radius2:!
Stat=SetRadiusEquals(R1)
Stat=SetInputFormat("n4b=","")
R2=InputRadius("R2",WsRadiusInput,WsSigned)
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN 
		IF First THEN Radius1
       		Stat=DeleteEntity(Pe)
       		IF Pe_created THEN Stat=DeleteEntity(Point2$)
		GOTO Epoint
       END IF
       Stat=DeleteEntity(Ps)
       IF Ps_created THEN Stat=DeleteEntity(Point1$)
       Stat=DeleteEntity(Pe)
       IF Pe_created THEN Stat=DeleteEntity(Point2$)
       GOTO Leave
END IF
No_r2_var= LastVariableInput(R2_var$)

Chamfer:!
Stat=SetEqualsValue(Length)
Stat=SetInputFormat("n4b=","")
Length=GetValue("CHAMFER LENGTH",Answer$)
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN Radius2
       Stat=DeleteEntity(Ps)
       IF Ps_created THEN Stat=DeleteEntity(Point1$)
       Stat=DeleteEntity(Pe)
       IF Pe_created THEN Stat=DeleteEntity(Point2$)
       GOTO Leave
END IF
No_length_var= LastVariableInput(Length_var$)


Stat=DeleteEntity(Ps,WsTrue)
Stat=DeleteEntity(Pe,WsTrue)

Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE 441: circle circle corner chamfer")
Last=FindLastType
RecordFunctionOff
IF ValidGeometry(Last) THEN
RecordFunctionOn
	Ps=TypeEndPoint(Last,WsEnd)
	V1= FreeParameter("R1",TypeEndRadius(Last,WsEnd))
RecordFunctionOff
ELSE
RecordFunctionOn
	SELECT Pick_return1
	CASE WsGeometryEnd
       		 Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
	CASE WsGeometryMid
       		Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
	CASE WsGeomCenter
        	Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
	END SELECT

	IF No_r1_var THEN
        	V1= FreeParameter("R1",R1)
	ELSE
        	V1= FreeParameter("R1",R1_var$)
	END IF
RecordFunctionOff
END IF
RecordFunctionOn
SELECT Pick_return2
CASE WsGeometryEnd
      Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
      Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
      Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
IF No_r2_var THEN
        V2= FreeParameter("R2",R2)
ELSE
        V2= FreeParameter("R2",R2_var$)
END IF
IF No_length_var THEN
        V3= FreeParameter("Chamfer length",Length)
ELSE
        V3= FreeParameter("Chamfer length",Length_var$)
END IF
Tp=Type4(441,Ps,Pe,V1,V2,V3)
RecordFunctionOff
IF ValidGeometry(Tp) THEN
        ActivateUndo
        Stat= AdvanceUndoNumber("type 441")
        IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
        IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)

        IF ValidGeometry(Last) THEN
                Stat= AddGroupToUndo(WsUBModifyMode,Last)
                RecordFunctionOn
                Stat=JoinTypes(Last,Tp)
                RecordFunctionOff
        END IF
        RecordFunctionOn
        Stat= NameEntity(Tp,Name$)

        Stat= DeleteEntity(Ps)
        Stat= DeleteEntity(Pe)
        RecordFunctionOff
        Curr_record= CurrentVarRecord
        CloseVarRecord

        Stat= AddGroupToUndo(WsUBCreateMode,Tp)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

ELSE
        RecordFunctionOn
        Stat= DeleteEntity(Ps)
        Stat= DeleteEntity(Pe)
        RecordFunctionOff
        Curr_record= CurrentVarRecord
        CloseVarRecord

        IF Ps_created THEN Stat= DeleteEntity(Point1$)
        IF Pe_created THEN Stat= DeleteEntity(Point2$)
        DelLastVarRecord
END IF
PlotAll


Leave:!
Stat=SetPickMask(WsPickAll)
Stat=SetPickReturn(WsCircleCenter)
Stat=DeleteEntity(Ps,WsTrue)
Stat=DeleteEntity(Pe,WsTrue)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
