Xcos GUI: fix Link creation 02/17302/4
Paul Bignier [Fri, 9 Oct 2015 14:12:48 +0000 (16:12 +0200)]
--> xcos();scicos_log("TRACE");
// Check that creating Links by dragging them from block ports updates CONTROL_POINTS at the right times

Change-Id: I4c5a59a4bf75bfd570bfe86ee75f30fa3fc579e7

scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/swing/handler/ConnectionHandler.java

index c93afef..5306135 100644 (file)
@@ -18,6 +18,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.graph.model.XcosCell;
 import org.scilab.modules.xcos.graph.swing.GraphComponent;
 
 import com.mxgraph.model.mxICell;
@@ -206,6 +207,17 @@ public class ConnectionHandler extends mxConnectionHandler {
 
             e.consume();
         } else {
+            if (marker.hasValidState()) {
+                final mxGraph graph = graphComponent.getGraph();
+                final double x = graph.snap(e.getX());
+                final double y = graph.snap(e.getY());
+
+                // We are ending a link creation on an valid port,
+                // so sync the points coordinates with the model
+                XcosCell cell = (XcosCell) connectPreview.getPreviewState().getCell();
+                cell.setGeometry(cell.getGeometry());
+            }
+
             multiPointLinkStarted = false;
             super.mouseReleased(e);
         }