Xcos GUI: snap split blocks on the grid 42/17542/2
Clément DAVID [Fri, 4 Dec 2015 09:52:35 +0000 (10:52 +0100)]
Change-Id: Ib67c58d4da2f4cc953b7ab15f881ced1050a6fc3

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

index 887400a..6e4a640 100644 (file)
@@ -81,18 +81,6 @@ public final class SplitBlock extends BasicBlock {
         if (geometry != null) {
             geometry.setWidth(DEFAULT_SIZE);
             geometry.setHeight(DEFAULT_SIZE);
-
-            /*
-             * Align the geometry on the grid
-             */
-            // FIXME
-            //            if (getParentDiagram() != null && getParentDiagram().isGridEnabled()) {
-            //                final double cx = getParentDiagram().snap(geometry.getCenterX());
-            //                final double cy = getParentDiagram().snap(geometry.getCenterY());
-            //
-            //                geometry.setX(cx - (DEFAULT_SIZE / 2));
-            //                geometry.setY(cy - (DEFAULT_SIZE / 2));
-            //            }
         }
 
         super.setGeometry(geometry);
index 2f1380c..5511d70 100644 (file)
@@ -871,6 +871,14 @@ public class XcosDiagram extends ScilabGraph {
 
         final SplitBlock splitBlock = (SplitBlock) XcosCellFactory.createBlock(f);
 
+        // snap the center of the split block on the grid
+        mxGeometry geom = splitBlock.getGeometry();
+        double x = snap(splitPoint.getX());
+        double y = snap(splitPoint.getY());
+        geom.setX(x - (geom.getWidth() / 2.));
+        geom.setY(y - (geom.getHeight() / 2.));
+        splitBlock.setGeometry(geom);
+
         getModel().beginUpdate();
         try {
             // Origin of the parent, (0,0) as default may be different in case
@@ -880,8 +888,6 @@ public class XcosDiagram extends ScilabGraph {
             }
 
             addCell(splitBlock);
-            // force resize and align on the grid
-            resizeCell(splitBlock, new mxRectangle(splitPoint.getX(), splitPoint.getY(), 0, 0));
 
             // Update old link
 
@@ -905,11 +911,7 @@ public class XcosDiagram extends ScilabGraph {
                 }
             }
 
-            // disable events
-            getModel().beginUpdate();
             getModel().remove(link);
-            getModel().endUpdate();
-
             connect(linkSource, splitBlock.getIn(), saveStartPoints, orig);
             connect(splitBlock.getOut1(), linkTarget, saveEndPoints, orig);
 
index 318723c..1ba7ec1 100644 (file)
@@ -206,7 +206,7 @@ public class ConnectionHandler extends mxConnectionHandler {
 
             e.consume();
         } else {
-            if (marker.hasValidState()) {
+            if (marker.hasValidState() && connectPreview.getPreviewState() != null) {
                 final mxGraph graph = graphComponent.getGraph();
                 final double x = graph.snap(e.getX());
                 final double y = graph.snap(e.getY());