
! script name: vrotate.d/2drotatecont
! var_topic: 2D rotate a contour

!A
!A NAME:
!A
!A 	Single Group: 2D Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a contour group to be
!A      rotated.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR TO BE ROTATED: Pick the
!B 		contour to be rotated.
!B
!B 	REFERENCE POINT: Pick the point to be
!B 		used as the reference for the rotate.
!B
!B 	ROTATION ANGLE: Enter the angular amount
!B 		the entities should be rotated.
!B
!B 	NUMBER OF TIMES: Enter the number of times
!B 		the rotation process should be repeated.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: 2d rotate contour ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Name$[256]
DIM Center$[256]
DIM Angle_var$[256]
DIM Ntimes_var$[256]
DEG
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

Highlight_color= 3

Start: !
ActivateUndo
Contour=PickGroupEnt("PICK CONTOUR TO BE ROTATED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Contour) THEN Start
Stat= EntityNameCheck(Contour,Contour$)
Stat=Highlight(Contour,Highlight_color,WsDirArrowOff)
IF NOT ValidGeometry(Contour) THEN 
	GOTO Start
ELSE
	IF NOT GroupCount(Contour) THEN Start
END IF

Ref_point:E2=PickEntity("REFERENCE POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E2) THEN Line_loop
IF NOT ValidDependency(E2) THEN Ref_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)

Angle_ques:Angle=InputAngle("ROTATION ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
	IF NOT ValidDependency(L1) THEN Angle_ques
        No_angle_var=0
        Stat= EntityNameCheck(L1,Angle_var$)
END IF

Stat=SetEqualsValue(1)
Stat=SetInputFormat("n0=","")
Number=GetValue("NUMBER OF TIMES",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Number=0 THEN Start
No_times_var= LastVariableInput(Ntimes_var$)


Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("ROTATE: 2d rotate contour")
Stat= SetRecDelLastExec
RecordFunctionOn
Stat= NullReference(Contour$)
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF Number>1 THEN
    IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
        IF No_times_var THEN
		V2= FreeParameter("Number",Number)
                G1= PlaneRotateGroup(Contour$,Pc,V1,V2)
        ELSE
                G1= PlaneRotateGroup(Contour$,Pc,V1,Ntimes_var$)
        END IF
    ELSE
        IF No_times_var THEN
		V2= FreeParameter("Number",Number)
                G1= PlaneRotateGroup(Contour$,Pc,Angle_var$,V2)
        ELSE
                G1= PlaneRotateGroup(Contour$,Pc,Angle_var$,Ntimes_var$)
        END IF
    END IF
ELSE
    IF No_angle_var THEN
		V1= FreeParameter("Angle",Angle)
		G1= PlaneRotateGroup(Contour$,Pc,V1)
    ELSE
		G1= PlaneRotateGroup(Contour$,Pc,Angle_var$)
    END IF
END IF
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("rotate contour")
Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

Leave:!
Stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pt)

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

