]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Interim commit for sysdyn, cloud symbol added.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 21 Jun 2010 10:02:31 +0000 (10:02 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 21 Jun 2010 10:02:31 +0000 (10:02 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16253 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/adapters.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynProject.java
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
sysdyn_ontologies/sysdyn.graph

index 582a8283c72ff14c7a3fb925f7584bb3fab8e71d..863bfe886212bcda32571264dc9989f785dda049 100644 (file)
@@ -25,5 +25,5 @@
                        <graph />\r
                        <this />\r
                </type>\r
-       </target>\r      \r       <target\r                interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r                  class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r                    <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r                 class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r        </target>\r      \r       <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r\r         <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r  </target>\r      \r
+       </target>\r      \r       <target\r                interface="org.simantics.sysdyn.ui.browser.nodes.AbstractNode">\r                <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/SysdynModel"\r                  class="org.simantics.sysdyn.ui.browser.nodes.ModelNode">\r                       <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/IndependentVariable"\r                  class="org.simantics.sysdyn.ui.browser.nodes.VariableNode">\r                    <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Simulation-1.0/Types/Experiment"\r                 class="org.simantics.sysdyn.ui.browser.nodes.ExperimentNode">\r                  <this />\r               </type>\r                \r               <type\r                  uri="http://www.simantics.org/Sysdyn-1.0/Result"\r                       class="org.simantics.sysdyn.ui.browser.nodes.SimulationResultNode">\r                    <this />\r               </type>\r        </target>\r\r     <target interface="org.simantics.diagram.adapter.ElementFactory">\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <resource uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r                    class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <resource uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r                        class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r\r             <type uri="http://www.simantics.org/Sysdyn-1.0/StockSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.StockFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-1.0/ValveSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.ValveFactory" />\r              <type uri="http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"\r                        class="org.simantics.sysdyn.ui.elements2.AuxiliaryFactory" />\r          <type uri="http://www.simantics.org/Sysdyn-1.0/CloudSymbol"\r                    class="org.simantics.sysdyn.ui.elements2.CloudFactory" />\r      </target>\r      \r
 </adapters>
\ No newline at end of file
index b46b3274a9632b1c6581be89bc9ef41f286b3f3c..72a5f8e66334da419d74b4d023534626cbf0e641 100644 (file)
@@ -12,8 +12,6 @@ import org.simantics.diagram.synchronization.IModifiableSynchronizationContext;
 import org.simantics.g2d.canvas.ICanvasContext;\r
 import org.simantics.g2d.canvas.impl.CanvasContext;\r
 import org.simantics.g2d.diagram.participant.DeleteHandler;\r
-import org.simantics.modeling.ui.diagramEditor.PopulateElementDropParticipant;\r
-import org.simantics.modeling.ui.diagramEditor.PopulateElementMonitorDropParticipant;\r
 import org.simantics.modeling.ui.diagramEditor.handlers.WorkbenchStructuralSelectionProvider2;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;\r
@@ -49,14 +47,6 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
         SysdynResource.getInstance(graph);\r
     }\r
 \r
-    @Override\r
-    protected void addDropParticipants(ICanvasContext ctx) {\r
-        // FIXME This is a workaround so that this participant can be disabled\r
-        // for SymbolViewer\r
-        ctx.add(new PopulateElementDropParticipant(synchronizer));\r
-        ctx.add(new PopulateElementMonitorDropParticipant(synchronizer, 0.15, 0.15));\r
-    }\r
-\r
     @Override\r
     protected void addStructureParticipants(ICanvasContext ctx) {\r
         structuralPath = getResourceInput().getResourceArray().removeFromBeginning(1);\r
index 09f3595a751516c088a79bad266c662ca2d950b5..ef91c80a6cca772645249cdb1fc806f434da3c58 100644 (file)
 package org.simantics.sysdyn.ui.elements2;\r
 \r
 import java.awt.BasicStroke;\r
-import java.awt.geom.AffineTransform;\r
 import java.awt.geom.Ellipse2D;\r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
-import java.util.Collections;\r
 \r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
 import org.simantics.diagram.elements.TextElementHandler;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
 import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
@@ -52,68 +31,17 @@ import org.simantics.g2d.element.handler.impl.TextFontImpl;
 import org.simantics.g2d.element.handler.impl.TextImpl;\r
 import org.simantics.g2d.image.Image;\r
 import org.simantics.g2d.image.impl.ShapeImage;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
 \r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class AuxiliaryFactory extends SysdynElementFactory {\r
 \r
-public class AuxiliaryFactory extends SyncElementFactory {\r
-\r
-    public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
-            ComponentNameSynchronizer.INSTANCE,\r
-            TransformSynchronizer.INSTANCE);\r
-\r
-    @Override\r
-    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
-        Builtins b = graph.getBuiltins();\r
-        G2DResource g2d = G2DResource.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-        ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
-        Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
-        String text = null;\r
-        if (component != null) {\r
-            text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
-        }\r
-        if (text == null)\r
-            text = "[empty]";\r
-\r
-        ElementUtils.setText(e, text);\r
-\r
-        if (graph.isInstanceOf(element, dr.FontProvider)) {\r
-            Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
-            if (fontResource != null)\r
-                ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
-        }\r
-        if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
-            Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
-            if (colorResource != null)\r
-                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
-        }\r
-\r
-        AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
-        ElementUtils.setTransform(e, at);\r
-\r
-        // This synchronizes only text and transformation (not font and color)\r
-        e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
-    }\r
+    // TODO: make the static symbol image a text "AUX"\r
+    private static final Image AUX_STATIC_IMAGE = new ShapeImage(new Ellipse2D.Double(-5, -2, 10, 4), null, new BasicStroke(0.1f), true);\r
 \r
     @Override\r
-    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
-    throws DatabaseException {\r
-        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
-        Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
-        Collection<Resource> definedBy = Collections.emptyList();\r
-        if (definedByList != null)\r
-            definedBy = OrderedSetUtils.toList(graph, definedByList);\r
-        Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
-        for (Resource r : definedBy) {\r
-            if (graph.isInstanceOf(r, dr.Terminal)) {\r
-                terminals.add(new ResourceTerminal(r));\r
-            }\r
-        }\r
-\r
+    protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
         return ElementClass.compile(\r
                 SimpleElementLayers.INSTANCE,\r
                 OutlinePick.INSTANCE,\r
@@ -130,7 +58,4 @@ public class AuxiliaryFactory extends SyncElementFactory {
         ).setId(AuxiliaryFactory.class.getSimpleName());\r
     }\r
 \r
-    // TODO: make the static symbol image a text "AUX"\r
-    private static final Image AUX_STATIC_IMAGE = new ShapeImage(new Ellipse2D.Double(-5, -2, 10, 4), null, new BasicStroke(0.1f), true);\r
-\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/CloudFactory.java
new file mode 100644 (file)
index 0000000..93c9c5b
--- /dev/null
@@ -0,0 +1,127 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Shape;\r
+import java.awt.geom.Path2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
+import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
+import org.simantics.g2d.element.handler.impl.OutlinePick;\r
+import org.simantics.g2d.element.handler.impl.SimpleElementLayers;\r
+import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImageInitializer;\r
+import org.simantics.g2d.element.handler.impl.StaticSymbolImpl;\r
+import org.simantics.g2d.element.handler.impl.TextColorImpl;\r
+import org.simantics.g2d.element.handler.impl.TextFontImpl;\r
+import org.simantics.g2d.element.handler.impl.TextImpl;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.g2d.image.impl.ShapeImage;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+public class CloudFactory extends SysdynElementFactory {\r
+\r
+    public static final double       CLOUD_SIZE_X  = 5.0;\r
+    public static final double       CLOUD_SIZE_Y  = 3.0;\r
+    public static final double       CLOUD_CURVES  = 7;\r
+\r
+    private static final BasicStroke    STROKE           = new BasicStroke(1f);\r
+    private static final Image       DEFAULT_IMAGE = new ShapeImage(getCloudShape(), null, STROKE, true);\r
+\r
+    static Shape getCloudShape() {\r
+        Path2D path = new Path2D.Double();\r
+        double ox = CLOUD_SIZE_X;\r
+        double oy = 0.0;\r
+        double posX = 0;\r
+        double posY = 0;\r
+        path.moveTo(posX + ox, posY + oy);\r
+        for (int i = 1; i < CLOUD_CURVES + 1; ++i) {\r
+            double angle = (Math.PI * 2.0 / CLOUD_CURVES) * i;\r
+            double x = Math.cos(angle) * CLOUD_SIZE_X;\r
+            double y = Math.sin(angle) * CLOUD_SIZE_Y;\r
+            path.curveTo(\r
+                    posX + (2*ox + x)*0.5, posY + (2*oy + y)*0.5,\r
+                    posX + (ox + 2*x)*0.5, posY + (oy + 2*y)*0.5,\r
+                    posX + x, posY + y);\r
+            ox = x;\r
+            oy = y;\r
+        }\r
+        return path;\r
+    }\r
+\r
+    @Override\r
+    protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
+        return ElementClass.compile(\r
+                SimpleElementLayers.INSTANCE,\r
+                OutlinePick.INSTANCE,\r
+                TextImpl.INSTANCE,\r
+                TextColorImpl.BLACK,\r
+                TextFontImpl.DEFAULT,\r
+                DefaultTransform.INSTANCE,\r
+                new StaticObjectAdapter(elementType),\r
+                new StaticSymbolImpl(DEFAULT_IMAGE),\r
+                StaticSymbolImageInitializer.INSTANCE,\r
+                CloudSceneGraph.INSTANCE,\r
+                BoundsOutline.INSTANCE,\r
+                new WholeElementTerminals(terminals)\r
+        ).setId(CloudFactory.class.getSimpleName());\r
+    }\r
+\r
+\r
+    public static class CloudSceneGraph implements SceneGraph, InternalSize {\r
+\r
+        private static final long           serialVersionUID = 5544256245734478634L;\r
+\r
+        public static final CloudSceneGraph INSTANCE         = new CloudSceneGraph();\r
+\r
+        private static final Key            NODE             = new SceneGraphNodeKey(ShapeNode.class, "VALVE_NODE");\r
+\r
+        @Override\r
+        public void init(IElement e, G2DParentNode parent) {\r
+            ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
+\r
+            node.setStroke(STROKE);\r
+            node.setScaleStroke(true);\r
+            node.setColor(Color.BLACK);\r
+            node.setShape(getCloudShape());\r
+        }\r
+\r
+        @Override\r
+        public void cleanup(IElement e) {\r
+            ElementUtils.removePossibleNode(e, NODE);\r
+        }\r
+\r
+        @Override\r
+        public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+            if (size == null)\r
+                size = new Rectangle2D.Double();\r
+            size.setFrame(getCloudShape().getBounds2D());\r
+            return size;\r
+        }\r
+\r
+    }\r
+\r
+}\r
index 98f9ae1d56fc575a924103732262f9596df33632..4f2e490573a5c72004c19ac980d8dd3fe98638d0 100644 (file)
 package org.simantics.sysdyn.ui.elements2;\r
 \r
 import java.awt.BasicStroke;\r
