Browse Source

FTG+PM: When reversing edge, also reverse waypoints.

Joeri Exelmans 4 years ago
parent
commit
205b3d91f6
1 changed files with 21 additions and 7 deletions
  1. 21 7
      src/main/webapp/plugins/cdf/ftgpm-edit.js

+ 21 - 7
src/main/webapp/plugins/cdf/ftgpm-edit.js

@@ -161,7 +161,8 @@ Draw.loadPlugin(function(ui) {
       // Update style
       checkEdge(ui, edge, fromTo);
 
-      // Reverse direction, if necessary
+
+      // Auto-correct direction
       const sourceCell = edge.source;
       const targetCell = edge.getTerminal();
 
@@ -171,10 +172,21 @@ Draw.loadPlugin(function(ui) {
 
       const sourceType = sourceCell.getAttribute("pmRole");
       const targetType = targetCell.getAttribute("pmRole");
+
+      // out-to-in: do nothing
+      // in-to-in: do nothing
+      // out-to-out: do nothing
+      // in-to-out: reverse:
       if (isInport(sourceType) && isOutport(targetType)) {
         console.log("REVERSE");
 
-        ui.editor.graph.model.setTerminals(edge, targetCell, sourceCell); // swap
+        // Reverse source and target
+        ui.editor.graph.model.setTerminals(edge, targetCell, sourceCell);
+        
+        // Reverse 'waypoints'
+        const newGeometry = edge.geometry.clone();
+        newGeometry.points.reverse();
+        ui.editor.graph.model.setGeometry(edge, newGeometry);
       }
     });
 
@@ -329,9 +341,10 @@ Draw.loadPlugin(function(ui) {
       }
     })
 
-    // ui.editor.undoManager.addListener(null, (_, eventObj) => {
-    //   console.log("UNDO:", eventObj);
-    // });
+    ui.editor.undoManager.addListener(null, (_, eventObj) => {
+      // For debugging:
+      console.log("UNDO:", eventObj);
+    });
 
     // Upon loading a model, 
     ui.editor.graph.addListener(mxEvent.ROOT, (_, eventObj) => {
@@ -344,8 +357,6 @@ Draw.loadPlugin(function(ui) {
       );
     });
 
-    window.ui = ui;
-
     ui.loadLibrary(new LocalLibrary(ui, portsExamplesLib, "FTG+PM with ports: Examples"));
     ui.loadLibrary(new LocalLibrary(ui, portsPrimitivesLib, "FTG+PM with ports: Primitives"));
 
@@ -382,4 +393,7 @@ Draw.loadPlugin(function(ui) {
 
     console.log("Activated FTG+PM without ports")
   }
+
+  // For debugging only
+  window.ui = ui;
 });