
! script name: vdraft.d/leaderballoon
! var_topic: construct text balloon with leader

!A
!A NAME:
!A
!A 	LeaderBalloon 	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a text balloon with a leader.
!A
!B INSTRUCTIONS:
!B
!B 	LEADER START POINT: Pick the point to be used for the start of the
!B 		leader. An arrow will be placed at this point.
!B
!B 	LEADER  MID POINT: Enter the point to be used for the
!B 		mid point of the leader.
!B
!B 	INPUT TEXT: Enter the  text to be placed in the balloon.
!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: leader balloon")

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Text$[256]
DIM Text1$[256]
DIM Point1$[256]
DIM Point2$[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= WsTextLeader
New_line$= "\n"
End_line$= CHR$(10)

Dim_loop:!

stat= SetInputFormat("a99","")
stat= GetValue("INPUT TEXT ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat= BackSlashChars(Answer$,Text$)

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

Input_method= CurrInputMethod
Stat=SetXyzInput(WsFreePoint)
Stat=SetLastPoint(Ps)
Pm=XyzInput("LEADER MID POINT",WsXyOnly)
Stat=SetXyzInput(Input_method)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Pm) THEN Dim_loop


IF Dynamic_position THEN
        Pe= ParameterPt(Pm,0)
ELSE
        Input_method= CurrInputMethod
        stat= SetXyzInput(WsFreePoint)
        Stat=SetLastPoint(Ps)
        Pe=XyzInput("TEXT LOCATION",WsXyOnly)
        stat= SetXyzInput(Input_method)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pe) THEN Dim_loop
END IF

IF Dynamic_position THEN
	PlotOff
	E1= TextBalloon(WsTextBalloon,Text$,Ps,Pm,Pe)
	PlotOn
        Stat=SetLastPoint(Pe)
        Stat=MakeInvisible(Ps)
        Stat=MakeInvisible(Pm)
        Stat=MakeInvisible(Pe)
        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(Ps)
                Stat=DeleteEntity(Pm)
                Stat=DeleteEntity(pe)
                GOTO Leave
        END IF

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

P1= SubtractVectors(Pm,Ps)
Stat= XYZPointValues(P1,X1,Y1,Z1)
Stat=DeleteEntity(P1)
P1= SubtractVectors(Pe,Ps)
Stat= XYZPointValues(P1,X2,Y2,Z2)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Pm)

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Leader Balloon")
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
V1= FreeParameter("Xmid",X1)
V2= FreeParameter("Ymid",Y1)
Pm= PtIncrXyz(Ps,V1,V2,Z1)
V1= FreeParameter("Xloc",X2)
V2= FreeParameter("Yloc",Y2)
V3= StringConstant(Text$)
V4= StringConstant(Textflags$)
Pe= PtIncrXyz(Ps,V1,V2,Z2)
E1= TextBalloon(WsTextBalloon,V3,Ps,Pm,Pe,V4)
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Ps,Pe,Pm)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

GOTO Dim_loop

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



