From 07c0c67b88160b51e61c5c1d2b9b602daafa44a9 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sat, 17 Aug 2019 04:38:10 -0400
Subject: [PATCH] Fix UV#

---
 GroupEditor.java |  149 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 97 insertions(+), 52 deletions(-)

diff --git a/GroupEditor.java b/GroupEditor.java
index 9f3c422..09250cb 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);
         }
 	}
 
@@ -540,33 +542,35 @@
 //		menu.add("-");
 		duplicateItem = oe.jTree.popup.add(new JMenuItem("Duplicate"));
 		duplicateItem.addActionListener(this);
-		cloneItem = menu.add(new MenuItem("Clone"));
+                
+		cloneItem = oe.jTree.popup.add(new JMenuItem("Clone"));
 		cloneItem.addActionListener(this);
-        if (Globals.ADVANCED)
+        //if (Globals.ADVANCED)
         {
 		cloneSupportItem = menu.add(new MenuItem("Clone (+supports)"));
 		cloneSupportItem.addActionListener(this);
         }
+                oe.jTree.popup.addSeparator();
 		menu.add("-");
-		cutItem = menu.add(new MenuItem("Cut"));
+		cutItem = oe.jTree.popup.add(new JMenuItem("Cut"));
 		cutItem.addActionListener(this);
-		copyItem = menu.add(new MenuItem("Copy"));
+		copyItem = oe.jTree.popup.add(new JMenuItem("Copy"));
 		copyItem.addActionListener(this);
 		pasteItem = menu.add(new MenuItem("Paste"));
 		pasteItem.addActionListener(this);
                 
-		menu.add("-");
-		pasteIntoItem = menu.add(new MenuItem("Paste into"));
+                oe.jTree.popup.addSeparator();
+		//menu.add("-");
+		pasteIntoItem = oe.jTree.popup.add(new JMenuItem("Paste into"));
 		pasteIntoItem.addActionListener(this);
-		pasteLinkItem = menu.add(new MenuItem("Paste link"));
+		pasteLinkItem = oe.jTree.popup.add(new JMenuItem("Paste link"));
 		pasteLinkItem.addActionListener(this);
-		pasteCloneItem = menu.add(new MenuItem("Paste clone"));
+		pasteCloneItem = oe.jTree.popup.add(new JMenuItem("Paste clone"));
 		pasteCloneItem.addActionListener(this);
-//		pasteExpandItem = menu.add(new MenuItem("Paste expand"));
+// CRASH	pasteExpandItem = oe.jTree.popup.add(new JMenuItem("Paste expand"));
 //		pasteExpandItem.addActionListener(this);
-		menu.add("-");
-		deleteItem = menu.add(new MenuItem("Delete"));
-		deleteItem.addActionListener(this);
+		//menu.add("-");
+                oe.jTree.popup.addSeparator();
                 
         if (Globals.ADVANCED)
         {
@@ -701,9 +705,8 @@
 		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"));
@@ -711,13 +714,21 @@
 //		compositeItem = menu.add(new MenuItem("Composite"));
 //		compositeItem.addActionListener(this);
                 
+		grabItem = oe.jTree.popup.add(new JMenuItem("Group"));
+		grabItem.addActionListener(this);
+                
         if (Globals.ADVANCED)
         {
 		hideItem = menu.add(new MenuItem("Hidden Group"));
 		hideItem.addActionListener(this);
         }
-		ungroupItem = menu.add(new MenuItem("Ungroup"));
+		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("-");
 //                
@@ -923,7 +934,7 @@
 	
         JTabbedPane resourcecontainer;
         cGridBag currenttab;
-        boolean added; // patch for jar
+        //boolean added; // patch for jar
                 
         int tabcount = 0;
         int colcount = 0;
@@ -940,12 +951,14 @@
 //        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;
@@ -953,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);
@@ -1059,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/empty.png", !Grafreed.NIMBUSLAF)); //, oe.aConstraints);
                 maximize3DButton.setToolTipText("Maximize 3D view");
 		maximize3DButton.addActionListener(this);
                 
@@ -1101,6 +1113,7 @@
 		copyOptionsPanel.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);
                 previousVersionButton.setToolTipText("Previous version");
@@ -1111,12 +1124,12 @@
 		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);
                 
@@ -1181,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);
@@ -1192,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)
                 {
@@ -1245,6 +1258,8 @@
                 cGridBag textures = new cGridBag();
                 
                 CreateTexturePanel(textures);
+                
+                resourcecontainer.setSelectedIndex((int)(Math.random() * resourcecontainer.getTabCount()));
                 
                 oe.toolboxPanel.add(textures);
                 
@@ -1498,6 +1513,7 @@
                     
             oe.SetupViews();
             
+        if (Globals.DEBUG)
 		System.out.println("SetupViews");
             DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer(
                   oe.cameraView, DnDConstants.ACTION_COPY_OR_MOVE, this); // ACTION_LINK ??
@@ -2159,7 +2175,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);
         }
