From d0dc7ff35d71919d503ae35592478b173cf3cfd3 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Mon, 10 Jun 2019 23:45:04 -0400
Subject: [PATCH] Extract big data.
---
ObjEditor.java | 67 +++++++++++++++++++++
GroupEditor.java | 3
Object3D.java | 55 ++++++++++++++++++
3 files changed, 121 insertions(+), 4 deletions(-)
diff --git a/GroupEditor.java b/GroupEditor.java
index b4f001a..43af894 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -3429,7 +3429,8 @@
int size = obj.MemorySize();
- System.err.println((size/1024) + " KB is the size of " + obj);
+ //System.err.println((size/1024) + " KB is the size of " + obj);
+ System.err.println("the size of " + obj + " is " + size + " (" + (size/1024) + "KB)");
}
}
catch (Exception e)
diff --git a/ObjEditor.java b/ObjEditor.java
index b7c343d..2cb5163 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -3214,6 +3214,47 @@
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)
+ {
+ 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 +3263,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)
{
@@ -3251,13 +3299,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);
+ copy.RestoreBigData(hashtable);
+
+ //assert(hashtable.isEmpty());
+
for (int i = tab.undoindex; i < tab.graphs.length; i++)
{
tab.graphs[i] = null;
@@ -3285,12 +3341,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();
@@ -4295,6 +4357,7 @@
if (readobj != null)
{
+ Save();
try
{
//readobj.deepCopySelf(copy);
diff --git a/Object3D.java b/Object3D.java
index 2c2cf4d..af581bd 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -163,6 +163,59 @@
}
}
+void ExtractBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
+{
+ if (hashtable.containsKey(GetUUID()))
+ return;
+
+ Object3D o = new Object3D();
+ o.bRep = this.bRep;
+ if (this.bRep != null)
+ {
+ o.transientrep = this.bRep.support;
+ o.bRep.support = null;
+ }
+
+// o.support = this.support;
+// o.fileparent = this.fileparent;
+// if (this.bRep != null)
+// o.bRep = this.bRep.support;
+
+ hashtable.put(GetUUID(), o);
+
+ this.bRep = null;
+// if (this.bRep != null)
+// this.bRep.support = null;
+// this.support = null;
+// this.fileparent = null;
+
+ for (int i=0; i<Size(); i++)
+ {
+ get(i).ExtractBigData(hashtable);
+ }
+}
+
+void RestoreBigData(java.util.Hashtable<java.util.UUID, Object3D> hashtable)
+{
+ if (!hashtable.containsKey(GetUUID()))
+ return;
+
+ Object3D o = hashtable.get(GetUUID());
+
+ this.bRep = o.bRep;
+ if (this.bRep != null)
+ this.bRep.support = o.transientrep;
+// this.support = o.support;
+// this.fileparent = o.fileparent;
+
+ hashtable.remove(GetUUID());
+
+ for (int i=0; i<Size(); i++)
+ {
+ get(i).RestoreBigData(hashtable);
+ }
+}
+
// MOCAP SUPPORT
double tx,ty,tz,rx,ry,rz;
@@ -7567,7 +7620,7 @@
/*transient*/ cVector2[] projectedVertices = new cVector2[0];
Object3D /*Composite*/ parent;
- Object3D /*Composite*/ fileparent;
+ Object3D /*Composite*/ fileparent; // In the case of FileObject
double[][] toParent; // dynamic matrix
double[][] fromParent;
--
Gitblit v1.6.2