
! script name: vtypes.d/type550
! var_topic: type 550

!A
!A NAME:
!A
!A 	Type 550   Type55 with Corner Radius
!A
!A~ image location - images/type550.gif
!A
!A DESCRIPTION:
!A
!A      Type 550 is a modified Type 55.  A circle is created tangent to
!A      the line and the next element.
!A
!# see also - htdocs/help.d/typeno.htm

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

DIM Answer$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM R1_var$[256]
DIM R2_var$[256]
DIM R3_var$[256]
DIM Angle_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$)

Radius3:!
Stat=SetRadiusEquals(R2)
Stat=SetInputFormat("n4b=","")
R3=InputRadius("ROUNDING RADIUS",WsRadiusInput,WsSigned)
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_r3_var= LastVariableInput(R3_var$)

Angle:!
Stat=SetInputFormat("n4b","")
Angle=InputAngle("ANGLE",WsSigned)
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN Radius3
	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_angle_var= LastVariableInput(Angle_var$)

Stat=SetInputFormat("a1b",",T,F,")
Stat=GetValue("To OR From TANGENT CIRCLES",Answer$)
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN Angle
	Stat=DeleteEntity(Ps)
       IF Ps_created THEN Stat=DeleteEntity(Point1$)
       Stat=DeleteEntity(Pe)
       IF Pe_created THEN Stat=DeleteEntity(Point2$)
       GOTO Leave
END IF

To_from= WsTo
IF Answer$= "F" THEN To_from= WsFrom


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


Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE 550: circle circle line corner radius")
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_r3_var THEN
        V3= FreeParameter("Corner radius",R3)
ELSE
        V3= FreeParameter("Corner radius",R3_var$)
END IF
IF No_angle_var THEN
        V4= FreeParameter("Angle",Angle)
ELSE
        V4= FreeParameter("Angle",Angle_var$)
END IF
V5= FreeParameter("To or From tangent arcs",To_From)
Tp=Type5(550,Ps,Pe,V1,V2,V3,V4,V5)
RecordFunctionOff
IF ValidGeometry(Tp) THEN
        ActivateUndo
        Stat= AdvanceUndoNumber("type 550")
        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
