Skip to content

Commit b827d21

Browse files
committed
Merge branch 'main' of git@github.com:CommonWealthRobotics/CaDoodle-Application.git into main
2 parents 21d20fa + 2377d29 commit b827d21

File tree

4 files changed

+76
-67
lines changed

4 files changed

+76
-67
lines changed

BowlerStudio

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.neuronrobotics.bowlerstudio.SplashManager;
2727
import com.neuronrobotics.bowlerstudio.scripting.DownloadManager;
2828
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.CaDoodleFile;
29+
import com.neuronrobotics.bowlerstudio.scripting.cadoodle.RandomStringFactory;
2930
import com.neuronrobotics.bowlerstudio.threed.BowlerStudio3dEngine;
3031
import com.neuronrobotics.sdk.common.Log;
3132

@@ -231,14 +232,17 @@ private void openProject(CaDoodleFile c) {
231232
File doodle = new File(target.getAbsolutePath() + DownloadManager.delim() + c.getSelf().getName());
232233

233234
CaDoodleFile nf = CaDoodleFile.fromFile(doodle, null, false);
234-
nf.setProjectName(c.getMyProjectName() + "_copy_" + index);
235+
nf.setProjectName(RandomStringFactory.getNextRandomName()+"_"+c.getMyProjectName() + "_copy_" + index);
235236
nf.setTimeCreated(System.currentTimeMillis());
236-
nf.save();
237+
nf.save(true);
237238
ap.setActiveProject(doodle);
239+
240+
238241
}
239242
ap.get().initialize();
240243
SplashManager.closeSplash();
241244
onFinish.run();
245+
ap.save();
242246
} catch (Exception e) {
243247
// Auto-generated catch block
244248
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;
@@ -1992,66 +1991,7 @@ public void moveInCameraFrame(TransformNR stateUnitVectorTmp) {
19921991
}
19931992

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

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

0 commit comments

Comments
 (0)