-import java.awt.geom.AffineTransform;\r
 import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
-import java.util.Collections;\r
 \r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
 import org.simantics.diagram.elements.TextElementHandler;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.ElementUtils;\r
-import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
 import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
@@ -52,67 +31,14 @@ import org.simantics.g2d.element.handler.impl.TextFontImpl;
 import org.simantics.g2d.element.handler.impl.TextImpl;\r
 import org.simantics.g2d.image.Image;\r
 import org.simantics.g2d.image.impl.ShapeImage;\r
-import org.simantics.modeling.ModelingResources;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
 \r
-public class StockFactory extends SyncElementFactory {\r
+public class StockFactory extends SysdynElementFactory {\r
 \r
-    public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
-            ComponentNameSynchronizer.INSTANCE,\r
-            TransformSynchronizer.INSTANCE);\r
+    private static final BasicStroke    STROKE           = new BasicStroke(1f);\r
+    private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, STROKE, true);\r
 \r
     @Override\r
-    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
-        Builtins b = graph.getBuiltins();\r
-        G2DResource g2d = G2DResource.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-        ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
-        Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
-        String text = null;\r
-        if (component != null) {\r
-            text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
-        }\r
-        if (text == null)\r
-            text = "[empty]";\r
-\r
-        ElementUtils.setText(e, text);\r
-\r
-        if (graph.isInstanceOf(element, dr.FontProvider)) {\r
-            Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
-            if (fontResource != null)\r
-                ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
-        }\r
-        if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
-            Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
-            if (colorResource != null)\r
-                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
-        }\r
-\r
-        AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
-        ElementUtils.setTransform(e, at);\r
-\r
-        // This synchronizes only text and transformation (not font and color)\r
-        e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
-    }\r
-\r
-    @Override\r
-    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
-    throws DatabaseException {\r
-        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
-        Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
-        Collection<Resource> definedBy = Collections.emptyList();\r
-        if (definedByList != null)\r
-            definedBy = OrderedSetUtils.toList(graph, definedByList);\r
-        Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
-        for (Resource r : definedBy) {\r
-            if (graph.isInstanceOf(r, dr.Terminal)) {\r
-                terminals.add(new ResourceTerminal(r));\r
-            }\r
-        }\r
-\r
+    protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
         return ElementClass.compile(\r
                 SimpleElementLayers.INSTANCE,\r
                 OutlinePick.INSTANCE,\r
@@ -130,6 +56,4 @@ public class StockFactory extends SyncElementFactory {
         ).setId(StockFactory.class.getSimpleName());\r
     }\r
 \r
-    private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2.5, 10, 5), null, new BasicStroke(0.1f), Image.VECTOR);\r
-\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementFactory.java
new file mode 100644 (file)
index 0000000..c3aad14
--- /dev/null
@@ -0,0 +1,117 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.geom.AffineTransform;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.G2DUtils;\r
+import org.simantics.diagram.adapter.SyncElementFactory;\r
+import org.simantics.diagram.content.ResourceTerminal;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
+import org.simantics.diagram.synchronization.IHintSynchronizer;\r
+import org.simantics.diagram.synchronization.SynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
+import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
+import org.simantics.g2d.canvas.ICanvasContext;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementClass;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+\r
+/**\r
+ * An ElementFactory that gathers common functionality for system dynamics symbols.\r
+ * Just implement {@link #compileElementClass(Resource, Collection)} to add a symbol.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ */\r
+public abstract class SysdynElementFactory extends SyncElementFactory {\r
+\r
+    public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
+            ComponentNameSynchronizer.INSTANCE,\r
+            TransformSynchronizer.INSTANCE);\r
+\r
+    @Override\r
+    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+        Builtins b = graph.getBuiltins();\r
+        G2DResource g2d = G2DResource.getInstance(graph);\r
+        DiagramResource dr = DiagramResource.getInstance(graph);\r
+        ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+        Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
+        String text = null;\r
+        if (component != null) {\r
+            text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
+        }\r
+        if (text == null)\r
+            text = "[empty]";\r
+\r
+        ElementUtils.setText(e, text);\r
+\r
+        if (graph.isInstanceOf(element, dr.FontProvider)) {\r
+            Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
+            if (fontResource != null)\r
+                ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
+        }\r
+        if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
+            Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
+            if (colorResource != null)\r
+                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
+        }\r
+\r
+        AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
+        ElementUtils.setTransform(e, at);\r
+\r
+        // This synchronizes only text and transformation (not font and color)\r
+        e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
+    }\r
+\r
+    @Override\r
+    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
+    throws DatabaseException {\r
+        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
+        DiagramResource dr = DiagramResource.getInstance(graph);\r
+\r
+        Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
+        Collection<Resource> definedBy = Collections.emptyList();\r
+        if (definedByList != null)\r
+            definedBy = OrderedSetUtils.toList(graph, definedByList);\r
+        Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
+        for (Resource r : definedBy) {\r
+            if (graph.isInstanceOf(r, dr.Terminal)) {\r
+                terminals.add(new ResourceTerminal(r));\r
+            }\r
+        }\r
+\r
+        return compileElementClass(elementType, terminals);\r
+    }\r
+\r
+    /**\r
+     * @param elementType the type of the loaded element\r
+     * @param terminals the terminals of the element type being loaded\r
+     * @return an {@link ElementClass} representing the loaded element type\r
+     */\r
+    protected abstract ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals);\r
+\r
+}\r
index e38a31e2961cc8e7e3af3532fe3ee27c3f5dfe77..030ff8561eb275f67655c89f3f96365776de5bb1 100644 (file)
@@ -13,31 +13,12 @@ package org.simantics.sysdyn.ui.elements2;
 \r
 import java.awt.BasicStroke;\r
 import java.awt.Color;\r
