|
@@ -105,6 +105,31 @@ public class CanvasController {
|
|
notifyObjListeners();
|
|
notifyObjListeners();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Replaces {@code toBeReplaced} by {@code by} on the canvas
|
|
|
|
+ * @param toBeReplaced the object that will be replaced
|
|
|
|
+ * @param by the object that will replace it
|
|
|
|
+ */
|
|
|
|
+ public void replaceObjectOnCanvas(AbstractCpsObject toBeReplaced, AbstractCpsObject by) {
|
|
|
|
+ /** let all edges of 'toBeReplaced' connect to 'by' */
|
|
|
|
+ for(CpsEdge e: toBeReplaced.getConnections()){
|
|
|
|
+ if(e.getA() == toBeReplaced){
|
|
|
|
+ e.setA(by);
|
|
|
|
+ }else if(e.getB() == toBeReplaced){
|
|
|
|
+ e.setB(by);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** if edge from an object to itself -> remove it */
|
|
|
|
+ if(e.getA() == e.getB())
|
|
|
|
+ removeEdgesOnCanvas(e);
|
|
|
|
+ else/** else add edge to 'by' */
|
|
|
|
+ by.addConnection(e);
|
|
|
|
+ }
|
|
|
|
+ /** delete 'toBeReplaced' new empty connections, to prevent Nullpointer*/
|
|
|
|
+ toBeReplaced.setConnections(new ArrayList<CpsEdge>(1));
|
|
|
|
+ deleteObjectOnCanvas(toBeReplaced);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Add an edge to the Canvas.
|
|
* Add an edge to the Canvas.
|
|
*
|
|
*
|