From 15123b19e7bc8da2869429b07f0fbaa0598e945e Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 20 Jun 2019 20:56:08 -0400
Subject: [PATCH] Rewind all.

---
 ObjEditor.java |  228 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 178 insertions(+), 50 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 05b548c..877fe87 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -168,6 +168,7 @@
 //        objEditor.ctrlPanel.remove(remarkButton);
         
         objEditor.ctrlPanel.remove(setupPanel);
+        objEditor.ctrlPanel.remove(setupPanel2);
         objEditor.ctrlPanel.remove(commandsPanel);
         objEditor.ctrlPanel.remove(pushPanel);
         //objEditor.ctrlPanel.remove(fillPanel);
@@ -278,7 +279,7 @@
         frame.setMenuBar(menuBar = new MenuBar());
         menuBar.add(fileMenu = new Menu("File"));
         fileMenu.add(newItem = new MenuItem("New"));
-        fileMenu.add(loadItem = new MenuItem("Load..."));
+        fileMenu.add(loadItem = new MenuItem("Open..."));
         
                 //oe.menuBar.add(menu = new Menu("Include"));
         Menu menu = new Menu("Import");
@@ -419,10 +420,10 @@
             e.printStackTrace();
         }
         
-        String selection = infoarea.getText();
-        java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
-        java.awt.datatransfer.Clipboard clipboard = 
-                Toolkit.getDefaultToolkit().getSystemClipboard();
+//        String selection = infoarea.getText();
+//        java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
+//        java.awt.datatransfer.Clipboard clipboard = 
+//                Toolkit.getDefaultToolkit().getSystemClipboard();
         //clipboard.setContents(data, data);
     }
     
@@ -747,6 +748,7 @@
     
     cGridBag namePanel;
     cGridBag setupPanel;
+    cGridBag setupPanel2;
     cGridBag commandsPanel;
     cGridBag pushPanel;
     cGridBag fillPanel;
@@ -939,21 +941,25 @@
         markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
         markCB.setToolTipText("Set the animation target transform");
         
-        rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
+            setupPanel2 = new cGridBag().setVertical(false);
+            
+        rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
         rewindCB.setToolTipText("Rewind animation");
         
-        randomCB = AddCheckBox(setupPanel, "Random", copy.random);
-        randomCB.setToolTipText("Option for switch node");
+        randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
+        randomCB.setToolTipText("Rewind or Go back and forth randomly");
 
         if (Globals.ADVANCED)
         {
-                link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
+                link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
                 link2masterCB.setToolTipText("Attach to support");
-                speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
+                speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
                 speedupCB.setToolTipText("Option motion capture");
         }
         
         oe.ctrlPanel.add(setupPanel);
+        oe.ctrlPanel.Return();
+        oe.ctrlPanel.add(setupPanel2);
         oe.ctrlPanel.Return();
         
             commandsPanel = new cGridBag().setVertical(false);
@@ -1935,6 +1941,7 @@
             e2.printStackTrace();
         }
     }
+    
     LoadJMEThread loadThread;
 
     class LoadJMEThread extends Thread
@@ -1992,6 +1999,7 @@
             //LoadFile0(filename, converter);
         }
     }
+    
     LoadOBJThread loadObjThread;
 
     class LoadOBJThread extends Thread
@@ -2070,19 +2078,19 @@
 
     void LoadObjFile(String fullname)
     {
-        /*
+        System.out.println("Loading " + fullname);
+        /**/
         //lastFilename = fullname;
         if(loadObjThread == null)
         {
-        loadObjThread = new LoadOBJThread();
-        loadObjThread.start();
+            loadObjThread = new LoadOBJThread();
+            loadObjThread.start();
         }
         
         loadObjThread.add(fullname);
-         */
+        /**/
 
-        System.out.println("Loading " + fullname);
-        makeSomething(new FileObject(fullname, true), true);
+        //makeSomething(new FileObject(fullname, true), true);
     }
 
     void LoadGFDFile(String fullname)
@@ -2925,7 +2933,7 @@
             return;
         } else if (event.getSource() == toggleSwitchItem)
         {
-            cameraView.ToggleRandom();
+            cameraView.ToggleSwitch();
             cameraView.repaint();
             return;
         } else if (event.getSource() == toggleHandleItem)
@@ -3212,23 +3220,45 @@
         objEditor.refreshContents();
     }
     
-    Object3D graphs[] = new Object3D[10000];
-    int undoindex = 0;
-    
-    static public Object clone(Object o)
+    static public byte[] Compress(Object3D o)
     {
         try
         {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream out = new ObjectOutputStream(baos);
+            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
+            ObjectOutputStream out = new ObjectOutputStream(zstream);
 
+        Object3D parent = o.parent;
+        o.parent = null;
+        
             out.writeObject(o);
+            
+        o.parent = parent;
+        
+            out.flush();
 
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            ObjectInputStream in = new ObjectInputStream(bais);
+            zstream.close();
+            out.close();
+            
+            return baos.toByteArray();
+        } catch (Exception e)
+        {
+            System.err.println(e);
+            return null;
+        }
+    }
+
+    static public Object Uncompress(byte[] bytes)
+    {
+        System.out.println("#bytes = " + bytes.length);
+        try
+        {
+            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+            java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
+            ObjectInputStream in = new ObjectInputStream(istream);
             Object obj = in.readObject();
             in.close();
-            out.close();
+            
             return obj;
         } catch (Exception e)
         {
@@ -3237,16 +3267,73 @@
         }
     }
 
