]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@20802 ac1ea38d...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 May 2011 10:36:33 +0000 (10:36 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 6 May 2011 10:36:33 +0000 (10:36 +0000)
15 files changed:
simantics-1.4/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java
simantics-1.4/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
simantics-1.4/org.simantics.sysdyn.ui/plugin.xml
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportExternalFunctionFilesHandler.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java [new file with mode: 0644]
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportFunctionLibrary.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java [new file with mode: 0644]
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/RemoveNodeHandler.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ExternalFilesTab.java
simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
simantics-1.4/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
simantics-1.4/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Module.java

index 49abb2b50161a98de3b927de7996f3f68ae81a23..19043005e069a01535c3db8f7dc9c5df54b40c76 100644 (file)
@@ -1,3 +1,14 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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.modelica.data;\r
 \r
 import java.io.InputStream;\r
@@ -12,13 +23,13 @@ public class CSVSimulationResult extends SimulationResult {
        \r
        @Override\r
     public void read(InputStream stream) {\r
+               errors.clear();\r
                \r
                // First line contains the variable names in format "name" (including quotes);\r
                String line = getLine(stream);\r
                if(line == null)\r
                        return;\r
                \r
-               // FIXME: yks elementti liikaa alusta.\r
                line = line.substring(1, line.lastIndexOf("\""));\r
                String[] names = line.split("\",\"");\r
                \r
@@ -38,8 +49,12 @@ public class CSVSimulationResult extends SimulationResult {
                                        try {\r
                                                valueMap.get(names[i]).add(Double.parseDouble(values[i]));\r
                                        } catch (NumberFormatException e) {\r
-                                               e.printStackTrace();\r
-                                               break;\r
+                                               ArrayList<TimeValuePair> list = errors.get(names[i]);\r
+                                               if(list == null) {\r
+                                                       list = new ArrayList<TimeValuePair>();\r
+                                                       errors.put(names[i], list);\r
+                                               }\r
+                                               list.add(new TimeValuePair(values[0], values[i]));\r
                                        }\r
                                }\r
                        }\r
@@ -51,5 +66,4 @@ public class CSVSimulationResult extends SimulationResult {
                variables.add(ds);\r
         }\r
     }\r
-    \r
 }\r
