From d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Wed, 17 Jul 2019 20:15:40 -0400 Subject: [PATCH] Version slider --- ObjEditor.java | 245 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 192 insertions(+), 53 deletions(-) diff --git a/ObjEditor.java b/ObjEditor.java index 5d7d1bb..6e1560f 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -282,6 +282,12 @@ client = inClient; copy = client; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + // "this" is not called: SetupUI2(objEditor); } @@ -295,6 +301,12 @@ client = inClient; copy = client; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + SetupUI2(callee.GetEditor()); } @@ -327,6 +339,12 @@ copy = localCopy; copy.editWindow = this; + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + SetupMenu(); //SetupName(objEditor); // new @@ -816,6 +834,28 @@ frame.validate(); } + private byte[] CompressCopy() + { + boolean temp = CameraPane.SWITCH; + CameraPane.SWITCH = false; + + copy.ExtractBigData(versiontable); + // if (copy == client) + + byte[] versions[] = copy.versions; + copy.versions = null; + + byte[] compress = Compress(copy); + + copy.versions = versions; + + copy.RestoreBigData(versiontable); + + CameraPane.SWITCH = temp; + + return compress; + } + private JTextPane createTextPane() { // TEXTAREA String[] initString = @@ -1174,10 +1214,11 @@ randomCB = AddCheckBox(setupPanel2, "Random", copy.random); randomCB.setToolTipText("Randomly Rewind (or Go back and forth)"); + link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master); + link2masterCB.setToolTipText("Attach to support"); + if (Globals.ADVANCED) { - link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master); - link2masterCB.setToolTipText("Attach to support"); speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup); speedupCB.setToolTipText("Option motion capture"); } @@ -3480,8 +3521,8 @@ try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos); - ObjectOutputStream out = new ObjectOutputStream(zstream); +// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos); + ObjectOutputStream out = new ObjectOutputStream(baos); //zstream); Object3D parent = o.parent; o.parent = null; @@ -3492,10 +3533,14 @@ out.flush(); - zstream.close(); + baos //zstream + .close(); out.close(); - return baos.toByteArray(); + byte[] bytes = baos.toByteArray(); + + System.out.println("save #bytes = " + bytes.length); + return bytes; } catch (Exception e) { System.err.println(e); @@ -3505,13 +3550,16 @@ static public Object Uncompress(byte[] bytes) { - System.out.println("#bytes = " + bytes.length); + System.out.println("restore #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); + //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais); + ObjectInputStream in = new ObjectInputStream(bais); // istream); Object obj = in.readObject(); + + bais //istream + .close(); in.close(); return obj; @@ -3566,12 +3614,11 @@ return null; } - java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>(); public void Save() { - // Default reduces the probability of heuristics errors. - Save(true); + //Save(true); + Replace(); } private boolean Equal(byte[] compress, byte[] name) @@ -3590,25 +3637,20 @@ return true; } + java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>(); + public boolean Save(boolean user) { System.err.println("Save"); cRadio tab = GetCurrentTab(); - boolean temp = CameraPane.SWITCH; - CameraPane.SWITCH = false; - - copy.ExtractBigData(hashtable); - - byte[] compress = Compress(copy); - - CameraPane.SWITCH = temp; + byte[] compress = CompressCopy(); boolean thesame = false; // Quick heuristic using length. Works only when stream is compressed. - if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1])) + if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1])) { thesame = true; } @@ -3616,18 +3658,23 @@ //EditorFrame.m_MainFrame.requestFocusInWindow(); if (!thesame) { - tab.user[tab.undoindex] = user; - tab.graphs[tab.undoindex++] = compress; + //tab.user[tab.versionindex] = user; + //boolean increment = true; // tab.graphs[tab.versionindex] == null; + + copy.versions[++copy.versionindex] = compress; + + // if (increment) + // tab.versionindex++; } - copy.RestoreBigData(hashtable); + //copy.RestoreBigData(versiontable); //assert(hashtable.isEmpty()); - for (int i = tab.undoindex; i < tab.graphs.length; i++) + for (int i = copy.versionindex+1; i < copy.versions.length; i++) { - tab.user[i] = false; - tab.graphs[i] = null; + //tab.user[i] = false; + copy.versions[i] = null; } SetUndoStates(); @@ -3637,7 +3684,7 @@ { try { - FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex); + FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex); ObjectOutputStream p = new ObjectOutputStream(ostream); p.writeObject(copy); @@ -3661,7 +3708,7 @@ boolean temp = CameraPane.SWITCH; CameraPane.SWITCH = false; - copy.ExtractBigData(hashtable); + copy.ExtractBigData(versiontable); copy.clear(); @@ -3670,7 +3717,7 @@ copy.add(obj.get(i)); } - copy.RestoreBigData(hashtable); + copy.RestoreBigData(versiontable); CameraPane.SWITCH = temp; @@ -3698,64 +3745,129 @@ } cButton undoButton; + cButton restoreButton; + cButton replaceButton; cButton redoButton; + boolean muteSlider; + + int VersionCount() + { + int count = 0; + + for (int i = copy.versions.length; --i >= 0;) + { + if (copy.versions[i] != null) + count++; + } + + return count; + } + void SetUndoStates() { cRadio tab = GetCurrentTab(); - undoButton.setEnabled(tab.undoindex > 0); - redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null); + restoreButton.setEnabled(copy.versionindex != -1); + replaceButton.setEnabled(copy.versionindex != -1); + + undoButton.setEnabled(copy.versionindex > 0); + redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null); + + muteSlider = true; + versionSlider.setMaximum(VersionCount() - 1); + versionSlider.setInteger(copy.versionindex); + muteSlider = false; } public boolean Undo() { + // Option? + Replace(); + System.err.println("Undo"); cRadio tab = GetCurrentTab(); - if (tab.undoindex == 0) + if (copy.versionindex == 0) { java.awt.Toolkit.getDefaultToolkit().beep(); return false; } - if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex]) +// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex]) +// { +// if (Save(false)) +// tab.versionindex -= 1; +// else +// { +// if (tab.versionindex <= 0) +// return false; +// else +// tab.versionindex -= 1; +// } +// } + + copy.versionindex -= 1; + + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + return true; + } + + public boolean Restore() + { + System.err.println("Restore"); + + cRadio tab = GetCurrentTab(); + + if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) { - if (Save(false)) - tab.undoindex -= 1; - else - { - if (tab.undoindex <= 0) - return false; - else - tab.undoindex -= 1; - } + java.awt.Toolkit.getDefaultToolkit().beep(); + return false; } - tab.undoindex -= 1; + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + + return true; + } - CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex])); + public boolean Replace() + { + System.err.println("Replace"); + + cRadio tab = GetCurrentTab(); + + if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) + { + // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep(); + return false; + } + + copy.versions[copy.versionindex] = CompressCopy(); return true; } public void Redo() { + // Option? + Replace(); + cRadio tab = GetCurrentTab(); - if (tab.graphs[tab.undoindex + 1] == null) + if (copy.versions[copy.versionindex + 1] == null) { java.awt.Toolkit.getDefaultToolkit().beep(); return; } - tab.undoindex += 1; + copy.versionindex += 1; - CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex])); + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); - if (!tab.user[tab.undoindex]) - tab.graphs[tab.undoindex] = null; + //if (!tab.user[tab.versionindex]) + // tab.graphs[tab.versionindex] = null; } void ImportGFD() @@ -4051,9 +4163,25 @@ //copy.Touch(); } + cNumberSlider versionSlider; + public void stateChanged(ChangeEvent e) { // assert(false); + if (e.getSource() == versionSlider) + { + if (muteSlider) + return; + + int version = versionSlider.getInteger(); + + if (copy.versions[version] != null) + { + CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version])); + } + + return; + } if (freezematerial) { @@ -4402,7 +4530,7 @@ void makeSomething(Object3D thing, boolean resetmodel) // deselect) { - if (Globals.SAVEONMAKE) // && resetmodel) + if (Globals.REPLACEONMAKE) // && resetmodel) Save(); //Tween.set(thing, 0).target(1).start(tweenManager); //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager); @@ -4718,8 +4846,8 @@ if (readobj != null) { - if (Globals.SAVEONMAKE) - Save(); + //if (Globals.SAVEONMAKE) // A new object cannot share meshes + // Save(); try { //readobj.deepCopySelf(copy); @@ -4774,6 +4902,17 @@ c.addChild(csg); } + copy.versions = readobj.versions; + copy.versionindex = readobj.versionindex; + + if (copy.versions == null) + { + copy.versions = new byte[100][]; + copy.versionindex = -1; + } + + //? SetUndoStates(); + ResetModel(); copy.HardTouch(); // recompile? refreshContents(); -- Gitblit v1.6.2