@@ -80,7 +80,7 @@ public class CaDoodleFile {
8080 private boolean initializing ;
8181 private static HashMap <String , VitaminBomManager > bomManagers = new HashMap <>();
8282 private VitaminBomManager bom ;
83- private IAcceptPruneForward accept = null ;
83+ private IAcceptPruneForward accept = null ;
8484
8585 public void close () {
8686 for (ICaDoodleOpperation op : cache .keySet ()) {
@@ -134,7 +134,7 @@ public void initialize() {
134134 CSGDatabase .clear ();
135135 createTempFile .delete ();
136136 } catch (IOException e ) {
137- // Auto-generated catch block
137+ // Auto-generated catch block
138138 e .printStackTrace ();
139139 }
140140 CSGDatabase .setDbFile (db );
@@ -259,7 +259,7 @@ public Thread regenerateFrom(ICaDoodleOpperation source) {
259259 try {
260260 setTimelineImage (process , op );
261261 } catch (IOException e ) {
262- // Auto-generated catch block
262+ // Auto-generated catch block
263263 e .printStackTrace ();
264264 }
265265 storeResultInCache (op , process );
@@ -303,7 +303,7 @@ public Thread regenerateCurrent() {
303303 try {
304304 setTimelineImage (process , op );
305305 } catch (IOException e ) {
306- // Auto-generated catch block
306+ // Auto-generated catch block
307307 e .printStackTrace ();
308308 }
309309 storeResultInCache (op , process );
@@ -326,7 +326,7 @@ private void process(ICaDoodleOpperation op) {
326326 try {
327327 setTimelineImage (process , op );
328328 } catch (IOException e ) {
329- // Auto-generated catch block
329+ // Auto-generated catch block
330330 e .printStackTrace ();
331331 }
332332 }
@@ -335,11 +335,11 @@ public boolean isOperationRunning() {
335335 if (opperationRunner != null )
336336 if (!opperationRunner .isAlive ())
337337 opperationRunner = null ;
338- if (opperationRunner != null ) {
339- if (Thread .currentThread ().getId () == opperationRunner .getId ())
338+ if (opperationRunner != null ) {
339+ if (Thread .currentThread ().getId () == opperationRunner .getId ())
340340 return false ;
341341 return true ;
342- }else
342+ } else
343343 return false ;
344344 }
345345
@@ -350,32 +350,32 @@ public Thread addOpperation(ICaDoodleOpperation o) throws CadoodleConcurrencyExc
350350 return opperationRunner ;
351351 }
352352 opperationRunner = new Thread (() -> {
353- boolean prune = false ;
353+ boolean prune = false ;
354354 while (toProcess .size () > 0 ) {
355355 opperationRunner .setName ("addOpperation Thread " + toProcess .size ());
356356 ICaDoodleOpperation op = toProcess .remove (0 );
357- OperationResult res = OperationResult .APPEND ;
357+ OperationResult res = OperationResult .APPEND ;
358358 if (getCurrentIndex () != getOpperations ().size ()) {
359359 try {
360- prune = true ;
360+ prune = true ;
361361 fireRegenerateStart ();
362- res = pruneForward (op );
362+ res = pruneForward (op );
363363 } catch (Exception e ) {
364364 e .printStackTrace ();
365365 break ;
366366 }
367367 }
368- if (res == OperationResult .APPEND || res == OperationResult .PRUNE ) {
368+ if (res == OperationResult .APPEND || res == OperationResult .PRUNE ) {
369369 try {
370370 getOpperations ().add (op );
371371 process (op );
372372 } catch (Exception ex ) {
373373 ex .printStackTrace ();
374374 }
375375 }
376- if (res == OperationResult .INSERT ) {
377- getOpperations ().add (getCurrentIndex (),op );
378- setCurrentIndex (getCurrentIndex ()+ 1 );
376+ if (res == OperationResult .INSERT ) {
377+ getOpperations ().add (getCurrentIndex (), op );
378+ setCurrentIndex (getCurrentIndex () + 1 );
379379 try {
380380 regenerateFrom (op ).join ();
381381 } catch (InterruptedException e ) {
@@ -387,14 +387,46 @@ public Thread addOpperation(ICaDoodleOpperation o) throws CadoodleConcurrencyExc
387387 }
388388 updateBoM ();
389389 fireSaveSuggestion ();
390- if (prune )
390+ if (prune )
391391 fireRegenerateDone ();
392392 opperationRunner = null ;
393393 });
394394 opperationRunner .start ();
395395 return opperationRunner ;
396396 }
397397
398+ public Thread deleteOperation (ICaDoodleOpperation op ) {
399+ if (isOperationRunning ()) {
400+ return opperationRunner ;
401+ }
402+ opperationRunner = new Thread (() -> {
403+ opperationRunner .setName ("addOpperation Thread " + toProcess .size ());
404+ int index =0 ;
405+ for (int i =0 ;i <getOpperations ().size ();i ++)
406+ if (getOpperations ().get (i )==op )
407+ index =i ;
408+ getOpperations ().remove (op );
409+ if (index ==getOpperations ().size ())
410+ index -=1 ;
411+ if (index <1 )
412+ index =1 ;
413+ ICaDoodleOpperation newTar = getOpperations ().get (index -1 );
414+ try {
415+ regenerateFrom (newTar ).join ();
416+ } catch (InterruptedException e ) {
417+ // TODO Auto-generated catch block
418+ e .printStackTrace ();
419+ }
420+ updateCurrentFromCache ();
421+
422+ updateBoM ();
423+ fireSaveSuggestion ();
424+ opperationRunner = null ;
425+ });
426+ opperationRunner .start ();
427+ return opperationRunner ;
428+ }
429+
398430 public static CSG getByName (List <CSG > back , String name ) {
399431 for (CSG c : back ) {
400432 if (c .getName ().contentEquals (name ))
@@ -472,26 +504,27 @@ public File getTimelineImageFile(int i) {
472504 }
473505
474506 private OperationResult pruneForward (ICaDoodleOpperation op ) throws Exception {
475- OperationResult res = OperationResult .INSERT ;
476- if (getAccept ()!= null ) {
507+ OperationResult res = OperationResult .INSERT ;
508+ if (getAccept () != null ) {
477509 res = getAccept ().accept ();
478- if (res == OperationResult .ABORT ) {
510+ if (res == OperationResult .ABORT ) {
479511 return res ;
480512 }
481513 }
482- for (int i = getCurrentIndex ()- 1 ; i < getOpperations ().size (); i ++) {
514+ for (int i = getCurrentIndex () - 1 ; i < getOpperations ().size (); i ++) {
483515 ICaDoodleOpperation key = getOpperations ().get (i );
484- if ( i >= getCurrentIndex ()) {
516+ if ( i >= getCurrentIndex ()) {
485517 List <CSG > back = cache .remove (key );
486518 if (back != null )
487519 back .clear ();
488520 }
489521 File imageCache = getTimelineImageFile (i );
490- //System.err.println("Deleting " + imageCache.getAbsolutePath());
522+ // System.err.println("Deleting " + imageCache.getAbsolutePath());
491523 imageCache .delete ();
492524 }
493- if (res ==OperationResult .PRUNE ) {
494- List <ICaDoodleOpperation > subList = (List <ICaDoodleOpperation >) getOpperations ().subList (0 , getCurrentIndex ());
525+ if (res == OperationResult .PRUNE ) {
526+ List <ICaDoodleOpperation > subList = (List <ICaDoodleOpperation >) getOpperations ().subList (0 ,
527+ getCurrentIndex ());
495528 ArrayList <ICaDoodleOpperation > newList = new ArrayList <ICaDoodleOpperation >();
496529 newList .addAll (subList );
497530 setOpperations (newList );
@@ -506,8 +539,8 @@ private void storeResultInCache(ICaDoodleOpperation op, List<CSG> process) {
506539 HashSet <String > names = new HashSet <>();
507540 for (CSG c : process ) {
508541 if (names .contains (c .getName ()))
509- throw new RuntimeException (
510- "There can not be 2 objects with the same name after an " + op . getType ()+ " opperation! " + c .getName ());
542+ throw new RuntimeException ("There can not be 2 objects with the same name after an " + op . getType ()
543+ + " opperation! " + c .getName ());
511544 names .add (c .getName ());
512545 cachedCopy .add (cloneCSG (c ).setStorage (new PropertyStorage ()).syncProperties (c ).setName (c .getName ())
513546 .setRegenerate (c .getRegenerate ()));
@@ -556,13 +589,13 @@ public void back() {
556589 fireSaveSuggestion ();
557590 fireTimelineUpdate ();
558591 }
559-
592+
560593 public void moveToOpIndex (int newIndex ) {
561- if (newIndex > getOpperations ().size ())
594+ if (newIndex > getOpperations ().size ())
562595 return ;
563- if (newIndex < 0 )
596+ if (newIndex < 0 )
564597 return ;
565- setCurrentIndex (newIndex + 1 );
598+ setCurrentIndex (newIndex + 1 );
566599 updateCurrentFromCache ();
567600 fireSaveSuggestion ();
568601 fireTimelineUpdate ();
@@ -742,12 +775,12 @@ public File save() throws IOException {
742775 }
743776
744777 private void setTimelineImage (List <CSG > currentState , ICaDoodleOpperation op ) throws IOException {
745- if (selfInternal == null )
778+ if (selfInternal == null )
746779 return ;
747- int currentIndex2 = 0 ;
748- for (int i = 0 ; i < getOpperations ().size ();i ++)
749- if (getOpperations ().get (i )== op )
750- currentIndex2 = i ;
780+ int currentIndex2 = 0 ;
781+ for (int i = 0 ; i < getOpperations ().size (); i ++)
782+ if (getOpperations ().get (i ) == op )
783+ currentIndex2 = i ;
751784// if(currentIndex2==0)
752785// return;
753786 File parent = selfInternal .getAbsoluteFile ().getParentFile ();
@@ -773,7 +806,7 @@ private void setTimelineImage(List<CSG> currentState, ICaDoodleOpperation op) th
773806 e .printStackTrace ();
774807 return ;
775808 }
776- }while (!imageCache .exists ());
809+ } while (!imageCache .exists ());
777810 if (currentIndex2 == currentIndex ) {
778811 Files .copy (imageCache , image );
779812 }
@@ -783,7 +816,7 @@ private void setTimelineImage(List<CSG> currentState, ICaDoodleOpperation op) th
783816 }
784817
785818 private void fireTimelineUpdate () {
786- for (ICaDoodleStateUpdate s : listeners ) {
819+ for (ICaDoodleStateUpdate s : listeners ) {
787820 s .onTimelineUpdate ();
788821 }
789822 }
@@ -877,7 +910,7 @@ public ArrayList<ICaDoodleOpperation> getOpperations() {
877910
878911 public void setOpperations (ArrayList <ICaDoodleOpperation > opperations ) {
879912 this .opperations = opperations ;
880- currentIndex = opperations .size ();
913+ currentIndex = opperations .size ();
881914 }
882915
883916 public TransformNR getWorkplane () {
0 commit comments