From ce39edd09f6f6311e20aebb4b18164f48b3e8bbd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Mon, 29 Jan 2018 17:48:03 +0100 Subject: [PATCH] Xcos: propagate ports style updates as mxUndoableEdit changes At least fix the following bugs (and probably others): bug #15066 fixed: Undo did not update ports positions bug #15278 fixed: Moving Xcos blocks reverted rotation and flip/mirror properties Change-Id: I1b5df7b282d669ff2b976bc88ca4612a39fdb5f0 --- scilab/CHANGES.md | 2 + .../org/scilab/modules/xcos/port/BasicPort.java | 11 +++-- .../modules/xcos/utils/BlockPositioning.java | 47 ++++++++------------ 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 2cc5a84..08d5f85 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -454,6 +454,7 @@ Known issues * [#15058](http://bugzilla.scilab.org/show_bug.cgi?id=15058): With integers, `gcd` and `lcm` could return a negative result, depending on the order of negative components. * [#15060](http://bugzilla.scilab.org/show_bug.cgi?id=15060): `fplot3d` did not draw because of an addition with an empty matrix which now returns an empty matrix. * [#15063](http://bugzilla.scilab.org/show_bug.cgi?id=15063): `fort` wasn't properly removed. +* [#15066](http://bugzilla.scilab.org/show_bug.cgi?id=15066): Undo did not update ports positions * [#15070](http://bugzilla.scilab.org/show_bug.cgi?id=15070): `bitset` failed when the bit position is specified as encoded integer. * [#15072](http://bugzilla.scilab.org/show_bug.cgi?id=15072): The context was stored as a root diagram attribute instead of being stored on each Superblock layer. * [#15079](http://bugzilla.scilab.org/show_bug.cgi?id=15079): When all children of a graphic handle have not the same number of sub-children, any vectorized extraction or insertion in subchildren failed. @@ -490,6 +491,7 @@ Known issues * [#15261](http://bugzilla.scilab.org/show_bug.cgi?id=15261): Insertion in struct felt with wrong default value. * [#15266](http://bugzilla.scilab.org/show_bug.cgi?id=15266): Wrong default out_mode in `linear_interpn`. * [#15273](http://bugzilla.scilab.org/show_bug.cgi?id=15273): The documented order of `eval_cshep2d` second derivatives was wrong. +* [#15278](http://bugzilla.scilab.org/show_bug.cgi?id=15278): Moving Xcos blocks reverted rotation and flip/mirror properties * [#15282](http://bugzilla.scilab.org/show_bug.cgi?id=15282): `help_from_sci` could set an xml:id starting with the forbidden `%` character. * [#15285](http://bugzilla.scilab.org/show_bug.cgi?id=15285): `resize_matrix` did not manage conversion into `int64` and `uint64`. * [#15300](http://bugzilla.scilab.org/show_bug.cgi?id=15300): Distributive assignments like `a=(1,2)` crashed Scilab. diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java index bae49d0..119ef12 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/port/BasicPort.java @@ -131,7 +131,7 @@ public abstract class BasicPort extends XcosCell { controller.setObjectProperty(uid, Kind.PORT, ObjectProperties.PORT_KIND, portKind.ordinal()); this.orientation = orientation; - setLabelPosition(orientation); + setStyle(computeLabelPosition(orientation)); } /** @@ -153,7 +153,7 @@ public abstract class BasicPort extends XcosCell { public final void setOrientation(Orientation defaultOrientation) { if (orientation != defaultOrientation) { orientation = defaultOrientation; - setLabelPosition(orientation); + setStyle(computeLabelPosition(orientation)); } } @@ -162,8 +162,9 @@ public abstract class BasicPort extends XcosCell { * * @param current * the port orientation, if null, does nothing. + * @return an updated style for the orientation */ - public final void setLabelPosition(final Orientation current) { + public final String computeLabelPosition(final Orientation current) { if (current != null) { StyleMap style = new StyleMap(getStyle()); @@ -180,8 +181,10 @@ public abstract class BasicPort extends XcosCell { style.put(mxConstants.STYLE_VERTICAL_ALIGN, current.getVerticalLabelPosition()); style.put(mxConstants.STYLE_SPACING, Double.toString(BasicPort.DEFAULT_PORTSIZE + 2.0)); - setStyle(style.toString()); + return style.toString(); } + + return getStyle(); } /** diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java index eeecd27..4eb7e43 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/BlockPositioning.java @@ -2,6 +2,7 @@ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2009 - DIGITEO - Antoine ELIAS * Copyright (C) 2011-2015 - Scilab Enterprises - Clement DAVID + * Copyright (C) 2018 - ESI Group - Clement DAVID * * Copyright (C) 2012 - 2016 - Scilab Enterprises * @@ -74,7 +75,7 @@ public final class BlockPositioning { diag.getModel().beginUpdate(); for (int i = 0; i < portsSize; ++i) { final BasicPort port = (ports.get(i)); - final mxGeometry portGeom = port.getGeometry(); + final mxGeometry portGeom = (mxGeometry) port.getGeometry().clone(); double nonVariantPosition = -portGeom.getWidth(); final int order = i; @@ -83,7 +84,8 @@ public final class BlockPositioning { portGeom.setX(nonVariantPosition); portGeom.setY(alignedPosition); - port.setLabelPosition(Orientation.WEST); + diag.getModel().setGeometry(port, portGeom); + diag.getModel().setStyle(port, port.computeLabelPosition(Orientation.WEST)); } diag.getModel().endUpdate(); } @@ -138,7 +140,7 @@ public final class BlockPositioning { diag.getModel().beginUpdate(); for (int i = 0; i < portsSize; ++i) { final BasicPort port = (ports.get(i)); - final mxGeometry portGeom = port.getGeometry(); + final mxGeometry portGeom = (mxGeometry) port.getGeometry().clone(); double nonVariantPosition = -portGeom.getHeight(); final int order = i; @@ -147,7 +149,8 @@ public final class BlockPositioning { portGeom.setX(alignedPosition); portGeom.setY(nonVariantPosition); - port.setLabelPosition(Orientation.NORTH); + diag.getModel().setGeometry(port, portGeom); + diag.getModel().setStyle(port, port.computeLabelPosition(Orientation.NORTH)); } diag.getModel().endUpdate(); } @@ -172,7 +175,7 @@ public final class BlockPositioning { diag.getModel().beginUpdate(); for (int i = 0; i < portsSize; ++i) { final BasicPort port = (ports.get(i)); - final mxGeometry portGeom = port.getGeometry(); + final mxGeometry portGeom = (mxGeometry) port.getGeometry().clone(); double nonVariantPosition = blockGeom.getWidth(); final int order = i; @@ -181,7 +184,8 @@ public final class BlockPositioning { portGeom.setX(nonVariantPosition); portGeom.setY(alignedPosition); - port.setLabelPosition(Orientation.EAST); + diag.getModel().setGeometry(port, portGeom); + diag.getModel().setStyle(port, port.computeLabelPosition(Orientation.EAST)); } diag.getModel().endUpdate(); } @@ -206,7 +210,7 @@ public final class BlockPositioning { diag.getModel().beginUpdate(); for (int i = 0; i < portsSize; ++i) { final BasicPort port = (ports.get(i)); - final mxGeometry portGeom = port.getGeometry(); + final mxGeometry portGeom = (mxGeometry) port.getGeometry().clone(); double nonVariantPosition = blockGeom.getHeight(); final int order = i; @@ -215,7 +219,8 @@ public final class BlockPositioning { portGeom.setX(alignedPosition); portGeom.setY(nonVariantPosition); - port.setLabelPosition(Orientation.SOUTH); + diag.getModel().setGeometry(port, portGeom); + diag.getModel().setStyle(port, port.computeLabelPosition(Orientation.SOUTH)); } diag.getModel().endUpdate(); } @@ -443,17 +448,12 @@ public final class BlockPositioning { * The block to work on */ public static void toggleFlip(final XcosDiagram diag, BasicBlock block) { - JavaController controller = new JavaController(); - String[] style = new String[1]; - controller.getObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, style); - - StyleMap styleMap = new StyleMap(style[0]); + StyleMap styleMap = new StyleMap(block.getStyle()); final boolean invertedFlip = ! Boolean.TRUE.toString().equals(styleMap.get(XcosConstants.STYLE_FLIP)); styleMap.put(XcosConstants.STYLE_FLIP, Boolean.toString(invertedFlip)); - controller.setObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, styleMap.toString()); - + diag.getModel().setStyle(block, styleMap.toString()); updateBlockView(diag, block); } @@ -464,17 +464,12 @@ public final class BlockPositioning { * The block to work on */ public static void toggleMirror(final XcosDiagram diag, BasicBlock block) { - JavaController controller = new JavaController(); - String[] style = new String[1]; - controller.getObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, style); - - StyleMap styleMap = new StyleMap(style[0]); + StyleMap styleMap = new StyleMap(block.getStyle()); final boolean invertedFlip = ! Boolean.TRUE.toString().equals(styleMap.get(XcosConstants.STYLE_MIRROR)); styleMap.put(XcosConstants.STYLE_MIRROR, Boolean.toString(invertedFlip)); - controller.setObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, styleMap.toString()); - + diag.getModel().setStyle(block, styleMap.toString()); updateBlockView(diag, block); } @@ -485,14 +480,10 @@ public final class BlockPositioning { * The block to work on */ public static void toggleAntiClockwiseRotation(final XcosDiagram diag, BasicBlock block) { - JavaController controller = new JavaController(); - String[] style = new String[1]; - controller.getObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, style); - - StyleMap styleMap = new StyleMap(style[0]); + StyleMap styleMap = new StyleMap(block.getStyle()); styleMap.put(XcosConstants.STYLE_ROTATION, Integer.toString(getNextAntiClockwiseAngle(styleMap))); - controller.setObjectProperty(block.getUID(), Kind.BLOCK, ObjectProperties.STYLE, styleMap.toString()); + diag.getModel().setStyle(block, styleMap.toString()); updateBlockView(diag, block); } -- 1.7.9.5