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 =
....@@ -3574,11 +3596,11 @@
35743596 return null;
35753597 }
35763598
3577
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35783599
35793600 public void Save()
35803601 {
3581
- Save(true);
3602
+ //Save(true);
3603
+ Replace();
35823604 }
35833605
35843606 private boolean Equal(byte[] compress, byte[] name)
....@@ -3597,25 +3619,20 @@
35973619 return true;
35983620 }
35993621
3622
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3623
+
36003624 public boolean Save(boolean user)
36013625 {
36023626 System.err.println("Save");
36033627
36043628 cRadio tab = GetCurrentTab();
36053629
3606
- boolean temp = CameraPane.SWITCH;
3607
- CameraPane.SWITCH = false;
3608
-
3609
- copy.ExtractBigData(hashtable);
3610
-
3611
- byte[] compress = Compress(copy);
3612
-
3613
- CameraPane.SWITCH = temp;
3630
+ byte[] compress = CompressCopy();
36143631
36153632 boolean thesame = false;
36163633
36173634 // Quick heuristic using length. Works only when stream is compressed.
3618
- 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]))
36193636 {
36203637 thesame = true;
36213638 }
....@@ -3623,23 +3640,23 @@
36233640 //EditorFrame.m_MainFrame.requestFocusInWindow();
36243641 if (!thesame)
36253642 {
3626
- //tab.user[tab.undoindex] = user;
3627
- boolean increment = tab.graphs[tab.undoindex] == null;
3643
+ //tab.user[tab.versionindex] = user;
3644
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
36283645
3629
- tab.graphs[tab.undoindex] = compress;
3646
+ copy.versions[++copy.versionindex] = compress;
36303647
3631
- if (increment)
3632
- tab.undoindex++;
3648
+ // if (increment)
3649
+ // tab.versionindex++;
36333650 }
36343651
3635
- copy.RestoreBigData(hashtable);
3652
+ //copy.RestoreBigData(versiontable);
36363653
36373654 //assert(hashtable.isEmpty());
36383655
3639
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3656
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36403657 {
36413658 //tab.user[i] = false;
3642
- // tab.graphs[i] = null;
3659
+ copy.versions[i] = null;
36433660 }
36443661
36453662 SetUndoStates();
....@@ -3649,7 +3666,7 @@
36493666 {
36503667 try
36513668 {
3652
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3669
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36533670 ObjectOutputStream p = new ObjectOutputStream(ostream);
36543671
36553672 p.writeObject(copy);
....@@ -3673,7 +3690,7 @@
36733690 boolean temp = CameraPane.SWITCH;
36743691 CameraPane.SWITCH = false;
36753692
3676
- copy.ExtractBigData(hashtable);
3693
+ copy.ExtractBigData(versiontable);
36773694
36783695 copy.clear();
36793696
....@@ -3682,7 +3699,7 @@
36823699 copy.add(obj.get(i));
36833700 }
36843701
3685
- copy.RestoreBigData(hashtable);
3702
+ copy.RestoreBigData(versiontable);
36863703
36873704 CameraPane.SWITCH = temp;
36883705
....@@ -3710,14 +3727,18 @@
37103727 }
37113728
37123729 cButton undoButton;
3730
+ cButton restoreButton;
3731
+ cButton replaceButton;
37133732 cButton redoButton;
37143733
37153734 void SetUndoStates()
37163735 {
37173736 cRadio tab = GetCurrentTab();
37183737
3719
- undoButton.setEnabled(tab.undoindex > 0);
3720
- 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);
37213742 }
37223743
37233744 public boolean Undo()
....@@ -3726,28 +3747,62 @@
37263747
37273748 cRadio tab = GetCurrentTab();
37283749
3729
- if (tab.undoindex == 0)
3750
+ if (copy.versionindex == 0)
37303751 {
37313752 java.awt.Toolkit.getDefaultToolkit().beep();
37323753 return false;
37333754 }
37343755
3735
- 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)
37363783 {
3737
- if (Save(false))
3738
- tab.undoindex -= 1;
3739
- else
3740
- {
3741
- if (tab.undoindex <= 0)
3742
- return false;
3743
- else
3744
- tab.undoindex -= 1;
3745
- }
3784
+ java.awt.Toolkit.getDefaultToolkit().beep();
3785
+ return false;
37463786 }
37473787
3748
- tab.undoindex -= 1;
3788
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3789
+
3790
+ return true;
3791
+ }
37493792
3750
- 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();
37513806
37523807 return true;
37533808 }
....@@ -3756,18 +3811,18 @@
37563811 {
37573812 cRadio tab = GetCurrentTab();
37583813
3759
- if (tab.graphs[tab.undoindex + 1] == null)
3814
+ if (copy.versions[copy.versionindex + 1] == null)
37603815 {
37613816 java.awt.Toolkit.getDefaultToolkit().beep();
37623817 return;
37633818 }
37643819
3765
- tab.undoindex += 1;
3820
+ copy.versionindex += 1;
37663821
3767
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3822
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
37683823
3769
- //if (!tab.user[tab.undoindex])
3770
- // tab.graphs[tab.undoindex] = null;
3824
+ //if (!tab.user[tab.versionindex])
3825
+ // tab.graphs[tab.versionindex] = null;
37713826 }
37723827
37733828 void ImportGFD()
....@@ -4063,9 +4118,22 @@
40634118 //copy.Touch();
40644119 }
40654120
4121
+ cNumberSlider versionField;
4122
+
40664123 public void stateChanged(ChangeEvent e)
40674124 {
40684125 // 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
+ }
40694137
40704138 if (freezematerial)
40714139 {
....@@ -4414,7 +4482,7 @@
44144482
44154483 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44164484 {
4417
- if (Globals.SAVEONMAKE) // && resetmodel)
4485
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44184486 Save();
44194487 //Tween.set(thing, 0).target(1).start(tweenManager);
44204488 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4786,6 +4854,11 @@
47864854 c.addChild(csg);
47874855 }
47884856
4857
+ copy.versions = readobj.versions;
4858
+ copy.versionindex = readobj.versionindex;
4859
+
4860
+ SetUndoStates();
4861
+
47894862 ResetModel();
47904863 copy.HardTouch(); // recompile?
47914864 refreshContents();