-import java.awt.geom.AffineTransform;\r
 import java.awt.geom.Path2D;\r
 import java.awt.geom.Rectangle2D;\r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
-import java.util.Collections;\r
 \r
-import org.simantics.db.Builtins;\r
-import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.G2DUtils;\r
-import org.simantics.diagram.adapter.SyncElementFactory;\r
-import org.simantics.diagram.content.ResourceTerminal;\r
 import org.simantics.diagram.elements.TextElementNoBounds;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.stubs.G2DResource;\r
-import org.simantics.diagram.synchronization.CompositeHintSynchronizer;\r
-import org.simantics.diagram.synchronization.IHintSynchronizer;\r
-import org.simantics.diagram.synchronization.SynchronizationHints;\r
-import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
-import org.simantics.diagram.synchronization.graph.TransformSynchronizer;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.element.ElementClass;\r
 import org.simantics.g2d.element.ElementUtils;\r
 import org.simantics.g2d.element.IElement;\r
@@ -59,76 +40,28 @@ import org.simantics.g2d.element.handler.impl.TextImpl;
 import org.simantics.g2d.image.Image;\r
 import org.simantics.g2d.image.impl.ShapeImage;\r
 import org.simantics.g2d.utils.Alignment;\r
-import org.simantics.modeling.ModelingResources;\r
 import org.simantics.scenegraph.g2d.G2DParentNode;\r
 import org.simantics.scenegraph.g2d.nodes.ShapeNode;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
 \r
 \r
