
! script name: dynvshapes.d/dyntwostep
! var_topic: two step profile contour

!A
!A NAME:
!A
!A 	Two step contour	VARIATIONAL	
!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)


Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
IF NOT Graphical_mode THEN LOAD "vcontours.d/twostep2pts"

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

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(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(2)
Length2=GetValue("LENGTH 2")
IF ExitScript(Destination$) THEN Leave

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



Pick_axis:!
PlotOn
stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Circle_loop
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)

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)
IF NOT ValidGeometry(Contour) THEN
	Stat= DeleteEntityList(Ps,Pe)
	IF Ps_created THEN Stat= DeleteEntity(Point1$)
	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)
	 IF Ps_created THEN Stat= DeleteEntity(Point1$)
	 Stat= DeleteEntityList(Ps,Pe)
       	 IF Destination$= "BACKUP" THEN Pick_axis
       	 GOTO Leave
END IF
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
Stat= DeleteGroup(Contour,WsTrue,WsTrue)
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)

IF NOT ValidDependency(E2) THEN
       E2= CopyEntity(Pe)
       Stat= EntityNameCheck(E2,Point2$)
       Stat= MakeVisible(E2)
       Pe_created= WsTrue
ELSE
       Stat= EntityNameCheck(E2,Point2$)
       Pe_created= WsFalse
END IF
Stat= DeleteEntityList(Ps,Pe)

Make_record:!
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: Two step profile")
Stat= SetRecDelLastExec
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
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
V1= FreeParameter("Type",Shape_type)
V2= FreeParameter("Diameter 1",Diameter1)
V3= FreeParameter("Length 1",Length1)
V4= FreeParameter("Diameter 2",Diameter2)
V5= FreeParameter("Length 2",Length2)
V6= FreeParameter("Diameter 3",Diameter3)
V7= FreeParameter("Corner radius (CW)",Radius_cw)
V8= FreeParameter("Corner radius (CCW)",Radius_ccw)
V9= FreeParameter("Taper 1 ",Taper1)
V10= FreeParameter("Taper 2 ",Taper2)
V11= FreeParameter("Taper 3 ",Taper2)
C1= TwoStepProfile2Pts(V1,Ps,Pe,V2,V3,V4,V5,V6,V7,V8,V9,V10,V11)
Stat= AutoNameGroup(C1,Name$)
Stat= DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("two step profile ")
	IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
	IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
	Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsFalse)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Pick_axis

Leave:!
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

