]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Lock Sketch (refs #4545)
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 13 Nov 2013 14:10:47 +0000 (14:10 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 13 Nov 2013 14:10:47 +0000 (14:10 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28253 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynPointerInteractor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/HoverTextNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/MultilineTextNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/SysdynElementHints.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/DependencyNode.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowEdgeClass.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowNode.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramToolHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/SysdynWorkbenchUtils.java

index 51ec05150c273214af029740a679bf5cd4291ac4..f2c009021ef233edd7216e63fa0d89d98e256712 100644 (file)
             <command\r
                   commandId="org.simantics.sysdyn.ui.exportModelButton"\r
                   icon="platform:/plugin/com.famfamfam.silk/icons/disk.png"\r
-                  id="org.simantics.sysdyn.ui.export.button">\r
+                  id="org.simantics.sysdyn.ui.export.button"\r
+                  tooltip="Save model">\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.exportModelAsButton"\r
                   icon="icons/save_as.png"\r
-                  id="org.simantics.sysdyn.ui.exportAs.button">\r
+                  id="org.simantics.sysdyn.ui.exportAs.button"\r
+                  tooltip="Save model as...">\r
             </command>\r
          </toolbar>\r
          <toolbar\r
    </extension>\r
    <extension\r
          point="org.simantics.ui.toolbarCommand">\r
+      <command\r
+            commandId="org.simantics.sysdyn.ui.diagramTool"\r
+            image="platform:/plugin/com.famfamfam.silk/icons/lock.png"\r
+            name="Lock Sketch"\r
+            toolbarId="org.simantics.sysdyn.ui.diagramToolbar"\r
+            type="radio"\r
+            value="lock">\r
+      </command>\r
       <command\r
             commandId="org.simantics.sysdyn.ui.diagramTool"\r
             image="icons/cursor.png"\r
       <command\r
             commandId="org.simantics.sysdyn.ui.diagramTool"\r
             image="icons/dependency.png"\r
-            name="Create Dependency"\r
+            name="Create Dependency (Alt+Mouse1)"\r
             toolbarId="org.simantics.sysdyn.ui.diagramToolbar"\r
             type="radio"\r
             value="dependency">\r
       <command\r
             commandId="org.simantics.sysdyn.ui.diagramTool"\r
             image="icons/flow.png"\r
-            name="Create Flow"\r
+            name="Create Flow (Alt+Mouse2)"\r
             toolbarId="org.simantics.sysdyn.ui.diagramToolbar"\r
             type="radio"\r
             value="flow">\r
index 55df646393d77ebdde33a34d067e571be2292201..a5a0df8a39453d3b4d0c37ac3dac3dd68e784024 100644 (file)
@@ -100,7 +100,9 @@ public class SysdynPointerInteractor extends PointerInteractor {
                                bsi = getDependencyConnectTool(ti, me.mouseId, curCanvasPos);\r
                        else if (SysdynElementHints.FLOW_TOOL.equals(sysdynMode))\r
                                bsi = getFlowConnectTool(ti, me.mouseId, curCanvasPos);\r
-                       else\r
+                       else if (SysdynElementHints.LOCK_TOOL.equals(sysdynMode)) {\r
+                               // Do nothing.\r
+                       } else\r
                                bsi = getDependencyConnectTool(ti, me.mouseId, curCanvasPos);\r
                }\r
                else if (me.button == MouseEvent.RIGHT_BUTTON) {\r
index c469a1b5400a8f4f9ce742de9452fa8d512fedad..24f3ab168887d79e63cf20f6a364f84aa7174bf9 100644 (file)
@@ -29,7 +29,9 @@ import org.simantics.scenegraph.g2d.events.FocusEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent;\r
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
 \r
 public class HoverTextNode extends TextNode implements ISelectionPainterNode {\r
 \r
@@ -159,6 +161,16 @@ public class HoverTextNode extends TextNode implements ISelectionPainterNode {
         }\r
         return false;\r
     }\r
+    \r
+    @Override\r
+    protected boolean mouseDragged(MouseDragBegin e) {\r
+       // Disable dragging if LockSketch is ON\r
+               if (SysdynElementHints.LOCK_TOOL.equals(SysdynWorkbenchUtils.getSysdynToolMode())){\r
+                       super.mouseDragged(e);\r
+                       return true;}\r
+               else\r
+                       return super.mouseDragged(e);\r
+    }\r
 \r
     public TextEditActivation activateEdit(int mouseId, IElement e, ICanvasContext ctx, boolean save) {\r
        if (save)\r
index d36bb8b996bce5aeaaca2ae32536907f7cff6f89..4b27ba0fc17c9f8fcd73adfe36e6a6f359c55605 100644 (file)
@@ -28,8 +28,10 @@ import java.util.ArrayList;
 import java.util.Hashtable;\r
 \r
 import org.simantics.diagram.elements.TextNode;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;\r
 import org.simantics.scenegraph.utils.GeometryUtils;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
 \r
 /**\r
  * Multi-line text node for diagrams. Editing is not \r
@@ -274,5 +276,14 @@ public class MultilineTextNode extends TextNode {
         renderSelectedHover(g, isSelected, hover);\r
 \r
     }\r
-\r
+    \r
+    @Override\r
+    protected boolean mouseDragged(MouseDragBegin e) {\r
+       // Disable dragging if LockSketch is ON\r
+               if (SysdynElementHints.LOCK_TOOL.equals(SysdynWorkbenchUtils.getSysdynToolMode()))\r
+                       return false;\r
+               else\r
+                       return super.mouseDragged(e);\r
+    }\r
+    \r
 }\r
index 4a46af469131a2cdd952d2821f89101e914a44fb..14a59e8361b68aa553bc702e2ebe3241b1e5c1c8 100644 (file)
@@ -25,5 +25,6 @@ public class SysdynElementHints {
     public static final Key       SYSDYN_KEY_TOOL = new KeyOf(ToolMode.class, "SysdynKeyTool");\r
     public static final IToolMode DEPENDENCY_TOOL = new ToolMode("DependencyTool");\r
     public static final IToolMode FLOW_TOOL       = new ToolMode("FlowTool");\r
+    public static final IToolMode LOCK_TOOL       = new ToolMode("LockTool");\r
     \r
 }\r
index 24178b011b15479bc36d4117c23ebd08f55f74da..888c0a99cbdf6bdfb3c70d14610c0ee71ec0fe80 100644 (file)
@@ -38,6 +38,8 @@ import org.simantics.scenegraph.g2d.nodes.ConnectionNode;
 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;\r
 import org.simantics.scenegraph.utils.NodeUtil;\r
 import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
+import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
 import org.simantics.utils.datastructures.Pair;\r
 \r
 /**\r
@@ -298,6 +300,11 @@ public class DependencyNode extends TextNode implements ISelectionPainterNode {
        if (isEventDummy(e)) {\r
                return false;\r
        }\r
+       \r
+       // Disable dragging if LockSketch is ON\r
+               if (SysdynElementHints.LOCK_TOOL.equals(SysdynWorkbenchUtils.getSysdynToolMode()))\r
+                       return false;\r
+               \r
        //System.out.println(this.toString() + " event: " + e.toString());\r
        boolean selected = NodeUtil.isSelected(this, 2);\r
        double myRadialDistance = this.getRadialDistanse(e.controlPosition);\r
index f238ec379998a7129689e6aa0bb9d3ab01941f5b..c300b646164a6747e78315e91a85959c48a7e9c5 100644 (file)
@@ -24,8 +24,6 @@ import org.simantics.g2d.element.handler.ElementHandler;
 import org.simantics.g2d.element.handler.SceneGraph;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
 import org.simantics.scenegraph.g2d.nodes.connection.IRouteGraphListener;\r
-import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode;\r
-\r
 \r
 \r
 public class RouteFlowEdgeClass extends RouteGraphConnectionClass {\r
@@ -59,9 +57,9 @@ public class RouteFlowEdgeClass extends RouteGraphConnectionClass {
             if (rg == null || renderer == null) {\r
                 cleanup(connection);\r
             } else {\r
-                RouteGraphNode rgn = connection.getHint(KEY_RG_NODE);\r
+               RouteFlowNode rgn = connection.getHint(KEY_RG_NODE);\r
                 if (rgn == null) {\r
-                    rgn = parent.addNode(ElementUtils.generateNodeId(connection), RouteGraphNode.class);\r
+                    rgn = parent.addNode(ElementUtils.generateNodeId(connection), RouteFlowNode.class);\r
                     connection.setHint(KEY_RG_NODE, rgn);\r
                 }\r
                 rgn.setRouteGraph(rg);\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/connections/RouteFlowNode.java
new file mode 100644 (file)
index 0000000..5318096
--- /dev/null
@@ -0,0 +1,37 @@
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2012 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.elements.connections;\r
+\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;\r
+import org.simantics.scenegraph.g2d.nodes.connection.RouteGraphNode;\r
+import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
+import org.simantics.sysdyn.ui.utils.SysdynWorkbenchUtils;\r
+\r
+/**\r
+ * Node for flow arrows.\r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public class RouteFlowNode extends RouteGraphNode {\r
+\r
+       private static final long serialVersionUID = 2576929364910319487L;\r
+       boolean isLock = false;\r
+\r
+       @Override\r
+    protected boolean mouseDragged(MouseDragBegin e) {\r
+               // Disable dragging if LockSketch is ON\r
+               if (SysdynElementHints.LOCK_TOOL.equals(SysdynWorkbenchUtils.getSysdynToolMode()))\r
+                       return false;\r
+               else\r
+                       return super.mouseDragged(e);\r
+       }\r
+}\r
index e162c85f50807252a4f02bd731a59e8b6c06a30a..7f4a2515afd0fefe0a496a3284d3a79c9cf78dc6 100644 (file)
@@ -32,6 +32,9 @@ public class DiagramToolHandler extends AbstractHandler {
                else if ("flow".equals(value)) {\r
                        mode = SysdynElementHints.FLOW_TOOL;\r
                }\r
+               else if ("lock".equals(value)) {\r
+                       mode = SysdynElementHints.LOCK_TOOL;\r
+               }\r
                else {\r
                        return null;\r
                }\r
@@ -39,7 +42,8 @@ public class DiagramToolHandler extends AbstractHandler {
                ThreadUtils.syncExec(context.getThreadAccess(), new Runnable() {\r
                        @Override\r
                        public void run() {\r
-                               if (mode.equals(SysdynElementHints.DEPENDENCY_TOOL) || mode.equals(SysdynElementHints.FLOW_TOOL)) {\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
@@ -47,8 +51,10 @@ public class DiagramToolHandler extends AbstractHandler {
                                        // as expected)\r
                                        context.getDefaultHintContext().setHint(Hints.KEY_TOOL, Hints.CONNECTTOOL);\r
                                        context.getDefaultHintContext().setHint(SysdynElementHints.SYSDYN_KEY_TOOL, mode);\r
-                               }\r
-                               else {\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
index e728b3f4aa4fe77ba13e26a2aefef1653917d44b..987fce90dd749ed88345bb2e6cc4a172d4182c47 100644 (file)
 \r
 package org.simantics.sysdyn.ui.utils;\r
 \r
+import org.eclipse.ui.IEditorPart;\r
 import org.eclipse.ui.IWorkbench;\r
 import org.eclipse.ui.IWorkbenchPage;\r
 import org.eclipse.ui.IWorkbenchWindow;\r
 import org.eclipse.ui.PlatformUI;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.canvas.IToolMode;\r
 import org.simantics.modeling.ui.diagramEditor.DiagramEditor;\r
+import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
+import org.simantics.utils.datastructures.hints.IHintContext;\r
+import org.simantics.utils.threads.ThreadUtils;\r
 \r
 /**\r
  * Workbench utilities.\r
@@ -52,4 +58,38 @@ public class SysdynWorkbenchUtils {
                }\r
                return page;\r
        }\r
+       \r
+       public static IToolMode getSysdynToolMode() {\r
+               IWorkbenchPage p = SysdynWorkbenchUtils.getActivePageOfEditor();\r
+               IEditorPart editor = p.getActiveEditor();\r
+               final ICanvasContext context = (ICanvasContext)(editor.getAdapter(ICanvasContext.class));\r
+               ToolQuery toolQuery = new ToolQuery(context);\r
+               ThreadUtils.syncExec(context.getThreadAccess(), toolQuery);\r
+               return toolQuery.getSysdynToolMode();\r
+       }\r
+\r
+       static class ToolQuery implements Runnable {\r
+\r
+               private IToolMode mode;\r
+               private ICanvasContext context;\r
+               \r
+               ToolQuery(ICanvasContext context) {\r
+                       this.context = context;\r
+                       this.mode = null;\r
+               }\r
+               \r
+               @Override\r
+               public void run() {\r
+                       IHintContext hc = context.getDefaultHintContext();\r
+                       if (hc == null)\r
+                               return;\r
+                       IToolMode sysdynMode = hc.getHint(SysdynElementHints.SYSDYN_KEY_TOOL);\r
+                       mode = sysdynMode;\r
+               }\r
+               \r
+               public IToolMode getSysdynToolMode() {\r
+                       return mode;\r
+               }\r
+               \r
+       }\r
 }\r