index 85779106c1d6317927b025260a646e8d7859e952..2e104443932087c541d0624b633376aba5e7cdab 100644 (file)
@@ -30,6 +30,18 @@ public class SimulationResult {
 \r
     List<DataSet> variables = new ArrayList<DataSet>();\r
     List<DataSet> initials = new ArrayList<DataSet>();\r
+    \r
+       class TimeValuePair {\r
+               public String time;\r
+               public String value;\r
+               \r
+               public TimeValuePair(String time, String value) {\r
+                       this.time = time;\r
+                       this.value = value;\r
+               }\r
+       }\r
+       \r
+       HashMap<String, ArrayList<TimeValuePair>> errors = new HashMap<String, ArrayList<TimeValuePair>>();\r
 \r
     static String getLine(InputStream stream) {\r
         if(stream == null)\r
@@ -172,4 +184,24 @@ public class SimulationResult {
                 return set;\r
         return null;\r
     }\r
+    \r
+    \r
+    /**\r
+     * Return errors encountered during reading of the results.\r
+     * \r
+     * @return\r
+     */\r
+    public String getResultReadErrors() {\r
+       StringBuilder errorString = new StringBuilder();\r
+        if(!errors.isEmpty()) {\r
+               errorString.append("Number format errors (Time, Value):\n");\r
+               for(String key : errors.keySet()) {\r
+                       errorString.append("\n" + key + ":\n");\r
+                       for(TimeValuePair tv : errors.get(key)) {\r
+                               errorString.append("    " + tv.time + ", " + tv.value + "\n");\r
+                       }\r
+               }\r
+        }\r
+        return errorString.toString();\r
+    }\r
 }\r
index 83a652e35b8d044c577ecc6ce1172a89da8dd79b..49de4a6929dd255ffca1539e984d2bb07b0e2bd9 100644 (file)
                </visibleWhen>\r
             </command>\r
             <command\r
-                  commandId="org.simantics.sysdyn.ui.importModuleLibrary"\r
-                  label="Module library"\r
+                  commandId="org.simantics.sysdyn.ui.importModule"\r
+                  label="Module"\r
                   style="push">\r
                <visibleWhen\r
                      checkEnabled="true">\r
                </visibleWhen>\r
             </command>\r
             <command\r
-                  commandId="org.simantics.sysdyn.ui.exportModuleLibrary"\r
-                  label="Module library"\r
+                  commandId="org.simantics.sysdyn.ui.exportModule"\r
+                  label="Module"\r
                   style="push">\r
                <visibleWhen\r
                      checkEnabled="true">\r
       </menuContribution>\r
       <menuContribution\r
             locationURI="popup:#ExternalFunctionFileBrowser?after=wbStart">\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.importExternalFunctionFile"\r
-               label="Import Files"\r
-               style="push">\r
-         </command>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.exportExternalFunctionFile"\r
-               label="Export Files"\r
-               style="push">\r
-         </command>\r
-         <command\r
-               commandId="org.simantics.sysdyn.ui.removeNode"\r
-               icon="icons/cross.png"\r
-               id="org.simantics.sysdyn.ui.browser.remove"\r
-               label="Remove"\r
-               style="push">\r
-            <visibleWhen\r
-                  checkEnabled="true">\r
-            </visibleWhen>\r
-         </command>\r
       </menuContribution>\r
    </extension>\r
    <extension\r
             id="org.simantics.sysdyn.ui.exportFunctionLibrary"\r
             name="Export Function Library">\r
       </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.importModule"\r
+            name="Import Module">\r
+      </command>\r
+      <command\r
+            id="org.simantics.sysdyn.ui.exportModule"\r
+            name="Export Module">\r
+      </command>\r
    </extension>\r
    <extension\r
          point="org.eclipse.ui.handlers">\r
             </with>\r
          </activeWhen>\r
       </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.ImportModuleHandler"\r
+            commandId="org.simantics.sysdyn.ui.importModule">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ModulesNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
+      <handler\r
+            class="org.simantics.sysdyn.ui.handlers.ExportModuleHandler"\r
+            commandId="org.simantics.sysdyn.ui.exportModule">\r
+         <activeWhen>\r
+            <with\r
+                  variable="selection">\r
+               <or>\r
+                  <test\r
+                        args="org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode"\r
+                        property="org.simantics.sysdyn.ui.nodeClass">\r
+                  </test>\r
+               </or>\r
+            </with>\r
+         </activeWhen>\r
+      </handler>\r
    </extension>\r
    <extension\r
          point="org.simantics.browsing.ui.common.viewpointContributionBinding">\r
index cf4b0ce8fcce8c7065a4f7ebdd8275a8424e8e94..754510d60e2155a3a1b71853a8a359afdd668e55 100644 (file)
@@ -44,8 +44,8 @@ public class FunctionLibraries  extends ViewpointContributor<FunctionsFolder> {
         }\r
         \r
         // Find model function libraries\r
-        for(Resource modelLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
-               new FunctionLibraryNode<Resource>(modelLibrary);\r
+        for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
+               result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
         }       \r
         \r
         Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.0");\r
index 96caea962d42ef166e0e3920fd2b1dfe78bb6c01..4b5aac4819960cb4760c42a7294353ed7b3c5de0 100644 (file)
@@ -146,7 +146,9 @@ public class InputFactory extends SysdynElementFactory {
                                                parent = ((ChildVariable)v).getParent(graph);\r
                                        if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) {\r
                                                String parentURI = parent.getURI(graph);\r
-                                               moduleName = (String) graph.getPossibleRelatedValue(graph.getResource(parentURI), l0.HasName);\r
+                                               Resource p = graph.getPossibleResource(parentURI);\r
+                                               if(p != null)\r
+                                                       moduleName = (String) graph.getPossibleRelatedValue(p, l0.HasName);\r
                                        }\r
                                        break;\r
                                }\r
