
! script name: vtypes.d/movetypes
! var_topic: move types in contour 

!A
!A NAME:
!A
!A 	Move Types     VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows types in a contour to be moved as the contour
!A 	is described.  The types moved are automatically attached to the
!A 	last type defined.
!A
!B INSTRUCTIONS:
!B
!B 	PICK STARTING TYPE: Pick an element of the starting type to be moved.
!B
!B 	PICK ENDING TYPE: Pick an element of the ending type to be moved.
!B
!B 	NUMBER OF TIMES MOVE: Enter the number of times the move sequence
!B 	 	should be repeated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: move types ")

DIM Destination$[256]
DIM Answer$[256]
DIM Start_type$[256]
DIM End_type$[256]
DIM Name$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

Start:!
stat= SetInputFormat("n4","")
Last_type=FindLastType
IF NOT ValidGeometry(Last_type) THEN Leave

stat= SetInputFormat("n4b","")
Start_type=PickTypeEnt("PICK STARTING TYPE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Start_type) THEN Start
Stat= EntityNameCheck(Start_type,Start_type$)

End_type:stat= SetInputFormat("n4b","")
End_type=PickTypeEnt("PICK ENDING TYPE")
IF (ExitScript(Destination$)) THEN
        IF Destination$= "BACKUP" THEN Start
        GOTO Leave
END IF
IF NOT ValidDependency(End_type) THEN End_type
Stat= EntityNameCheck(End_type,End_type$)

Stat=SetInputFormat("n0=b","")
Stat=SetEqualsValue(1)
Ntimes=GetValue("NUMBER OF TIMES MOVE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN End_type
       GOTO Leave
END IF

Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE M: move types")
Last=FindLastType
V1= FreeParameter("Number times",Ntimes)

RecordFunctionOff
ActivateUndo
Stat= AdvanceUndoNumber("move types")
Stat= AddGroupToUndo(WsUBModifyMode,Last)
RecordFunctionOn

Tp=MoveTypes(Start_type$,End_type$,Last,V1)
Stat= NameEntity(Tp,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

IF ValidGeometry(Tp) THEN
	Stat= AddGroupToUndo(WsUBCreateMode,Tp)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
ELSE
	DelLastVarRecord
END IF

PlotAll
Leave:!
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
