
! script name: vtrimming.d/grpsplitcont
! var_topic: split a contour by intersections with a group

!A
!A NAME:
!A
!A 	Group Intersect Split Contour  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script splits a contour into component paths based
!A	on the intersections with a group of elements.
!A	The select point divides the components into selected
!A	and non selected components by the rule that the selected
!A	components include the picked one and every other component.
!A	Current properties as color, line type, layer are applied
!A	to the selected components.
!A
!A~ image location - images/contoursplit.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick the contour.
!B
!B 	PICK GROUP: Pick the group of intersecting elements
!B
!B	PICK SELECT POINT: This point determines which components are
!B			selected.
!B
!B NOTE:
!B
!B	It there are no intersections the entire contour is selected.
!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: group intersect split  contour ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour1$[256]
DIM Contour2$[256]
DIM Point$[256]
DIM Name$[256]


Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Start:!

Pick_contour1:!
Stat=SetInputFormat("n4","")
E1=PickEntity("PICK CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave
Contour1= ParentGroup(E1)
IF (NOT ValidGeometry(Contour1)) THEN
        IF (NOT ValidDependency(E1)) THEN Pick_contour1
        Stat= EntityNameCheck(E1,Contour1$)
        Contour1= E1
ELSE
        IF (NOT ValidDependency(Contour1)) THEN Pick_contour1
        Stat= EntityNameCheck(Contour1,Contour1$)
END IF
IF NOT LEN(Contour1$) THEN Pick_contour1
IF NOT IsEntVariational(Contour1) THEN
   Stat=SetInputFormat("a99","")
   Stat= GetValue("NON-VDM ENTITY. CANNOT USE ON NON VDM ENTITY ",Answer$)
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF


Pick_contour2:!
Stat=SetInputFormat("n4","")
E2=PickEntity("PICK INTERSECTING GROUP")
IF (ExitScript(Destination$)) THEN Leave
Contour2= ParentGroup(E2)
IF (NOT ValidGeometry(Contour2)) THEN 
	IF (NOT ValidDependency(E2)) THEN Pick_contour2
	Stat= EntityNameCheck(E2,Contour2$)
	Contour2= E2
ELSE
	IF (NOT ValidDependency(Contour2)) THEN Pick_contour2
	Stat= EntityNameCheck(Contour2,Contour2$)
END IF
IF NOT LEN(Contour2$) THEN Pick_contour2

Pick_select: !
E1=PickEntity("PICK SELECT POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_select
IF NOT ValidDependency(E1) THEN Pick_select
Pick_para=LastPickPara
Pick_return=CurrPickReturn
Stat=EntityNameCheck(E1,Point$)

ActivateUndo
Stat= AdvanceUndoNumber("group split")


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TRIM: Group intersect split contour ")
Stat= NullReference(Contour1$)
Stat= NullReference(Contour2$)
SELECT Pick_return
    CASE WsGeometryEnd
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
    CASE WsGeometryMid
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
    CASE WsGeomCenter
        Pt=ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
V1= FreeParameter("Select ",1)
G1=IntersectSplitCont(Contour1$,Contour2$,Pt,V1)
Stat= AutoNameGroup(G1,Name$)
Stat= AddGroupToUndo(WsUBDeleteMode,Contour1$,1,WsTrue)
Stat= AddGroupToUndo(WsUBCreateMode,G1,0,WsTrue)
Stat= DeleteGroup(Contour1$,WsTrue)
RecordFunctionOff
Stat= PlotEntity(G1)
RecordFunctionOn
Stat= DeleteEntityList(G1,Pt)
RecordFunctionOff
 Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= PlotEntity(Point$)
GOTO Pick_contour1

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


