
! script name: lines.d/dynptangline
! topic: construct line through point at angle to a line

!A
!A NAME:
!A
!A 	Dynamic Point: Angle: Line
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line through a point at a specified angle
!A 	to another line.  The other line has already been defined.
!A
!A~ image location - images/ptangleline.gif
!B INSTRUCTIONS:
!B
!B 	ANGLE OF LINE: Enter the angle of the line to be constructed.
!B
!B 	PICK LINE: Pick the line to be used as the reference for the
!B 		specified angle.
!B
!B		The +/- keys toggle the sign of the angle.
!B		The 6 key will add one degree to the angle.
!B		The 4 key will subtract one degree to the angle.
!B		The 8 key will add five degrees to the angle.
!B		The 4 key will subtract five degrees to the angle.
!B		The > key will increase the length of the line.
!B		The < key will decrease the length of the line.
!B
!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: point: angle: line ")

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

DEG

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
Angle1=NamedVarVal("line angle",WsSystemVars,0.0)
Ask_angle=NamedVarVal("ask line angle",WsSystemVars,0.0)


ActivateUndo
Start:!
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

Dynamic_angle= GetDefault(WsDynAngleDefault)
Dynamic_length= GetDefault(WsDynLengthDefault)

Stat= SetDefaults(WsDynamicLength1,Dynamic_length)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,5)

Trim_line= WsUnTrimmed


Line_loop:!
Pick_line:Stat=SetInputFormat("n4b","")
L1=PickSpecificEnt("PICK LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(L1) THEN Pick_line

IF NOT Graphical_mode THEN

Angle1=InputAngle("ANGLE OF LINE")
IF (ExitScript(Destination$)) THEN Leave

stat= SetInputFormat("n4b","")
Pref=XyzInput("LINE LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pref) THEN Line_loop

L1=PtAngleLine(Pref,Angle1,L1,Trim_line)
Stat= DeleteEntity(Pref)
ActivateUndo
Stat= AdvanceUndoNumber("line")
Stat= AddItemToUndo(WsUBCreateMode,L1)
GOTO Line_loop

ELSE

IF Ask_angle THEN
  Angle1=InputAngle("ANGLE OF LINE")
  IF (ExitScript(Destination$)) THEN Leave
END IF
Line_length= GetDefault(WsLineLength)

Place_line:!
Angle1= GetAngleEquals
Stat=DynLabel("Angle:"&VAL$(Angle1)&":Length:"&VAL$(Line_length)&":")
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
E1=PtAngleLine(Pref,Angle1,L1,Trim_line,Line_length)
Line_angle= LineAngle(L1)
Stat= MakeInvisible(E1)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
PlotOn
Stat=SetLastPoint(Pdest)

Vnum= LastPickView
Params(0)= Angle1
Params(1)= Line_angle
Params(2)= Line_length
Params(3)= Trim_line
Num_params=4
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynPtAngleLine,"PICK LOCATION",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(E1,WsTrue)
        IF Destination$= "BACKUP" THEN Pick_line
        GOTO Leave
END IF
Angle1=Params(0)
Line_length=Params(2)
Trim_line=Params(3)
Stat= SetAngleEquals(Angle1)
Stat= MakeVisible(E1)
Stat=SetLastPoint(Pdest)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pdest)
Stat= PlotEntity(E1)
ActivateUndo
Stat= AdvanceUndoNumber("line")
Stat= AddItemToUndo(WsUBCreateMode,E1)
Vang=CreateVariable("line angle",WsSystemVars,Angle1)
GOTO Place_line
END IF


Leave:!
Stat=DynLabel("")
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat=SetInputFormat("n4","")
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
