
! script name: vpoints.d/offsetpoint
! var_topic: construct points offset to a pair of baselines

!A
!A NAME:
!A
!A 	Offset Baselines Point	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a point offset from a pair of baselines.
!A
!A~ image location - images/voffsetintersectpt.jpg
!B INSTRUCTIONS:
!B
!B 	PICK BASE LINE 1
!B
!B 	PICK BASE LINE 2
!B
!B 	DISTANCE FROM LINE 1
!B
!B 	DISTANCE FROM LINE 2
!B
!B 	PICK LEFT/RIGHT OF LINES
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: offset baseline point ")

DIM Destination$[256]
DIM Answer$[256]
DIM Lname1$[256]
DIM Lname2$[256]
DIM Name$[256]
DIM Dist_var1$[256]
DIM Dist_var2$[256]

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

Distr=NamedVarVal("parallel distance",WsSystemVars,.25)

ActivateUndo
Pick_line1:!
Stat=SetInputFormat("n4","")
E1=PickSpecificEnt("PICK BASE LINE 1 ",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_line1
Stat= EntityNameCheck(E1,Lname1$)

Pick_line2:!
Stat=SetInputFormat("n4","")
E2=PickSpecificEnt("PICK BASE LINE 2 ",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_line2
Stat= EntityNameCheck(E2,Lname2$)

Dist1= Distr
Dist2= Distr

Line_loop:!
Stat=SetEqualsValue(Dist1)
Stat=SetInputFormat("n4=","")

Dist1=GetValue("DISTANCE FROM LINE 1",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_dist1_var= LastVariableInput(Dist1_var$)

Stat=SetEqualsValue(Dist2)
Stat=SetInputFormat("n4=","")
Dist2=GetValue("DISTANCE FROM LINE 2",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_dist2_var= LastVariableInput(Dist2_var$)


Stat=SetInputFormat("n4","")
Pt=InputFreePoint("PICK LEFT/RIGHT OF LINES")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN Line_loop

S1=PtLeftRight(E1,Pt)
S2=PtLeftRight(E2,Pt)
Stat=DeleteEntity(Pt)


PlotOff
Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Offset Baseline Point")
Stat= SetRecDelLastExec
IF No_dist1_var THEN
	V1= FreeParameter("Distance1",Dist1)
	L1=Parallel(Lname1$,V1,WsUNTRIMMED,S1)
ELSE
	L1=Parallel(Lname1$,Dist1_var$,WsUNTRIMMED,S1)
END IF
IF No_dist2_var THEN
	V2= FreeParameter("Distance2",Dist2)
	L2=Parallel(Lname2$,V2,WsUNTRIMMED,S2)
ELSE
	L2=Parallel(Lname2$,Dist2_var$,WsUNTRIMMED,S2)
END IF
Pt= Intersect(L1,L2)
Stat= NameEntity(Pt,Name$)
Stat=DeleteEntityList(L1,L2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn
Stat= PlotEntity(Lname1$)
Stat= PlotEntity(Lname2$)
Stat= PlotEntity(Name$)

ActivateUndo
Stat= AdvanceUndoNumber("offset point")
Stat= AddItemToUndo(WsUBCreateMode,Pt)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

GOTO Line_loop

Leave:!
Vdist=CreateVariable("parallel distance",WsSystemVars,Distr)
Stat=SetInputFormat("n4","")

Stat=DeleteEntity(Pt)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

