\r
@Override \r
protected PointerInteractor getPointerInteractor() {\r
- return new org.simantics.sysdyn.ui.editor.participant.PointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider());\r
+ return new org.simantics.sysdyn.ui.editor.participant.SysdynPointerInteractor(true, true, true, false, true, false, synchronizer.getElementClassProvider());\r
}\r
\r
@Override\r
+++ /dev/null
-package org.simantics.sysdyn.ui.editor.participant;\r
-/*******************************************************************************\r
- * Copyright (c) 2010 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
-\r
-import java.awt.Shape;\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.List;\r
-\r
-import org.simantics.diagram.participant.ConnectTool2;\r
-import org.simantics.g2d.canvas.Hints;\r
-import org.simantics.g2d.canvas.IToolMode;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
-import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;\r
-import org.simantics.g2d.connection.IConnectionAdvisor;\r
-import org.simantics.g2d.diagram.DiagramHints;\r
-import org.simantics.g2d.diagram.handler.PickContext;\r
-import org.simantics.g2d.diagram.participant.Selection;\r
-import org.simantics.g2d.diagram.participant.TerminalPainter;\r
-import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil;\r
-import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
-import org.simantics.g2d.element.ElementClasses;\r
-import org.simantics.g2d.element.IElement;\r
-import org.simantics.g2d.element.IElementClassProvider;\r
-import org.simantics.g2d.participant.KeyUtil;\r
-import org.simantics.g2d.participant.MouseUtil;\r
-import org.simantics.g2d.participant.TransformUtil;\r
-import org.simantics.g2d.utils.GeometryUtils;\r
-import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent;\r
-import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
-import org.simantics.sysdyn.ui.editor.participant.SysdynElementClassProviders.ISysdynElementClassProvider;\r
-import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
-import org.simantics.sysdyn.ui.editor.routing.FlowRouter;\r
-import org.simantics.sysdyn.ui.elements.AuxiliaryFactory;\r
-import org.simantics.sysdyn.ui.elements.CloudFactory;\r
-import org.simantics.sysdyn.ui.elements.InputFactory;\r
-import org.simantics.sysdyn.ui.elements.ModuleFactory;\r
-import org.simantics.sysdyn.ui.elements.connections.ConnectionClasses;\r
-\r
-/**\r
- * Pointer tool does the following operations with mouse:\r
- * - Selections\r
- * - Scale\r
- * - Rotate\r
- * - Translate\r
- * - Draws connections\r
- *\r
- *\r
- * Pointer tool is active only when KEY_TOOLMODE is PointerToolMode\r
- *\r
- * TODO Pick rectangle not a point\r
- *\r
- * @author Toni Kalajainen\r
- */\r
-public class PointerInteractor extends org.simantics.diagram.participant.PointerInteractor2 {\r
-\r
- @Dependency Selection selection;\r
- @Dependency KeyUtil keys;\r
- @Dependency TransformUtil util;\r
- @Dependency PickContext pickContext;\r
- @Dependency MouseUtil mice;\r
- @Reference TerminalPainter terminalPainter;\r
-\r
- public PointerInteractor(boolean clickSelect, boolean boxSelect, boolean dragElement, boolean dndDragElement, boolean connect, boolean doubleClickEdit, IElementClassProvider newConnectionClassProvider) {\r
- super(clickSelect, boxSelect, dragElement, dndDragElement, connect, doubleClickEdit, newConnectionClassProvider);\r
- }\r
-\r
- @EventHandler(priority = TOOL_PRIORITY)\r
- public boolean handlePress(MouseButtonPressedEvent me) {\r
- if (!connects()) return false;\r
- \r
- IToolMode mode = getHint(Hints.KEY_TOOL);\r
-\r
- if (mode != Hints.POINTERTOOL && mode != Hints.CONNECTTOOL) return false;\r
- assertDependencies();\r
- Point2D curCanvasPos = util.controlToCanvas(me.controlPosition, null);\r
-\r
- // Pick Terminal\r
- TerminalInfo ti = pickTerminal(me.controlPosition);\r
-\r
- if((me.stateMask & MouseEvent.ALT_MASK) == 0) return false;\r
-\r
- if(elementClassProvider != null) {\r
- ConnectTool2 bsi = null;\r
- if (ti != null) {\r
-\r
- IElement terminalElement = ti.e;\r
-\r
- if( me.button == MouseEvent.LEFT_BUTTON) {\r
- if(terminalElement.getElementClass().getId().equals(CloudFactory.class.getSimpleName())) return false;\r
- diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new DependencyRouter());\r
- diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, false);\r
- ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
- secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.DEPENDENCY));\r
-\r
- } else if (me.button == MouseEvent.RIGHT_BUTTON) {\r
- String id = terminalElement.getElementClass().getId();\r
- if(id.equals(AuxiliaryFactory.class.getSimpleName())\r
- || id.equals(InputFactory.class.getSimpleName())\r
- || id.equals(ModuleFactory.class.getSimpleName())) return false;\r
- diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter(false));\r
- diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true);\r
- ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
- secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW));\r
-\r
- }\r
-\r
- IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR);\r
- if (advisor == null || (advisor != null && advisor.canBeginConnection(null, ti.e, ti.t))) {\r
- bsi = new SysdynConnectTool(ti, me.mouseId, curCanvasPos);\r
- }\r
- } \r
- else if (me.button == MouseEvent.RIGHT_BUTTON) {\r
- // Start connection out of thin air, without a terminal.\r
- diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter(false));\r
- diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true);\r
- ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
- secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW));\r
- bsi = new SysdynConnectTool(null, me.mouseId, curCanvasPos);\r
- }\r
-\r
- if (bsi != null) {\r
- getContext().add(bsi);\r
- return true;\r
- }\r
-\r
- }\r
- return false;\r
- }\r
-\r
- public List<TerminalInfo> pickTerminals(Point2D controlPos)\r
- {\r
- Rectangle2D controlPickRect = new Rectangle2D.Double(controlPos.getX()-PointerInteractor.PICK_DIST, controlPos.getY()-PointerInteractor.PICK_DIST, PointerInteractor.PICK_DIST*2+1, PointerInteractor.PICK_DIST*2+1);\r
- Shape canvasPickRect = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform());\r
- List<TerminalInfo> ti = TerminalUtil.pickTerminals(diagram, canvasPickRect, false, true);\r
- return ti;\r
- }\r
-}\r
endFlagNode.setTransform(AffineTransform.getTranslateInstance(mouseCanvasPos.getX(), mouseCanvasPos.getY()));\r
}\r
\r
- List<TerminalInfo> tiList = ((org.simantics.sysdyn.ui.editor.participant.PointerInteractor)pi).pickTerminals(me.controlPosition);\r
+ List<TerminalInfo> tiList = ((org.simantics.sysdyn.ui.editor.participant.SysdynPointerInteractor)pi).pickTerminals(me.controlPosition);\r
TerminalInfo ti = null;\r
\r
IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR);\r
--- /dev/null
+package org.simantics.sysdyn.ui.editor.participant;\r
+/*******************************************************************************\r
+ * Copyright (c) 2010 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
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.List;\r
+\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.canvas.ICanvasParticipant;\r
+import org.simantics.g2d.canvas.IToolMode;\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;\r
+import org.simantics.g2d.connection.IConnectionAdvisor;\r
+import org.simantics.g2d.diagram.DiagramHints;\r
+import org.simantics.g2d.diagram.handler.PickContext;\r
+import org.simantics.g2d.diagram.participant.Selection;\r
+import org.simantics.g2d.diagram.participant.TerminalPainter;\r
+import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil;\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
+import org.simantics.g2d.element.ElementClasses;\r
+import org.simantics.g2d.element.IElementClassProvider;\r
+import org.simantics.g2d.participant.KeyUtil;\r
+import org.simantics.g2d.participant.MouseUtil;\r
+import org.simantics.g2d.participant.TransformUtil;\r
+import org.simantics.g2d.utils.GeometryUtils;\r
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;\r
+import org.simantics.sysdyn.ui.editor.participant.SysdynElementClassProviders.ISysdynElementClassProvider;\r
+import org.simantics.sysdyn.ui.editor.routing.DependencyRouter;\r
+import org.simantics.sysdyn.ui.editor.routing.FlowRouter;\r
+import org.simantics.sysdyn.ui.elements.AuxiliaryFactory;\r
+import org.simantics.sysdyn.ui.elements.CloudFactory;\r
+import org.simantics.sysdyn.ui.elements.InputFactory;\r
+import org.simantics.sysdyn.ui.elements.ModuleFactory;\r
+import org.simantics.sysdyn.ui.elements.SysdynElementHints;\r
+import org.simantics.sysdyn.ui.elements.connections.ConnectionClasses;\r
+\r
+/**\r
+ * Pointer tool does the following operations with mouse:\r
+ * - Selections\r
+ * - Scale\r
+ * - Rotate\r
+ * - Translate\r
+ * - Draws connections\r
+ *\r
+ * Pointer tool is active only when KEY_TOOLMODE is PointerToolMode\r
+ *\r
+ * TODO Pick rectangle not a point\r
+ *\r
+ * @author Toni Kalajainen\r
+ */\r
+public class SysdynPointerInteractor extends PointerInteractor {\r
+\r
+ @Dependency Selection selection;\r
+ @Dependency KeyUtil keys;\r
+ @Dependency TransformUtil util;\r
+ @Dependency PickContext pickContext;\r
+ @Dependency MouseUtil mice;\r
+ @Reference TerminalPainter terminalPainter;\r
+\r
+ public SysdynPointerInteractor(boolean clickSelect, boolean boxSelect, boolean dragElement, boolean dndDragElement, boolean connect, boolean doubleClickEdit, IElementClassProvider newConnectionClassProvider) {\r
+ super(clickSelect, boxSelect, dragElement, dndDragElement, connect, doubleClickEdit, newConnectionClassProvider);\r
+ }\r
+\r
+ @EventHandler(priority = TOOL_PRIORITY)\r
+ public boolean handlePress(MouseButtonPressedEvent me) {\r
+ if (!connects()) \r
+ return false;\r
+ if (elementClassProvider == null)\r
+ return false;\r
+ \r
+ IToolMode mode = getHint(Hints.KEY_TOOL);\r
+ if (!Hints.CONNECTTOOL.equals(mode))\r
+ return false;\r
+ \r
+ IToolMode sysdynMode = getHint(SysdynElementHints.SYSDYN_KEY_TOOL);\r
+ \r
+ assertDependencies();\r
+ \r
+ TerminalInfo ti = pickTerminal(me.controlPosition);\r
+ Point2D curCanvasPos = util.controlToCanvas(me.controlPosition, null);\r
+ \r
+ ICanvasParticipant bsi = null;\r
+ \r
+ if (me.button == MouseEvent.LEFT_BUTTON) {\r
+ if (SysdynElementHints.DEPENDENCY_TOOL.equals(sysdynMode))\r
+ bsi = getDependencyConnectTool(ti, me.mouseId, curCanvasPos);\r
+ else if (SysdynElementHints.FLOW_TOOL.equals(sysdynMode))\r
+ bsi = getFlowConnectTool(ti, me.mouseId, curCanvasPos);\r
+ else\r
+ bsi = getDependencyConnectTool(ti, me.mouseId, curCanvasPos);\r
+ }\r
+ else if (me.button == MouseEvent.RIGHT_BUTTON) {\r
+ if (SysdynElementHints.DEPENDENCY_TOOL.equals(sysdynMode) ||\r
+ SysdynElementHints.FLOW_TOOL.equals(sysdynMode))\r
+ return false;\r
+ else\r
+ bsi = getFlowConnectTool(ti, me.mouseId, curCanvasPos);\r
+ }\r
+\r
+ if (bsi != null) {\r
+ getContext().add(bsi);\r
+ return true;\r
+ }\r
+ \r
+ return false;\r
+ }\r
+ \r
+ private ICanvasParticipant getDependencyConnectTool(TerminalInfo ti, int mouseId, Point2D curCanvasPos) {\r
+ // can not have dependencies that start from thin air\r
+ if (ti == null)\r
+ return null;\r
+ // can not have dependencies that start from clouds\r
+ if (ti.e.getElementClass().getId().equals(CloudFactory.class.getSimpleName())) \r
+ return null;\r
+ \r
+ diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new DependencyRouter());\r
+ diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, false);\r
+ ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
+ secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.DEPENDENCY));\r
+\r
+ // not sure if this is necessary\r
+ IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR);\r
+ if (advisor == null || advisor.canBeginConnection(null, ti.e, ti.t)) {\r
+ return new SysdynConnectTool(ti, mouseId, curCanvasPos);\r
+ }\r
+ \r
+ return null;\r
+ }\r
+ \r
+ private ICanvasParticipant getFlowConnectTool(TerminalInfo ti, int mouseId, Point2D curCanvasPos) {\r
+ // flows must start from thin air or clouds\r
+ if (ti != null && (ti.e.getElementClass().getId().equals(AuxiliaryFactory.class.getSimpleName()) || \r
+ ti.e.getElementClass().getId().equals(InputFactory.class.getSimpleName()) || \r
+ ti.e.getElementClass().getId().equals(ModuleFactory.class.getSimpleName()))) \r
+ return null;\r
+ \r
+ diagram.setHint(DiagramHints.ROUTE_ALGORITHM, new FlowRouter());\r
+ diagram.setHint(DiagramHints.KEY_USE_CONNECTION_FLAGS, true);\r
+ ISysdynElementClassProvider secp = (ISysdynElementClassProvider)elementClassProvider;\r
+ secp.put(ElementClasses.CONNECTION, elementClassProvider.get(ConnectionClasses.FLOW));\r
+ \r
+ // not sure if this is necessary\r
+ IConnectionAdvisor advisor = diagram.getHint(DiagramHints.CONNECTION_ADVISOR);\r
+ if (ti == null || advisor == null || advisor.canBeginConnection(null, ti.e, ti.t)) {\r
+ return new SysdynConnectTool(ti, mouseId, curCanvasPos);\r
+ }\r
+ \r
+ return null;\r
+ }\r
+\r
+ public List<TerminalInfo> pickTerminals(Point2D controlPos) {\r
+ Rectangle2D controlPickRect = new Rectangle2D.Double(controlPos.getX()-SysdynPointerInteractor.PICK_DIST, controlPos.getY()-SysdynPointerInteractor.PICK_DIST, SysdynPointerInteractor.PICK_DIST*2+1, SysdynPointerInteractor.PICK_DIST*2+1);\r
+ Shape canvasPickRect = GeometryUtils.transformShape(controlPickRect, util.getInverseTransform());\r
+ return TerminalUtil.pickTerminals(diagram, canvasPickRect, false, true);\r
+ }\r
+}\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.elements;\r
\r
+import org.simantics.g2d.canvas.IToolMode;\r
+import org.simantics.g2d.canvas.impl.ToolMode;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
\r
\r
public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE");\r
public static final Key KEY_ORIENTATION = new KeyOf(String.class, "ORIENTATION"); \r
- public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION"); \r
+ public static final Key KEY_LOCATION = new KeyOf(String.class, "LOCATION"); \r
+ \r
+ 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
\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.handlers;\r
+\r
+import org.eclipse.core.commands.AbstractHandler;\r
+import org.eclipse.core.commands.ExecutionEvent;\r
+import org.eclipse.core.commands.ExecutionException;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+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
+ @Override\r
+ public Object execute(ExecutionEvent event) throws ExecutionException {\r
+ final ICanvasContext context = (ICanvasContext)HandlerUtil.getActiveEditor(event).getAdapter(ICanvasContext.class);\r
+ if (context == null) {\r
+ throw new ExecutionException("Could not get context from editor");\r
+ }\r
+\r
+ String value = (String)event.getCommand().getState(RadioState.STATE_ID).getValue();\r
+ \r
+ final IToolMode mode;\r
+ if ("pointer".equals(value)) {\r
+ mode = Hints.POINTERTOOL;\r
+ }\r
+ else if ("dependency".equals(value)) {\r
+ mode = SysdynElementHints.DEPENDENCY_TOOL;\r
+ }\r
+ else if ("flow".equals(value)) {\r
+ mode = SysdynElementHints.FLOW_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) || 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
+ }\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
+\r
+}\r