+    static public Object clone(Object o)
+    {
+        try
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream out = new ObjectOutputStream(baos);
+
+            out.writeObject(o);
+            
+            out.flush();
+            out.close();
+            
+            byte[] bytes = baos.toByteArray();
+            
+            System.out.println("clone = " + bytes.length);
+
+            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+            ObjectInputStream in = new ObjectInputStream(bais);
+            Object obj = in.readObject();
+            in.close();
+            
+            return obj;
+        } catch (Exception e)
+        {
+            System.err.println(e);
+            return null;
+        }
+    }
+
+    cRadio GetCurrentTab()
+    {
+        cRadio ab;
+        for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
+        {
+            ab = (cRadio)e.nextElement();
+            if(ab.GetObject() == copy)
+            {
+                return ab;
+            }
+        }
+        
+        return null;
+    }
+    
+    java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
+    
     public void Save()
     {
-        if (true) return;
+        cRadio tab = GetCurrentTab();
+        
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
+        copy.ExtractBigData(hashtable);
         
         //EditorFrame.m_MainFrame.requestFocusInWindow();
-        graphs[undoindex++] = (Object3D)clone(copy);
+        tab.graphs[tab.undoindex++] = Compress(copy);
 
-        for (int i = undoindex; i < graphs.length; i++)
+        copy.RestoreBigData(hashtable);
+
+        CameraPane.SWITCH = temp;
+        
+        //assert(hashtable.isEmpty());
+        
+        for (int i = tab.undoindex; i < tab.graphs.length; i++)
         {
-            graphs[i] = null;
+            tab.graphs[i] = null;
         }
 
         // test save
@@ -3254,7 +3341,7 @@
         {
             try
             {
-                FileOutputStream ostream = new FileOutputStream("save" + undoindex);
+                FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
                 ObjectOutputStream p = new ObjectOutputStream(ostream);
 
                 p.writeObject(copy);
@@ -3269,48 +3356,81 @@
         }
     }
 
+    void CopyChanged(Object3D obj)
+    {
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
+        copy.ExtractBigData(hashtable);
+        
+        copy.clear();
+        
+        for (int i=0; i<obj.Size(); i++)
+        {
+            copy.add(obj.get(i));
+        }
+        
+        copy.RestoreBigData(hashtable);
+        
+        CameraPane.SWITCH = temp;
+        
+        //assert(hashtable.isEmpty());
+        
+        copy.Touch();
+        
+        ResetModel();
+        copy.HardTouch(); // recompile?
+        
+        cRadio ab;
+        for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
+        {
+            ab = (cRadio)e.nextElement();
+            Object3D test = copy.GetObject(ab.object.GetUUID());
+            //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
+            if (test != null)
+            {
+                test.editWindow = ab.object.editWindow;
+                ab.object = test;
+            }
+        }
+        
+        refreshContents();
+    }
+    
     public void Undo()
     {
-        if (undoindex == 0)
+        cRadio tab = GetCurrentTab();
+        
+        if (tab.undoindex == 0)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
         }
 
-        if (graphs[undoindex] == null)
+        if (tab.graphs[tab.undoindex] == null)
         {
             Save();
-            undoindex -= 1;
+            tab.undoindex -= 1;
         }
 
-        undoindex -= 1;
+        tab.undoindex -= 1;
 
-        copy = graphs[undoindex];
-        
-        cameraView.object = copy;
-        copy.Touch();
-        
-        ResetModel();
-        refreshContents();
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
     public void Redo()
     {
-        if (graphs[undoindex + 1] == null)
+        cRadio tab = GetCurrentTab();
+        
+        if (tab.graphs[tab.undoindex + 1] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
         }
 
-        undoindex += 1;
+        tab.undoindex += 1;
 
-        copy = graphs[undoindex];
-
-        cameraView.object = copy;
-        copy.Touch();
-        
-        ResetModel();
-        refreshContents();
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
         void ImportGFD()
@@ -4181,6 +4301,7 @@
 
         try
         {
+            // Try compressed version first.
             java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
             java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
             java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
@@ -4250,6 +4371,12 @@
 
     void LoadIt(Object obj)
     {
+        if (obj == null)
+        {
+            // Invalid file
+            return;
+        }
+        
         System.out.println("Loaded " + obj);
         //new Exception().printStackTrace();
         Object3D readobj = (Object3D) obj;
@@ -4259,6 +4386,7 @@
         
         if (readobj != null)
         {
+            Save();
             try
             {
                 //readobj.deepCopySelf(copy);

--
Gitblit v1.6.2