index 84573763920e5563768915299f6902bdd34b55af..727bb8be423ec09769fcb7371276e470759b1d98 100644 (file)
@@ -44,6 +44,10 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler {
                if (resources.length < 1)\r
                        return null;\r
 \r
+               return exportFiles(shell, resources);\r
+       }\r
+       \r
+       public static Object exportFiles(Shell shell, final Resource[] resources) {\r
                DirectoryDialog dd = new DirectoryDialog(shell);\r
                dd.setFilterPath(Platform.getLocation().toOSString());\r
                dd.setText("Export files to...");\r
@@ -72,7 +76,6 @@ public class ExportExternalFunctionFilesHandler extends AbstractHandler {
                                \r
                        }\r
                });\r
-\r
                return null;\r
        }\r
 \r
diff --git a/simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java b/simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ExportModuleHandler.java
new file mode 100644 (file)
index 0000000..17b5bd0
--- /dev/null
@@ -0,0 +1,244 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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 java.io.File;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\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.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.MessageBox;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.primitiverequest.PossibleRelatedValue;\r
+import org.simantics.db.common.request.ObjectsWithType;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.util.TransferableGraphRequest2;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.ResourceAdaptionUtils;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public class ExportModuleHandler  extends AbstractHandler {\r
+\r
+       /**\r
+        * Temporary exception. At this phase, the system will not support exporting modules\r
+        * that depend on other modules. \r
+        * \r
+        * @author TLTEEMU\r
+        *\r
+        */\r
+       class ContainsDependenciesException extends DatabaseException {\r
+               private static final long serialVersionUID = -1533706136673146020L;\r
+               \r
+               private Collection<String> dependencies;\r
+               \r
+               ContainsDependenciesException(Collection<String> dependencies) {\r
+                       this.dependencies = dependencies;\r
+               }\r
+               \r
+               public Collection<String> getDependencies() {\r
+                       return this.dependencies;\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        final Resource modulesymbol = ResourceAdaptionUtils.toSingleResource(sel);\r
+        if(modulesymbol == null) return null;\r
+               \r
+               String name = null;\r
+               try {\r
+                       name = SimanticsUI.getSession().syncRequest(new Read<String>() {\r
+\r
+                               @Override\r
+                               public String perform(ReadGraph graph) throws DatabaseException {\r
+                                       ModelingResources mr = ModelingResources.getInstance(graph);\r
+                                       StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                       Layer0 l0 = Layer0.getInstance(graph);\r
+                                       \r
+                                       Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
+                                       if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
+                                               return null;\r
+                                       \r
+                                       Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+                                       if (configuration == null)\r
+                                               return null;\r
+                                       \r
+                                       ArrayList<String> dependencies = null;\r
+                                       for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Module))) {\r
+                                               if(dependencies == null)\r
+                                                       dependencies = new ArrayList<String>();\r
+                                               String name = NameUtils.getSafeName(graph, r);\r
+                                               String instanceOf = NameUtils.getSafeName(graph, graph.getSingleObject(r, l0.InstanceOf));\r
+                                               dependencies.add(name + " : " + instanceOf);\r
+                                       }\r
+                                       if(dependencies != null && !dependencies.isEmpty())\r
+                                               throw new ContainsDependenciesException(dependencies);\r
+                                       \r
+                                       String name = graph.getPossibleRelatedValue(component, l0.HasName, Bindings.STRING);\r
+                                       return name;\r
+                                       \r
+                               }\r
+                               \r
+                       });\r
+               } catch (ContainsDependenciesException e1) {\r
+                       Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+                       MessageBox mb = new MessageBox(shell, SWT.OK);\r
+                       StringBuilder sb = new StringBuilder();\r
+                       sb.append("This version does not support exporting modules with other module instances.\n\n");\r
+                       sb.append("Dependencies:\n");\r
+                       for(String s : e1.getDependencies())\r
+                               sb.append("    " + s + "\n");\r
+                       mb.setMessage(sb.toString());\r
+                       mb.setText("Module contains dependencies.");\r
+                       mb.open();\r
+                       return null;\r
+               } catch (DatabaseException e1) {\r
+                       e1.printStackTrace();\r
+               }\r
+               if(name == null) return null;\r
+               \r
+               Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+               FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+               fd.setText("Export..");\r
+               fd.setFileName(name);\r
+               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               String[] filterExt = {"*.tg"};\r
+               fd.setFilterExtensions(filterExt);\r
+               final String selected = fd.open();\r
+               if(selected == null) return null;\r
+               \r
+               \r
+               SimanticsUI.getSession().asyncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph graph) throws DatabaseException {\r
+                               Layer0 l0 = Layer0.getInstance(graph);\r
+                               ModelingResources mr = ModelingResources.getInstance(graph);\r
+\r
+                               final Resource component = graph.getPossibleObject(modulesymbol, mr.SymbolToComponentType);\r
+                               if (component == null || !graph.hasStatement(component, Layer0.getInstance(graph).PartOf))\r
+                                       return;\r
+                               String name = graph.syncRequest(new PossibleRelatedValue<String>(component, l0.HasName, Bindings.STRING ));\r
+                               final ArrayList<Pair<Resource, String>> roots = new ArrayList<Pair<Resource, String>>();\r
+                               roots.add(Pair.make(component, name));\r
+\r
+                               graph.asyncRequest(new WriteRequest() {\r
+\r
+                                       @Override\r
+                                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                                               Layer0 l0 = Layer0.getInstance(graph);\r
+                                               StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+\r
+                                               Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+                                               if (!graph.hasStatement(configuration, l0.PartOf, component)&& \r
+                                                               !graph.hasStatement(modulesymbol, l0.PartOf, component)) {\r
+                                                       // Make sure that configuration and symbol are included.\r
+                                                       // In old versions, they were attached to model, not to module.\r
+                                                       Resource previousPartof = graph.getSingleObject(configuration, l0.PartOf);\r
+\r
+                                                       graph.deny(configuration, l0.PartOf);\r
+                                                       graph.deny(modulesymbol, l0.PartOf);\r
+                                                       graph.claim(configuration, l0.PartOf, l0.ConsistsOf, component);\r
+                                                       graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, component);\r
+\r
+                                                       export(graph, selected, roots, component);\r
+\r
+                                                       graph.deny(configuration, l0.PartOf);\r
+                                                       graph.deny(modulesymbol, l0.PartOf);\r
+                                                       graph.claim(configuration, l0.PartOf, l0.ConsistsOf, previousPartof);\r
+                                                       graph.claim(modulesymbol, l0.PartOf, l0.ConsistsOf, previousPartof);\r
+                                               } else {\r
+                                                       // Normal export\r
+                                                       export(graph, selected, roots, component);\r
+                                               }\r
+                                       }\r
+                               });\r
+\r
+                       }\r
+               });\r
+\r
+               return null;\r
+       }\r
+       \r
+       /**\r
+        * Export module (without dependencies to other modules) and write it to file. \r
+        * Disable existing enumeration replacement for during export.  \r
+        *  \r
+        * @param graph WriteGraph\r
+        * @param path Path for the exported file\r
+        * @param roots\r
+        * @param component Module\r
+        */\r
+       private void export(WriteGraph graph, String path, ArrayList<Pair<Resource, String>> roots, Resource component) {\r
+               \r
+               // FIXME: Enumeration replacement handling like this is not suitable.\r
+               try {\r
+                       Layer0 l0 = Layer0.getInstance(graph);\r
+                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                       StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
+\r
+                       Resource configuration = graph.getPossibleObject(component, sr2.IsDefinedBy);\r
+                       ArrayList<Pair<Resource, Resource>> replacements = new ArrayList<Pair<Resource, Resource>>();\r
+\r
+                       for(Resource enumeration : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {\r
+                               if(graph.hasStatement(enumeration, sr.ReplacedEnumeration_Inverse)) {\r
+                                       for(Resource replacement : graph.getObjects(enumeration, sr.ReplacedEnumeration_Inverse)) {\r
+                                               replacements.add(new Pair<Resource, Resource>(enumeration, replacement));\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       for(Pair<Resource,Resource> replacement : replacements)\r
+                               graph.deny(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second);\r
+                       \r
+                       TransferableGraph1 tg = graph.syncRequest(new TransferableGraphRequest2(roots, component));\r
+                       Files.createFile(new File(path), Bindings.getBindingUnchecked(TransferableGraph1.class), tg);\r
+                       \r
+                       for(Pair<Resource,Resource> replacement : replacements)\r
+                               graph.claim(replacement.first, sr.ReplacedEnumeration_Inverse, replacement.second);\r
+\r
+               } catch (RuntimeBindingConstructionException e) {\r
+                       e.printStackTrace();\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+               } catch (DatabaseException e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+}
\ No newline at end of file
index bf16f6c9c20b9ebd6f44fcae801f14b9d3d15a07..3193d41635a1d6c0ba4c21d333f6b8b0d76ee2e8 100644 (file)
@@ -43,19 +43,24 @@ import org.simantics.layer0.Layer0;
 import org.simantics.layer0.utils.direct.GraphUtils;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.manager.FunctionUtils;\r
+import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
 import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
 import org.simantics.ui.utils.ResourceAdaptionUtils;\r
 \r
 public class ImportFunctionLibrary  extends AbstractHandler {\r
 \r
        @Override\r
        public Object execute(ExecutionEvent event) throws ExecutionException {\r
-               Resource project = SimanticsUI.getProject().get();\r
-               if(project == null) return null;\r
-\r
         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
-        final Resource functionLibrary = ResourceAdaptionUtils.toSingleResource(sel);\r
-        if(functionLibrary == null) return null;\r
+        Resource r = ResourceAdaptionUtils.toSingleResource(sel);\r
+        if(r == null) {\r
+               FunctionsFolder mn = AdaptionUtils.adaptToSingle(sel, FunctionsFolder.class);\r
+               r = mn.data;\r
+        }\r
+        if(r == null) return null;\r
+        \r
+        final Resource functionLibrary = r;\r
         \r
                Shell shell = HandlerUtil.getActiveShellChecked(event);\r
                FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
diff --git a/simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java b/simantics-1.4/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/ImportModuleHandler.java
new file mode 100644 (file)
index 0000000..c973385
--- /dev/null
@@ -0,0 +1,82 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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 java.io.File;\r
+import java.io.IOException;\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.core.runtime.Platform;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.simantics.browsing.ui.common.node.AbstractNode;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.Files;\r
+import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteHandler;\r
+import org.simantics.db.layer0.adapter.impl.DefaultPasteImportAdvisor;\r
+import org.simantics.graph.db.MissingDependencyException;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.ui.utils.AdaptionUtils;\r
+\r
+public class ImportModuleHandler extends AbstractHandler {\r
+\r
+       @Override\r
+       public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        ISelection sel = HandlerUtil.getCurrentSelection(event);\r
+        \r
+        @SuppressWarnings("unchecked")\r
+               AbstractNode<Resource> node = AdaptionUtils.adaptToSingle(sel, AbstractNode.class);\r
+        if (node == null)\r
+            return null;\r
+\r
+        final Resource model = node.data;\r
+        \r
+               Shell shell = HandlerUtil.getActiveShellChecked(event);\r
+               FileDialog fd = new FileDialog(shell, SWT.OPEN);\r
+               fd.setText("Import Module");\r
+               fd.setFilterPath(Platform.getLocation().toOSString());\r
+               String[] filterExt = {"*.tg"};\r
+               fd.setFilterExtensions(filterExt);\r
+               String selected = fd.open();\r
+               if(selected == null) return null;\r
+\r
+               TransferableGraph1 tg = null;\r
+               try {\r
+                       tg = (TransferableGraph1)Files.readFile(new File(selected), Bindings.getBindingUnchecked(TransferableGraph1.class));\r
+               } catch (RuntimeBindingConstructionException e) {\r
+                       e.printStackTrace();\r
+               } catch (IOException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               if(tg == null) return null;\r
+\r
+               \r
+               DefaultPasteImportAdvisor ia = new DefaultPasteImportAdvisor(model);\r
+               try {\r
+                       DefaultPasteHandler.defaultExecute(tg, model, ia);\r
+               } catch (MissingDependencyException e) {\r
+                       e.printStackTrace();\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+               \r
+               return null;\r
+       }\r
+\r
+}\r
index 5f8a66fb69640a73eb5afaad6df3edd551ed4c67..a6c4e6c04e6aa7593c070de33397bd5ab1829fc3 100644 (file)
@@ -68,7 +68,7 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 Resource configuration = GraphUtils.create2(g, \r
                         sr.Configuration,\r
                         l0.HasName, name + "Configuration",\r
-                        l0.PartOf, model);\r
+                        l0.PartOf, moduleType);\r
                 \r
                 g.claim(moduleType, sr2.IsDefinedBy , configuration);\r
                 \r
@@ -92,10 +92,10 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 \r
                 Resource moduleSymbol = g.newResource();\r
                 g.claimLiteral(moduleSymbol, l0.HasName, name + " Symbol");\r
-                g.claimLiteral(moduleSymbol, l0.HasLabel, name);\r
+                g.claimLiteral(moduleSymbol, l0.HasLabel, name + " Symbol");\r
                 g.claim(moduleSymbol, l0.Inherits, sr.ModuleSymbol);\r
                 g.claim(moduleSymbol, mr.SymbolToComponentType, moduleType);\r
-                g.claim(moduleSymbol, l0.PartOf, model);\r
+                g.claim(moduleSymbol, l0.PartOf, moduleType);\r
                 \r
                 Resource terminal = g.newResource();\r
                 g.claim(terminal, l0.InstanceOf, sr.SysdynTerminal);\r
index 0391d90b425794f1fac21651b8571568a1208ee0..e2ee3669972ce9ac3815d23a149ae17486b984d5 100644 (file)
@@ -50,7 +50,7 @@ public class RemoveNodeHandler extends AbstractHandler {
         return null;\r
     }\r
 \r
-    private void deleteItem(final Resource[] resources) {\r
+    public static void deleteItem(final Resource[] resources) {\r
         try {\r
             SimanticsUI.getSession().syncRequest(new WriteRequest() {\r
                 @Override\r
index b965ed6a28cbb4595b3576a067918bc9bd9981dc..407ea60c4d9b16d06a972671d6e1a5d571d7acc5 100644 (file)
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.properties;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.eclipse.jface.dialogs.MessageDialog;\r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.jface.viewers.ISelectionProvider;\r
+import org.eclipse.jface.viewers.IStructuredSelection;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.eclipse.swt.widgets.Control;\r
 import org.eclipse.swt.widgets.Shell;\r
 import org.eclipse.swt.widgets.Tree;\r
 import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.AdaptableHintContext;\r
 import org.simantics.browsing.ui.swt.SingleSelectionInputSource;\r
 import org.simantics.browsing.ui.swt.widgets.Button;\r
 import org.simantics.browsing.ui.swt.widgets.GraphExplorerComposite;\r
@@ -30,7 +38,9 @@ import org.simantics.db.WriteGraph;
 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.sysdyn.ui.handlers.ExportExternalFunctionFilesHandler;\r
 import org.simantics.sysdyn.ui.handlers.ImportExternalFunctionFilesHandler;\r
+import org.simantics.sysdyn.ui.handlers.RemoveNodeHandler;\r
 import org.simantics.ui.SimanticsUI;\r
 import org.simantics.utils.datastructures.ArrayMap;\r
 import org.simantics.utils.datastructures.Pair;\r
@@ -38,7 +48,7 @@ import org.simantics.utils.datastructures.Pair;
 public class ExternalFilesTab extends LabelPropertyTabContributor implements Widget {\r
 \r
        GraphExplorerComposite externalFilesExplorer;\r
-       Button importButton; \r
+       Button importButton, exportButton, removeButton\r
        \r
        @Override\r
        public void createControls(Composite body, IWorkbenchSite site,\r
@@ -67,7 +77,12 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                if (c instanceof Tree)\r
                        ((Tree) c).setLinesVisible(true);\r
                \r
-               importButton = new Button(composite, support, SWT.NONE);\r
+               \r
+               Composite buttonRow = new Composite(composite, SWT.NONE);\r
+               GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonRow);\r
+               GridDataFactory.fillDefaults().grab(true, false).applyTo(buttonRow);\r
+               \r
+               importButton = new Button(buttonRow, support, SWT.NONE);\r
                importButton.setText("Import");\r
                importButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
 \r
@@ -84,7 +99,7 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                                                final Pair<String, String[]> importedFiles = ImportExternalFunctionFilesHandler.importFiles(shell, "Import files", ImportExternalFunctionFilesHandler.C_EXTENSIONS);\r
                                                \r
                                                SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
-                                                       \r
+\r
                                                        @Override\r
                                                        public void perform(WriteGraph graph) throws DatabaseException {\r
                                                                ImportExternalFunctionFilesHandler.addFilesToFunction(graph, input, importedFiles);\r
@@ -92,11 +107,65 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                                                });\r
                                        }\r
                                });\r
-                               \r
-                               \r
+\r
+\r
+                       }\r
+               });\r
+\r
+               exportButton = new Button(buttonRow, support, SWT.NONE);\r
+               exportButton.setText("Export");\r
+               exportButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, final Resource input)\r
+                       throws DatabaseException {\r
+\r
+                               exportButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+                                       @Override\r
+                                       public void run() {\r
+                                               Shell shell = exportButton.getWidget().getShell();\r
+                                               List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+                                               Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+                                               if (resources.length > 0)\r
+                                                       ExportExternalFunctionFilesHandler.exportFiles(shell, resources);\r
+                                       }\r
+                               });\r
+\r
+\r
+                       }\r
+               });\r
+\r
+               removeButton = new Button(buttonRow, support, SWT.NONE);\r
+               removeButton.setText("Remove");\r
+               removeButton.addSelectionListener(new SelectionListenerImpl<Resource>(context) {\r
+\r
+                       @Override\r
+                       public void apply(WriteGraph graph, final Resource input)\r
+                       throws DatabaseException {\r
+\r
+                               removeButton.getWidget().getDisplay().asyncExec(new Runnable() {\r
+\r
+                                       @Override\r
+                                       public void run() {\r
+                                               Shell shell = removeButton.getWidget().getShell();\r
+\r
+                                               List<Resource> resourceList = getSelectedResources(externalFilesExplorer);\r
+                                               Resource[] resources = resourceList.toArray(new Resource[resourceList.size()]);\r
+                                               if(resources.length > 0) {\r
+                                                       MessageDialog dialog = new MessageDialog(shell, resources.length > 1 ? "Remove selected items" : "Remove selected item" , null, "Are you sure?", 0,\r
+                                                                       new String[] { "OK", "Cancel" }, 0);\r
+                                                       dialog.create();\r
+                                                       if (dialog.open() == 0) {\r
+                                                               RemoveNodeHandler.deleteItem(resources);\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               });\r
+\r
+\r
                        }\r
                });\r
-               \r
        }\r
 \r
        @Override\r
@@ -104,5 +173,21 @@ public class ExternalFilesTab extends LabelPropertyTabContributor implements Wid
                externalFilesExplorer.setInput(context, input);\r
        }\r
 \r
+       private List<Resource> getSelectedResources(GraphExplorerComposite explorer) {\r
+               List<Resource> result = new ArrayList<Resource>();\r
+               \r
+               ISelection selection = ((ISelectionProvider) explorer\r
+                               .getAdapter(ISelectionProvider.class)).getSelection();\r
+               if (selection == null)\r
+                       return result;\r
+               IStructuredSelection iss = (IStructuredSelection) selection;\r
+               @SuppressWarnings("unchecked")\r
+               List<AdaptableHintContext> selections = iss.toList();\r
+               for(AdaptableHintContext ahc : selections) {\r
+                       Resource resource = (Resource) ahc.getAdapter(Resource.class);\r
+                       result.add(resource);\r
+               }\r
+               return result;\r
+       }\r
 \r
 }\r
index fcc2f1049a6b48d22354611299d16d7c801664ac..c11c57b7deb4530c542a126076d9124125927c6f 100644 (file)
@@ -35,7 +35,7 @@ public class TrendView extends ViewPart {
        Frame frame;\r
        ChartPanel panel;\r
        SysdynDatasets sysdynDatasets = new SysdynDatasets();\r
-\r
+       SysdynDatasetSelectionListener sysdynDatasetSelectionListener;\r
 \r
        @SuppressWarnings("serial")\r
        class SysdynDatasets extends AbstractXYDataset {\r
@@ -107,7 +107,7 @@ public class TrendView extends ViewPart {
 \r
                });\r
 \r
-               getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(new SysdynDatasetSelectionListener() {\r
+               sysdynDatasetSelectionListener = new SysdynDatasetSelectionListener() {\r
 \r
                        @Override\r
                        protected void selectionChanged(final Collection<SysdynDataSet> activeDatasets) {\r
@@ -120,9 +120,17 @@ public class TrendView extends ViewPart {
 \r
                                });\r
                        }\r
-               });\r
+               };\r
+               \r
+               getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(sysdynDatasetSelectionListener);\r
 \r
        }\r
