]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Creation of new modules
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 23 Jul 2010 11:28:30 +0000 (11:28 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 23 Jul 2010 11:28:30 +0000 (11:28 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16801 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Model.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelChildren.java [deleted file]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleLabeler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Modules.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java
sysdyn_ontologies/sysdyn.graph

index 90babd615a8d8432a22da3f1a4e598f8e5d064f7..4ae354c98bd4df26d21bf60385bd86f5d14d75b1 100644 (file)
                   id="org.simantics.sysdyn.ui.browser.newModule"\r
                   label="Module"\r
                   style="push">\r
+               <visibleWhen\r
+                     checkEnabled="true">\r
+                  <with\r
+                        variable="selection">\r
+                     <test\r
+                           args="org.simantics.sysdyn.ui.browser.nodes.ModulesNode"\r
+                           property="org.simantics.sysdyn.ui.nodeClass">\r
+                     </test>\r
+                  </with>\r
+               </visibleWhen>\r
             </command>\r
             <command\r
                   commandId="org.simantics.sysdyn.ui.newExperiment"\r
                preference="1.0">\r
          </implementation>\r
          <implementation\r
-               class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
+               class="org.simantics.sysdyn.ui.browser.contributions.Project"\r
                preference="1.0">\r
          </implementation>\r
          <implementation\r
                preference="1.0">\r
          </implementation>\r
          <implementation\r
-               class="org.simantics.sysdyn.ui.browser.contributions.ModelChildren"\r
+               class="org.simantics.sysdyn.ui.browser.contributions.Model"\r
                preference="2.0">\r
          </implementation>\r
          <implementation\r
                class="org.simantics.sysdyn.ui.browser.contributions.InputLabeler"\r
                preference="2.0">\r
          </implementation>\r
+         <implementation\r
+               class="org.simantics.sysdyn.ui.browser.contributions.ModuleTypeLabeler"\r
+               preference="2.0">\r
+         </implementation>\r
       </binding>\r
    </extension>\r
    <extension\r
index 9f5c18beb1477d6820de50c1112747950f3e42bd..eb2d5a0f20336495908756053a1f642183201b51 100644 (file)
@@ -2,41 +2,35 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
-\r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ObjectsWithType;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;\r
+import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder;\r
 \r
-public class Model extends ViewpointContributor<Resource> {\r
+public class Model  extends ViewpointContributor<ModelNode> {\r
 \r
     @Override\r
-    public Collection<?> getContribution(ReadGraph graph, Resource project)\r
+    public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
     throws DatabaseException {\r
-\r
         ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
-        Builtins b = graph.getBuiltins();\r
-        SysdynResource sr = SysdynResource.getInstance(graph);\r
-        for(Resource r : graph.syncRequest(new ObjectsWithType(project, b.ConsistsOf, sr.SysdynModel))) {\r
-            try {\r
-                result.add(graph.adapt(r, AbstractNode.class));\r
-            } catch(DatabaseException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-        result.add(new ModulesNode(project));\r
+        result.add(new ConfigurationNode(\r
+                graph.getSingleObject(\r
+                        model.resource, \r
+                        graph.getBuiltins().HasConfiguration))\r
+        );\r
+        result.add(new ExperimentsFolder(model.resource));\r
+        result.add(new OperatingInterfacesFolder(model.resource));\r
+        result.add(new ModulesNode(model.resource));\r
         return result;\r
-\r
     }\r
 \r
     @Override\r
     public String getViewpointId() {\r
         return "Standard";\r
     }\r
-    \r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelChildren.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModelChildren.java
deleted file mode 100644 (file)
index d5dc863..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.simantics.sysdyn.ui.browser.contributions;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.ConfigurationNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.ExperimentsFolder;\r
-import org.simantics.sysdyn.ui.browser.nodes.ModelNode;\r
-import org.simantics.sysdyn.ui.browser.nodes.OperatingInterfacesFolder;\r
-\r
-public class ModelChildren  extends ViewpointContributor<ModelNode> {\r
-\r
-    @Override\r
-    public Collection<?> getContribution(ReadGraph graph, ModelNode model)\r
-    throws DatabaseException {\r
-        ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
-        result.add(new ConfigurationNode(\r
-                graph.getSingleObject(\r
-                        model.resource, \r
-                        graph.getBuiltins().HasConfiguration))\r
-        );\r
-        result.add(new ExperimentsFolder(model.resource));\r
-        result.add(new OperatingInterfacesFolder(model.resource));\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public String getViewpointId() {\r
-        return "Standard";\r
-    }\r
-}\r
index fdc289c637dedfd0042bf9c4f64742c24d18091c..78e02ffe013dc3b3b1e6c339cc5056c03ffa8b90 100644 (file)
@@ -25,9 +25,6 @@ public class ModuleLabeler  extends LabelerContributor<ModuleNode>{
         Builtins b = graph.getBuiltins();\r
         Resource resource = module.resource;\r
         StringBuilder sb = new StringBuilder();\r
-        for(Resource r : graph.getObjects(resource, b.HasLabel))\r
-            sb.append(graph.getValue(r));\r
-        sb.append(" : ");\r
         for(Resource r : graph.getObjects(resource, b.HasName))\r
             sb.append(graph.getValue(r));\r
         sb.append(" : ");\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleTypeLabeler.java
new file mode 100644 (file)
index 0000000..cefdd32
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
+\r
+public class ModuleTypeLabeler extends LabelerContributor<ModuleTypeNode>{\r
+\r
+    @Override\r
+    public String getLabel(ReadGraph graph, ModuleTypeNode moduleType) throws DatabaseException {\r
+        String label = graph.getPossibleRelatedValue(moduleType.resource, graph.getBuiltins().HasLabel);\r
+        return label == null ? "Model (no name)" : label;\r
+    }\r
+\r
+}\r
index 8b6111fc309444203c6a07b41b919c647c43eb4d..5281330f5404e580451672b54f4b927cadf81c79 100644 (file)
@@ -17,13 +17,13 @@ import org.simantics.sysdyn.ui.browser.nodes.ModulesNode;
 public class Modules extends ViewpointContributor<ModulesNode> {\r
 \r
     @Override\r
-    public Collection<?> getContribution(ReadGraph graph, ModulesNode project)\r
+    public Collection<?> getContribution(ReadGraph graph, ModulesNode model)\r
     throws DatabaseException {\r
 \r
         ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
         Builtins b = graph.getBuiltins();\r
         StructuralResource2 st = StructuralResource2.getInstance(graph);\r
-        for(Resource r : graph.syncRequest(new ObjectsWithType(project.resource, b.IsRelatedTo, st.ComponentType))) {\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(model.resource, b.ConsistsOf, st.ComponentType))) {\r
             result.add(new ModuleTypeNode(r));\r
         }\r
         return result;\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Project.java
new file mode 100644 (file)
index 0000000..83ef90d
--- /dev/null
@@ -0,0 +1,40 @@
+package org.simantics.sysdyn.ui.browser.contributions;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.browser.nodes.AbstractNode;\r
+\r
+public class Project extends ViewpointContributor<Resource> {\r
+\r
+    @Override\r
+    public Collection<?> getContribution(ReadGraph graph, Resource project)\r
+    throws DatabaseException {\r
+\r
+        ArrayList<AbstractNode> result = new ArrayList<AbstractNode>();\r
+        Builtins b = graph.getBuiltins();\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+        for(Resource r : graph.syncRequest(new ObjectsWithType(project, b.ConsistsOf, sr.SysdynModel))) {\r
+            try {\r
+                result.add(graph.adapt(r, AbstractNode.class));\r
+            } catch(DatabaseException e) {\r
+                e.printStackTrace();\r
+            }\r
+        }\r
+        return result;\r
+\r
+    }\r
+\r
+    @Override\r
+    public String getViewpointId() {\r
+        return "Standard";\r
+    }\r
+    \r
+}\r
index 54d75f8733662f68a12791049e2037e5c55759ef..e178b0b592e0e5f2ae91215bb9b30bada2ebb7b3 100644 (file)
@@ -3,12 +3,91 @@ 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.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.ui.handlers.HandlerUtil;\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.ModelingUtils;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
 public class NewModuleNodeHandler extends AbstractHandler {\r
 \r
     @Override\r
     public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        System.out.println("New module!");\r
+        \r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        Resource[] resources = ResourceAdaptionUtils.toResources(sel);\r
+        if (resources.length != 1)\r
+            return null;\r
+        \r
+        final Resource model = resources[0];\r
+        \r
+        SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
+            \r
+            @Override\r
+            public void perform(WriteGraph g) throws DatabaseException {\r
+                // Same as in SysdynProject.java. Should use the same code, not copy.\r
+                SysdynResource sr = SysdynResource.getInstance(g);\r
+                ModelingUtils mu = new ModelingUtils(g);\r
+                \r
+                Resource moduleType = g.newResource();\r
+                g.claimValue(moduleType, mu.b.HasName, "ModuleType");\r
+                g.claimValue(moduleType, mu.b.HasLabel, "ModuleTypeLabel");\r
+                g.claim(moduleType, mu.b.Inherits, sr.Module);\r
+                g.claim(moduleType, mu.b.PartOf, model);\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
+                Resource mapping = g.newResource();\r
+                g.claim(mapping, mu.b.InstanceOf, null, sr.DiagramToCompositeMapping);\r
+                g.claim(diagram, mu.b.HasTrigger, mapping);\r
+\r
+                \r
+                Resource configuration = GraphUtils.create2(g, \r
+                        sr.Configuration,\r
+                        mu.mr.CompositeToDiagram, diagram);\r
+                \r
+                g.claim(moduleType, mu.sr.IsDefinedBy , configuration);\r
+                \r
+                \r
+                Resource moduleSymbol = g.newResource();\r
+                g.claimValue(moduleSymbol, mu.b.HasName, "ModuuliSymboli");\r
+                g.claimValue(moduleSymbol, mu.b.HasLabel, "ModuuliSymboliLabel");\r
+                g.claim(moduleSymbol, mu.b.Inherits, sr.ModuleSymbol);\r
+                g.claim(moduleSymbol, mu.mr.SymbolToComponentType, moduleType);\r
+                \r
+                Resource terminal = g.newResource();\r
+                g.claim(terminal, mu.b.InstanceOf, sr.SysdynTerminal);\r
+                Resource connectionVariable = g.newResource();\r
+                g.claim(connectionVariable, mu.b.InstanceOf, mu.sr.ConnectionVariable);\r
+                g.claim(connectionVariable, mu.sr.Binds, sr.IsHeadOfTerminal);\r
+                g.claim(connectionVariable, mu.sr.IsParameterOf, sr.ModuleSymbol);\r
+                g.claim(terminal, mu.dr.HasConnectionVariable, connectionVariable);\r
+                \r
+                \r
+                Resource terminal2 = g.newResource();\r
+                g.claim(terminal2, mu.b.InstanceOf, sr.SysdynTerminal);\r
+                Resource connectionVariable2 = g.newResource();\r
+                g.claim(connectionVariable2, mu.b.InstanceOf, mu.sr.ConnectionVariable);\r
+                g.claim(connectionVariable2, mu.sr.Binds, sr.IsTailOfTerminal);\r
+                g.claim(connectionVariable2, mu.sr.IsParameterOf, sr.ModuleSymbol);\r
+                g.claim(terminal2, mu.dr.HasConnectionVariable, connectionVariable2);\r
+                \r
+                g.claim(moduleSymbol, mu.sr.IsDefinedBy, OrderedSetUtils.create(g, mu.sr.Composite, terminal, terminal2));\r
+            \r
+                \r
+            }\r
+        });\r
         return null;\r
     }\r
 \r
index d9cba57dc36a16e1c02bf954c1929e3afcb2724c..f3abe32ed28a915f527881e8314ae05ee996a813 100644 (file)
@@ -78,10 +78,10 @@ public class ModelicaWriter {
             } else if (element instanceof Module) {\r
                 Module m = (Module)element; \r
                 modules.add(m);\r
-                moduleInputs.put(m.getLabel(), new ArrayList<Input>());\r
+                moduleInputs.put(m.getName(), new ArrayList<Input>());\r
                 for(IElement e : m.getType().getConfiguration().getElements())\r
                     if(e instanceof Input && !((Input)e).isHeadOfDependency()) {\r
-                        moduleInputs.get(m.getLabel()).add((Input)e);\r
+                        moduleInputs.get(m.getName()).add((Input)e);\r
                     }\r
             } else if (element instanceof Input) {\r
                 inputs.add((Input)element);\r
@@ -112,7 +112,7 @@ public class ModelicaWriter {
         if(!modules.isEmpty()) {\r
             b.append("// Module definitions\n");\r
             for(Module m : modules) {\r
-                b.append("    " + m.getType().getName() + " " + m.getLabel() + ";\n");\r
+                b.append("    " + m.getType().getName() + " " + m.getName() + ";\n");\r
             }\r
         }\r
         \r
@@ -155,7 +155,7 @@ public class ModelicaWriter {
             Input variable = (Input)dependency.getHead();\r
             Module module = (Module)dependency.getTail();\r
             Variable reference = (Variable)dependency.refersTo();\r
-            b.append("    " + variable.getName() + " = " + module.getLabel() + "." + reference.getName() + ";\n");\r
+            b.append("    " + variable.getName() + " = " + module.getName() + "." + reference.getName() + ";\n");\r
         }\r
 \r
         b.append("// Outputs\n");\r
@@ -163,8 +163,8 @@ public class ModelicaWriter {
             Variable variable = (Variable)dependency.getTail();\r
             Module module = (Module)dependency.getHead();\r
             Input reference = (Input)dependency.refersTo();\r
-            b.append("    " + module.getLabel() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
-            moduleInputs.get(module.getLabel()).remove(reference);\r
+            b.append("    " + module.getName() + "." + reference.getName() + " = " + variable.getName() + ";\n");\r
+            moduleInputs.get(module.getName()).remove(reference);\r
         }\r
         \r
         b.append("// Default values for inputs in modules\n");\r
index 7aed35d3b216cbf4f1098c783fb6c31c7c82667d..3af65a541efcaca41254fa763af7f75a7e89ad7d 100644 (file)
@@ -12,9 +12,6 @@ public class Module implements IElement {
     @RelatedValue("http://www.simantics.org/Layer0-1.0/HasName")\r
     private String name;\r
 \r
-    @RelatedValue("http://www.simantics.org/Layer0-1.0/HasLabel")\r
-    private String label;\r
-\r
     @RelatedElement("http://www.simantics.org/Layer0-1.0/PartOf")\r
     private Configuration parentConfiguration;\r
 \r
@@ -47,11 +44,6 @@ public class Module implements IElement {
     public String getName() {\r
         return name;\r
     }\r
-\r
-\r
-    public String getLabel() {\r
-        return label;\r
-    }\r
     \r
     public ModuleType getType() {\r
        return type;\r
index 25f1dcd14a90701b1a4a7f833d11e2299ec6d0a7..3869fac17d5c20ddf83a6957a26f80278100344a 100644 (file)
@@ -604,10 +604,13 @@ CapacitySymbol <T ModuleSymbol
 _ @ "CustomerModel" : SysdynModel\r
   L0.HasLabel "Asiakasmalli" : L0.String\r
   L0.PartOf SysdynModuleTestProject\r
-  L0.ConsistsOf _ @ "Experiment" : Experiment\r
-    L0.HasLabel "Experiment" : L0.String\r
   SIMU.HasConfiguration RootConfiguration\r
-  L0.ConsistsOf RootConfiguration\r
+  L0.ConsistsOf \r
+    _ @ "Experiment" : Experiment\r
+      L0.HasLabel "Experiment" : L0.String\r
+    CustomerModule\r
+    CapacityModule  \r
+    RootConfiguration   \r
 \r
 # Layerit ja connectiontype!\r
 \r
@@ -1220,8 +1223,3 @@ CustomerModuleConfigurationDiagram : ConfigurationDiagram <R L0.HasNext
     _ : DependencyConnection\r
       MOD.DiagramConnectionToConnection Dependency36\r
       dep(PotentialCustomerConcentrationElement, PotentialCustomersStockElement, "-0.1")  \r
-      \r
-SysdynModuleTestProject\r
-  L0.IsRelatedTo CustomerModule\r
-  L0.IsRelatedTo CapacityModule\r
-\r