@@ -2680,27 +2700,35 @@
 		} else
 		if (source == loopItem || source == loopButton)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf();
                         csg.count = 5;
-			group(csg);
                         Composite child = new cGroup("Branch");
                         csg.addChild(child);
                         child.addChild(csg);
+			group(csg);
+                    }
 		} else
 		if (source == doubleItem)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf("Fork");
                         csg.count = 5;
-			group(csg);
                         Composite child = new cGroup("Branch A");
                         csg.addChild(child);
                         child.addChild(csg);
                         child = new cGroup("Branch B");
                         csg.addChild(child);
                         child.addChild(csg);
+			group(csg);
+                    }
 		} else
 		if (source == tripleItem)
 		{
+                    if (!group.selection.isEmpty())
+                    {
                         Composite csg = new GroupLeaf("Trident");
                         csg.count = 4;
 			group(csg);
@@ -2713,6 +2741,7 @@
                         child = new cGroup();
                         csg.addChild(child);
                         child.addChild(csg);
+                    }
 		} else
 		if (source == computeAOItem)
 		{
@@ -3348,22 +3377,34 @@
 		} else
 		if (source == ungroupItem || source == ungroupButton)
 		{
-                    boolean hasRoot = false;
+                    boolean canUngroup = true;
                     
                     for (int i=0; i<group.selection.size(); i++)
                     {
-                        if (group.selection.get(i) == group)
+                        Object3D selectedItem = group.selection.get(i);
+                        
+                        if (selectedItem.Size() == 0)
                         {
-                            hasRoot = true;
+                            // Cannot ungroup leaves
+                            canUngroup = false;
+                            break;
+                        }
+                                
+                        if (selectedItem == group)
+                        {
+                            // Cannot ungroup root
+                            canUngroup = false;
                             break;
                         }
                     }
 
-                    if (!hasRoot)
+                    if (canUngroup)
                     {
                         for (int i=0; i<group.selection.size(); i++)
                         {
-                            Ungroup(group.selection.get(i));
+                            Object3D selectedItem = group.selection.get(i);
+                            
+                            Ungroup(selectedItem);
                         }
 
                         ClearSelection(false);
@@ -4083,7 +4124,10 @@
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
             
-            Save(true);
+            // Cannot work with loops
+            // To fix this issue, first mark all nodes above the root,
+            // and check if any of these nodes are reachable below the root.
+            //Save(true);
         }
         
                     SetVersionStates();
@@ -5328,7 +5372,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;
@@ -6233,11 +6278,11 @@
 	private MenuItem lookAtItem;
 	private MenuItem lookFromItem;
 	private MenuItem switchViewItem;
-	private MenuItem cutItem;
+	private JMenuItem cutItem;
 	private MenuItem undoItem;
 	private MenuItem redoItem;
 	private JMenuItem duplicateItem;
-	private MenuItem cloneItem;
+	private JMenuItem cloneItem;
 	private MenuItem cloneSupportItem;
 	private MenuItem overwriteGeoItem;
 	private MenuItem overwriteMatItem;
@@ -6258,13 +6303,13 @@
 	private MenuItem cloneGeometriesItem;
 	private MenuItem shareGeometriesItem;
 	private MenuItem mergeGeometriesItem;
-	private MenuItem copyItem;
+	private JMenuItem copyItem;
 	private MenuItem pasteItem;
-	private MenuItem pasteIntoItem;
-	private MenuItem pasteLinkItem;
-	private MenuItem pasteCloneItem;
-	private MenuItem pasteExpandItem;
-	private MenuItem deleteItem;
+	private JMenuItem pasteIntoItem;
+	private JMenuItem pasteLinkItem;
+	private JMenuItem pasteCloneItem;
+	private JMenuItem pasteExpandItem;
+	private JMenuItem deleteItem;
 	private MenuItem clearAllItem;
 	private MenuItem genUVItem;
 	private MenuItem genNormalsMESHItem;
@@ -6319,7 +6364,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;
@@ -6332,7 +6377,7 @@
 	private MenuItem switchTransfoItem;
 	private MenuItem morphItem;
 	private MenuItem linkerItem;
-	private MenuItem ungroupItem;
+	private JMenuItem ungroupItem;
 	private MenuItem editItem;
 	private MenuItem openWindowItem;
 	private MenuItem editLeafItem;

--
Gitblit v1.6.2