
! script name: draft.d/verticalangle
! var_topic: angular dimension between a line and a vertical line.

!A
!A NAME:
!A
!A 	Vertical Angle
!A
!A DESCRIPTION:
!A
!A 	This script constructs an angular dimension.  The angular dimension
!A 	is the angle between a line and a vertical line.
!A
!A~ image location - images/vertangle.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST LINE: Pick the first line.
!B
!B 	PICK VERTICAL LINE ANCHOR POINT: Pick a
!B 		point to anchor the vertical line.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the
!B 		location for the dimension label to be printed.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: vertical angle dim ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Line$[256]
DIM Point3$[256]
DIM Name$[256]
DIM Textflags$[20]
DEG

Start:!
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Dynamic_position=1
Dim_type= WsAngleDim

Dim_loop:! 
L1=PickSpecificEnt("PICK FIRST LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(L1) THEN Dim_loop
Stat= EntityNameCheck(L1,Line$)
Parameter1= LastPickPara

Anchor:!
Input_method= CurrInputMethod
stat= SetXyzInput(WsFreePoint)
Pend=XyzInput("VERTICAL LINE ANCHOR POINT ",WsXyOnly)
stat= SetXyzInput(Input_method)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pend) THEN Dim_loop

L2=PointAngle(Pend,90.0)

Vertex= Intersect(L1,L2)
Stat=DeleteEntity(L2)
IF NOT ValidGeometry(Vertex) THEN
	Stat=DeleteEntity(Pend)
	GOTO Dim_loop
END IF
Pstart= ParameterPt(L1,Parameter1)

D1= DistTwoPts(Pstart,Pend)
IF D1< Delta THEN 
	Stat=DeleteEntity(Vertex)
	Stat=DeleteEntity(Pstart)
	Stat=DeleteEntity(Pend)
	GOTO Dim_loop
END IF
	

IF Dynamic_position THEN
        P1= SubtractVectors(Pstart,Pend)
        Ploc= AddVectors(Pstart,P1)
        Stat=DeleteEntity(P1)
ELSE
        Input_method= CurrInputMethod
        stat= SetXyzInput(WsFreePoint)
        Stat=SetLastPoint(Pstart)
        Ploc=XyzInput("DIM LOCATION",WsXyOnly)
        stat= SetXyzInput(Input_method)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Ploc) THEN Dim_loop
	Last_pick_ent= LastPickEnt
        Pick_para3= LastPickPara
        Pick_return3= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point3$)
                 Point_reference=1
        END IF
END IF


IF Dynamic_position THEN
	PlotOff
	E1= AngleDim(Dim_type,Vertex,Pstart,Pend,Ploc,"","")
	PlotOn
	Stat=MakeInvisible(Vertex)
        Stat=MakeInvisible(Pstart)
        Stat=MakeInvisible(Pend)
        Stat=DeleteEntity(Ploc)

	IF NOT ValidGeometry(E1) THEN Dim_loop
        Which_end=2
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK DIM LOCATION",WsFalse)
	IF (ExitScript(Destination$)) THEN 
                Stat= DeleteEntity(E1)
		Stat=MakeVisible(Vertex)
        	Stat=MakeVisible(Pstart)
        	Stat=MakeVisible(Pend)
                Stat=DeleteEntity(Vertex)
                Stat=DeleteEntity(Pstart)
                Stat=DeleteEntity(Pend)
                GOTO Leave
        END IF
	Last_pick_ent= LastPickEnt
        Pick_para3= LastPickPara
        Pick_return3= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point3$)
                 Point_reference=1
        END IF
	PlotOff
        Ploc= ParameterPt(E1,0.5)
        Stat= DimTextFlagStr(E1,Textflags$)
        Stat= DeleteEntity(E1)
        PlotOn
ELSE
        Textflags$=""
END IF

Stat=MakeVisible(Vertex)
Stat=MakeVisible(Pstart)
Stat=MakeVisible(Pend)
P1= SubtractVectors(Ploc,Pstart)
Stat= XYZPointValues(P1,X1,Y1,Z1)
Stat=DeleteEntityList(P1,Ploc)
P1= SubtractVectors(Pend,Pstart)
Stat= XYZPointValues(P1,X2,Y2,Z2)
Stat=DeleteEntityList(P1,Vertex,Pstart,Pend)

PlotOff
Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Vertical Angle")
Stat= SetRecDelLastExec
Ps= ParameterPt(Line$,Parameter1)
V1= FreeParameter("Xanchor",X2)
V2= FreeParameter("Yanchor",Y2)
Pe= PtIncrXyz(Ps,V1,V2,Z2)
L2=PointAngle(Pe,90.0)
Vertex= Intersect(Line$,L2)
IF Point_reference THEN
        SELECT Pick_return3
        CASE WsGeometryEnd
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeometryEnd)
        CASE WsGeometryMid
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeometryMid)
        CASE WsGeomCenter
                 Ploc= ParameterReturnPt(Point3$,Pick_para3,WsGeomCenter)
        END SELECT
ELSE
        V1= FreeParameter("Xloc",X1)
        V2= FreeParameter("Yloc",Y1)
        Ploc= PtIncrXyz(Ps,V1,V2,Z1)
END IF
V4= StringConstant(Textflags$)
E1= AngleDim(WsAngleDim,Vertex,Ps,Pe,Ploc,"","",V4)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Ploc,Vertex,Ps,Pe,L2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
PlotOn

Stat= PlotEntity(E1)
Stat= PlotEntity(Line$)
IF NOT ValidGeometry(E1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("vertical angle dim")
	Stat= AddDimToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Dim_loop

Leave:!
Stat=DeleteEntityList(Ploc,Vertex,Pstart,Pend)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
