
! script name: vmove.d/dyn3dmultcont
! var_topic: Dynamic move multiple groups

!A
!A NAME:
!A
!A 	Graphical 3D	VARATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script moves multiple groups graphically.
!A
!B INSTRUCTIONS:
!B
!B 	PICK GROUP TO BE MOVED: Pick an element
!B 		on the group to be moved.
!B
!B 	REFERENCE POINT ABS X,Y,Z: Enter the X,Y,Z
!B 		coordinates of the point to be used as the reference
!B 		for the move.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PICK DESTINATION POINT: The elements to be
!B 		moved are displayed graphically with the cursor. 
!B		Hitting the Select Buttonon the mouse will select the location.
!B		The numeric keypad controls the orientation.
!B
!B			(6) 0   degree orientation.
!B			(9) 45  degree orientation.
!B			(8) 90  degree orientation.
!B			(7) 135 degree orientation.
!B			(4) 180 degree orientation.
!B			(1) 225 degree orientation.
!B			(2) 270 degree orientation.
!B			(3) 305 degree orientation.
!B
!B 		Plus (+) and (-) turn the entities +/- the angular increment.
!B		The Default angular increment is 5 degrees. 
!B		Hitting ( A ) will change the increment to 10 degrees.		
!B		Hitting ( a ) will change the increment to 1 degrees.		
!B		Hitting ( F ) or ( f ) will change the increment to 0.1 degrees.
!B		Hitting ( D ) or ( d ) will return the increment to 5 degrees.
!B
!B
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: Graphical 3D")

DIM Answer$[256]
DIM Destination$[256]
DIM Extras$[256]
DIM Contour$[256]
DIM Xangle$[256]
DIM Yangle$[256]
DIM Zangle$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DEG

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

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Place_min= NamedVarVal("Graph place min",WsSystemVars,50)
Place_max= NamedVarVal("Graph place max",WsSystemVars,500)
Place_density= NamedVarVal("Graph place density",WsSystemVars,3)

Start: !
ActivateUndo
Stat=SetPickMask(WsPickAll)
Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

stat= SetInputFormat("n4","")
Group1=CreateGroup("TEMP")
Extras$= ""

Contour_loop:!
LOOP
        stat= SetInputFormat("a1",",P,B,")
