Normand Briere
2019-06-21 15123b19e7bc8da2869429b07f0fbaa0598e945e
ObjEditor.java
....@@ -168,6 +168,7 @@
168168 // objEditor.ctrlPanel.remove(remarkButton);
169169
170170 objEditor.ctrlPanel.remove(setupPanel);
171
+ objEditor.ctrlPanel.remove(setupPanel2);
171172 objEditor.ctrlPanel.remove(commandsPanel);
172173 objEditor.ctrlPanel.remove(pushPanel);
173174 //objEditor.ctrlPanel.remove(fillPanel);
....@@ -278,7 +279,7 @@
278279 frame.setMenuBar(menuBar = new MenuBar());
279280 menuBar.add(fileMenu = new Menu("File"));
280281 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
282
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282283
283284 //oe.menuBar.add(menu = new Menu("Include"));
284285 Menu menu = new Menu("Import");
....@@ -419,10 +420,10 @@
419420 e.printStackTrace();
420421 }
421422
422
- String selection = infoarea.getText();
423
- java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
424
- java.awt.datatransfer.Clipboard clipboard =
425
- Toolkit.getDefaultToolkit().getSystemClipboard();
423
+// String selection = infoarea.getText();
424
+// java.awt.datatransfer.StringSelection data = new java.awt.datatransfer.StringSelection(selection);
425
+// java.awt.datatransfer.Clipboard clipboard =
426
+// Toolkit.getDefaultToolkit().getSystemClipboard();
426427 //clipboard.setContents(data, data);
427428 }
428429
....@@ -747,6 +748,7 @@
747748
748749 cGridBag namePanel;
749750 cGridBag setupPanel;
751
+ cGridBag setupPanel2;
750752 cGridBag commandsPanel;
751753 cGridBag pushPanel;
752754 cGridBag fillPanel;
....@@ -939,21 +941,25 @@
939941 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
940942 markCB.setToolTipText("Set the animation target transform");
941943
942
- rewindCB = AddCheckBox(setupPanel, "Rewind", copy.rewind);
944
+ setupPanel2 = new cGridBag().setVertical(false);
945
+
946
+ rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
943947 rewindCB.setToolTipText("Rewind animation");
944948
945
- randomCB = AddCheckBox(setupPanel, "Random", copy.random);
946
- randomCB.setToolTipText("Option for switch node");
949
+ randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
950
+ randomCB.setToolTipText("Rewind or Go back and forth randomly");
947951
948952 if (Globals.ADVANCED)
949953 {
950
- link2masterCB = AddCheckBox(setupPanel, "Support", copy.link2master);
954
+ link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
951955 link2masterCB.setToolTipText("Attach to support");
952
- speedupCB = AddCheckBox(setupPanel, "Speed", copy.speedup);
956
+ speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
953957 speedupCB.setToolTipText("Option motion capture");
954958 }
955959
956960 oe.ctrlPanel.add(setupPanel);
961
+ oe.ctrlPanel.Return();
962
+ oe.ctrlPanel.add(setupPanel2);
957963 oe.ctrlPanel.Return();
958964
959965 commandsPanel = new cGridBag().setVertical(false);
....@@ -1935,6 +1941,7 @@
19351941 e2.printStackTrace();
19361942 }
19371943 }
1944
+
19381945 LoadJMEThread loadThread;
19391946
19401947 class LoadJMEThread extends Thread
....@@ -1992,6 +1999,7 @@
19921999 //LoadFile0(filename, converter);
19932000 }
19942001 }
2002
+
19952003 LoadOBJThread loadObjThread;
19962004
19972005 class LoadOBJThread extends Thread
....@@ -2070,19 +2078,19 @@
20702078
20712079 void LoadObjFile(String fullname)
20722080 {
2073
- /*
2081
+ System.out.println("Loading " + fullname);
2082
+ /**/
20742083 //lastFilename = fullname;
20752084 if(loadObjThread == null)
20762085 {
2077
- loadObjThread = new LoadOBJThread();
2078
- loadObjThread.start();
2086
+ loadObjThread = new LoadOBJThread();
2087
+ loadObjThread.start();
20792088 }
20802089
20812090 loadObjThread.add(fullname);
2082
- */
2091
+ /**/
20832092
2084
- System.out.println("Loading " + fullname);
2085
- makeSomething(new FileObject(fullname, true), true);
2093
+ //makeSomething(new FileObject(fullname, true), true);
20862094 }
20872095
20882096 void LoadGFDFile(String fullname)
....@@ -2925,7 +2933,7 @@
29252933 return;
29262934 } else if (event.getSource() == toggleSwitchItem)
29272935 {
2928
- cameraView.ToggleRandom();
2936
+ cameraView.ToggleSwitch();
29292937 cameraView.repaint();
29302938 return;
29312939 } else if (event.getSource() == toggleHandleItem)
....@@ -3212,23 +3220,45 @@
32123220 objEditor.refreshContents();
32133221 }
32143222
3215
- Object3D graphs[] = new Object3D[10000];
3216
- int undoindex = 0;
3217
-
3218
- static public Object clone(Object o)
3223
+ static public byte[] Compress(Object3D o)
32193224 {
32203225 try
32213226 {
32223227 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3223
- ObjectOutputStream out = new ObjectOutputStream(baos);
3228
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3229
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
32243230
3231
+ Object3D parent = o.parent;
3232
+ o.parent = null;
3233
+
32253234 out.writeObject(o);
3235
+
3236
+ o.parent = parent;
3237
+
3238
+ out.flush();
32263239
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3240
+ zstream.close();
3241
+ out.close();
3242
+
3243
+ return baos.toByteArray();
3244
+ } catch (Exception e)
3245
+ {
3246
+ System.err.println(e);
3247
+ return null;
3248
+ }
3249
+ }
3250
+
3251
+ static public Object Uncompress(byte[] bytes)
3252
+ {
3253
+ System.out.println("#bytes = " + bytes.length);
3254
+ try
3255
+ {
3256
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3257
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3258
+ ObjectInputStream in = new ObjectInputStream(istream);
32293259 Object obj = in.readObject();
32303260 in.close();
3231
- out.close();
3261
+
32323262 return obj;
32333263 } catch (Exception e)
32343264 {
....@@ -3237,16 +3267,73 @@
32373267 }
32383268 }
32393269
3270
+ static public Object clone(Object o)
3271
+ {
3272
+ try
3273
+ {
3274
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3275
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3276
+
3277
+ out.writeObject(o);
3278
+
3279
+ out.flush();
3280
+ out.close();
3281
+
3282
+ byte[] bytes = baos.toByteArray();
3283
+
3284
+ System.out.println("clone = " + bytes.length);
3285
+
3286
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3287
+ ObjectInputStream in = new ObjectInputStream(bais);
3288
+ Object obj = in.readObject();
3289
+ in.close();
3290
+
3291
+ return obj;
3292
+ } catch (Exception e)
3293
+ {
3294
+ System.err.println(e);
3295
+ return null;
3296
+ }
3297
+ }
3298
+
3299
+ cRadio GetCurrentTab()
3300
+ {
3301
+ cRadio ab;
3302
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3303
+ {
3304
+ ab = (cRadio)e.nextElement();
3305
+ if(ab.GetObject() == copy)
3306
+ {
3307
+ return ab;
3308
+ }
3309
+ }
3310
+
3311
+ return null;
3312
+ }
3313
+
3314
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3315
+
32403316 public void Save()
32413317 {
3242
- if (true) return;
3318
+ cRadio tab = GetCurrentTab();
3319
+
3320
+ boolean temp = CameraPane.SWITCH;
3321
+ CameraPane.SWITCH = false;
3322
+
3323
+ copy.ExtractBigData(hashtable);
32433324
32443325 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3326
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463327
3247
- for (int i = undoindex; i < graphs.length; i++)
3328
+ copy.RestoreBigData(hashtable);
3329
+
3330
+ CameraPane.SWITCH = temp;
3331
+
3332
+ //assert(hashtable.isEmpty());
3333
+
3334
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483335 {
3249
- graphs[i] = null;
3336
+ tab.graphs[i] = null;
32503337 }
32513338
32523339 // test save
....@@ -3254,7 +3341,7 @@
32543341 {
32553342 try
32563343 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3344
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583345 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593346
32603347 p.writeObject(copy);
....@@ -3269,48 +3356,81 @@
32693356 }
32703357 }
32713358
3359
+ void CopyChanged(Object3D obj)
3360
+ {
3361
+ boolean temp = CameraPane.SWITCH;
3362
+ CameraPane.SWITCH = false;
3363
+
3364
+ copy.ExtractBigData(hashtable);
3365
+
3366
+ copy.clear();
3367
+
3368
+ for (int i=0; i<obj.Size(); i++)
3369
+ {
3370
+ copy.add(obj.get(i));
3371
+ }
3372
+
3373
+ copy.RestoreBigData(hashtable);
3374
+
3375
+ CameraPane.SWITCH = temp;
3376
+
3377
+ //assert(hashtable.isEmpty());
3378
+
3379
+ copy.Touch();
3380
+
3381
+ ResetModel();
3382
+ copy.HardTouch(); // recompile?
3383
+
3384
+ cRadio ab;
3385
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3386
+ {
3387
+ ab = (cRadio)e.nextElement();
3388
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3389
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3390
+ if (test != null)
3391
+ {
3392
+ test.editWindow = ab.object.editWindow;
3393
+ ab.object = test;
3394
+ }
3395
+ }
3396
+
3397
+ refreshContents();
3398
+ }
3399
+
32723400 public void Undo()
32733401 {
3274
- if (undoindex == 0)
3402
+ cRadio tab = GetCurrentTab();
3403
+
3404
+ if (tab.undoindex == 0)
32753405 {
32763406 java.awt.Toolkit.getDefaultToolkit().beep();
32773407 return;
32783408 }
32793409
3280
- if (graphs[undoindex] == null)
3410
+ if (tab.graphs[tab.undoindex] == null)
32813411 {
32823412 Save();
3283
- undoindex -= 1;
3413
+ tab.undoindex -= 1;
32843414 }
32853415
3286
- undoindex -= 1;
3416
+ tab.undoindex -= 1;
32873417
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3418
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953419 }
32963420
32973421 public void Redo()
32983422 {
3299
- if (graphs[undoindex + 1] == null)
3423
+ cRadio tab = GetCurrentTab();
3424
+
3425
+ if (tab.graphs[tab.undoindex + 1] == null)
33003426 {
33013427 java.awt.Toolkit.getDefaultToolkit().beep();
33023428 return;
33033429 }
33043430
3305
- undoindex += 1;
3431
+ tab.undoindex += 1;
33063432
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3433
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143434 }
33153435
33163436 void ImportGFD()
....@@ -4181,6 +4301,7 @@
41814301
41824302 try
41834303 {
4304
+ // Try compressed version first.
41844305 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
41854306 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
41864307 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4250,6 +4371,12 @@
42504371
42514372 void LoadIt(Object obj)
42524373 {
4374
+ if (obj == null)
4375
+ {
4376
+ // Invalid file
4377
+ return;
4378
+ }
4379
+
42534380 System.out.println("Loaded " + obj);
42544381 //new Exception().printStackTrace();
42554382 Object3D readobj = (Object3D) obj;
....@@ -4259,6 +4386,7 @@
42594386
42604387 if (readobj != null)
42614388 {
4389
+ Save();
42624390 try
42634391 {
42644392 //readobj.deepCopySelf(copy);