
! script name: vtrimming.d/addopencont
! var_topic: add open contours

!A
!A NAME:
!A
!A 	Add open contours  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script adds two contours which may be open. The contours are
!A	divided into components by the intersection points. The select
!A	points determine which components are saved.
!A	
!A
!A~ image location - images/addopencont.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR #1: Pick the first contour.
!B
!B	PICK SELECT POINT FOR CONTOUR #1: Determines saved portion of contour1.
!B
!B
!B 	PICK CONTOUR #2: Pick the second contour.
!B
!B	PICK SELECT POINT FOR CONTOUR #2: Determines saved portion of contour2. 
!B
!B
!B
!B NOTE:
!B
!B	This function deletes the original contour.
!B
!B	This function should only be used on contours which are
!B	created or embeded variationally. If used on a non variational
!B	contour the function will work the first time but future
!B	execution of the variational object will fail.
!B	If the contours are defined in a different object than the object
!B	that this function is in, it may be necessary to do an execute all
!B	when editing information.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: add open contours")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour1$[256]
DIM Contour2$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]


Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Start:!

Pick_contour1:!
Stat=SetInputFormat("n4","")
E1=PickEntity("PICK CONTOUR #1 ")
IF (ExitScript(Destination$)) THEN Leave
Contour1= ParentGroup(E1)
IF (NOT ValidDependency(Contour1)) THEN Pick_contour1
Stat= EntityNameCheck(Contour1,Contour1$)
IF NOT LEN(Contour1$) THEN Pick_contour1



Pick_select1: !
E1=PickEntity("PICK SELECT POINT FOR CONTOUR #1 ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_select1
Pick_para1=LastPickPara
Pick_return1=CurrPickReturn
Stat=EntityNameCheck(E1,Point1$)


Pick_contour2:!
Stat=SetInputFormat("n4","")
E2=PickEntity("PICK CONTOUR #2 ")
IF (ExitScript(Destination$)) THEN Leave
Contour2= ParentGroup(E2)
IF (NOT ValidDependency(Contour2)) THEN Pick_contour2
Stat= EntityNameCheck(Contour2,Contour2$)
IF NOT LEN(Contour2$) THEN Pick_contour2

Pick_select2: !
E2=PickEntity("PICK SELECT POINT FOR CONTOUR #2 ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_select2
Pick_para2=LastPickPara
Pick_return2=CurrPickReturn
Stat=EntityNameCheck(E2,Point2$)


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TRIM: add open contours ")
SELECT Pick_return1
    CASE WsGeometryEnd
        P1=ParameterReturnPt(Point1$,Pick_para1,WsGeometryEnd)
    CASE WsGeometryMid
        P1=ParameterReturnPt(Point1$,Pick_para1,WsGeometryMid)
    CASE WsGeomCenter
        P1=ParameterReturnPt(Point1$,Pick_para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
    CASE WsGeometryEnd
        P2=ParameterReturnPt(Point2$,Pick_para2,WsGeometryEnd)
    CASE WsGeometryMid
        P2=ParameterReturnPt(Point2$,Pick_para2,WsGeometryMid)
    CASE WsGeomCenter
        P2=ParameterReturnPt(Point2$,Pick_para2,WsGeomCenter)
END SELECT
G1=AddOpenContours(Contour1$,P1,Contour2$,P2)
RecordFunctionOff
IF ValidGeometry(G1) THEN
        RecordFunctionOn
        Stat=AutoNameGroup(G1,Name$)

        ActivateUndo
        Stat= AdvanceUndoNumber("add open contours")
        Stat= AddGroupToUndo(WsUBDeleteMode,Contour1$,1,WsTrue)
        Stat= AddGroupToUndo(WsUBDeleteMode,Contour2$,1,WsTrue)
	Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsTrue)

        Stat=DeleteGroup(Contour1$,WsTrue)
        Stat=DeleteGroup(Contour2$,WsTrue)
        RecordFunctionOff
        Stat=PlotEntity(G1)
END IF
RecordFunctionOn
Stat= DeleteEntityList(G1,P1,P2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
GOTO Pick_contour1

Leave:!
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END


