]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@12943 ac1ea38d-2e2b...
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 Nov 2009 15:05:51 +0000 (15:05 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 Nov 2009 15:05:51 +0000 (15:05 +0000)
19 files changed:
org.simantics.sysdyn.ui/.classpath [new file with mode: 0644]
org.simantics.sysdyn.ui/.project [new file with mode: 0644]
org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.sysdyn.ui/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.sysdyn.ui/adapters.xml [new file with mode: 0644]
org.simantics.sysdyn.ui/build.properties [new file with mode: 0644]
org.simantics.sysdyn.ui/plugin.xml [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Drawable.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/IDrawable.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ITransformable.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TestDrawable.java [new file with mode: 0644]

diff --git a/org.simantics.sysdyn.ui/.classpath b/org.simantics.sysdyn.ui/.classpath
new file mode 100644 (file)
index 0000000..8a8f166
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.sysdyn.ui/.project b/org.simantics.sysdyn.ui/.project
new file mode 100644 (file)
index 0000000..2ebd569
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.sysdyn.ui</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs b/org.simantics.sysdyn.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..6d81695
--- /dev/null
@@ -0,0 +1,8 @@
+#Thu Nov 05 12:45:23 EET 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
diff --git a/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF b/org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..33131ca
--- /dev/null
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Ui
+Bundle-SymbolicName: org.simantics.sysdyn.ui;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.simantics.sysdyn.ui.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.simantics.ui;bundle-version="1.0.0",
+ org.simantics.diagram;bundle-version="1.0.0",
+ org.simantics.db;bundle-version="0.6.2",
+ org.simantics.db.common;bundle-version="0.6.2",
+ org.simantics.db.layer0;bundle-version="0.7.0",
+ org.simantics.g2d;bundle-version="1.0.0",
+ org.simantics.scenegraph;bundle-version="1.0.0",
+ org.simantics.layer0.utils;bundle-version="0.6.2"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/org.simantics.sysdyn.ui/adapters.xml b/org.simantics.sysdyn.ui/adapters.xml
new file mode 100644 (file)
index 0000000..86c2aa3
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<adapters>\r
+<!-- \r
+       <target interface="org.simantics.project.features.IProjectFeature">\r
+               <type\r
+                       uri="http://www.simantics.org/Ontology/ProConf/1.0#SymbolManagerFeature"\r
+                       class="org.simantics.diagram.symbollibrary.SymbolManagerFeature">\r
+               </type>\r
+       </target>\r
+\r
+       <target interface="org.simantics.g2d.diagram.DiagramClass">\r
+               <baseType uri="http://www.simantics.org/Simantics/Diagram/2.0#Composite" />\r
+               <adapter uri="http://www.simantics.org/Simantics/Diagram/2.0#Composite"\r
+                       adapterClass="org.simantics.diagram.adapter.DiagramClassAdapter" />\r
+       </target>\r
+ -->\r
+       <target interface="org.simantics.diagram.adapter.GraphElementClassFactory">\r
+               <resource uri="http://www.simantics.org/Sysdyn#VariableElement"\r
+                       class="org.simantics.sysdyn.ui.adapters.VariableClassFactory" />\r
+       </target>\r
+\r
+       <target interface="org.simantics.diagram.adapter.GraphElementFactory">\r
+               <type uri="http://www.simantics.org/Sysdyn#VariableElement"\r
+                       class="org.simantics.sysdyn.ui.adapters.VariableClassFactory" />\r
+       </target>\r
+\r
+       <target interface="org.simantics.diagram.synchronization.graph.ElementWriter">\r
+               <type uri="http://www.simantics.org/Sysdyn#VariableElement"\r
+                       class="org.simantics.sysdyn.ui.adapters.VariableElementWriter" />\r
+       </target>\r
+\r
+</adapters>
\ No newline at end of file
diff --git a/org.simantics.sysdyn.ui/build.properties b/org.simantics.sysdyn.ui/build.properties
new file mode 100644 (file)
index 0000000..6f20375
--- /dev/null
@@ -0,0 +1,5 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .,\\r
+               plugin.xml\r
diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml
new file mode 100644 (file)
index 0000000..cac6482
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<?eclipse version="3.4"?>\r
+<plugin>\r
+   <extension\r
+         point="org.eclipse.ui.editors">\r
+      <editor\r
+            class="org.simantics.sysdyn.ui.diagram.SysdynDiagramEditor"\r
+            default="false"\r
+            id="org.simantics.sysdyn.ui.diagramEditor"\r
+            name="Sysdyn diagram editor">\r
+      </editor>\r
+   </extension>\r
+   <extension\r
+         point="org.simantics.ui.resourceEditorAdapter">\r
+      <adapter\r
+            editorId="org.simantics.sysdyn.ui.diagramEditor"\r
+            priority="3"\r
+            type_uris="http://www.vtt.fi/Simantics/Layer0/1.0/Types#Entity">\r
+      </adapter>\r
+   </extension>\r
+\r
+</plugin>\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/Activator.java
new file mode 100644 (file)
index 0000000..2134237
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.sysdyn.ui;\r
+\r
+import org.eclipse.ui.plugin.AbstractUIPlugin;\r
+import org.osgi.framework.BundleContext;\r
+\r
+/**\r
+ * The activator class controls the plug-in life cycle\r
+ */\r
+public class Activator extends AbstractUIPlugin {\r
+\r
+       // The plug-in ID\r
+       public static final String PLUGIN_ID = "org.simantics.sysdyn.ui";\r
+\r
+       // The shared instance\r
+       private static Activator plugin;\r
+       \r
+       /**\r
+        * The constructor\r
+        */\r
+       public Activator() {\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
+        */\r
+       public void start(BundleContext context) throws Exception {\r
+               super.start(context);\r
+               plugin = this;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
+        */\r
+       public void stop(BundleContext context) throws Exception {\r
+               plugin = null;\r
+               super.stop(context);\r
+       }\r
+\r
+       /**\r
+        * Returns the shared instance\r
+        *\r
+        * @return the shared instance\r
+        */\r
+       public static Activator getDefault() {\r
+               return plugin;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/SysdynResource.java
new file mode 100644 (file)
index 0000000..426b322
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui;\r
+\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public class SysdynResource {\r
+    \r
+    public final Resource HasX;\r
+    public final Resource HasY;\r
+    public final Resource SysdynModel;\r
+    public final Resource SysdynModelManager;\r
+    public final Resource SysdynModellingDomain;\r
+    public final Resource TestDiagram;\r
+    public final Resource Variable;\r
+    public final Resource VariableElement;\r
+    \r
+    public static class URIs {\r
+        public static final String HasX = "http://www.simantics.org/Sysdyn#HasX";\r
+        public static final String HasY = "http://www.simantics.org/Sysdyn#HasY";\r
+        public static final String SysdynModel = "http://www.simantics.org/Sysdyn#SysdynModel";\r
+        public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn#SysdynModelManager";\r
+        public static final String SysdynModellingDomain = "http://www.simantics.org/Sysdyn#SysdynModellingDomain";\r
+        public static final String TestDiagram = "http://www.simantics.org/Sysdyn#TestDiagram";\r
+        public static final String Variable = "http://www.simantics.org/Sysdyn#Variable";\r
+        public static final String VariableElement = "http://www.simantics.org/Sysdyn#VariableElement";\r
+    }\r
+    \r
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
+        try {\r
+            return graph.getResourceByURI(uri);\r
+        } catch(DatabaseException e) {\r
+            System.err.println(e.getMessage());\r
+            return null;\r
+        }\r
+    }\r
+    \r
+    public SysdynResource(ReadGraph graph) {\r
+        HasX = getResourceOrNull(graph, URIs.HasX);\r
+        HasY = getResourceOrNull(graph, URIs.HasY);\r
+        SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
+        SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
+        SysdynModellingDomain = getResourceOrNull(graph, URIs.SysdynModellingDomain);\r
+        TestDiagram = getResourceOrNull(graph, URIs.TestDiagram);\r
+        Variable = getResourceOrNull(graph, URIs.Variable);\r
+        VariableElement = getResourceOrNull(graph, URIs.VariableElement);\r
+    }\r
+    \r
+    public static SysdynResource getInstance(ReadGraph graph) {\r
+        Session session = graph.getSession();\r
+        SysdynResource ret = session.getService(SysdynResource.class);\r
+        if(ret == null) {\r
+            ret = new SysdynResource(graph);\r
+            session.registerService(SysdynResource.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+}\r
+\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableClassFactory.java
new file mode 100644 (file)
index 0000000..e45047f
--- /dev/null
@@ -0,0 +1,46 @@
+package org.simantics.sysdyn.ui.adapters;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.ElementQuerySupport;\r
+import org.simantics.diagram.adapter.GraphElementClassFactory;\r
+import org.simantics.diagram.adapter.GraphElementFactory;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.impl.Element;\r
+import org.simantics.sysdyn.ui.SysdynResource;\r
+import org.simantics.sysdyn.ui.diagram.DrawableElementClass;\r
+import org.simantics.sysdyn.ui.elements.TestDrawable;\r
+\r
+public class VariableClassFactory implements GraphElementFactory, GraphElementClassFactory {\r
+\r
+       @Override\r
+       public IElement spawn(ReadGraph g, Resource resource,\r
+                       ElementQuerySupport support, IDiagram diagram)\r
+                       throws DatabaseException {\r
+               SysdynResource sr = SysdynResource.getInstance(g);\r
+               \r
+               ElementClass elementClass = \r
+                       DrawableElementClass.createElementClass(sr.VariableElement);\r
+               IElement element = Element.spawnNew(elementClass);\r
+                       \r
+               TestDrawable drawable = new TestDrawable();\r
+               drawable.moveTo(\r
+                               (Double)g.getRelatedValue(resource, sr.HasX),\r
+                               (Double)g.getRelatedValue(resource, sr.HasY)\r
+                               );\r
+               element.setHint(DrawableElementClass.KEY_CONTENT, drawable);\r
+               \r
+               //diagram.addElement(element);\r
+               return element;\r
+       }\r
+\r
+       @Override\r
+       public ElementClass create(ReadGraph g, Resource elementType,\r
+                       ElementQuerySupport support) throws DatabaseException {\r
+               return DrawableElementClass.createElementClass(elementType);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/adapters/VariableElementWriter.java
new file mode 100644 (file)
index 0000000..a671b6b
--- /dev/null
@@ -0,0 +1,23 @@
+package org.simantics.sysdyn.ui.adapters;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.synchronization.graph.ElementWriter;\r
+import org.simantics.g2d.element.IElement;\r
+\r
+public class VariableElementWriter implements ElementWriter {\r
+\r
+       @Override\r
+       public void addToGraph(WriteGraph graph, IElement element,\r
+                       Resource elementResource) throws DatabaseException {\r
+               System.out.println("addToGraph");               \r
+       }\r
+\r
+       @Override\r
+       public void removeFromGraph(WriteGraph graph, Resource elementResource)\r
+                       throws DatabaseException {\r
+               System.out.println("removeFromGraph");          \r
+       }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DiagramEditorFacade.java
new file mode 100644 (file)
index 0000000..daf3582
--- /dev/null
@@ -0,0 +1,124 @@
+package org.simantics.sysdyn.ui.diagram;\r
+\r
+import java.awt.Color;\r
+\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.GraphToDiagramSynchronizer;\r
+import org.simantics.diagram.adapter.IDiagramLoader;\r
+import org.simantics.diagram.participant.SGFocusParticipant;\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.canvas.impl.CanvasContext;\r
+import org.simantics.g2d.chassis.SWTChassis;\r
+import org.simantics.g2d.diagram.DiagramHints;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.diagram.participant.CanvasBoundsParticipant;\r
+import org.simantics.g2d.diagram.participant.DiagramParticipant;\r
+import org.simantics.g2d.diagram.participant.ElementInteractor;\r
+import org.simantics.g2d.diagram.participant.ElementPainter;\r
+import org.simantics.g2d.diagram.participant.Selection;\r
+import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
+import org.simantics.g2d.element.ElementClassProviders;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.impl.Element;\r
+import org.simantics.g2d.participant.CanvasGrab;\r
+import org.simantics.g2d.participant.KeyUtil;\r
+import org.simantics.g2d.participant.MousePanZoomInteractor;\r
+import org.simantics.g2d.participant.MouseUtil;\r
+import org.simantics.g2d.participant.Notifications;\r
+import org.simantics.g2d.participant.PanZoomRotateHandler;\r
+import org.simantics.g2d.participant.PointerPainter;\r
+import org.simantics.g2d.participant.RulerPainter;\r
+import org.simantics.g2d.participant.SGTransformUtil;\r
+import org.simantics.g2d.snap.GridSnapAdvisor;\r
+import org.simantics.layer0.utils.ResourceArray;\r
+import org.simantics.sysdyn.ui.elements.IDrawable;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.workbench.ResourceEditorPart;\r
+import org.simantics.utils.datastructures.hints.IHintContext;\r
+import org.simantics.utils.threads.AWTThread;\r
+\r
+public abstract class DiagramEditorFacade extends ResourceEditorPart {\r
+\r
+       SWTChassis chassis;\r
+       IDiagram diagram;\r
+       IDiagramLoader loader;\r
+       \r
+       public DiagramEditorFacade() {\r
+               super();                \r
+       }\r
+       \r
+       @Override\r
+       public void reload(ReadGraph g) throws DatabaseException {\r
+               // TODO Auto-generated method stub              \r
+       }\r
+               \r
+       @Override\r
+       public void createPartControl(Composite parent) {\r
+               chassis = new SWTChassis(parent, SWT.NONE);\r
+               chassis.syncPopulate(); \r
+               \r
+               final ICanvasContext context = new CanvasContext(\r
+                               AWTThread.getThreadAccess());\r
+               chassis.setCanvasContext(context);\r
+\r
+               context.add(new SGTransformUtil());\r
+               context.add(new MouseUtil());\r
+               context.add(new KeyUtil());\r
+               context.add(new PanZoomRotateHandler());\r
+               context.add(new MousePanZoomInteractor());\r
+               context.add(new RulerPainter());\r
+               context.add(new CanvasGrab());\r
+               context.add(new CanvasBoundsParticipant());\r
+               context.add(new Notifications());\r
+               context.add(new SGFocusParticipant(chassis));   \r
+               context.add(new DiagramParticipant());\r
+               context.add(new ElementPainter());\r
+               context.add(new PointerInteractor(true, true, true, false, true, false, null));\r
+               context.add(new ElementInteractor());\r
+               context.add(new Selection());        \r
+               \r
+               IHintContext h = context.getDefaultHintContext();               \r
+               h.setHint(PointerPainter.KEY_PAINT_POINTER, true);              \r
+               \r
+               h.setHint(ElementPainter.KEY_SELECTION_FRAME_COLOR, Color.MAGENTA);\r
+        h.setHint(Hints.KEY_TOOL, Hints.POINTERTOOL);\r
+\r
+        h.setHint(PanZoomRotateHandler.KEY_ZOOM_IN_LIMIT, 100000.0);\r
+        h.setHint(PanZoomRotateHandler.KEY_ZOOM_OUT_LIMIT, 10.0);\r
+\r
+        h.setHint(DiagramHints.SNAP_ADVISOR,\r
+                       new GridSnapAdvisor(10.0));\r
+        \r
+        try {\r
+                       SimanticsUI.getSession().syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       loader = new GraphToDiagramSynchronizer(graph, context, \r
+                                                       ElementClassProviders.staticProvider(null));\r
+                                       \r
+                                       diagram = loader.loadDiagram(graph,\r
+                                                       getResourceInput().getResource(),\r
+                                                       ResourceArray.EMPTY, \r
+                                                       null);                                  \r
+                               }\r
+                               \r
+                       });\r
+                       h.setHint(DiagramHints.KEY_DIAGRAM, diagram);\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }               \r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void setFocus() {\r
+               chassis.setFocus();             \r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/DrawableElementClass.java
new file mode 100644 (file)
index 0000000..2851dcc
--- /dev/null
@@ -0,0 +1,137 @@
+package org.simantics.sysdyn.ui.diagram;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.diagram.adapter.handler.ResourceAdapter;\r
+import org.simantics.g2d.diagram.handler.PickRequest.PickPolicy;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.element.handler.Move;\r
+import org.simantics.g2d.element.handler.Outline;\r
+import org.simantics.g2d.element.handler.Pick2;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.Transform;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.sysdyn.ui.elements.IDrawable;\r
+import org.simantics.sysdyn.ui.elements.ITransformable;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+public class DrawableElementClass {\r
+       private DrawableElementClass() {}\r
+       \r
+       public static KeyOf KEY_CONTENT = new KeyOf(IDrawable.class, "CONTENT");\r
+       public static AffineTransform IDENTITY_TRANSFORM = new AffineTransform();\r
+               \r
+       public static WidgetHandler WIDGET_HANDLER_INSTANCE = new WidgetHandler();\r
+       \r
+       private static class WidgetHandler implements Transform, SceneGraph, InternalSize, Move, Outline, Pick2 {\r
+\r
+               private static final long serialVersionUID = 1722978969083481038L;\r
+               \r
+               @Override\r
+               public void setTransform(IElement e, AffineTransform at) {\r
+                       IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT);\r
+                       if(drawable instanceof ITransformable) {\r
+                               drawable = ((ITransformable)drawable).setTransform(at);\r
+                               e.setHint(KEY_CONTENT, drawable);\r
+                               drawable.updateSG();\r
+                       }\r
+               }\r
+               \r
+               @Override\r
+               public AffineTransform getTransform(IElement e) {\r
+                       IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT);\r
+                       if(drawable instanceof ITransformable)\r
+                               return ((ITransformable)drawable).getTransform();       \r
+                       else\r
+                               return IDENTITY_TRANSFORM;\r
+               }\r
+               \r
+               @Override\r
+               public void cleanup(IElement e) {\r
+                       ((IDrawable)e.getHint(KEY_CONTENT)).cleanupSG();        \r
+               }\r
+\r
+               @Override\r
+               public void init(IElement e, G2DParentNode parent) {\r
+                       ((IDrawable)e.getHint(KEY_CONTENT)).initSG(parent);\r
+               }\r
+               \r
+               @Override\r
+               public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+                       if(size == null)\r
+                               size = new Rectangle2D.Double();\r
+                       ((IDrawable)e.getHint(KEY_CONTENT)).getBounds(size);\r
+                       return size;\r
+               }\r
+\r
+               @Override\r
+               public Point2D getPosition(IElement e) {\r
+                       IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT);\r
+                       if(drawable instanceof ITransformable)\r
+                               return ((ITransformable)drawable).getPosition();        \r
+                       else\r
+                               return new Point2D.Double(0.0, 0.0);\r
+               }\r
+\r
+               @Override\r
+               public void moveTo(IElement e, double x, double y) {\r
+                       IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT);\r
+                       if(drawable instanceof ITransformable) {\r
+                               drawable = ((ITransformable)drawable).moveTo(x, y);\r
+                               e.setHint(KEY_CONTENT, drawable);\r
+                               drawable.updateSG();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public Shape getElementShape(IElement e) {\r
+                       return getBounds(e, null);\r
+               }\r
+               \r
+               @Override\r
+               public int pick(IElement e, Shape s, PickPolicy policy,\r
+                               Collection<IElement> result) {\r
+                       if(pickTest(e, s, policy)) {\r
+                               result.add(e);\r
+                               return 1;\r
+                       }\r
+                       else\r
+                               return 0;                       \r
+               }\r
+\r
+               @Override\r
+               public boolean pickTest(IElement e, Shape s, PickPolicy policy) {\r
+                       IDrawable drawable = (IDrawable)e.getHint(KEY_CONTENT);\r
+                       switch(policy) {\r
+                       case PICK_CONTAINED_OBJECTS:\r
+                               return drawable.pickContained(s);\r
+                       case PICK_INTERSECTING_OBJECTS:\r
+                               return drawable.pickIntersecting(s);\r
+                       default:\r
+                               return false;\r
+                       }                       \r
+               }\r
+               \r
+       }\r
+\r
+       public static ElementClass createElementClass(final Resource resource) { \r
+               return ElementClass.compile(\r
+                       WIDGET_HANDLER_INSTANCE,\r
+                       new ResourceAdapter() {\r
+\r
+                               @Override\r
+                               public Resource getResource() {\r
+                                       return resource;\r
+                               }\r
+                               \r
+                       }\r
+               );\r
+       }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/diagram/SysdynDiagramEditor.java
new file mode 100644 (file)
index 0000000..614a437
--- /dev/null
@@ -0,0 +1,12 @@
+package org.simantics.sysdyn.ui.diagram;\r
+\r
+import org.simantics.sysdyn.ui.elements.TestDrawable;\r
+\r
+\r
+public class SysdynDiagramEditor extends DiagramEditorFacade {\r
+\r
+       public SysdynDiagramEditor() {\r
+               super();\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Drawable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/Drawable.java
new file mode 100644 (file)
index 0000000..90ab9cd
--- /dev/null
@@ -0,0 +1,34 @@
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+\r
+public abstract class Drawable implements IDrawable {\r
+\r
+       public static final AffineTransform IDENTITY = new AffineTransform();\r
+               \r
+       @Override\r
+       public void initSG(G2DParentNode parent) {\r
+       }\r
+       \r
+       @Override\r
+       public void cleanupSG() {\r
+       }\r
+\r
+       @Override\r
+       public void updateSG() {                \r
+       }\r
+\r
+       @Override\r
+       public boolean pickContained(Shape s) {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public boolean pickIntersecting(Shape s) {\r
+               return false;\r
+       }       \r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/IDrawable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/IDrawable.java
new file mode 100644 (file)
index 0000000..d48a3c9
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+\r
+public interface IDrawable {\r
+       void getBounds(Rectangle2D size);\r
+       void initSG(G2DParentNode parent);\r
+       void updateSG();\r
+       void cleanupSG();\r
+       boolean pickIntersecting(Shape s);\r
+       boolean pickContained(Shape s);\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ITransformable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ITransformable.java
new file mode 100644 (file)
index 0000000..266b8b5
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+\r
+public interface ITransformable extends IDrawable {\r
+       ITransformable setTransform(AffineTransform at);\r
+       AffineTransform getTransform(); \r
+       public ITransformable moveTo(double x, double y);\r
+       Point2D getPosition();\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/PositionableDrawable.java
new file mode 100644 (file)
index 0000000..58d697e
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Point2D;\r
+\r
+public abstract class PositionableDrawable extends Drawable implements ITransformable, Cloneable {\r
+       protected double posX;\r
+       protected double posY;\r
+       \r
+       @Override\r
+       public Point2D getPosition() {\r
+               return new Point2D.Double(posX, posY);\r
+       }\r
+       @Override\r
+       public AffineTransform getTransform() {\r
+               return new AffineTransform(1.0, 0.0, 0.0, 1.0, posX, posY);\r
+       }\r
+       @Override\r
+       public ITransformable moveTo(double x, double y) {\r
+               try {\r
+                       PositionableDrawable d = (PositionableDrawable)clone();\r
+                       d.posX = x;\r
+                       d.posY = y;\r
+                       return d;\r
+               } catch(CloneNotSupportedException e) {                 \r
+                       throw new Error(e);\r
+               }\r
+       }\r
+       @Override\r
+       public ITransformable setTransform(AffineTransform at) {\r
+               try {\r
+                       PositionableDrawable d = (PositionableDrawable)clone();\r
+                       d.posX = at.getTranslateX();\r
+                       d.posY = at.getTranslateY();\r
+                       return d;\r
+               } catch(CloneNotSupportedException e) {                 \r
+                       throw new Error(e);\r
+               }               \r
+       }\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TestDrawable.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TestDrawable.java
new file mode 100644 (file)
index 0000000..5d35c5e
--- /dev/null
@@ -0,0 +1,36 @@
+package org.simantics.sysdyn.ui.elements;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+\r
+\r
+public class TestDrawable extends PositionableDrawable {\r
+\r
+       @Override\r
+       public void getBounds(Rectangle2D size) {\r
+               size.setFrame(-10.0, -10.0, 20.0, 20.0);\r
+       }\r
+       \r
+       ShapeNode node;\r
+       \r
+       @Override\r
+       public void initSG(G2DParentNode parent) {\r
+               node = parent.addNode(ShapeNode.class);\r
+               node.setShape(new Rectangle2D.Double(-10.0, -10.0, 20.0, 20.0));\r
+       }               \r
+       \r
+       @Override\r
+       public boolean pickContained(Shape s) {\r
+               return s.contains(-10.0, -10.0, 20.0, 20.0);\r
+       }\r
+       \r
+       @Override\r
+       public boolean pickIntersecting(Shape s) {\r
+               return s.intersects(-10.0, -10.0, 20.0, 20.0);\r
+       }\r
+       \r
+}\r