From d5d6485126da83b06645e90e3e4ce66659a56009 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sat, 17 Aug 2019 13:56:24 -0400
Subject: [PATCH] Reset transform, fix loop versioning.

---
 GroupEditor.java |  122 +++++++++++++++++++++++++---------------
 1 files changed, 76 insertions(+), 46 deletions(-)

diff --git a/GroupEditor.java b/GroupEditor.java
index b32dee9..b37d3ac 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -415,12 +415,14 @@
 		this.copy = this.group = group;
 		//selectees = this.group.selectees;
 		
+                assert(false);
+                
         if (copy.versionlist == null)
         {
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
             
-            Save(true);
+            //Save(true);
         }
         
 		if(ui)
@@ -449,7 +451,7 @@
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
             
-            Save(true);
+            //Save(true);
         }
 	}
 
@@ -569,9 +571,6 @@
 //		pasteExpandItem.addActionListener(this);
 		//menu.add("-");
                 oe.jTree.popup.addSeparator();
-                
-		deleteItem = oe.jTree.popup.add(new JMenuItem("Delete"));
-		deleteItem.addActionListener(this);
                 
         if (Globals.ADVANCED)
         {
@@ -706,15 +705,17 @@
 		setMasterItem.addActionListener(this);
         }
                 
-		oe.menuBar.add(menu = new Menu("Group"));
-//		grabItem = menu.add(new MenuItem("Grab"));
-//		grabItem.addActionListener(this);
+		oe.menuBar.add(menu = new Menu("Order"));
+                
 		backItem = menu.add(new MenuItem("Back"));
 		backItem.addActionListener(this);
 		frontItem = menu.add(new MenuItem("Front"));
 		frontItem.addActionListener(this);
 //		compositeItem = menu.add(new MenuItem("Composite"));
 //		compositeItem.addActionListener(this);
+                
+		grabItem = oe.jTree.popup.add(new JMenuItem("Group"));
+		grabItem.addActionListener(this);
                 
         if (Globals.ADVANCED)
         {
@@ -723,6 +724,11 @@
         }
 		ungroupItem = oe.jTree.popup.add(new JMenuItem("Ungroup"));
 		ungroupItem.addActionListener(this);
+                
+                oe.jTree.popup.addSeparator();
+                
+		deleteItem = oe.jTree.popup.add(new JMenuItem("Delete"));
+		deleteItem.addActionListener(this);
                 
 //		menu.add("-");
 //                
@@ -928,7 +934,7 @@
 	
         JTabbedPane resourcecontainer;
         cGridBag currenttab;
-        boolean added; // patch for jar
+        //boolean added; // patch for jar
                 
         int tabcount = 0;
         int colcount = 0;
