From 4113164b3be1e50251ac40d6fd65660f0a6c2e63 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 11 Jun 2019 18:46:21 -0400
Subject: [PATCH] Compressed undo stack.

---
 ObjEditor.java |   78 +++++++++++++++++++++++++++++++++++---
 1 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 422d126..13331f4 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -2927,7 +2927,7 @@
             return;
         } else if (event.getSource() == toggleSwitchItem)
         {
-            cameraView.ToggleRandom();
+            cameraView.ToggleSwitch();
             cameraView.repaint();
             return;
         } else if (event.getSource() == toggleHandleItem)
@@ -3214,6 +3214,48 @@
         objEditor.refreshContents();
     }
     
+    static public byte[] Compress(Object o)
+    {
+        try
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
+            ObjectOutputStream out = new ObjectOutputStream(zstream);
+
+            out.writeObject(o);
+            
+            out.flush();
+
+            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();
+            
+            return obj;
+        } catch (Exception e)
+        {
+            System.err.println(e);
+            return null;
+        }
+    }
+
     static public Object clone(Object o)
     {
         try
@@ -3222,12 +3264,19 @@
             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(baos.toByteArray());
+            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
             ObjectInputStream in = new ObjectInputStream(bais);
             Object obj = in.readObject();
             in.close();
-            out.close();
+            
             return obj;
         } catch (Exception e)
         {
@@ -3242,7 +3291,7 @@
         for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
         {
             ab = (cRadio)e.nextElement();
-            if(ab.GetObject() == client)
+            if(ab.GetObject() == copy)
             {
                 return ab;
             }
@@ -3251,13 +3300,21 @@
         return null;
     }
     
+    java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
+    
     public void Save()
     {
         cRadio tab = GetCurrentTab();
         
+        copy.ExtractBigData(hashtable);
+        
         //EditorFrame.m_MainFrame.requestFocusInWindow();
-        tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
+        tab.graphs[tab.undoindex++] = Compress(copy);
 
+        copy.RestoreBigData(hashtable);
+        
+        //assert(hashtable.isEmpty());
+        
         for (int i = tab.undoindex; i < tab.graphs.length; i++)
         {
             tab.graphs[i] = null;
@@ -3285,12 +3342,18 @@
 
     void CopyChanged(Object3D obj)
     {
+        copy.ExtractBigData(hashtable);
+        
         copy.clear();
         
         for (int i=0; i<obj.Size(); i++)
         {
             copy.add(obj.get(i));
         }
+        
+        copy.RestoreBigData(hashtable);
+        
+        //assert(hashtable.isEmpty());
         
         copy.Touch();
         
@@ -3331,7 +3394,7 @@
 
         tab.undoindex -= 1;
 
-        CopyChanged(tab.graphs[tab.undoindex]);
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
     public void Redo()
@@ -3346,7 +3409,7 @@
 
         tab.undoindex += 1;
 
-        CopyChanged(tab.graphs[tab.undoindex]);
+        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
     }
 
         void ImportGFD()
@@ -4295,6 +4358,7 @@
         
         if (readobj != null)
         {
+            Save();
             try
             {
                 //readobj.deepCopySelf(copy);

--
Gitblit v1.6.2