From 6d06de9020050f40b4913e385c1a7170935ae000 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Cl=C3=A9ment=20DAVID?= Date: Wed, 26 Sep 2018 18:08:03 +0200 Subject: [PATCH] Fix misc. issues with Tab opening Change-Id: I800127c125b0ad631450878d219c2033486c43b7 --- scilab/CHANGES.md | 10 ++--- .../src/java/org/scilab/modules/xcos/Xcos.java | 24 +++++++++++- .../src/java/org/scilab/modules/xcos/XcosTab.java | 2 + .../xcos/block/actions/BlockParametersAction.java | 35 +++++++++++------ .../xcos/block/actions/ShowParentAction.java | 41 ++++++++++++-------- .../modules/xcos/io/writer/CustomWriter.java | 10 +++-- 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md index 5a1a6a1..3473b7e 100644 --- a/scilab/CHANGES.md +++ b/scilab/CHANGES.md @@ -503,6 +503,8 @@ Known issues * [#14522](http://bugzilla.scilab.org/show_bug.cgi?id=14522): `or(%nan)` was %F. * [#14536](http://bugzilla.scilab.org/show_bug.cgi?id=14536): `xpoly` crashed Scilab when it is used in logarithmic mode for points with negative or null coordinates. * [#14539](http://bugzilla.scilab.org/show_bug.cgi?id=14539): It was not possible to build Scilab with hdf5 1.10.0. +* [#14606](http://bugzilla.scilab.org/show_bug.cgi?id=14606): Memory used by variables returned by `[names,mem]=who()` was always zero. +* [#14670](http://bugzilla.scilab.org/show_bug.cgi?id=14670): Superblocks could be opened more than once. * [#14701](http://bugzilla.scilab.org/show_bug.cgi?id=14701): `poly(c,v,"coeff")` did not ignore null high order coefficients. * [#14704](http://bugzilla.scilab.org/show_bug.cgi?id=14704): In Scinotes, URL for the `https://`, `ftp://`, `ftps://`, and `file://` protocols were no longer hyperlinked. * [#14708](http://bugzilla.scilab.org/show_bug.cgi?id=14708): polynomial operators `+` `-` `/` `./` `*` `.*` no longer simplified null high orders coefficients from result @@ -605,13 +607,9 @@ Known issues * [#15632](http://bugzilla.scilab.org/show_bug.cgi?id=15632): `x=[];x()=1` crashed Scilab. * [#15635](http://bugzilla.scilab.org/show_bug.cgi?id=15635): `dellip(1,4)` terminated with neither output nor error (regression) * [#15636](http://bugzilla.scilab.org/show_bug.cgi?id=15636): Clicking on its icon did not always give focus to Help browser -<<<<<<< HEAD -* [#15645](http://bugzilla.scilab.org/show_bug.cgi?id=15645): `deff('y=f(x)','z=x^2'),fsolve(1,f)` crashed scilab -* [#15642](http://bugzilla.scilab.org/show_bug.cgi?id=15642):A(:) gave incorrect display when A is sparse boolean (regression) -======= * [#15638](http://bugzilla.scilab.org/show_bug.cgi?id=15638): `colorbar()`: Both colors on the bar tips spanned an interval twice smaller than for other colors. This made almost impossible to choose a convenient number of colors to share the whole values interval in a simple way. -* [#15648](http://bugzilla.scilab.org/show_bug.cgi?id=15648): `sparse([1 1],1,[-1 -1])` crashed scilab ->>>>>>> 04860748d5d... * Bugs 15638 15805 15806 fixed: colorbar() improved +* [#15642](http://bugzilla.scilab.org/show_bug.cgi?id=15642):A(:) gave incorrect display when A is sparse boolean (regression) +* [#15645](http://bugzilla.scilab.org/show_bug.cgi?id=15645): `deff('y=f(x)','z=x^2'),fsolve(1,f)` crashed scilab * [#15647](http://bugzilla.scilab.org/show_bug.cgi?id=15647): `spzeros(-1,-1)` yielded a corrupted result * [#15648](http://bugzilla.scilab.org/show_bug.cgi?id=15648): `sparse([1 1],1,[-1 -1])` crashed scilab * [#15652](http://bugzilla.scilab.org/show_bug.cgi?id=15652): An appended comment // after a comma in an multiline literal array now generates an error (regression). diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java index a4514c8..15a82aa 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/Xcos.java @@ -69,8 +69,6 @@ import org.scilab.modules.xcos.utils.FileUtils; import org.scilab.modules.xcos.utils.XcosMessages; import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxGraphModel; -import com.mxgraph.model.mxICell; import com.mxgraph.util.mxEvent; import com.mxgraph.util.mxEventObject; import com.mxgraph.view.mxStylesheet; @@ -1030,6 +1028,28 @@ public final class Xcos { } /** + * Look for the diagram that match the model object in the diagram hierarchy. + * @param uid + * the UID to search for + * @return the associated diagram + */ + public static XcosDiagram findDiagram(long uid) { + final Xcos instance = getInstance(); + + for (Collection diags : instance.diagrams.values()) { + for (XcosDiagram diag : diags) { + final Object defaultParent = diag.getDefaultParent(); + + if (defaultParent instanceof XcosCell && ((XcosCell) defaultParent).getUID() == uid) { + return diag; + } + } + } + + return null; + } + + /** * Look for the parent diagram of the cell in the diagram hierarchy. * * @param cell diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java index 51c3072..67e3cf4 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java @@ -2,6 +2,7 @@ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab * Copyright (C) 2010-2011 - DIGITEO - Clement DAVID * Copyright (C) 2011-2017 - Scilab Enterprises - Clement DAVID + * Copyright (C) 2017-2018 - ESI Group - Clement DAVID * * Copyright (C) 2012 - 2016 - Scilab Enterprises * @@ -332,6 +333,7 @@ public class XcosTab extends SwingScilabDockablePanel implements SimpleTab { if (visible) { tab.createDefaultWindow().setVisible(true); + graph.fireEvent(new mxEventObject(mxEvent.ROOT)); graph.updateTabTitle(); BarUpdater.updateBars(tab.getParentWindowId(), tab.getMenuBar(), tab.getToolBar(), tab.getInfoBar(), tab.getName(), tab.getWindowIcon()); } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockParametersAction.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockParametersAction.java index 0035c37..06aefdc 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockParametersAction.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/BlockParametersAction.java @@ -111,22 +111,33 @@ public class BlockParametersAction extends VertexSelectionDependantAction { BlockInterFunction func = XcosCellFactory.lookForInterfunction(interfaceFunction[0]); if (func.equals(BlockInterFunction.SUPER_f)) { // this is a super-block, open it - XcosDiagram sub = new XcosDiagram(controller, cell.getUID(), cell.getKind(), cell.getId()); - XcosCellFactory.insertChildren(controller, sub); - ScicosObjectOwner root = Xcos.findRoot(graph); - Xcos.getInstance().addDiagram(root, sub); + XcosDiagram sub = Xcos.findDiagram(cell.getUID()); + if (sub == null) { + sub = new XcosDiagram(controller, cell.getUID(), cell.getKind(), cell.getId()); + XcosCellFactory.insertChildren(controller, sub); - // propagate the modified status after discarding modification - // done on children insertion - sub.setModified(false); - sub.setModified(Xcos.getInstance().isModified(root)); + ScicosObjectOwner root = Xcos.findRoot(graph); + Xcos.getInstance().addDiagram(root, sub); - // setup graphical interface - sub.getUndoManager().clear(); - sub.installListeners(); + // propagate the modified status after discarding modification + // done on children insertion + sub.setModified(false); + sub.setModified(Xcos.getInstance().isModified(root)); - XcosTab.restore(sub, true); + // setup graphical interface + sub.getUndoManager().clear(); + sub.installListeners(); + } + + // restore the parent graph tab + final XcosTab tab = XcosTab.get(sub); + if (tab == null) { + XcosTab.restore(sub); + } else { + tab.setCurrent(); + tab.requestFocus(); + } } else { BasicBlock block = (BasicBlock) cell; // prevent to open twice diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java index 17d3a47..02165b3 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/block/actions/ShowParentAction.java @@ -31,6 +31,9 @@ import org.scilab.modules.xcos.Xcos; import org.scilab.modules.xcos.XcosTab; import org.scilab.modules.xcos.XcosView; import org.scilab.modules.xcos.graph.XcosDiagram; +import org.scilab.modules.xcos.graph.model.ScicosObjectOwner; +import org.scilab.modules.xcos.graph.model.XcosCell; +import org.scilab.modules.xcos.graph.model.XcosCellFactory; import org.scilab.modules.xcos.utils.XcosMessages; /** @@ -79,30 +82,36 @@ public class ShowParentAction extends DefaultAction { if (graph.getKind() == Kind.BLOCK) { JavaController controller = new JavaController(); - long[] parent = new long[1]; - Kind kind = Kind.BLOCK; - controller.getObjectProperty(graph.getUID(), kind, ObjectProperties.PARENT_BLOCK, parent); - if (parent[0] == 0) { - kind = Kind.DIAGRAM; - controller.getObjectProperty(graph.getUID(), kind, ObjectProperties.PARENT_DIAGRAM, parent); - } - XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getName()); + XcosCell defaultParent = (XcosCell) graph.getDefaultParent(); + XcosDiagram parentGraph = Xcos.findParent(controller, defaultParent.getUID(), defaultParent.getKind()); + + // the parent graph is not visible yet, load it into the UI + if (parentGraph == null) { + long[] parent = {0}; + Kind parentKind = Kind.BLOCK; + + // use parent / children model property + controller.getObjectProperty(defaultParent.getUID(), defaultParent.getKind(), ObjectProperties.PARENT_BLOCK, parent); + if (parent[0] == 0) { + parentKind = Kind.DIAGRAM; + controller.getObjectProperty(defaultParent.getUID(), defaultParent.getKind(), ObjectProperties.PARENT_DIAGRAM, parent); + } - XcosDiagram diagram = (XcosDiagram) view.getVisibleObjects().get(parent[0]); - if (diagram == null) { - String[] strUID = new String[] { "" }; - controller.getObjectProperty(graph.getUID(), kind, ObjectProperties.UID, strUID); + parentGraph = new XcosDiagram(controller, parent[0], parentKind, ""); + XcosCellFactory.insertChildren(controller, parentGraph); + parentGraph.installListeners(); - diagram = new XcosDiagram(controller, parent[0], kind, strUID[0]); - view.getVisibleObjects().put(parent[0], diagram); + Xcos.getInstance().addDiagram(Xcos.findRoot(controller, graph), parentGraph); } - final XcosTab tab = XcosTab.get(diagram); + // restore the parent graph tab + final XcosTab tab = XcosTab.get(parentGraph); if (tab == null) { - XcosTab.restore(diagram); + XcosTab.restore(parentGraph); } else { tab.setCurrent(); + tab.requestFocus(); } } } diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java index 6420c23..21db771 100644 --- a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java +++ b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/io/writer/CustomWriter.java @@ -1,7 +1,7 @@ /* * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab - * Copyright (C) 2015-2015 - Scilab Enterprises - Clement DAVID - * Copyright (C) 2017 - ESI Group - Clement DAVID + * Copyright (C) 2015-2017 - Scilab Enterprises - Clement DAVID + * Copyright (C) 2017-2018 - ESI Group - Clement DAVID * * Copyright (C) 2012 - 2016 - Scilab Enterprises * @@ -162,8 +162,10 @@ public class CustomWriter extends ScilabWriter { final int len = children.size(); for (int i = 0; i < len; i++) { long child = children.get(i); - Kind childKind = Kind.values()[kinds.get(i)]; - shared.write(child, childKind); + if (child != 0) { + Kind childKind = Kind.values()[kinds.get(i)]; + shared.write(child, childKind); + } } shared.layers.pop(); -- 1.7.9.5