+       \r
+       @Override\r
+       public void dispose() {\r
+               super.dispose();\r
+               getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(sysdynDatasetSelectionListener);\r
+       }\r
 \r
        @Override\r
        public void setFocus() {\r
index ed8941b4b31f3a3387a8bcefa9efbede522e8373..748841a9f204e75008a2a51e29e0463fd800100c 100644 (file)
@@ -155,7 +155,7 @@ public class SysdynModel implements IMappingListener, IModel {
                this.modelResource = modelResource;\r
        }\r
 \r
-       public synchronized void simulate(IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException {\r
+       public synchronized void simulate(final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, final Experiment experiment) throws IOException {\r
                canceled = false;\r
                progressMonitor.subTask("Write modelica classes");\r
                ModelicaWriter writer = new ModelicaWriter();\r
@@ -255,6 +255,10 @@ public class SysdynModel implements IMappingListener, IModel {
                                                        resultChanged();\r
                                                        \r
                                                        setExperimentStopped(experiment);\r
+                                                       \r
+                                                       String errorString = result.getResultReadErrors();\r
+                                                       if(errorString != null && !errorString.isEmpty()) \r
+                                                               monitor.message(errorString);\r
                                                }\r
                                        } catch (FileNotFoundException e) {\r
                                                e.printStackTrace();\r
@@ -351,6 +355,7 @@ public class SysdynModel implements IMappingListener, IModel {
        public void resultChanged() {\r
                synchronized(resultListeners) {\r
                        for(Runnable listener : resultListeners) {\r
+                               System.out.println("Run resultListener");\r
                                listener.run();\r
                        }\r
                }\r
index 02fa9e8d008b394295187597b9d888565a6f4dd0..d04bc24041924c55caf9f63f00f4d90c2f4f3e8b 100644 (file)
@@ -52,7 +52,7 @@ public class Module implements IElement {
     /**\r
      * Returns the declaration of a module with possible redeclared enumerations\r
      * \r
-     * Module m(redeclare type E1 = enumeration(i1, i2, i3), redeclare type E2 = enumeration(i4, i5, i6));\r
+     * Module m(redeclared.size = enumeration.size, redeclared.elements = enumeration.elements);\r
      * \r
      * @return Declaration of a module instance\r
      */\r