]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fix several bugs with diagram tool modes.
authorjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 10 Apr 2015 12:59:17 +0000 (12:59 +0000)
committerjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 10 Apr 2015 12:59:17 +0000 (12:59 +0000)
- 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

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/CreateVariablesShortcutParticipant.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynConnectTool.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java

index 03aa920fc00f6b464ce63eece7d11bce27ab0635..9756871a8559e2d350811512be37b12bf4434f1d 100644 (file)
             type="radio"\r
             value="flow">\r
       </command>\r
-      <command\r
-            commandId="org.simantics.sysdyn.ui.diagramTool"\r
-            image="platform:/plugin/com.famfamfam.silk/icons/textfield_add.png"\r
-            name="Create Auxiliary (Shift+A)"\r
-            toolbarId="org.simantics.sysdyn.ui.diagramToolbar"\r
-            type="radio"\r
-            value="auxiliary">\r
-      </command>\r
    </extension>\r
    <extension\r
          point="org.simantics.project.feature">\r
index 96d6f930eb817cbb93a425c45d69be96f88d827a..4e2c6c87fb3996627330296ceaf2dc7edf537447 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;\r
 import org.simantics.diagram.elements.TextNode;\r
 import org.simantics.diagram.query.DiagramRequests;\r
+import org.simantics.g2d.canvas.Hints;\r
 import org.simantics.g2d.canvas.SGDesignation;\r
 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;\r
@@ -51,6 +52,7 @@ import org.simantics.sysdyn.ui.elements.InputFactory;
 import org.simantics.sysdyn.ui.elements.LoopFactory;\r
 import org.simantics.sysdyn.ui.elements.ShadowFactory;\r
 import org.simantics.sysdyn.ui.elements.StockFactory;\r
+import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
 import org.simantics.sysdyn.ui.elements.ValveFactory;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.Callback;\r
@@ -119,6 +121,11 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa
 \r
        @EventHandler(priority = -10)\r
        public boolean handleKeyboardEvent(KeyEvent ke) {\r
+               \r
+               // ignore this event if we are not in the unmodified pointer tool mode\r
+               if (!Hints.POINTERTOOL.equals(getHint(Hints.KEY_TOOL)) || getHint(SysdynElementHints.SYSDYN_KEY_TOOL) != null) {\r
+                       return false;\r
+               }\r
 \r
                KeyPressedEvent kpe;\r
                if (ke instanceof KeyPressedEvent) {\r
@@ -225,6 +232,11 @@ public class CreateVariablesShortcutParticipant extends AbstractDiagramParticipa
                } else {\r
                        return false;\r
                }\r
+               \r
+               // only create a variable if we are in the unmodified pointer tool mode\r
+               if (!Hints.POINTERTOOL.equals(getHint(Hints.KEY_TOOL)) || getHint(SysdynElementHints.SYSDYN_KEY_TOOL) != null) {\r
+                       return false;\r
+               }\r
 \r
                if (!\r
                                (\r
index 72de5cbed0d3e00bfca3bb96d9b7a366c4b1239f..e08193eac62d848046d95e6d5deea115d8c55b29 100644 (file)
@@ -193,7 +193,7 @@ public class SysdynConnectTool extends ConnectTool2 {
                                } else if (ti != null && ti == startFlag) {\r
                                        c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y),\r
                                                        ElementUtils.getElementBoundsOnDiagram(ti.e).getBounds2D());\r
-                               } else if (isEndingInFlag() && ti.e != null) {\r
+                               } else if (ti != null && isEndingInFlag()) {\r
                                        c.parentObstacle = org.simantics.scenegraph.utils.GeometryUtils.transformRectangle(AffineTransform.getTranslateInstance(c.x, c.y),\r
                                                        CloudFactory.CLOUD_IMAGE.getBounds());\r
                                } else {\r
index 7f4a2515afd0fefe0a496a3284d3a79c9cf78dc6..6a5a357718e5933cce0e22c02a4de8bcccd4e59c 100644 (file)
@@ -7,9 +7,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import org.eclipse.ui.handlers.RadioState;\r
 import org.simantics.g2d.canvas.Hints;\r
 import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.canvas.IToolMode;\r
 import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
-import org.simantics.utils.threads.ThreadUtils;\r
 \r
 public class DiagramToolHandler extends AbstractHandler {\r
 \r
@@ -22,44 +20,27 @@ public class DiagramToolHandler extends AbstractHandler {
 \r
                String value = (String)event.getCommand().getState(RadioState.STATE_ID).getValue();\r
                \r
-               final IToolMode mode;\r
+               // if one of the connection modes is selected, use the\r
+               // default connection tool as the base and indicate the\r
+               // desired connection type in another hint (this is done\r
+               // to make sure all features of the connection tool work\r
+               // as expected)\r
                if ("pointer".equals(value)) {\r
-                       mode = Hints.POINTERTOOL;\r
+                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);\r
+                       context.getDefaultHintContext().removeHint(SysdynElementHints.SYSDYN_KEY_TOOL);\r
                }\r
                else if ("dependency".equals(value)) {\r
-                       mode = SysdynElementHints.DEPENDENCY_TOOL;\r
+                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL);\r
+                       context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.DEPENDENCY_TOOL);\r
                }\r
                else if ("flow".equals(value)) {\r
-                       mode = SysdynElementHints.FLOW_TOOL;\r
+                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL);\r
+                       context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.FLOW_TOOL);\r
                }\r
                else if ("lock".equals(value)) {\r
-                       mode = SysdynElementHints.LOCK_TOOL;\r
+                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);\r
+                       context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, SysdynElementHints.LOCK_TOOL);\r
                }\r
-               else {\r
-                       return null;\r
-               }\r
-               \r
-               ThreadUtils.syncExec(context.getThreadAccess(), new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               if (mode.equals(SysdynElementHints.DEPENDENCY_TOOL) \r
-                                               || mode.equals(SysdynElementHints.FLOW_TOOL)) {\r
-                                       // if one of the connection modes is selected, use the\r
-                                       // default connection tool as the base and indicate the\r
-                                       // desired connection type in another hint (this is done\r
-                                       // to make sure all features of the connection tool work\r
-                                       // as expected)\r
-                                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL);\r
-                                       context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, mode);\r
-                               } else if (mode.equals(SysdynElementHints.LOCK_TOOL)) {\r
-                                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);\r
-                                       context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, mode);\r
-                               } else {\r
-                                       context.getDefaultHintContext().setHint(Hints.KEY_TOOL, mode);\r
-                                       context.getDefaultHintContext().removeHint(SysdynElementHints.SYSDYN_KEY_TOOL);\r
-                               }\r
-                       }\r
-               });\r
                \r
                return null;\r
        }\r