Normand Briere
2019-06-16 372b7fd481a476cd659713a4a01bf28bf6760cbe
ObjEditor.java
....@@ -278,7 +278,7 @@
278278 frame.setMenuBar(menuBar = new MenuBar());
279279 menuBar.add(fileMenu = new Menu("File"));
280280 fileMenu.add(newItem = new MenuItem("New"));
281
- fileMenu.add(loadItem = new MenuItem("Load..."));
281
+ fileMenu.add(loadItem = new MenuItem("Open..."));
282282
283283 //oe.menuBar.add(menu = new Menu("Include"));
284284 Menu menu = new Menu("Import");
....@@ -1935,6 +1935,7 @@
19351935 e2.printStackTrace();
19361936 }
19371937 }
1938
+
19381939 LoadJMEThread loadThread;
19391940
19401941 class LoadJMEThread extends Thread
....@@ -1992,6 +1993,7 @@
19921993 //LoadFile0(filename, converter);
19931994 }
19941995 }
1996
+
19951997 LoadOBJThread loadObjThread;
19961998
19971999 class LoadOBJThread extends Thread
....@@ -2070,19 +2072,19 @@
20702072
20712073 void LoadObjFile(String fullname)
20722074 {
2073
- /*
2075
+ System.out.println("Loading " + fullname);
2076
+ /**/
20742077 //lastFilename = fullname;
20752078 if(loadObjThread == null)
20762079 {
2077
- loadObjThread = new LoadOBJThread();
2078
- loadObjThread.start();
2080
+ loadObjThread = new LoadOBJThread();
2081
+ loadObjThread.start();
20792082 }
20802083
20812084 loadObjThread.add(fullname);
2082
- */
2085
+ /**/
20832086
2084
- System.out.println("Loading " + fullname);
2085
- makeSomething(new FileObject(fullname, true), true);
2087
+ //makeSomething(new FileObject(fullname, true), true);
20862088 }
20872089
20882090 void LoadGFDFile(String fullname)
....@@ -2925,7 +2927,7 @@
29252927 return;
29262928 } else if (event.getSource() == toggleSwitchItem)
29272929 {
2928
- cameraView.ToggleRandom();
2930
+ cameraView.ToggleSwitch();
29292931 cameraView.repaint();
29302932 return;
29312933 } else if (event.getSource() == toggleHandleItem)
....@@ -3212,23 +3214,45 @@
32123214 objEditor.refreshContents();
32133215 }
32143216
3215
- Object3D graphs[] = new Object3D[10000];
3216
- int undoindex = 0;
3217
-
3218
- static public Object clone(Object o)
3217
+ static public byte[] Compress(Object3D o)
32193218 {
32203219 try
32213220 {
32223221 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3223
- ObjectOutputStream out = new ObjectOutputStream(baos);
3222
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3223
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
32243224
3225
+ Object3D parent = o.parent;
3226
+ o.parent = null;
3227
+
32253228 out.writeObject(o);
3229
+
3230
+ o.parent = parent;
3231
+
3232
+ out.flush();
32263233
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3234
+ zstream.close();
3235
+ out.close();
3236
+
3237
+ return baos.toByteArray();
3238
+ } catch (Exception e)
3239
+ {
3240
+ System.err.println(e);
3241
+ return null;
3242
+ }
3243
+ }
3244
+
3245
+ static public Object Uncompress(byte[] bytes)
3246
+ {
3247
+ System.out.println("#bytes = " + bytes.length);
3248
+ try
3249
+ {
3250
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3251
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3252
+ ObjectInputStream in = new ObjectInputStream(istream);
32293253 Object obj = in.readObject();
32303254 in.close();
3231
- out.close();
3255
+
32323256 return obj;
32333257 } catch (Exception e)
32343258 {
....@@ -3237,16 +3261,73 @@
32373261 }
32383262 }
32393263
3264
+ static public Object clone(Object o)
3265
+ {
3266
+ try
3267
+ {
3268
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3269
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3270
+
3271
+ out.writeObject(o);
3272
+
3273
+ out.flush();
3274
+ out.close();
3275
+
3276
+ byte[] bytes = baos.toByteArray();
3277
+
3278
+ System.out.println("clone = " + bytes.length);
3279
+
3280
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3281
+ ObjectInputStream in = new ObjectInputStream(bais);
3282
+ Object obj = in.readObject();
3283
+ in.close();
3284
+
3285
+ return obj;
3286
+ } catch (Exception e)
3287
+ {
3288
+ System.err.println(e);
3289
+ return null;
3290
+ }
3291
+ }
3292
+
3293
+ cRadio GetCurrentTab()
3294
+ {
3295
+ cRadio ab;
3296
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3297
+ {
3298
+ ab = (cRadio)e.nextElement();
3299
+ if(ab.GetObject() == copy)
3300
+ {
3301
+ return ab;
3302
+ }
3303
+ }
3304
+
3305
+ return null;
3306
+ }
3307
+
3308
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3309
+
32403310 public void Save()
32413311 {
3242
- if (true) return;
3312
+ cRadio tab = GetCurrentTab();
3313
+
3314
+ boolean temp = CameraPane.SWITCH;
3315
+ CameraPane.SWITCH = false;
3316
+
3317
+ copy.ExtractBigData(hashtable);
32433318
32443319 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3320
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463321
3247
- for (int i = undoindex; i < graphs.length; i++)
3322
+ copy.RestoreBigData(hashtable);
3323
+
3324
+ CameraPane.SWITCH = temp;
3325
+
3326
+ //assert(hashtable.isEmpty());
3327
+
3328
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483329 {
3249
- graphs[i] = null;
3330
+ tab.graphs[i] = null;
32503331 }
32513332
32523333 // test save
....@@ -3254,7 +3335,7 @@
32543335 {
32553336 try
32563337 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3338
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583339 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593340
32603341 p.writeObject(copy);
....@@ -3269,48 +3350,81 @@
32693350 }
32703351 }
32713352
3353
+ void CopyChanged(Object3D obj)
3354
+ {
3355
+ boolean temp = CameraPane.SWITCH;
3356
+ CameraPane.SWITCH = false;
3357
+
3358
+ copy.ExtractBigData(hashtable);
3359
+
3360
+ copy.clear();
3361
+
3362
+ for (int i=0; i<obj.Size(); i++)
3363
+ {
3364
+ copy.add(obj.get(i));
3365
+ }
3366
+
3367
+ copy.RestoreBigData(hashtable);
3368
+
3369
+ CameraPane.SWITCH = temp;
3370
+
3371
+ //assert(hashtable.isEmpty());
3372
+
3373
+ copy.Touch();
3374
+
3375
+ ResetModel();
3376
+ copy.HardTouch(); // recompile?
3377
+
3378
+ cRadio ab;
3379
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3380
+ {
3381
+ ab = (cRadio)e.nextElement();
3382
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3383
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3384
+ if (test != null)
3385
+ {
3386
+ test.editWindow = ab.object.editWindow;
3387
+ ab.object = test;
3388
+ }
3389
+ }
3390
+
3391
+ refreshContents();
3392
+ }
3393
+
32723394 public void Undo()
32733395 {
3274
- if (undoindex == 0)
3396
+ cRadio tab = GetCurrentTab();
3397
+
3398
+ if (tab.undoindex == 0)
32753399 {
32763400 java.awt.Toolkit.getDefaultToolkit().beep();
32773401 return;
32783402 }
32793403
3280
- if (graphs[undoindex] == null)
3404
+ if (tab.graphs[tab.undoindex] == null)
32813405 {
32823406 Save();
3283
- undoindex -= 1;
3407
+ tab.undoindex -= 1;
32843408 }
32853409
3286
- undoindex -= 1;
3410
+ tab.undoindex -= 1;
32873411
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3412
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953413 }
32963414
32973415 public void Redo()
32983416 {
3299
- if (graphs[undoindex + 1] == null)
3417
+ cRadio tab = GetCurrentTab();
3418
+
3419
+ if (tab.graphs[tab.undoindex + 1] == null)
33003420 {
33013421 java.awt.Toolkit.getDefaultToolkit().beep();
33023422 return;
33033423 }
33043424
3305
- undoindex += 1;
3425
+ tab.undoindex += 1;
33063426
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3427
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143428 }
33153429
33163430 void ImportGFD()
....@@ -4259,6 +4373,7 @@
42594373
42604374 if (readobj != null)
42614375 {
4376
+ Save();
42624377 try
42634378 {
42644379 //readobj.deepCopySelf(copy);