
! script name: vcontours.d/contsegment
! var_topic: create a segment of a contour

!A
!A NAME:
!A
!A 	Contour Segment		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a segment contour of a contour.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick an element on the contour.
!B
!B 	PICK START POINT: Pick  the start point of the segment.
!B
!B 	PICK END POINT: Pick the end point of the segment.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: contour segment ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Pick_contour: !
Contour=PickGroupEnt("PICK CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat=EntityNameCheck(Contour,Contour$)

Stat=SetInputFormat("n4","")

Pick_start: !
E1=PickEntity("PICK START POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_start
IF NOT ValidDependency(E1) THEN Pick_start
T1=LastPickPara
Pick_return1=CurrPickReturn
Stat=EntityNameCheck(E1,Point1$)
Ps=ParameterReturnPt(E1,T1,Pick_return1)

Pick_end: !
Stat=SetLastPoint(Ps)
E2=PickEntity("PICK END POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E2) THEN Pick_end
IF NOT ValidDependency(E2) THEN Pick_end
T2=LastPickPara
Pick_return2=CurrPickReturn
Stat=EntityNameCheck(E2,Point2$)
Pe=ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)

Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Contour segment")
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
SELECT Pick_return2
    CASE WsGeometryEnd
	Pe=ParameterReturnPt(Point2$,T2,WsGeometryEnd)
    CASE WsGeometryMid
	Pe=ParameterReturnPt(Point2$,T2,WsGeometryMid)
    CASE WsGeomCenter
	Pe=ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
C1=ContourSegment(Contour$,Ps,Pe,WsFalse)
Stat=AutoNameGroup(C1,Name$)
Stat=DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("contour segment")
Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= PlotEntity(Contour$)
Stat= PlotEntity(C1)
GOTO Pick_contour

Leave:!
Stat=DeleteEntityList(Ps,Pe)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

