From: jkauttio Date: Fri, 10 Apr 2015 12:59:17 +0000 (+0000) Subject: Fix several bugs with diagram tool modes. X-Git-Tag: v1.29.0~110 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d1e49bce496e6d30690bf69dbbf9cff4d83380e1;p=simantics%2Fsysdyn.git Fix several bugs with diagram tool modes. - Remove the auxiliary creation mode from the tool bar as it was not implemented in the first place - Fix a NullPointerException in flow creation mode which occurred when the mouse pointer hovered over diagram elements - Make variable creation shortcuts (shift-a, shift-s etc.) to only work in the basic pointer mode, this also fixes a bug which allowed variables to be created when the diagram was in the lock mode - Clean up DiagramToolHandler, context was initialized inside a separate thread even though there does not seem to be any reason to do so. Revert this change if something breaks. fixes #5758 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@31159 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 03aa920f..9756871a 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -3307,14 +3307,6 @@ type="radio" value="flow"> - - diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java index 96d6f930..4e2c6c87 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java @@ -21,6 +21,7 @@ import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.adapter.GraphToDiagramSynchronizer; import org.simantics.diagram.elements.TextNode; import org.simantics.diagram.query.DiagramRequests; +import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.SGDesignation; import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit; @@ -51,6 +52,7 @@ import org.simantics.sysdyn.ui.elements.InputFactory; import org.simantics.sysdyn.ui.elements.LoopFactory; import org.simantics.sysdyn.ui.elements.ShadowFactory; import org.simantics.sysdyn.ui.elements.StockFactory; +import org.simantics.sysdyn.ui.elements.SysdynElementHints; import org.simantics.sysdyn.ui.elements.ValveFactory; import org.simantics.ui.SimanticsUI; import org.simantics.utils.datastructures.Callback; @@ -119,6 +121,11 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa @EventHandler(priority = -10) public boolean handleKeyboardEvent(KeyEvent ke) { + + // ignore this event if we are not in the unmodified pointer tool mode + if (!Hints.POINTERTOOL.equals(getHint(Hints.KEY_TOOL)) || getHint(SysdynElementHints.SYSDYN_KEY_TOOL) != null) { + return false; + } KeyPressedEvent kpe; if (ke instanceof KeyPressedEvent) { @@ -225,6 +232,11 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa } else { return false; } + + // only create a variable if we are in the unmodified pointer tool mode + if (!Hints.POINTERTOOL.equals(getHint(Hints.KEY_TOOL)) || getHint(SysdynElementHints.SYSDYN_KEY_TOOL) != null) { + return false; + } if (! ( diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java index 72de5cbe..e08193ea 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java @@ -193,7 +193,7 @@ public class SysdynConnectTool extends ConnectTool2 { } else if (ti != null && ti == startFlag) { c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D()); - } else if (isEndingInFlag() && ti.e != null) { + } else if (ti != null && isEndingInFlag()) { c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y), CloudFactory.CLOUD_IMAGE.getBounds()); } else { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java index 7f4a2515..6a5a3577 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java @@ -7,9 +7,7 @@ import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.handlers.RadioState; import org.simantics.g2d.canvas.Hints; import org.simantics.g2d.canvas.ICanvasContext; -import org.simantics.g2d.canvas.IToolMode; import org.simantics.sysdyn.ui.elements.SysdynElementHints; -import org.simantics.utils.threads.ThreadUtils; public class DiagramToolHandler extends AbstractHandler { @@ -22,44 +20,27 @@ public class DiagramToolHandler extends AbstractHandler { String value = (String)event.getCommand().getState(RadioState.STATE_ID).getValue(); - final IToolMode mode; + // if one of the connection modes is selected, use the + // default connection tool as the base and indicate the + // desired connection type in another hint (this is done + // to make sure all features of the connection tool work + // as expected) if ("pointer".equals(value)) { - mode = Hints.POINTERTOOL; + context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL); + context.getDefaultHintContext().removeHint(SysdynElementHints.SYSDYN_KEY_TOOL); } else if ("dependency".equals(value)) { - mode = SysdynElementHints.DEPENDENCY_TOOL; + context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL); + context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.DEPENDENCY_TOOL); } else if ("flow".equals(value)) { - mode = SysdynElementHints.FLOW_TOOL; + context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL); + context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.FLOW_TOOL); } else if ("lock".equals(value)) { - mode = SysdynElementHints.LOCK_TOOL; + context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL); + context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.LOCK_TOOL); } - else { - return null; - } - - ThreadUtils.syncExec(context.getThreadAccess(), new Runnable() { - @Override - public void run() { - if (mode.equals(SysdynElementHints.DEPENDENCY_TOOL) - || mode.equals(SysdynElementHints.FLOW_TOOL)) { - // if one of the connection modes is selected, use the - // default connection tool as the base and indicate the - // desired connection type in another hint (this is done - // to make sure all features of the connection tool work - // as expected) - context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL); - context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, mode); - } else if (mode.equals(SysdynElementHints.LOCK_TOOL)) { - context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL); - context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, mode); - } else { - context.getDefaultHintContext().setHint(Hints.KEY_TOOL, mode); - context.getDefaultHintContext().removeHint(SysdynElementHints.SYSDYN_KEY_TOOL); - } - } - }); return null; }