
! script name: vdraft.d/angle2lines
! var_topic: construct angle 2 lines  dimension

!A
!A NAME:
!A
!A 	Angular Dimension Between Two Lines.
!A
!A DESCRIPTION:
!A
!A 	This script constructs an angular dimension.  The angular dimension
!A 	is the angle between two lines.
!A
!A~ image location - images/ang2lines.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST LINE: Pick the first line.
!B
!B 	PICK SECOND LINE: Pick the second line.
!B
!B 	DIM LOCATION: PICK FREE POINT: Pick the location for the dimension
!B 		label to be printed.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: angle 2 lines dimension ")

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

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Start:!
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,Line1$)
Parameter1= LastPickPara

L2=PickSpecificEnt("PICK SECOND LINE",WsPickLines)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(L2) THEN Dim_loop
Stat= EntityNameCheck(L2,Line2$)
Parameter2= LastPickPara

Vertex= Intersect(L1,L2)
IF NOT ValidGeometry(Vertex) THEN Dim_loop
Pstart= ParameterPt(L1,Parameter1)
Pend=   ParameterPt(L2,Parameter2)

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

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

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Angle Two Lines")
Stat= SetRecDelLastExec
Vertex= Intersect(Line1$,Line2$)
Ps= ParameterPt(Line1$,Parameter1)
Pe= ParameterPt(Line2$,Parameter2)
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)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

GOTO Dim_loop

Leave:!
Stat=DeleteEntityList(Ploc,Vertex,Ps,Pe)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
