
! script name: vdraft.d/cutplaneline
! var_topic: construct cutting plane line.

!A
!A NAME:
!A
!A 	Cutting Plane Line	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs an cutting plane line with its
!A 	associated label and arrows.
!A
!B INSTRUCTIONS:
!B
!B 	START POINT: Pick the start point of the line.
!B
!B 	END POINT: Pick the end point of the line.
!B
!B 	INPUT LABEL, None: Enter the label should be 1 character
!B
!C NOTE:
!C
!C	The labels may be located in three dirrerent places.
!C	This is controled by the parameter Label location.
!C	A value of 1 puts the labels at the ends of the arrows.
!C	A value of 2 puts the labels below the cutting plane line.
!C	A value of 3 puts the labels at the ends of the cutting plane line.
!C	Values of 11,12,13 give only the left half configuration.
!C	Values of 21,22,23 give only the right half configuration.
!C
!# see also - htdocs/help.d/dynamicdim.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: cutting plane line ")

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= WsCuttingPlaneLine
New_line$= "\n"
End_line$= CHR$(10)
Text_height= GetDefault(WsTextHeight)
Text_width= GetDefault(WsTextWidth)
Arrow_height= GetDefault(WsArrowHeight)
Arrow_width= GetDefault(WsArrowWidth)
Text_scale= 3.0
Label_location= 1


Dim_loop:! 
stat= SetInputFormat("a99","")
stat= GetValue("INPUT LABEL, 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

stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Line_loop:Pstart=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pstart) THEN Line_loop
E1= LastPickEnt
Pick_para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pstart)
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created=WsTrue
ELSE
        Stat= EntityNameCheck(E1,Point1$)
        Ps_created=WsFalse
END IF
Stat=SetLastPoint(Pstart)


IF Dynamic_position THEN
        Pend= PointXYZ(0,0,0)
ELSE
	End_point:!
        Stat= PointInputMode(1)
        Pend=XyzInput("ENDING",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pend) THEN Line_loop
        E2= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pend)
                 Stat= EntityNameCheck(E2,Point2$)
                 Pe_created=WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point2$)
                 Pe_created=WsFalse
        END IF
        Stat=SetLastPoint(Pend)
END IF


Height= 2.0*Text_scale*Text_height
Side= WsLeft
IF Dynamic_position THEN
	PlotOff
	E1= CuttingPlaneLine(Dim_type,Pstart,Pend,Height,Label_location,8,Side,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
	Stat=DeleteEntity(Pend)
        Pend= ParameterPt(E1,1.0)
	E2= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
	IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pend)
                 Stat= EntityNameCheck(E2,Point2$)
                 Stat= MakeVisible(E2)
                 Pe_created=WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point2$)
                 Pe_created=WsFalse
        END IF

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

PlotOff
Stat=SetLastPoint(Pend)
Stat=DeleteEntity(Pstart,WsTrue)
Stat=DeleteEntity(Pend,WsTrue)
PlotOn


Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Text arrow")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Pick_para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Pick_para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Pick_para1,WsGeomCenter)
END SELECT
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
V3= StringConstant(Text$)
V4= StringConstant(Textflags$)
V5= FreeParameter("Height",Height)
V6= FreeParameter("Label location",Label_location)
V7= FreeParameter("Linetype",8)
V8= FreeParameter("Side",Side)
V9= FreeParameter("Text scale",3.0)
E1= CuttingPlaneLine(WsCuttingPlaneLine,Ps,Pe,V5,V6,V7,V8,V3,V9,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("cutting plane line")
	IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
	IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
	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
