
! script name: vtypes.d/inverttypes
! var_topic: invert types in contour

!A
!A NAME:
!A
!A 	Invert Types  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows types in a contour to be inverted as the contour
!A 	is described.  The types inverted 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
!B 		inverted.
!B
!B 	PICK ENDING TYPE: Pick an element of the ending type to be inverted.
!B
!B 	ANGLE OF INVERSION LINE: Enter the angle of the line that the types
!B 		should be inverted about.
!B

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

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


stat= SetInputFormat("n4","")

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$)

Angle:!
Stat=SetInputFormat("n4b","")
Angle=InputAngle("ANGLE OF INVERSION LINE")
IF (ExitScript(Destination$)) THEN
       IF Destination$= "BACKUP" THEN End_type
       GOTO Leave
END IF
No_angle_var= LastVariableInput(Angle_var$)

Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE I: invert types")
Last=FindLastType
IF No_angle_var THEN
        V1= FreeParameter("Angle",Angle)
ELSE
        V1= FreeParameter("Angle",Angle_var$)
END IF

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

Tp=InvertTypes(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
