
! script name: vinvert.d/2dinvertmcont
! var_topic: 2D invert multiple contours

!A
!A NAME:
!A
!A 	Multiple Groups: 2D Duplicate	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script inverts multiple contours.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOURS TO BE INVERTED, Backup, Proceed: Pick
!B 		one of the contours to be inverted.  The question
!B 		will repeat until "Proceed" is answered.  All contours
!B 		picked will then be inverted.
!B
!B 		B - The backup option allows the last contours picked to
!B 		    be removed from the group of contours to be inverted.
!B
!B 	REFERENCE POINT : Pick the point to be
!B 		used as the reference for the invert.
!B
!B 	INVERSION ANGLE: Enter the angle about
!B 		which the entities should be inverted.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: 2d invert multiple contours ")

DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[64]
DIM Contour$[256]
DIM Name$[256]
DIM Center$[256]
DIM Angle_var$[256]
DEG


Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Start: !
ActivateUndo

stat= SetInputFormat("n4","")

Group=CreateGroup("TEMP")
Extras$= ""
LOOP
        stat= SetInputFormat("a1",",P,B,")
Pick_ent:Contour= PickGroupEnt("PICK CONTOURS TO INVERT"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group)
                C1=GroupElement(Group,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group,Num1)
                Stat= SetSelectedFlag(C1,WsFalse)
                Stat= PlotEntity(C1)
                IF Num1=1 THEN Extras$= ""
        ELSE
                IF ValidGeometry(Contour) THEN
                IF NOT ValidDependency(Contour) THEN Pick_ent
                IF IsEntityDependent(Contour)= WsFalse THEN
                   stat= SetInputFormat("a99","")
                   Stat= GetValue("NOT A VARIATIONAL CONTOUR, Proceed ",Answer$)
                   IF ExitScript(Destination$) THEN Leave
                   GOTO Pick_ent
                END IF
                        N1= ElementGrpNum(Group,Contour)
                        IF NOT N1 THEN Stat=AddToGroup(Group,Contour)
                        Extras$=", Backup , Proceed "
                        Stat= SetSelectedFlag(Contour,WsTrue)
                        Stat= PlotEntity(Contour)
                END IF
        END IF

END LOOP
IF NOT ValidGeometry(Group) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group) THEN Start
END IF

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

Angle_ques:Angle=InputAngle("INVERSION 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= DeleteEntity(Pc)



Stat= SetSelectedFlag(Group,WsFalse)
Num_elements= GroupCount(Group)
Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("INVERT: 2d invert mult contours")
Stat= SetRecDelLastExec
G1= CreateGroup("Picked Contours")

FOR I=1 TO Num_elements
RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Contour$$)
	IF ValidDependency(E1) THEN 
		RecordFunctionOn
        	Stat= AddToGroup(G1,Contour$$)
		RecordFunctionOff
	END IF
NEXT I
RecordFunctionOn
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 No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
	T1=AngleTransform(Pc,90,0,V1,WsWorkplaneVals)
ELSE
	T1=AngleTransform(Pc,90,0,Angle_var$,WsWorkplaneVals)
END IF
T2=InvertInPlane(T1)
G2= CopyGroup(G1)
Stat=TransGroupTrans(G2,T2,WsTrue,WsTrue)
Stat= AutoNameGroup(G2,Name$)
ActivateUndo
Stat= AdvanceUndoNumber("invert contours")
Stat= AddGroupToUndo(WsUBCreateMode,G2,0,WsTrue)
Stat=DeleteEntityList(G1,G2,Pc,T1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Center$)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)

GOTO Start

Leave: !
stat= SetInputFormat("n4","")
Stat= DeleteEntity(Pc)
Stat= SetSelectedFlag(Group,WsFalse)
Stat= PlotEntity(Group)
Stat= DeleteEntity(Group)
Stat= DeleteEntity(G1)

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

