From e73a3835e8ddb7d10ecbc13ac9174efaf837b425 Mon Sep 17 00:00:00 2001 From: lempinen Date: Thu, 19 Aug 2010 07:15:22 +0000 Subject: [PATCH] Got rid of h2d git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17359 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.feature/feature.xml | 7 - org.simantics.sysdyn.ui/META-INF/MANIFEST.MF | 3 +- org.simantics.sysdyn.ui/adapters.xml | 11 +- org.simantics.sysdyn.ui/plugin.xml | 67 +--- .../sysdyn/ui/TestDiagramEditor.java | 55 --- .../simantics/sysdyn/ui/actions/Connect.java | 135 ------- .../sysdyn/ui/actions/ConnectBase.java | 117 ------ .../sysdyn/ui/actions/ConnectDependency.java | 44 --- .../sysdyn/ui/actions/ConnectFlow.java | 61 ---- .../sysdyn/ui/actions/CreateAuxiliary.java | 34 -- .../sysdyn/ui/actions/CreateCloud.java | 33 -- .../sysdyn/ui/actions/CreateStock.java | 34 -- .../sysdyn/ui/actions/CreateValve.java | 32 -- .../ui/actions/DiagramContextMenuData.java | 25 -- .../sysdyn/ui/actions/OpenContextMenu.java | 91 ----- .../sysdyn/ui/editor/SysdynDiagramEditor.java | 332 ------------------ .../sysdyn/ui/editor/SysdynDiagramSchema.java | 65 ---- .../simantics/sysdyn/ui/elements/Arcs.java | 165 --------- .../sysdyn/ui/elements/AuxiliaryElement.java | 26 -- .../sysdyn/ui/elements/CloudElement.java | 81 ----- .../sysdyn/ui/elements/DependencyElement.java | 217 ------------ .../sysdyn/ui/elements/FlowElement.java | 249 ------------- .../simantics/sysdyn/ui/elements/Flows.java | 44 --- .../ui/elements/RectangularElement.java | 61 ---- .../sysdyn/ui/elements/StockElement.java | 49 --- .../sysdyn/ui/elements/TextElement.java | 244 ------------- .../sysdyn/ui/elements/ValveElement.java | 90 ----- .../sysdyn/ui/elements/ValveElementOld.java | 83 ----- .../sysdyn/ui/elements2/BorderSceneGraph.java | 3 - .../sysdyn/ui/elements2/RectangleNode.java | 36 ++ .../ui/handlers/CreateAuxiliaryHandler.java | 25 -- .../ui/handlers/CreateCloudHandler.java | 24 -- .../ui/handlers/CreateStockHandler.java | 24 -- .../ui/handlers/CreateValveHandler.java | 25 -- .../DiagramContextMenuActionHandler.java | 51 --- .../sysdyn/ui/handlers/DisposeExperiment.java | 11 - .../sysdyn/ui/handlers/RemoveHandler.java | 25 -- .../sysdyn/ui/handlers/RenameHandler.java | 32 -- .../ui/handlers/RunBasicExperiment.java | 2 - .../sysdyn/ui/handlers/ShowModuleHandler.java | 3 - .../ToggleSimulation.java | 5 +- .../sysdyn/ui/handlers/UnlinkNodeHandler.java | 140 -------- .../listeners/SysdynExperimentListener.java | 2 +- .../ui/sg/SysdynSceneGraphProvider.java | 172 --------- 44 files changed, 41 insertions(+), 2994 deletions(-) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/TestDiagramEditor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/Connect.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectBase.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectDependency.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectFlow.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateAuxiliary.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateCloud.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateStock.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateValve.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/DiagramContextMenuData.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramSchema.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Arcs.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Flows.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java create mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateAuxiliaryHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateCloudHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateStockHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateValveHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramContextMenuActionHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameHandler.java rename org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/{actions => handlers}/ToggleSimulation.java (92%) delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler.java delete mode 100644 org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java diff --git a/org.simantics.sysdyn.feature/feature.xml b/org.simantics.sysdyn.feature/feature.xml index d3bbe93b..e39c000f 100644 --- a/org.simantics.sysdyn.feature/feature.xml +++ b/org.simantics.sysdyn.feature/feature.xml @@ -74,13 +74,6 @@ version="0.0.0" unpack="false"/> - - - - - - - - - none 0 fill 1 + none 0 fill 1 \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index 6910abb3..84efadd9 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -20,12 +20,6 @@ id="org.simantics.sysdyn.ui.diagramViewer" name="System dynamic diagram viewer"> - - - - - - - - - - - - - - - - @@ -344,7 +305,7 @@ name="Rename Node"> - - - - - - - - - - @@ -429,18 +376,6 @@ - - - - - - - - diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/TestDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/TestDiagramEditor.java deleted file mode 100644 index b85a32c3..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/TestDiagramEditor.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui; - -import javax.swing.JFrame; - -import org.simantics.h2d.canvas.EditorCanvas; -import org.simantics.h2d.diagram.Diagram; -import org.simantics.h2d.editor.impl.DiagramEditor; -import org.simantics.h2d.event.handler.DefaultEventHandlers; -import org.simantics.sysdyn.ui.actions.Connect; -import org.simantics.sysdyn.ui.actions.CreateAuxiliary; -import org.simantics.sysdyn.ui.actions.CreateCloud; -import org.simantics.sysdyn.ui.actions.CreateStock; -import org.simantics.sysdyn.ui.actions.CreateValve; - -public class TestDiagramEditor extends JFrame { - - public TestDiagramEditor() { - super("Test Canvas"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - Diagram diagram = new Diagram(); - final DiagramEditor editor = new DiagramEditor(getRootPane(), diagram); - - DefaultEventHandlers.configure(editor); - editor.addEventHandler(1, "key(A)", new CreateAuxiliary()); - editor.addEventHandler(1, "key(S)", new CreateStock()); - editor.addEventHandler(1, "key(V)", new CreateValve()); - editor.addEventHandler(1, "key(C)", new CreateCloud()); - editor.addEventHandler(1, "drag(alt+left)", new Connect()); - - getContentPane().add(new EditorCanvas(editor)); - - setSize(800, 600); - } - - public static void main(String[] args) { - javax.swing.SwingUtilities.invokeLater(new Runnable() { - public void run() { - new TestDiagramEditor().setVisible(true); - } - }); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/Connect.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/Connect.java deleted file mode 100644 index fb379331..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/Connect.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.element.IElement; -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.h2d.event.DragEvent; -import org.simantics.h2d.event.handler.DragEventHandler; -import org.simantics.h2d.node.RectangleNode; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.sysdyn.ui.elements.AuxiliaryElement; -import org.simantics.sysdyn.ui.elements.CloudElement; -import org.simantics.sysdyn.ui.elements.DependencyElement; -import org.simantics.sysdyn.ui.elements.FlowElement; -import org.simantics.sysdyn.ui.elements.StockElement; -import org.simantics.sysdyn.ui.elements.ValveElement; - -public class Connect extends DragEventHandler { - - Connectable from; - Connectable to; - - RectangleNode fromNode = new RectangleNode(); - RectangleNode toNode = new RectangleNode(); - - @Override - protected boolean begin(IDiagramEditor editor, DragEvent event) { - for(IElement element : event.pickedElements) { - Connectable connectable = element.getInterface(Connectable.class); - if(connectable != null) { - this.from = connectable; - return true; - } - } - return false; - } - - @Override - protected void update(IDiagramEditor editor, DragEvent event) { - for(IElement element : editor.pickElements(event.current)) { - Connectable connectable = element.getInterface(Connectable.class); - if(connectable != null && connectable != from) { - if(connectable == to) - return; - to = connectable; - - Rectangle2D bounds = new Rectangle2D.Double(); - to.getBounds(bounds); - bounds.setFrame( - bounds.getX()-2.0, - bounds.getY()-2.0, - bounds.getWidth()+4.0, - bounds.getHeight()+4.0); - toNode.init(bounds); - - editor.requestRepaint(); - return; - } - } - to = null; - toNode.init(fromNode.getBounds()); - editor.requestRepaint(); - } - - @Override - protected void end(IDiagramEditor editor, DragEvent event) { - if(to != null) { - IElement newElement; - if(from instanceof ValveElement && to instanceof StockElement) - newElement = new FlowElement(from, to); - else if(from instanceof StockElement && to instanceof ValveElement) - newElement = new FlowElement(from, to); - else if( (from instanceof StockElement || from instanceof CloudElement) - && (to instanceof StockElement || to instanceof CloudElement)) { - Point2D fromOrigo = from.getOrigo(); - Point2D toOrigo = to.getOrigo(); - newElement = new ValveElement( - 0.5 * (fromOrigo.getX() + toOrigo.getX()), - 0.5 * (fromOrigo.getY() + toOrigo.getY()) - ); - editor.getDiagram().addElement(new FlowElement(from, (ValveElement)newElement)); - editor.getDiagram().addElement(new FlowElement((ValveElement)newElement, to)); - } - else if(from instanceof ValveElement && to instanceof AuxiliaryElement) - newElement = new DependencyElement(to, from); - else if(from instanceof AuxiliaryElement && to instanceof StockElement) - newElement = new DependencyElement(to, from); - else - newElement = new DependencyElement(from, to); - editor.getDiagram().addElement(newElement); - if(newElement instanceof ValveElement) - ((ValveElement)newElement).beginRenameAction(editor); - } - - from = null; - to = null; - } - - @Override - public void init(G2DParentNode parent) { - fromNode = parent.addNode(RectangleNode.class); - toNode = parent.addNode(RectangleNode.class); - - Rectangle2D bounds = new Rectangle2D.Double(); - from.getBounds(bounds); - bounds.setFrame( - bounds.getX()-2.0, - bounds.getY()-2.0, - bounds.getWidth()+4.0, - bounds.getHeight()+4.0); - - fromNode.init(bounds); - toNode.init(bounds); - } - - @Override - public void remove() { - fromNode.remove(); - toNode.remove(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectBase.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectBase.java deleted file mode 100644 index d1cde772..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectBase.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import java.awt.geom.Rectangle2D; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.element.IElement; -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.h2d.event.DragEvent; -import org.simantics.h2d.event.handler.DragEventHandler; -import org.simantics.h2d.node.RectangleNode; -import org.simantics.scenegraph.g2d.G2DParentNode; - -public abstract class ConnectBase extends DragEventHandler { - - protected Connectable from; - protected Connectable to; - - RectangleNode fromNode = new RectangleNode(); - RectangleNode toNode = new RectangleNode(); - - /** - * This is called when starting to make a connection. - */ - protected abstract boolean isAllowedTail(Connectable tail); - - /** - * This is called when the mouse hovers over another connection point. - */ - protected abstract boolean isAllowedHead(Connectable head); - - protected abstract void connect(IDiagramEditor editor); - - @Override - protected boolean begin(IDiagramEditor editor, DragEvent event) { - for(IElement element : event.pickedElements) { - Connectable connectable = element.getInterface(Connectable.class); - if(connectable != null && isAllowedTail(connectable)) { - this.from = connectable; - return true; - } - } - return false; - } - - @Override - protected void update(IDiagramEditor editor, DragEvent event) { - for(IElement element : editor.pickElements(event.current)) { - Connectable connectable = element.getInterface(Connectable.class); - if(connectable != null && connectable != from) { - if(connectable == to) - return; - if(!isAllowedHead(connectable)) - continue; - to = connectable; - - Rectangle2D bounds = new Rectangle2D.Double(); - to.getBounds(bounds); - bounds.setFrame( - bounds.getX()-2.0, - bounds.getY()-2.0, - bounds.getWidth()+4.0, - bounds.getHeight()+4.0); - toNode.init(bounds); - - editor.requestRepaint(); - return; - } - } - to = null; - toNode.init(fromNode.getBounds()); - editor.requestRepaint(); - } - - @Override - protected void end(IDiagramEditor editor, DragEvent event) { - if(to != null) - connect(editor); - - from = null; - to = null; - } - - @Override - public void init(G2DParentNode parent) { - fromNode = parent.addNode(RectangleNode.class); - toNode = parent.addNode(RectangleNode.class); - - Rectangle2D bounds = new Rectangle2D.Double(); - from.getBounds(bounds); - bounds.setFrame( - bounds.getX()-2.0, - bounds.getY()-2.0, - bounds.getWidth()+4.0, - bounds.getHeight()+4.0); - - fromNode.init(bounds); - toNode.init(bounds); - } - - @Override - public void remove() { - fromNode.remove(); - toNode.remove(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectDependency.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectDependency.java deleted file mode 100644 index 1392fc48..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectDependency.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.sysdyn.ui.elements.AuxiliaryElement; -import org.simantics.sysdyn.ui.elements.DependencyElement; -import org.simantics.sysdyn.ui.elements.StockElement; -import org.simantics.sysdyn.ui.elements.ValveElement; - -public class ConnectDependency extends ConnectBase { - - @Override - protected boolean isAllowedTail(Connectable tail) { - return tail instanceof AuxiliaryElement - || tail instanceof StockElement - || tail instanceof ValveElement - ; - } - - @Override - protected boolean isAllowedHead(Connectable head) { - return head instanceof AuxiliaryElement - || head instanceof ValveElement - ; - } - - @Override - protected void connect(IDiagramEditor editor) { - editor.getDiagram().addElement(new DependencyElement(from, to)); - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectFlow.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectFlow.java deleted file mode 100644 index 4885f7ad..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ConnectFlow.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import java.awt.geom.Point2D; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.sysdyn.ui.elements.CloudElement; -import org.simantics.sysdyn.ui.elements.FlowElement; -import org.simantics.sysdyn.ui.elements.StockElement; -import org.simantics.sysdyn.ui.elements.ValveElement; - -public class ConnectFlow extends ConnectBase { - - @Override - protected boolean isAllowedTail(Connectable tail) { - return tail instanceof CloudElement - || tail instanceof StockElement - || tail instanceof ValveElement - ; - } - - @Override - protected boolean isAllowedHead(Connectable head) { - return head instanceof CloudElement - || head instanceof StockElement - || (head instanceof ValveElement && !(from instanceof ValveElement)) - ; - } - - @Override - protected void connect(IDiagramEditor editor) { - if(from instanceof ValveElement || to instanceof ValveElement) - editor.getDiagram().addElement(new FlowElement(from, to)); - else { - Point2D fromOrigo = from.getOrigo(); - Point2D toOrigo = to.getOrigo(); - ValveElement valveElement = new ValveElement( - 0.5 * (fromOrigo.getX() + toOrigo.getX()), - 0.5 * (fromOrigo.getY() + toOrigo.getY()) - ); - editor.getDiagram().addElement(valveElement); - editor.getDiagram().addElement(new FlowElement(from, valveElement)); - editor.getDiagram().addElement(new FlowElement(valveElement, to)); - - valveElement.beginRenameAction(editor); - } - } - - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateAuxiliary.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateAuxiliary.java deleted file mode 100644 index 4bde7cc6..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateAuxiliary.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ILocatableEvent; -import org.simantics.h2d.event.handler.IEventHandler; -import org.simantics.sysdyn.ui.elements.AuxiliaryElement; - -public class CreateAuxiliary implements IEventHandler { - - @Override - public boolean handle(IDiagramEditor editor, IEvent _event) { - ILocatableEvent event = (ILocatableEvent)_event; - AuxiliaryElement element = new AuxiliaryElement("Auxiliary", - event.getLocation().getX(), - event.getLocation().getY()); - editor.getDiagram().addElement(element); - element.beginRenameAction(editor); - editor.requestRepaint(); - return true; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateCloud.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateCloud.java deleted file mode 100644 index ec03cca2..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateCloud.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ILocatableEvent; -import org.simantics.h2d.event.handler.IEventHandler; -import org.simantics.sysdyn.ui.elements.CloudElement; - -public class CreateCloud implements IEventHandler { - - @Override - public boolean handle(IDiagramEditor editor, IEvent _event) { - ILocatableEvent event = (ILocatableEvent)_event; - CloudElement element = new CloudElement( - event.getLocation().getX(), - event.getLocation().getY()); - editor.getDiagram().addElement(element); - editor.requestRepaint(); - return true; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateStock.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateStock.java deleted file mode 100644 index 104852e5..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateStock.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ILocatableEvent; -import org.simantics.h2d.event.handler.IEventHandler; -import org.simantics.sysdyn.ui.elements.StockElement; - -public class CreateStock implements IEventHandler { - - @Override - public boolean handle(IDiagramEditor editor, IEvent _event) { - ILocatableEvent event = (ILocatableEvent)_event; - StockElement element = new StockElement("Stock", - event.getLocation().getX(), - event.getLocation().getY()); - editor.getDiagram().addElement(element); - element.beginRenameAction(editor); - editor.requestRepaint(); - return true; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateValve.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateValve.java deleted file mode 100644 index 20a8c85d..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/CreateValve.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ILocatableEvent; -import org.simantics.h2d.event.handler.IEventHandler; -import org.simantics.sysdyn.ui.elements.ValveElement; - -public class CreateValve implements IEventHandler { - - @Override - public boolean handle(IDiagramEditor editor, IEvent _event) { - ILocatableEvent event = (ILocatableEvent)_event; - editor.getDiagram().addElement(new ValveElement( - event.getLocation().getX(), - event.getLocation().getY())); - editor.requestRepaint(); - return true; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/DiagramContextMenuData.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/DiagramContextMenuData.java deleted file mode 100644 index c5c45d9b..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/DiagramContextMenuData.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; - -public class DiagramContextMenuData { - public final IDiagramEditor diagramEditor; - public final IEvent event; - - public DiagramContextMenuData(IDiagramEditor diagramEditor, IEvent event) { - this.diagramEditor = diagramEditor; - this.event = event; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java deleted file mode 100644 index 53f89ffa..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/OpenContextMenu.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; - -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPartSite; -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ReleaseEvent; -import org.simantics.h2d.event.handler.IEventHandler; - -public class OpenContextMenu implements IEventHandler { - - Control control; - IWorkbenchPartSite site; - String menuId; - - MenuManager menuManager; - - public OpenContextMenu(Control control, IWorkbenchPartSite site, - String menuId) { - super(); - this.control = control; - this.site = site; - this.menuId = menuId; - menuManager = createPopupMenu(); - if (menuManager != null) { - Menu menu = menuManager.createContextMenu(control); - control.setMenu(menu); - if (site != null) { - site.registerContextMenu(menuManager.getId(), menuManager, - site.getSelectionProvider()); - } - } - } - - @Override - public boolean handle(final IDiagramEditor editor, IEvent _event) { - final ReleaseEvent event = (ReleaseEvent)_event; - control.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if (control.isDisposed()) - return; - //Point p = control.toDisplay(event.getLocation().get(int) cp.getX(), (int) cp.getY()); - menuManager.getMenu().setLocation( - new Point((int)event.dispPoint.getX(), (int)event.dispPoint.getY())); - menuManager.getMenu().setData( - new DiagramContextMenuData(editor, event) - ); - menuManager.getMenu().setVisible(true); - } - - }); - return true; - } - - protected MenuManager createPopupMenu() { - final MenuManager mm = new MenuManager("Diagram Popup", menuId); - mm.setRemoveAllWhenShown(true); - mm.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - mm.add(new GroupMarker(IWorkbenchActionConstants.WB_START)); - mm.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT)); - mm.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT)); - mm.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - mm.add(new GroupMarker(IWorkbenchActionConstants.WB_END)); - } - }); - return mm; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java deleted file mode 100644 index 444f9eab..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.editor; - -import java.awt.Frame; -import java.util.ArrayList; -import java.util.Collections; - -import javax.swing.SwingUtilities; - -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.swt.SWT; -import org.eclipse.swt.awt.SWT_AWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.PartInitException; -import org.simantics.browsing.ui.swt.IPropertyPage; -import org.simantics.db.Builtins; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.management.ISessionContext; -import org.simantics.db.management.ISessionContextProvider; -import org.simantics.diagram.DiagramTypeUtils; -import org.simantics.diagram.symbolcontribution.ISymbolProvider; -import org.simantics.h2d.canvas.EditorCanvas; -import org.simantics.h2d.diagram.IDiagram; -import org.simantics.h2d.diagram.IDiagramListener; -import org.simantics.h2d.editor.ISelection; -import org.simantics.h2d.editor.ISelectionListener; -import org.simantics.h2d.editor.impl.DiagramEditor; -import org.simantics.h2d.element.IElement; -import org.simantics.h2d.element.IElementListener; -import org.simantics.h2d.event.handler.DefaultEventHandlers; -import org.simantics.layer0.utils.triggers.IActivation; -import org.simantics.modeling.ModelingResources; -import org.simantics.objmap.IMapping; -import org.simantics.objmap.IMappingListener; -import org.simantics.objmap.MappingException; -import org.simantics.objmap.Mappings; -import org.simantics.scenegraph.INode; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.sysdyn.ui.actions.ConnectDependency; -import org.simantics.sysdyn.ui.actions.ConnectFlow; -import org.simantics.sysdyn.ui.actions.CreateAuxiliary; -import org.simantics.sysdyn.ui.actions.CreateCloud; -import org.simantics.sysdyn.ui.actions.CreateStock; -import org.simantics.sysdyn.ui.actions.CreateValve; -import org.simantics.sysdyn.ui.actions.OpenContextMenu; -import org.simantics.sysdyn.ui.properties.SysdynPropertyPage; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.workbench.ResourceEditorPart; -import org.simantics.ui.workbench.TitleRequest; -import org.simantics.ui.workbench.TitleUpdater; -import org.simantics.utils.datastructures.Callable; -import org.simantics.utils.datastructures.Callback; -import org.simantics.utils.ui.ErrorLogger; -import org.simantics.utils.ui.jface.ActiveSelectionProvider; - -public class SysdynDiagramEditor extends ResourceEditorPart { - - EditorCanvas canvas; - IDiagram diagram; - IMapping mapping; - Frame frame; - boolean disposed = false; - Composite frameComposite; - Resource diagramResource; - protected ISessionContextProvider sessionContextProvider; - protected ISessionContext sessionContext; - protected IActivation activation; - - IElementListener elementUpdateListener = new IElementListener() { - - @Override - public void elementUpdated(IElement element) { - mapping.rangeModified(element); - } - - @Override - public void elementRemoved(IElement element) { - } - }; - - protected void readDiagram(ReadGraph g) throws DatabaseException { - SysdynDiagramSchema schema = new SysdynDiagramSchema(g); - mapping = Mappings.createWithListening(schema); - - try { - diagram = (IDiagram)mapping.map(g, getInputResource()); - for(IElement element : diagram.getElements()) - element.addListener(elementUpdateListener); - } catch (MappingException e) { - e.printStackTrace(); - } - - final Session session = g.getSession(); - mapping.addMappingListener(new IMappingListener() { - - @Override - public void rangeModified() { - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - try { - session.syncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) - throws DatabaseException { - mapping.updateDomain(graph); - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - }); - } - - @Override - public void domainModified() { - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - try { - session.syncRequest(new ReadRequest() { - @Override - public void run(ReadGraph graph) throws DatabaseException { - mapping.updateRange(graph); - } - }); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - }); - } - - }); - - diagram.addDiagramListener(new IDiagramListener() { - - @Override - public void elementAdded(IElement element) { - mapping.rangeModified(diagram); - element.addListener(elementUpdateListener); - } - - @Override - public void elementRemoved(IElement element) { - mapping.rangeModified(element); - mapping.rangeModified(diagram); - } - - }); - } - - @Override - public void init(IEditorSite site, IEditorInput input) - throws PartInitException { - super.init(site, input); - - try { - SimanticsUI.getSession().syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph g) throws DatabaseException { - diagramResource = g.getSingleObject(getInputResource(), ModelingResources.getInstance(g).CompositeToDiagram); - readDiagram(g); - } - - }); - - SimanticsUI.getSession().asyncRequest( - new TitleRequest(site.getId(), getResourceInput()) { - @Override - public String perform(ReadGraph graph) throws DatabaseException { - Builtins b = graph.getBuiltins(); - Resource r = graph.getSingleObject( - getResourceInput().getResource(), - SimulationResource.getInstance(graph).IsConfigurationOf); - String label = graph.getPossibleRelatedValue(r, b.HasLabel); - return label; - } - }, - new TitleUpdater(site.getShell().getDisplay(), new Callback() { - @Override - public void run(String partName) { - setPartName(partName); - } - }, new Callable() { - @Override - public Boolean call() { - return disposed; - } - })); - } catch (DatabaseException e) { - e.printStackTrace(); - } - } - - @Override - public void createPartControl(final Composite parent) { - frameComposite = new Composite(parent, - SWT.NO_BACKGROUND | SWT.EMBEDDED); - frame = SWT_AWT.new_Frame(frameComposite); - - - /// KOKEILLAAN - - /* - sessionContextProvider = SimanticsUI.getSessionContextProvider(); - sessionContext = sessionContextProvider.getSessionContext(); - - IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class); - if (activationManager != null) { - activation = activationManager.activate(diagramResource); - } - */ - /// LOPPUU - - final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider(); - getSite().setSelectionProvider(selectionProvider); - - final OpenContextMenu openContextMenu = new OpenContextMenu( - parent, getSite(), "#SysdynDiagramPopup"); - - SwingUtilities.invokeLater(new Runnable() { - - @Override - public void run() { - DiagramEditor editor = new DiagramEditor(null, diagram); - - DefaultEventHandlers.configure(editor); - editor.addEventHandler(1, "key(A)", new CreateAuxiliary()); - editor.addEventHandler(1, "key(S)", new CreateStock()); - editor.addEventHandler(1, "key(V)", new CreateValve()); - editor.addEventHandler(1, "key(C)", new CreateCloud()); - editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency()); - editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow()); - editor.addEventHandler(1, "release(right)", openContextMenu); - - canvas = new EditorCanvas(editor); - frame.add(canvas); - - frameComposite.getDisplay().asyncExec(new Runnable() { - @Override - public void run() { - setFocus(); - } - }); - - - editor.getSelection().addSelectionListener(new ISelectionListener() { - - @Override - public void selectionChanged(ISelection selection) { - final ArrayList resources = new ArrayList(selection.size()); - for(IElement element : selection) - resources.add(mapping.inverseGet(element)); - frameComposite.getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - if(!frameComposite.isDisposed()) - selectionProvider.setSelection(new StructuredSelection(resources)); - } - - }); - } - - }); - } - - }); - } - - @Override - public void setFocus() { - if(frameComposite != null && !frameComposite.isDisposed()) { - frameComposite.setFocus(); - if(canvas!=null) - canvas.requestFocus(); - } - } - - @Override - public void dispose() { - mapping.dispose(); - frame.dispose(); - disposed = true; - } - - @SuppressWarnings("unchecked") - @Override - public Object getAdapter(Class adapter) { - if (adapter == INode.class) { - return canvas.getEditor().getSceneGraph(); - } - if (adapter == ISymbolProvider.class) { - try { - - return DiagramTypeUtils.readSymbolContributions(SimanticsUI.getSession(), diagramResource); - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(getClass() + " failed to adapt to ISymbolProvider, see exception for details.", e); - return null; - } - } - if (adapter == IPropertyPage.class) { - return new SysdynPropertyPage(getSite(), Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser")); - } - return super.getAdapter(adapter); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramSchema.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramSchema.java deleted file mode 100644 index d0d2b3ec..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramSchema.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.editor; - -import java.util.Collection; - -import org.simantics.db.Builtins; -import org.simantics.db.ReadGraph; -import org.simantics.db.exception.DatabaseException; -import org.simantics.h2d.diagram.Diagram; -import org.simantics.objmap.rules.MappedElementsRule; -import org.simantics.objmap.rules.domain.RelatedObjectsAccessor; -import org.simantics.objmap.rules.range.FieldAccessor; -import org.simantics.objmap.schema.MappingSchemas; -import org.simantics.objmap.schema.SimpleLinkType; -import org.simantics.objmap.schema.SimpleSchema; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.elements.AuxiliaryElement; -import org.simantics.sysdyn.ui.elements.CloudElement; -import org.simantics.sysdyn.ui.elements.DependencyElement; -import org.simantics.sysdyn.ui.elements.FlowElement; -import org.simantics.sysdyn.ui.elements.StockElement; -import org.simantics.sysdyn.ui.elements.ValveElement; - -public class SysdynDiagramSchema extends SimpleSchema { - - public SysdynDiagramSchema(ReadGraph g) throws DatabaseException { - Builtins b = g.getBuiltins(); - SysdynResource sr = SysdynResource.getInstance(g); - try { - { - SimpleLinkType linkType = - new SimpleLinkType(sr.Configuration, Diagram.class); - linkType.addRule(new MappedElementsRule( - new RelatedObjectsAccessor(b.ConsistsOf, true), - new FieldAccessor>(Diagram.class.getField("elements")) - )); - addLinkType(linkType); - } - - addLinkType(MappingSchemas.fromAnnotations(g, AuxiliaryElement.class)); - addLinkType(MappingSchemas.fromAnnotations(g, StockElement.class)); - addLinkType(MappingSchemas.fromAnnotations(g, CloudElement.class)); - addLinkType(MappingSchemas.fromAnnotations(g, ValveElement.class)); - addLinkType(MappingSchemas.fromAnnotations(g, DependencyElement.class)); - addLinkType(MappingSchemas.fromAnnotations(g, FlowElement.class)); - } catch(NoSuchFieldException e) { - e.printStackTrace(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Arcs.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Arcs.java deleted file mode 100644 index 7651fcd0..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Arcs.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.geom.Rectangle2D; - -public class Arcs { - - public static final double PI2 = Math.PI*2.0; - - /** - * Returns angle + 2PI * n such that the - * result is between -PI and PI. - */ - public static double normalizeAngle(double angle) { - return Math.IEEEremainder(angle, PI2); - } - - /** - * Returns true, if three normalized angles are clockwise oriented. - */ - public static boolean areClockwiseOrdered(double angle1, double angle2, double angle3) { - //System.out.println(angle1 + " " + angle2 + " " + angle3); - return angle1 < angle2 - ? (angle2 < angle3 || angle3 < angle1) - : (angle2 < angle3 && angle3 < angle1) - ; - } - - /** - * Returns an angle in radians between straight line from (x0,y0) to (x2,y2) - * and an arc from (x0,y0) to (x2,y2) thru (x1,y1). The angle - * is measured at (x0,y0) and is between -PI and PI. - */ - public static double angleOfArc( - double x0, double y0, - double x1, double y1, - double x2, double y2) { - double dx0 = x1-x0; - double dy0 = y1-y0; - double dx1 = x1-x2; - double dy1 = y1-y2; - double dx = x2-x0; - double dy = y2-y0; - // Length of cross product (p1-p0)x(p2-p0) - double dd = dx0*dy - dy0*dx; - - if(Math.abs(dd) < 1e-6) // Points are (almost) collinear - return 0.0; - else { - // (p1-p0)*(p1-p2) / dd - double offset = (dx0*dx1 + dy0*dy1) / dd; - double angle = Math.PI*0.5 - Math.atan(offset); - if(dd > 0.0) - angle = angle-Math.PI; - return angle; - - } - } - - private static double updateBestNextAngle(double curAngle, double bestAngle, double newAngle) { - if(newAngle < curAngle) - newAngle += PI2; - if(newAngle < bestAngle) - return newAngle; - return bestAngle; - } - - private static double updateBestPrevAngle(double curAngle, double bestAngle, double newAngle) { - if(newAngle > curAngle) - newAngle -= PI2; - if(newAngle > bestAngle) - return newAngle; - return bestAngle; - } - - public static double nextIntersectingAngle(double cx, double cy, double r, - double curAngle, Rectangle2D rect, boolean dir) { - if(!dir) { - double bestAngle = curAngle + PI2; - { - double dx = rect.getMinX() - cx; - if(Math.abs(dx) < r) { - double angle = normalizeAngle(Math.acos(dx / r)); - bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); - bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle); - } - } - { - double dx = rect.getMaxX() - cx; - if(Math.abs(dx) < r) { - double angle = normalizeAngle(Math.acos(dx / r)); - bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); - bestAngle = updateBestNextAngle(curAngle, bestAngle, -angle); - } - } - { - double dy = cy - rect.getMinY(); - if(Math.abs(dy) < r) { - double angle = Math.asin(dy / r); - bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); - bestAngle = updateBestNextAngle(curAngle, bestAngle, - normalizeAngle(Math.PI-angle)); - } - } - { - double dy = cy - rect.getMaxY(); - if(Math.abs(dy) < r) { - double angle = Math.asin(dy / r); - bestAngle = updateBestNextAngle(curAngle, bestAngle, angle); - bestAngle = updateBestNextAngle(curAngle, bestAngle, - normalizeAngle(Math.PI-angle)); - } - } - return normalizeAngle(bestAngle); - } - else { - double bestAngle = curAngle - PI2; - { - double dx = rect.getMinX() - cx; - if(Math.abs(dx) < r) { - double angle = normalizeAngle(Math.acos(dx / r)); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle); - } - } - { - double dx = rect.getMaxX() - cx; - if(Math.abs(dx) < r) { - double angle = normalizeAngle(Math.acos(dx / r)); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, -angle); - } - } - { - double dy = cy - rect.getMinY(); - if(Math.abs(dy) < r) { - double angle = Math.asin(dy / r); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, - normalizeAngle(Math.PI-angle)); - } - } - { - double dy = cy - rect.getMaxY(); - if(Math.abs(dy) < r) { - double angle = Math.asin(dy / r); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, angle); - bestAngle = updateBestPrevAngle(curAngle, bestAngle, - normalizeAngle(Math.PI-angle)); - } - } - return normalizeAngle(bestAngle); - } - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryElement.java deleted file mode 100644 index 068f65f8..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryElement.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import org.simantics.objmap.annotations.GraphType; - -@GraphType("http://www.simantics.org/Sysdyn-1.0/Auxiliary") -public class AuxiliaryElement extends TextElement { - - public AuxiliaryElement() { - } - - public AuxiliaryElement(String label, double x, double y) { - super(label, x, y); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java deleted file mode 100644 index f7cd27fd..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.geom.Path2D; - -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.h2d.node.ShapeNode; -import org.simantics.objmap.annotations.GraphType; -import org.simantics.scenegraph.g2d.G2DParentNode; - -@GraphType("http://www.simantics.org/Sysdyn-1.0/Cloud") -public class CloudElement extends RectangularElement implements Connectable { - - public static final double CLOUD_SIZE_X = 5.0; - public static final double CLOUD_SIZE_Y = 3.0; - - public static final double CLOUD_CURVES = 7; - - ShapeNode cloudNode; - boolean rotated = false; - - public CloudElement() { - } - - public CloudElement(double x, double y) { - this.posX = x; - this.posY = y; - } - - @Override - public void init(G2DParentNode parent) { - cloudNode = parent.addNode(ShapeNode.class); - cloudNode.setColor(Color.BLACK); - cloudNode.setScaleStroke(true); - cloudNode.setStroke(new BasicStroke(1)); - update(); - } - - @Override - public void remove() { - cloudNode.remove(); - } - - protected void update() { - //bounds.setFrame(posX-CLOUD_SIZE_X, posY-CLOUD_SIZE_Y, 2.0*CLOUD_SIZE_X, 2.0*CLOUD_SIZE_Y); - Path2D path = new Path2D.Double(); - double ox = CLOUD_SIZE_X; - double oy = 0.0; - path.moveTo(posX+ox, posY+oy); - for(int i=1;i 0.0); - double extent = angle1-angle0; - //double arcAngle = angle0; - if(angle < 0.0) { - double temp = angle0; - angle0 = angle1; - angle1 = temp; - extent = -extent; - } - if(extent < 0) - extent += Math.PI*2.0; - else if(extent >= 360.0) - extent -= Math.PI*2.0; - Shape shape = new Arc2D.Double(cx-r, cy-r, 2*r, 2*r, - Math.toDegrees(angle0), - Math.toDegrees(extent), - Arc2D.OPEN); - arcNode.setShape(shape); - - double xx = Math.cos(angle > 0.0 ? angle1 : angle0); - double yy = -Math.sin(angle > 0.0 ? angle1 : angle0); - Shape arrowShape = createArrow(cx + r*xx, cy + r*yy, - angle < 0.0 ? -yy : yy, - angle > 0.0 ? -xx : xx); - arrowNode.setShape(arrowShape); - } - - public void update() { - if(arcNode != null) - updateSceneGraph(); - fireElementUpdated(); - } - - @Override - public void getBounds(Rectangle2D bounds) { - bounds.setFrame(arcNode.getBounds()); - } - - @Override - public boolean hitTest(double x, double y, double tolerance) { - double dx = x-cx; - double dy = y-cy; - double dist = dx*dx + dy*dy; - if(dist < (r+tolerance)*(r+tolerance) && - dist > (r-tolerance)*(r-tolerance)) { - double angle = Arcs.normalizeAngle(Math.atan2(-dy, dx)); - if(Arcs.areClockwiseOrdered(angle0, angle, angle1)) - return true; - } - return false; - } - - class EventHandler extends DragEventHandler { - @Override - protected boolean begin(IDiagramEditor editor, DragEvent event) { - return event.startModifiers.equals("left"); - } - - @Override - protected void update(IDiagramEditor editor, DragEvent event) { - if(event == null) - return; - angle = Arcs.angleOfArc( - tail.getOrigo().getX(), tail.getOrigo().getY(), - event.current.getX(), event.current.getY(), - head.getOrigo().getX(), head.getOrigo().getY() - ); - DependencyElement.this.update(); - editor.requestRepaint(); - } - } - - @SuppressWarnings("unchecked") - @Override - public T getInterface(Class clazz) { - if(clazz == IEventHandler.class) - return (T)new EventHandler(); - return super.getInterface(clazz); - } - - @Override - public void elementRemoved(IElement element) { - remove(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java deleted file mode 100644 index 9371a6d4..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java +++ /dev/null @@ -1,249 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.geom.Path2D; -import java.awt.geom.Rectangle2D; - -import org.simantics.h2d.element.Element; -import org.simantics.h2d.element.IElement; -import org.simantics.h2d.element.IElementListener; -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.h2d.node.FilledShapeNode; -import org.simantics.h2d.node.ShapeNode; -import org.simantics.objmap.annotations.GraphType; -import org.simantics.objmap.annotations.RelatedElement; -import org.simantics.scenegraph.g2d.G2DParentNode; - -@GraphType("http://www.simantics.org/Sysdyn-1.0/Flow") -public class FlowElement extends Element implements IElementListener { - - public static double ARROW_LENGTH = 3.2; - public static double ARROW_WIDTH = 3; - - static final double OFFSET = 1.5; - static final double ARROW_OFFSET = 3.2; - - /* - * Total length of the arrow is ARROW_LENGTH1 + ARROW_LENGTH2 - */ - @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasTail") - Connectable tail; - @RelatedElement("http://www.simantics.org/Sysdyn-1.0/HasHead") - Connectable head; - - // Auxiliary - double angle0; - double angle1; - double cx; - double cy; - double r; - - // Scene graph - ShapeNode lineNode1; - ShapeNode lineNode2; - FilledShapeNode arrowNode; - - public FlowElement() { - } - - public FlowElement(Connectable tail, Connectable head) { - super(); - this.tail = tail; - this.head = head; - tail.addListener(this); - head.addListener(this); - } - - @Override - public void elementUpdated(IElement element) { - update(); - } - - @Override - public void remove() { - lineNode1.remove(); - lineNode2.remove(); - arrowNode.remove(); - tail.removeListener(this); - head.removeListener(this); - super.remove(); - } - - @Override - public void init(G2DParentNode parent) { - tail.addListener(this); - head.addListener(this); - - lineNode1 = parent.addNode(ShapeNode.class); - lineNode1.setScaleStroke(true); - lineNode2 = parent.addNode(ShapeNode.class); - lineNode2.setScaleStroke(true); - - arrowNode = parent.addNode(FilledShapeNode.class); - update(); - } - - protected void createArrow(Connectable head, Connectable tail) { - double x = tail.getOrigo().getX(); - double y = tail.getOrigo().getY(); - - Rectangle2D rect = new Rectangle2D.Double(); - head.getBounds(rect); - double cx = rect.getCenterX(); - double minx = rect.getMinX(); - double maxx = rect.getMaxX(); - double miny = rect.getMinY(); - double maxy = rect.getMaxY(); - - Path2D path = new Path2D.Double(); - - // approach from top - if (y < miny) { - path.moveTo(cx, miny); - path.lineTo(cx + ARROW_WIDTH, miny - ARROW_LENGTH); - path.lineTo(cx - ARROW_WIDTH, miny - ARROW_LENGTH); - } - - // approach from beneath - else if (y > maxy) { - path.moveTo(cx, maxy); - path.lineTo(cx + ARROW_WIDTH, maxy + ARROW_LENGTH); - path.lineTo(cx - ARROW_WIDTH, maxy + ARROW_LENGTH); - } - - // approach from left - else if (x < minx) { - path.moveTo(minx, y); - path.lineTo(minx - ARROW_LENGTH, y - ARROW_WIDTH); - path.lineTo(minx - ARROW_LENGTH, y + ARROW_WIDTH); - } - - // approach from right - else if (x > maxx) { - path.moveTo(maxx, y); - path.lineTo(maxx + ARROW_LENGTH, y - ARROW_WIDTH); - path.lineTo(maxx + ARROW_LENGTH, y + ARROW_WIDTH); - } - else - return; // FIXME (HN) This is just a quick bugfix, didn't understand the logic completely - - path.closePath(); - arrowNode.setShape(path); - } - - // TODO - - private void draw(boolean vertical, double ... coordinates) { - lineNode1.setShape(Flows.createOffsetLine(vertical, OFFSET, coordinates)); - lineNode2.setShape(Flows.createOffsetLine(vertical, -OFFSET, coordinates)); - } - - private void draw(boolean hasArrow, Connectable valve, Connectable node) { - double x0 = valve.getOrigo().getX(); - double y0 = valve.getOrigo().getY(); - double x1 = node.getOrigo().getX(); - double y1 = node.getOrigo().getY(); - - Rectangle2D rect = new Rectangle2D.Double(); - node.getBounds(rect); - - double minY = hasArrow ? rect.getMinY() - ARROW_OFFSET : rect.getMinY(); - double maxY = hasArrow ? rect.getMaxY() + ARROW_OFFSET : rect.getMaxY(); - double minX = hasArrow ? rect.getMinX() - ARROW_OFFSET : rect.getMinX(); - double maxX = hasArrow ? rect.getMaxX() + ARROW_OFFSET : rect.getMaxX(); - - - if( ((ValveElement)valve).rotated ) { - if(y1 > y0) - y0 += OFFSET; - else - y0 -= OFFSET; - if(rect.getMinX() <= x0 && rect.getMaxX() >= x0) { - if(y1 > y0) - draw(true, y0, x0, minY); - else - draw(true, y0, x0, maxY); - } - else { - if(x1 > x0) - draw(true, y0, x0, y1, minX); - else - draw(true, y0, x0, y1, maxX); - } - } - else { - if(x1 > x0) - x0 += OFFSET; - else - x0 -= OFFSET; - if(rect.getMinY() <= y0 && rect.getMaxY() >= y0) { - if(x1 > x0) - draw(false, x0, y0, minX); - else - draw(false, x0, y0, maxX); - } - else { - if(y1 > y0) - draw(false, x0, y0, x1, minY); - else - draw(false, x0, y0, x1, maxY); - } - } - - - } - - protected void updateSceneGraph() { - boolean hasArrow = tail instanceof ValveElement && !(head instanceof ValveElement); - if(tail instanceof ValveElement) - draw(hasArrow, tail, head); - else if(head instanceof ValveElement) - draw(hasArrow, head, tail); - if(hasArrow) - createArrow(head, tail); - } - - // TODO - - public void update() { - if(lineNode1 != null) - updateSceneGraph(); - fireElementUpdated(); - } - - @Override - public void getBounds(Rectangle2D bounds) { - bounds.setFrame(lineNode1.getBoundsInLocal()); - bounds.add(lineNode2.getBoundsInLocal()); - } - - @Override - public boolean hitTest(double x, double y, double tolerance) { - // FIXME totally incorrect - /*Rectangle2D rect = new Rectangle2D.Double(); - getBounds(rect); - return rect.contains(x, y);*/ - return false; - } - - @Override - public T getInterface(Class clazz) { - return super.getInterface(clazz); - } - - @Override - public void elementRemoved(IElement element) { - remove(); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Flows.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Flows.java deleted file mode 100644 index 59e7def1..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Flows.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.geom.Path2D; - -public class Flows { - public static Path2D createLine(boolean vertical, double ... coordinates) { - Path2D path = new Path2D.Double(); - if(vertical) - path.moveTo(coordinates[1], coordinates[0]); - else - path.moveTo(coordinates[0], coordinates[1]); - for(int i=2;i elements = editor.getDiagram().getElements(); - for(IElement e : elements) { - if(e instanceof TextElement) { - TextElement t = (TextElement) e; - if(t != TextElement.this && t.label.equals(textNode.getText())) { - label = oldText; - //update(); - //editor.requestRepaint(); - } - } - } - } - } - - } - - public void beginRenameAction(IDiagramEditor editor) { - editor.addAction(new TextEditingAction(editor)); - } - - @Override - public boolean handle(IDiagramEditor editor, IEvent _event) { - if(_event instanceof KeyboardEvent) { - KeyboardEvent event = (KeyboardEvent)_event; - if(event.key.equals("F3") || event.key.equals("F2")) { - beginRenameAction(editor); - return true; - } - } - return false; - } - - boolean oldHasEquation = false; - - boolean hasEquation = true; - String oldLabel = label; - - @UpdateMethod - boolean updateCheck(ReadGraph g, Resource resource) { -// SysdynResource sr = SysdynResource.getInstance(g); - boolean update = false; -// try { -// hasEquation = -// !g.getObjects(resource, sr.HasExpression).isEmpty(); -// if(oldHasEquation != hasEquation) -// update = true; - if(!label.equals(oldLabel)) { - oldLabel = label; - update = true; - } - if(update) - update(); -// } catch (DatabaseException e) { -// e.printStackTrace(); -// } - return false; - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java deleted file mode 100644 index 81f14937..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.geom.Path2D; - -import org.simantics.h2d.element.handler.Rotatable; -import org.simantics.h2d.node.ShapeNode; -import org.simantics.objmap.annotations.GraphType; -import org.simantics.scenegraph.g2d.G2DParentNode; - -@GraphType("http://www.simantics.org/Sysdyn-1.0/Valve") -public class ValveElement extends TextElement implements Rotatable { - - public static final double VALVE_SIZE = 5.0; - - ShapeNode valveNode; - boolean rotated = false; - - public ValveElement() { - } - - public ValveElement(double x, double y) { - this.posX = x; - this.posY = y; - } - - @Override - public double getTextDeltaY() { - return 8.0; - } - - @Override - public void init(G2DParentNode parent) { - valveNode = parent.addNode(ShapeNode.class); - valveNode.setColor(Color.BLACK); - valveNode.setScaleStroke(true); - valveNode.setStroke(new BasicStroke(1)); - super.init(parent); - } - - @Override - public void remove() { - valveNode.remove(); - super.remove(); - } - - @Override - protected void update() { - Path2D path = new Path2D.Double(); - path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE); - if(rotated) { - path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); - path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE); - } - else { - path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE); - path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); - } - path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE); - path.closePath(); - valveNode.setShape(path); - updateText(); - bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE); - fireElementUpdated(); - } - - @Override - public void rotate(int amount) { - if((amount & 1) == 1) { - rotated = !rotated; - update(); - } - } - - public boolean isRotated() { - return rotated; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java deleted file mode 100644 index d63c7d4c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.elements; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.geom.Path2D; - -import org.simantics.h2d.element.handler.Connectable; -import org.simantics.h2d.element.handler.Rotatable; -import org.simantics.h2d.node.ShapeNode; -import org.simantics.objmap.annotations.GraphType; -import org.simantics.scenegraph.g2d.G2DParentNode; - -@GraphType("http://www.simantics.org/Sysdyn-1.0/Valve") -public class ValveElementOld extends RectangularElement implements Connectable, Rotatable { - - public static final double VALVE_SIZE = 5.0; - - ShapeNode valveNode; - boolean rotated = false; - - public ValveElementOld() { - } - - public ValveElementOld(double x, double y) { - this.posX = x; - this.posY = y; - } - - @Override - public void init(G2DParentNode parent) { - valveNode = parent.addNode(ShapeNode.class); - valveNode.setColor(Color.BLACK); - valveNode.setScaleStroke(true); - valveNode.setStroke(new BasicStroke(1)); - update(); - } - - @Override - public void remove() { - valveNode.remove(); - } - - protected void update() { - bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE); - Path2D path = new Path2D.Double(); - path.moveTo(posX-VALVE_SIZE, posY-VALVE_SIZE); - if(rotated) { - path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); - path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE); - } - else { - path.lineTo(posX+VALVE_SIZE, posY-VALVE_SIZE); - path.lineTo(posX-VALVE_SIZE, posY+VALVE_SIZE); - } - path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE); - path.closePath(); - valveNode.setShape(path); - fireElementUpdated(); - } - - @Override - public void rotate(int amount) { - if((amount & 1) == 1) { - rotated = !rotated; - update(); - } - } - - public boolean isRotated() { - return rotated; - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java index 96a3cd5e..5916f732 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/BorderSceneGraph.java @@ -1,12 +1,10 @@ package org.simantics.sysdyn.ui.elements2; import java.awt.geom.AffineTransform; - import org.simantics.g2d.element.ElementUtils; import org.simantics.g2d.element.IElement; import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.SceneGraph; -import org.simantics.h2d.node.RectangleNode; import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.hints.IHintContext.Key; @@ -39,5 +37,4 @@ public class BorderSceneGraph implements SceneGraph, Callback { public void cleanup(IElement e) { ElementUtils.removePossibleNode(e, BORDER_NODE); } - } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java new file mode 100644 index 00000000..c3701054 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/RectangleNode.java @@ -0,0 +1,36 @@ +package org.simantics.sysdyn.ui.elements2; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Rectangle2D; +import org.simantics.scenegraph.g2d.G2DNode; + +public class RectangleNode extends G2DNode { + + private static final long serialVersionUID = 654692698101485672L; + + protected Rectangle2D bounds = null; + + @SyncField("bounds") + public void init(Rectangle2D bounds) { + this.bounds = bounds; + } + + @Override + public void render(Graphics2D g) { + if(bounds == null) return; + g.transform(transform); + g.setColor(Color.BLACK); + double scale = g.getTransform().getScaleX(); + g.setStroke(new BasicStroke( (float)(1.0 / scale) )); + + g.draw(bounds); + } + + @Override + public Rectangle2D getBoundsInLocal() { + return bounds; + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateAuxiliaryHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateAuxiliaryHandler.java deleted file mode 100644 index cc32ba40..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateAuxiliaryHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.sysdyn.ui.actions.CreateAuxiliary; - -public class CreateAuxiliaryHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - CreateAuxiliary ca = new CreateAuxiliary(); - ca.handle(editor, event); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateCloudHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateCloudHandler.java deleted file mode 100644 index 2beded5c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateCloudHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.sysdyn.ui.actions.CreateCloud; - -public class CreateCloudHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - CreateCloud cc = new CreateCloud(); - cc.handle(editor, event); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateStockHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateStockHandler.java deleted file mode 100644 index 2716596a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateStockHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.sysdyn.ui.actions.CreateStock; - -public class CreateStockHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - CreateStock cs = new CreateStock(); - cs.handle(editor, event); - } -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateValveHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateValveHandler.java deleted file mode 100644 index e4fe83b1..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/CreateValveHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.sysdyn.ui.actions.CreateValve; - -public class CreateValveHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - CreateValve cv = new CreateValve(); - cv.handle(editor, event); - } - -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramContextMenuActionHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramContextMenuActionHandler.java deleted file mode 100644 index b13abfab..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DiagramContextMenuActionHandler.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.sysdyn.ui.actions.DiagramContextMenuData; -import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor; - -public abstract class DiagramContextMenuActionHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchPart ap = HandlerUtil.getActivePart(event); - if(ap instanceof SysdynDiagramEditor) { - Event ci = (Event)event.getTrigger(); - MenuItem mi = (MenuItem) ci.widget; - Menu m = mi.getParent(); - while(m.getParentMenu() != null) - m = m.getParentMenu(); - DiagramContextMenuData cmd = (DiagramContextMenuData) m.getData(); - IDiagramEditor de = cmd.diagramEditor; - IEvent evnt = cmd.event; - handleEvent(de, evnt); - } - return null; - } - - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - // Implement in another class - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java index 13bc387c..40b66ad3 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/DisposeExperiment.java @@ -3,9 +3,7 @@ package org.simantics.sysdyn.ui.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.simantics.project.IExperimentDescriptor; import org.simantics.project.IProject; -import org.simantics.project.ProjectKeys; import org.simantics.simulation.experiment.IExperiment; import org.simantics.simulation.project.IExperimentManager; import org.simantics.ui.SimanticsUI; @@ -20,15 +18,6 @@ public class DisposeExperiment extends AbstractHandler { IExperiment experiment = manager.getActiveExperiment(); if (experiment != null) experiment.shutdown(); - - /* - // Keep the UI happy. - IExperimentDescriptor ed = project.getHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT); - if (ed != null) { - ed.getParent().removeHint(ProjectKeys.KEY_SELECTED_EXPERIMENT); - project.removeHint(ProjectKeys.KEY_SELECTED_UI_EXPERIMENT); - } - */ return null; } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveHandler.java deleted file mode 100644 index b5edcc2c..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.handler.Delete; - -public class RemoveHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - Delete d = new Delete(); - d.handle(editor, event); - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameHandler.java deleted file mode 100644 index a187806f..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RenameHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import org.simantics.h2d.editor.IDiagramEditor; -import org.simantics.h2d.element.IElement; -import org.simantics.h2d.event.IEvent; -import org.simantics.h2d.event.ILocatableEvent; -import org.simantics.sysdyn.ui.elements.TextElement; - -public class RenameHandler extends DiagramContextMenuActionHandler { - - protected void handleEvent(IDiagramEditor editor, IEvent event) { - ILocatableEvent e = (ILocatableEvent)event; - if(e.getPickedElements().size() <= 0) return; - IElement element = e.getPickedElements().get(0); - if(element instanceof TextElement) { - TextElement te = (TextElement)element; - te.beginRenameAction(editor); - } - } - -} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java index 8b81ffc1..a4f6488d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RunBasicExperiment.java @@ -14,7 +14,6 @@ import org.eclipse.ui.menus.UIElement; import org.simantics.simulation.experiment.IDynamicExperiment; import org.simantics.simulation.experiment.IExperiment; import org.simantics.simulation.project.IExperimentManager; -import org.simantics.sysdyn.ui.actions.ToggleSimulation; import org.simantics.ui.SimanticsUI; public class RunBasicExperiment extends AbstractHandler implements IElementUpdater { @@ -31,7 +30,6 @@ public class RunBasicExperiment extends AbstractHandler implements IElementUpdat return null; } - @SuppressWarnings("unchecked") @Override public void updateElement(UIElement element, Map parameters) { ICommandService commandService = diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java index eff51ec0..7d48e60e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java @@ -22,7 +22,6 @@ import org.simantics.databoard.binding.java.StringBindingDefault; import org.simantics.db.Builtins; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.ResourceArray; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; @@ -31,7 +30,6 @@ import org.simantics.diagram.stubs.DiagramResource; import org.simantics.modeling.ComponentUtils; import org.simantics.modeling.ModelingResources; import org.simantics.structural.stubs.StructuralResource2; -import org.simantics.structural2.StructuralVariables; import org.simantics.sysdyn.SysdynResource; import org.simantics.sysdyn.ui.editor.DiagramViewer; import org.simantics.ui.SimanticsUI; @@ -88,7 +86,6 @@ public class ShowModuleHandler extends AbstractHandler { if(diagram == null) return; final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, b.HasName, StringBindingDefault.INSTANCE); - if(rvi == null) return; PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java similarity index 92% rename from org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java rename to org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java index d92a2de7..3f220a5e 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/actions/ToggleSimulation.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ToggleSimulation.java @@ -9,7 +9,7 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.sysdyn.ui.actions; +package org.simantics.sysdyn.ui.handlers; import java.util.Map; @@ -23,11 +23,9 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.commands.IElementUpdater; import org.eclipse.ui.menus.UIElement; -import org.simantics.simulation.experiment.IDynamicExperiment; import org.simantics.simulation.experiment.IExperiment; import org.simantics.simulation.project.IExperimentManager; import org.simantics.sysdyn.manager.SysdynExperiment; -import org.simantics.sysdyn.ui.handlers.RunBasicExperiment; import org.simantics.ui.SimanticsUI; public class ToggleSimulation extends AbstractHandler implements IElementUpdater { @@ -67,7 +65,6 @@ public class ToggleSimulation extends AbstractHandler implements IElementUpdater return (Boolean)state.getValue(); } - @SuppressWarnings("unchecked") @Override public void updateElement(UIElement element, Map parameters) { ICommandService commandService = diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler.java deleted file mode 100644 index b073c84a..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/UnlinkNodeHandler.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.handlers; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.handlers.HandlerUtil; -import org.simantics.db.Builtins; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.CancelTransactionException; -import org.simantics.db.exception.DatabaseException; -import org.simantics.simulation.ontology.SimulationResource; -import org.simantics.sysdyn.SysdynResource; -import org.simantics.sysdyn.ui.editor.SysdynDiagramEditor; -import org.simantics.ui.SimanticsUI; -import org.simantics.ui.utils.ResourceAdaptionUtils; -import org.simantics.utils.ui.ExceptionUtils; - -/** - * @author Tuukka Lehtonen - */ -public class UnlinkNodeHandler extends AbstractHandler { - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Shell shell = HandlerUtil.getActiveShellChecked(event); - ISelection sel = HandlerUtil.getCurrentSelection(event); - Resource[] resources = ResourceAdaptionUtils.toResources(sel); - if (resources.length == 0) - return null; - - MessageDialog dialog = new MessageDialog(shell, "Remove Item", null, "Are you sure?", 0, - new String[] { "OK", "Cancel" }, 0); - dialog.create(); - if (dialog.open() == 0) - deleteItem(resources); - - return null; - } - - private void deleteItem(final Resource[] resources) { - final ArrayList configurations = new ArrayList(); - try { - SimanticsUI.getSession().syncRequest(new WriteRequest() { - @Override - public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException { - SysdynResource sr = SysdynResource.getInstance(graph); - SimulationResource SIMU = SimulationResource.getInstance(graph); - for (Resource r : resources) { - if (graph.isInstanceOf(r, sr.SysdynModel)) { - unlinkModel(graph, r); - configurations.add(graph.getSingleObject(r, SIMU.HasConfiguration)); - } - else if (graph.isInstanceOf(r, SIMU.Experiment)) - unlinkExperiment(graph, r); - else if (graph.isInstanceOf(r, sr.Result)) - unlinkResult(graph, r); - } - } - }); - } catch (DatabaseException e) { - ExceptionUtils.logAndShowError(e); - } - - for (Resource r : configurations) { - IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); - for(IEditorReference er : editorReferences) { - if(er.getEditor(false) instanceof SysdynDiagramEditor) { - SysdynDiagramEditor editor = (SysdynDiagramEditor)er.getEditor(false); - if(editor.getResourceInput().getResource().equals(r)) { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false); - } - } - } - } - - } - - private void unlinkModel(WriteGraph graph, Resource model) throws DatabaseException { - Builtins b = graph.getBuiltins(); - - for(Resource r : graph.getObjects(model, b.ConsistsOf)) - if(graph.isInstanceOf(r, SysdynResource.getInstance(graph).Result)) - deleteResultFiles(graph, r); - - graph.deny(model, b.PartOf); - } - - private void unlinkExperiment(WriteGraph graph, Resource experiment) throws DatabaseException { - Builtins b = graph.getBuiltins(); - Collection results = graph.getObjects(experiment, SysdynResource.getInstance(graph).HasResult); - if(results != null) - for(Resource result : results) - unlinkResult(graph, result); - graph.deny(experiment, b.PartOf); - - } - - private void unlinkResult(WriteGraph graph, Resource result) throws DatabaseException { - Builtins b = graph.getBuiltins(); - deleteResultFiles(graph, result); - graph.deny(result, b.PartOf); - graph.deny(result, graph.getInverse(SysdynResource.getInstance(graph).HasResult)); - - } - - private void deleteResultFiles(WriteGraph graph, Resource result) throws DatabaseException { - String path; - path = graph.getPossibleRelatedValue(result, SysdynResource.getInstance(graph).HasResultFile); - if(path != null) { - File file = new File(path); - file.delete(); - File parent = file.getParentFile(); - if(parent.listFiles().length == 0) - parent.delete(); - } - } - -} \ No newline at end of file diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java index bd81f37a..a8961429 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/listeners/SysdynExperimentListener.java @@ -7,8 +7,8 @@ import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.contexts.IContextActivation; import org.simantics.simulation.experiment.ExperimentState; import org.simantics.simulation.experiment.IExperimentListener; -import org.simantics.sysdyn.ui.actions.ToggleSimulation; import org.simantics.sysdyn.ui.handlers.RunBasicExperiment; +import org.simantics.sysdyn.ui.handlers.ToggleSimulation; public class SysdynExperimentListener implements IExperimentListener { diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java deleted file mode 100644 index be4a5077..00000000 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/sg/SysdynSceneGraphProvider.java +++ /dev/null @@ -1,172 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.sysdyn.ui.sg; - -import java.awt.AWTEvent; -import java.awt.event.AWTEventListener; -import java.awt.geom.Rectangle2D; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.h2d.diagram.IDiagram; -import org.simantics.h2d.diagram.IDiagramListener; -import org.simantics.h2d.element.IElement; -import org.simantics.objmap.IMapping; -import org.simantics.objmap.IMappingListener; -import org.simantics.objmap.MappingException; -import org.simantics.objmap.Mappings; -import org.simantics.scenegraph.adapters.ISceneGraphProvider; -import org.simantics.scenegraph.g2d.G2DParentNode; -import org.simantics.scenegraph.g2d.G2DSceneGraph; -import org.simantics.scenegraph.g2d.nodes.NavigationNode; -import org.simantics.scenegraph.g2d.nodes.PageBorderNode; -import org.simantics.scenegraph.g2d.nodes.TransformNode; -import org.simantics.sysdyn.ui.editor.SysdynDiagramSchema; - -public class SysdynSceneGraphProvider implements ISceneGraphProvider, AWTEventListener { - - protected Resource resource; - - IDiagram diagram; - IMapping mapping; - - public SysdynSceneGraphProvider(ReadGraph g, final Resource resource) { - this.resource = resource; - - SysdynDiagramSchema schema; - try { - schema = new SysdynDiagramSchema(g); - } catch (DatabaseException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - return; - } - - mapping = Mappings.createWithListening(schema); - - try { - diagram = (IDiagram)mapping.map(g, resource); - } catch (MappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - final Session session = g.getSession(); - mapping.addMappingListener(new IMappingListener() { - - @Override - public void rangeModified() { - session.asyncRequest(new WriteRequest() { - - @Override - public void perform(WriteGraph graph) - throws DatabaseException { - try { - mapping.updateDomain(graph); - } catch(Exception e) { - e.printStackTrace(); - } - } - - }); - } - - @Override - public void domainModified() { - session.asyncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - try { - mapping.updateRange(graph); - } catch(Exception e) { - e.printStackTrace(); - } - } - }); - } - }); - } - - @Override - public void dispose() { - - } - - @Override - public AWTEventListener getEventListener() { - return this; - } - - @Override - public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg) { - return initializeSceneGraph(sg, null); - } - - G2DSceneGraph sceneGraph; - TransformNode diagramCoordinatesNode; - G2DParentNode elementsNode; - G2DParentNode selectionNode; - G2DParentNode actionNode; - - @Override - public G2DSceneGraph initializeSceneGraph(G2DSceneGraph sg, String view) { - sceneGraph = sg; - diagramCoordinatesNode = sceneGraph.addNode(NavigationNode.class); - - PageBorderNode border = diagramCoordinatesNode.addNode(PageBorderNode.class); - 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); - - elementsNode = diagramCoordinatesNode.addNode(G2DParentNode.class); - elementsNode.setZIndex(0); - - selectionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); - selectionNode.setZIndex(1); - - actionNode = diagramCoordinatesNode.addNode(G2DParentNode.class); - actionNode.setZIndex(2); - - for(IElement element : diagram.getElements()) - element.init(elementsNode); - diagram.addDiagramListener(new IDiagramListener() { - - @Override - public void elementAdded(IElement element) { - element.init(elementsNode); - } - - @Override - public void elementRemoved(IElement element) { - element.remove(); - } - }); - - return sg; - } - - @Override - public void setHint(Object key, Object value) { - // TODO Auto-generated method stub - - } - - @Override - public void eventDispatched(AWTEvent event) { - - } - -} -- 2.47.1