
! script name: vcontours.d/joincontours
! var_topic: join two contours

!A
!A NAME:
!A
!A 	Join Contours		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script joins two contours.  A line will join the start point
!A 	of the first contour to the end point of the other contour.
!A 	The original contour is deleted.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST CONTOUR: Pick the first
!B 		contour to be joined, the start point of this
!B 		contour will be used for the joining.
!B
!B 	PICK NEXT CONTOUR: Pick the other
!B 		contour to be joined, the end point of this
!B 		contour will be used for the joining.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: join contours ")

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Join_loop: !

Pick_contour1: !
Contour1=PickGroupEnt("PICK FIRST CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour1) THEN Pick_contour1
Stat=EntityNameCheck(Contour1,Contour1$)
IF NOT IsEntVariational(Contour1) THEN
   Stat=SetInputFormat("a1",",Y,N,")
   Stat= GetValue("NON-VDM ENTITY. LOAD NON-VDM? Yes or No ",Answer$)
   IF Answer$="N" THEN Pick_contour
   Destination$= "contours.d/joincontours"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Pick_contour2: !
Contour2=PickGroupEnt("PICK NEXT CONTOUR ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour2) THEN Pick_contour2
Stat=EntityNameCheck(Contour2,Contour2$)
IF NOT IsEntVariational(Contour2) THEN
   Stat=SetInputFormat("a1",",Y,N,")
   Stat= GetValue("NON-VDM ENTITY. LOAD NON-VDM? Yes or No ",Answer$)
   IF Answer$="N" THEN Pick_contour
   Destination$= "contours.d/joincontours"
   Stat=SetInputFormat("n4","")
   GOTO Leave
END IF

Tool= GetAssocTool(Contour1$)
Has_tool= ValidGeometry(Tool)

Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Join contours")
V2= FreeParameter("Dia comp dir",GetDCompDirection(Contour1$))
C1=CopyGroup(Contour1$)
C2=CopyGroup(Contour2$)
C3=JoinContours(C1,C2)
Stat=DeleteEntity(C1)
Stat=DeleteEntity(C2)
RecordFunctionOff
IF ValidGeometry(C3) THEN
	RecordFunctionOn
	Stat=AutoNameGroup(C3,Name$)
	Stat=SetDCompDirection(C3,V2)
	IF Has_tool THEN
		Tool= GetAssocTool(Contour1$)
		Stat= AssociateTool(C3,Tool)
	END IF
	ActivateUndo
	Stat= AdvanceUndoNumber("join contours")
	Stat= AddGroupToUndo(WsUBDeleteMode,Contour1$,1,WsTrue)
	Stat= AddGroupToUndo(WsUBDeleteMode,Contour2$,1,WsTrue)

	Stat=DeleteGroup(Contour1$,WsTrue)
	Stat=DeleteGroup(Contour2$,WsTrue)
	RecordFunctionOff
	Stat=PlotEntity(C3)
END IF
RecordFunctionOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C3) THEN
	DelLastVarRecord
ELSE
	Stat= AddGroupToUndo(WsUBCreateMode,C3,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Join_loop

Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

