
! script name: vdraft.d/doubleballoon
! var_topic: construct over/under text balloon with leader

!A
!A NAME:
!A
!A 	Over Under Balloon 	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a over under text balloon with a leader.
!A
!B INSTRUCTIONS:
!B
!B 	LEADER START POINT: Pick the point to be
!B 		used for the start of the leader.
!B 		An arrow will be placed at this point.
!B
!B 	LEADER MID POINT: PICK FREE POINT: Pick the
!B 		point to be used for the mid point of the leader.
!B
!B 	TEXT LOCATION: PICK FREE POINT: Pick the
!B 		point to be used for the location of the balloon.
!B
!B 	INPUT UPPER TEXT: Enter the text to be
!B 		placed in the upper half of the balloon.
!B
!B 	INPUT LOWER TEXT: Enter the text to be
!B 		placed in the lower half of 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
!C 	to 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: over under  balloon")

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Text1$[256]
DIM Text2$[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

Dynamic_position=1
Dim_type= WsTextLeader

ActivateUndo
Dim_loop:!
stat= SetInputFormat("a99","")
stat= GetValue("INPUT UPPER TEXT ",Answer$)
IF ExitScript(Destination$) THEN Leave
Stat= BackSlashChars(Answer$,Text1$)

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

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= OverUnderBalloon(WsTextBalloon,Text1$,Text2$,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=DeleteEntityList(P1,Ps,Pe,Pm)

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Over Under 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(Text1$)
V4= StringConstant(Text2$)
V5= StringConstant(Textflags$)
Pe= PtIncrXyz(Ps,V1,V2,Z2)
E1= OverUnderBalloon(WsTextBalloon,V3,V4,Ps,Pm,Pe,V5)
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("over under 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


