
! script name: vtypes.d/rotatetypes
! var_topic: rotate types in contour

!A
!A NAME:
!A
!A 	Rotate Types VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows types in a contour to be rotated as the contour
!A 	is described.  The types rotated 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 rotated.
!B
!B 	PICK ENDING TYPE: Pick an element of the ending type to be rotated.
!B
!B 	ROTATION ANGLE: Enter the angular rotation of the types being rotated
!B 		in degrees.
!B
!B 	NUMBER OF TIMES ROTATE: Enter the number of times the rotate sequence
!B 		should be repeated.
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Start_type$[256]
DIM End_type$[256]
DIM Angle_var$[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$)

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

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

Stat= GenerateVarName(WsTypeEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("TYPE R: rotate types")
Last=FindLastType
IF No_angle_var THEN
        V1= FreeParameter("Angle",Angle)
ELSE
        V1= FreeParameter("Angle",Angle_var$)
END IF
V2= FreeParameter("Number times",Ntimes)

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

Tp=RotateTypes(Start_type$,End_type$,Last,V1,V2)
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
