Skip to content

Commit 93ac458

Browse files
committed
Ensure models load even with errors
1 parent 6e79bfe commit 93ac458

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleFile.java

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public void initialize() {
295295
opperations = opperations.stream().filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));
296296
if (indexStarting > opperations.size())
297297
indexStarting = opperations.size();
298+
ArrayList<CaDoodleOperation> toRem = new ArrayList<CaDoodleOperation>();
298299
for (int i = 0; i < getOpperations().size(); i++) {
299300
CaDoodleOperation op = getOpperations().get(i);
300301
if (op == null)
@@ -306,11 +307,15 @@ public void initialize() {
306307
process(op);
307308
} catch (Throwable t) {
308309
com.neuronrobotics.sdk.common.Log.error(t);
309-
indexStarting = i + 1;
310-
break;
311-
// opperations.remove(op);
310+
//indexStarting = i ;
311+
//break;
312+
//toRem.add(op);
312313
}
313314
}
315+
//opperations.removeAll(toRem);
316+
// if(indexStarting>opperations.size()) {
317+
// indexStarting = opperations.size();
318+
// }
314319
setCurrentIndex(indexStarting);
315320
updateCurrentFromCache();
316321
loadImageFromFile();
@@ -499,18 +504,31 @@ public void run() {
499504

500505
}
501506

502-
private void process(CaDoodleOperation op) {
507+
private void process(CaDoodleOperation op) throws Exception{
503508
op.setCaDoodleFile(this);
504-
List<CSG> process = op.process(getCurrentState());
505-
if (MakeRobot.class.isInstance(op)) {
506-
MakeRobot mr = (MakeRobot) op;
507-
getRobots().put(mr.getName(), mr.getBuilder());
509+
List<CSG> process=null;
510+
Exception ex=null;
511+
try {
512+
process= op.process(getCurrentState());
513+
if (MakeRobot.class.isInstance(op)) {
514+
MakeRobot mr = (MakeRobot) op;
515+
getRobots().put(mr.getName(), mr.getBuilder());
516+
}
517+
}catch(Exception ex1) {
518+
ex=ex1;
519+
}
520+
if(process==null) {
521+
process=getCurrentState();
522+
}
523+
if(process.size()==0) {
524+
Log.error("Nothing returned int he process step?");
508525
}
509526
int currentIndex2 = getCurrentIndex();
510527
storeResultInCache(op, process);
511528
setCurrentIndex(currentIndex2 + 1);
512529
setCurrentState(op, process);
513-
530+
if(ex!=null)
531+
throw ex;
514532
}
515533

516534
public boolean isOperationRunning() {
@@ -569,7 +587,12 @@ public void run() {
569587
}
570588
if (getResult() == OperationResult.INSERT) {
571589
getOpperations().add(getCurrentIndex(), op);
572-
process(op);
590+
try {
591+
process(op);
592+
} catch (Exception e) {
593+
// TODO Auto-generated catch block
594+
e.printStackTrace();
595+
}
573596
try {
574597
regenerateFrom(op).join();
575598
} catch (InterruptedException e) {
@@ -632,12 +655,12 @@ public void run() {
632655
return t;
633656
}
634657

635-
public static CSG getByName(List<CSG> back, String name) {
658+
public static CSG getByName(List<CSG> back, String name) throws NameMissingException{
636659
for (CSG c : back) {
637660
if (c.getName().contentEquals(name))
638661
return c;
639662
}
640-
throw new RuntimeException("Fail! there was no object named " + name);
663+
throw new NameMissingException("Fail! there was no object named " + name);
641664
}
642665

643666
public static int applyToAllConstituantElements(boolean addRet, List<String> targetNames, ArrayList<CSG> back,
@@ -649,10 +672,10 @@ public static int applyToAllConstituantElements(boolean addRet, List<String> tar
649672
CSG c = getByName(back, s);
650673
if (c.isInGroup())
651674
continue;
652-
} catch (Exception ex) {
653-
com.neuronrobotics.sdk.common.Log.error(ex);
654-
//continue;
675+
}catch(NameMissingException e) {
676+
continue;
655677
}
678+
656679
applyToAllConstituantElements(addRet, s, back, p, depth, appliedMemory);
657680
}
658681
return back.size();
@@ -755,8 +778,7 @@ private void storeResultInCache(CaDoodleOperation op, List<CSG> process) {
755778
HashSet<String> names = new HashSet<>();
756779
for (CSG c : process) {
757780
if (names.contains(c.getName()))
758-
throw new RuntimeException("There can not be 2 objects with the same name after an " + op.getType()
759-
+ " opperation! " + c.getName());
781+
continue;
760782
names.add(c.getName());
761783
CSG cachedVer = cloneCSG(c).setStorage(new PropertyStorage()).syncProperties(getCsgDBinstance(), c)
762784
.setName(c.getName()).setRegenerate(c.getRegenerate()).setID(c);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;
2+
3+
public class NameMissingException extends Exception {
4+
5+
public NameMissingException(String string) {
6+
super(string);
7+
}
8+
9+
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Paste.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,31 @@ public ArrayList<CSG> process(CSG ic, int depth) {
5454
},1);
5555

5656
for (String from : cpMap.keySet()) {
57-
CSG source = CaDoodleFile.getByName(back, from);
57+
CSG source;
58+
try {
59+
source = CaDoodleFile.getByName(back, from);
60+
} catch (NameMissingException e) {
61+
continue;
62+
}
5863
if (source.isGroupResult()) {
5964
ArrayList<String> c = constituants(back, from);
6065
if(c.size()<1) {
6166
new RuntimeException("A group result must have at least 1 constituants!").printStackTrace();;
6267
continue;
6368
}
64-
String newGroupName = CaDoodleFile.getByName(back, cpMap.get(from)).getName();
69+
String newGroupName;
70+
try {
71+
newGroupName = CaDoodleFile.getByName(back, cpMap.get(from)).getName();
72+
} catch (NameMissingException e) {
73+
continue;
74+
}
6575
for (String s : c) {
66-
CSG dest = CaDoodleFile.getByName(back, s);
76+
CSG dest;
77+
try {
78+
dest = CaDoodleFile.getByName(back, s);
79+
} catch (NameMissingException e) {
80+
continue;
81+
}
6782
dest.removeGroupMembership(from);
6883
dest.addGroupMembership(newGroupName);
6984
}
@@ -75,9 +90,19 @@ public ArrayList<CSG> process(CSG ic, int depth) {
7590
private ArrayList<String> constituants(ArrayList<CSG> b, String name) {
7691
ArrayList<String> c = new ArrayList<String>();
7792
for (String ky:cpMap.keySet()) {
78-
CSG byName = CaDoodleFile.getByName(b,ky);
93+
CSG byName;
94+
try {
95+
byName = CaDoodleFile.getByName(b,ky);
96+
} catch (NameMissingException e) {
97+
continue;
98+
}
7999
String name2 = cpMap.get(ky);
80-
CSG byName2 = CaDoodleFile.getByName(b,name2);
100+
CSG byName2;
101+
try {
102+
byName2 = CaDoodleFile.getByName(b,name2);
103+
} catch (NameMissingException e) {
104+
continue;
105+
}
81106
for(CSG csg:Arrays.asList(byName,byName2)){
82107
if (csg.checkGroupMembership(name)) {
83108
// only add objects that were created by this operation

0 commit comments

Comments
 (0)