
! script name: dynvlines.d/dynvertline
! var_topic: construct line parallel to Y axis through point

!A
!A NAME:
!A
!A 	Dynamic Vertical Line  Variational
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line parallel to the Y axis through a point.
!A
!B INSTRUCTIONS:
!B
!B 	PICK LOCATION: Pick the location of the line to be
!B 		constructed parallel to the X axis.  NOTE: To enter
!B 		the coordinates of a point for the line to pass through
!B 		parallel to the X axis, see DYNAMIC INPUT OPTIONS.
!B
!B		The > key will increase the length of the line
!B		The < key will decrease the length of the line
!C NOTES:
!C
!C 	The dynamic input mode is an option that may be turned off by
!C 	setting the variable "Graphical mode=0".  To set the variable,
!C 	under "Settings", select "Variables".  The selection box will appear
!C 	at this time.  Select "Graphical mode=1" and change the
!C 	setting to "0".  The dynamic input mode is the default whenever
!C 	Synergy is started.  This change is for this session of Synergy
!C 	only.
!C
!C 	The dynamic input mode may be turned off for future sessions of
!C 	Synergy by going to "Settings" and selecting "Constants".  The editor
!C 	will bring up the setconstants script.  The following line needs
!C 	to be modified (the 1.0 needs to be changed to 0.0):
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,1.0)
!C
!C 	to:
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,0.0)
!C
!C 	The line is near the middle of the script.
!C
!# see also - points.d/dyninput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: Vertical line ")

DIM Answer$[256]
DIM Center$[256]
DIM Name$[256]
DIM Destination$[256]
REAL Params(0:10)

DEG

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

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


Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)
Dynamic_length= GetDefault(WsDynLengthDefault)

Stat= SetDefaults(WsDynamicLength1,Dynamic_length)
Stat= SetDefaults(WsDynamicAng1Incr,0)
Stat= SetDefaults(WsDynamicAng2Incr,0)


Place_line:!
Line_angle= 90.0
No_angle_var=1
IF NOT Graphical_mode THEN
        stat=SetInputFormat("n4b","")
        Stat= PointInputMode(1)
Center: Pref=XyzInput("LINE LOCATION",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pref) THEN Line_loop
        Last_pick_ent= LastPickEnt
        Pick_para= LastPickPara
        Pick_return= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Last_pick_ent= CopyEntity(Pref)
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
                 Pick_para= 0.0
                 Pick_return= WsGeometryEnd
		 Pc_created=WsTrue
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created=WsFalse
        END IF
        Stat=SetLastPoint(Pref)
ELSE
	PlotOff
        Pref= PointXYZ(0,0,0)
        Pdest= CopyEntity(Pref)
        L1=PointAngle(Pref,Line_angle)
        Stat= MakeInvisible(L1)
        Stat= MakeInvisible(Pref)
        Stat= MakeInvisible(Pdest)
        PlotOn
        Stat=SetLastPoint(Pdest)

	Vnum= LastPickView
	Params(0)= Line_angle
	Params(1)= 0.0
	Params(2)= WsUNTRIMMED
	Num_params=3
	No_angle_var=1
	Stat=SetInputFormat("n4b","")
	Stat=DynamicEntity(Vnum,L1,Pref,Pdest,WsDynLineAngle,"LINE LOCATION ",Params,Num_params)
	IF (ExitScript(Destination$)) THEN
       		 Stat=DeleteEntity(L1,WsTrue)
       		 GOTO Leave
	END IF
	Last_pick_ent= LastPickEnt
        Pick_para= LastPickPara
        Pick_return= CurrPickReturn
        Line_angle= Params(0)
        Line_length= Params(1)
        IF NOT ValidDependency(Last_pick_ent) THEN
		 Last_pick_ent=CopyEntity(Pdest)
                 Stat= MakeVisible(Last_pick_ent)
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created=WsTrue
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created=WsFalse
        END IF
        Stat=DeleteEntity(L1)
	Stat=SetLastPoint(Pdest)
	Stat=DeleteEntity(Pdest)
END IF
Stat=DeleteEntity(Pref)

Make_record:!
Stat= GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LINE: Vertical")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
CASE WsNearest
        Pc= ParameterReturnPt(Center$,Pick_para,WsNearest)
END SELECT
V1= FreeParameter("Line length",Line_length)
IF No_angle_var THEN
        V2= FreeParameter("Angle",Line_angle)
        L1=PointAngle(Pc,V2,WsUnTrimmed,V1)
ELSE
        L1=PointAngle(Pc,Angle_var$,WsUnTrimmed,V1)
END IF
Stat= NameEntity(L1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Center$)
Stat= PlotEntity(L1)

ActivateUndo
Stat= AdvanceUndoNumber("var line")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

GOTO Place_line

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat=SetInputFormat("n4","")
Stat= DeleteEntityList(Pref,Pdest)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END

