
! script name: vtypes.d/type10
! var_topic: type 10

!A
!A NAME:
!A
!A 	Type 10   Line with Corner Radius
!A
!A~ image location - images/type10.gif
!A
!A DESCRIPTION:
!A
!A      Type 10 is a modified Type 1. A circle is created tangent to the line
!A      and the next element.  It is assumed that the next element starts with
!A      a zero radius.  Type 10 may not be used to end a contour description
!A      of an open contour.
!A
!# see also - htdocs/help.d/typeno.htm

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

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



Radius2:!
Stat=SetRadiusEquals(R1)
Stat=SetInputFormat("n4b=","")
R2=InputRadius("ROUNDING RADIUS",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_r2_var= LastVariableInput(R2_var$)

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


Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE 10: line to 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

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("Corner radius",R2)
ELSE
        V2= FreeParameter("Corner radius",R2_var$)
END IF
RecordFunctionOff
IF ValidGeometry(Last) THEN
        IF ABS(R1)> 0.0 THEN
                RecordFunctionOn
                Tp=Type3(30,Ps,Pe,V1,V2)
                RecordFunctionOff
        ELSE
                RecordFunctionOn
                Tp=Type10(10,Ps,Pe,V2)
                RecordFunctionOff
        END IF
ELSE
        RecordFunctionOn
        Tp=Type10(10,Ps,Pe,V2)
        RecordFunctionOff
END IF
RecordFunctionOff
IF ValidGeometry(Tp) THEN
        ActivateUndo
        Stat= AdvanceUndoNumber("type 10")
        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
