version="0.0.0"\r
unpack="false"/>\r
\r
- <plugin\r
- id="org.simantics.h2d"\r
- download-size="0"\r
- install-size="0"\r
- version="0.0.0"\r
- unpack="false"/>\r
-\r
<plugin\r
id="org.simantics.sysdyn"\r
download-size="0"\r
Bundle-SymbolicName: org.simantics.sysdyn.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
- org.simantics.layer0.utils;bundle-version="0.6.2",
+Require-Bundle: org.simantics.layer0.utils;bundle-version="0.6.2",
org.simantics.scenegraph;bundle-version="0.9.0",
org.junit4;bundle-version="4.5.0",
org.simantics.ui;bundle-version="1.0.0",
<resource\r
uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r
class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
- <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r class="org.simantics.sysdyn.ui.project.SysdynProject" />\r </target>\r \r <target interface="org.simantics.project.IProjectLifeCycle">\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r </target>\r \r
- <target\r
- interface="org.simantics.scenegraph.adapters.ISceneGraphProvider">\r
- <type\r
- uri="http://www.simantics.org/Sysdyn-1.0/Configuration"\r
- class="org.simantics.sysdyn.ui.sg.SysdynSceneGraphProvider">\r
- <graph />\r
- <this />\r
- </type>\r
- </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Input"\r class="org.simantics.sysdyn.ui.browser.nodes.InputNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleNode">\r <this />\r </type>\r \r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode">\r <this />\r </resource>\r\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r <this />\r </resource>\r\r <type\r uri="http://www.simantics.org/Simulation-1.0/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r \r </target>\r\r <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r <target interface="org.simantics.g2d.diagram.DiagramClass">\r <adapter uri="http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram"\r adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r </target>\r\r <!-- Sysdyn symbols -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" /> \r </target>\r \r <!-- Sysdyn connections -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <!-- Edges -->\r <resource uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <!-- : SYSDYN.Connection-->\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowConnectionFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r </target>\r \r <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r <baseType uri="http://www.simantics.org/Diagram-2.0/HasConnector" />\r <resource uri="http://www.simantics.org/Diagram-2.0/HasPlainConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>none 0</string>\r </resource>\r <resource uri="http://www.simantics.org/Diagram-2.0/HasArrowConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>fill 1</string>\r </resource>\r </target>\r \r
+ <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r class="org.simantics.sysdyn.ui.project.SysdynProject" />\r </target>\r \r <target interface="org.simantics.project.IProjectLifeCycle">\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r </target>\r \r <target\r interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r <type\r uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Input"\r class="org.simantics.sysdyn.ui.browser.nodes.InputNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleNode">\r <this />\r </type>\r \r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/Module"\r class="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode">\r <this />\r </resource>\r\r <resource\r uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.browser.nodes.SymbolNode">\r <this />\r </resource>\r\r <type\r uri="http://www.simantics.org/Simulation-1.0/Experiment"\r class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r <this />\r </type>\r \r <type\r uri="http://www.simantics.org/Sysdyn-1.0/Result"\r class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r <this />\r </type>\r \r </target>\r\r <!-- Inject default connection routing algorithm for sysdyn diagrams -->\r <target interface="org.simantics.g2d.diagram.DiagramClass">\r <adapter uri="http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram"\r adapterClass="org.simantics.sysdyn.ui.elements2.ConfigurationDiagramClassAdapter" />\r </target>\r\r <!-- Sysdyn symbols -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" />\r\r <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r class="org.simantics.sysdyn.ui.elements2.ModuleFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/InputSymbol"\r class="org.simantics.sysdyn.ui.elements2.InputFactory" /> \r </target>\r \r <!-- Sysdyn connections -->\r <target interface="org.simantics.diagram.adapter.ElementFactory">\r <!-- Edges -->\r <resource uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <resource uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowEdgeFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyEdgeFactory" />\r <!-- : SYSDYN.Connection-->\r <type uri="http://www.simantics.org/Sysdyn-1.0/FlowConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.FlowConnectionFactory" />\r <type uri="http://www.simantics.org/Sysdyn-1.0/DependencyConnection"\r class="org.simantics.sysdyn.ui.elements2.connections.DependencyConnectionFactory" />\r </target>\r \r <target interface="org.simantics.g2d.connection.EdgeVisualsConfigurer">\r <baseType uri="http://www.simantics.org/Diagram-2.0/HasConnector" />\r <resource uri="http://www.simantics.org/Diagram-2.0/HasPlainConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>none 0</string>\r </resource>\r <resource uri="http://www.simantics.org/Diagram-2.0/HasArrowConnector"\r class="org.simantics.diagram.content.ArrowConfigurer">\r <string>fill 1</string>\r </resource>\r </target>\r \r
</adapters>
\ No newline at end of file
id="org.simantics.sysdyn.ui.diagramViewer"\r
name="System dynamic diagram viewer">\r
</editor>\r
- <editor\r
- class="org.simantics.sysdyn.ui.editor.SysdynDiagramEditor"\r
- default="false"\r
- id="org.simantics.sysdyn.ui.diagramEditor"\r
- name="System dynamic diagram editor">\r
- </editor>\r
<editor\r
class="org.simantics.sysdyn.ui.modelica.SysdynModelicaEditor"\r
contributorClass="org.simantics.sysdyn.ui.modelica.TextEditorActionBarContributor"\r
groupId="org.simantics.diagramEditor.group"\r
priority="100">\r
</adapterClass>\r
- <adapter\r
- editorId="org.simantics.sysdyn.ui.diagramEditor"\r
- priority="3"\r
- type_uris="http://www.simantics.org/Sysdyn-1.0/Configuration">\r
- </adapter>\r
<adapter\r
editorId="org.simantics.sysdyn.ui.modelicaEditor"\r
priority="2"\r
id="org.simantics.sysdyn.ui.showModule"\r
name="Show Module">\r
</command>\r
- <command\r
- defaultHandler="org.simantics.sysdyn.ui.handlers.CreateAuxiliaryHandler"\r
- id="org.simantics.sysdyn.ui.createAuxiliary"\r
- name="Create Auxiliary">\r
- </command>\r
- <command\r
- defaultHandler="org.simantics.sysdyn.ui.handlers.CreateCloudHandler"\r
- id="org.simantics.sysdyn.ui.createCloud"\r
- name="Create Cloud">\r
- </command>\r
- <command\r
- defaultHandler="org.simantics.sysdyn.ui.handlers.CreateStockHandler"\r
- id="org.simantics.sysdyn.ui.createStock"\r
- name="Create Stock">\r
- </command>\r
- <command\r
- defaultHandler="org.simantics.sysdyn.ui.handlers.CreateValveHandler"\r
- id="org.simantics.sysdyn.ui.createValve"\r
- name="Create Valve">\r
- </command>\r
- <command\r
- id="org.simantics.sysdyn.ui.remove"\r
- name="Remove">\r
- </command>\r
- <command\r
- id="org.simantics.sysdyn.ui.rename"\r
- name="Rename">\r
- </command>\r
<command\r
id="org.simantics.sysdyn.ui.removeNode"\r
name="Remove Node">\r
name="Rename Node">\r
</command>\r
<command\r
- defaultHandler="org.simantics.sysdyn.ui.actions.ToggleSimulation"\r
+ defaultHandler="org.simantics.sysdyn.ui.handlers.ToggleSimulation"\r
id="org.simantics.sysdyn.ui.toggleSimulation"\r
name="Toggle Simulate">\r
<state\r
class="org.simantics.sysdyn.ui.trend.PinTrend"\r
commandId="org.simantics.sysdyn.ui.trend.view.pin">\r
</handler>\r
- <handler\r
- class="org.simantics.sysdyn.ui.handlers.RemoveHandler"\r
- commandId="org.simantics.sysdyn.ui.remove">\r
- <activeWhen>\r
- <with\r
- variable="selection">\r
- <not>\r
- <count\r
- value="0">\r
- </count>\r
- </not>\r
- </with>\r
- </activeWhen>\r
- </handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.ShowModuleHandler"\r
commandId="org.simantics.sysdyn.ui.showModule">\r
</and>\r
</enabledWhen>\r
</handler>\r
- <handler\r
- class="org.simantics.sysdyn.ui.handlers.RenameHandler"\r
- commandId="org.simantics.sysdyn.ui.rename">\r
- <activeWhen>\r
- <with\r
- variable="selection">\r
- <count\r
- value="1">\r
- </count>\r
- </with>\r
- </activeWhen>\r
- </handler>\r
<handler\r
class="org.simantics.sysdyn.ui.handlers.UnlinkNodeHandler2"\r
commandId="org.simantics.sysdyn.ui.removeNode">\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import javax.swing.JFrame;\r
-\r
-import org.simantics.h2d.canvas.EditorCanvas;\r
-import org.simantics.h2d.diagram.Diagram;\r
-import org.simantics.h2d.editor.impl.DiagramEditor;\r
-import org.simantics.h2d.event.handler.DefaultEventHandlers;\r
-import org.simantics.sysdyn.ui.actions.Connect;\r
-import org.simantics.sysdyn.ui.actions.CreateAuxiliary;\r
-import org.simantics.sysdyn.ui.actions.CreateCloud;\r
-import org.simantics.sysdyn.ui.actions.CreateStock;\r
-import org.simantics.sysdyn.ui.actions.CreateValve;\r
-\r
-public class TestDiagramEditor extends JFrame {\r
-\r
- public TestDiagramEditor() {\r
- super("Test Canvas");\r
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
- \r
- Diagram diagram = new Diagram();\r
- final DiagramEditor editor = new DiagramEditor(getRootPane(), diagram);\r
- \r
- DefaultEventHandlers.configure(editor);\r
- editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
- editor.addEventHandler(1, "key(S)", new CreateStock());\r
- editor.addEventHandler(1, "key(V)", new CreateValve());\r
- editor.addEventHandler(1, "key(C)", new CreateCloud());\r
- editor.addEventHandler(1, "drag(alt+left)", new Connect());\r
- \r
- getContentPane().add(new EditorCanvas(editor));\r
-\r
- setSize(800, 600);\r
- }\r
- \r
- public static void main(String[] args) {\r
- javax.swing.SwingUtilities.invokeLater(new Runnable() {\r
- public void run() {\r
- new TestDiagramEditor().setVisible(true);\r
- }\r
- }); \r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.event.DragEvent;\r
-import org.simantics.h2d.event.handler.DragEventHandler;\r
-import org.simantics.h2d.node.RectangleNode;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.sysdyn.ui.elements.AuxiliaryElement;\r
-import org.simantics.sysdyn.ui.elements.CloudElement;\r
-import org.simantics.sysdyn.ui.elements.DependencyElement;\r
-import org.simantics.sysdyn.ui.elements.FlowElement;\r
-import org.simantics.sysdyn.ui.elements.StockElement;\r
-import org.simantics.sysdyn.ui.elements.ValveElement;\r
-\r
-public class Connect extends DragEventHandler {\r
-\r
- Connectable from;\r
- Connectable to;\r
- \r
- RectangleNode fromNode = new RectangleNode(); \r
- RectangleNode toNode = new RectangleNode();\r
- \r
- @Override\r
- protected boolean begin(IDiagramEditor editor, DragEvent event) {\r
- for(IElement element : event.pickedElements) {\r
- Connectable connectable = element.getInterface(Connectable.class);\r
- if(connectable != null) {\r
- this.from = connectable;\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- @Override\r
- protected void update(IDiagramEditor editor, DragEvent event) {\r
- for(IElement element : editor.pickElements(event.current)) {\r
- Connectable connectable = element.getInterface(Connectable.class); \r
- if(connectable != null && connectable != from) {\r
- if(connectable == to)\r
- return;\r
- to = connectable;\r
- \r
- Rectangle2D bounds = new Rectangle2D.Double(); \r
- to.getBounds(bounds);\r
- bounds.setFrame(\r
- bounds.getX()-2.0, \r
- bounds.getY()-2.0, \r
- bounds.getWidth()+4.0, \r
- bounds.getHeight()+4.0); \r
- toNode.init(bounds);\r
- \r
- editor.requestRepaint(); \r
- return;\r
- }\r
- }\r
- to = null;\r
- toNode.init(fromNode.getBounds());\r
- editor.requestRepaint();\r
- }\r
- \r
- @Override\r
- protected void end(IDiagramEditor editor, DragEvent event) {\r
- if(to != null) {\r
- IElement newElement;\r
- if(from instanceof ValveElement && to instanceof StockElement)\r
- newElement = new FlowElement(from, to);\r
- else if(from instanceof StockElement && to instanceof ValveElement)\r
- newElement = new FlowElement(from, to);\r
- else if( (from instanceof StockElement || from instanceof CloudElement) \r
- && (to instanceof StockElement || to instanceof CloudElement)) {\r
- Point2D fromOrigo = from.getOrigo();\r
- Point2D toOrigo = to.getOrigo();\r
- newElement = new ValveElement(\r
- 0.5 * (fromOrigo.getX() + toOrigo.getX()),\r
- 0.5 * (fromOrigo.getY() + toOrigo.getY())\r
- );\r
- editor.getDiagram().addElement(new FlowElement(from, (ValveElement)newElement));\r
- editor.getDiagram().addElement(new FlowElement((ValveElement)newElement, to)); \r
- }\r
- else if(from instanceof ValveElement && to instanceof AuxiliaryElement)\r
- newElement = new DependencyElement(to, from);\r
- else if(from instanceof AuxiliaryElement && to instanceof StockElement)\r
- newElement = new DependencyElement(to, from);\r
- else \r
- newElement = new DependencyElement(from, to);\r
- editor.getDiagram().addElement(newElement);\r
- if(newElement instanceof ValveElement)\r
- ((ValveElement)newElement).beginRenameAction(editor);\r
- }\r
- \r
- from = null;\r
- to = null;\r
- }\r
- \r
- @Override\r
- public void init(G2DParentNode parent) {\r
- fromNode = parent.addNode(RectangleNode.class);\r
- toNode = parent.addNode(RectangleNode.class);\r
- \r
- Rectangle2D bounds = new Rectangle2D.Double(); \r
- from.getBounds(bounds);\r
- bounds.setFrame(\r
- bounds.getX()-2.0, \r
- bounds.getY()-2.0, \r
- bounds.getWidth()+4.0, \r
- bounds.getHeight()+4.0);\r
- \r
- fromNode.init(bounds);\r
- toNode.init(bounds);\r
- }\r
- \r
- @Override\r
- public void remove() {\r
- fromNode.remove();\r
- toNode.remove();\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.event.DragEvent;\r
-import org.simantics.h2d.event.handler.DragEventHandler;\r
-import org.simantics.h2d.node.RectangleNode;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-public abstract class ConnectBase extends DragEventHandler {\r
-\r
- protected Connectable from;\r
- protected Connectable to;\r
- \r
- RectangleNode fromNode = new RectangleNode(); \r
- RectangleNode toNode = new RectangleNode();\r
- \r
- /**\r
- * This is called when starting to make a connection.\r
- */\r
- protected abstract boolean isAllowedTail(Connectable tail);\r
- \r
- /**\r
- * This is called when the mouse hovers over another connection point.\r
- */\r
- protected abstract boolean isAllowedHead(Connectable head);\r
- \r
- protected abstract void connect(IDiagramEditor editor);\r
- \r
- @Override\r
- protected boolean begin(IDiagramEditor editor, DragEvent event) {\r
- for(IElement element : event.pickedElements) {\r
- Connectable connectable = element.getInterface(Connectable.class);\r
- if(connectable != null && isAllowedTail(connectable)) {\r
- this.from = connectable;\r
- return true;\r
- }\r
- }\r
- return false;\r
- }\r
- \r
- @Override\r
- protected void update(IDiagramEditor editor, DragEvent event) {\r
- for(IElement element : editor.pickElements(event.current)) {\r
- Connectable connectable = element.getInterface(Connectable.class); \r
- if(connectable != null && connectable != from) {\r
- if(connectable == to)\r
- return;\r
- if(!isAllowedHead(connectable))\r
- continue;\r
- to = connectable;\r
- \r
- Rectangle2D bounds = new Rectangle2D.Double(); \r
- to.getBounds(bounds);\r
- bounds.setFrame(\r
- bounds.getX()-2.0, \r
- bounds.getY()-2.0, \r
- bounds.getWidth()+4.0, \r
- bounds.getHeight()+4.0); \r
- toNode.init(bounds);\r
- \r
- editor.requestRepaint(); \r
- return;\r
- }\r
- }\r
- to = null;\r
- toNode.init(fromNode.getBounds());\r
- editor.requestRepaint();\r
- }\r
- \r
- @Override\r
- protected void end(IDiagramEditor editor, DragEvent event) {\r
- if(to != null)\r
- connect(editor);\r
- \r
- from = null;\r
- to = null;\r
- }\r
- \r
- @Override\r
- public void init(G2DParentNode parent) {\r
- fromNode = parent.addNode(RectangleNode.class);\r
- toNode = parent.addNode(RectangleNode.class);\r
- \r
- Rectangle2D bounds = new Rectangle2D.Double(); \r
- from.getBounds(bounds);\r
- bounds.setFrame(\r
- bounds.getX()-2.0, \r
- bounds.getY()-2.0, \r
- bounds.getWidth()+4.0, \r
- bounds.getHeight()+4.0);\r
- \r
- fromNode.init(bounds);\r
- toNode.init(bounds);\r
- }\r
- \r
- @Override\r
- public void remove() {\r
- fromNode.remove();\r
- toNode.remove();\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.sysdyn.ui.elements.AuxiliaryElement;\r
-import org.simantics.sysdyn.ui.elements.DependencyElement;\r
-import org.simantics.sysdyn.ui.elements.StockElement;\r
-import org.simantics.sysdyn.ui.elements.ValveElement;\r
-\r
-public class ConnectDependency extends ConnectBase {\r
-\r
- @Override\r
- protected boolean isAllowedTail(Connectable tail) {\r
- return tail instanceof AuxiliaryElement \r
- || tail instanceof StockElement\r
- || tail instanceof ValveElement \r
- ;\r
- }\r
- \r
- @Override\r
- protected boolean isAllowedHead(Connectable head) {\r
- return head instanceof AuxiliaryElement \r
- || head instanceof ValveElement\r
- ; \r
- }\r
-\r
- @Override\r
- protected void connect(IDiagramEditor editor) {\r
- editor.getDiagram().addElement(new DependencyElement(from, to)); \r
- }\r
-\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import java.awt.geom.Point2D;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.sysdyn.ui.elements.CloudElement;\r
-import org.simantics.sysdyn.ui.elements.FlowElement;\r
-import org.simantics.sysdyn.ui.elements.StockElement;\r
-import org.simantics.sysdyn.ui.elements.ValveElement;\r
-\r
-public class ConnectFlow extends ConnectBase {\r
-\r
- @Override\r
- protected boolean isAllowedTail(Connectable tail) {\r
- return tail instanceof CloudElement \r
- || tail instanceof StockElement\r
- || tail instanceof ValveElement\r
- ;\r
- }\r
- \r
- @Override\r
- protected boolean isAllowedHead(Connectable head) {\r
- return head instanceof CloudElement \r
- || head instanceof StockElement \r
- || (head instanceof ValveElement && !(from instanceof ValveElement))\r
- ; \r
- }\r
-\r
- @Override\r
- protected void connect(IDiagramEditor editor) {\r
- if(from instanceof ValveElement || to instanceof ValveElement)\r
- editor.getDiagram().addElement(new FlowElement(from, to));\r
- else {\r
- Point2D fromOrigo = from.getOrigo();\r
- Point2D toOrigo = to.getOrigo();\r
- ValveElement valveElement = new ValveElement(\r
- 0.5 * (fromOrigo.getX() + toOrigo.getX()),\r
- 0.5 * (fromOrigo.getY() + toOrigo.getY())\r
- );\r
- editor.getDiagram().addElement(valveElement);\r
- editor.getDiagram().addElement(new FlowElement(from, valveElement));\r
- editor.getDiagram().addElement(new FlowElement(valveElement, to));\r
- \r
- valveElement.beginRenameAction(editor);\r
- }\r
- }\r
-\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ILocatableEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.sysdyn.ui.elements.AuxiliaryElement;\r
-\r
-public class CreateAuxiliary implements IEventHandler {\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- ILocatableEvent event = (ILocatableEvent)_event;\r
- AuxiliaryElement element = new AuxiliaryElement("Auxiliary", \r
- event.getLocation().getX(),\r
- event.getLocation().getY());\r
- editor.getDiagram().addElement(element);\r
- element.beginRenameAction(editor);\r
- editor.requestRepaint();\r
- return true;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ILocatableEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.sysdyn.ui.elements.CloudElement;\r
-\r
-public class CreateCloud implements IEventHandler {\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- ILocatableEvent event = (ILocatableEvent)_event;\r
- CloudElement element = new CloudElement( \r
- event.getLocation().getX(),\r
- event.getLocation().getY());\r
- editor.getDiagram().addElement(element); \r
- editor.requestRepaint();\r
- return true;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ILocatableEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.sysdyn.ui.elements.StockElement;\r
-\r
-public class CreateStock implements IEventHandler {\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- ILocatableEvent event = (ILocatableEvent)_event;\r
- StockElement element = new StockElement("Stock", \r
- event.getLocation().getX(),\r
- event.getLocation().getY());\r
- editor.getDiagram().addElement(element);\r
- element.beginRenameAction(editor);\r
- editor.requestRepaint();\r
- return true;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ILocatableEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.sysdyn.ui.elements.ValveElement;\r
-\r
-public class CreateValve implements IEventHandler {\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- ILocatableEvent event = (ILocatableEvent)_event;\r
- editor.getDiagram().addElement(new ValveElement( \r
- event.getLocation().getX(),\r
- event.getLocation().getY()));\r
- editor.requestRepaint();\r
- return true;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-\r
-public class DiagramContextMenuData {\r
- public final IDiagramEditor diagramEditor;\r
- public final IEvent event;\r
- \r
- public DiagramContextMenuData(IDiagramEditor diagramEditor, IEvent event) {\r
- this.diagramEditor = diagramEditor;\r
- this.event = event;\r
- } \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.actions;\r
-\r
-import org.eclipse.jface.action.GroupMarker;\r
-import org.eclipse.jface.action.IMenuListener;\r
-import org.eclipse.jface.action.IMenuManager;\r
-import org.eclipse.jface.action.MenuManager;\r
-import org.eclipse.jface.action.Separator;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.ui.IWorkbenchActionConstants;\r
-import org.eclipse.ui.IWorkbenchPartSite;\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ReleaseEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-\r
-public class OpenContextMenu implements IEventHandler {\r
-\r
- Control control;\r
- IWorkbenchPartSite site;\r
- String menuId;\r
-\r
- MenuManager menuManager;\r
-\r
- public OpenContextMenu(Control control, IWorkbenchPartSite site,\r
- String menuId) {\r
- super();\r
- this.control = control;\r
- this.site = site;\r
- this.menuId = menuId;\r
- menuManager = createPopupMenu();\r
- if (menuManager != null) {\r
- Menu menu = menuManager.createContextMenu(control);\r
- control.setMenu(menu);\r
- if (site != null) {\r
- site.registerContextMenu(menuManager.getId(), menuManager,\r
- site.getSelectionProvider());\r
- }\r
- }\r
- }\r
-\r
- @Override\r
- public boolean handle(final IDiagramEditor editor, IEvent _event) {\r
- final ReleaseEvent event = (ReleaseEvent)_event;\r
- control.getDisplay().asyncExec(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- if (control.isDisposed())\r
- return;\r
- //Point p = control.toDisplay(event.getLocation().get(int) cp.getX(), (int) cp.getY());\r
- menuManager.getMenu().setLocation(\r
- new Point((int)event.dispPoint.getX(), (int)event.dispPoint.getY()));\r
- menuManager.getMenu().setData(\r
- new DiagramContextMenuData(editor, event)\r
- );\r
- menuManager.getMenu().setVisible(true);\r
- }\r
-\r
- });\r
- return true;\r
- }\r
-\r
- protected MenuManager createPopupMenu() {\r
- final MenuManager mm = new MenuManager("Diagram Popup", menuId);\r
- mm.setRemoveAllWhenShown(true);\r
- mm.addMenuListener(new IMenuListener() {\r
- public void menuAboutToShow(IMenuManager manager) {\r
- mm.add(new GroupMarker(IWorkbenchActionConstants.WB_START));\r
- mm.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));\r
- mm.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));\r
- mm.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
- mm.add(new GroupMarker(IWorkbenchActionConstants.WB_END));\r
- }\r
- });\r
- return mm;\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.editor;\r
-\r
-import java.awt.Frame;\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-\r
-import javax.swing.SwingUtilities;\r
-\r
-import org.eclipse.jface.viewers.StructuredSelection;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.awt.SWT_AWT;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorSite;\r
-import org.eclipse.ui.PartInitException;\r
-import org.simantics.browsing.ui.swt.IPropertyPage;\r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.management.ISessionContextProvider;\r
-import org.simantics.diagram.DiagramTypeUtils;\r
-import org.simantics.diagram.symbolcontribution.ISymbolProvider;\r
-import org.simantics.h2d.canvas.EditorCanvas;\r
-import org.simantics.h2d.diagram.IDiagram;\r
-import org.simantics.h2d.diagram.IDiagramListener;\r
-import org.simantics.h2d.editor.ISelection;\r
-import org.simantics.h2d.editor.ISelectionListener;\r
-import org.simantics.h2d.editor.impl.DiagramEditor;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.IElementListener;\r
-import org.simantics.h2d.event.handler.DefaultEventHandlers;\r
-import org.simantics.layer0.utils.triggers.IActivation;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.objmap.IMapping;\r
-import org.simantics.objmap.IMappingListener;\r
-import org.simantics.objmap.MappingException;\r
-import org.simantics.objmap.Mappings;\r
-import org.simantics.scenegraph.INode;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.sysdyn.ui.actions.ConnectDependency;\r
-import org.simantics.sysdyn.ui.actions.ConnectFlow;\r
-import org.simantics.sysdyn.ui.actions.CreateAuxiliary;\r
-import org.simantics.sysdyn.ui.actions.CreateCloud;\r
-import org.simantics.sysdyn.ui.actions.CreateStock;\r
-import org.simantics.sysdyn.ui.actions.CreateValve;\r
-import org.simantics.sysdyn.ui.actions.OpenContextMenu;\r
-import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.workbench.ResourceEditorPart;\r
-import org.simantics.ui.workbench.TitleRequest;\r
-import org.simantics.ui.workbench.TitleUpdater;\r
-import org.simantics.utils.datastructures.Callable;\r
-import org.simantics.utils.datastructures.Callback;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
-\r
-public class SysdynDiagramEditor extends ResourceEditorPart {\r
-\r
- EditorCanvas canvas;\r
- IDiagram diagram;\r
- IMapping mapping;\r
- Frame frame;\r
- boolean disposed = false;\r
- Composite frameComposite;\r
- Resource diagramResource;\r
- protected ISessionContextProvider sessionContextProvider;\r
- protected ISessionContext sessionContext;\r
- protected IActivation activation;\r
-\r
- IElementListener elementUpdateListener = new IElementListener() {\r
-\r
- @Override\r
- public void elementUpdated(IElement element) {\r
- mapping.rangeModified(element);\r
- }\r
-\r
- @Override\r
- public void elementRemoved(IElement element) {\r
- }\r
- };\r
-\r
- protected void readDiagram(ReadGraph g) throws DatabaseException {\r
- SysdynDiagramSchema schema = new SysdynDiagramSchema(g);\r
- mapping = Mappings.createWithListening(schema);\r
-\r
- try {\r
- diagram = (IDiagram)mapping.map(g, getInputResource());\r
- for(IElement element : diagram.getElements())\r
- element.addListener(elementUpdateListener);\r
- } catch (MappingException e) {\r
- e.printStackTrace();\r
- }\r
-\r
- final Session session = g.getSession();\r
- mapping.addMappingListener(new IMappingListener() {\r
-\r
- @Override\r
- public void rangeModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- try {\r
- session.syncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph)\r
- throws DatabaseException {\r
- mapping.updateDomain(graph);\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- });\r
- }\r
-\r
- @Override\r
- public void domainModified() {\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- try {\r
- session.syncRequest(new ReadRequest() {\r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- mapping.updateRange(graph);\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- });\r
- }\r
-\r
- });\r
-\r
- diagram.addDiagramListener(new IDiagramListener() {\r
-\r
- @Override\r
- public void elementAdded(IElement element) {\r
- mapping.rangeModified(diagram);\r
- element.addListener(elementUpdateListener);\r
- }\r
-\r
- @Override\r
- public void elementRemoved(IElement element) {\r
- mapping.rangeModified(element);\r
- mapping.rangeModified(diagram);\r
- }\r
-\r
- });\r
- }\r
-\r
- @Override\r
- public void init(IEditorSite site, IEditorInput input)\r
- throws PartInitException {\r
- super.init(site, input);\r
-\r
- try {\r
- SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
-\r
- @Override\r
- public void run(ReadGraph g) throws DatabaseException {\r
- diagramResource = g.getSingleObject(getInputResource(), ModelingResources.getInstance(g).CompositeToDiagram);\r
- readDiagram(g);\r
- }\r
-\r
- });\r
-\r
- SimanticsUI.getSession().asyncRequest(\r
- new TitleRequest(site.getId(), getResourceInput()) {\r
- @Override\r
- public String perform(ReadGraph graph) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- Resource r = graph.getSingleObject(\r
- getResourceInput().getResource(),\r
- SimulationResource.getInstance(graph).IsConfigurationOf);\r
- String label = graph.getPossibleRelatedValue(r, b.HasLabel);\r
- return label;\r
- }\r
- },\r
- new TitleUpdater(site.getShell().getDisplay(), new Callback<String>() {\r
- @Override\r
- public void run(String partName) {\r
- setPartName(partName);\r
- }\r
- }, new Callable<Boolean>() {\r
- @Override\r
- public Boolean call() {\r
- return disposed;\r
- }\r
- }));\r
- } catch (DatabaseException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
-\r
- @Override\r
- public void createPartControl(final Composite parent) {\r
- frameComposite = new Composite(parent,\r
- SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
- frame = SWT_AWT.new_Frame(frameComposite);\r
-\r
-\r
- /// KOKEILLAAN\r
-\r
- /*\r
- sessionContextProvider = SimanticsUI.getSessionContextProvider();\r
- sessionContext = sessionContextProvider.getSessionContext();\r
-\r
- IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);\r
- if (activationManager != null) {\r
- activation = activationManager.activate(diagramResource);\r
- }\r
- */\r
- /// LOPPUU\r
-\r
- final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
- getSite().setSelectionProvider(selectionProvider);\r
-\r
- final OpenContextMenu openContextMenu = new OpenContextMenu(\r
- parent, getSite(), "#SysdynDiagramPopup");\r
-\r
- SwingUtilities.invokeLater(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- DiagramEditor editor = new DiagramEditor(null, diagram);\r
-\r
- DefaultEventHandlers.configure(editor);\r
- editor.addEventHandler(1, "key(A)", new CreateAuxiliary());\r
- editor.addEventHandler(1, "key(S)", new CreateStock());\r
- editor.addEventHandler(1, "key(V)", new CreateValve());\r
- editor.addEventHandler(1, "key(C)", new CreateCloud());\r
- editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
- editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
- editor.addEventHandler(1, "release(right)", openContextMenu);\r
-\r
- canvas = new EditorCanvas(editor);\r
- frame.add(canvas);\r
-\r
- frameComposite.getDisplay().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- setFocus();\r
- }\r
- });\r
-\r
-\r
- editor.getSelection().addSelectionListener(new ISelectionListener() {\r
-\r
- @Override\r
- public void selectionChanged(ISelection selection) {\r
- final ArrayList<Resource> resources = new ArrayList<Resource>(selection.size());\r
- for(IElement element : selection)\r
- resources.add(mapping.inverseGet(element));\r
- frameComposite.getDisplay().asyncExec(new Runnable() {\r
-\r
- @Override\r
- public void run() {\r
- if(!frameComposite.isDisposed())\r
- selectionProvider.setSelection(new StructuredSelection(resources));\r
- }\r
-\r
- });\r
- }\r
-\r
- });\r
- }\r
-\r
- });\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- if(frameComposite != null && !frameComposite.isDisposed()) {\r
- frameComposite.setFocus();\r
- if(canvas!=null)\r
- canvas.requestFocus();\r
- }\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- mapping.dispose();\r
- frame.dispose();\r
- disposed = true;\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public Object getAdapter(Class adapter) {\r
- if (adapter == INode.class) {\r
- return canvas.getEditor().getSceneGraph();\r
- }\r
- if (adapter == ISymbolProvider.class) {\r
- try {\r
-\r
- return DiagramTypeUtils.readSymbolContributions(SimanticsUI.getSession(), diagramResource);\r
- } catch (DatabaseException e) {\r
- ErrorLogger.defaultLogError(getClass() + " failed to adapt to ISymbolProvider, see exception for details.", e);\r
- return null;\r
- }\r
- }\r
- if (adapter == IPropertyPage.class) {\r
- return new SysdynPropertyPage(getSite(), Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser"));\r
- }\r
- return super.getAdapter(adapter);\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.editor;\r
-\r
-import java.util.Collection;\r
-\r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.h2d.diagram.Diagram;\r
-import org.simantics.objmap.rules.MappedElementsRule;\r
-import org.simantics.objmap.rules.domain.RelatedObjectsAccessor;\r
-import org.simantics.objmap.rules.range.FieldAccessor;\r
-import org.simantics.objmap.schema.MappingSchemas;\r
-import org.simantics.objmap.schema.SimpleLinkType;\r
-import org.simantics.objmap.schema.SimpleSchema;\r
-import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.elements.AuxiliaryElement;\r
-import org.simantics.sysdyn.ui.elements.CloudElement;\r
-import org.simantics.sysdyn.ui.elements.DependencyElement;\r
-import org.simantics.sysdyn.ui.elements.FlowElement;\r
-import org.simantics.sysdyn.ui.elements.StockElement;\r
-import org.simantics.sysdyn.ui.elements.ValveElement;\r
-\r
-public class SysdynDiagramSchema extends SimpleSchema {\r
-\r
- public SysdynDiagramSchema(ReadGraph g) throws DatabaseException {\r
- Builtins b = g.getBuiltins();\r
- SysdynResource sr = SysdynResource.getInstance(g);\r
- try {\r
- {\r
- SimpleLinkType linkType = \r
- new SimpleLinkType(sr.Configuration, Diagram.class);\r
- linkType.addRule(new MappedElementsRule(\r
- new RelatedObjectsAccessor(b.ConsistsOf, true),\r
- new FieldAccessor<Collection<Object>>(Diagram.class.getField("elements"))\r
- ));\r
- addLinkType(linkType);\r
- } \r
- \r
- addLinkType(MappingSchemas.fromAnnotations(g, AuxiliaryElement.class)); \r
- addLinkType(MappingSchemas.fromAnnotations(g, StockElement.class));\r
- addLinkType(MappingSchemas.fromAnnotations(g, CloudElement.class));\r
- addLinkType(MappingSchemas.fromAnnotations(g, ValveElement.class));\r
- addLinkType(MappingSchemas.fromAnnotations(g, DependencyElement.class));\r
- addLinkType(MappingSchemas.fromAnnotations(g, FlowElement.class));\r
- } catch(NoSuchFieldException e) {\r
- e.printStackTrace();\r
- } catch (InstantiationException e) {\r
- e.printStackTrace();\r
- } catch (IllegalAccessException e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.geom.Rectangle2D;\r
-\r
-public class Arcs {\r
-\r
- public static final double PI2 = Math.PI*2.0;\r
- \r
- /**\r
- * Returns angle + 2PI * n such that the\r
- * result is between -PI and PI.\r
- */\r
- public static double normalizeAngle(double angle) {\r
- return Math.IEEEremainder(angle, PI2);\r
- }\r
- \r
- /**\r
- * Returns true, if three normalized angles are clockwise oriented.\r
- */\r
- public static boolean areClockwiseOrdered(double angle1, double angle2, double angle3) {\r
- //System.out.println(angle1 + " " + angle2 + " " + angle3);\r
- return angle1 < angle2 \r
- ? (angle2 < angle3 || angle3 < angle1)\r
- : (angle2 < angle3 && angle3 < angle1)\r
- ;\r
- }\r
- \r
- /**\r
- * Returns an angle in radians between straight line from (x0,y0) to (x2,y2)\r
- * and an arc from (x0,y0) to (x2,y2) thru (x1,y1). The angle\r
- * is measured at (x0,y0) and is between -PI and PI.\r
- */\r
- public static double angleOfArc(\r
- double x0, double y0, \r
- double x1, double y1,\r
- double x2, double y2) {\r
- double dx0 = x1-x0;\r
- double dy0 = y1-y0;\r
- double dx1 = x1-x2;\r
- double dy1 = y1-y2;\r
- double dx = x2-x0;\r
- double dy = y2-y0;\r
- // Length of cross product (p1-p0)x(p2-p0)\r
- double dd = dx0*dy - dy0*dx; \r
- \r
- if(Math.abs(dd) < 1e-6) // Points are (almost) collinear\r
- return 0.0;\r
- else { \r
- // (p1-p0)*(p1-p2) / dd\r
- double offset = (dx0*dx1 + dy0*dy1) / dd;\r
- double angle = Math.PI*0.5 - Math.atan(offset);\r
- if(dd > 0.0)\r
- angle = angle-Math.PI;\r
- return angle;\r
- \r
- }\r
- }\r
- \r
- private static double updateBestNextAngle(double curAngle, double bestAngle, double newAngle) {\r
- if(newAngle < curAngle)\r
- newAngle += PI2;\r
- if(newAngle < bestAngle)\r
- return newAngle;\r
- return bestAngle; \r
- } \r
- \r
- private static double updateBestPrevAngle(double curAngle, double bestAngle, double newAngle) {\r
- if(newAngle > curAngle)\r
- newAngle -= PI2;\r
- if(newAngle > bestAngle)\r
- return newAngle;\r
- return bestAngle; \r
- } \r
- \r
- public static double nextIntersectingAngle(double cx, double cy, double r,\r
- double curAngle, Rectangle2D rect, boolean dir) {\r
- if(!dir) {\r
- double bestAngle = curAngle + PI2;\r
- {\r
- double dx = rect.getMinX() - cx;\r
- if(Math.abs(dx) < r) {\r
- double angle = normalizeAngle(Math.acos(dx / r));\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle);\r
- }\r
- }\r
- {\r
- double dx = rect.getMaxX() - cx;\r
- if(Math.abs(dx) < r) {\r
- double angle = normalizeAngle(Math.acos(dx / r));\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle);\r
- }\r
- }\r
- {\r
- double dy = cy - rect.getMinY();\r
- if(Math.abs(dy) < r) {\r
- double angle = Math.asin(dy / r);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, \r
- normalizeAngle(Math.PI-angle));\r
- }\r
- }\r
- {\r
- double dy = cy - rect.getMaxY();\r
- if(Math.abs(dy) < r) {\r
- double angle = Math.asin(dy / r);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestNextAngle(curAngle, bestAngle, \r
- normalizeAngle(Math.PI-angle));\r
- }\r
- }\r
- return normalizeAngle(bestAngle);\r
- } \r
- else {\r
- double bestAngle = curAngle - PI2;\r
- {\r
- double dx = rect.getMinX() - cx;\r
- if(Math.abs(dx) < r) {\r
- double angle = normalizeAngle(Math.acos(dx / r));\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle);\r
- }\r
- }\r
- {\r
- double dx = rect.getMaxX() - cx;\r
- if(Math.abs(dx) < r) {\r
- double angle = normalizeAngle(Math.acos(dx / r));\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle);\r
- }\r
- }\r
- {\r
- double dy = cy - rect.getMinY();\r
- if(Math.abs(dy) < r) {\r
- double angle = Math.asin(dy / r);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, \r
- normalizeAngle(Math.PI-angle));\r
- }\r
- }\r
- {\r
- double dy = cy - rect.getMaxY();\r
- if(Math.abs(dy) < r) {\r
- double angle = Math.asin(dy / r);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle);\r
- bestAngle = updateBestPrevAngle(curAngle, bestAngle, \r
- normalizeAngle(Math.PI-angle));\r
- }\r
- }\r
- return normalizeAngle(bestAngle);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import org.simantics.objmap.annotations.GraphType;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Auxiliary")\r
-public class AuxiliaryElement extends TextElement {\r
- \r
- public AuxiliaryElement() { \r
- }\r
- \r
- public AuxiliaryElement(String label, double x, double y) {\r
- super(label, x, y);\r
- } \r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.geom.Path2D;\r
-\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.node.ShapeNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Cloud")\r
-public class CloudElement extends RectangularElement implements Connectable {\r
- \r
- public static final double CLOUD_SIZE_X = 5.0;\r
- public static final double CLOUD_SIZE_Y = 3.0;\r
- \r
- public static final double CLOUD_CURVES = 7;\r
- \r
- ShapeNode cloudNode;\r
- boolean rotated = false;\r
- \r
- public CloudElement() { \r
- }\r
- \r
- public CloudElement(double x, double y) {\r
- this.posX = x;\r
- this.posY = y; \r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- cloudNode = parent.addNode(ShapeNode.class);\r
- cloudNode.setColor(Color.BLACK);\r
- cloudNode.setScaleStroke(true);\r
- cloudNode.setStroke(new BasicStroke(1));\r
- update();\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- cloudNode.remove();\r
- }\r
- \r
- protected void update() {\r
- //bounds.setFrame(posX-CLOUD_SIZE_X, posY-CLOUD_SIZE_Y, 2.0*CLOUD_SIZE_X, 2.0*CLOUD_SIZE_Y);\r
- Path2D path = new Path2D.Double(); \r
- double ox = CLOUD_SIZE_X;\r
- double oy = 0.0;\r
- path.moveTo(posX+ox, posY+oy); \r
- for(int i=1;i<CLOUD_CURVES+1;++i) {\r
- double angle = (Math.PI * 2.0 / CLOUD_CURVES) * i;\r
- double x = Math.cos(angle) * CLOUD_SIZE_X;\r
- double y = Math.sin(angle) * CLOUD_SIZE_Y;\r
- path.curveTo(\r
- posX+(2*ox + x)*0.5, posY+(2*oy + y)*0.5,\r
- posX+(ox + 2*x)*0.5, posY+(oy + 2*y)*0.5,\r
- posX + x, posY + y);\r
- ox = x;\r
- oy = y;\r
- }\r
- cloudNode.setShape(path);\r
- bounds = path.getBounds2D();\r
- fireElementUpdated();\r
- }\r
-\r
- public boolean isRotated() {\r
- return rotated;\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Shape;\r
-import java.awt.geom.Arc2D;\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.Element;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.IElementListener;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.event.DragEvent;\r
-import org.simantics.h2d.event.handler.DragEventHandler;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.h2d.node.FilledShapeNode;\r
-import org.simantics.h2d.node.ShapeNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.objmap.annotations.RelatedElement;\r
-import org.simantics.objmap.annotations.RelatedValue;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Dependency")\r
-public class DependencyElement extends Element implements IElementListener {\r
- \r
- /*\r
- * Total length of the arrow is ARROW_LENGTH1 + ARROW_LENGTH2\r
- */\r
- public static double ARROW_LENGTH1 = 0.2;\r
- public static double ARROW_LENGTH2 = 3.0;\r
- public static double ARROW_WIDTH = 1.8;\r
- \r
- @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasTail")\r
- Connectable tail;\r
- @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasHead")\r
- Connectable head;\r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasAngle")\r
- double angle = 0.1;\r
-\r
- // Auxiliary \r
- double angle0;\r
- double angle1;\r
- double cx;\r
- double cy;\r
- double r;\r
- \r
- // Scene graph\r
- ShapeNode arcNode;\r
- FilledShapeNode arrowNode;\r
- \r
- public DependencyElement() { \r
- }\r
- \r
- public DependencyElement(Connectable tail, Connectable head) {\r
- super();\r
- this.tail = tail;\r
- this.head = head;\r
- }\r
- \r
- @Override\r
- public void elementUpdated(IElement element) {\r
- update(); \r
- } \r
-\r
- @Override\r
- public void remove() {\r
- arcNode.remove();\r
- arrowNode.remove();\r
- tail.removeListener(this);\r
- head.removeListener(this);\r
- super.remove();\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- tail.addListener(this);\r
- head.addListener(this);\r
- \r
- arcNode = parent.addNode(ShapeNode.class);\r
- arcNode.setScaleStroke(true);\r
- arcNode.setStroke(new BasicStroke(1));\r
- arrowNode = parent.addNode(FilledShapeNode.class);\r
- update();\r
- }\r
- \r
- protected Shape createArrow(double x, double y, double dx, double dy) {\r
- Path2D path = new Path2D.Double();\r
- path.moveTo(x+ARROW_LENGTH1*dx, y+ARROW_LENGTH1*dy);\r
- x -= ARROW_LENGTH2*dx;\r
- y -= ARROW_LENGTH2*dy;\r
- path.lineTo(x-ARROW_WIDTH*dy, y+ARROW_WIDTH*dx);\r
- path.lineTo(x+ARROW_WIDTH*dy, y-ARROW_WIDTH*dx);\r
- path.closePath();\r
- return path;\r
- }\r
- \r
- protected void updateSceneGraph() {\r
- double x0 = tail.getOrigo().getX();\r
- double y0 = tail.getOrigo().getY();\r
- double x1 = head.getOrigo().getX();\r
- double y1 = head.getOrigo().getY();\r
- \r
- double offset = \r
- Math.abs(angle) < 1.0e-6\r
- ? 1e3 * Math.signum(angle)\r
- : Math.tan(Math.PI*0.5-angle)*0.5;\r
- cx = 0.5*(x0+x1) + offset * (y1-y0);\r
- cy = 0.5*(y0+y1) + offset * (x0-x1);\r
- double dx0 = x0 - cx;\r
- double dy0 = y0 - cy;\r
- double dx1 = x1 - cx;\r
- double dy1 = y1 - cy;\r
- r = Math.sqrt(dx0*dx0 + dy0*dy0);\r
- Rectangle2D bounds = new Rectangle2D.Double();\r
- tail.getBounds(bounds);\r
- angle0 = Arcs.nextIntersectingAngle(cx, cy, r, \r
- Math.atan2(-dy0, dx0), bounds, angle < 0.0);\r
- head.getBounds(bounds);\r
- angle1 = Arcs.nextIntersectingAngle(cx, cy, r, \r
- Math.atan2(-dy1, dx1), bounds, angle > 0.0);\r
- double extent = angle1-angle0;\r
- //double arcAngle = angle0;\r
- if(angle < 0.0) {\r
- double temp = angle0; \r
- angle0 = angle1;\r
- angle1 = temp;\r
- extent = -extent;\r
- } \r
- if(extent < 0)\r
- extent += Math.PI*2.0;\r
- else if(extent >= 360.0)\r
- extent -= Math.PI*2.0;\r
- Shape shape = new Arc2D.Double(cx-r, cy-r, 2*r, 2*r, \r
- Math.toDegrees(angle0), \r
- Math.toDegrees(extent), \r
- Arc2D.OPEN); \r
- arcNode.setShape(shape);\r
- \r
- double xx = Math.cos(angle > 0.0 ? angle1 : angle0);\r
- double yy = -Math.sin(angle > 0.0 ? angle1 : angle0);\r
- Shape arrowShape = createArrow(cx + r*xx, cy + r*yy, \r
- angle < 0.0 ? -yy : yy, \r
- angle > 0.0 ? -xx : xx);\r
- arrowNode.setShape(arrowShape);\r
- }\r
- \r
- public void update() {\r
- if(arcNode != null)\r
- updateSceneGraph();\r
- fireElementUpdated();\r
- }\r
- \r
- @Override\r
- public void getBounds(Rectangle2D bounds) {\r
- bounds.setFrame(arcNode.getBounds());\r
- }\r
-\r
- @Override\r
- public boolean hitTest(double x, double y, double tolerance) {\r
- double dx = x-cx;\r
- double dy = y-cy;\r
- double dist = dx*dx + dy*dy;\r
- if(dist < (r+tolerance)*(r+tolerance) &&\r
- dist > (r-tolerance)*(r-tolerance)) {\r
- double angle = Arcs.normalizeAngle(Math.atan2(-dy, dx));\r
- if(Arcs.areClockwiseOrdered(angle0, angle, angle1))\r
- return true;\r
- }\r
- return false;\r
- }\r
- \r
- class EventHandler extends DragEventHandler {\r
- @Override\r
- protected boolean begin(IDiagramEditor editor, DragEvent event) {\r
- return event.startModifiers.equals("left");\r
- }\r
- \r
- @Override\r
- protected void update(IDiagramEditor editor, DragEvent event) {\r
- if(event == null)\r
- return;\r
- angle = Arcs.angleOfArc(\r
- tail.getOrigo().getX(), tail.getOrigo().getY(), \r
- event.current.getX(), event.current.getY(), \r
- head.getOrigo().getX(), head.getOrigo().getY()\r
- );\r
- DependencyElement.this.update();\r
- editor.requestRepaint();\r
- }\r
- }\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T> T getInterface(Class<T> clazz) {\r
- if(clazz == IEventHandler.class) \r
- return (T)new EventHandler();\r
- return super.getInterface(clazz);\r
- }\r
-\r
- @Override\r
- public void elementRemoved(IElement element) {\r
- remove(); \r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.geom.Path2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.h2d.element.Element;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.IElementListener;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.node.FilledShapeNode;\r
-import org.simantics.h2d.node.ShapeNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.objmap.annotations.RelatedElement;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Flow")\r
-public class FlowElement extends Element implements IElementListener {\r
-\r
- public static double ARROW_LENGTH = 3.2;\r
- public static double ARROW_WIDTH = 3;\r
-\r
- static final double OFFSET = 1.5;\r
- static final double ARROW_OFFSET = 3.2;\r
-\r
- /*\r
- * Total length of the arrow is ARROW_LENGTH1 + ARROW_LENGTH2\r
- */ \r
- @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasTail")\r
- Connectable tail;\r
- @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasHead")\r
- Connectable head;\r
-\r
- // Auxiliary \r
- double angle0;\r
- double angle1;\r
- double cx;\r
- double cy;\r
- double r;\r
-\r
- // Scene graph\r
- ShapeNode lineNode1;\r
- ShapeNode lineNode2;\r
- FilledShapeNode arrowNode;\r
-\r
- public FlowElement() { \r
- }\r
-\r
- public FlowElement(Connectable tail, Connectable head) {\r
- super();\r
- this.tail = tail;\r
- this.head = head;\r
- tail.addListener(this);\r
- head.addListener(this);\r
- }\r
-\r
- @Override\r
- public void elementUpdated(IElement element) {\r
- update(); \r
- } \r
-\r
- @Override\r
- public void remove() {\r
- lineNode1.remove();\r
- lineNode2.remove();\r
- arrowNode.remove();\r
- tail.removeListener(this);\r
- head.removeListener(this);\r
- super.remove();\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- tail.addListener(this);\r
- head.addListener(this);\r
-\r
- lineNode1 = parent.addNode(ShapeNode.class);\r
- lineNode1.setScaleStroke(true);\r
- lineNode2 = parent.addNode(ShapeNode.class);\r
- lineNode2.setScaleStroke(true);\r
-\r
- arrowNode = parent.addNode(FilledShapeNode.class);\r
- update();\r
- }\r
-\r
- protected void createArrow(Connectable head, Connectable tail) { \r
- double x = tail.getOrigo().getX();\r
- double y = tail.getOrigo().getY();\r
-\r
- Rectangle2D rect = new Rectangle2D.Double();\r
- head.getBounds(rect);\r
- double cx = rect.getCenterX();\r
- double minx = rect.getMinX();\r
- double maxx = rect.getMaxX();\r
- double miny = rect.getMinY();\r
- double maxy = rect.getMaxY();\r
-\r
- Path2D path = new Path2D.Double();\r
-\r
- // approach from top\r
- if (y < miny) {\r
- path.moveTo(cx, miny);\r
- path.lineTo(cx + ARROW_WIDTH, miny - ARROW_LENGTH);\r
- path.lineTo(cx - ARROW_WIDTH, miny - ARROW_LENGTH);\r
- } \r
-\r
- // approach from beneath\r
- else if (y > maxy) {\r
- path.moveTo(cx, maxy);\r
- path.lineTo(cx + ARROW_WIDTH, maxy + ARROW_LENGTH);\r
- path.lineTo(cx - ARROW_WIDTH, maxy + ARROW_LENGTH);\r
- }\r
-\r
- // approach from left\r
- else if (x < minx) {\r
- path.moveTo(minx, y);\r
- path.lineTo(minx - ARROW_LENGTH, y - ARROW_WIDTH);\r
- path.lineTo(minx - ARROW_LENGTH, y + ARROW_WIDTH);\r
- }\r
-\r
- // approach from right\r
- else if (x > maxx) {\r
- path.moveTo(maxx, y);\r
- path.lineTo(maxx + ARROW_LENGTH, y - ARROW_WIDTH);\r
- path.lineTo(maxx + ARROW_LENGTH, y + ARROW_WIDTH);\r
- }\r
- else\r
- return; // FIXME (HN) This is just a quick bugfix, didn't understand the logic completely \r
-\r
- path.closePath();\r
- arrowNode.setShape(path);\r
- }\r
-\r
- // TODO\r
-\r
- private void draw(boolean vertical, double ... coordinates) {\r
- lineNode1.setShape(Flows.createOffsetLine(vertical, OFFSET, coordinates));\r
- lineNode2.setShape(Flows.createOffsetLine(vertical, -OFFSET, coordinates));\r
- }\r
-\r
- private void draw(boolean hasArrow, Connectable valve, Connectable node) {\r
- double x0 = valve.getOrigo().getX();\r
- double y0 = valve.getOrigo().getY(); \r
- double x1 = node.getOrigo().getX();\r
- double y1 = node.getOrigo().getY();\r
-\r
- Rectangle2D rect = new Rectangle2D.Double();\r
- node.getBounds(rect);\r
- \r
- double minY = hasArrow ? rect.getMinY() - ARROW_OFFSET : rect.getMinY();\r
- double maxY = hasArrow ? rect.getMaxY() + ARROW_OFFSET : rect.getMaxY();\r
- double minX = hasArrow ? rect.getMinX() - ARROW_OFFSET : rect.getMinX();\r
- double maxX = hasArrow ? rect.getMaxX() + ARROW_OFFSET : rect.getMaxX();\r
- \r
- \r
- if( ((ValveElement)valve).rotated ) {\r
- if(y1 > y0)\r
- y0 += OFFSET;\r
- else\r
- y0 -= OFFSET;\r
- if(rect.getMinX() <= x0 && rect.getMaxX() >= x0) {\r
- if(y1 > y0)\r
- draw(true, y0, x0, minY);\r
- else\r
- draw(true, y0, x0, maxY);\r
- }\r
- else {\r
- if(x1 > x0)\r
- draw(true, y0, x0, y1, minX);\r
- else\r
- draw(true, y0, x0, y1, maxX);\r
- }\r
- }\r
- else {\r
- if(x1 > x0)\r
- x0 += OFFSET;\r
- else\r
- x0 -= OFFSET;\r
- if(rect.getMinY() <= y0 && rect.getMaxY() >= y0) {\r
- if(x1 > x0)\r
- draw(false, x0, y0, minX);\r
- else\r
- draw(false, x0, y0, maxX);\r
- }\r
- else {\r
- if(y1 > y0)\r
- draw(false, x0, y0, x1, minY);\r
- else\r
- draw(false, x0, y0, x1, maxY);\r
- }\r
- }\r
-\r
-\r
- }\r
-\r
- protected void updateSceneGraph() {\r
- boolean hasArrow = tail instanceof ValveElement && !(head instanceof ValveElement);\r
- if(tail instanceof ValveElement)\r
- draw(hasArrow, tail, head);\r
- else if(head instanceof ValveElement)\r
- draw(hasArrow, head, tail);\r
- if(hasArrow)\r
- createArrow(head, tail);\r
- }\r
-\r
- // TODO\r
-\r
- public void update() {\r
- if(lineNode1 != null)\r
- updateSceneGraph();\r
- fireElementUpdated();\r
- }\r
-\r
- @Override\r
- public void getBounds(Rectangle2D bounds) {\r
- bounds.setFrame(lineNode1.getBoundsInLocal());\r
- bounds.add(lineNode2.getBoundsInLocal());\r
- }\r
-\r
- @Override\r
- public boolean hitTest(double x, double y, double tolerance) {\r
- // FIXME totally incorrect\r
- /*Rectangle2D rect = new Rectangle2D.Double();\r
- getBounds(rect);\r
- return rect.contains(x, y);*/\r
- return false;\r
- }\r
-\r
- @Override\r
- public <T> T getInterface(Class<T> clazz) { \r
- return super.getInterface(clazz);\r
- }\r
-\r
- @Override\r
- public void elementRemoved(IElement element) {\r
- remove(); \r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.geom.Path2D;\r
-\r
-public class Flows {\r
- public static Path2D createLine(boolean vertical, double ... coordinates) {\r
- Path2D path = new Path2D.Double();\r
- if(vertical)\r
- path.moveTo(coordinates[1], coordinates[0]);\r
- else\r
- path.moveTo(coordinates[0], coordinates[1]);\r
- for(int i=2;i<coordinates.length;++i, vertical = !vertical) {\r
- if(vertical)\r
- path.lineTo(coordinates[i-1], coordinates[i]);\r
- else\r
- path.lineTo(coordinates[i], coordinates[i-1]);\r
- }\r
- return path;\r
- }\r
- \r
- public static Path2D createOffsetLine(boolean vertical, double offset, double ... coordinates) {\r
- double[] newCoordinats = new double[coordinates.length];\r
- newCoordinats[0] = coordinates[0];\r
- newCoordinats[coordinates.length-1] = coordinates[coordinates.length-1];\r
- for(int i=1;i<coordinates.length-1;++i) {\r
- if(coordinates[i-1] < coordinates[i+1] ^ (i&1)==1)\r
- newCoordinats[i] = coordinates[i]+offset;\r
- else\r
- newCoordinats[i] = coordinates[i]-offset;\r
- }\r
- return createLine(vertical, newCoordinats);\r
- }\r
-}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.geom.Point2D;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.h2d.element.Element;\r
-import org.simantics.h2d.element.handler.Movable;\r
-import org.simantics.objmap.annotations.RelatedValue;\r
-\r
-/**\r
- * Base class of elements that have rectangular shape (for hit testing)\r
- * and which can be moved.\r
- * @author Hannu Niemistö\r
- */\r
-public abstract class RectangularElement extends Element implements Movable {\r
- \r
- protected Rectangle2D bounds = new Rectangle2D.Double();\r
- \r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasX")\r
- protected double posX;\r
- @RelatedValue("http://www.simantics.org/Sysdyn-1.0/HasY")\r
- protected double posY; \r
- \r
- public RectangularElement() { \r
- }\r
- \r
- @Override\r
- public void getBounds(Rectangle2D bounds) {\r
- bounds.setFrame(this.bounds);\r
- }\r
-\r
- @Override\r
- public boolean hitTest(double x, double y, double tolerance) {\r
- return bounds.intersects(x-tolerance, y-tolerance, 2.0*tolerance, 2.0*tolerance);\r
- } \r
- \r
- protected abstract void update();\r
- \r
- @Override\r
- public void move(double deltaX, double deltaY) {\r
- posX += deltaX;\r
- posY += deltaY;\r
- update();\r
- }\r
- \r
- public Point2D getOrigo() {\r
- return new Point2D.Double(posX, posY);\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import org.simantics.h2d.node.RectangleNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Stock")\r
-public class StockElement extends TextElement {\r
- \r
- RectangleNode rectangleNode;\r
- \r
- public StockElement() { \r
- }\r
- \r
- public StockElement(String label, double x, double y) {\r
- super(label, x, y);\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- rectangleNode = parent.addNode(RectangleNode.class);\r
- super.init(parent);\r
- }\r
- \r
- @Override\r
- public void remove() {\r
- rectangleNode.remove();\r
- super.remove();\r
- }\r
-\r
- @Override\r
- protected void update() {\r
- super.update();\r
- if(rectangleNode != null)\r
- rectangleNode.init(bounds);\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.Color;\r
-import java.awt.Font;\r
-import java.awt.font.FontRenderContext;\r
-import java.awt.geom.AffineTransform;\r
-import java.awt.geom.Rectangle2D;\r
-import java.util.List;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.h2d.action.IAction;\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.element.handler.Movable;\r
-import org.simantics.h2d.event.ClickEvent;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.KeyboardEvent;\r
-import org.simantics.h2d.event.handler.IEventHandler;\r
-import org.simantics.h2d.node.ITextListener;\r
-import org.simantics.h2d.node.TextNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.objmap.annotations.RelatedValue;\r
-import org.simantics.objmap.annotations.UpdateMethod;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.sysdyn.SysdynResource;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Auxiliary")\r
-public class TextElement extends RectangularElement implements Movable, Connectable, IEventHandler {\r
-\r
- static final Font FONT = new Font("sans-serif", Font.PLAIN, 12);\r
- static final double FONT_SCALE = 0.3;\r
- static final AffineTransform FONT_TRANSFORM = new AffineTransform(FONT_SCALE, 0.0, 0.0, FONT_SCALE, 0.0, 0.0);\r
-\r
- static final double XPADDING = 4.0;\r
- static final double YPADDING = 2.0;\r
- static final FontRenderContext FRC = new FontRenderContext(FONT_TRANSFORM, true, true);\r
-\r
- // Properties\r
- @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
- public String label = "Unnamed";\r
-\r
- @RelatedValue("http://www.simantics.org/Layer0-1.0/HasType")\r
- public String type = "Real";\r
-\r
- // Auxiliary fields\r
- double textX;\r
- double textY;\r
-\r
- TextNode textNode;\r
-\r
- public TextElement() { \r
- }\r
-\r
- public double getTextDeltaX() {\r
- return 0.0;\r
- }\r
-\r
- public double getTextDeltaY() {\r
- return 0.0;\r
- }\r
-\r
- public TextElement(String label, double x, double y) {\r
- this.label = label;\r
- this.posX = x;\r
- this.posY = y;\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- textNode.remove();\r
- super.remove();\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- textNode = parent.addNode(TextNode.class);\r
- update();\r
- }\r
-\r
- protected void updateText() {\r
- Rectangle2D textBounds = FONT.getStringBounds(label, FRC);\r
- textBounds.setFrame(\r
- textBounds.getX()*FONT_SCALE,\r
- textBounds.getY()*FONT_SCALE,\r
- textBounds.getWidth()*FONT_SCALE,\r
- textBounds.getHeight()*FONT_SCALE\r
- );\r
-\r
- textX = posX+getTextDeltaX()-textBounds.getCenterX();\r
- textY = posY+getTextDeltaY()-textBounds.getCenterY();\r
- bounds.setFrame(\r
- posX+getTextDeltaX()-textBounds.getWidth()*0.5-XPADDING,\r
- posY+getTextDeltaY()-textBounds.getHeight()*0.5-YPADDING,\r
- textBounds.getWidth()+XPADDING*2,\r
- textBounds.getHeight()+YPADDING*2\r
- ); \r
-\r
- if(textNode != null) {\r
- textNode.init(label, FONT, hasEquation ? Color.BLACK : Color.RED, \r
- textX, textY, FONT_SCALE);\r
- oldHasEquation = hasEquation;\r
- }\r
- }\r
-\r
- protected void update() {\r
- updateText(); \r
- fireElementUpdated();\r
- }\r
-\r
- class TextEditingAction implements IAction, ITextListener {\r
-\r
- String oldText;\r
- IDiagramEditor editor;\r
-\r
- public TextEditingAction(IDiagramEditor editor) {\r
- super();\r
- this.editor = editor;\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- oldText = textNode.getText();\r
- textNode.setEditMode(true); \r
- textNode.setTextListener(this);\r
- /*textFieldNode = parent.addNode(TextFieldNode.class);\r
- textFieldNode.init(10.0, 10.0);*/\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- textNode.setEditMode(false);\r
- textNode.setTextListener(null);\r
- //textFieldNode.remove(); \r
- }\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- if(_event instanceof KeyboardEvent) {\r
- KeyboardEvent event = (KeyboardEvent)_event;\r
- if(event.key.equals("Escape")) {\r
- label = oldText;\r
- update();\r
- editor.removeAction(this); \r
- editor.requestRepaint(); \r
- }\r
- else if(event.key.equals("Enter")) {\r
- validateNewName();\r
- update(); \r
- editor.removeAction(this);\r
- editor.requestRepaint();\r
- }\r
- return true;\r
- }\r
- else if(_event instanceof ClickEvent) {\r
- validateNewName();\r
- update();\r
- editor.removeAction(this);\r
- editor.requestRepaint();\r
- }\r
- return false;\r
- }\r
-\r
- @Override\r
- public void textChanged() {\r
- label = textNode.getText();\r
- //update();\r
- editor.requestRepaint();\r
- }\r
- \r
- private void validateNewName(){\r
- if(!label.equals(oldText)) {\r
- List<IElement> elements = editor.getDiagram().getElements();\r
- for(IElement e : elements) {\r
- if(e instanceof TextElement) {\r
- TextElement t = (TextElement) e;\r
- if(t != TextElement.this && t.label.equals(textNode.getText())) {\r
- label = oldText;\r
- //update();\r
- //editor.requestRepaint(); \r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- }\r
-\r
- public void beginRenameAction(IDiagramEditor editor) {\r
- editor.addAction(new TextEditingAction(editor));\r
- }\r
-\r
- @Override\r
- public boolean handle(IDiagramEditor editor, IEvent _event) {\r
- if(_event instanceof KeyboardEvent) {\r
- KeyboardEvent event = (KeyboardEvent)_event;\r
- if(event.key.equals("F3") || event.key.equals("F2")) {\r
- beginRenameAction(editor);\r
- return true;\r
- } \r
- }\r
- return false;\r
- } \r
-\r
- boolean oldHasEquation = false;\r
-\r
- boolean hasEquation = true;\r
- String oldLabel = label;\r
-\r
- @UpdateMethod\r
- boolean updateCheck(ReadGraph g, Resource resource) {\r
-// SysdynResource sr = SysdynResource.getInstance(g);\r
- boolean update = false;\r
-// try {\r
-// hasEquation = \r
-// !g.getObjects(resource, sr.HasExpression).isEmpty();\r
-// if(oldHasEquation != hasEquation) \r
-// update = true;\r
- if(!label.equals(oldLabel)) {\r
- oldLabel = label; \r
- update = true;\r
- }\r
- if(update) \r
- update();\r
-// } catch (DatabaseException e) {\r
-// e.printStackTrace();\r
-// } \r
- return false;\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.geom.Path2D;\r
-\r
-import org.simantics.h2d.element.handler.Rotatable;\r
-import org.simantics.h2d.node.ShapeNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Valve")\r
-public class ValveElement extends TextElement implements Rotatable {\r
- \r
- public static final double VALVE_SIZE = 5.0;\r
- \r
- ShapeNode valveNode;\r
- boolean rotated = false;\r
- \r
- public ValveElement() { \r
- }\r
- \r
- public ValveElement(double x, double y) {\r
- this.posX = x;\r
- this.posY = y; \r
- }\r
- \r
- @Override\r
- public double getTextDeltaY() {\r
- return 8.0;\r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- valveNode = parent.addNode(ShapeNode.class);\r
- valveNode.setColor(Color.BLACK);\r
- valveNode.setScaleStroke(true);\r
- valveNode.setStroke(new BasicStroke(1));\r
- super.init(parent);\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- valveNode.remove();\r
- super.remove();\r
- }\r
- \r
- @Override\r
- protected void update() { \r
- Path2D path = new Path2D.Double();\r
- path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE);\r
- if(rotated) {\r
- path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE);\r
- path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
- }\r
- else { \r
- path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
- path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); \r
- }\r
- path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE);\r
- path.closePath();\r
- valveNode.setShape(path);\r
- updateText();\r
- bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
- fireElementUpdated();\r
- }\r
-\r
- @Override\r
- public void rotate(int amount) {\r
- if((amount & 1) == 1) {\r
- rotated = !rotated;\r
- update();\r
- }\r
- }\r
-\r
- public boolean isRotated() {\r
- return rotated;\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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;\r
-\r
-import java.awt.BasicStroke;\r
-import java.awt.Color;\r
-import java.awt.geom.Path2D;\r
-\r
-import org.simantics.h2d.element.handler.Connectable;\r
-import org.simantics.h2d.element.handler.Rotatable;\r
-import org.simantics.h2d.node.ShapeNode;\r
-import org.simantics.objmap.annotations.GraphType;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-\r
-@GraphType("http://www.simantics.org/Sysdyn-1.0/Valve")\r
-public class ValveElementOld extends RectangularElement implements Connectable, Rotatable {\r
- \r
- public static final double VALVE_SIZE = 5.0;\r
- \r
- ShapeNode valveNode;\r
- boolean rotated = false;\r
- \r
- public ValveElementOld() { \r
- }\r
- \r
- public ValveElementOld(double x, double y) {\r
- this.posX = x;\r
- this.posY = y; \r
- }\r
-\r
- @Override\r
- public void init(G2DParentNode parent) {\r
- valveNode = parent.addNode(ShapeNode.class);\r
- valveNode.setColor(Color.BLACK);\r
- valveNode.setScaleStroke(true);\r
- valveNode.setStroke(new BasicStroke(1));\r
- update();\r
- }\r
-\r
- @Override\r
- public void remove() {\r
- valveNode.remove();\r
- }\r
- \r
- protected void update() {\r
- bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
- Path2D path = new Path2D.Double();\r
- path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE);\r
- if(rotated) {\r
- path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE);\r
- path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
- }\r
- else { \r
- path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE);\r
- path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); \r
- }\r
- path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE);\r
- path.closePath();\r
- valveNode.setShape(path);\r
- fireElementUpdated();\r
- }\r
-\r
- @Override\r
- public void rotate(int amount) {\r
- if((amount & 1) == 1) {\r
- rotated = !rotated;\r
- update();\r
- }\r
- }\r
-\r
- public boolean isRotated() {\r
- return rotated;\r
- }\r
-}\r
package org.simantics.sysdyn.ui.elements2;\r
\r
import java.awt.geom.AffineTransform;\r
-\r
import org.simantics.g2d.element.ElementUtils;\r
import org.simantics.g2d.element.IElement;\r
import org.simantics.g2d.element.SceneGraphNodeKey;\r
import org.simantics.g2d.element.handler.SceneGraph;\r
-import org.simantics.h2d.node.RectangleNode;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.utils.datastructures.Callback;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
public void cleanup(IElement e) {\r
ElementUtils.removePossibleNode(e, BORDER_NODE);\r
}\r
-\r
}\r
--- /dev/null
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Graphics2D;\r
+import java.awt.geom.Rectangle2D;\r
+import org.simantics.scenegraph.g2d.G2DNode;\r
+\r
+public class RectangleNode extends G2DNode {\r
+ \r
+ private static final long serialVersionUID = 654692698101485672L;\r
+\r
+ protected Rectangle2D bounds = null;\r
+\r
+ @SyncField("bounds")\r
+ public void init(Rectangle2D bounds) {\r
+ this.bounds = bounds;\r
+ }\r
+\r
+ @Override\r
+ public void render(Graphics2D g) {\r
+ if(bounds == null) return;\r
+ g.transform(transform);\r
+ g.setColor(Color.BLACK);\r
+ double scale = g.getTransform().getScaleX();\r
+ g.setStroke(new BasicStroke( (float)(1.0 / scale) ));\r
+\r
+ g.draw(bounds);\r
+ }\r
+\r
+ @Override\r
+ public Rectangle2D getBoundsInLocal() {\r
+ return bounds;\r
+ }\r
+ \r
+}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.sysdyn.ui.actions.CreateAuxiliary;\r
-\r
-public class CreateAuxiliaryHandler extends DiagramContextMenuActionHandler {\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- CreateAuxiliary ca = new CreateAuxiliary();\r
- ca.handle(editor, event);\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.sysdyn.ui.actions.CreateCloud;\r
-\r
-public class CreateCloudHandler extends DiagramContextMenuActionHandler {\r
-\r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- CreateCloud cc = new CreateCloud();\r
- cc.handle(editor, event);\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.sysdyn.ui.actions.CreateStock;\r
-\r
-public class CreateStockHandler extends DiagramContextMenuActionHandler {\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- CreateStock cs = new CreateStock();\r
- cs.handle(editor, event);\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.sysdyn.ui.actions.CreateValve;\r
-\r
-public class CreateValveHandler extends DiagramContextMenuActionHandler {\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- CreateValve cv = new CreateValve();\r
- cv.handle(editor, event);\r
- }\r
-\r
-}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.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.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.swt.widgets.MenuItem;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.sysdyn.ui.actions.DiagramContextMenuData;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
-\r
-public abstract class DiagramContextMenuActionHandler extends AbstractHandler {\r
- \r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- IWorkbenchPart ap = HandlerUtil.getActivePart(event);\r
- if(ap instanceof SysdynDiagramEditor) {\r
- Event ci = (Event)event.getTrigger();\r
- MenuItem mi = (MenuItem) ci.widget;\r
- Menu m = mi.getParent();\r
- while(m.getParentMenu() != null)\r
- m = m.getParentMenu();\r
- DiagramContextMenuData cmd = (DiagramContextMenuData) m.getData();\r
- IDiagramEditor de = cmd.diagramEditor;\r
- IEvent evnt = cmd.event;\r
- handleEvent(de, evnt);\r
- }\r
- return null;\r
- }\r
-\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- // Implement in another class\r
- }\r
-\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.simantics.project.IExperimentDescriptor;\r
import org.simantics.project.IProject;\r
-import org.simantics.project.ProjectKeys;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.ui.SimanticsUI;\r
IExperiment experiment = manager.getActiveExperiment();\r
if (experiment != null)\r
experiment.shutdown();\r
-\r
- /*\r
- // Keep the UI happy.\r
- IExperimentDescriptor ed = project.getHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
- if (ed != null) {\r
- ed.getParent().removeHint(ProjectKeys.KEY_SELECTED_EXPERIMENT);\r
- project.removeHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT);\r
- }\r
- */\r
return null;\r
}\r
\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.handler.Delete;\r
-\r
-public class RemoveHandler extends DiagramContextMenuActionHandler {\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- Delete d = new Delete();\r
- d.handle(editor, event);\r
- }\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import org.simantics.h2d.editor.IDiagramEditor;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.h2d.event.IEvent;\r
-import org.simantics.h2d.event.ILocatableEvent;\r
-import org.simantics.sysdyn.ui.elements.TextElement;\r
-\r
-public class RenameHandler extends DiagramContextMenuActionHandler {\r
- \r
- protected void handleEvent(IDiagramEditor editor, IEvent event) {\r
- ILocatableEvent e = (ILocatableEvent)event;\r
- if(e.getPickedElements().size() <= 0) return;\r
- IElement element = e.getPickedElements().get(0);\r
- if(element instanceof TextElement) {\r
- TextElement te = (TextElement)element;\r
- te.beginRenameAction(editor);\r
- }\r
- }\r
-\r
-}\r
import org.simantics.simulation.experiment.IDynamicExperiment;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class RunBasicExperiment extends AbstractHandler implements IElementUpdater {\r
return null;\r
}\r
\r
- @SuppressWarnings("unchecked")\r
@Override\r
public void updateElement(UIElement element, Map parameters) {\r
ICommandService commandService =\r
import org.simantics.db.Builtins;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
import org.simantics.db.common.request.ReadRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.modeling.ComponentUtils;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.structural2.StructuralVariables;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.ui.editor.DiagramViewer;\r
import org.simantics.ui.SimanticsUI;\r
if(diagram == null) return;\r
\r
final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, b.HasName, StringBindingDefault.INSTANCE);\r
- if(rvi == null) return;\r
\r
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
\r
* Contributors:\r
* VTT Technical Research Centre of Finland - initial API and implementation\r
*******************************************************************************/\r
-package org.simantics.sysdyn.ui.actions;\r
+package org.simantics.sysdyn.ui.handlers;\r
\r
\r
import java.util.Map;\r
import org.eclipse.ui.commands.ICommandService;\r
import org.eclipse.ui.commands.IElementUpdater;\r
import org.eclipse.ui.menus.UIElement;\r
-import org.simantics.simulation.experiment.IDynamicExperiment;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.manager.SysdynExperiment;\r
-import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class ToggleSimulation extends AbstractHandler implements IElementUpdater {\r
return (Boolean)state.getValue();\r
}\r
\r
- @SuppressWarnings("unchecked")\r
@Override\r
public void updateElement(UIElement element, Map parameters) {\r
ICommandService commandService =\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.handlers;\r
-\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\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.jface.dialogs.MessageDialog;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IEditorReference;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.CancelTransactionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class UnlinkNodeHandler extends AbstractHandler {\r
-\r
- @Override\r
- public Object execute(ExecutionEvent event) throws ExecutionException {\r
- Shell shell = HandlerUtil.getActiveShellChecked(event);\r
- ISelection sel = HandlerUtil.getCurrentSelection(event);\r
- Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
- if (resources.length == 0)\r
- return null;\r
-\r
- MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0,\r
- new String[] { "OK", "Cancel" }, 0);\r
- dialog.create();\r
- if (dialog.open() == 0)\r
- deleteItem(resources);\r
-\r
- return null;\r
- }\r
-\r
- private void deleteItem(final Resource[] resources) {\r
- final ArrayList<Resource> configurations = new ArrayList<Resource>();\r
- try {\r
- SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- SimulationResource SIMU = SimulationResource.getInstance(graph);\r
- for (Resource r : resources) {\r
- if (graph.isInstanceOf(r, sr.SysdynModel)) {\r
- unlinkModel(graph, r);\r
- configurations.add(graph.getSingleObject(r, SIMU.HasConfiguration));\r
- }\r
- else if (graph.isInstanceOf(r, SIMU.Experiment))\r
- unlinkExperiment(graph, r);\r
- else if (graph.isInstanceOf(r, sr.Result))\r
- unlinkResult(graph, r);\r
- }\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- ExceptionUtils.logAndShowError(e);\r
- }\r
-\r
- for (Resource r : configurations) {\r
- IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();\r
- for(IEditorReference er : editorReferences) {\r
- if(er.getEditor(false) instanceof SysdynDiagramEditor) {\r
- SysdynDiagramEditor editor = (SysdynDiagramEditor)er.getEditor(false);\r
- if(editor.getResourceInput().getResource().equals(r)) {\r
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false);\r
- }\r
- }\r
- }\r
- }\r
-\r
- }\r
-\r
- private void unlinkModel(WriteGraph graph, Resource model) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
-\r
- for(Resource r : graph.getObjects(model, b.ConsistsOf))\r
- if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result))\r
- deleteResultFiles(graph, r);\r
-\r
- graph.deny(model, b.PartOf);\r
- }\r
-\r
- private void unlinkExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- Collection<Resource> results = graph.getObjects(experiment, SysdynResource.getInstance(graph).HasResult);\r
- if(results != null)\r
- for(Resource result : results)\r
- unlinkResult(graph, result);\r
- graph.deny(experiment, b.PartOf);\r
-\r
- }\r
-\r
- private void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException {\r
- Builtins b = graph.getBuiltins();\r
- deleteResultFiles(graph, result);\r
- graph.deny(result, b.PartOf);\r
- graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult));\r
-\r
- }\r
-\r
- private void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException {\r
- String path;\r
- path = graph.getPossibleRelatedValue(result, SysdynResource.getInstance(graph).HasResultFile);\r
- if(path != null) {\r
- File file = new File(path);\r
- file.delete();\r
- File parent = file.getParentFile();\r
- if(parent.listFiles().length == 0)\r
- parent.delete();\r
- }\r
- }\r
-\r
-}
\ No newline at end of file
import org.eclipse.ui.contexts.IContextActivation;\r
import org.simantics.simulation.experiment.ExperimentState;\r
import org.simantics.simulation.experiment.IExperimentListener;\r
-import org.simantics.sysdyn.ui.actions.ToggleSimulation;\r
import org.simantics.sysdyn.ui.handlers.RunBasicExperiment;\r
+import org.simantics.sysdyn.ui.handlers.ToggleSimulation;\r
\r
public class SysdynExperimentListener implements IExperimentListener {\r
\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in 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.sg;\r
-\r
-import java.awt.AWTEvent;\r
-import java.awt.event.AWTEventListener;\r
-import java.awt.geom.Rectangle2D;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.ReadRequest;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.h2d.diagram.IDiagram;\r
-import org.simantics.h2d.diagram.IDiagramListener;\r
-import org.simantics.h2d.element.IElement;\r
-import org.simantics.objmap.IMapping;\r
-import org.simantics.objmap.IMappingListener;\r
-import org.simantics.objmap.MappingException;\r
-import org.simantics.objmap.Mappings;\r
-import org.simantics.scenegraph.adapters.ISceneGraphProvider;\r
-import org.simantics.scenegraph.g2d.G2DParentNode;\r
-import org.simantics.scenegraph.g2d.G2DSceneGraph;\r
-import org.simantics.scenegraph.g2d.nodes.NavigationNode;\r
-import org.simantics.scenegraph.g2d.nodes.PageBorderNode;\r
-import org.simantics.scenegraph.g2d.nodes.TransformNode;\r
-import org.simantics.sysdyn.ui.editor.SysdynDiagramSchema;\r
-\r
-public class SysdynSceneGraphProvider implements ISceneGraphProvider, AWTEventListener {\r
-\r
- protected Resource resource;\r
-\r
- IDiagram diagram;\r
- IMapping mapping;\r
-\r
- public SysdynSceneGraphProvider(ReadGraph g, final Resource resource) {\r
- this.resource = resource;\r
- \r
- SysdynDiagramSchema schema;\r
- try {\r
- schema = new SysdynDiagramSchema(g);\r
- } catch (DatabaseException e1) {\r
- // TODO Auto-generated catch block\r
- e1.printStackTrace();\r
- return;\r
- }\r
- \r
- mapping = Mappings.createWithListening(schema);\r
- \r
- try {\r
- diagram = (IDiagram)mapping.map(g, resource);\r
- } catch (MappingException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
- \r
- final Session session = g.getSession();\r
- mapping.addMappingListener(new IMappingListener() {\r
- \r
- @Override\r
- public void rangeModified() { \r
- session.asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph)\r
- throws DatabaseException {\r
- try {\r
- mapping.updateDomain(graph);\r
- } catch(Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- \r
- });\r
- }\r
- \r
- @Override\r
- public void domainModified() {\r
- session.asyncRequest(new ReadRequest() {\r
- \r
- @Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
- try {\r
- mapping.updateRange(graph);\r
- } catch(Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
- });\r
- }\r
- });\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- \r
- }\r
- \r
- @Override\r
- public AWTEventListener getEventListener() {\r
- return this;\r
- }\r
-\r
- @Override\r
- public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg) {\r
- return initializeSceneGraph(sg, null);\r
- }\r
-\r
- G2DSceneGraph sceneGraph;\r
- TransformNode diagramCoordinatesNode;\r
- G2DParentNode elementsNode;\r
- G2DParentNode selectionNode;\r
- G2DParentNode actionNode;\r
-\r
- @Override\r
- public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String view) {\r
- sceneGraph = sg;\r
- diagramCoordinatesNode = sceneGraph.addNode(NavigationNode.class);\r
-\r
- PageBorderNode border = diagramCoordinatesNode.addNode(PageBorderNode.class);\r
- border.init(new Rectangle2D.Double(0.0, 0.0, 297.0, 210.0), new Rectangle2D.Double(10.0, 10.0, 277.0, 190.0), Boolean.TRUE);\r
-\r
- elementsNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
- elementsNode.setZIndex(0);\r
-\r
- selectionNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
- selectionNode.setZIndex(1);\r
-\r
- actionNode = diagramCoordinatesNode.addNode(G2DParentNode.class);\r
- actionNode.setZIndex(2);\r
- \r
- for(IElement element : diagram.getElements())\r
- element.init(elementsNode);\r
- diagram.addDiagramListener(new IDiagramListener() {\r
- \r
- @Override\r
- public void elementAdded(IElement element) {\r
- element.init(elementsNode);\r
- }\r
-\r
- @Override\r
- public void elementRemoved(IElement element) {\r
- element.remove();\r
- }\r
- });\r
- \r
- return sg;\r
- }\r
-\r
- @Override\r
- public void setHint(Object key, Object value) {\r
- // TODO Auto-generated method stub\r
-\r
- }\r
-\r
- @Override\r
- public void eventDispatched(AWTEvent event) {\r
- \r
- }\r
-\r
-}\r