-public class ValveFactory extends SyncElementFactory {\r
+public class ValveFactory extends SysdynElementFactory {\r
 \r
-    public static final Key KEY_ROTATED = new KeyOf(Boolean.class, "ROTATED");\r
+    public static final Key             KEY_ROTATED        = new KeyOf(Boolean.class, "ROTATED");\r
 \r
-    public static final double VALVE_SIZE = 2.5;\r
+    public static final double          VALVE_SIZE         = 2.5;\r
 \r
-    public static final IHintSynchronizer SYNCHRONIZER = new CompositeHintSynchronizer(\r
-            ComponentNameSynchronizer.INSTANCE,\r
-            TransformSynchronizer.INSTANCE);\r
+    private static final ElementHandler TEXT_NODE          = new TextElementNoBounds(0, VALVE_SIZE + 2, Alignment.CENTER);\r
 \r
-    @Override\r
-    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
-        Builtins b = graph.getBuiltins();\r
-        G2DResource g2d = G2DResource.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-        ModelingResources mr = ModelingResources.getInstance(graph);\r
-\r
-        Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
-        String text = null;\r
-        if (component != null) {\r
-            text = (String) graph.getPossibleRelatedValue(component, b.HasName);\r
-        }\r
-        if (text == null)\r
-            text = "[empty]";\r
-\r
-        ElementUtils.setText(e, text);\r
-\r
-        if (graph.isInstanceOf(element, dr.FontProvider)) {\r
-            Resource fontResource = graph.getPossibleObject(element, g2d.HasFont);\r
-            if (fontResource != null)\r
-                ElementUtils.setTextFont(e, G2DUtils.getFont(graph, fontResource));\r
-        }\r
-        if (graph.isInstanceOf(element, dr.ColorProvider)) {\r
-            Resource colorResource = graph.getPossibleObject(element, g2d.HasColor);\r
-            if (colorResource != null)\r
-                ElementUtils.setTextColor(e, G2DUtils.getColor(graph, colorResource));\r
-        }\r
-\r
-        AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, element);\r
-        ElementUtils.setTransform(e, at);\r
-\r
-        // This synchronizes only text and transformation (not font and color)\r
-        e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, SYNCHRONIZER);\r
-    }\r
+    private static final BasicStroke    STROKE             = new BasicStroke(1f);\r
+    private static final Image          VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true);\r
 \r
