Skip to content

Commit 20e788a

Browse files
committed
Change the opperation options to include insertion
1 parent fa31576 commit 20e788a

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public Thread regenerateFrom(ICaDoodleOpperation source) {
223223
if (initializing)
224224
return null;
225225
if (isRegenerating() || isOperationRunning()) {
226-
com.neuronrobotics.sdk.common.Log.error("Opperation is running, ignoring regen");
226+
System.err.println("Opperation is running, ignoring regen");
227227
return null;
228228
}
229229
fireRegenerateStart();
@@ -255,7 +255,7 @@ public Thread regenerateFrom(ICaDoodleOpperation source) {
255255
int currentIndex2 = getCurrentIndex() - 1;
256256
ICaDoodleOpperation op = opperations.get(currentIndex2);
257257
List<CSG> process = op.process(getPreviouState());
258-
getTimelineImageFile(currentIndex2).delete();
258+
getTimelineImageFile(op).delete();
259259
try {
260260
setTimelineImage(process, op);
261261
} catch (IOException e) {
@@ -335,7 +335,12 @@ public boolean isOperationRunning() {
335335
if (opperationRunner != null)
336336
if (!opperationRunner.isAlive())
337337
opperationRunner = null;
338-
return opperationRunner != null;
338+
if(opperationRunner != null) {
339+
if(Thread.currentThread().getId() == opperationRunner.getId())
340+
return false;
341+
return true;
342+
}else
343+
return false;
339344
}
340345

341346
public Thread addOpperation(ICaDoodleOpperation o) throws CadoodleConcurrencyException {
@@ -349,21 +354,35 @@ public Thread addOpperation(ICaDoodleOpperation o) throws CadoodleConcurrencyExc
349354
while (toProcess.size() > 0) {
350355
opperationRunner.setName("addOpperation Thread " + toProcess.size());
351356
ICaDoodleOpperation op = toProcess.remove(0);
357+
OperationResult res=OperationResult.APPEND;
352358
if (getCurrentIndex() != getOpperations().size()) {
353359
try {
354360
prune=true;
355361
fireRegenerateStart();
356-
pruneForward();
362+
res=pruneForward(op);
357363
} catch (Exception e) {
358364
e.printStackTrace();
359365
break;
360366
}
361367
}
362-
try {
363-
getOpperations().add(op);
364-
process(op);
365-
} catch (Exception ex) {
366-
ex.printStackTrace();
368+
if(res==OperationResult.APPEND || res==OperationResult.PRUNE) {
369+
try {
370+
getOpperations().add(op);
371+
process(op);
372+
} catch (Exception ex) {
373+
ex.printStackTrace();
374+
}
375+
}
376+
if(res==OperationResult.INSERT) {
377+
getOpperations().add(getCurrentIndex(),op);
378+
setCurrentIndex(getCurrentIndex()+1);
379+
try {
380+
regenerateFrom(op).join();
381+
} catch (InterruptedException e) {
382+
// TODO Auto-generated catch block
383+
e.printStackTrace();
384+
}
385+
updateCurrentFromCache();
367386
}
368387
}
369388
updateBoM();
@@ -452,10 +471,12 @@ public File getTimelineImageFile(int i) {
452471
return file;
453472
}
454473

455-
private void pruneForward() throws Exception {
474+
private OperationResult pruneForward(ICaDoodleOpperation op) throws Exception {
475+
OperationResult res=OperationResult.INSERT;
456476
if(getAccept()!=null) {
457-
if(!getAccept().accept()) {
458-
throw new Exception("Do not accept the prune");
477+
res = getAccept().accept();
478+
if(res==OperationResult.ABORT) {
479+
return res;
459480
}
460481
}
461482
for (int i = getCurrentIndex()-1; i < getOpperations().size(); i++) {
@@ -469,13 +490,15 @@ private void pruneForward() throws Exception {
469490
//System.err.println("Deleting " + imageCache.getAbsolutePath());
470491
imageCache.delete();
471492
}
472-
List<ICaDoodleOpperation> subList = (List<ICaDoodleOpperation>) getOpperations().subList(0, getCurrentIndex());
473-
ArrayList<ICaDoodleOpperation> newList = new ArrayList<ICaDoodleOpperation>();
474-
newList.addAll(subList);
475-
setOpperations(newList);
476-
com.neuronrobotics.sdk.common.Log.error("Pruning forward here!");
477-
fireTimelineUpdate();
478-
493+
if(res==OperationResult.PRUNE) {
494+
List<ICaDoodleOpperation> subList = (List<ICaDoodleOpperation>) getOpperations().subList(0, getCurrentIndex());
495+
ArrayList<ICaDoodleOpperation> newList = new ArrayList<ICaDoodleOpperation>();
496+
newList.addAll(subList);
497+
setOpperations(newList);
498+
com.neuronrobotics.sdk.common.Log.error("Pruning forward here!");
499+
fireTimelineUpdate();
500+
}
501+
return res;
479502
}
480503

481504
private void storeResultInCache(ICaDoodleOpperation op, List<CSG> process) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;
22

33
public interface IAcceptPruneForward {
4-
public boolean accept();
4+
public OperationResult accept();
55
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.neuronrobotics.bowlerstudio.scripting.cadoodle;
2+
3+
public enum OperationResult {
4+
PRUNE,INSERT,ABORT,APPEND;
5+
}

0 commit comments

Comments
 (0)