]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Working on g2d-based system dynamics editing.
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 20:22:53 +0000 (20:22 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 15 Jun 2010 20:22:53 +0000 (20:22 +0000)
Lots of small changes all over, shouldn't break anything.

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16170 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/editor/SymbolsFeature.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java
sysdyn_ontologies/sysdyn.graph

index 4b5529598a7614f442a76c8ef3d3c2561e690753..582a8283c72ff14c7a3fb925f7584bb3fab8e71d 100644 (file)
@@ -16,7 +16,7 @@
                <resource\r
                        uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r
                        class="org.simantics.sysdyn.ui.project.SysdynProject" />\r
-               <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynSymbols"\r                        class="org.simantics.sysdyn.ui.editor.SymbolsFeature" />\r               <resource\r            uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r            class="org.simantics.sysdyn.ui.project.SysdynProject" />\r        </target>\r      \r       <target interface="org.simantics.project.IProjectLifeCycle">\r           <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r                        class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r      </target>\r      \r
+               <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynModelManager"\r                   class="org.simantics.sysdyn.ui.project.SysdynProject" />\r       </target>\r      \r       <target interface="org.simantics.project.IProjectLifeCycle">\r           <resource\r                      uri="http://www.simantics.org/Sysdyn-1.0/SysdynProject"\r                        class="org.simantics.sysdyn.ui.project.SysdynProjectLifeCycle" />\r      </target>\r      \r
        <target\r
                interface="org.simantics.scenegraph.adapters.ISceneGraphProvider">\r
                <type\r
@@ -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>\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
 </adapters>
\ No newline at end of file
index 54e8ba086de7132e6fa39af4fd443c4139993510..b46b3274a9632b1c6581be89bc9ef41f286b3f3c 100644 (file)
@@ -1,5 +1,10 @@
 package org.simantics.sysdyn.ui.editor;\r
 \r
+import java.util.Collections;\r
+import java.util.Set;\r
+\r
+import org.eclipse.ui.IWorkbenchPartSite;\r
+import org.simantics.browsing.ui.swt.IPropertyPage;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.diagram.handler.ConnectionCommandHandler;\r
 import org.simantics.diagram.handler.CopyPasteHandler;\r
@@ -10,18 +15,22 @@ import org.simantics.g2d.diagram.participant.DeleteHandler;
 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
 \r
 /**\r
  * @author Tuukka Lehtonen\r
  */\r
 public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer {\r
 \r
-    @SuppressWarnings("unchecked")\r
     @Override\r
-    public Object getAdapter(Class adapter) {\r
-//        if (adapter == IPropertyPage.class)\r
-//            return new AprosPropertyPage(getSite());\r
-        return super.getAdapter(adapter);\r
+    protected Set<String> getPropertyPageContexts() {\r
+        return Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser");\r
+    }\r
+\r
+    @Override\r
+    protected IPropertyPage createPropertyPage(IWorkbenchPartSite site, Set<String> contexts) {\r
+        return new SysdynPropertyPage(site, contexts);\r
     }\r
 \r
     @Override\r
@@ -35,7 +44,9 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
     @Override\r
     protected void initializeSynchronizationContext(ReadGraph graph, IModifiableSynchronizationContext context) {\r
         super.initializeSynchronizationContext(graph, context);\r
-//        context.set(AprosDiagramSynchronizationHints.APROS_RESOURCE, AprosBuiltins.getInstance(graph));\r
+\r
+        // Make sure SysdynResource is available.\r
+        SysdynResource.getInstance(graph);\r
     }\r
 \r
     @Override\r
@@ -49,11 +60,7 @@ public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.Diagr
     @Override\r
     protected void addStructureParticipants(ICanvasContext ctx) {\r
         structuralPath = getResourceInput().getResourceArray().removeFromBeginning(1);\r
-\r
         ctx.add(new WorkbenchStructuralSelectionProvider2(swt, getSite(), structuralPath));\r
-        // Add visual browsing capabilities for structural models\r
-//        ctx.add(new StructuralBrowsingHandler(getSite(), sessionContext, structuralPath));\r
-//        ctx.add(new LinkBrowsingHandler(getSite(), this, sessionContext));\r
     }\r
 \r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SymbolsFeature.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SymbolsFeature.java
deleted file mode 100644 (file)
index 6f2d1d7..0000000
+++ /dev/null
@@ -1,336 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.ui.editor;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.procedure.adapter.MultiProcedureAdapter;\r
-import org.simantics.db.common.request.ResourceRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.ResourceNotFoundException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.diagram.query.DiagramRequests;\r
-import org.simantics.diagram.stubs.DiagramResource;\r
-import org.simantics.diagram.symbollibrary.ISymbolGroup;\r
-import org.simantics.diagram.symbollibrary.ISymbolItem;\r
-import org.simantics.diagram.symbollibrary.ISymbolManager;\r
-import org.simantics.g2d.element.ElementClass;\r
-import org.simantics.g2d.element.handler.StaticSymbol;\r
-import org.simantics.layer0.utils.direct.GraphUtils;\r
-import org.simantics.layer0.utils.direct.GraphUtils.ResourceTester;\r
-import org.simantics.project.IProject;\r
-import org.simantics.project.exception.ProjectException;\r
-import org.simantics.project.features.AbstractProjectFeature;\r
-import org.simantics.project.features.IGraphProjectFeature;\r
-import org.simantics.utils.datastructures.cache.ProvisionException;\r
-import org.simantics.utils.datastructures.hints.IHintObservable;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- *\r
- * TODO: live tracking of symbol libraries based on selected model, since they can contain their own local symbols\r
- * Currently the code only provides the symbols that are in the ontology\r
- */\r
-public class SymbolsFeature extends AbstractProjectFeature implements IGraphProjectFeature {\r
-\r
-    Collection<ISymbolGroup> symbolGroups = Collections.emptySet();\r
-\r
-    Collection<ISymbolGroup> toSymbolGroups(Resource... rs) {\r
-        Collection<ISymbolGroup> result = new ArrayList<ISymbolGroup>(rs.length);\r
-        for (int i = 0; i < rs.length; ++i) {\r
-            result.add(new SymbolGroup(rs[i]));\r
-        }\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public void configure(ReadGraph g) throws ProjectException {\r
-//        IProject p = getProject();\r
-//        ISymbolManager sm = p.getHint(ISymbolManager.KEY_SYMBOL_MANAGER);\r
-//        if (sm != null) {\r
-//            Collection<Resource> grps;\r
-//            try {\r
-//                grps = g.syncRequest(new GroupDiscoveryQuery(p));\r
-//                AprosSymbolsFeature.this.symbolGroups = toSymbolGroups(grps.toArray(Resource.NONE));\r
-//                sm.addEntryPoints(symbolGroups);\r
-//            } catch (DatabaseException e) {\r
-//                throw new ProjectException(e);\r
-//            }\r
-//        }\r
-    }\r
-\r
-    @Override\r
-    public void deconfigure() throws ProjectException {\r
-        ISymbolManager sm = getProject().getHint(ISymbolManager.KEY_SYMBOL_MANAGER);\r
-        if (sm != null) {\r
-            sm.removeEntryPoints(symbolGroups);\r
-            symbolGroups = Collections.emptySet();\r
-        }\r
-    }\r
-\r
-    public class SymbolGroup implements ISymbolGroup {\r
-        final Resource r;\r
-\r
-        public SymbolGroup(Resource r) {\r
-            this.r = r;\r
-        }\r
-\r
-        @Override\r
-        public ISymbolItem[] getItems() {\r
-            RequestProcessor sgrp = getGraphRequestProcessor();\r
-            IProject project = peekProject();\r
-            if (project == null || sgrp == null)\r
-                return new ISymbolItem[0];\r
-            Collection<Resource> items;\r
-            try {\r
-                items = sgrp.syncRequest(new ElementDiscoveryQuery(r));\r
-                List<ISymbolItem> result = new ArrayList<ISymbolItem>();\r
-                for (Resource r : items) {\r
-                    result.add(new SymbolItem(this, r));\r
-                }\r
-                Collections.sort(result, new Comparator<ISymbolItem>() {\r
-                    @Override\r
-                    public int compare(ISymbolItem o1, ISymbolItem o2) {\r
-                        String n1 = o1.getName();\r
-                        String n2 = o2.getName();\r
-                        return n1.compareTo(n2);\r
-                    }\r
-                });\r
-                return result.toArray(new ISymbolItem[result.size()]);\r
-            } catch (DatabaseException e) {\r
-                throw new RuntimeException(e);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public String getName() {\r
-            try {\r
-                RequestProcessor sgrp = getGraphRequestProcessor();\r
-                IProject project = peekProject();\r
-                if (project == null || sgrp == null)\r
-                    return "(no project)";\r
-                return sgrp.syncRequest(new SafeLabelQuery(r));\r
-            } catch (DatabaseException e) {\r
-                throw new RuntimeException(e);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public String getDescription() {\r
-            return getName();\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            return r.hashCode();\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            SymbolGroup other = (SymbolGroup) obj;\r
-            return r.equals(other.r);\r
-        }\r
-    }\r
-\r
-    public class SymbolItem implements ISymbolItem {\r
-\r
-        final ISymbolGroup group;\r
-        final Resource r;\r
-\r
-        public SymbolItem(ISymbolGroup group, Resource r) {\r
-            this.group = group;\r
-            this.r = r;\r
-        }\r
-\r
-        @Override\r
-        public ISymbolGroup getGroup() {\r
-            return group;\r
-        }\r
-\r
-        @Override\r
-        public ElementClass getElementClass(IHintObservable hints) {\r
-            RequestProcessor sgrp = getGraphRequestProcessor();\r
-            if (sgrp == null)\r
-                throw new ProvisionException("No RequestProcessor available for querying an ElementClass for resource " + r);\r
-            try {\r
-                ElementClass ec = sgrp.syncRequest(DiagramRequests.getElementClass(r, hints));\r
-                if (ec == null)\r
-                    throw new ProvisionException("ElementClass query failed, returned null");\r
-                if (!ec.containsClass(StaticSymbol.class))\r
-                    throw new ProvisionException("ElementClass " + ec + " does not provide a StaticSymbol handler");\r
-                return ec;\r
-            } catch (DatabaseException e) {\r
-                throw new ProvisionException(e);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public String getName() {\r
-            try {\r
-                RequestProcessor sgrp = getGraphRequestProcessor();\r
-                // Return a safe "" if the query cannot be performed.\r
-                return sgrp != null ? sgrp.syncRequest(new SafeLabelQuery(r)) : "";\r
-            } catch (DatabaseException e) {\r
-                throw new RuntimeException(e);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public String getDescription() {\r
-            return getName();\r
-        }\r
-\r
-        @SuppressWarnings("unchecked")\r
-        @Override\r
-        public Object getAdapter(Class adapter) {\r
-            //if (adapter == ElementClass.class)\r
-            //    return getElementClass();\r
-            if (adapter == Resource.class)\r
-                return r;\r
-            return null;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + group.hashCode();\r
-            result = prime * result + r.hashCode();\r
-            return result;\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null)\r
-                return false;\r
-            if (getClass() != obj.getClass())\r
-                return false;\r
-            SymbolItem other = (SymbolItem) obj;\r
-            if (!group.equals(other.group))\r
-                return false;\r
-            return r.equals(other.r);\r
-        }\r
-    }\r
-\r
-    static class SafeLabelQuery extends ResourceRead<String> {\r
-        public SafeLabelQuery(Resource resource) {\r
-            super(resource);\r
-        }\r
-\r
-        @Override\r
-        public String perform(ReadGraph g) throws DatabaseException {\r
-            try {\r
-                return g.adapt(resource, String.class);\r
-            } catch (DatabaseException e) {\r
-                return GraphUtils.getReadableName(g, resource);\r
-            }\r
-        }\r
-    }\r
-\r
-    public static class GroupDiscoveryQuery implements Read<Collection<Resource>> {\r
-\r
-        IProject project;\r
-\r
-        GroupDiscoveryQuery(IProject project) {\r
-            assert project != null;\r
-            this.project = project;\r
-        }\r
-\r
-        @Override\r
-        public Collection<Resource> perform(ReadGraph g) throws DatabaseException {\r
-            try {\r
-                Resource[] eps = new Resource[] {\r
-                        g.getResource("http://www.simantics.org/Sysdyn-1.0/SymbolReferences")\r
-                };\r
-\r
-                final DiagramResource dr = DiagramResource.getInstance(g);\r
-                final ArrayList<Resource> groups = new ArrayList<Resource>();\r
-                for (Resource ep : eps) {\r
-                    GraphUtils.findResources(g, Collections.singletonList(ep), g.getBuiltins().ConsistsOf, new ResourceTester() {\r
-                        @Override\r
-                        public boolean test(ReadGraph g, Resource r) throws DatabaseException {\r
-                            return g.isInstanceOf(r, g.getBuiltins().Library)\r
-                            || g.isInstanceOf(r, dr.SymbolReferenceLibrary);\r
-                        }\r
-                    }, new MultiProcedureAdapter<Resource>() {\r
-                        @Override\r
-                        public void execute(Resource result) {\r
-                            groups.add(result);\r
-                        }\r
-                        @Override\r
-                        public void exception(Throwable t) {\r
-                            new Exception().printStackTrace();\r
-                            t.printStackTrace();\r
-                        }\r
-                    });\r
-                }\r
-                return groups;\r
-\r
-            } catch (ResourceNotFoundException e) {\r
-                throw new RuntimeException(e);\r
-            }\r
-        }\r
-\r
-        @Override\r
-        public boolean equals(Object obj) {\r
-            if (this == obj)\r
-                return true;\r
-            if (obj == null || getClass() != obj.getClass())\r
-                return false;\r
-            GroupDiscoveryQuery other = (GroupDiscoveryQuery) obj;\r
-            if (!project.equals(other.project))\r
-                return false;\r
-            return true;\r
-        }\r
-\r
-        @Override\r
-        public int hashCode() {\r
-            final int prime = 31;\r
-            int result = 1;\r
-            result = prime * result + ((project == null) ? 0 : project.hashCode());\r
-            return result;\r
-        }\r
-    }\r
-\r
-    static public class ElementDiscoveryQuery extends ResourceRead<Collection<Resource>> {\r
-        public ElementDiscoveryQuery(Resource resource) {\r
-            super(resource);\r
-        }\r
-        @Override\r
-        public Collection<Resource> perform(ReadGraph g) throws DatabaseException {\r
-            DiagramResource dr = DiagramResource.getInstance(g);\r
-            Collection<Resource> objs = g.getObjects(resource, g.getBuiltins().DependsOn);\r
-            // Filter out everything besides Elements.\r
-            ArrayList<Resource> result = new ArrayList<Resource>(objs.size());\r
-            for (Resource r : objs) {\r
-                if (g.isInheritedFrom(r, dr.Element))\r
-                    result.add( r );\r
-            }\r
-            return result;\r
-        }\r
-    }\r
-\r
-}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/AuxiliaryFactory.java
new file mode 100644 (file)
index 0000000..d946c88
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************\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.geom.Rectangle2D;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.SyncElementFactory;\r
+import org.simantics.diagram.elements.TextElementHandler;\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.IElement;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\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.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
+\r
+\r
+public class AuxiliaryFactory extends SyncElementFactory {\r
+\r
+    @Override\r
+    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+        // TODO: implement\r
+    }\r
+\r
+    @Override\r
+    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
+    throws DatabaseException {\r
+        String id = "Auxiliary: " + NameUtils.getSafeName(graph, elementType);\r
+        return ElementClass.compile(\r
+                TextImpl.INSTANCE,\r
+                TextColorImpl.BLACK,\r
+                TextFontImpl.DEFAULT,\r
+                new StaticObjectAdapter(elementType),\r
+                DefaultTransform.INSTANCE,\r
+                SimpleElementLayers.INSTANCE,\r
+                TextElementHandler.INSTANCE,\r
+                new StaticSymbolImpl(AUX_STATIC_IMAGE)\r
+        )\r
+        .setId(id)\r
+        ;\r
+    }\r
+\r
+    private static final Image AUX_STATIC_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -2, 10, 4), null, new BasicStroke(1));\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ComponentNameSynchronizer.java
new file mode 100644 (file)
index 0000000..29b118f
--- /dev/null
@@ -0,0 +1,55 @@
+/*******************************************************************************\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 org.simantics.databoard.binding.java.StringJavaBinding;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.diagram.synchronization.IModificationQueue;\r
+import org.simantics.diagram.synchronization.ISynchronizationContext;\r
+import org.simantics.diagram.synchronization.graph.GraphSynchronizationHints;\r
+import org.simantics.diagram.synchronization.graph.RelatedPropertyModification;\r
+import org.simantics.diagram.synchronization.graph.ResourceSynchronizer;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ComponentNameSynchronizer extends ResourceSynchronizer {\r
+\r
+    public static final ComponentNameSynchronizer INSTANCE = new ComponentNameSynchronizer();\r
+\r
+    private static final Key[] SYNCHRONIZED_HINTS = {\r
+        ElementHints.KEY_TEXT\r
+    };\r
+\r
+    @Override\r
+    public Key[] getSynchronizedHints() {\r
+        return SYNCHRONIZED_HINTS;\r
+    }\r
+\r
+    @Override\r
+    public boolean hintChanged(ISynchronizationContext context, IModificationQueue queue, Resource object, IHintObservable sender, Key key, Object oldValue, Object newValue) {\r
+        if (ElementHints.KEY_TEXT.equals(key)) {\r
+            Session session = context.get(GraphSynchronizationHints.SESSION);\r
+            Builtins b = session.getBuiltins();\r
+            ModelingResources mr = session.getService(ModelingResources.class);\r
+            return queue.offer(new RelatedPropertyModification(object, mr.ElementToComponent, b.HasName, b.String, newValue, StringJavaBinding.INSTANCE), null);\r
+        }\r
+        return false;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/StockFactory.java
new file mode 100644 (file)
index 0000000..6c1941c
--- /dev/null
@@ -0,0 +1,172 @@
+/*******************************************************************************\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.Shape;\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.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.Outline;\r
+import org.simantics.g2d.element.handler.SceneGraph;\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.h2d.node.RectangleNode;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+\r
+public class StockFactory 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.isInheritedFrom(r, dr.Terminal)) {\r
+                terminals.add(new ResourceTerminal(r));\r
+            }\r
+        }\r
+\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
+                TextElementHandler.INSTANCE,\r
+                BorderSceneGraph.INSTANCE,\r
+                BoundsOutline.INSTANCE,\r
+                new WholeElementTerminals(terminals)\r
+        ).setId(StockFactory.class.getSimpleName());\r
+    }\r
+\r
+    private static final Image DEFAULT_IMAGE = new ShapeImage(new Rectangle2D.Double(-5, -5, 10, 10), null, new BasicStroke(1.0f), Image.VECTOR);\r
+\r
+    static class BoundsOutline implements Outline {\r
+        public static final BoundsOutline INSTANCE = new BoundsOutline();\r
+        private static final long serialVersionUID = 5544256245734478634L;\r
+        @Override\r
+        public Shape getElementShape(IElement e) {\r
+            return ElementUtils.getElementBounds(e);\r
+        }\r
+    }\r
+\r
+    static class BorderSceneGraph implements SceneGraph, Callback<RectangleNode> {\r
+        public static final BorderSceneGraph INSTANCE = new BorderSceneGraph();\r
+        private static final long serialVersionUID = 5544256245734478634L;\r
+        private static final Key BORDER_NODE = new SceneGraphNodeKey(RectangleNode.class, "BORDER_NODE");\r
+        @Override\r
+        public void init(IElement e, G2DParentNode parent) {\r
+            RectangleNode node = ElementUtils.getOrCreateNode(e, parent, BORDER_NODE, "border", RectangleNode.class, this);\r
+\r
+            // Calculate borders from text node bounds.\r
+            node.init(ElementUtils.getElementBounds(e));\r
+        }\r
+        @Override\r
+        public void run(RectangleNode node) {\r
+            node.setZIndex(-10);\r
+        }\r
+        @Override\r
+        public void cleanup(IElement e) {\r
+            ElementUtils.removePossibleNode(e, BORDER_NODE);\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java
new file mode 100644 (file)
index 0000000..817c57b
--- /dev/null
@@ -0,0 +1,88 @@
+/*******************************************************************************\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.geom.Path2D;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.adapter.SyncElementFactory;\r
+import org.simantics.diagram.elements.TextElementHandler;\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.IElement;\r
+import org.simantics.g2d.element.handler.impl.DefaultTransform;\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.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
+\r
+\r
+public class ValveFactory extends SyncElementFactory {\r
+\r
+    public static final double VALVE_SIZE = 5.0;\r
+\r
+    @Override\r
+    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+        // TODO: implement\r
+    }\r
+\r
+    @Override\r
+    public ElementClass create(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType)\r
+    throws DatabaseException {\r
+        String id = "Valve: " + NameUtils.getSafeName(graph, elementType);\r
+        return ElementClass.compile(\r
+                TextImpl.INSTANCE,\r
+                TextColorImpl.BLACK,\r
+                TextFontImpl.DEFAULT,\r
+                new StaticObjectAdapter(elementType),\r
+                DefaultTransform.INSTANCE,\r
+                SimpleElementLayers.INSTANCE,\r
+                TextElementHandler.INSTANCE,\r
+                new StaticSymbolImpl(VALVE_STATIC_IMAGE)\r
+        )\r
+        .setId(id)\r
+        ;\r
+    }\r
+\r
+    private static final Image VALVE_STATIC_IMAGE = new ShapeImage(createShape(VALVE_SIZE, false), null, new BasicStroke(1));\r
+\r
+    /**\r
+     * @param valveSize\r
+     * @param rotated <code>true</code> for vertical valve, <code>false</code>\r
+     *        for horizontal\r
+     * @return\r
+     */\r
+    private static Path2D createShape(double valveSize, boolean rotated) {\r
+        Path2D path = new Path2D.Double();\r
+        path.moveTo(-valveSize, -valveSize);\r
+        if(rotated) {\r
+            path.lineTo(-valveSize, +valveSize);\r
+            path.lineTo(+valveSize, -valveSize);\r
+        } else {\r
+            path.lineTo(+valveSize, -valveSize);\r
+            path.lineTo(-valveSize, +valveSize);\r
+        }\r
+        path.lineTo(+valveSize, +valveSize);\r
+        path.closePath();\r
+        return path;\r
+    }\r
+\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/WholeElementTerminals.java
new file mode 100644 (file)
index 0000000..46296ae
--- /dev/null
@@ -0,0 +1,29 @@
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import java.awt.Shape;\r
+import java.util.Collection;\r
+\r
+import org.simantics.g2d.diagram.handler.Topology.Terminal;\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.g2d.element.handler.impl.Terminals;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class WholeElementTerminals extends Terminals {\r
+\r
+    private static final long serialVersionUID = -8209833430671135001L;\r
+\r
+    public WholeElementTerminals(Collection<ObjectTerminal> ts) {\r
+        super(ts);\r
+    }\r
+\r
+    @Override\r
+    public Shape getTerminalShape(IElement node, Terminal t) {\r
+        // For each terminal, return the shape of the element.\r
+        return ElementUtils.getElementShapeOrBounds(node);\r
+    }\r
+\r
+}\r
index 3be2eda9527daef26bbff47fac35d4bb34279a0b..c6f7adaa0f87ac13a4c9aaccfb9eac0775acc15f 100644 (file)
@@ -57,12 +57,13 @@ public class SysdynResource {
     public final Resource HasY;\r
     public final Resource IndependentVariable;\r
     public final Resource IsHeadOf;\r
+    public final Resource IsHeadOfTerminal;\r
     public final Resource IsTailOf;\r
+    public final Resource IsTailOfTerminal;\r
     public final Resource LookupExpression;\r
     public final Resource Module;\r
     public final Resource NormalExpression;\r
     public final Resource ParameterExpression;\r
-    public final Resource PhantomTerminal;\r
     public final Resource RefersTo;\r
     public final Resource Result;\r
     public final Resource SimulateOnChangeExperiment;\r
@@ -73,7 +74,7 @@ public class SysdynResource {
     public final Resource SysdynModel;\r
     public final Resource SysdynModelManager;\r
     public final Resource SysdynProject;\r
-    public final Resource SysdynSymbols;\r
+    public final Resource SysdynTerminal;\r
     public final Resource Terminal;\r
     public final Resource Valve;\r
     public final Resource ValveSymbol;\r
@@ -118,12 +119,13 @@ public class SysdynResource {
         public static final String HasY = "http://www.simantics.org/Sysdyn-1.0/HasY";\r
         public static final String IndependentVariable = "http://www.simantics.org/Sysdyn-1.0/IndependentVariable";\r
         public static final String IsHeadOf = "http://www.simantics.org/Sysdyn-1.0/IsHeadOf";\r
+        public static final String IsHeadOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsHeadOfTerminal";\r
         public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf";\r
+        public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal";\r
         public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression";\r
         public static final String Module = "http://www.simantics.org/Sysdyn-1.0/Module";\r
         public static final String NormalExpression = "http://www.simantics.org/Sysdyn-1.0/NormalExpression";\r
         public static final String ParameterExpression = "http://www.simantics.org/Sysdyn-1.0/ParameterExpression";\r
-        public static final String PhantomTerminal = "http://www.simantics.org/Sysdyn-1.0/PhantomTerminal";\r
         public static final String RefersTo = "http://www.simantics.org/Sysdyn-1.0/RefersTo";\r
         public static final String Result = "http://www.simantics.org/Sysdyn-1.0/Result";\r
         public static final String SimulateOnChangeExperiment = "http://www.simantics.org/Sysdyn-1.0/SimulateOnChangeExperiment";\r
@@ -134,7 +136,7 @@ public class SysdynResource {
         public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.0/SysdynModel";\r
         public static final String SysdynModelManager = "http://www.simantics.org/Sysdyn-1.0/SysdynModelManager";\r
         public static final String SysdynProject = "http://www.simantics.org/Sysdyn-1.0/SysdynProject";\r
-        public static final String SysdynSymbols = "http://www.simantics.org/Sysdyn-1.0/SysdynSymbols";\r
+        public static final String SysdynTerminal = "http://www.simantics.org/Sysdyn-1.0/SysdynTerminal";\r
         public static final String Terminal = "http://www.simantics.org/Sysdyn-1.0/Terminal";\r
         public static final String Valve = "http://www.simantics.org/Sysdyn-1.0/Valve";\r
         public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.0/ValveSymbol";\r
@@ -189,12 +191,13 @@ public class SysdynResource {
         HasY = getResourceOrNull(graph, URIs.HasY);\r
         IndependentVariable = getResourceOrNull(graph, URIs.IndependentVariable);\r
         IsHeadOf = getResourceOrNull(graph, URIs.IsHeadOf);\r
+        IsHeadOfTerminal = getResourceOrNull(graph, URIs.IsHeadOfTerminal);\r
         IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
+        IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
         LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
         Module = getResourceOrNull(graph, URIs.Module);\r
         NormalExpression = getResourceOrNull(graph, URIs.NormalExpression);\r
         ParameterExpression = getResourceOrNull(graph, URIs.ParameterExpression);\r
-        PhantomTerminal = getResourceOrNull(graph, URIs.PhantomTerminal);\r
         RefersTo = getResourceOrNull(graph, URIs.RefersTo);\r
         Result = getResourceOrNull(graph, URIs.Result);\r
         SimulateOnChangeExperiment = getResourceOrNull(graph, URIs.SimulateOnChangeExperiment);\r
@@ -205,7 +208,7 @@ public class SysdynResource {
         SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
         SysdynModelManager = getResourceOrNull(graph, URIs.SysdynModelManager);\r
         SysdynProject = getResourceOrNull(graph, URIs.SysdynProject);\r
-        SysdynSymbols = getResourceOrNull(graph, URIs.SysdynSymbols);\r
+        SysdynTerminal = getResourceOrNull(graph, URIs.SysdynTerminal);\r
         Terminal = getResourceOrNull(graph, URIs.Terminal);\r
         Valve = getResourceOrNull(graph, URIs.Valve);\r
         ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol);\r
index 9f37766af66a746e7b4b7ddd92bc81ed6d919d9e..6cd7f836917bd333185fde5ae8c57905651840c6 100644 (file)
@@ -9,8 +9,6 @@
 \r
 %deflib L0.Type Sysdyn\r
 %deflib L0.Relation Sysdyn\r
-\r
-\r
 %deflib DIA.ElementClass Symbols\r
 \r
 %define assert($pred,$obj)\r
@@ -46,7 +44,7 @@ SysdynProject : PROJ.Feature
         L0.HasDescription "Specifies the ontologies required by a Sysdyn project." : L0.String\r
         PROJ.RequiresNamespace\r
           "http://www.simantics.org/Sysdyn-1.0" : L0.URI\r
-      SysdynSymbols\r
+      WORKBENCH.SymbolManager\r
       PROJ.ExperimentControl\r
       SysdynModelManager : PROJ.Feature\r
         L0.PartOf Sysdyn\r
@@ -55,12 +53,6 @@ SysdynProject : PROJ.Feature
         PROJ.RequiresFeature MOD.ModelingProject\r
         PROJ.RequiresFeature PROJ.ExperimentControl\r
 \r
-SysdynSymbols : PROJ.Feature\r
-    L0.PartOf Sysdyn\r
-    L0.HasLabel "Sysdyn symbols" : L0.String\r
-    L0.HasDescription """Sysdyn symbols.""" : L0.String\r
-    PROJ.RequiresFeature WORKBENCH.SymbolManager\r
-\r
 ######################################################################\r
 # Model\r
 ######################################################################    \r
@@ -146,7 +138,7 @@ Stock <T IndependentVariable
     L0.HasPredicate L0.HasType\r
     L0.HasObject "Real" : L0.String\r
 \r
-Cloud <T Variable      \r
+Cloud <T Variable\r
 \r
 Module <T Variable\r
     [HasTerminal]\r
@@ -181,31 +173,31 @@ Dependency <T ST.Connection
 Flow <T ST.Connection\r
     [HasHead card "1"]\r
     [HasTail card "1"]\r
-    \r
+\r
 RefersTo <R L0.IsRelatedTo\r
     L0.HasDomain [Terminal]\r
     L0.HasRange [IndependentVariable]\r
-    \r
+\r
 HasTerminal <R L0.IsRelatedTo\r
     L0.HasRange [Terminal]\r
-    \r
+\r
 \r
 ######################################################################\r
 # Expression\r
 ######################################################################\r
-    \r
+\r
 HasEquation <R L0.HasProperty\r
     L0.HasRange L0.String  \r
-    \r
+\r
 HasInitialEquation <R L0.HasProperty\r
     L0.HasRange L0.String\r
-    \r
+\r
 HasLookup <R L0.HasProperty\r
     L0.HasRange L0.String  \r
 \r
 HasMinX <R L0.HasProperty\r
     L0.HasRange L0.Double\r
-    \r
+\r
 HasMaxX <R L0.HasProperty\r
     L0.HasRange L0.Double\r
 \r
@@ -214,12 +206,12 @@ HasMinY <R L0.HasProperty
 \r
 HasMaxY <R L0.HasProperty\r
     L0.HasRange L0.Double\r
-    \r
+\r
 Expression <T L0.Entity\r
 \r
 NormalExpression <T Expression\r
     [HasEquation card "1"]    \r
-    \r
+\r
 ParameterExpression <T Expression\r
     [HasEquation card "1"]   \r
 \r
@@ -231,10 +223,10 @@ DelayExpression <T Expression
 \r
 StockExpression <T Expression\r
     [HasInitialEquation card "1"]\r
-  \r
+\r
 LookupExpression <T Expression\r
     [HasLookup card "1"]   \r
-    \r
+\r
 WithLookupExpression <T Expression\r
     [HasLookup card "1"]  \r
     [HasEquation card "1"]    \r
@@ -242,12 +234,12 @@ WithLookupExpression <T Expression
     [HasMaxX card "1"]\r
     [HasMinY card "1"]\r
     [HasMaxY card "1"]\r
-    \r
-      \r
+\r
+\r
 ######################################################################\r
 # Experiments\r
 ######################################################################\r
-      \r
+\r
 Experiment <T L0.Entity\r
     [HasResult]\r
 \r
@@ -277,61 +269,6 @@ HasParameterFile <R L0.HasProperty
 HasResultFile <R L0.HasProperty\r
     L0.HasRange L0.String\r
 \r
-    \r
-######################################################################\r
-# Symbols\r
-######################################################################\r
-\r
-#Auxiliary\r
-#  MOD.ComponentTypeToSymbol AuxiliarySymbol <T DIA.DefinedElement\r
-#    L0.HasLabel "Auxiliary" : L0.String\r
-#    L0.IsDependencyOf BasicSymbolLibrary\r
-#    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-#      _ : DIA.SVGElement\r
-#        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-#<ellipse cx="0" cy="0" rx="8" ry="4" stroke="black" stroke-width="0.2" fill="none" />\r
-#</svg>""" : L0.String\r
-\r
-#Stock\r
-#  MOD.ComponentTypeToSymbol StockSymbol <T DIA.DefinedElement\r
-#    L0.HasLabel "Stock" : L0.String\r
-#    L0.IsDependencyOf BasicSymbolLibrary\r
-#    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-#      _ : DIA.SVGElement\r
-#        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-#<rect x="-8" y="-4" width="16" height="8" stroke="black" stroke-width="0.2" fill="none"/>\r
-#</svg>""" : L0.String\r
-\r
-\r
-#Valve\r
-#  MOD.ComponentTypeToSymbol ValveSymbol <T DIA.DefinedElement\r
-#    L0.HasLabel "Valve" : L0.String\r
-#    L0.IsDependencyOf BasicSymbolLibrary\r
-#    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-#      _ : DIA.SVGElement\r
-#        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-#<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-#<path\r
-#     stroke="black" stroke-width="0.2" fill="none"\r
-#     d="M-3 3 L3 -3 L-3 -3 L3 3 Z" />     \r
-#</svg>""" : L0.String\r
-\r
-\r
-\r
-\r
-\r
-######################################################################\r
-# Terminal\r
-######################################################################\r
-\r
-PhantomTerminal <T DIA.DefinedElement <T DIA.Terminal\r
-  ST.IsDefinedBy %list : DIA.Composite <R L0.IsRelatedTo\r
-    _ : DIA.SVGElement\r
-      G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" overflow="visible" version="1.1"><ellipse cx="0.0" cy="0.0" rx="1.0" ry="1.0" fill="none" stroke-width="0.1" stroke="none"/></svg>""" : L0.String\r
-  L0.PartOf Sysdyn      \r
-\r
 ######################################################################\r
 # Macros for component types\r
 ######################################################################\r
@@ -345,95 +282,83 @@ PhantomTerminal <T DIA.DefinedElement <T DIA.Terminal
     ST.HasParameter _ : ST.ConnectionVariable\r
       ST.Binds $relation\r
 \r
-######################################################################\r
-# Macros for symbols\r
-######################################################################\r
+%define defSymbol($label, $componentType)\r
+  $subject <T DIA.Element\r
+    L0.PartOf Sysdyn\r
+    MOD.SymbolToComponentType $componentType \r
+    L0.HasLabel $label : L0.String\r
 \r
-%define defSymbol($library, $svg)\r
-  $subject <T DIA.DefinedElement\r
-    L0.IsDependencyOf $library\r
-    ST.IsDefinedBy %list : DIA.Composite <R L0.IsRelatedTo\r
-      _ : DIA.SVGElement\r
-        G2D.HasSVGDocument $svg : L0.String\r
+%define defConnectionPoint($connectionType, $attachmentRelation)\r
+  $subject <R ST.IsConnectedTo \r
+      ST.AllowsConnectionType $connectionType\r
+      ST.HasAttachmentRelation $attachmentRelation\r
 \r
-%define terminal($transform, $parent, $target)\r
+%define terminal($parent, $relation)\r
   $subject\r
-    G2D.HasTransform $transform : G2D.Transform\r
     DIA.HasConnectionVariable _ : ST.ConnectionVariable\r
-      ST.Binds _ <R ST.IsConnectedTo\r
-        MOD.DiagramConnectionRelationToConnectionRelation $target\r
+      ST.Binds $relation \r
       ST.IsParameterOf $parent\r
 \r
+%define terminalRelation($target)\r
+  $subject <R ST.IsConnectedTo\r
+    MOD.DiagramConnectionRelationToConnectionRelation $target\r
 \r
 ######################################################################\r
 # Component types\r
 ######################################################################\r
 \r
-%define defConnectionPoint($connectionType, $attachmentRelation)\r
-  $subject <R ST.IsConnectedTo \r
-      ST.AllowsConnectionType $connectionType\r
-      ST.HasAttachmentRelation $attachmentRelation\r
+IsHeadOfTerminal\r
+  terminalRelation(IsHeadOf)\r
+IsTailOfTerminal\r
+  terminalRelation(IsTailOf)\r
 \r
+SysdynTerminal <T DIA.Terminal\r
 \r
 ######################################################################\r
 Stock\r
   def()\r
   connection(IsTailOf)\r
   connection(IsHeadOf)\r
-  # symbol\r
-  MOD.ComponentTypeToSymbol StockSymbol <T DIA.DefinedElement\r
-    L0.HasLabel "Stock" : L0.String\r
-    L0.IsDependencyOf BasicSymbolLibrary\r
-    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-      _ : DIA.SVGElement\r
-        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-<rect x="-8" y="-4" width="16" height="8" stroke="black" stroke-width="0.2" fill="none"/>\r
-</svg>""" : L0.String\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,-7,0", StockSymbol , IsHeadOf)\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,7,0", StockSymbol , IsTailOf)\r
+\r
+StockSymbol <T DIA.FontProvider <T DIA.ColorProvider\r
+  defSymbol("Stock", Stock)\r
+  L0.IsDependencyOf BasicSymbolLibrary\r
+  ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsHeadOfTerminal)\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsTailOfTerminal)\r
 \r
 ######################################################################\r
 Valve\r
   def()\r
   connection(IsTailOf)\r
   connection(IsHeadOf)\r
-  # symbol\r
-  MOD.ComponentTypeToSymbol ValveSymbol <T DIA.DefinedElement\r
-    L0.HasLabel "Valve" : L0.String\r
-    L0.IsDependencyOf BasicSymbolLibrary\r
-    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-      _ : DIA.SVGElement\r
-        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-<path\r
-     stroke="black" stroke-width="0.2" fill="none"\r
-     d="M-3 3 L3 -3 L-3 -3 L3 3 Z" />     \r
-</svg>""" : L0.String\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,-7,0", ValveSymbol, IsHeadOf)\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,7,0", ValveSymbol, IsTailOf)\r
+\r
+ValveSymbol <T DIA.FontProvider <T DIA.ColorProvider\r
+  defSymbol("Valve", Valve)\r
+  L0.IsDependencyOf BasicSymbolLibrary\r
+  ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsHeadOfTerminal)\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsTailOfTerminal)\r
 \r
 ######################################################################\r
 Auxiliary\r
   def()\r
   connection(IsTailOf)\r
   connection(IsHeadOf)\r
-  # symbol\r
-  MOD.ComponentTypeToSymbol AuxiliarySymbol <T DIA.DefinedElement\r
-    L0.HasLabel "Valve" : L0.String\r
-    L0.IsDependencyOf BasicSymbolLibrary\r
-    ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
-      _ : DIA.SVGElement\r
-        G2D.HasSVGDocument """<?xml version="1.0" encoding="UTF-8" standalone="no"?>\r
-<svg xmlns="http://www.w3.org/2000/svg" overflow="visible">\r
-<ellipse cx="0" cy="0" rx="8" ry="4" stroke="black" stroke-width="0.2" fill="none" />\r
-</svg>""" : L0.String\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,-7,0", AuxiliarySymbol, IsHeadOf)\r
-      _ : PhantomTerminal\r
-        terminal("1,0,0,1,7,0", AuxiliarySymbol, IsTailOf)\r
 \r
+AuxiliarySymbol <T DIA.FontProvider <T DIA.ColorProvider\r
+  defSymbol("Auxiliary", Auxiliary)\r
+  L0.IsDependencyOf BasicSymbolLibrary\r
+  ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsHeadOfTerminal)\r
+      _ : SysdynTerminal\r
+        terminal(StockSymbol, IsTailOfTerminal)\r
+\r
+######################################################################\r
+# Diagram connection types\r
+######################################################################\r