Normand Briere
2019-06-16 7b6b5ba546450e71ecc812356952b594acc5add5
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");
....@@ -419,10 +419,10 @@
419419 e.printStackTrace();
420420 }
421421
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();
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();
426426 //clipboard.setContents(data, data);
427427 }
428428
....@@ -2072,19 +2072,19 @@
20722072
20732073 void LoadObjFile(String fullname)
20742074 {
2075
- /*
2075
+ System.out.println("Loading " + fullname);
2076
+ /**/
20762077 //lastFilename = fullname;
20772078 if(loadObjThread == null)
20782079 {
2079
- loadObjThread = new LoadOBJThread();
2080
- loadObjThread.start();
2080
+ loadObjThread = new LoadOBJThread();
2081
+ loadObjThread.start();
20812082 }
20822083
20832084 loadObjThread.add(fullname);
2084
- */
2085
+ /**/
20852086
2086
- System.out.println("Loading " + fullname);
2087
- makeSomething(new FileObject(fullname, true), true);
2087
+ //makeSomething(new FileObject(fullname, true), true);
20882088 }
20892089
20902090 void LoadGFDFile(String fullname)
....@@ -2927,7 +2927,7 @@
29272927 return;
29282928 } else if (event.getSource() == toggleSwitchItem)
29292929 {
2930
- cameraView.ToggleRandom();
2930
+ cameraView.ToggleSwitch();
29312931 cameraView.repaint();
29322932 return;
29332933 } else if (event.getSource() == toggleHandleItem)
....@@ -3214,6 +3214,53 @@
32143214 objEditor.refreshContents();
32153215 }
32163216
3217
+ static public byte[] Compress(Object3D o)
3218
+ {
3219
+ try
3220
+ {
3221
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
3222
+ java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3223
+ ObjectOutputStream out = new ObjectOutputStream(zstream);
3224
+
3225
+ Object3D parent = o.parent;
3226
+ o.parent = null;
3227
+
3228
+ out.writeObject(o);
3229
+
3230
+ o.parent = parent;
3231
+
3232
+ out.flush();
3233
+
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);
3253
+ Object obj = in.readObject();
3254
+ in.close();
3255
+
3256
+ return obj;
3257
+ } catch (Exception e)
3258
+ {
3259
+ System.err.println(e);
3260
+ return null;
3261
+ }
3262
+ }
3263
+
32173264 static public Object clone(Object o)
32183265 {
32193266 try
....@@ -3222,12 +3269,19 @@
32223269 ObjectOutputStream out = new ObjectOutputStream(baos);
32233270
32243271 out.writeObject(o);
3272
+
3273
+ out.flush();
3274
+ out.close();
3275
+
3276
+ byte[] bytes = baos.toByteArray();
3277
+
3278
+ System.out.println("clone = " + bytes.length);
32253279
3226
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
3280
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
32273281 ObjectInputStream in = new ObjectInputStream(bais);
32283282 Object obj = in.readObject();
32293283 in.close();
3230
- out.close();
3284
+
32313285 return obj;
32323286 } catch (Exception e)
32333287 {
....@@ -3251,13 +3305,26 @@
32513305 return null;
32523306 }
32533307
3308
+ java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
3309
+
32543310 public void Save()
32553311 {
32563312 cRadio tab = GetCurrentTab();
32573313
3314
+ boolean temp = CameraPane.SWITCH;
3315
+ CameraPane.SWITCH = false;
3316
+
3317
+ copy.ExtractBigData(hashtable);
3318
+
32583319 //EditorFrame.m_MainFrame.requestFocusInWindow();
3259
- tab.graphs[tab.undoindex++] = (Object3D)clone(copy);
3320
+ tab.graphs[tab.undoindex++] = Compress(copy);
32603321
3322
+ copy.RestoreBigData(hashtable);
3323
+
3324
+ CameraPane.SWITCH = temp;
3325
+
3326
+ //assert(hashtable.isEmpty());
3327
+
32613328 for (int i = tab.undoindex; i < tab.graphs.length; i++)
32623329 {
32633330 tab.graphs[i] = null;
....@@ -3285,12 +3352,23 @@
32853352
32863353 void CopyChanged(Object3D obj)
32873354 {
3355
+ boolean temp = CameraPane.SWITCH;
3356
+ CameraPane.SWITCH = false;
3357
+
3358
+ copy.ExtractBigData(hashtable);
3359
+
32883360 copy.clear();
32893361
32903362 for (int i=0; i<obj.Size(); i++)
32913363 {
32923364 copy.add(obj.get(i));
32933365 }
3366
+
3367
+ copy.RestoreBigData(hashtable);
3368
+
3369
+ CameraPane.SWITCH = temp;
3370
+
3371
+ //assert(hashtable.isEmpty());
32943372
32953373 copy.Touch();
32963374
....@@ -3331,7 +3409,7 @@
33313409
33323410 tab.undoindex -= 1;
33333411
3334
- CopyChanged(tab.graphs[tab.undoindex]);
3412
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33353413 }
33363414
33373415 public void Redo()
....@@ -3346,7 +3424,7 @@
33463424
33473425 tab.undoindex += 1;
33483426
3349
- CopyChanged(tab.graphs[tab.undoindex]);
3427
+ CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
33503428 }
33513429
33523430 void ImportGFD()
....@@ -4217,6 +4295,7 @@
42174295
42184296 try
42194297 {
4298
+ // Try compressed version first.
42204299 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
42214300 java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
42224301 java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
....@@ -4286,6 +4365,12 @@
42864365
42874366 void LoadIt(Object obj)
42884367 {
4368
+ if (obj == null)
4369
+ {
4370
+ // Invalid file
4371
+ return;
4372
+ }
4373
+
42894374 System.out.println("Loaded " + obj);
42904375 //new Exception().printStackTrace();
42914376 Object3D readobj = (Object3D) obj;
....@@ -4295,6 +4380,7 @@
42954380
42964381 if (readobj != null)
42974382 {
4383
+ Save();
42984384 try
42994385 {
43004386 //readobj.deepCopySelf(copy);