Xcos: fix Split block management 95/18095/4
Clément DAVID [Tue, 19 Apr 2016 12:57:43 +0000 (14:57 +0200)]
The DELAYV_f_en_US.zcos schema has been remade from scratch to check that
all edit actions are fully connected.

Change-Id: Iec6826e6ec8f79de3c8e1ffe9bed9b20cd47ebd5

scilab/modules/graph/src/java/org/scilab/modules/graph/event/ArrowKeyListener.java
scilab/modules/helptools/images/DELAYV_f_en_US.zcos.png
scilab/modules/xcos/examples/discrete_pal/en_US/DELAYV_f_en_US.zcos
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/model/XcosCell.java

index f778dc4..36b9c39 100644 (file)
@@ -59,12 +59,12 @@ public final class ArrowKeyListener implements KeyListener {
                 model.beginUpdate();
                 try {
                     for (Object cell : graph.getSelectionCells()) {
-                        // first increment
-                        graph.translateCell(cell, xIncrement, yIncrement);
-
-                        // then align
+                        // first snap
                         final mxGeometry geom = model.getGeometry(cell);
-                        model.setGeometry(cell, snap(graph, geom));
+                        snap(graph, geom);
+
+                        // then move and transaction
+                        graph.translateCell(cell, xIncrement, yIncrement);
                     }
                 } finally {
                     model.endUpdate();
index 9ead7fb..3c2eb92 100644 (file)
Binary files a/scilab/modules/helptools/images/DELAYV_f_en_US.zcos.png and b/scilab/modules/helptools/images/DELAYV_f_en_US.zcos.png differ
index 22e451a..b86a51d 100644 (file)
Binary files a/scilab/modules/xcos/examples/discrete_pal/en_US/DELAYV_f_en_US.zcos and b/scilab/modules/xcos/examples/discrete_pal/en_US/DELAYV_f_en_US.zcos differ
index 980c649..084106d 100644 (file)
@@ -887,10 +887,10 @@ public class XcosDiagram extends ScilabGraph {
 
         // 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.));
+        double x = snap(splitPoint.getX()) - (SplitBlock.DEFAULT_SIZE / 2.);
+        double y = snap(splitPoint.getY()) - (SplitBlock.DEFAULT_SIZE / 2.);
+        geom.setX(x);
+        geom.setY(y);
         splitBlock.setGeometry(geom);
 
         getModel().beginUpdate();
@@ -1127,6 +1127,29 @@ public class XcosDiagram extends ScilabGraph {
     }
 
     /**
+     * Translate the cell and align any split block
+     * @param cell any object
+     * @param dx the X delta
+     * @param dy the Y delta
+     */
+    @Override
+    public void translateCell(Object cell, double dx, double dy) {
+        if (cell instanceof SplitBlock) {
+            mxGeometry geom = model.getGeometry(cell);
+
+            final double posX = snap(geom.getX() + dx) - (SplitBlock.DEFAULT_SIZE / 2.);
+            final double posY = snap(geom.getY() + dy) - (SplitBlock.DEFAULT_SIZE / 2.);
+
+            dx = posX - geom.getX();
+            dy = posY - geom.getY();
+        }
+
+        super.translateCell(cell, dx, dy);
+    }
+
+
+
+    /**
      * Removes the given cells from the graph including all connected edges if includeEdges is true. The change is carried out using cellsRemoved.
      *
      * @param cells
index 7135002..bffb37b 100644 (file)
@@ -403,15 +403,14 @@ public class XcosCell extends mxCell {
     @Override
     public mxICell setTerminal(mxICell terminal, boolean isSource) {
         mxICell cell = super.setTerminal(terminal, isSource);
-
-        final long uid;
         if (cell == null) {
-            uid = 0l;
-        } else {
-            // a terminal of an XcosCell is always another XcosCell
-            uid = ((XcosCell) cell).getUID();
+            return cell;
         }
 
+        // a terminal of an XcosCell is always another XcosCell
+        final long uid = ((XcosCell) cell).getUID();
+        final Kind kind = ((XcosCell) cell).getKind();
+
         JavaController controller = new JavaController();
         switch (getKind()) {
             case LINK:
@@ -421,7 +420,7 @@ public class XcosCell extends mxCell {
                     controller.setObjectProperty(getUID(), getKind(), ObjectProperties.DESTINATION_PORT, uid);
                 }
                 if (uid != 0l) {
-                    controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.CONNECTED_SIGNALS, getUID());
+                    controller.setObjectProperty(uid, kind, ObjectProperties.CONNECTED_SIGNALS, getUID());
                 }
                 break;
             default: