Normand Briere
2019-06-11 d0dc7ff35d71919d503ae35592478b173cf3cfd3
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
....@@ -3212,23 +3214,39 @@
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
+ try
3243
+ {
3244
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3245
+ java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3246
+ ObjectInputStream in = new ObjectInputStream(istream);
32293247 Object obj = in.readObject();
32303248 in.close();
3231
- out.close();
3249
+
32323250 return obj;
32333251 } catch (Exception e)
32343252 {
....@@ -3237,16 +3255,68 @@
32373255 }
32383256 }
32393257
3258
+ static public Object clone(Object o)
3259
+ {
3260
+ try
3261
+ {
3262
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3263
+ ObjectOutputStream out = new ObjectOutputStream(baos);
3264
+
3265
+ out.writeObject(o);
3266
+
3267
+ out.flush();
3268
+ out.close();
3269
+
3270
+ byte[] bytes = baos.toByteArray();
3271
+
3272
+ System.out.println("clone = " + bytes.length);
3273
+
3274
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3275
+ ObjectInputStream in = new ObjectInputStream(bais);
3276
+ Object obj = in.readObject();
3277
+ in.close();
3278
+
3279
+ return obj;
3280
+ } catch (Exception e)
3281
+ {
3282
+ System.err.println(e);
3283
+ return null;
3284
+ }
3285
+ }
3286
+
3287
+ cRadio GetCurrentTab()
3288
+ {
3289
+ cRadio ab;
3290
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3291
+ {
3292
+ ab = (cRadio)e.nextElement();
3293
+ if(ab.GetObject() == copy)
3294
+ {
3295
+ return ab;
3296
+ }
3297
+ }
3298
+
3299
+ return null;
3300
+ }
3301
+
3302
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3303
+
32403304 public void Save()
32413305 {
3242
- if (true) return;
3306
+ cRadio tab = GetCurrentTab();
3307
+
3308
+ copy.ExtractBigData(hashtable);
32433309
32443310 //EditorFrame.m_MainFrame.requestFocusInWindow();
3245
- graphs[undoindex++] = (Object3D)clone(copy);
3311
+ tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
32463312
3247
- for (int i = undoindex; i < graphs.length; i++)
3313
+ copy.RestoreBigData(hashtable);
3314
+
3315
+ //assert(hashtable.isEmpty());
3316
+
3317
+ for (int i = tab.undoindex; i < tab.graphs.length; i++)
32483318 {
3249
- graphs[i] = null;
3319
+ tab.graphs[i] = null;
32503320 }
32513321
32523322 // test save
....@@ -3254,7 +3324,7 @@
32543324 {
32553325 try
32563326 {
3257
- FileOutputStream ostream = new FileOutputStream("save" + undoindex);
3327
+ FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
32583328 ObjectOutputStream p = new ObjectOutputStream(ostream);
32593329
32603330 p.writeObject(copy);
....@@ -3269,48 +3339,76 @@
32693339 }
32703340 }
32713341
3342
+ void CopyChanged(Object3D obj)
3343
+ {
3344
+ copy.ExtractBigData(hashtable);
3345
+
3346
+ copy.clear();
3347
+
3348
+ for (int i=0; i<obj.Size(); i++)
3349
+ {
3350
+ copy.add(obj.get(i));
3351
+ }
3352
+
3353
+ copy.RestoreBigData(hashtable);
3354
+
3355
+ //assert(hashtable.isEmpty());
3356
+
3357
+ copy.Touch();
3358
+
3359
+ ResetModel();
3360
+ copy.HardTouch(); // recompile?
3361
+
3362
+ cRadio ab;
3363
+ for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
3364
+ {
3365
+ ab = (cRadio)e.nextElement();
3366
+ Object3D test = copy.GetObject(ab.object.GetUUID());
3367
+ //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
3368
+ if (test != null)
3369
+ {
3370
+ test.editWindow = ab.object.editWindow;
3371
+ ab.object = test;
3372
+ }
3373
+ }
3374
+
3375
+ refreshContents();
3376
+ }
3377
+
32723378 public void Undo()
32733379 {
3274
- if (undoindex == 0)
3380
+ cRadio tab = GetCurrentTab();
3381
+
3382
+ if (tab.undoindex == 0)
32753383 {
32763384 java.awt.Toolkit.getDefaultToolkit().beep();
32773385 return;
32783386 }
32793387
3280
- if (graphs[undoindex] == null)
3388
+ if (tab.graphs[tab.undoindex] == null)
32813389 {
32823390 Save();
3283
- undoindex -= 1;
3391
+ tab.undoindex -= 1;
32843392 }
32853393
3286
- undoindex -= 1;
3394
+ tab.undoindex -= 1;
32873395
3288
- copy = graphs[undoindex];
3289
-
3290
- cameraView.object = copy;
3291
- copy.Touch();
3292
-
3293
- ResetModel();
3294
- refreshContents();
3396
+ CopyChanged(tab.graphs[tab.undoindex]);
32953397 }
32963398
32973399 public void Redo()
32983400 {
3299
- if (graphs[undoindex + 1] == null)
3401
+ cRadio tab = GetCurrentTab();
3402
+
3403
+ if (tab.graphs[tab.undoindex + 1] == null)
33003404 {
33013405 java.awt.Toolkit.getDefaultToolkit().beep();
33023406 return;
33033407 }
33043408
3305
- undoindex += 1;
3409
+ tab.undoindex += 1;
33063410
3307
- copy = graphs[undoindex];
3308
-
3309
- cameraView.object = copy;
3310
- copy.Touch();
3311
-
3312
- ResetModel();
3313
- refreshContents();
3411
+ CopyChanged(tab.graphs[tab.undoindex]);
33143412 }
33153413
33163414 void ImportGFD()
....@@ -4259,6 +4357,7 @@
42594357
42604358 if (readobj != null)
42614359 {
4360
+ Save();
42624361 try
42634362 {
42644363 //readobj.deepCopySelf(copy);