From bc829f47837b5a001f911542140b0b8e63c2bb0c Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 14 Jul 2019 19:47:03 -0400
Subject: [PATCH] Fix extract big data.

---
 GroupEditor.java |  215 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 156 insertions(+), 59 deletions(-)

diff --git a/GroupEditor.java b/GroupEditor.java
index d57f0f7..ec26bdb 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -84,6 +84,10 @@
 
     void CloneSelection(boolean supports)
     {
+        if (Globals.SAVEONMAKE)
+            Save();
+        boolean keep = Globals.SAVEONMAKE;
+        Globals.SAVEONMAKE = false;
         //   Object3D keep = GrafreeD.clipboard;
            //Object3D obj;
            for (int i=0; i<group.selection.size(); i++)// Enumeration e = group.selection.elements(); e.hasMoreElements();)
@@ -94,6 +98,7 @@
                
                makeSomething(clone, i==group.selection.size()-1);
            }
+        Globals.SAVEONMAKE = keep;
     }
 
     void CloneClipboard(boolean supports)
@@ -220,7 +225,7 @@
 //        toggleSwitchItem.addItemListener(this);
 //        toggleSwitchItem.setState(CameraPane.SWITCH);
         
-        cameraMenu.add(toggleHandleItem = new CheckboxMenuItem("Handles"));
+        cameraMenu.add(toggleHandleItem = new CheckboxMenuItem("Show Handles"));
         toggleHandleItem.addItemListener(this);
         toggleHandleItem.setState(CameraPane.HANDLES);
         
@@ -380,13 +385,14 @@
 		shadowYItem.addActionListener(this);
                 shadowZItem = menu.add(new MenuItem("Shadow Blue"));
 		shadowZItem.addActionListener(this);
+		attributeItem = menu.add(new MenuItem("Attribute"));
+		attributeItem.addActionListener(this);
+                
         if (Globals.ADVANCED)
         {
 		menu.add("-");
 		linkerItem = menu.add(new MenuItem("Linker"));
 		linkerItem.addActionListener(this);
-		attributeItem = menu.add(new MenuItem("Attribute"));
-		attributeItem.addActionListener(this);
 		templateItem = menu.add(new MenuItem("Template"));
 		templateItem.addActionListener(this);
 		pointflowItem = menu.add(new MenuItem("Point Flow"));
@@ -582,7 +588,7 @@
          */
                 cGridBag copyOptionsPanel = new cGridBag();
                                         
-                copyOptionsPanel.preferredHeight = 2;
+                copyOptionsPanel.preferredHeight = 1;
                 
                 //this.AddOptions(oe.toolbarPanel, oe.aConstraints);
                 
@@ -590,14 +596,21 @@
                 //minButton.setToolTipText("Minimize window");
 		//minButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(maxButton = GetButton("icons/add-128.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                maxButton.setToolTipText("Maximize window");
-		maxButton.addActionListener(this);
+                if (Globals.ADVANCED)
+                {
+                    oe.toolbarPanel.add(maxButton = GetButton("icons/add-128.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                    maxButton.setToolTipText("Maximize window");
+                    maxButton.addActionListener(this);
+                }
                 
 		oe.toolbarPanel.add(fullButton = GetButton("icons/fullscreen.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 fullButton.setToolTipText("Full-screen window");
 		fullButton.addActionListener(this);
                 
+		oe.toolbarPanel.add(screenfitButton = GetButton("icons/fit.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                screenfitButton.setToolTipText("Screen fit");
+		screenfitButton.addActionListener(this);
+
 		oe.toolbarPanel.add(restoreCameraButton = GetButton("icons/eye.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 restoreCameraButton.setToolTipText("Restore viewpoint");
 		restoreCameraButton.addActionListener(this);
@@ -605,10 +618,12 @@
 		copyOptionsPanel.add(undoButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 undoButton.setToolTipText("Undo changes");
 		undoButton.addActionListener(this);
+                undoButton.setEnabled(false);
                 
 		copyOptionsPanel.add(redoButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 redoButton.setToolTipText("Redo changes");
 		redoButton.addActionListener(this);
+                redoButton.setEnabled(false);
                 
 		copyOptionsPanel.add(saveButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 saveButton.setToolTipText("Save changes");
@@ -628,10 +643,6 @@
                                 
                 //oe.toolboxPanel.Return();
                 
-		copyOptionsPanel.add(screenfitButton = GetButton("icons/fit.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                screenfitButton.setToolTipText("Screen fit");
-		screenfitButton.addActionListener(this);
-
 //                copyOptionsPanel.add(trackCB = GetToggleButton("icons/track.png", CameraPane.TRACK)); //, oe.aConstraints);
 //                trackCB.setToolTipText("Enable tracking");
 //                                trackCB.addItemListener(this);
@@ -724,7 +735,7 @@
                                compositeButton.addActionListener(this);
 
                 oe.toolboxPanel.add(switchButton = GetButton("icons/switch.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                switchButton.setToolTipText("Create switch");
+                switchButton.setToolTipText("Create item switcher");
                                switchButton.addActionListener(this);
 
                 oe.toolboxPanel.add(loopButton = GetButton("icons/loop.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
@@ -743,17 +754,29 @@
                 lightButton.setToolTipText("Create light");
                                lightButton.addActionListener(this);
 
+                for (int i=6; --i>=0;)
+                {
+                oe.toolboxPanel.Return();
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                oe.toolboxPanel.add(new cGridBag());
+                }
+                
                 // EDIT panel
-		editCommandsPanel.add(editButton = new cButton("+", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                editButton.setToolTipText("Edit selection");
+		editCommandsPanel.add(editButton = GetButton("icons/controls.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                editButton.setToolTipText("Pin selection controls");
 		editButton.addActionListener(this);
 
-		editCommandsPanel.add(uneditButton = new cButton("-", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                uneditButton.setToolTipText("Unedit selection");
+		editCommandsPanel.add(uneditButton = GetButton("icons/remove.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                uneditButton.setToolTipText("Remove selection controls");
 		uneditButton.addActionListener(this);
 
 		editCommandsPanel.add(allParamsButton = new JCheckBox("All", allparams)); //, oe.aConstraints);
-                allParamsButton.setToolTipText("Edit all params");
+                allParamsButton.setToolTipText("Show all controle");
 		allParamsButton.addActionListener(this);
 
 		editCommandsPanel.add(clearPanelButton = new cButton("C", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
@@ -770,6 +793,7 @@
                 
                 editCommandsPanel.preferredHeight = 1;
                 
+                SetPinStates(false);
 //                oe.treePanel.add(commandsPanel);
 //                oe.treePanel.Return();
                 
@@ -843,14 +867,18 @@
                                 boxCB.addItemListener(this);
                                 
                 panel.add(zoomBoxCB = new cCheckBox("Zoom", CameraPane.ZOOMBOXMODE)); //, constraints);
-                zoomBoxCB.setToolTipText("Display bounding boxes when moving the wheel");
+                zoomBoxCB.setToolTipText("Display only for wheel");
                                 zoomBoxCB.addItemListener(this);
 
         if (true) // Globals.ADVANCED)
         {
-                panel.add(supportCB = new cCheckBox("Support", CameraPane.SUPPORT)); //, constraints);
-                supportCB.setToolTipText("Enable rigging");
-                                supportCB.addItemListener(this);
+//                panel.add(supportCB = new cCheckBox("Support", CameraPane.SUPPORT)); //, constraints);
+//                supportCB.setToolTipText("Enable rigging");
+//                                supportCB.addItemListener(this);
+
+                panel.add(freezeCB = new cCheckBox("Freeze", Globals.FREEZEONMOVE)); //, constraints);
+                freezeCB.setToolTipText("Fast moving camera");
+                                freezeCB.addItemListener(this);
 
         //        panel.add(localCB = new cCheckBox("Local", CameraPane.LOCALTRANSFORM), constraints);
         //                        localCB.addItemListener(this);
@@ -905,7 +933,7 @@
                                 oeilCB.addItemListener(this);
 
                 panel.add(shadowCB = new cCheckBox("Shadow", Globals.COMPUTESHADOWWHENLIVE)); //, constraints);
-                shadowCB.setToolTipText("Compute shadows when live");
+                shadowCB.setToolTipText("When live compute shadows");
                                 shadowCB.addItemListener(this);
 
                 panel.Return();
@@ -914,11 +942,11 @@
                                 toggleTextureCB.addItemListener(this);
                                 
                 panel.add(toggleSwitchCB = new cCheckBox("Switch", CameraPane.SWITCH)); //, constraints);
-                toggleSwitchCB.setToolTipText("Use switch");
+                toggleSwitchCB.setToolTipText("Choose a single item");
                                 toggleSwitchCB.addItemListener(this);
                                 
                 panel.add(autosaveCB = new cCheckBox("Auto-save", Globals.SAVEONMAKE)); //, constraints);
-                autosaveCB.setToolTipText("Auto-save on structure change");
+                autosaveCB.setToolTipText("On structure change");
                                 autosaveCB.addItemListener(this);
 
                 panel.Return();
@@ -948,7 +976,7 @@
         {
             cRadio radioButton = new cRadio(obj.name);
             
-            // Patch to avoid bug with transparency.
+            // June 2019. Patch to avoid bug with transparency.
             radioButton.hadMaterial = obj.material != null;
             if (!radioButton.hadMaterial)
             {
@@ -985,6 +1013,7 @@
         cCheckBox slowCB;
         cCheckBox boxCB;
         cCheckBox zoomBoxCB;
+        cCheckBox freezeCB;
         //cToggleButton trackCB;
         cCheckBox trackCB;
         cCheckBox smoothfocusCB;
@@ -1103,6 +1132,10 @@
             {
                 Globals.COMPUTESHADOWWHENLIVE ^= true;
             }
+            else if(e.getSource() == freezeCB)
+            {
+                Globals.FREEZEONMOVE ^= true;
+            }
             else if(e.getSource() == autosaveCB)
             {
                 Globals.SAVEONMAKE ^= true;
@@ -1187,8 +1220,6 @@
                         }
                     }
                     
-                    String string = (String) object;
-                    
                     System.out.println("Transfer = " + object + "; drop : " + target);
 //                    if( object instanceof java.io.File[])
 //                    {
@@ -1196,6 +1227,8 @@
 //                        objEditor.DropFile((java.io.File[]) object, true);
 //                        return;
 //                    }
+                    
+                    String string = object.toString();
                     
                     // File path for Mac and Windows
                     if (string.charAt(0) == '/' || string.charAt(1) == ':')
@@ -1445,6 +1478,9 @@
 		animationItem.addItemListener(this);
                 animationItem.setState(Globals.ANIMATION);
                 
+		menu.add(archiveItem = new MenuItem("Archive3D..."));
+		archiveItem.addActionListener(this);
+                
 		menu.add("-");
 		parseverticesItem = menu.add(new MenuItem("Multiplicity"));
 		parseverticesItem.addActionListener(this);
@@ -1457,6 +1493,8 @@
 		reduce34MorphItem = menu.add(new MenuItem("Reduce Morphs (34)"));
 		reduce34MorphItem.addActionListener(this);
 		menu.add("-");
+		menu.add(memoryItem = new MenuItem("Memory Usage"));
+		memoryItem.addActionListener(this);
 		menu.add(computeAOItem = new MenuItem("Compute AO"));
 		computeAOItem.addActionListener(this);
                 
@@ -1465,8 +1503,6 @@
 		mirrorItem = menu.add(new MenuItem("Mirror Poses"));
 		mirrorItem.addActionListener(this);
 		menu.add("-");
-		menu.add(memoryItem = new MenuItem("Memory Usage"));
-		memoryItem.addActionListener(this);
 		menu.add(analyzeItem = new MenuItem("Analyze"));
 		analyzeItem.addActionListener(this);
 		menu.add(dumpItem = new MenuItem("Print"));
@@ -1614,6 +1650,20 @@
             
             makeSomething(shadow);
         }
+
+    private void ClearUnpinned()
+    {
+        //for (Object3D obj : listUI)
+        for (int i=listUI.size(); --i>=0;)
+        {
+            Object3D obj = listUI.elementAt(i);
+            if (!obj.pinned)
+            {
+                obj.CloseUI();
+                listUI.remove(i);
+            }
+        }
+    }
         
     /**
      * applyExample
@@ -2093,25 +2143,25 @@
                         Composite csg = new GroupLeaf();
                         csg.count = 5;
 			group(csg);
-                        Composite child = new cGroup();
+                        Composite child = new cGroup("Branch");
                         csg.addChild(child);
                         child.addChild(csg);
 		} else
 		if (source == doubleItem)
 		{
-                        Composite csg = new GroupLeaf();
+                        Composite csg = new GroupLeaf("Fork");
                         csg.count = 5;
 			group(csg);
-                        Composite child = new cGroup();
+                        Composite child = new cGroup("Branch A");
                         csg.addChild(child);
                         child.addChild(csg);
-                        child = new cGroup();
+                        child = new cGroup("Branch B");
                         csg.addChild(child);
                         child.addChild(csg);
 		} else
 		if (source == tripleItem)
 		{
-                        Composite csg = new GroupLeaf();
+                        Composite csg = new GroupLeaf("Trident");
                         csg.count = 4;
 			group(csg);
                         Composite child = new cGroup();
@@ -2175,7 +2225,8 @@
 		} else
 		if (source == undoButton)
 		{
-			Undo();
+			if (!Undo())
+                            java.awt.Toolkit.getDefaultToolkit().beep();
 		} else
 		if (source == redoButton)
 		{
@@ -2183,7 +2234,8 @@
 		} else
 		if (source == saveButton)
 		{
-			Save();
+			if (!Save(true))
+                            java.awt.Toolkit.getDefaultToolkit().beep();
 		} else
 		if (source == oneStepButton)
 		{
@@ -2192,17 +2244,14 @@
 		} else
 		if (source == screenfitButton)
 		{
-			//Reload(lastConverter, lastFilename, true);
                     ScreenFit();
 		} else
 		if (source == screenfitpointButton)
 		{
-			//Reload(lastConverter, lastFilename, true);
                     ScreenFitPoint();
 		} else
 		if (source == snapobjectButton)
 		{
-			//Reload(lastConverter, lastFilename, true);
                     SnapObject();
 		} else
 //		if (event.getSource() == recompileButton)
@@ -2726,15 +2775,28 @@
 		} else
 		if (source == ungroupItem || source == ungroupButton)
 		{
-			//ungroup();
+                    boolean hasRoot = false;
+                    
                     for (int i=0; i<group.selection.size(); i++)
                     {
-                        Ungroup(group.selection.get(i));
+                        if (group.selection.get(i) == group)
+                        {
+                            hasRoot = true;
+                            break;
+                        }
                     }
 
-                    ClearSelection(false);
-                    
-                    refreshContents();
+                    if (!hasRoot)
+                    {
+                        for (int i=0; i<group.selection.size(); i++)
+                        {
+                            Ungroup(group.selection.get(i));
+                        }
+
+                        ClearSelection(false);
+
+                        refreshContents();
+                    }
 		} else
 		if (source == genUVItem)
                 {
@@ -3326,6 +3388,12 @@
 		} else
 		if (source == editItem || source == editButton)
 		{
+			for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
+			{
+				Object3D child = (Object3D)e.nextElement();
+                                child.pinned = true;
+                        }
+                        
 			EditSelection(false);
 		} else
 		if (source == uneditButton)
@@ -3335,6 +3403,7 @@
 				Object3D child = (Object3D)e.nextElement();
                                 if(child.editWindow != null)
                                     objectPanel.setSelectedIndex(objectPanel.indexOfTab("Edit"));
+                                child.pinned = false;
 				child.CloseUI();
                                 listUI.remove(child);
                                 
@@ -3351,6 +3420,7 @@
                     //copy.ClearUI();
                     for (Object3D obj : listUI)
                     {
+                        obj.pinned = false;
                         obj.CloseUI();
                     }
                     listUI.clear();
@@ -3360,7 +3430,7 @@
 		{
                     assert(copy == group);
                     
-                    objectPanel.setSelectedIndex(objectPanel.indexOfTab("Edit"));
+                    //objectPanel.setSelectedIndex(objectPanel.indexOfTab("Edit"));
                     
                     for (Object3D obj : listUI)
                     {
@@ -3435,6 +3505,11 @@
                         currentLayout = sevenButton;
                      */
                     radio.layout.doClick();
+                    
+                    ClearUnpinned();
+                    SetPinStates(group.selection.size() > 0);
+                    if (group.selection.size() == 1)
+                        EditSelection(false);
                     keepparent = group.parent;
                     // PARENT = NULL or not???
                     //group.parent = null; // ROOT
@@ -4502,10 +4577,6 @@
 //		}
 //	}
 	
-        static boolean allparams = true;
-        
-        static Vector<Object3D> listUI = new Vector<Object3D>();
-        
 	void EditSelection(boolean newWindow)
 	{
         //    aConstraints.gridy = 0;
@@ -4598,7 +4669,8 @@
 		//new Exception().printStackTrace();
 
 		freezemodel = true;
-		
+        ClearUnpinned();
+                    
 		/**/
 		//switch (event.id)
 		{
@@ -4631,7 +4703,7 @@
 			if (tps != null && tps.length > 0 && tps[0].getLastPathComponent() instanceof Camera)
                             // a camera
                         {
-                            if (tps[0].getLastPathComponent() != Globals.theRenderer.LightCamera())
+                            if (tps[0].getLastPathComponent() != Globals.theRenderer.LightCamera()) // Crash the camera because of invalid lightspace
                             {
                                 CameraPane.camerachangeframe = 0; // don't refuse it
                                 Globals.theRenderer.SetCamera((Camera) tps[0].getLastPathComponent());
@@ -4640,6 +4712,13 @@
                          //   Globals.theRenderer.eyeCamera = Globals.theRenderer.manipCamera;
                         }
                             
+                        if (tps != null && tps.length == 1)
+                        {
+                            EditSelection(false);
+                        }
+                        
+                        SetPinStates(tps != null && tps.length > 0);
+                        
 			refreshContents();
 			//return true;
 		}
@@ -4649,10 +4728,18 @@
 		freezemodel = false;
 	}
         
+        void SetPinStates(boolean enabled)
+        {
+            editButton.setEnabled(enabled);
+            uneditButton.setEnabled(enabled);
+            unselectButton.setEnabled(enabled);
+            flashSelectionButton.setEnabled(enabled);
+        }
+
         void refreshContents(boolean cp)
         {
             if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Info"))
-            if (!Globals.MOUSEDRAGGED) // && !Globals.TIMERRUNNING)
+            if (!Globals.MOUSEDRAGGED && group.selection != null) // && !Globals.TIMERRUNNING)
             {
                 objEditor.ClearInfo(); // .GetMaterial());
 
@@ -4751,8 +4838,8 @@
                 
 		if (cut)
 		{
-        if (Globals.SAVEONMAKE)
-                    Save();
+//        if (Globals.SAVEONMAKE) // Moved to the clipboard, no need to save.
+//                    Save();
 			//int indices[] = jList.getSelectedIndices();
 			//for (int i = indices.length - 1; i >= 0; i--)
 			//jList.remove(indices[i]);
@@ -4855,6 +4942,10 @@
 	
 	void paste(boolean expand)
 	{
+        if (Globals.SAVEONMAKE)
+            Save();
+        boolean keep = Globals.SAVEONMAKE;
+        Globals.SAVEONMAKE = false;
 	//	if (GrafreeD.clipboard == null)
 	//		return;
 		boolean first = true;
@@ -4914,6 +5005,7 @@
                         Grafreed.clipboard.get(0).parent = keepparent;
 		}
 		
+        Globals.SAVEONMAKE = keep;
 		ResetModel();
 		refreshContents();
 	}
@@ -5049,6 +5141,10 @@
         
 	void group(Object3D csg, boolean grab)
 	{
+        if (Globals.SAVEONMAKE)
+            Save();
+        boolean keep = Globals.SAVEONMAKE;
+        Globals.SAVEONMAKE = false;
 		if (//false) // why??
                     !group.selection.isEmpty())
                 {
@@ -5162,10 +5258,15 @@
                 //node.add(csg);
 		//makeSomething(node);
 		makeSomething(csg);
+        Globals.SAVEONMAKE = keep;
 	}
 	
         void Ungroup(Object3D g)
         {
+        if (Globals.SAVEONMAKE)
+            Save();
+        boolean keep = Globals.SAVEONMAKE;
+        Globals.SAVEONMAKE = false;
             if (g instanceof HiddenObject)
             {
                 HiddenObject h = (HiddenObject) g;
@@ -5182,6 +5283,7 @@
                     objEditor.makeSomething(g.get(i), false);
                 }
             }
+        Globals.SAVEONMAKE = keep;
         }
         
 	void ungroup()
@@ -5472,11 +5574,6 @@
 	
 	cButton restoreCameraButton;
         
-	cButton minButton;
-	cButton maxButton;
-	cButton fullButton;
-	cButton undoButton;
-	cButton redoButton;
 	cButton saveButton;
 	cButton oneStepButton;
         

--
Gitblit v1.6.2