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)
....@@ -3207,10 +3215,224 @@
32073215 {
32083216 copy.remove(1);
32093217 }
3218
+
32103219 ResetModel();
32113220 objEditor.refreshContents();
32123221 }
32133222
3223
+ static public byte[] Compress(Object3D o)
3224
+ {
3225
+ try
3226
+ {
3227
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3228
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3229
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
3230
+
3231
+ Object3D parent = o.parent;
3232
+ o.parent = null;
3233
+
3234
+ out.writeObject(o);
3235
+
3236
+ o.parent = parent;
3237
+
3238
+ out.flush();
3239
+
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);
3259
+ Object obj = in.readObject();
3260
+ in.close();
3261
+
3262
+ return obj;
3263
+ } catch (Exception e)
3264
+ {
3265
+ System.err.println(e);
3266
+ return null;
3267
+ }
3268
+ }
3269
+
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
+
3316
+ public void Save()
3317
+ {
3318
+ cRadio tab = GetCurrentTab();
3319
+
3320
+ boolean temp = CameraPane.SWITCH;
3321
+ CameraPane.SWITCH = false;
3322
+
3323
+ copy.ExtractBigData(hashtable);
3324
+
3325
+ //EditorFrame.m_MainFrame.requestFocusInWindow();
3326
+ tab.graphs[tab.undoindex++] = Compress(copy);
3327
+
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++)
3335
+ {
3336
+ tab.graphs[i] = null;
3337
+ }
3338
+
3339
+ // test save
3340
+ if (false)
3341
+ {
3342
+ try
3343
+ {
3344
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3345
+ ObjectOutputStream p = new ObjectOutputStream(ostream);
3346
+
3347
+ p.writeObject(copy);
3348
+
3349
+ p.flush();
3350
+
3351
+ ostream.close();
3352
+ } catch (Exception e)
3353
+ {
3354
+ e.printStackTrace();
3355
+ }
3356
+ }
3357
+ }
3358
+
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
+
3400
+ public void Undo()
3401
+ {
3402
+ cRadio tab = GetCurrentTab();
3403
+
3404
+ if (tab.undoindex == 0)
3405
+ {
3406
+ java.awt.Toolkit.getDefaultToolkit().beep();
3407
+ return;
3408
+ }
3409
+
3410
+ if (tab.graphs[tab.undoindex] == null)
3411
+ {
3412
+ Save();
3413
+ tab.undoindex -= 1;
3414
+ }
3415
+
3416
+ tab.undoindex -= 1;
3417
+
3418
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3419
+ }
3420
+
3421
+ public void Redo()
3422
+ {
3423
+ cRadio tab = GetCurrentTab();
3424
+
3425
+ if (tab.graphs[tab.undoindex + 1] == null)
3426
+ {
3427
+ java.awt.Toolkit.getDefaultToolkit().beep();
3428
+ return;
3429
+ }
3430
+
3431
+ tab.undoindex += 1;
3432
+
3433
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3434
+ }
3435
+
32143436 void ImportGFD()
32153437 {
32163438 FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD);
....@@ -3855,6 +4077,7 @@
38554077
38564078 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
38574079 {
4080
+ Save();
38584081 //Tween.set(thing, 0).target(1).start(tweenManager);
38594082 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
38604083 // if (thing instanceof GenericJointDemo)
....@@ -4078,6 +4301,7 @@
40784301
40794302 try
40804303 {
4304
+ // Try compressed version first.
40814305 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
40824306 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
40834307 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4147,6 +4371,12 @@
41474371
41484372 void LoadIt(Object obj)
41494373 {
4374
+ if (obj == null)
4375
+ {
4376
+ // Invalid file
4377
+ return;
4378
+ }
4379
+
41504380 System.out.println("Loaded " + obj);
41514381 //new Exception().printStackTrace();
41524382 Object3D readobj = (Object3D) obj;
....@@ -4156,6 +4386,7 @@
41564386
41574387 if (readobj != null)
41584388 {
4389
+ Save();
41594390 try
41604391 {
41614392 //readobj.deepCopySelf(copy);