]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Sysdyn dev
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 9 Jul 2010 06:20:18 +0000 (06:20 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 9 Jul 2010 06:20:18 +0000 (06:20 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16568 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/plugin.xml
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/DiagramViewer.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/StockExpression.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java
sysdyn_ontologies/sysdyn.graph

index e3c3fe6841473629bd88357daa397d1807558c7a..5b5c4cfd5ba41974958c88c7afc194f9dbb4ad2b 100644 (file)
                   style="push">\r
             </command>\r
          </menu>\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.showModule"\r
+               icon="icons/silk/palette.png"\r
+               label="Show Module"\r
+               style="push">\r
+            <visibleWhen>\r
+               <and>\r
+                  <with\r
+                        variable="selection">\r
+                     <and>\r
+                        <test\r
+                              args="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r
+                              property="org.simantics.graph.resourceType">\r
+                        </test>\r
+                     </and>\r
+                  </with>\r
+               </and>\r
+            </visibleWhen>\r
+         </command>\r
          <command\r
                commandId="org.simantics.sysdyn.ui.rename"\r
                icon="icons/textfield_rename.png"\r
                id="org.simantics.sysdyn.ui.trend.view.pin.state">\r
          </state>\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.showModule"\r
+            name="Show Module">\r
+      </command>\r
       <command\r
             defaultHandler="org.simantics.sysdyn.ui.handlers.CreateAuxiliaryHandler"\r
             id="org.simantics.sysdyn.ui.createAuxiliary"\r
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.ShowModuleHandler"\r
+            commandId="org.simantics.sysdyn.ui.showModule">\r
+         <enabledWhen>\r
+            <and>\r
+               <with\r
+                     variable="selection">\r
+                  <and>\r
+                     <test\r
+                           args="http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"\r
+                           property="org.simantics.graph.resourceType">\r
+                     </test>\r
+                  </and>\r
+               </with>\r
+            </and>\r
+         </enabledWhen>\r
+      </handler>\r
       <handler\r
             class="org.simantics.sysdyn.ui.handlers.RenameHandler"\r
             commandId="org.simantics.sysdyn.ui.rename">\r
index 4251e9bf9b5e98fde0d0012c80ec63b864cff288..1b023211f458557d234b6782df400bba1cb8c4b6 100644 (file)
@@ -34,7 +34,11 @@ import org.simantics.sysdyn.ui.properties.SysdynPropertyPage;
  */\r
 public class DiagramViewer extends org.simantics.modeling.ui.diagramEditor.DiagramViewer {\r
 \r
-    @Override\r
+    protected String getPopupId() {\r
+        return "#SysdynDiagramPopup";\r
+    }\r
+\r
+       @Override\r
     protected Set<String> getPropertyPageContexts() {\r
         return Collections.singleton("http://www.simantics.org/Sysdyn-1.0/Browser");\r
     }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ShowModuleHandler.java
new file mode 100644 (file)
index 0000000..eff51ec
--- /dev/null
@@ -0,0 +1,119 @@
+/*******************************************************************************\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.handlers;\r
+\r
+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.PartInitException;\r
+import org.eclipse.ui.PlatformUI;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.db.Builtins;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.ResourceArray;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
+import org.simantics.modeling.ComponentUtils;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.structural2.StructuralVariables;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.editor.DiagramViewer;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.ui.workbench.ResourceEditorInput2;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+/**\r
+ * Style Edit\r
+ * \r
+ * TODO : should we have extension point for expanding styles?\r
+ * TODO : default ColorChooser is not suitable for this task\r
+ * TODO : how to store MetricsFormat template list\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class ShowModuleHandler extends AbstractHandler {\r
+\r
+    private static final String EDITOR_ID = "org.simantics.sysdyn.ui.diagramViewer";\r
+\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+               \r
+               ISelection s = HandlerUtil.getCurrentSelectionChecked(event);\r
+               final Resource resources[] = ResourceAdaptionUtils.toResources(s);\r
+               final DiagramViewer viewer = (DiagramViewer)HandlerUtil.getActiveEditor(event);\r
+               \r
+               SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+\r
+                DiagramResource dr = DiagramResource.getInstance(graph);\r
+                               Resource runtime = viewer.getRuntime();\r
+                               String uri = graph.getPossibleRelatedValue(runtime, dr.HasVariable, StringBindingDefault.INSTANCE);\r
+                               String currentRVI = graph.getPossibleRelatedValue(runtime, dr.HasRVI, StringBindingDefault.INSTANCE);\r
+                               Variable variable = Variables.getVariable(graph, uri);\r
+                               Resource model = Variables.getModel(graph, variable);\r
+                               final String modelURI = graph.getURI(model);\r
+                               \r
+                               for(Resource element : resources) {\r
+\r
+                                       Builtins b = graph.getBuiltins();\r
+                                       ModelingResources mr = ModelingResources.getInstance(graph);\r
+                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                       StructuralResource2 st = StructuralResource2.getInstance(graph);\r
+                                       \r
+                                       final Resource component = graph.getPossibleObject(element, mr.ElementToComponent);\r
+                                       final Resource componentType = graph.getPossibleType(component, sr.Module);\r
+                                       final Resource configuration = graph.getPossibleObject(componentType, st.IsDefinedBy);\r
+                                       final Resource diagram = ComponentUtils.getPossibleCompositeDiagram(graph, configuration);\r
+                                       \r
+                                       if(diagram == null) return;\r
+                                       \r
+                                       final String rvi = currentRVI + "/" + graph.getPossibleRelatedValue(component, b.HasName, StringBindingDefault.INSTANCE);\r
+                                       if(rvi == null) return;\r
+\r
+                                       PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {\r
+\r
+                                               @Override\r
+                                               public void run() {\r
+                                                       //                        for (Triple<Resource, String, String> in : ins) {\r
+                                                       try {\r
+                                                               String editorId = EDITOR_ID;\r
+                                                               System.out.println("Activating diagram: model=" + modelURI + " rvi='" + rvi + "'");\r
+                                                               WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, diagram, modelURI, rvi));\r
+                                                       } catch (PartInitException e) {\r
+                                                               // TODO Auto-generated catch block\r
+                                                               e.printStackTrace();\r
+                                                       }\r
+                                                       //                        }\r
+                                               }\r
+                                       });\r
+                               \r
+                               }\r
+                               \r
+                       }\r
+               });\r
+               \r
+               return null;\r
+       }\r
+       \r
+\r
+}\r
index 2f09a9531a3e4649e428da309be84d4543a804e1..f9be16055bdec1e9f8a1bb519e7dda05c7ad4065 100644 (file)
@@ -181,10 +181,9 @@ public class StockExpression implements IExpression {
                             Resource tail = graph.getPossibleObject(r, sr.HasTail);\r
                             if(tail != null) {\r
                                 Object name = graph.getPossibleRelatedValue(tail, b.HasName);\r
-                                if (name != null) {\r
-                                       System.out.println("STOCK += " + name);\r
+                                if (name != null) \r
                                     builder.append(" + " + name);\r
-                                }\r
+                                \r
                             }\r
                         }\r
                     }\r
index f66c3087bac480a6137e7fc6f59cbbac5e51a189..707d83a8ea32926cae5f50770527fbef9969ca3e 100644 (file)
@@ -39,6 +39,8 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;\r
 import org.simantics.db.common.request.ReadRequest;\r
 import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.SelectionHints;\r
+import org.simantics.diagram.stubs.DiagramResource;\r
 import org.simantics.modeling.ModelingResources;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.SysdynDataSet;\r
@@ -137,6 +139,7 @@ public class TrendView extends ViewPart {
                     return;\r
                 if(selection instanceof IStructuredSelection) {\r
                     Set<Resource> ress = ISelectionUtils.filterSetSelection(selection, Resource.class);\r
+                       Resource runtime = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_VARIABLE_RESOURCE, Resource.class);\r
 //                    Object[] els = ((IStructuredSelection) selection).toArray();\r
 //                    Resource[] resources = new Resource[els.length];\r
 //                    for(int i=0;i<els.length;++i) {\r
@@ -145,7 +148,7 @@ public class TrendView extends ViewPart {
 //                        else\r
 //                            return;\r
 //                    }\r
-                    setSelection(ress.toArray(Resource.NONE));\r
+                    setSelection(ress.toArray(Resource.NONE), runtime);\r
                 }                \r
             }\r
         });\r
@@ -161,13 +164,16 @@ public class TrendView extends ViewPart {
     }\r
 \r
     Resource[] resources;\r
+    Resource runtime;\r
 \r
-    protected void setSelection(Resource[] resources) {\r
+    protected void setSelection(Resource[] resources, Resource runtime) {\r
         this.resources = resources;\r
+        this.runtime = runtime;\r
         updateView();\r
     }\r
 \r
     public void updateView() {\r
+       \r
         Session session = SimanticsUI.peekSession();\r
         if (session == null)\r
             return;\r
@@ -178,9 +184,9 @@ public class TrendView extends ViewPart {
 \r
                 final ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
                 for(Resource resource : resources) {\r
-                    Collection<SysdynDataSet> set = load(g, resource);\r
+                    Collection<SysdynDataSet> set = load(g, resource, runtime);\r
                     if(set == null) return;\r
-                    datasets.addAll(load(g, resource));\r
+                    datasets.addAll(load(g, resource, runtime));\r
                 }
 \r
                 SwingUtilities.invokeLater(new Runnable() {\r
@@ -218,19 +224,25 @@ public class TrendView extends ViewPart {
         }\r
     }\r
 \r
-    protected Collection<SysdynDataSet> load(ReadGraph g, Resource resource) throws DatabaseException {\r
+    protected Collection<SysdynDataSet> load(ReadGraph g, Resource resource, Resource runtime) throws DatabaseException {\r
         Builtins b = g.getBuiltins();\r
         SysdynResource sr = SysdynResource.getInstance(g);\r
 \r
+        DiagramResource dr = DiagramResource.getInstance(g);\r
+        \r
+//        String rvi = g.getPossibleRelatedValue(runtime, dr.HasRVI);\r
+//        System.out.println("load results rvi='" + rvi + "'");\r
+        String prefix = "";\r
+        \r
         ModelingResources mr = ModelingResources.getInstance(g);\r
         Resource map = g.getPossibleObject(resource, mr.ElementToComponent);\r
         if(map != null) resource = map;\r
 \r
         if(g.isInstanceOf(resource, sr.Variable)) {\r
             Resource module = g.getPossibleObject(resource, b.PartOf);\r
-            while(!g.isInstanceOf(module, sr.Configuration)) {\r
-                module = g.getPossibleObject(module, b.PartOf);\r
-            }\r
+//            while(!g.isInstanceOf(module, sr.Configuration)) {\r
+//                module = g.getPossibleObject(module, b.PartOf);\r
+//            }\r
             if(g.isInstanceOf(module, sr.Configuration)) {\r
                 SysdynModel model = getModel(g, module);\r
                 if(model == null)\r
@@ -243,7 +255,7 @@ public class TrendView extends ViewPart {
                     Collection<SysdynResult> activeResults =  model.getActiveResults(g);\r
                     ArrayList<SysdynDataSet> datasets = new ArrayList<SysdynDataSet>();\r
                     for(SysdynResult r : activeResults) {\r
-                        SysdynDataSet sdds = r.getDataSet(var.getName());\r
+                        SysdynDataSet sdds = r.getDataSet(prefix + var.getName());\r
                         if(sdds != null) datasets.add(sdds);\r
                     }\r
                     return datasets;\r
index 500148246a7cc9207d57d89842b35a32ddf67518..430564432867841cd421ef743a6446bdda111fe5 100644 (file)
@@ -44,6 +44,7 @@ public class SysdynResult {
     }\r
 \r
     public SysdynResult(String result, String path) {\r
+       System.out.println("sysdynresult " + result + " " + path);\r
         this.resultName = result;\r
         File file = new File(path);\r
         try {\r
index 20908392b9a09c57ef56be23258c28816b16e84b..c6e9f606c1b62fac8f67874cbd46a5be1ae93607 100644 (file)
@@ -183,7 +183,7 @@ Module <T ST.Component
     [L0.HasLabel card "1"]\r
      \r
 ModuleSymbol <T DIA.FontProvider <T DIA.ColorProvider\r
-  defSymbol("Stock", Module)\r
+  defSymbol("ModuleSymbol", Module)\r
   ST.IsDefinedBy %list : DIA.Composite <R L0.HasNext\r
       _ : SysdynTerminal\r
         terminal(ModuleSymbol, IsHeadOfTerminal)\r
@@ -841,16 +841,16 @@ CapacityModuleConfiguration @ "Kapasiteettimoduulikonfiguraatio" : Configuration
       #tag(IsInput)\r
 \r
     ### Dependencies    \r
-    _ : Flow\r
+    Flow3 : Flow\r
       HasHead Investment\r
       HasTail DummyCloud2  \r
-    _ : Flow\r
+    Flow4 : Flow\r
       HasHead CapacityStock\r
       HasTail Investment  \r
-    _ : Flow\r
+    Flow5 : Flow\r
       HasHead Reductions\r
       HasTail CapacityStock\r
-    _ : Flow\r
+    Flow6 : Flow\r
       HasHead DummyCloud3\r
       HasTail Reductions                    \r
     _  : Dependency\r
@@ -890,6 +890,43 @@ CapacityModuleConfiguration @ "Kapasiteettimoduulikonfiguraatio" : Configuration
       HasHead Investment\r
       HasTail CapacityAdjustment                                     \r
       \r
+CapacityModuleConfigurationDiagram : ConfigurationDiagram <R L0.HasNext\r
+  MOD.DiagramToComposite CapacityModuleConfiguration\r
+  DIA.HasLayer _ @ "Admin" : DIA.Layer\r
+    DIA.IsActive "true" : L0.Boolean\r
+    DIA.HasFocusableTag AdminIsFocusable\r
+    DIA.HasVisibleTag AdminIsVisible\r
+  #L0.HasTrigger _ : DiagramToCompositeMapping\r
+  %list_elements\r
+    DummyCloud2Element : CloudSymbol\r
+        MOD.ElementToComponent DummyCloud2\r
+        DIA.HasTransform "1.0, 0.0, 0.0, 1.0, 85.0, 90.0" : G2D.Transform\r
+    InvestmentElement : ValveSymbol\r
+        MOD.ElementToComponent Investment\r
+        DIA.HasTransform "1.0, 0.0, 0.0, 1.0, 100.0, 90.0" : G2D.Transform\r
+    CapacityStockElement : StockSymbol\r
+        MOD.ElementToComponent CapacityStock\r
+        DIA.HasTransform "1.0, 0.0, 0.0, 1.0, 115.0, 90.0" : G2D.Transform\r
+    ReductionsElement : ValveSymbol\r
+        MOD.ElementToComponent Reductions\r
+        DIA.HasTransform "1.0, 0.0, 0.0, 1.0, 130.0, 90.0" : G2D.Transform\r
+    DummyCloud3Element : CloudSymbol\r
+        MOD.ElementToComponent DummyCloud3\r
+        DIA.HasTransform "1.0, 0.0, 0.0, 1.0, 145.0, 90.0" : G2D.Transform\r
+    _ : FlowConnection\r
+        MOD.DiagramConnectionToConnection Flow3\r
+        flow(DummyCloud2Element, InvestmentElement)\r
+    _ : FlowConnection\r
+        MOD.DiagramConnectionToConnection Flow4\r
+        flow(InvestmentElement, CapacityStockElement)\r
+    _ : FlowConnection\r
+        MOD.DiagramConnectionToConnection Flow5\r
+        flow(CapacityStockElement, ReductionsElement)\r
+    _ : FlowConnection\r
+        MOD.DiagramConnectionToConnection Flow6\r
+        flow(ReductionsElement, DummyCloud3Element)\r
+\r
+\r
 CustomerModule @ "Asiakasmoduuli" <T Module\r
   ST.IsDefinedBy CustomerModuleConfiguration\r
 \r