
! script name: vdraft.d/textarrow
! var_topic: construct text arrow

!A
!A NAME:
!A
!A 	Text arrow	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs an arrow, a line with end points defined
!A 	by the user, with text placed after the last point defined.
!A
!B INSTRUCTIONS:
!B
!B 	ARROW START POINT: Pick the start point of the arrow.
!B
!B 	ARROW END POINT: Pick the end point of the arrow.
!B
!B 	INPUT TEXT, None: Enter the line of text to be placed at the end point
!B 		of the arrow.  Enter "N" for None, if no text is to be placed
!B 		at this time.
!B
!C NOTE:
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their ascii number.
!C 	Type in \031 for example to use the character in the font assigned to
!C 	the ascii number 31. The code must be a three digit number from 001 to
!C 	255.  Some of the extended characters like the geometric tolerancing
!C 	symbols take up more than one space so they should be bracketed with
!C 	extra spaces.
!C
!# see also - htdocs/help.d/dynamicdim.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: text arrow ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Text$[256]
DIM Text1$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]
DEG


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

ActivateUndo
Dynamic_position=1
Dim_type= WsTextArrow
New_line$= "\n"
End_line$= CHR$(10)


Dim_loop:! 
stat= SetInputFormat("a99","")
stat= GetValue("INPUT TEXT, None ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "N", "n", "None","NONE"
	Text$=""
CASE ELSE
	Stat= BackSlashChars(Answer$,Text1$)
	Stat= ReplaceString(Text1$,New_line$,End_line$,Text$)
END SELECT

Element1=PickEntity("ARROW START POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Element1) THEN Dim_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(Element1,Point1$)
Pstart= ParameterReturnPt(Element1,T1,Pick_return1)


IF Dynamic_position THEN
        Pend= PointXYZ(0,0,0)
ELSE
        Input_method= CurrInputMethod
        stat= SetXyzInput(WsFreePoint)
        Stat=SetLastPoint(Pstart)
        Pend=XyzInput("ARROW END",WsXyOnly)
        stat= SetXyzInput(Input_method)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pend) THEN Dim_loop
	Last_pick_ent= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point2$)
                 Point_reference=1
        END IF
END IF


IF Dynamic_position THEN
	PlotOff
	E1= TextArrow(Dim_type,Pstart,Pend,Text$)
	PlotOn
	Stat=SetLastPoint(Pend)
        Stat=MakeInvisible(Pstart)
        Stat=MakeInvisible(Pend)
        IF NOT ValidGeometry(E1) THEN Dim_loop

        Which_end=1
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK LEADER END LOCATION",WsFalse)
	IF (ExitScript(Destination$)) THEN 
                Stat= DeleteEntity(E1)
                Stat=DeleteEntity(Pstart)
                Stat=DeleteEntity(Pend)
                GOTO Leave
        END IF
	Last_pick_ent= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point2$)
                 Point_reference=1
        END IF

	PlotOff
        Pend= ParameterPt(E1,1.0)
        Stat= DimTextFlagStr(E1,Textflags$)
        Stat= DeleteEntity(E1)
        PlotOn
ELSE
        Textflags$=""
END IF

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

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Text arrow")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
IF Point_reference THEN
        SELECT Pick_return2
        CASE WsGeometryEnd
                 Pe= ParameterReturnPt(Point2$,Pick_para2,WsGeometryEnd)
        CASE WsGeometryMid
                 Pe= ParameterReturnPt(Point2$,Pick_para2,WsGeometryMid)
        CASE WsGeomCenter
                 Pe= ParameterReturnPt(Point2$,Pick_para2,WsGeomCenter)
        END SELECT
ELSE
        V1= FreeParameter("Xloc",X1)
        V2= FreeParameter("Yloc",Y1)
        Pe= PtIncrXyz(Ps,V1,V2,Z1)
END IF
V3= StringConstant(Text$)
V4= StringConstant(Textflags$)
E1= TextArrow(WsTextArrow,Ps,Pe,V3,V4)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(E1)
Stat= PlotEntity(Point1$)
IF NOT ValidGeometry(E1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("text arrow")
	Stat= AddDimToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF


GOTO Dim_loop

Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntityList(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