@@ -940,17 +946,19 @@
         
     public void ResourceCallBack(String[] path)
     {
-        for (int i = 0; i < path.length; i++)
-            System.out.print(path[i] + "/");
-        System.out.println();
+//        for (int i = 0; i < path.length; i++)
+//            System.out.print(path[i] + "/");
+//        System.out.println();
         
         if (//rowcount == 0 ||
-                path.length == 1)
+                path.length == 1 && !path[0].equals("") && !path[0].equals(".DS_Store"))
         {
             currenttab = new cGridBag();
-            added = false;
             String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
             currenttab.setName(tabname);
+            //added = false;
+            resourcecontainer.add(currenttab);
+            resourcecontainer.setToolTipTextAt(tabcount++, "Texture Group " + tabname);
             rowcount = 1;
             colcount = 0;
             texturecount = 0;
@@ -958,12 +966,11 @@
         
         if (path.length > 2 && path[2].toLowerCase().endsWith(".jpg"))
         {
-            if (!added)
+            //if (!added)
             {
-                added = true;
-                resourcecontainer.add(currenttab);
+                //added = true;
                 String tabname = path[0]; // String.valueOf((char)('A'+tabcount));
-                resourcecontainer.setToolTipTextAt(tabcount++, "Texture Group " + tabname);
+                currenttab = (cGridBag)resourcecontainer.getComponentAt(resourcecontainer.indexOfTab(tabname));
             }
             
             AddTextureButton(path[0], path[1], path[2], texturecount++, currenttab);
@@ -1031,9 +1038,9 @@
         oe.radioPanel.add(dummyButton);
         oe.buttonGroup.add(dummyButton);
          */
-                cGridBag copyOptionsPanel = new cGridBag();
+                cGridBag versionManagerPanel = new cGridBag();
                                         
-                copyOptionsPanel.preferredHeight = 2;
+                versionManagerPanel.preferredHeight = 4;
                 
                 //this.AddOptions(oe.toolbarPanel, oe.aConstraints);
                 
@@ -1064,7 +1071,7 @@
                 collapseButton.setToolTipText("Collapse toolbar");
 		collapseButton.addActionListener(this);
                 
-		oe.toolbarPanel.add(maximize3DButton = GetButton("", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		oe.toolbarPanel.add(maximize3DButton = GetButton("icons/square.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 maximize3DButton.setToolTipText("Maximize 3D view");
 		maximize3DButton.addActionListener(this);
                 
@@ -1099,15 +1106,16 @@
                 restoreCameraButton.setToolTipText("Restore viewpoint");
 		restoreCameraButton.addActionListener(this);
                 
-		copyOptionsPanel.add(saveVersionButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		versionManagerPanel.add(saveVersionButton = GetButton("icons/down_arrow.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 saveVersionButton.setToolTipText("Duplicate current version");
 		saveVersionButton.addActionListener(this);
                                                 
-		copyOptionsPanel.add(deleteVersionButton = GetButton("icons/trash.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		versionManagerPanel.add(deleteVersionButton = GetButton("icons/trash.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 deleteVersionButton.setToolTipText("Delete current version");
 		deleteVersionButton.addActionListener(this);
+                deleteVersionButton.setEnabled(false);
                                                 
-		copyOptionsPanel.add(previousVersionButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		versionManagerPanel.add(previousVersionButton = GetButton("icons/undo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 previousVersionButton.setToolTipText("Previous version");
 		previousVersionButton.addActionListener(this);
                 previousVersionButton.setEnabled(false);
@@ -1116,16 +1124,16 @@
 		updown.add(restoreButton = GetButton("icons/restore.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 restoreButton.setToolTipText("Undo (restore current version)");
 		restoreButton.addActionListener(this);
-                //restoreButton.setEnabled(false);
+                restoreButton.setEnabled(false);
                 
 		updown.add(replaceButton = GetButton("icons/replace.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 replaceButton.setToolTipText("Save (replace current version)");
 		replaceButton.addActionListener(this);
-                //replaceButton.setEnabled(false);
+                replaceButton.setEnabled(false);
                 
-                copyOptionsPanel.add(updown);
+                versionManagerPanel.add(updown);
                 
-		copyOptionsPanel.add(nextVersionButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+		versionManagerPanel.add(nextVersionButton = GetButton("icons/redo.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 nextVersionButton.setToolTipText("Next version");
 		nextVersionButton.addActionListener(this);
                 nextVersionButton.setEnabled(false);
@@ -1186,6 +1194,10 @@
                 boxButton.setToolTipText("Create box");
                                 boxButton.addActionListener(this);
 
+                row1.add(superButton = GetButton("icons/super.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
+                superButton.setToolTipText("Create superellipsoid");
+                                superButton.addActionListener(this);
+
                 row1.add(sphereButton = GetButton("icons/sphere.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 sphereButton.setToolTipText("Create sphere");
                                 sphereButton.addActionListener(this);
@@ -1197,10 +1209,6 @@
                 row1.add(torusButton = GetButton("icons/torus.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 torusButton.setToolTipText("Create torus");
                                 torusButton.addActionListener(this);
-
-                row1.add(superButton = GetButton("icons/super.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
-                superButton.setToolTipText("Create superellipsoid");
-                                superButton.addActionListener(this);
 
                 if (Globals.ADVANCED)
                 {
@@ -1250,6 +1258,8 @@
                 cGridBag textures = new cGridBag();
                 
                 CreateTexturePanel(textures);
+                
+                resourcecontainer.setSelectedIndex((int)(Math.random() * resourcecontainer.getTabCount()));
                 
                 oe.toolboxPanel.add(textures);
                 
@@ -1301,6 +1311,8 @@
                 
                 cGridBag jSPPanel = new cGridBag();
 
+            jSPPanel.preferredHeight = 20;
+            
                 JScrollPane jSP;
 		//ctrlPanel.add(new JScrollPane(jTree = new cTree(new cTreeModel(this))), aConstraints);
 		jSPPanel.add(jSP = new JScrollPane(oe.jTree)); //, oe.aConstraints);
@@ -1309,11 +1321,11 @@
                 oe.treePanel.add(jSPPanel);
                 oe.treePanel.Return();
 
-                oe.treePanel.add(copyOptionsPanel);
+                oe.treePanel.add(versionManagerPanel);
                 oe.treePanel.Return();
-        cGridBag sliderPane = AddSlider(oe.treePanel, "Version", 0, 0, 0);
-            versionSlider = (cNumberSlider)sliderPane.getComponent(1);
-            sliderPane.preferredHeight = 1;
+        versionSliderPane = AddSlider(oe.treePanel, "Version", 0, 0, 0);
+            versionSlider = (cNumberSlider)versionSliderPane.getComponent(1);
+            versionSliderPane.preferredHeight = 3;
                 
 //        mainPanel.setDividerLocation(0.1); //1.0);
         mainPanel.setResizeWeight(0.4);
@@ -1503,6 +1515,7 @@
                     
             oe.SetupViews();
             
+        if (Globals.DEBUG)
 		System.out.println("SetupViews");
             DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
                   oe.cameraView, DnDConstants.ACTION_COPY_OR_MOVE, this); // ACTION_LINK ??
@@ -2164,7 +2177,11 @@
             shadow.material = new cMaterial(obj.material);
             shadow.material.diffuse = 0.0001f;
             shadow.material.specular = 0.0001f;
-            //shadow.projectedVertices[1].x = 300;
+            shadow.material.opacity = 0.75f;
+            
+            AllocProjectedVertices(shadow);
+        
+            shadow.projectedVertices[1].x = 300;
             
             makeSomething(shadow);
         }
@@ -3953,6 +3970,8 @@
 		if (source == closeButton)
 		{
 //System.out.println("CLOSE: " + buttonGroup.getSelection());
+                    Replace();
+                    
                     cRadio ab;
                     for (Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
                     {
@@ -4051,6 +4070,8 @@
 		} else
                 if(source instanceof cRadio)
 		{
+                    Replace();
+                    
                     group.parent = keepparent;
                         group.attributes = 0;
                     //group.editWindow = null;
@@ -4106,10 +4127,21 @@
                     
         if (copy.versionlist == null)
         {
-            copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
             
-            Save(true);
+            // Cannot work with loops
+            // To fix this issue, we first mark all nodes above the root,
+            // and check if any of these nodes are reachable below the root.
+            Grafreed.grafreed.universe.TagObjects(copy, true);
+            
+            if (!copy.HasTags())
+            {
+                copy.versionlist = new Object3D[100];
+                
+                Save(true);
+            }
+            
+            Grafreed.grafreed.universe.TagObjects(copy, false);
         }
         
                     SetVersionStates();
@@ -4257,7 +4289,7 @@
                         TouchTransform(obj);
                         continue;
                     }
-                    if ((mask&2) != 0) // Scale
+                    if ((mask&2) != 0) // Scale/rotation
                     {
                         obj.toParent[0][0] = obj.toParent[1][1] = obj.toParent[2][2] = 1;
                         obj.toParent[0][1] = obj.toParent[1][0] = obj.toParent[2][0] = 0;
@@ -4265,10 +4297,6 @@
                         obj.fromParent[0][0] = obj.fromParent[1][1] = obj.fromParent[2][2] = 1;
                         obj.fromParent[0][1] = obj.fromParent[1][0] = obj.fromParent[2][0] = 0;
                         obj.fromParent[0][2] = obj.fromParent[1][2] = obj.fromParent[2][1] = 0;
-                    }
-                    if ((mask&4) != 0) // Rotation
-                    {
-                        // ?
                     }
                     if ((mask&1) != 0) // Translation
                     {
@@ -5354,7 +5382,8 @@
             if (group.selection != null)
             for (Enumeration e = group.selection.elements(); e.hasMoreElements();)
             {
-                    if (!(e.nextElement() instanceof Composite))
+                    Object next = e.nextElement();
+                    if (!(next instanceof Composite)) // || (next instanceof GroupLeaf))
                     {
                         allComposites = false;
                         break;
@@ -5366,6 +5395,7 @@
 
         void refreshContents(boolean cp)
         {
+            if (false)
             //if (objectPanel.getSelectedIndex() == 2) // objectPanel.indexOfTab("Info"))
             if (!Globals.MOUSEDRAGGED && group.selection != null) // && !Globals.TIMERRUNNING)
             {
@@ -6345,7 +6375,7 @@
 	private MenuItem transformGeometryItem;
 	private MenuItem transformChildrenItem;
 	private MenuItem hideItem;
-	private MenuItem grabItem;
+	private JMenuItem grabItem;
 	private MenuItem backItem;
 	private MenuItem frontItem;
 	private MenuItem cameraItem;

--
Gitblit v1.6.2