Normand Briere
2019-06-13 4629090fafbef256abd0686a85ee12042d658868
ObjEditor.java
....@@ -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
....@@ -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,40 @@
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(Object 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
32253225 out.writeObject(o);
3226
+
3227
+ out.flush();
32263228
3227
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3228
- ObjectInputStream in = new ObjectInputStream(bais);
3229
+ zstream.close();
3230
+ out.close();
3231
+
3232
+ return baos.toByteArray();
3233
+ } catch (Exception e)
3234
+ {
3235
+ System.err.println(e);
3236
+ return null;
3237
+ }
3238
+ }
3239
+
3240
+ static public Object Uncompress(byte[] bytes)
3241
+ {
3242
+ System.out.println("#bytes = " + bytes.length);
3243
+ try
3244
+ {
3245
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3246
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3247
+ ObjectInputStream in = new ObjectInputStream(istream);
32293248 Object obj = in.readObject();
32303249 in.close();
3231
- out.close();
3250
+
32323251 return obj;
32333252 } catch (Exception e)
32343253 {
....@@ -3237,16 +3256,73 @@
32373256 }
32383257 }
32393258
3259
+ static public Object clone(Object o)
3260
+ {
3261
+ try
3262
+ {
3263
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3264
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3265
+
3266
+ out.writeObject(o);
3267
+
3268
+ out.flush();
3269
+ out.close();
3270
+
3271
+ byte[] bytes = baos.toByteArray();
3272
+
3273
+ System.out.println("clone = " + bytes.length);
3274
+
3275
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3276
+ ObjectInputStream in = new ObjectInputStream(bais);
3277
+ Object obj = in.readObject();
3278
+ in.close();
3279
+
3280
+ return obj;
3281
+ } catch (Exception e)
3282
+ {
3283
+ System.err.println(e);
3284
+ return null;
3285
+ }
3286
+ }
3287
+
3288
+ cRadio GetCurrentTab()
3289
+ {
3290
+ cRadio ab;
3291
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3292
+ {
3293
+ ab = (cRadio)e.nextElement();
3294
+ if(ab.GetObject() == copy)
3295
+ {
3296
+ return ab;
3297
+ }
3298
+ }
3299
+
3300
+ return null;
3301
+ }
3302
+
3303
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3304
+
32403305 public void Save()
32413306 {
3242
- if (true) return;
3307
+ cRadio tab = GetCurrentTab();
3308
+
3309
+ boolean temp = CameraPane.SWITCH;
3310
+ CameraPane.SWITCH = false;
3311
+
3312
+ copy.ExtractBigData(hashtable);
32433313
32443314 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3315
+ tab.graphs[tab.undoindex++] = Compress(copy);
32463316
3247
- for (int i = undoindex; i < graphs.length; i++)
3317
+ copy.RestoreBigData(hashtable);
3318
+
3319
+ CameraPane.SWITCH = temp;
3320
+
3321
+ //assert(hashtable.isEmpty());
3322
+
3323
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483324 {
3249
- graphs[i] = null;
3325
+ tab.graphs[i] = null;
32503326 }
32513327
32523328 // test save
....@@ -3254,7 +3330,7 @@
32543330 {
32553331 try
32563332 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3333
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583334 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593335
32603336 p.writeObject(copy);
....@@ -3269,48 +3345,81 @@
32693345 }
32703346 }
32713347
3348
+ void CopyChanged(Object3D obj)
3349
+ {
3350
+ boolean temp = CameraPane.SWITCH;
3351
+ CameraPane.SWITCH = false;
3352
+
3353
+ copy.ExtractBigData(hashtable);
3354
+
3355
+ copy.clear();
3356
+
3357
+ for (int i=0; i<obj.Size(); i++)
3358
+ {
3359
+ copy.add(obj.get(i));
3360
+ }
3361
+
3362
+ copy.RestoreBigData(hashtable);
3363
+
3364
+ CameraPane.SWITCH = temp;
3365
+
3366
+ //assert(hashtable.isEmpty());
3367
+
3368
+ copy.Touch();
3369
+
3370
+ ResetModel();
3371
+ copy.HardTouch(); // recompile?
3372
+
3373
+ cRadio ab;
3374
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3375
+ {
3376
+ ab = (cRadio)e.nextElement();
3377
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3378
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3379
+ if (test != null)
3380
+ {
3381
+ test.editWindow = ab.object.editWindow;
3382
+ ab.object = test;
3383
+ }
3384
+ }
3385
+
3386
+ refreshContents();
3387
+ }
3388
+
32723389 public void Undo()
32733390 {
3274
- if (undoindex == 0)
3391
+ cRadio tab = GetCurrentTab();
3392
+
3393
+ if (tab.undoindex == 0)
32753394 {
32763395 java.awt.Toolkit.getDefaultToolkit().beep();
32773396 return;
32783397 }
32793398
3280
- if (graphs[undoindex] == null)
3399
+ if (tab.graphs[tab.undoindex] == null)
32813400 {
32823401 Save();
3283
- undoindex -= 1;
3402
+ tab.undoindex -= 1;
32843403 }
32853404
3286
- undoindex -= 1;
3405
+ tab.undoindex -= 1;
32873406
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3407
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
32953408 }
32963409
32973410 public void Redo()
32983411 {
3299
- if (graphs[undoindex + 1] == null)
3412
+ cRadio tab = GetCurrentTab();
3413
+
3414
+ if (tab.graphs[tab.undoindex + 1] == null)
33003415 {
33013416 java.awt.Toolkit.getDefaultToolkit().beep();
33023417 return;
33033418 }
33043419
3305
- undoindex += 1;
3420
+ tab.undoindex += 1;
33063421
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3422
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33143423 }
33153424
33163425 void ImportGFD()
....@@ -4259,6 +4368,7 @@
42594368
42604369 if (readobj != null)
42614370 {
4371
+ Save();
42624372 try
42634373 {
42644374 //readobj.deepCopySelf(copy);