Skip to content

Commit 701d4d9

Browse files
committed
close #206
The new save overwrite protection was preventing copies from getting initialized.
1 parent b18151c commit 701d4d9

File tree

3 files changed

+72
-65
lines changed

3 files changed

+72
-65
lines changed

src/main/java/com/commonwealthrobotics/ActiveProject.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public class ActiveProject implements ICaDoodleStateUpdate {
8686
private ArrayList<ICaDoodleStateUpdate> listeners = new ArrayList<ICaDoodleStateUpdate>();
8787
// private boolean isAlwaysAccept=false;
8888
// private boolean isAlwaysInsert=false;
89-
89+
private Thread autosaveThread = null;
90+
private boolean needsSave = false;
9091
public ActiveProject() {
9192
// this.listener = listener;
9293

@@ -179,6 +180,7 @@ public CaDoodleFile setActiveProject(File f) throws Exception {
179180
if (fromFile != null) {
180181
fromFile.removeListener(this);
181182
}
183+
autosaveThread=null;
182184
ConfigurationDatabase.put("CaDoodle", "CaDoodleActiveFile", f.getAbsolutePath());
183185
return loadActive();
184186
}
@@ -395,7 +397,7 @@ public OperationResult accept() {
395397
}
396398
}
397399

398-
public void save(CaDoodleFile cf) throws SaveOverwriteException {
400+
private void save(CaDoodleFile cf) throws SaveOverwriteException {
399401
try {
400402
cf.setSelf(getActiveProject());
401403
} catch (Exception e) {
@@ -666,4 +668,67 @@ public void loadFromZip(File file) {
666668
}
667669
Log.debug("Extraction complete, NO DOODLE FOUND IN TL!");
668670
}
671+
672+
public void save() {
673+
// com.neuronrobotics.sdk.common.Log.error("Save Requested");
674+
needsSave = true;
675+
// new Exception("Auto-save called here").printStackTrace();
676+
if (autosaveThread == null) {
677+
autosaveThread = new Thread(() -> {
678+
while (!get().isInitialized()) {
679+
try {
680+
Thread.sleep(100);
681+
} catch (InterruptedException e) {
682+
e.printStackTrace();
683+
}
684+
}
685+
686+
while (isOpen()) {
687+
if (needsSave && (get().timeSinceLastUpdate() > 1000)) {
688+
ICadoodleSaveStatusUpdate saveDisplay = get().getSaveUpdate();
689+
get().setSaveUpdate(null);
690+
691+
Thread t = new Thread(() -> {
692+
com.neuronrobotics.sdk.common.Log
693+
.debug("Auto save " + get().getSelf().getAbsolutePath());
694+
try {
695+
save(get());
696+
} catch (SaveOverwriteException e) {
697+
Log.error(e);
698+
}
699+
});
700+
t.start();
701+
702+
needsSave = false;
703+
try {
704+
Thread.sleep(300);
705+
} catch (InterruptedException e) {
706+
com.neuronrobotics.sdk.common.Log.error(e);
707+
}
708+
709+
get().setSaveUpdate(saveDisplay);
710+
if (t.isAlive() && get().isTimelineOpen())
711+
SplashManager.renderSplashFrame(99, "Saving Files");
712+
713+
try {
714+
t.join();
715+
} catch (InterruptedException e) {
716+
com.neuronrobotics.sdk.common.Log.error(e);
717+
}
718+
SplashManager.closeSplash();
719+
}
720+
721+
try {
722+
Thread.sleep(200);
723+
} catch (InterruptedException e) {
724+
// Auto-generated catch block
725+
com.neuronrobotics.sdk.common.Log.error(e);
726+
}
727+
}
728+
});
729+
730+
autosaveThread.setName("Auto-save thread");
731+
autosaveThread.start();
732+
}
733+
}
669734
}

src/main/java/com/commonwealthrobotics/ProjectManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ private void openProject(CaDoodleFile c) {
233233
CaDoodleFile nf = CaDoodleFile.fromFile(doodle, null, false);
234234
nf.setProjectName(c.getMyProjectName() + "_copy_" + index);
235235
nf.setTimeCreated(System.currentTimeMillis());
236-
nf.save();
237236
ap.setActiveProject(doodle);
237+
238+
238239
}
239240
ap.get().initialize();
240241
SplashManager.closeSplash();
241242
onFinish.run();
243+
ap.save();
242244
} catch (Exception e) {
243245
// Auto-generated catch block
244246
com.neuronrobotics.sdk.common.Log.error(e);

src/main/java/com/commonwealthrobotics/controls/SelectionSession.java

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ public class SelectionSession implements ICaDoodleStateUpdate {
136136
private double x;
137137
private double y;
138138
private double z;
139-
private Thread autosaveThread = null;
140-
private boolean needsSave = false;
139+
141140
private Affine selection = new Affine();
142141
private Manipulation manipulation = new Manipulation(selection, new Vector3d(1, 1, 0), new TransformNR(), this::sendNewWorldPosition, false);
143142
private Point3D startingPosition3D;
@@ -1993,66 +1992,7 @@ public void moveInCameraFrame(TransformNR stateUnitVectorTmp) {
19931992
}
19941993

19951994
public void save() {
1996-
// com.neuronrobotics.sdk.common.Log.error("Save Requested");
1997-
needsSave = true;
1998-
// new Exception("Auto-save called here").printStackTrace();
1999-
if (autosaveThread == null) {
2000-
autosaveThread = new Thread(() -> {
2001-
while (!ap.get().isInitialized()) {
2002-
try {
2003-
Thread.sleep(100);
2004-
} catch (InterruptedException e) {
2005-
e.printStackTrace();
2006-
}
2007-
}
2008-
2009-
while (ap.isOpen()) {
2010-
if (needsSave && (ap.get().timeSinceLastUpdate() > 1000)) {
2011-
ICadoodleSaveStatusUpdate saveDisplay = ap.get().getSaveUpdate();
2012-
ap.get().setSaveUpdate(null);
2013-
2014-
Thread t = new Thread(() -> {
2015-
com.neuronrobotics.sdk.common.Log
2016-
.debug("Auto save " + ap.get().getSelf().getAbsolutePath());
2017-
try {
2018-
ap.save(ap.get());
2019-
} catch (SaveOverwriteException e) {
2020-
Log.error(e);
2021-
}
2022-
});
2023-
t.start();
2024-
2025-
needsSave = false;
2026-
try {
2027-
Thread.sleep(300);
2028-
} catch (InterruptedException e) {
2029-
com.neuronrobotics.sdk.common.Log.error(e);
2030-
}
2031-
2032-
ap.get().setSaveUpdate(saveDisplay);
2033-
if (t.isAlive() && ap.get().isTimelineOpen())
2034-
SplashManager.renderSplashFrame(99, "Saving Files");
2035-
2036-
try {
2037-
t.join();
2038-
} catch (InterruptedException e) {
2039-
com.neuronrobotics.sdk.common.Log.error(e);
2040-
}
2041-
SplashManager.closeSplash();
2042-
}
2043-
2044-
try {
2045-
Thread.sleep(200);
2046-
} catch (InterruptedException e) {
2047-
// Auto-generated catch block
2048-
com.neuronrobotics.sdk.common.Log.error(e);
2049-
}
2050-
}
2051-
});
2052-
2053-
autosaveThread.setName("Auto-save thread");
2054-
autosaveThread.start();
2055-
}
1995+
ap.save();
20561996
}
20571997

20581998
public boolean compareLists(List<String> list1, List<String> list2) {

0 commit comments

Comments
 (0)