Normand Briere
2019-08-01 c49ad213b600f844e9070cb09390c3e6d3d13db4
ObjEditor.java
....@@ -41,64 +41,78 @@
4141 JFrame frame;
4242
4343 static ObjEditor theFrame;
44
+
45
+ public cGridBag GetSeparator()
46
+ {
47
+ cGridBag separator = new cGridBag();
48
+ separator.add(new JSeparator());
49
+ separator.preferredHeight = 5;
50
+ return separator;
51
+ }
4452
4553 cButton GetButton(String name, boolean border)
4654 {
47
- try
48
- {
49
- ImageIcon icon = GetIcon(name);
50
- return new cButton(icon, border);
51
- }
52
- catch (Exception e)
53
- {
54
- return new cButton(name, border);
55
- }
55
+ ImageIcon icon = GetIcon(name);
56
+ return new cButton(icon, border);
57
+ }
58
+
59
+ cLabel GetLabel(String name, boolean border)
60
+ {
61
+ //ImageIcon icon = GetIcon(name);
62
+ return new cLabel(GetImage(name), border);
5663 }
5764
5865 cToggleButton GetToggleButton(String name, boolean border)
5966 {
60
- try
61
- {
62
- ImageIcon icon = GetIcon(name);
63
- return new cToggleButton(icon, border);
64
- }
65
- catch (Exception e)
66
- {
67
- return new cToggleButton(name, border);
68
- }
67
+ ImageIcon icon = GetIcon(name);
68
+ return new cToggleButton(icon, border);
6969 }
7070
7171 cCheckBox GetCheckBox(String name, boolean border)
7272 {
73
+ ImageIcon icon = GetIcon(name);
74
+ return new cCheckBox(icon, border);
75
+ }
76
+
77
+ ImageIcon GetIcon(String name)
78
+ {
7379 try
7480 {
75
- ImageIcon icon = GetIcon(name);
76
- return new cCheckBox(icon, border);
81
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
82
+
83
+// if (image.getWidth() > 48 && image.getHeight() > 48)
84
+// {
85
+// BufferedImage resized = new BufferedImage(48, 48, image.getType());
86
+// Graphics2D g = resized.createGraphics();
87
+// g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
88
+// //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
89
+// g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
90
+// g.dispose();
91
+//
92
+// image = resized;
93
+// }
94
+
95
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
96
+ return icon;
7797 }
7898 catch (Exception e)
7999 {
80
- return new cCheckBox(name, border);
100
+ return null;
81101 }
82102 }
83
-
84
- private ImageIcon GetIcon(String name) throws IOException
103
+
104
+ BufferedImage GetImage(String name)
85105 {
86
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
-
88
- if (image.getWidth() != 24 && image.getHeight() != 24)
106
+ try
89107 {
90
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
91
- Graphics2D g = resized.createGraphics();
92
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
93
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
94
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
95
- g.dispose();
96
-
97
- image = resized;
108
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
109
+
110
+ return image;
98111 }
99
-
100
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
- return icon;
112
+ catch (Exception e)
113
+ {
114
+ return null;
115
+ }
102116 }
103117
104118 // SCRIPT
....@@ -282,6 +296,12 @@
282296 client = inClient;
283297 copy = client;
284298
299
+ if (copy.versions == null)
300
+ {
301
+ copy.versions = new Object3D[100];
302
+ copy.versionindex = -1;
303
+ }
304
+
285305 // "this" is not called: SetupUI2(objEditor);
286306 }
287307
....@@ -295,6 +315,12 @@
295315 client = inClient;
296316 copy = client;
297317
318
+ if (copy.versions == null)
319
+ {
320
+ copy.versions = new Object3D[100];
321
+ copy.versionindex = -1;
322
+ }
323
+
298324 SetupUI2(callee.GetEditor());
299325 }
300326
....@@ -327,6 +353,12 @@
327353 copy = localCopy;
328354 copy.editWindow = this;
329355
356
+ if (copy.versions == null)
357
+ {
358
+// copy.versions = new byte[100][];
359
+// copy.versionindex = -1;
360
+ }
361
+
330362 SetupMenu();
331363
332364 //SetupName(objEditor); // new
....@@ -419,11 +451,12 @@
419451
420452 toolbarPanel = new JPanel();
421453 toolbarPanel.setName("Toolbar");
454
+
422455 treePanel = new cGridBag();
423456 treePanel.setName("Tree");
424457
425458 editPanel = new cGridBag().setVertical(true);
426
- editPanel.setName("Edit");
459
+ //editPanel.setName("Edit");
427460
428461 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
429462
....@@ -431,11 +464,11 @@
431464 editPanel.add(editCommandsPanel);
432465 editPanel.add(ctrlPanel);
433466
434
- toolboxPanel = new cGridBag().setVertical(false);
435
- toolboxPanel.setName("Toolbox");
467
+ toolboxPanel = new cGridBag().setVertical(true);
468
+ //toolboxPanel.setName("Toolbox");
436469
437470 materialPanel = new cGridBag().setVertical(true);
438
- materialPanel.setName("Material");
471
+ //materialPanel.setName("Material");
439472
440473 /*JTextPane*/
441474 infoarea = createTextPane();
....@@ -443,6 +476,7 @@
443476
444477 infoarea.setEditable(true);
445478 SetText();
479
+
446480 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
447481 // infoarea.setOpaque(false);
448482 // //infoarea.setForeground(textcolor);
....@@ -450,7 +484,7 @@
450484 // TEXTAREA infoarea.setWrapStyleWord(true);
451485 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452486 infoPanel.setPreferredSize(new Dimension(1, 1));
453
- infoPanel.setName("Info");
487
+ //infoPanel.setName("Info");
454488 //infoPanel.setLayout(new BorderLayout());
455489 //infoPanel.add(createTextPane());
456490
....@@ -816,6 +850,29 @@
816850 frame.validate();
817851 }
818852
853
+ private Object3D CompressCopy()
854
+ {
855
+ boolean temp = CameraPane.SWITCH;
856
+ CameraPane.SWITCH = false;
857
+
858
+ copy.ExtractBigData(versiontable);
859
+ // if (copy == client)
860
+
861
+ Object3D versions[] = copy.versions;
862
+ copy.versions = null;
863
+
864
+ //byte[] compress = Compress(copy);
865
+ Object3D compress = (Object3D)Grafreed.clone(copy);
866
+
867
+ copy.versions = versions;
868
+
869
+ copy.RestoreBigData(versiontable);
870
+
871
+ CameraPane.SWITCH = temp;
872
+
873
+ return compress;
874
+ }
875
+
819876 private JTextPane createTextPane()
820877 {
821878 // TEXTAREA String[] initString =
....@@ -946,7 +1003,7 @@
9461003 // NumberSlider vDivsField;
9471004 // JCheckBox endcaps;
9481005 JCheckBox liveCB;
949
- JCheckBox selectCB;
1006
+ JCheckBox selectableCB;
9501007 JCheckBox hideCB;
9511008 JCheckBox link2masterCB;
9521009 JCheckBox markCB;
....@@ -1158,13 +1215,16 @@
11581215
11591216 liveCB = AddCheckBox(setupPanel, "Live", copy.live);
11601217 liveCB.setToolTipText("Animate object");
1161
- selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1162
- selectCB.setToolTipText("Make object selectable");
1218
+ selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1219
+ selectableCB.setToolTipText("Make object selectable");
11631220 // Return();
1221
+
11641222 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11651223 hideCB.setToolTipText("Hide object");
11661224 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
11671225 markCB.setToolTipText("As animation target transform");
1226
+
1227
+ ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
11681228
11691229 setupPanel2 = new cGridBag().setVertical(false);
11701230
....@@ -1174,10 +1234,11 @@
11741234 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751235 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761236
1237
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1238
+ link2masterCB.setToolTipText("Attach to support");
1239
+
11771240 if (Globals.ADVANCED)
11781241 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811242 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821243 speedupCB.setToolTipText("Option motion capture");
11831244 }
....@@ -1451,6 +1512,7 @@
14511512 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14521513 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14531514 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1515
+ //XYZPanel.setName("XYZ");
14541516
14551517 /*
14561518 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1488,16 +1550,29 @@
14881550 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14891551 //tmp.setName("Edit");
14901552 objectPanel.add(materialPanel);
1553
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
1554
+ objectPanel.setToolTipTextAt(0, "Material panel");
1555
+
14911556 // JPanel north = new JPanel(new BorderLayout());
14921557 // north.setName("Edit");
14931558 // north.add(ctrlPanel, BorderLayout.NORTH);
14941559 // objectPanel.add(north);
14951560 objectPanel.add(editPanel);
1561
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1562
+ objectPanel.setToolTipTextAt(1, "Edit panel");
14961563
14971564 //if (Globals.ADVANCED)
14981565 objectPanel.add(infoPanel);
1566
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1567
+ objectPanel.setToolTipTextAt(2, "Info panel");
1568
+
1569
+ objectPanel.add(XYZPanel);
1570
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1571
+ objectPanel.setToolTipTextAt(3, "XYZ/RGB panel");
14991572
15001573 objectPanel.add(toolboxPanel);
1574
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
1575
+ objectPanel.setToolTipTextAt(4, "Objects/backgrounds panel");
15011576
15021577 /*
15031578 aConstraints.gridx = 0;
....@@ -1518,7 +1593,7 @@
15181593 scrollpane.addMouseWheelListener(this); // Default not fast enough
15191594
15201595 /*JTabbedPane*/ scenePanel = new cGridBag();
1521
- scenePanel.preferredWidth = 6;
1596
+ scenePanel.preferredWidth = 5;
15221597
15231598 JTabbedPane tabbedPane = new JTabbedPane();
15241599 tabbedPane.add(scrollpane);
....@@ -1596,7 +1671,7 @@
15961671 bigThree = new cGridBag();
15971672 bigThree.addComponent(scenePanel);
15981673 bigThree.addComponent(centralPanel);
1599
- bigThree.addComponent(XYZPanel);
1674
+ //bigThree.addComponent(XYZPanel);
16001675
16011676 // // SIDE EFFECT!!!
16021677 // aConstraints.gridx = 0;
....@@ -1637,7 +1712,6 @@
16371712 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
16381713 frame.addWindowListener(new WindowAdapter()
16391714 {
1640
-
16411715 public void windowClosing(WindowEvent e)
16421716 {
16431717 Close();
....@@ -1699,27 +1773,48 @@
16991773 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17001774
17011775 cGridBag colorSection = new cGridBag().setVertical(true);
1776
+
1777
+ cGridBag huepanel = new cGridBag();
1778
+ cGridBag huelabel = new cGridBag();
1779
+ huelabel.add(GetLabel("icons/hue.png", false));
1780
+ huelabel.preferredWidth = 20;
1781
+ huepanel.add(new cGridBag()); // Label
1782
+ huepanel.add(huelabel); // Field/slider
1783
+
1784
+ huepanel.preferredHeight = 7;
1785
+
1786
+ colorSection.add(huepanel);
17021787
17031788 cGridBag color = new cGridBag();
1704
- color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1705
- colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1706
- color.add(colorField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1789
+
1790
+ color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
1791
+ colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1792
+ color.add(colorField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1793
+
17071794 //colorField.preferredWidth = 200;
17081795 colorSection.add(color);
17091796
17101797 cGridBag modulation = new cGridBag();
17111798 modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints);
17121799 modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1713
- modulation.add(modulationField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1800
+ modulation.add(modulationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
17141801 colorSection.add(modulation);
17151802
1803
+ cGridBag opacity = new cGridBag();
1804
+ opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1805
+ opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1806
+ opacity.add(opacityField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1807
+ colorSection.add(opacity);
1808
+
1809
+ colorSection.add(GetSeparator());
1810
+
17161811 cGridBag texture = new cGridBag();
17171812 texture.add(textureLabel = new JLabel("Texture")); // , aConstraints);
17181813 textureLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17191814 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
17201815 colorSection.add(texture);
17211816
1722
- panel.add(new JSeparator());
1817
+ panel.add(GetSeparator());
17231818
17241819 panel.add(colorSection);
17251820
....@@ -1775,7 +1870,7 @@
17751870 shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17761871 diffuseSection.add(shadowbias);
17771872
1778
- panel.add(new JSeparator());
1873
+ panel.add(GetSeparator());
17791874
17801875 panel.add(diffuseSection);
17811876
....@@ -1838,7 +1933,7 @@
18381933 specularSection.add(anisoV);
18391934
18401935
1841
- panel.add(new JSeparator());
1936
+ panel.add(GetSeparator());
18421937
18431938 panel.add(specularSection);
18441939
....@@ -1863,12 +1958,6 @@
18631958 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18641959 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
18651960 colorSection.add(backlit);
1866
-
1867
- cGridBag opacity = new cGridBag();
1868
- opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
1869
- opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1870
- opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1871
- colorSection.add(opacity);
18721961
18731962 //panel.add(new JSeparator());
18741963
....@@ -1914,7 +2003,7 @@
19142003 opacityPower.add(opacityPowerField = new cNumberSlider(this, 0.0, 10 /*10 dec 2013*/)); // , aConstraints);
19152004 textureSection.add(opacityPower);
19162005
1917
- panel.add(new JSeparator());
2006
+ panel.add(GetSeparator());
19182007
19192008 panel.add(textureSection);
19202009
....@@ -3213,7 +3302,7 @@
32133302 {
32143303 copy.live ^= true;
32153304 return;
3216
- } else if (event.getSource() == selectCB)
3305
+ } else if (event.getSource() == selectableCB)
32173306 {
32183307 copy.dontselect ^= true;
32193308 return;
....@@ -3477,11 +3566,12 @@
34773566
34783567 static public byte[] Compress(Object3D o)
34793568 {
3569
+ // Slower to actually compress.
34803570 try
34813571 {
34823572 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3483
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3484
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3573
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3574
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34853575
34863576 Object3D parent = o.parent;
34873577 o.parent = null;
....@@ -3492,10 +3582,14 @@
34923582
34933583 out.flush();
34943584
3495
- zstream.close();
3585
+ baos //zstream
3586
+ .close();
34963587 out.close();
34973588
3498
- return baos.toByteArray();
3589
+ byte[] bytes = baos.toByteArray();
3590
+
3591
+ System.out.println("save #bytes = " + bytes.length);
3592
+ return bytes;
34993593 } catch (Exception e)
35003594 {
35013595 System.err.println(e);
....@@ -3505,13 +3599,16 @@
35053599
35063600 static public Object Uncompress(byte[] bytes)
35073601 {
3508
- System.out.println("#bytes = " + bytes.length);
3602
+ System.out.println("restore #bytes = " + bytes.length);
35093603 try
35103604 {
35113605 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3512
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3513
- ObjectInputStream in = new ObjectInputStream(istream);
3606
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3607
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35143608 Object obj = in.readObject();
3609
+
3610
+ bais //istream
3611
+ .close();
35153612 in.close();
35163613
35173614 return obj;
....@@ -3566,12 +3663,11 @@
35663663 return null;
35673664 }
35683665
3569
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35703666
35713667 public void Save()
35723668 {
3573
- // Default reduces the probability of heuristics errors.
3574
- Save(true);
3669
+ //Save(true);
3670
+ Replace();
35753671 }
35763672
35773673 private boolean Equal(byte[] compress, byte[] name)
....@@ -3590,44 +3686,43 @@
35903686 return true;
35913687 }
35923688
3689
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3690
+
35933691 public boolean Save(boolean user)
35943692 {
35953693 System.err.println("Save");
35963694
35973695 cRadio tab = GetCurrentTab();
35983696
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;
3697
+ Object3D compress = CompressCopy(); // Saved version. No need for "Replace".
36073698
36083699 boolean thesame = false;
36093700
3610
- // 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]))
3612
- {
3613
- thesame = true;
3614
- }
3701
+// if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3702
+// {
3703
+// thesame = true;
3704
+// }
36153705
36163706 //EditorFrame.m_MainFrame.requestFocusInWindow();
36173707 if (!thesame)
36183708 {
3619
- tab.user[tab.undoindex] = user;
3620
- tab.graphs[tab.undoindex++] = compress;
3709
+ //tab.user[tab.versionindex] = user;
3710
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3711
+
3712
+ copy.versions[++copy.versionindex] = compress;
3713
+
3714
+ // if (increment)
3715
+ // tab.versionindex++;
36213716 }
36223717
3623
- copy.RestoreBigData(hashtable);
3718
+ //copy.RestoreBigData(versiontable);
36243719
36253720 //assert(hashtable.isEmpty());
36263721
3627
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3722
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
36283723 {
3629
- tab.user[i] = false;
3630
- tab.graphs[i] = null;
3724
+ //tab.user[i] = false;
3725
+ copy.versions[i] = null;
36313726 }
36323727
36333728 SetUndoStates();
....@@ -3637,7 +3732,7 @@
36373732 {
36383733 try
36393734 {
3640
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3735
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36413736 ObjectOutputStream p = new ObjectOutputStream(ostream);
36423737
36433738 p.writeObject(copy);
....@@ -3661,16 +3756,19 @@
36613756 boolean temp = CameraPane.SWITCH;
36623757 CameraPane.SWITCH = false;
36633758
3664
- copy.ExtractBigData(hashtable);
3759
+ copy.ExtractBigData(versiontable);
36653760
36663761 copy.clear();
36673762
3763
+ copy.skyboxname = obj.skyboxname;
3764
+ copy.skyboxext = obj.skyboxext;
3765
+
36683766 for (int i=0; i<obj.Size(); i++)
36693767 {
36703768 copy.add(obj.get(i));
36713769 }
36723770
3673
- copy.RestoreBigData(hashtable);
3771
+ copy.RestoreBigData(versiontable);
36743772
36753773 CameraPane.SWITCH = temp;
36763774
....@@ -3698,64 +3796,130 @@
36983796 }
36993797
37003798 cButton undoButton;
3799
+ cButton restoreButton;
3800
+ cButton replaceButton;
37013801 cButton redoButton;
37023802
3803
+ boolean muteSlider;
3804
+
3805
+ int VersionCount()
3806
+ {
3807
+ int count = 0;
3808
+
3809
+ for (int i = copy.versions.length; --i >= 0;)
3810
+ {
3811
+ if (copy.versions[i] != null)
3812
+ count++;
3813
+ }
3814
+
3815
+ return count;
3816
+ }
3817
+
37033818 void SetUndoStates()
37043819 {
37053820 cRadio tab = GetCurrentTab();
37063821
3707
- undoButton.setEnabled(tab.undoindex > 0);
3708
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3822
+ restoreButton.setEnabled(copy.versionindex != -1);
3823
+ replaceButton.setEnabled(copy.versionindex != -1);
3824
+
3825
+ undoButton.setEnabled(copy.versionindex > 0);
3826
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3827
+
3828
+ muteSlider = true;
3829
+ versionSlider.setMaximum(VersionCount() - 1);
3830
+ versionSlider.setInteger(copy.versionindex);
3831
+ muteSlider = false;
37093832 }
37103833
37113834 public boolean Undo()
37123835 {
3836
+ // Option?
3837
+ Replace();
3838
+
37133839 System.err.println("Undo");
37143840
37153841 cRadio tab = GetCurrentTab();
37163842
3717
- if (tab.undoindex == 0)
3843
+ if (copy.versionindex == 0)
37183844 {
37193845 java.awt.Toolkit.getDefaultToolkit().beep();
37203846 return false;
37213847 }
37223848
3723
- if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
3849
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3850
+// {
3851
+// if (Save(false))
3852
+// tab.versionindex -= 1;
3853
+// else
3854
+// {
3855
+// if (tab.versionindex <= 0)
3856
+// return false;
3857
+// else
3858
+// tab.versionindex -= 1;
3859
+// }
3860
+// }
3861
+
3862
+ copy.versionindex -= 1;
3863
+
3864
+ CopyChanged((Object3D)copy.versions[copy.versionindex]);
3865
+
3866
+ return true;
3867
+ }
3868
+
3869
+ public boolean Restore()
3870
+ {
3871
+ System.err.println("Restore");
3872
+
3873
+ cRadio tab = GetCurrentTab();
3874
+
3875
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
37243876 {
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
- }
3877
+ java.awt.Toolkit.getDefaultToolkit().beep();
3878
+ return false;
37343879 }
37353880
3736
- tab.undoindex -= 1;
3881
+ //CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3882
+ CopyChanged(copy.versions[copy.versionindex]);
3883
+
3884
+ return true;
3885
+ }
37373886
3738
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3887
+ public boolean Replace()
3888
+ {
3889
+ System.err.println("Replace");
3890
+
3891
+ cRadio tab = GetCurrentTab();
3892
+
3893
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3894
+ {
3895
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3896
+ return false;
3897
+ }
3898
+
3899
+ copy.versions[copy.versionindex] = CompressCopy();
37393900
37403901 return true;
37413902 }
37423903
37433904 public void Redo()
37443905 {
3906
+ // Option?
3907
+ Replace();
3908
+
37453909 cRadio tab = GetCurrentTab();
37463910
3747
- if (tab.graphs[tab.undoindex + 1] == null)
3911
+ if (copy.versions[copy.versionindex + 1] == null)
37483912 {
37493913 java.awt.Toolkit.getDefaultToolkit().beep();
37503914 return;
37513915 }
37523916
3753
- tab.undoindex += 1;
3917
+ copy.versionindex += 1;
37543918
3755
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3919
+ CopyChanged(copy.versions[copy.versionindex]);
37563920
3757
- if (!tab.user[tab.undoindex])
3758
- tab.graphs[tab.undoindex] = null;
3921
+ //if (!tab.user[tab.versionindex])
3922
+ // tab.graphs[tab.versionindex] = null;
37593923 }
37603924
37613925 void ImportGFD()
....@@ -4051,9 +4215,25 @@
40514215 //copy.Touch();
40524216 }
40534217
4218
+ cNumberSlider versionSlider;
4219
+
40544220 public void stateChanged(ChangeEvent e)
40554221 {
40564222 // assert(false);
4223
+ if (e.getSource() == versionSlider)
4224
+ {
4225
+ if (muteSlider)
4226
+ return;
4227
+
4228
+ int version = versionSlider.getInteger();
4229
+
4230
+ if (copy.versions[version] != null)
4231
+ {
4232
+ CopyChanged(copy.versions[copy.versionindex = version]);
4233
+ }
4234
+
4235
+ return;
4236
+ }
40574237
40584238 if (freezematerial)
40594239 {
....@@ -4402,7 +4582,7 @@
44024582
44034583 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
44044584 {
4405
- if (Globals.SAVEONMAKE) // && resetmodel)
4585
+ if (Globals.REPLACEONMAKE) // && resetmodel)
44064586 Save();
44074587 //Tween.set(thing, 0).target(1).start(tweenManager);
44084588 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4644,7 +4824,9 @@
46444824 readobj.ResetDisplayList();
46454825 } catch (Exception e)
46464826 {
4647
- //e.printStackTrace();
4827
+ if (!e.toString().contains("GZIP"))
4828
+ e.printStackTrace();
4829
+
46484830 try
46494831 {
46504832 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
....@@ -4718,12 +4900,14 @@
47184900
47194901 if (readobj != null)
47204902 {
4721
- if (Globals.SAVEONMAKE)
4722
- Save();
4903
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4904
+ // Save();
47234905 try
47244906 {
47254907 //readobj.deepCopySelf(copy);
47264908 copy.clear(); // june 2014
4909
+ copy.skyboxname = readobj.skyboxname;
4910
+ copy.skyboxext = readobj.skyboxext;
47274911 for (int i = 0; i < readobj.size(); i++)
47284912 {
47294913 Object3D child = readobj.get(i); // reserve(i);
....@@ -4764,6 +4948,7 @@
47644948 }
47654949 } catch (ClassCastException e)
47664950 {
4951
+ e.printStackTrace();
47674952 assert (false);
47684953 Composite c = (Composite) copy;
47694954 c.children.clear();
....@@ -4774,6 +4959,17 @@
47744959 c.addChild(csg);
47754960 }
47764961
4962
+ copy.versions = readobj.versions;
4963
+ copy.versionindex = readobj.versionindex;
4964
+
4965
+ if (copy.versions == null)
4966
+ {
4967
+ copy.versions = new Object3D[100];
4968
+ copy.versionindex = -1;
4969
+ }
4970
+
4971
+ //? SetUndoStates();
4972
+
47774973 ResetModel();
47784974 copy.HardTouch(); // recompile?
47794975 refreshContents();
....@@ -4883,6 +5079,7 @@
48835079 //ps.print(buffer.toString());
48845080 } catch (IOException e)
48855081 {
5082
+ e.printStackTrace();
48865083 }
48875084 }
48885085