]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
buggy symbol viewer
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 25 May 2010 06:36:05 +0000 (06:36 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 25 May 2010 06:36:05 +0000 (06:36 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@15843 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/META-INF/MANIFEST.MF
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/SysdynDiagramEditor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModelHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/SysdynPerspectiveFactory.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 df09a233e0003057e1a85775ca08bb7e4f8956a4..9fcc740cf6976a0c07335ea966ff7e867761dbcd 100644 (file)
@@ -26,6 +26,8 @@ Require-Bundle: org.simantics.h2d;bundle-version="1.0.0",
  org.simantics.modeling.ui;bundle-version="1.0.0",
  org.eclipse.ui.cheatsheets,
  org.simantics.graphviz.ui;bundle-version="1.0.0",
- org.simantics.graphviz;bundle-version="1.0.0"
+ org.simantics.graphviz;bundle-version="1.0.0",
+ org.simantics.diagram;bundle-version="0.9.4",
+ org.simantics.modeling;bundle-version="1.0.0"
 Bundle-Activator: org.simantics.sysdyn.ui.Activator
 Bundle-ActivationPolicy: lazy
index 497b8cf9528739a83b144783f5c1dddeda1b2941..05d41f6ea55d34ef108228186b74e7dd06463fca 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.editor;
 \r
 import java.awt.Frame;\r
 import java.util.ArrayList;\r
+import java.util.Collection;\r
 \r
 import javax.swing.SwingUtilities;\r
 \r
@@ -31,6 +32,10 @@ import org.simantics.db.WriteGraph;
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.db.management.ISessionContextProvider;\r
+import org.simantics.diagram.DiagramTypeUtils;\r
+import org.simantics.diagram.symbolcontribution.ISymbolProvider;\r
 import org.simantics.h2d.canvas.EditorCanvas;\r
 import org.simantics.h2d.diagram.IDiagram;\r
 import org.simantics.h2d.diagram.IDiagramListener;\r
@@ -40,6 +45,9 @@ import org.simantics.h2d.editor.impl.DiagramEditor;
 import org.simantics.h2d.element.IElement;\r
 import org.simantics.h2d.element.IElementListener;\r
 import org.simantics.h2d.event.handler.DefaultEventHandlers;\r
+import org.simantics.layer0.utils.triggers.IActivation;\r
+import org.simantics.layer0.utils.triggers.IActivationManager;\r
+import org.simantics.modeling.ModelingResources;\r
 import org.simantics.objmap.IMapping;\r
 import org.simantics.objmap.IMappingListener;\r
 import org.simantics.objmap.MappingException;\r
@@ -58,6 +66,7 @@ import org.simantics.ui.workbench.TitleRequest;
 import org.simantics.ui.workbench.TitleUpdater;\r
 import org.simantics.utils.datastructures.Callable;\r
 import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.ui.ErrorLogger;\r
 import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
 \r
 public class SysdynDiagramEditor extends ResourceEditorPart {\r
@@ -68,6 +77,10 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
     Frame frame;\r
     boolean disposed = false;  \r
     Composite frameComposite;\r
+    Resource diagramResource;\r
+    protected ISessionContextProvider    sessionContextProvider;\r
+    protected ISessionContext            sessionContext;\r
+    protected IActivation                activation;\r
 \r
     IElementListener elementUpdateListener = new IElementListener() {\r
 \r
@@ -168,6 +181,8 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
 \r
                 @Override\r
                 public void run(ReadGraph g) throws DatabaseException {\r
+                    diagramResource = g.getSingleObject(getInputResource(), ModelingResources.getInstance(g).CompositeToDiagram);\r
+                    System.out.println(diagramResource);\r
                     readDiagram(g);                    \r
                 }\r
 \r
@@ -206,6 +221,20 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
         frameComposite = new Composite(parent, \r
                 SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
         frame = SWT_AWT.new_Frame(frameComposite);\r
+        \r
+        \r
+        /// KOKEILLAAN\r
+        \r
+        /*\r
+        sessionContextProvider = SimanticsUI.getSessionContextProvider();\r
+        sessionContext = sessionContextProvider.getSessionContext();\r
+\r
+        IActivationManager activationManager = sessionContext.getSession().peekService(IActivationManager.class);\r
+        if (activationManager != null) {\r
+            activation = activationManager.activate(diagramResource);\r
+        }\r
+        */\r
+        /// LOPPUU\r
 \r
         final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
         getSite().setSelectionProvider(selectionProvider);\r
@@ -285,6 +314,15 @@ public class SysdynDiagramEditor extends ResourceEditorPart {
         if (adapter == INode.class) {\r
             return canvas.getEditor().getSceneGraph();\r
         }\r
+        if (adapter == ISymbolProvider.class) {\r
+            try {\r
+\r
+                return DiagramTypeUtils.readSymbolContributions(SimanticsUI.getSession(), diagramResource);\r
+            } catch (DatabaseException e) {\r
+                ErrorLogger.defaultLogError(getClass() + " failed to adapt to ISymbolProvider, see exception for details.", e);\r
+                return null;\r
+            }\r
+        }\r
         return super.getAdapter(adapter);\r
     }\r
 }\r
index 148bb34eb006a0b9e254722e4be23226a5c71fab..19d0611e98ea09fec96b9f4fdd76a6173587b20b 100644 (file)
@@ -3,11 +3,19 @@ package org.simantics.sysdyn.ui.handlers;
 import org.eclipse.core.commands.AbstractHandler;\r
 import org.eclipse.core.commands.ExecutionEvent;\r
 import org.eclipse.core.commands.ExecutionException; \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.WriteGraph;\r
 import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ModelingUtils;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.ui.SimanticsUI;\r
 \r
@@ -22,18 +30,33 @@ public class NewModelHandler extends AbstractHandler {
                 // Same as in SysdynProject.java. Should use the same code, not copy.\r
                 Builtins b = graph.getBuiltins();\r
                 SysdynResource sr = SysdynResource.getInstance(graph);\r
+                ModelingResources mr = ModelingResources.getInstance(graph);\r
+                ModelingUtils mu = new ModelingUtils(graph);\r
+                \r
                 Resource model = graph.newResource();\r
                 graph.claimValue(model, b.HasName, "Model1");\r
                 graph.claimValue(model, b.HasLabel, "Model1");\r
                 graph.claim(model, b.InstanceOf, sr.SysdynModel);\r
                 graph.claim(model, b.PartOf, SimanticsUI.getProject().get());\r
                 \r
-                Resource conf = graph.newResource();\r
-                graph.claimValue(conf, b.HasName, "Configuration");\r
-                graph.claim(conf, b.InstanceOf, sr.Configuration);\r
+                \r
+                Resource diagram = OrderedSetUtils.create(graph, sr.ConfigurationDiagram);\r
+                GraphLayer l = new GraphLayerUtil(graph).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+                graph.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+                graph.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
+                \r
+                Resource conf = GraphUtils.create2(graph, \r
+                        sr.Configuration,\r
+                        b.HasName, "Configuration",\r
+                        sr.HasStartTime, 0.0,\r
+                        sr.HasStopTime, 10.0);\r
+\r
+                graph.claim(conf, mr.CompositeToDiagram, diagram);\r
                 graph.claim(model, b.HasConfiguration, conf);\r
-                graph.claimValue(conf, sr.HasStartTime, 0.0);\r
-                graph.claimValue(conf, sr.HasStopTime, 10.0);\r
+                \r
+                Resource mapping = graph.newResource();\r
+                graph.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
+                graph.claim(diagram, b.HasTrigger, mapping);\r
             }\r
         });\r
         return null;\r
index 1d86dbe6d53b730a3e36eced5218b43f8d4c733a..4ced7a1153ecc43b475ad87641073d0be6a796b0 100644 (file)
@@ -43,6 +43,9 @@ public class SysdynPerspectiveFactory implements IPerspectiveFactory {
 \r
         IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, 0.25f, editorArea);\r
         left.addView("org.simantics.sysdyn.ui.browser");\r
+        \r
+        IFolderLayout right = layout.createFolder("right", IPageLayout.RIGHT, 0.7f, editorArea);\r
+        right.addView("org.simantics.diagram.symbollibrary");\r
 \r
         // Open cheatsheets view on the first time the user creates a sysdyn project\r
         // for a particular workspace.\r
index 1020b1cdf1c0550e25947521436415474efe19fc..178089b8df98095b5f4d6978cdf483f4aa26a61c 100644 (file)
@@ -13,13 +13,20 @@ package org.simantics.sysdyn.ui.project;
 \r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.ui.PartInitException;\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.db.WriteGraph;\r
 import org.simantics.db.common.request.Queries;\r
+import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.service.LifecycleSupport;\r
+import org.simantics.diagram.DiagramConstants;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayer;\r
+import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.modeling.ModelingUtils;\r
 import org.simantics.project.ProjectElementType;\r
 import org.simantics.project.ProjectElements;\r
 import org.simantics.project.ProjectKeys;\r
@@ -71,19 +78,35 @@ public class SysdynProject extends AbstractProjectFeature {
             try {\r
                 Builtins b = g.getBuiltins();\r
                 SysdynResource sr = SysdynResource.getInstance(g);\r
+                ModelingResources mr = ModelingResources.getInstance(g);\r
+                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
                 g.claim(model, b.InstanceOf, sr.SysdynModel);\r
                 g.claim(model, b.PartOf, library);\r
+\r
+                Resource diagram = OrderedSetUtils.create(g, sr.ConfigurationDiagram);\r
+                GraphLayer l = new GraphLayerUtil(g).createLayer(DiagramConstants.DEFAULT_LAYER_NAME, true);\r
+                g.claim(diagram, mu.dr.HasLayer, l.getLayer());\r
+                g.claimValue(diagram, b.HasName, "Diagrammi", StringJavaBinding.INSTANCE);\r
                 \r
+\r
                 Resource conf = g.newResource();\r
                 g.claimValue(conf, b.HasName, "Configuration");\r
                 g.claim(conf, b.InstanceOf, sr.Configuration);\r
-                g.claim(model, b.HasConfiguration, conf);\r
                 g.claimValue(conf, sr.HasStartTime, 0.0);\r
                 g.claimValue(conf, sr.HasStopTime, 10.0);\r
+                \r
+                g.claim(conf, mr.CompositeToDiagram, diagram);\r
+                g.claim(model, b.HasConfiguration, conf);\r
+                \r
+                Resource mapping = g.newResource();\r
+                g.claim(mapping, b.InstanceOf, null, mr.DiagramToCompositeMapping);\r
+                g.claim(diagram, b.HasTrigger, mapping);\r
 \r
+                callback.run(model);\r
             } catch(Exception e) {\r
                 errorCallback.run(e);\r
             }\r
index 87165c9e0178f2cdf31889334c363b6523d9f591..8f3d8b3103387011a397d12209ce2db789966eaf 100644 (file)
@@ -23,6 +23,7 @@ public class SysdynResource {
     public final Resource Auxiliary;\r
     public final Resource Cloud;\r
     public final Resource Configuration;\r
+    public final Resource ConfigurationDiagram;\r
     public final Resource ConstantExpression;\r
     public final Resource DelayExpression;\r
     public final Resource Dependency;\r
@@ -63,6 +64,7 @@ public class SysdynResource {
         public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
         public static final String Cloud = "http://www.simantics.org/Sysdyn-1.0/Cloud";\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
         public static final String DelayExpression = "http://www.simantics.org/Sysdyn-1.0/DelayExpression";\r
         public static final String Dependency = "http://www.simantics.org/Sysdyn-1.0/Dependency";\r
@@ -113,6 +115,7 @@ public class SysdynResource {
         Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
         Cloud = getResourceOrNull(graph, URIs.Cloud);\r
         Configuration = getResourceOrNull(graph, URIs.Configuration);\r
+        ConfigurationDiagram = getResourceOrNull(graph, URIs.ConfigurationDiagram);\r
         ConstantExpression = getResourceOrNull(graph, URIs.ConstantExpression);\r
         DelayExpression = getResourceOrNull(graph, URIs.DelayExpression);\r
         Dependency = getResourceOrNull(graph, URIs.Dependency);\r
index a615777ec815049cc0624b69d0dd27d00307c2fa..f847af7d4fff553de1f96b71e0729b847b9d7a40 100644 (file)
@@ -1,11 +1,23 @@
 %import "layer0.graph" L0\r
+%import "diagram2.graph" DIA\r
+%import "g2d.graph" G2D\r
 %import "structural2.graph" ST\r
+%import "modeling.graph" MOD\r
 %import "project.graph" PROJ\r
 %import "simulation.graph" SIMU\r
 \r
 %deflib L0.Type Sysdyn\r
 %deflib L0.Relation Sysdyn\r
 \r
+\r
+%deflib DIA.ElementClass Symbols\r
+\r
+%define assert($pred,$obj)\r
+    $subject\r
+        L0.Asserts _ : L0.Assertion\r
+            L0.HasPredicate $pred\r
+            L0.HasObject    $obj\r
+\r
 ######################################################################\r
 # Defines ontology and attaches it to SimanticsDomain\r
 ######################################################################\r
@@ -15,29 +27,47 @@ Sysdyn @ "Sysdyn-1.0" : L0.Ontology
     L0.HasVersion "1.0" : L0.Version\r
     L0.HasResourceClass "org.simantics.sysdyn.SysdynResource" : L0.String\r
     L0.HasPackageName "sysdyn" : L0.String  \r
+    L0.ConsistsOf\r
+        Symbols : L0.Library\r
 \r
 SysdynProject : PROJ.Feature\r
     L0.HasLabel "System Dynamics Project" : L0.String\r
     L0.HasDescription """System dynamics modelling project. Create system dynamics models and simulate them with OpenModelica.""" : L0.String\r
     L0.PartOf Sysdyn\r
-    L0.PartOf PROJ.PublishedProjectFeatures\r
+    L0.PartOf PROJ.PublishedProjectFeatures    \r
     \r
 ######################################################################\r
 # Model\r
 ######################################################################    \r
 \r
 SysdynModel <T SIMU.Model\r
-    [SIMU.HasConfiguration all Configuration]\r
+  L0.PartOf Sysdyn\r
+  [SIMU.HasConfiguration all Configuration]\r
 \r
 ######################################################################\r
 # Configuration\r
 ######################################################################\r
+       \r
+ConfigurationDiagram <T DIA.Diagram\r
+  L0.PartOf Sysdyn\r
+  assert(ST.HasModelingRules, SysdynDiagramModelingRules) \r
+  DIA.HasSymbolContribution _ : DIA.BasicSymbolContribution\r
+    DIA.BasicSymbolContributionHasSymbolLibrary\r
+       BasicSymbolLibrary\r
+       \r
+SysdynDiagramModelingRules : MOD.MappedModelingRules\r
+  MOD.HasBaseRules ST.StandardModelingRules\r
+  \r
+SymbolReferences : DIA.SymbolReferenceLibrary\r
+  L0.PartOf Sysdyn\r
+  L0.ConsistsOf\r
+    BasicSymbolLibrary @ "Basic Symbols" : DIA.SymbolReferenceLibrary\r
 \r
 Configuration <T ST.Composite\r
     [L0.ConsistsOf all (Variable or Dependency)]\r
     [HasStartTime card "1"]\r
     [HasStopTime card "1"]\r
-\r
+              \r
 HasStartTime <R L0.HasProperty\r
     L0.HasRange L0.Double   \r
 \r
@@ -72,10 +102,10 @@ IndependentVariable <T Variable
     [HasExpression card "0..1"]    \r
 \r
 Auxiliary <T IndependentVariable\r
-    \r
-Stock <T IndependentVariable\r
 \r
 Valve <T IndependentVariable\r
+    \r
+Stock <T IndependentVariable\r
 \r
 Cloud <T Variable      \r
 \r
@@ -152,4 +182,45 @@ LookupExpression <T Expression
     \r
 WithLookupExpression <T Expression\r
     [HasLookup card "1"]  \r
-    [HasEquation card "1"]    
\ No newline at end of file
+    [HasEquation card "1"]    \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.IsRelatedTo\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.IsRelatedTo\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