
! script name: vlines.d/ptdistangle
! var_topic: construct line at specified angle and distance from point

!A
!A NAME:
!A
!A 	Point: Dist: Angle  -- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line at a specific angle and a specific
!A 	distance from a point.
!A
!A~ image location - images/ptdistangle.gif
!A
!B INSTRUCTIONS:
!B
!B 	INPUT ABS X,Y: Enter the X,Y coordinates of the point
!B 		to be used as the reference for the construction
!B 		of the line.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PERPENDICULAR DISTANCE: Enter the distance that the
!B 		line should be constructed from the point.
!B
!B 	ANGLE OF LINE: Enter the angle of the line to be constructed.
!B
!B 	PICK LEFT/RIGHT OF LINE: This indicates which side
!B 		of the point the line will be constructed on.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: point: dist: angle ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Center$[256]
DIM Angle_var$[256]
DIM Dist_var$[256]

DEG


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

ActivateUndo
Line_loop:Stat=SetInputFormat("n4","")
E1=PickEntity("POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Line_loop
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Center$)
T= LastPickPara
Pick_return= CurrPickReturn
Pc= ParameterReturnPt(E1,T,Pick_return)

Distr=NamedVarVal("parallel distance",WsSystemVars,0.5)
Stat=SetEqualsValue(Distr)
Stat=SetInputFormat("n4=","")

Distance=GetValue("PERPENDICULAR DISTANCE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_dist_var= LastVariableInput(Dist_var$)

Distr=Distance
Vdist=CreateVariable("parallel distance",WsSystemVars,Distr)

Angle_ques:Angle=InputAngle("ANGLE OF LINE")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
	IF NOT ValidDependency(L1) THEN Angle_ques
        Stat= EntityNameCheck(L1,Angle_var$)
        No_angle_var=0
END IF

L2=PointAngle(Pc,Angle,WsUNTRIMMED)

Pickpt=InputFreePoint("PICK LEFT/RIGHT OF LINE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pickpt) THEN Line_loop

S1=PtLeftRight(L2,Pickpt)
Stat= DeleteEntity(L2)
Stat= DeleteEntity(Pickpt)
Stat= DeleteEntity(Pc)

Stat= GenerateVarName(WsLineEnt,Name$)

RecordFunctionOn
Stat= RecordDescr("LINE: Point distance angle")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_dist_var THEN
	V1= FreeParameter("Distance",Distance)
	IF No_angle_var THEN
		V2= FreeParameter("Angle",Angle)
       	 	L1=PtDistAngle(Pc,V1,V2,S1)
	ELSE
       		L1=PtDistAngle(Pc,V1,Angle_var$,S1)
	END IF
ELSE
	IF No_angle_var THEN
		V2= FreeParameter("Angle",Angle)
       	 	L1=PtDistAngle(Pc,Dist_var$,V2,S1)
	ELSE
       		L1=PtDistAngle(Pc,Dist_var$,Angle_var$,S1)
	END IF
END IF
Stat= NameEntity(L1,Name$)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

ActivateUndo
Stat= AdvanceUndoNumber("pt dist angle")
Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Line_loop

Leave:!
Stat= DeleteEntity(L2)
Stat= DeleteEntity(Pickpt)
Stat= DeleteEntity(Pc)
Stat=SetXyzInput(WsXyzInput)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