Pick_ent:Contour= PickGroupEnt("PICK CONTOURS TO BE MOVED"&Extras$,0,Answer$)
        IF ExitScript(Destination$) THEN Leave
        Stat=SetInputFormat("n4"," ")
        EXIT IF Answer$= "P"
        IF Answer$="B" THEN
                Num1=GroupCount(Group1)
                C1=GroupElement(Group1,Num1)
                IF Num1 THEN Stat= RemoveFromGrp(Group1,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(Group1,Contour)
                        IF NOT N1 THEN Stat=AddToGroup(Group1,Contour)
                        Extras$=", Backup , Proceed "
                        Stat= SetSelectedFlag(Contour,WsTrue)
                        Stat= PlotEntity(Contour)
                END IF
        END IF

END LOOP

stat= SetInputFormat("n4","")
IF NOT ValidGeometry(Group1) THEN
        GOTO Start
ELSE
        IF NOT GroupCount(Group1) THEN 
		Stat= DeleteEntity(Group1)
		GOTO Start
	END IF
END IF

Xangle: Xangle=InputAngle("X ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_xangle_var= LastVariableInput(Xangle$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Xangle
        Stat= EntityNameCheck(L1,Xangle$)
        No_xangle_var=0
END IF

Yangle:Yangle=InputAngle("Y ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_yangle_var= LastVariableInput(Yangle$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Yangle
        Stat= EntityNameCheck(L1,Yangle$)
        No_yangle_var=0
END IF

Zangle:Zangle=InputAngle("Z ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_zangle_var= LastVariableInput(Zangle$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
        IF NOT ValidDependency(L1) THEN Zangle
        Stat= EntityNameCheck(L1,Zangle$)
        No_zangle_var=0
END IF

Ref_pt:P1=PickEntity("REFERENCE POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(P1) THEN Ref_pt
Para1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(P1,Point1$)
Pref= ParameterReturnPt(P1,Para1,Pick_return1)


Place_group:!
FadeUndoButtons
Angle= 0
PlotOff
Pdest= CopyEntity(Pref)
Axis_line= WorkplaneAxisLine(Work,Pref)
StdWorkplane
Orient= Rot3dAnglesTrans(Pref,Xangle,Yangle,Zangle)
Group2= CopyGroup(Group1)
Stat=TransGroupTrans(Group2,Orient,WsTrue)
Stat= SetWorkplane(Work)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
PlotOn

Vnum= LastPickView
stat= SetInputFormat("n4b","")
Group3= MakeSparseGroup(Group2,Place_min,Place_max,Place_density)
Stat= EraseEntity(Group1)
Stat= MakeInvisible(Group2)
Stat= MakeInvisible(Group1)
Rotate_angle= DynamicMoveGroup(Vnum,Group3,Pref,Pdest,Angle,"PICK DESTINATION POINT")
Stat= DeleteEntity(Group3)
Stat= DeleteGroup(Group2,2)
Stat= MakeVisible(Group1)
IF ExitScript(Destination$) THEN 
	Stat= PlotEntity(Group1)
	GOTO Leave
END IF
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
IF NOT ValidDependency(E2) THEN
        E2= CopyEntity(Pdest)
        Stat= MakeVisible(E2)
        Stat= EntityNameCheck(E2,Point2$)
	P2_created= WsTrue
ELSE
        Stat= EntityNameCheck(E2,Point2$)
	P2_created= WsFalse
END IF
Stat= DeleteEntityList(Pref,Pdest,Axis_line)


Make_record:!
Stat= SetSelectedFlag(Group1,WsFalse)

ActivateUndo
Stat= AdvanceUndoNumber("move contours")
Stat= AddGroupToUndo(WsUBModifyMode,Group,0,WsTrue)

Num_elements= GroupCount(Group1)
RecordFunctionOn
Stat= RecordDescr("MOVE: ref move multi contours")
G1= CreateGroup("Picked Contours")
FOR I=1 TO Num_elements
RecordFunctionOff
        Contour= GroupElement(Group1,I)
        Stat= EntityNameCheck(Contour,Contour$)
        IF ValidDependency(Contour) THEN
                RecordFunctionOn
                Stat= AddToGroup(G1,Contour$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
IF No_xangle_var THEN
        V1= FreeParameter("X angle",Xangle)
ELSE
        V1= FreeParameter("X angle",Xangle$)
END IF
IF No_yangle_var THEN
        V2= FreeParameter("Y angle",Yangle)
ELSE
        V2= FreeParameter("Y angle",Yangle$)
END IF
IF No_xangle_var THEN
        V3= FreeParameter("Z angle",Zangle)
ELSE
        V3= FreeParameter("Z angle",Zangle$)
END IF
Work= CurrentWorkplane
L1= WorkplaneAxisLine(Work,Ps)
Stat=SetWorkplane(0)
V4= FreeParameter("Rotate angle",Rotate_angle)
Trans1= Rot3DMoveAxisTrans(Pe,L1,V4,V1,V2,V3)
Stat=TransGroupTrans(G1,Trans1,WsTrue)
Stat= DeleteEntityList(G1,Ps,Pe,L1)
Stat=SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord


IF P2_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= DeleteEntityList(Group1,Pref,Pdest,Axis_line)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
Stat=SetPickMask(WsPickAll)
GOTO Start

Leave: !
Stat=SetPickMask(WsPickAll)
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF
stat= SetInputFormat("n4","")
Stat= SetSelectedFlag(Group1,WsFalse)
Stat=PlotEntity(Group1)
Stat= DeleteEntityList(Group1,Pref,Pdest,Axis_line)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