+    /* (non-Javadoc)\r
+     * @see org.simantics.sysdyn.ui.elements2.SysdynElementFactory#compileElementClass(org.simantics.db.Resource, java.util.Collection)\r
+     */\r
     @Override\r
-    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
-    throws DatabaseException {\r
-        StructuralResource2 sr = StructuralResource2.getInstance(graph);\r
-        DiagramResource dr = DiagramResource.getInstance(graph);\r
-\r
-        Resource definedByList = graph.getPossibleObject(elementType, sr.IsDefinedBy);\r
-        Collection<Resource> definedBy = Collections.emptyList();\r
-        if (definedByList != null)\r
-            definedBy = OrderedSetUtils.toList(graph, definedByList);\r
-        Collection<ObjectTerminal> terminals = new ArrayList<ObjectTerminal>(definedBy.size());\r
-        for (Resource r : definedBy) {\r
-            if (graph.isInstanceOf(r, dr.Terminal)) {\r
-                terminals.add(new ResourceTerminal(r));\r
-            }\r
-        }\r
-\r
+    protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
         return ElementClass.compile(\r
                 SimpleElementLayers.INSTANCE,\r
                 OutlinePick.INSTANCE,\r
@@ -146,11 +79,6 @@ public class ValveFactory extends SyncElementFactory {
         ).setId(ValveFactory.class.getSimpleName());\r
     }\r
 \r
-    private static final ElementHandler TEXT_NODE = new TextElementNoBounds(0, VALVE_SIZE+2, Alignment.CENTER);\r
-\r
-    private static final BasicStroke STROKE = new BasicStroke(1f);\r
-    private static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, STROKE, true);\r
-\r
     /**\r
      * @param valveSize\r
      * @param rotated <code>true</code> for vertical valve, <code>false</code>\r
@@ -184,13 +112,11 @@ public class ValveFactory extends SyncElementFactory {
         public void init(IElement e, G2DParentNode parent) {\r
             ShapeNode node = ElementUtils.getOrCreateNode(e, parent, NODE, "valve", ShapeNode.class);\r
 \r
-            System.out.println("shape node : " + node);\r
             // Calculate borders from text node bounds.\r
             node.setStroke(STROKE);\r
             node.setScaleStroke(true);\r
             node.setColor(Color.BLACK);\r
             node.setShape(createShape(VALVE_SIZE, Boolean.TRUE.equals(e.getHint(KEY_ROTATED))));\r
-            System.out.println("shape node after init: " + node);\r
         }\r
 \r
         @Override\r
index 9634c86e2e7803ad97fe984c819b32c7164a10ba..8a4a8a0ce393106f8d500449f7c9b34dd2e4d8d9 100644 (file)
@@ -87,8 +87,11 @@ public class SysdynProject extends AbstractProjectFeature {
                 ModelingUtils mu = new ModelingUtils(g);\r
 \r
                 Resource model = g.newResource();\r
-                g.claimValue(model, b.HasName, "Model1");\r
-                g.claimValue(model, b.HasLabel, "Model1");\r
+\r
+                String modelName = GraphUtils.findFreshName(g, "Model", library, b.ConsistsOf, "%s%d");\r
+\r
+                g.claimValue(model, b.HasName, modelName);\r
+                g.claimValue(model, b.HasLabel, modelName);\r
                 g.claim(model, b.InstanceOf, sr.SysdynModel);\r
                 g.claim(model, b.PartOf, library);\r
 \r
index 0377b37ab5b5dd05f586892efbd4ac6ea921d6d4..b745a584d50049ffe84e2d8fb6edca4be3eb7600 100644 (file)
@@ -24,6 +24,7 @@ public class SysdynResource {
     public final Resource AuxiliarySymbol;\r
     public final Resource BasicExperiment;\r
     public final Resource Cloud;\r
+    public final Resource CloudSymbol;\r
     public final Resource Configuration;\r
     public final Resource ConfigurationDiagram;\r
     public final Resource ConstantExpression;\r
@@ -89,6 +90,7 @@ public class SysdynResource {
         public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
         public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
         public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\r
+        public static final String CloudSymbol = "http://www.simantics.org/Sysdyn-1.0/CloudSymbol";\r
         public static final String Configuration = "http://www.simantics.org/Sysdyn-1.0/Configuration";\r
         public static final String ConfigurationDiagram = "http://www.simantics.org/Sysdyn-1.0/ConfigurationDiagram";\r
         public static final String ConstantExpression = "http://www.simantics.org/Sysdyn-1.0/ConstantExpression";\r
@@ -164,6 +166,7 @@ public class SysdynResource {
         AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
         BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
         Cloud = getResourceOrNull(graph, URIs.Cloud);\r
+        CloudSymbol = getResourceOrNull(graph, URIs.CloudSymbol);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
         ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
         ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
index 01475b73d4b37303067665ac45718ebfd75e2e5b..16f5064066d6c68a57ae5623bf447efeb209b4df 100644 (file)
@@ -353,9 +353,9 @@ ValveSymbol <T DIA.FontProvider <T DIA.ColorProvider
   L0.IsDependencyOf BasicSymbolLibrary\r
   ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
       _ : SysdynTerminal\r
-        terminal(StockSymbol, IsHeadOfTerminal)\r
+        terminal(ValveSymbol, IsHeadOfTerminal)\r
       _ : SysdynTerminal\r
-        terminal(StockSymbol, IsTailOfTerminal)\r
+        terminal(ValveSymbol, IsTailOfTerminal)\r
 \r
 ######################################################################\r
 Auxiliary\r
@@ -368,9 +368,24 @@ AuxiliarySymbol <T DIA.FontProvider <T DIA.ColorProvider
   L0.IsDependencyOf BasicSymbolLibrary\r
   ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
       _ : SysdynTerminal\r
-        terminal(StockSymbol, IsHeadOfTerminal)\r
+        terminal(AuxiliarySymbol, IsHeadOfTerminal)\r
       _ : SysdynTerminal\r
-        terminal(StockSymbol, IsTailOfTerminal)\r
+        terminal(AuxiliarySymbol, IsTailOfTerminal)\r
+\r
+######################################################################\r
+Cloud\r
+  def()\r
+  connection(IsTailOf)\r
+  connection(IsHeadOf)\r
+\r
+CloudSymbol <T DIA.FontProvider <T DIA.ColorProvider\r
+  defSymbol("Cloud", Cloud)\r
+  L0.IsDependencyOf BasicSymbolLibrary\r
+  ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+      _ : SysdynTerminal\r
+        terminal(CloudSymbol, IsHeadOfTerminal)\r
+      _ : SysdynTerminal\r
+        terminal(CloudSymbol, IsTailOfTerminal)\r
 \r
 ######################################################################\r
 # Diagram connection types\r