Normand Briere
2019-07-17 a5580a47d246c1272b10adba68070f6e13da5e41
ObjEditor.java
....@@ -816,6 +816,28 @@
816816 frame.validate();
817817 }
818818
819
+ private byte[] CompressCopy()
820
+ {
821
+ boolean temp = CameraPane.SWITCH;
822
+ CameraPane.SWITCH = false;
823
+
824
+ copy.ExtractBigData(versiontable);
825
+ // if (copy == client)
826
+
827
+ byte[] versions[] = copy.versions;
828
+ copy.versions = null;
829
+
830
+ byte[] compress = Compress(copy);
831
+
832
+ copy.versions = versions;
833
+
834
+ copy.RestoreBigData(versiontable);
835
+
836
+ CameraPane.SWITCH = temp;
837
+
838
+ return compress;
839
+ }
840
+
819841 private JTextPane createTextPane()
820842 {
821843 // TEXTAREA String[] initString =
....@@ -1174,10 +1196,11 @@
11741196 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751197 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761198
1199
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1200
+ link2masterCB.setToolTipText("Attach to support");
1201
+
11771202 if (Globals.ADVANCED)
11781203 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811204 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821205 speedupCB.setToolTipText("Option motion capture");
11831206 }
....@@ -3480,8 +3503,8 @@
34803503 try
34813504 {
34823505 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3483
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3484
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3506
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3507
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34853508
34863509 Object3D parent = o.parent;
34873510 o.parent = null;
....@@ -3492,10 +3515,14 @@
34923515
34933516 out.flush();
34943517
3495
- zstream.close();
3518
+ baos //zstream
3519
+ .close();
34963520 out.close();
34973521
3498
- return baos.toByteArray();
3522
+ byte[] bytes = baos.toByteArray();
3523
+
3524
+ System.out.println("save #bytes = " + bytes.length);
3525
+ return bytes;
34993526 } catch (Exception e)
35003527 {
35013528 System.err.println(e);
....@@ -3505,13 +3532,16 @@
35053532
35063533 static public Object Uncompress(byte[] bytes)
35073534 {
3508
- System.out.println("#bytes = " + bytes.length);
3535
+ System.out.println("restore #bytes = " + bytes.length);
35093536 try
35103537 {
35113538 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3512
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3513
- ObjectInputStream in = new ObjectInputStream(istream);
3539
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3540
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35143541 Object obj = in.readObject();
3542
+
3543
+ bais //istream
3544
+ .close();
35153545 in.close();
35163546
35173547 return obj;
....@@ -3566,12 +3596,11 @@
35663596 return null;
35673597 }
35683598
3569
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35703599
35713600 public void Save()
35723601 {
3573
- // Default reduces the probability of heuristics errors.
3574
- Save(true);
3602
+ //Save(true);
3603
+ Replace();
35753604 }
35763605
35773606 private boolean Equal(byte[] compress, byte[] name)
....@@ -3590,25 +3619,20 @@
35903619 return true;
35913620 }
35923621
3622
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3623
+
35933624 public boolean Save(boolean user)
35943625 {
35953626 System.err.println("Save");
35963627
35973628 cRadio tab = GetCurrentTab();
35983629
3599
- boolean temp = CameraPane.SWITCH;
3600
- CameraPane.SWITCH = false;
3601
-
3602
- copy.ExtractBigData(hashtable);
3603
-
3604
- byte[] compress = Compress(copy);
3605
-
3606
- CameraPane.SWITCH = temp;
3630
+ byte[] compress = CompressCopy();
36073631
36083632 boolean thesame = false;
36093633
36103634 // Quick heuristic using length. Works only when stream is compressed.
3611
- if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
3635
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
36123636 {
36133637 thesame = true;
36143638 }
....@@ -3616,18 +3640,23 @@
36163640 //EditorFrame.m_MainFrame.requestFocusInWindow();
36173641 if (!thesame)
36183642 {
3619
- tab.user[tab.undoindex] = user;
3620
- tab.graphs[tab.undoindex++] = compress;
3643
+ //tab.user[tab.versionindex] = user;
3644
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3645
+
3646
+ copy.versions[++copy.versionindex] = compress;
3647
+
3648
+ // if (increment)
3649
+ // tab.versionindex++;
36213650 }
36223651
3623
- copy.RestoreBigData(hashtable);
3652
+ //copy.RestoreBigData(versiontable);
36243653
36253654 //assert(hashtable.isEmpty());
36263655
3627
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3656
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36283657 {
3629
- tab.user[i] = false;
3630
- tab.graphs[i] = null;
3658
+ //tab.user[i] = false;
3659
+ copy.versions[i] = null;
36313660 }
36323661
36333662 SetUndoStates();
....@@ -3637,7 +3666,7 @@
36373666 {
36383667 try
36393668 {
3640
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3669
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36413670 ObjectOutputStream p = new ObjectOutputStream(ostream);
36423671
36433672 p.writeObject(copy);
....@@ -3661,7 +3690,7 @@
36613690 boolean temp = CameraPane.SWITCH;
36623691 CameraPane.SWITCH = false;
36633692
3664
- copy.ExtractBigData(hashtable);
3693
+ copy.ExtractBigData(versiontable);
36653694
36663695 copy.clear();
36673696
....@@ -3670,7 +3699,7 @@
36703699 copy.add(obj.get(i));
36713700 }
36723701
3673
- copy.RestoreBigData(hashtable);
3702
+ copy.RestoreBigData(versiontable);
36743703
36753704 CameraPane.SWITCH = temp;
36763705
....@@ -3698,14 +3727,18 @@
36983727 }
36993728
37003729 cButton undoButton;
3730
+ cButton restoreButton;
3731
+ cButton replaceButton;
37013732 cButton redoButton;
37023733
37033734 void SetUndoStates()
37043735 {
37053736 cRadio tab = GetCurrentTab();
37063737
3707
- undoButton.setEnabled(tab.undoindex > 0);
3708
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3738
+ restoreButton.setEnabled(copy.versionindex != -1);
3739
+ replaceButton.setEnabled(copy.versionindex != -1);
3740
+ undoButton.setEnabled(copy.versionindex > 0);
3741
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
37093742 }
37103743
37113744 public boolean Undo()
....@@ -3714,28 +3747,62 @@
37143747
37153748 cRadio tab = GetCurrentTab();
37163749
3717
- if (tab.undoindex == 0)
3750
+ if (copy.versionindex == 0)
37183751 {
37193752 java.awt.Toolkit.getDefaultToolkit().beep();
37203753 return false;
37213754 }
37223755
3723
- if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
3756
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3757
+// {
3758
+// if (Save(false))
3759
+// tab.versionindex -= 1;
3760
+// else
3761
+// {
3762
+// if (tab.versionindex <= 0)
3763
+// return false;
3764
+// else
3765
+// tab.versionindex -= 1;
3766
+// }
3767
+// }
3768
+
3769
+ copy.versionindex -= 1;
3770
+
3771
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3772
+
3773
+ return true;
3774
+ }
3775
+
3776
+ public boolean Restore()
3777
+ {
3778
+ System.err.println("Restore");
3779
+
3780
+ cRadio tab = GetCurrentTab();
3781
+
3782
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
37243783 {
3725
- if (Save(false))
3726
- tab.undoindex -= 1;
3727
- else
3728
- {
3729
- if (tab.undoindex <= 0)
3730
- return false;
3731
- else
3732
- tab.undoindex -= 1;
3733
- }
3784
+ java.awt.Toolkit.getDefaultToolkit().beep();
3785
+ return false;
37343786 }
37353787
3736
- tab.undoindex -= 1;
3788
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3789
+
3790
+ return true;
3791
+ }
37373792
3738
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3793
+ public boolean Replace()
3794
+ {
3795
+ System.err.println("Replace");
3796
+
3797
+ cRadio tab = GetCurrentTab();
3798
+
3799
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3800
+ {
3801
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3802
+ return false;
3803
+ }
3804
+
3805
+ copy.versions[copy.versionindex] = CompressCopy();
37393806
37403807 return true;
37413808 }
....@@ -3744,18 +3811,18 @@
37443811 {
37453812 cRadio tab = GetCurrentTab();
37463813
3747
- if (tab.graphs[tab.undoindex + 1] == null)
3814
+ if (copy.versions[copy.versionindex + 1] == null)
37483815 {
37493816 java.awt.Toolkit.getDefaultToolkit().beep();
37503817 return;
37513818 }
37523819
3753
- tab.undoindex += 1;
3820
+ copy.versionindex += 1;
37543821
3755
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3822
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
37563823
3757
- if (!tab.user[tab.undoindex])
3758
- tab.graphs[tab.undoindex] = null;
3824
+ //if (!tab.user[tab.versionindex])
3825
+ // tab.graphs[tab.versionindex] = null;
37593826 }
37603827
37613828 void ImportGFD()
....@@ -4051,9 +4118,22 @@
40514118 //copy.Touch();
40524119 }
40534120
4121
+ cNumberSlider versionField;
4122
+
40544123 public void stateChanged(ChangeEvent e)
40554124 {
40564125 // assert(false);
4126
+ if (e.getSource() == versionField)
4127
+ {
4128
+ int version = versionField.getInteger();
4129
+
4130
+ if (copy.versions[version] != null)
4131
+ {
4132
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4133
+ }
4134
+
4135
+ return;
4136
+ }
40574137
40584138 if (freezematerial)
40594139 {
....@@ -4402,7 +4482,7 @@
44024482
44034483 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44044484 {
4405
- if (Globals.SAVEONMAKE) // && resetmodel)
4485
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44064486 Save();
44074487 //Tween.set(thing, 0).target(1).start(tweenManager);
44084488 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4718,8 +4798,8 @@
47184798
47194799 if (readobj != null)
47204800 {
4721
- if (Globals.SAVEONMAKE)
4722
- Save();
4801
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4802
+ // Save();
47234803 try
47244804 {
47254805 //readobj.deepCopySelf(copy);
....@@ -4774,6 +4854,11 @@
47744854 c.addChild(csg);
47754855 }
47764856
4857
+ copy.versions = readobj.versions;
4858
+ copy.versionindex = readobj.versionindex;
4859
+
4860
+ SetUndoStates();
4861
+
47774862 ResetModel();
47784863 copy.HardTouch(); // recompile?
47794864 refreshContents();