
! script name: dyn_shapes.d/dyntwostep
! topic: two step profile contour

!A
!A NAME:
!A
!A 	Two step contour
!A
!A DESCRIPTION:
!A
!A	This script constructs a contour consisting of two steps
!A	in a shaft. May be used as a turning profile or to draw 
!A	shapes like a counterbore.
!A
!A~ image location - images/twostepprofile.gif
!A
!B INSTRUCTIONS:
!B
!B	DIAMETER 1: First diameter.
!B
!B	LENGTH 1: Length along first diameter.
!B
!B	DIAMETER 2: Second diameter.
!B
!B	LENGTH 2: Length along second diameter.
!B
!B	DIAMETER 3: Second diameter.
!B
!B	START POINT: Pick the start point.
!B
!B	END POINT: Pick the end point.
!B
!B
!C NOTES:
!C
!C	This script can generate the following versions:
!C
!C		type= 1: Complete Profile
!C		type= 2: Upper Half 
!C		type= 3: Lower Half
!C		type= 11: Complete Profile Chamfered
!C		type= 12: Upper Half  Chamfered
!C		type= 13: Lower Half Chamfered
!C		type= 21: Complete Profile Radius CCW Chamfered CW
!C		type= 22: Upper Half  Radius CCW Chamfered CW
!C		type= 23: Lower Half Radius CCW Chamfered CW
!C		type= 31: Complete Profile Radius CW Chamfered CCW
!C		type= 32: Upper Half  Radius CW Chamfered CCW
!C		type= 33: Lower Half Radius CW Chamfered CCW
!C
!C	The following features are controled by Free Parameters:
!C
!C		Shape type: Type of shape. See above. 
!C		Radius CW:  Corner radius or chamfer for CW corners.
!C		Radius CCW: Corner radius or chamfer for CCW corners.
!C		Taper 1:    Taper of first length segment.
!C		Taper 2:    Taper of second length segment.
!C		Taper 3:    Taper of third length segment.
!C
!C
!C	The key controls are:
!C
!C		< >  Diameter 1 +/-
!C		{ }  Diameter 2 +/-
!C		F G  Diameter 3 +/-
!C		6 4  Radius CW
!C		8 2  Radius CCW
!C		9 7  Length 1
!C		3 1  Length 2
!C		/ 1  Length 3
!C		+ -  Shape Type
!C
!C
!C
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: Two step  two points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
REAL Params(0:20)



IF ARGC=2 THEN
        Answer$= UPC$(ARGV(1))
	Shape_type= VAL(Answer$)
ELSE
        Shape_sype=1
END IF


Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_length2= GetDefault(WsDynamicLength2)
Dynamic_radius= GetDefault(WsDynRadiusDefault)
Dynamic_data1= GetDefault(WsDynamicData1)
Dynamic_data2= GetDefault(WsDynamicData2)
Dynamic_data3= GetDefault(WsDynamicData3)
Dynamic_data4= GetDefault(WsDynamicData4)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length1)
Stat= SetDefaults(WsDynamicData1,Dynamic_length1)
Stat= SetDefaults(WsDynamicData2,Dynamic_length1)
Stat= SetDefaults(WsDynamicData3,Dynamic_length1)
Stat= SetDefaults(WsDynamicData4,Dynamic_length1)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_radius)

Rect_loop:!

Stat=SetInputFormat("n4=","")
Diameter1=InputRadius("DIAMETER 1",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0)
Taper1=GetValue("TAPER 1")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
Length1=GetValue("LENGTH 1")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Diameter2=InputRadius("DIAMETER 2",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0)
Taper2=GetValue("TAPER 2")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2)
Length2=GetValue("LENGTH 2")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4=","")
Diameter3=InputRadius("DIAMETER 3",WsDiaInput)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(0)
Taper3=GetValue("TAPER 3")
IF ExitScript(Destination$) THEN Leave


Pick_axis:!
Stat=DynLabel("D1:"&VAL$(Diameter1)&":L1:"&VAL$(Length1)&":D2:"&VAL$(Diameter2)&":L2:"&VAL$(Length2))
PlotOn
stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Circle_loop
Stat=SetLastPoint(Ps)

PlotOff
Angle= 0.0
Length3= Length1+ Length2+ 3.0
Pe= PtIncrXyz(Ps,Length3,0.0,0.0)
Contour= TwoStepProfile2Pts(Shape_type,Ps,Pe,Diameter1,Length1,Diameter2,Length2,Diameter3,Radius_cw,Radius_ccw,Taper1,Taper2,Taper3)
IF NOT ValidGeometry(Contour) THEN
	Stat= DeleteEntityList(Ps,Pe)
	GOTO Pick_axis
END IF
Params(0)= Shape_type
Params(1)= Diameter1
Params(2)= Diameter2
Params(3)= Diameter3
Params(4)= Length1
Params(5)= Length2
Params(6)= Length3
Params(8)= Angle
Params(8)= Radius_cw
Params(9)= Radius_ccw
Params(10)= Taper1
Params(11)= Taper2
Params(12)= Taper3
Stat= MakeInvisible(Contour)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Num_params=3
Stat=SetInputFormat("n4b","")
Stat=DynamicShape(Vnum,Contour,Ps,Pe,WsDynamicTwoStep,"PICK END POINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
	 Stat=DeleteGroup(Contour,WsTrue,WsTrue)
	 Stat= DeleteEntityList(Ps,Pe)
       	 IF Destination$= "BACKUP" THEN Pick_axis
       	 GOTO Leave
END IF
Shape_type= Params(0)
Diameter1= Params(1)
Diameter2= Params(2)
Diameter3= Params(3)
Length1= Params(4)
Length2= Params(5)
Length3= Params(6)
Angle= Params(7)
Radius_cw= Params(8)
Radius_ccw= Params(9)
Taper1= Params(10)
Taper2= Params(11)
Taper3= Params(12)
Stat= DeleteEntityList(Ps,Pe)

Stat= PlotEntity(Contour)
IF NOT ValidGeometry(Contour) THEN
	ActivateUndo
	Stat= AdvanceUndoNumber("two step profile ")
	Stat= AddGroupToUndo(WsUBCreateMode,Contour,1,WsFalse)
END IF

GOTO Pick_axis

Leave:!
Stat=DynLabel("")
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= DeleteEntityList(Ps,Pe)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length2)
Stat= SetDefaults(WsDynamicData1,Dynamic_data1)
Stat= SetDefaults(WsDynamicData2,Dynamic_data2)
Stat= SetDefaults(WsDynamicData3,Dynamic_data3)
Stat= SetDefaults(WsDynamicData3,Dynamic_data4)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)


IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
	IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END

