]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Merge until trunk@25092 to branches/simantics-1.6 on 2012-06-01. refs #3455
authorlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 1 Jun 2012 12:22:30 +0000 (12:22 +0000)
committerlehtonen <lehtonen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 1 Jun 2012 12:22:30 +0000 (12:22 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/branches@25093 ac1ea38d-2e2b-0410-8846-a27921b304fc

37 files changed:
simantics-1.6/org.simantics.modelica/FMUSolution/FMUSolution.opensdf [deleted file]
simantics-1.6/org.simantics.modelica/src/org/simantics/modelica/data/CSVSimulationResult.java
simantics-1.6/org.simantics.modelica/src/org/simantics/modelica/data/Mat4Reader.java
simantics-1.6/org.simantics.modelica/src/org/simantics/modelica/data/MatSimulationResult.java
simantics-1.6/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
simantics-1.6/org.simantics.sysdyn.ontology/graph.tg
simantics-1.6/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
simantics-1.6/org.simantics.sysdyn.ontology/graph/SysdynFunctions.pgraph
simantics-1.6/org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/Configuration.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/FunctionLibraries.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/LibraryFunctions.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/browser/contributions/ModuleType.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/editor/participant/SysdynComponentCopyAdvisor.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/menu/PlaybackSliderContribution.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ConfigurationTab.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/ArrayExpressionCombo.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/NameAndArrayRangeModifyListener.java [new file with mode: 0644]
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/structure/ModuleStructureGraphRequest.java
simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/utils/ExpressionUtils.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/VariableRVIUtils.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/HistoryDatasetResult.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynExperiment.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynInitKeys.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynModel.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynPlaybackExperiment.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Book.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Configuration.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Sheet.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/WithLookupExpression.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/SheetFormatUtils.java
simantics-1.6/org.simantics.sysdyn/src/org/simantics/sysdyn/simulation/SimulationJob.java

diff --git a/simantics-1.6/org.simantics.modelica/FMUSolution/FMUSolution.opensdf b/simantics-1.6/org.simantics.modelica/FMUSolution/FMUSolution.opensdf
deleted file mode 100644 (file)
index f8442e6..0000000
Binary files a/simantics-1.6/org.simantics.modelica/FMUSolution/FMUSolution.opensdf and /dev/null differ
index 1c3b1e2f228ced7380a40a40c48378ff9c840833..8787adf946066afc8014938caef0be77d971defb 100644 (file)
@@ -28,7 +28,7 @@ public class CSVSimulationResult extends SimulationResult {
         * Overridden method to support csv-formatted simulation results\r
         */\r
        @Override\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int outputInterval) {\r
                errors.clear();\r
                \r
                // First line contains the variable names in format "name" (including quotes);\r
@@ -42,7 +42,7 @@ public class CSVSimulationResult extends SimulationResult {
                // Create lists for receiving values for each variable. Names still with quotes.\r
                for(String name : names) {\r
                        if(!name.isEmpty())\r
-                               valueMap.put(name, new DataSet(name, new double[numberOfTimeSteps], new double[numberOfTimeSteps]));\r
+                               valueMap.put(name, new DataSet(name, new double[numberOfLines], new double[numberOfLines]));\r
                }\r
 \r
                int row = 0;\r
index 0d89636832aed87990336826ff772a52ddf59969..ceafe6b0b097a3f971372654d7a2dc6f5d2936c0 100644 (file)
@@ -108,7 +108,14 @@ public class Mat4Reader {
         }\r
     }\r
 \r
-    public static Map<String, double[]> read(InputStream in) throws IOException {\r
+    /**\r
+     * \r
+     * @param in InputStream of a mat file\r
+     * @param outputInterval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc... \r
+     * @return\r
+     * @throws IOException\r
+     */\r
+    public static Map<String, double[]> read(InputStream in, int outputInterval) throws IOException {\r
         Mat4Reader reader = new Mat4Reader(in);\r
         reader.readMatrix(); // Header\r
         StringMatrix names = (StringMatrix)reader.readMatrix(); // Variable names\r
@@ -131,13 +138,17 @@ public class Mat4Reader {
         for(int i=0;i<info.columns;++i) {\r
             if(infoData[i*4] != 2)\r
                 continue;\r
-            double[] v = new double[values.columns];\r
+            // If values.columns % outputInterval != 0, the value in the last time step would not be displayed without adding a +1;\r
+            int size = values.columns % outputInterval != 0 ? values.columns / outputInterval + 1 : values.columns; \r
+            double[] v = new double[size];\r
             int sc = infoData[i*4+1];\r
             int c = sc > 0 ? sc-1 : 1-sc;\r
             //System.out.println("i=" + i + ", sc=" + sc + ", c=" + c);\r
-            for(int j=0;j<v.length;++j)\r
-                v[j] = valueData[rows*j+c];\r
-            if(sc < 0)\r
+            for(int j=0;j<v.length;++j) {\r
+               int adjusted = j * outputInterval;\r
+               if(adjusted >= values.columns) adjusted = values.columns - 1;\r
+                v[j] = valueData[rows * adjusted + c];\r
+            } if(sc < 0)\r
                 for(int j=0;j<v.length;++j)\r
                     v[j] = -v[j];\r
             result.put(names.data[i], v);\r
index e563d514212efd1c1ba972ccfd6cfbb48f1c6052..73a67d12b3adf6068834f47b632c8b2ddc3d4549 100644 (file)
@@ -24,10 +24,10 @@ import java.util.Map;
 public class MatSimulationResult extends SimulationResult {\r
     \r
     @Override\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int interval) {\r
         Map<String, double[]> valueMap = null;\r
         try {\r
-            valueMap =  Mat4Reader.read(stream);\r
+            valueMap =  Mat4Reader.read(stream, interval);\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
             return;\r
index 725d7e71befd5a111ed8dac7901f7aa8a2c8b871..a21a21554827d8c8a402b844108e3b59ea4e8c39 100644 (file)
@@ -50,7 +50,7 @@ public class SimulationResult {
 \r
     protected List<DataSet> variables = new ArrayList<DataSet>();\r
     protected List<DataSet> initials = new ArrayList<DataSet>();\r
-    protected int numberOfTimeSteps = 0;\r
+    protected int numberOfLines = 0;\r
     \r
     /**\r
      * Private class used in displaying errors\r
@@ -262,36 +262,50 @@ public class SimulationResult {
     }\r
 \r
 \r
-    final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)");\r
+    \r
+    /**\r
+     * Read result file. Read all values in the result file.\r
+     *  \r
+     * @param file result file\r
+     * @throws FileNotFoundException\r
+     * @throws IOException\r
+     */\r
+    public void read(File file) throws FileNotFoundException, IOException {\r
+       read(file, 1);\r
+    }\r
+\r
 \r
     /**\r
      * Read result file\r
      * \r
      * @param file result file\r
+     * @param interval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc...\r
      * @throws FileNotFoundException\r
      * @throws IOException\r
      */\r
-    public void read(File file) throws FileNotFoundException, IOException {\r
+    public void read(File file, int interval) throws FileNotFoundException, IOException {\r
         // First check the number of time steps\r
         FileReader fr = new FileReader(file);\r
         LineNumberReader  lnr = new LineNumberReader(fr);\r
         lnr.skip(Long.MAX_VALUE);\r
-        numberOfTimeSteps = lnr.getLineNumber() - 1; // minus the first row, which is for names\r
+        numberOfLines = lnr.getLineNumber() - 1; // minus the first row, which is for names\r
         lnr.close();\r
         fr.close();\r
 \r
         InputStream is = new FileInputStream(file);\r
-        read(is);\r
+        read(is, interval);\r
         is.close();\r
     }\r
 \r
-    \r
+    final static Pattern p1 = Pattern.compile("DataSet: ([^ ]*)");\r
+\r
     /**\r
      * Read result file. The basic implementation supports\r
      * plt-formatted results. Overridden to support other formats. \r
      * @param stream FileInputStream for the result file\r
+     * @param interval the interval of results to be read. 1 reads all time steps, 2 reads every other time step, etc...\r
      */\r
-    public void read(InputStream stream) {\r
+    public void read(InputStream stream, int outputInterval) {\r
         while(true) {\r
             String line = getLine(stream);\r
             if(line == null)\r
@@ -307,8 +321,8 @@ public class SimulationResult {
                 return;\r
             String name = matcher.group(1);\r
 \r
-            double[] dtimes = new double[numberOfTimeSteps];\r
-            double[] dvalues = new double[numberOfTimeSteps];\r
+            double[] dtimes = new double[numberOfLines];\r
+            double[] dvalues = new double[numberOfLines];\r
             int i = 0;\r
             while(true) {\r
                 String line = getLine(stream);\r
index efe3183fb9e739f23e8abc2e11d436338108becb..8185e6cc23e6ced9e888f380ad97437aa17e3792 100644 (file)
Binary files a/simantics-1.6/org.simantics.sysdyn.ontology/graph.tg and b/simantics-1.6/org.simantics.sysdyn.ontology/graph.tg differ
index 54086f8a7641f8498cf7cb66c3e5140c363c535c..9584de37c0429f9f399df38923116e466868edd3 100644 (file)
@@ -33,6 +33,7 @@ SYSDYN.SharedModuleOntolofgy <T L0.Ontology
 SYSDYN.SysdynModel <T MOD.StructuralModel
     >-- SYSDYN.SysdynModel.startTime --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.stopTime --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
+    >-- SYSDYN.SysdynModel.simulationStepLength --> L0.Double <R L0.HasProperty : L0.FunctionalRelation    
     >-- SYSDYN.SysdynModel.outputInterval --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.tolerance --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
     >-- SYSDYN.SysdynModel.solver --> L0.String <R L0.HasProperty : L0.FunctionalRelation
index 09ced343f87e7c384f8029f419f063ca68d97b9e..4595b360b43f5863b9f7d4f13368185f6fe660e8 100644 (file)
@@ -3,6 +3,15 @@ SYSDYN = <http://www.simantics.org/Sysdyn-1.1>
 \r
 FL = <http://www.simantics.org/Sysdyn-1.1/Built-in Functions> : SYSDYN.SysdynModelicaFunctionLibrary\r
 \r
+FL.minmax : SYSDYN.SysdynModelicaFunction\r
+    L0.HasDescription "Limits the result of an equation to between the given minimum and maximum values."\r
+    SYSDYN.SysdynModelicaFunction.modelicaFunctionCode """    input Real expression;\r
+    input Real minimum;\r
+    input Real maximum;\r
+    output Real result;\r
+algorithm\r
+    result := min(maximum, max(minimum, expression));"""\r
+\r
 \r
 FL.xidz : SYSDYN.SysdynModelicaFunction\r
     L0.HasDescription "X if divided by zero"\r
index d4ebd8ce13ec4404c754ddc316708117e0854f4b..79f98c2a6db7baa2f3968d040b5f4b653fc4073d 100644 (file)
@@ -51,6 +51,7 @@ public class SysdynResource {
     public final Resource Built$in_Functions_Vensim_Functions_ZIDZ;\r
     public final Resource Built$in_Functions_interpolate;\r
     public final Resource Built$in_Functions_interpolateFull;\r
+    public final Resource Built$in_Functions_minmax;\r
     public final Resource Built$in_Functions_xidz;\r
     public final Resource Built$in_Functions_zidz;\r
     public final Resource Center;\r
@@ -284,6 +285,8 @@ public class SysdynResource {
     public final Resource SysdynModel;\r
     public final Resource SysdynModel_outputInterval;\r
     public final Resource SysdynModel_outputInterval_Inverse;\r
+    public final Resource SysdynModel_simulationStepLength;\r
+    public final Resource SysdynModel_simulationStepLength_Inverse;\r
     public final Resource SysdynModel_solver;\r
     public final Resource SysdynModel_solver_Inverse;\r
     public final Resource SysdynModel_startTime;\r
@@ -401,6 +404,7 @@ public class SysdynResource {
         public static final String Built$in_Functions_Vensim_Functions_ZIDZ = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/Vensim%20Functions/ZIDZ";\r
         public static final String Built$in_Functions_interpolate = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolate";\r
         public static final String Built$in_Functions_interpolateFull = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/interpolateFull";\r
+        public static final String Built$in_Functions_minmax = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/minmax";\r
         public static final String Built$in_Functions_xidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/xidz";\r
         public static final String Built$in_Functions_zidz = "http://www.simantics.org/Sysdyn-1.1/Built-in%20Functions/zidz";\r
         public static final String Center = "http://www.simantics.org/Sysdyn-1.1/Center";\r
@@ -634,6 +638,8 @@ public class SysdynResource {
         public static final String SysdynModel = "http://www.simantics.org/Sysdyn-1.1/SysdynModel";\r
         public static final String SysdynModel_outputInterval = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval";\r
         public static final String SysdynModel_outputInterval_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/outputInterval/Inverse";\r
+        public static final String SysdynModel_simulationStepLength = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/simulationStepLength";\r
+        public static final String SysdynModel_simulationStepLength_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/simulationStepLength/Inverse";\r
         public static final String SysdynModel_solver = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/solver";\r
         public static final String SysdynModel_solver_Inverse = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/solver/Inverse";\r
         public static final String SysdynModel_startTime = "http://www.simantics.org/Sysdyn-1.1/SysdynModel/startTime";\r
@@ -761,6 +767,7 @@ public class SysdynResource {
         Built$in_Functions_Vensim_Functions_ZIDZ = getResourceOrNull(graph, URIs.Built$in_Functions_Vensim_Functions_ZIDZ);\r
         Built$in_Functions_interpolate = getResourceOrNull(graph, URIs.Built$in_Functions_interpolate);\r
         Built$in_Functions_interpolateFull = getResourceOrNull(graph, URIs.Built$in_Functions_interpolateFull);\r
+        Built$in_Functions_minmax = getResourceOrNull(graph, URIs.Built$in_Functions_minmax);\r
         Built$in_Functions_xidz = getResourceOrNull(graph, URIs.Built$in_Functions_xidz);\r
         Built$in_Functions_zidz = getResourceOrNull(graph, URIs.Built$in_Functions_zidz);\r
         Center = getResourceOrNull(graph, URIs.Center);\r
@@ -994,6 +1001,8 @@ public class SysdynResource {
         SysdynModel = getResourceOrNull(graph, URIs.SysdynModel);\r
         SysdynModel_outputInterval = getResourceOrNull(graph, URIs.SysdynModel_outputInterval);\r
         SysdynModel_outputInterval_Inverse = getResourceOrNull(graph, URIs.SysdynModel_outputInterval_Inverse);\r
+        SysdynModel_simulationStepLength = getResourceOrNull(graph, URIs.SysdynModel_simulationStepLength);\r
+        SysdynModel_simulationStepLength_Inverse = getResourceOrNull(graph, URIs.SysdynModel_simulationStepLength_Inverse);\r
         SysdynModel_solver = getResourceOrNull(graph, URIs.SysdynModel_solver);\r
         SysdynModel_solver_Inverse = getResourceOrNull(graph, URIs.SysdynModel_solver_Inverse);\r
         SysdynModel_startTime = getResourceOrNull(graph, URIs.SysdynModel_startTime);\r
index c874e0428c6fee8ca7b8080f3dbe5068469dedda..d50bfbc2ab00658f77e3999669bc8db57aa47d11 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.TreeMap;\r
 \r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
 import org.simantics.db.ReadGraph;\r
@@ -22,7 +23,6 @@ import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;\r
 import org.simantics.db.layer0.variable.Variables;\r
 import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ui.modelBrowser2.model.SheetsNode;\r
 import org.simantics.spreadsheet.resource.SpreadsheetResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.BookNode;\r
@@ -31,6 +31,7 @@ import org.simantics.sysdyn.ui.browser.nodes.EnumerationNode;
 import org.simantics.sysdyn.ui.browser.nodes.InputNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
 \r
 public class Configuration extends ViewpointContributor<ConfigurationNode<Resource>> {\r
 \r
@@ -44,37 +45,45 @@ public class Configuration extends ViewpointContributor<ConfigurationNode<Resour
                }\r
                \r
                SysdynResource sr = SysdynResource.getInstance(graph);\r
-               ArrayList<Variable> variables = new ArrayList<Variable>();\r
-               ArrayList<Variable> inputs = new ArrayList<Variable>();\r
-               ArrayList<Variable> modules = new ArrayList<Variable>();\r
-               ArrayList<Variable> enumerations = new ArrayList<Variable>();\r
+               TreeMap<String, Variable> variables = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+               TreeMap<String, Variable> inputs = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+               TreeMap<String, Variable> modules = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+               TreeMap<String, Variable> enumerations = new TreeMap<String, Variable>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+\r
 \r
                for(Variable child : variable.browseChildren(graph)) {\r
                        Resource represents = (Resource)child.getPropertyValue(graph, Variables.REPRESENTS);\r
                        if(graph.isInstanceOf(represents, sr.IndependentVariable)) {\r
-                               variables.add(child);\r
+                               variables.put(child.getName(graph), child);\r
                        } else if (graph.isInstanceOf(represents, sr.Input)) {\r
-                               inputs.add(child);\r
+                               inputs.put(child.getName(graph), child);\r
                        } else if (graph.isInstanceOf(represents, sr.Module)) {\r
-                               modules.add(child);\r
+                               modules.put(child.getName(graph), child);\r
                        } else if (graph.isInstanceOf(represents, sr.Enumeration)) {\r
-                               enumerations.add(child);\r
+                               enumerations.put(child.getName(graph), child);\r
                        }\r
                }\r
                \r
-               for (Variable v : variables) {\r
+               for (String s : variables.keySet()) {\r
+                       Variable v = variables.get(s);\r
                        Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
                        result.add(new VariableNode<Variable>(v, represents));\r
                }\r
-               for (Variable v : inputs) {\r
+               \r
+               for (String s : inputs.keySet()) {\r
+                       Variable v = inputs.get(s);\r
                        Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
                        result.add(new InputNode(v, represents));\r
                }\r
-               for (Variable v : modules) { \r
+               \r
+               for (String s : modules.keySet()) {\r
+                       Variable v = modules.get(s);\r
                        Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
                        result.add(new ModuleNode(v, represents));\r
                }\r
-               for (Variable v : enumerations) {\r
+               \r
+               for (String s : enumerations.keySet()) {\r
+                       Variable v = enumerations.get(s);\r
                        Resource represents = (Resource)v.getPropertyValue(graph, Variables.REPRESENTS);\r
                        result.add(new EnumerationNode(v, represents));\r
                }\r
index 87151394996dd77b890a6c018a3ca2ae9cf3e162..5cd6bbeeff727c0e1895fba170e0f6f9905241a4 100644 (file)
@@ -13,12 +13,14 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.TreeMap;\r
 \r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
@@ -26,6 +28,7 @@ import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;
 import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.FunctionsFolder;\r
 import org.simantics.sysdyn.ui.browser.nodes.SharedFunctionsFolder;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
 \r
 public class FunctionLibraries  extends ViewpointContributor<FunctionsFolder> {\r
 \r
@@ -38,16 +41,23 @@ public class FunctionLibraries  extends ViewpointContributor<FunctionsFolder> {
        \r
         ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
         \r
-        // Find model functions\r
+               TreeMap<String, Resource> sortResult = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+        // Find and sort model functions\r
         for(Resource function : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunction))) {\r
-               result.add(new FunctionNode(function));\r
+                       sortResult.put(NameUtils.getSafeName(graph, function), function);\r
         }\r
+               for(Resource function : sortResult.values())\r
+                       result.add(new FunctionNode(function));\r
         \r
-        // Find model function libraries\r
+        // Find and sort model function libraries\r
+               sortResult.clear();\r
         for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(functionsFolder.data, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
-               result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
-        }       \r
-        \r
+                       sortResult.put(NameUtils.getSafeName(graph, functionLibrary), functionLibrary);\r
+               }\r
+               for(Resource functionLibrary : sortResult.values())\r
+                       result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+               \r
+               // Find built-in functions\r
         Resource sysdyn = graph.getPossibleResource("http://www.simantics.org/Sysdyn-1.1");\r
         if(sysdyn != null) {\r
                for(Resource library : graph.syncRequest(new ObjectsWithType(sysdyn, l0.ConsistsOf, sr.SysdynModelicaFunctionLibrary))) {\r
index c37ea4657f8e81f0e69a738141ebe92503f76d29..6e3a1a1fa6ddcec185a53897eca789af50fc34f9 100644 (file)
@@ -13,17 +13,20 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.TreeMap;\r
 \r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\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.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.ui.browser.nodes.FunctionLibraryNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.FunctionNode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
 \r
 public class LibraryFunctions extends ViewpointContributor<FunctionLibraryNode<Resource>> {\r
 \r
@@ -32,16 +35,28 @@ public class LibraryFunctions extends ViewpointContributor<FunctionLibraryNode<R
                        FunctionLibraryNode<Resource> library) throws DatabaseException {\r
                Layer0 l0 = Layer0.getInstance(graph);\r
                ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();\r
+               \r
+               TreeMap<String, Resource> sortResult = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
+\r
+               // Find and sort functions in library\r
                for(Resource function : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunction))) {\r
-                       result.add(new FunctionNode(function));\r
+                       sortResult.put(NameUtils.getSafeName(graph, function), function);\r
                }\r
+               for(Resource function : sortResult.values())\r
+                       result.add(new FunctionNode(function));\r
+\r
+               // Find and sort libraries in library\r
+               sortResult.clear();\r
                for(Resource functionLibrary : graph.syncRequest(new ObjectsWithType(library.data, l0.ConsistsOf, SysdynResource.getInstance(graph).SysdynModelicaFunctionLibrary))) {\r
-                       result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+                       sortResult.put(NameUtils.getSafeName(graph, functionLibrary), functionLibrary);\r
                }\r
+               for(Resource functionLibrary : sortResult.values())\r
+                       result.add(new FunctionLibraryNode<Resource>(functionLibrary));\r
+               \r
                return result;\r
 \r
     }\r
-\r
+       \r
     @Override\r
     public String getViewpointId() {\r
         return "Standard";\r
index ed5a9ead174ae68949b9724168521b740d9107d8..4ebe335e712aea0e6c088e2fd67486ed2f4f33f2 100644 (file)
@@ -13,9 +13,11 @@ package org.simantics.sysdyn.ui.browser.contributions;
 \r
 import java.util.ArrayList;\r
 import java.util.Collection;\r
+import java.util.TreeMap;\r
 \r
 import org.simantics.browsing.ui.common.node.AbstractNode;\r
 import org.simantics.browsing.ui.graph.contributor.viewpoint.ViewpointContributor;\r
+import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.common.request.ObjectsWithType;\r
@@ -29,6 +31,7 @@ import org.simantics.sysdyn.ui.browser.nodes.InputNode;
 import org.simantics.sysdyn.ui.browser.nodes.ModuleNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.ModuleTypeNode;\r
 import org.simantics.sysdyn.ui.browser.nodes.VariableNode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
 \r
 public class ModuleType extends ViewpointContributor<ModuleTypeNode> {\r
 \r
@@ -44,18 +47,39 @@ public class ModuleType extends ViewpointContributor<ModuleTypeNode> {
 \r
                if(instance == null) return result;\r
                Resource conf = graph.getSingleObject(instance, str.IsDefinedBy);\r
+               \r
+               // Independent variables\r
+               TreeMap<String, Resource> variables = new TreeMap<String, Resource>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);\r
                for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.IndependentVariable))) {\r
-                       result.add(new VariableNode<Resource>(r));\r
+                       variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
                }\r
+               for(String key : variables.keySet())\r
+                       result.add(new VariableNode<Resource>(variables.get(key)));\r
+               \r
+               // Inputs\r
+               variables.clear();\r
                for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Input))) {\r
-                       result.add(new InputNode(r));\r
+                       variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
                }\r
+               for(String key : variables.keySet())\r
+                       result.add(new InputNode(variables.get(key)));\r
+               \r
+               // Modules\r
+               variables.clear();\r
                for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Module))) {\r
-                       result.add(new ModuleNode(r));\r
+                       variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
                }\r
+               for(String key : variables.keySet())\r
+                       result.add(new ModuleNode(variables.get(key)));\r
+               \r
+               // Enumerations\r
+               variables.clear();\r
                for(Resource r : graph.syncRequest(new ObjectsWithType(conf, l0.ConsistsOf, sr.Enumeration))) {\r
-                       result.add(new EnumerationNode(r));\r
+                       variables.put((String)graph.getPossibleRelatedValue(r, l0.HasName, Bindings.STRING), r);\r
                }\r
+               for(String key : variables.keySet())\r
+                       result.add(new EnumerationNode(variables.get(key)));\r
+               \r
                return result;\r
        }\r
 \r
index 62672a39f9dec1c52ccd600c9ea537e5def7ea01..94e3a9f02eaa6ad5562f16e24368f399d25c1b5a 100644 (file)
@@ -11,6 +11,8 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.ui.editor.participant;\r
 \r
+import java.util.Map;\r
+\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -26,10 +28,10 @@ import org.simantics.modeling.mapping.ComponentCopyAdvisor;
 import org.simantics.structural.stubs.StructuralResource2;\r
 import org.simantics.utils.datastructures.BinaryFunction;\r
 \r
-public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{\r
+public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor {\r
 \r
     @Override\r
-    public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer, Resource targetContainer) throws DatabaseException {\r
+    public Object copy(ISynchronizationContext context, WriteGraph graph, Resource source, Resource sourceContainer, Resource targetContainer, Map<Object, Object> map) throws DatabaseException {\r
        \r
        BinaryFunction<Boolean, ReadGraph, Statement> tester = new BinaryFunction<Boolean, ReadGraph, Statement>() {\r
 \r
@@ -56,7 +58,7 @@ public class SysdynComponentCopyAdvisor extends ComponentCopyAdvisor{
        \r
        StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
        if(graph.isInstanceOf(source, sr2.Connection)) {\r
-                copy = CopyAdvisorUtil.copy(graph, source, tester);\r
+                copy = CopyAdvisorUtil.copy(graph, source, tester, map);\r
        } else {\r
             copy = CopyAdvisorUtil.copy4(graph, source);\r
        }\r
index aae0b0ef51f9d66cbcf9b48136652bb0114147f9..27e3b551bdaad5b75e0fee2ade08acb214eb6259 100644 (file)
@@ -61,17 +61,16 @@ public class PlaybackSliderContribution extends ToolBarContributionItem {
                 return;\r
             spe = (SysdynPlaybackExperiment)experiment;\r
 \r
-            Double[] numbers = new Double[3];\r
+            Double[] numbers = new Double[2];\r
             try {\r
                 numbers = SimanticsUI.getSession().syncRequest(new Read<Double[]>() {\r
                     @Override\r
                     public Double[] perform(ReadGraph graph) throws DatabaseException {\r
-                        Double[] numbers = new Double[3];\r
+                        Double[] numbers = new Double[2];\r
                         Resource model = spe.getModel();\r
                         SysdynResource sr = SysdynResource.getInstance(graph);\r
                         numbers[0] = graph.getRelatedValue(model, sr.SysdynModel_startTime);\r
                         numbers[1] = graph.getRelatedValue(model, sr.SysdynModel_stopTime);\r
-                        numbers[2] = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
                         return numbers;\r
                     }\r
                 });\r
index f0d9b324fefcda81909066796022850065cd1a05..96dea950c51521d1b01e96885faede1d3aa72034 100644 (file)
@@ -120,12 +120,22 @@ public class ConfigurationTab extends LabelPropertyTabContributor {
         label = new Label(composite, SWT.NONE);\r
         label.setText("Step length\n(empty = default)");\r
 \r
+        TrackedText stepLength = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
+        stepLength.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SysdynModel_simulationStepLength));\r
+        stepLength.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SysdynModel_simulationStepLength));\r
+        stepLength.setInputValidator(new DoubleValidator());\r
+        GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(stepLength.getWidget());\r
+        \r
+        label = new Label(composite, SWT.NONE);\r
+        label.setText("Output interval\n(empty = all steps)");\r
+\r
         TrackedText outputInterval = new TrackedText(composite, support, SWT.BORDER | SWT.RIGHT);\r
         outputInterval.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.SysdynModel_outputInterval));\r
         outputInterval.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.SysdynModel_outputInterval));\r
         outputInterval.setInputValidator(new DoubleValidator());\r
         GridDataFactory.fillDefaults().hint(200, SWT.DEFAULT).applyTo(outputInterval.getWidget());\r
         \r
+        \r
         label = new Label(composite, SWT.NONE);\r
         label.setText("Method");\r
         \r
index e27c80de6878b4cf2c901fa6df5d63029ac42e37..58fb0eb0e21d7c6a10175c767a256f17808d8069 100644 (file)
@@ -72,6 +72,7 @@ import org.simantics.sysdyn.ui.properties.widgets.ExpressionTypes.ExpressionType
 import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.IsOutputWidget;\r
 import org.simantics.sysdyn.ui.properties.widgets.ShortcutTabWidget;\r
+import org.simantics.sysdyn.ui.properties.widgets.arrays.NameAndArrayRangeModifyListener;\r
 import org.simantics.sysdyn.ui.properties.widgets.expressions.ExpressionWidgetInput;\r
 import org.simantics.sysdyn.ui.properties.widgets.factories.VariableNameValidator;\r
 import org.simantics.ui.SimanticsUI;\r
@@ -182,6 +183,8 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
                expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE);\r
                expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable());\r
 \r
+               arrayEquationCombo.addModifyListener(new NameAndArrayRangeModifyListener(support, expressionWidget, (ArrayExpressionCombo)arrayEquationCombo));\r
+\r
                addListeners(context);\r
        }\r
 \r
index 5994a0c5e8578a11175ecbf4c643f9c376b232f7..bab2c3952765f5bec04d3352ac1884766d8745b7 100644 (file)
@@ -2,33 +2,23 @@ package org.simantics.sysdyn.ui.properties.widgets;
 \r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.StringTokenizer;\r
 import java.util.LinkedHashMap;\r
+import java.util.Map;\r
 \r
 import org.eclipse.swt.widgets.Combo;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.simantics.browsing.ui.swt.widgets.TrackedCombo;\r
-import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
 import org.simantics.browsing.ui.swt.widgets.impl.ReadFactoryImpl;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
-import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.VirtualGraph;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.common.utils.OrderedSetUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.management.ISessionContext;\r
 import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.service.VirtualGraphSupport;\r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
 \r
 public class ArrayExpressionCombo extends TrackedCombo {\r
 \r
@@ -110,7 +100,6 @@ public class ArrayExpressionCombo extends TrackedCombo {
                        }\r
                });\r
 \r
-               this.addModifyListener(new NameAndArrayRangeModifyListener(support));\r
        }\r
 \r
 \r
@@ -185,92 +174,18 @@ public class ArrayExpressionCombo extends TrackedCombo {
                sb.append("]");\r
                return sb.toString();\r
        }\r
-\r
-       private class NameAndArrayRangeModifyListener extends ComboModifyListenerImpl<Resource> implements Widget {\r
-\r
-               Resource lastExpression; \r
-\r
-               public NameAndArrayRangeModifyListener(WidgetSupport support) {\r
-                       support.register(this);\r
-               }\r
-\r
-               @Override\r
-               public void setInput(ISessionContext context, Object input) {\r
-                       super.setInput(context, input);\r
-               }\r
-\r
-               @Override\r
-               public void modifyText(TrackedModifyEvent e) {\r
-\r
-                       Combo combo = (Combo)e.getWidget();\r
-                       LinkedHashMap<?, ?> data = (LinkedHashMap<?, ?>) combo.getData();\r
-\r
-                       Resource expression = (Resource) data.get(combo.getText());\r
-                       if(expression != null) {\r
-                               lastExpression = expression;\r
-                               lastSelectedIndex = combo.getSelectionIndex();\r
-                       } else {\r
-                               for(Object key : data.keySet()) {\r
-                                       int index = lastSelectedIndex < 0 ? 0 : lastSelectedIndex;\r
-                                       if((Integer)combo.getData((String)key) == index) {\r
-                                               lastExpression =  (Resource) data.get((String)key);\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       super.modifyText(e);\r
-               }\r
-\r
-               @Override\r
-               public void applyText(WriteGraph graph, final Resource variable, String text)\r
-               throws DatabaseException {\r
-                       StringTokenizer st = new StringTokenizer(text, "[]");\r
-                       final String newName = st.nextToken();\r
-                       String range = null;\r
-                       if(st.hasMoreTokens()) {\r
-                               range = st.nextToken();\r
-                       }\r
-                       String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName);\r
-                       if(!originalName.equals(newName)) {\r
-                               VariableNameUtils.renameInEquations(graph, variable, originalName, newName);\r
-                               graph.claimLiteral(variable, Layer0.getInstance(graph).HasName, newName);\r
-                       }\r
-\r
-                       SysdynResource sr = SysdynResource.getInstance(graph);\r
-\r
-                       if(range != null && lastExpression != null) {\r
-                               String oldRange = graph.getPossibleRelatedValue(lastExpression, sr.Expression_arrayRange);\r
-                               if(oldRange == null || !range.equals(oldRange)) {\r
-                                       graph.claimLiteral(lastExpression, sr.Expression_arrayRange, "[" + range + "]");\r
-                               }\r
-                       } else if (range == null && lastExpression != null && graph.hasStatement(lastExpression, sr.Expression_arrayRange)) {\r
-                           graph.deny(lastExpression, sr.Expression_arrayRange);\r
-                       }\r
-\r
-                       Resource activeExpression = graph.getPossibleObject(variable, sr.IndependentVariable_activeExpression);\r
-\r
-                       if(lastExpression != null && !lastExpression.equals(activeExpression)) {\r
-                               VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
-                               final Session session = graph.getSession();\r
-                               session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) {\r
-                                       @Override\r
-                                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                                               VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
-                                               session.asyncRequest(new WriteRequest(runtime) {\r
-                                                       @Override\r
-                                                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                                                               SysdynResource sr = SysdynResource.getInstance(graph);\r
-                                                               if(graph.hasStatement(variable, sr.IndependentVariable_activeExpression))\r
-                                                                       graph.deny(variable, sr.IndependentVariable_activeExpression);\r
-                                                               graph.claim(variable, sr.IndependentVariable_activeExpression, lastExpression);\r
-                                                       }\r
-                                               }\r
-                                               );\r
-                                       }\r
-                               });\r
-                       }\r
-               }\r
+       \r
+       /**\r
+        * Get the index that has previously been selected\r
+        * @return\r
+        */\r
+       public int getLastSelectedIndex() {\r
+               return lastSelectedIndex;\r
+       }\r
+       \r
+       public void setLastSelectedIndex(int lastSelectedIndex) {\r
+               this.lastSelectedIndex = lastSelectedIndex;\r
        }\r
+\r
 }\r
 \r
diff --git a/simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/NameAndArrayRangeModifyListener.java b/simantics-1.6/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/arrays/NameAndArrayRangeModifyListener.java
new file mode 100644 (file)
index 0000000..2d81400
--- /dev/null
@@ -0,0 +1,146 @@
+package org.simantics.sysdyn.ui.properties.widgets.arrays;\r
+\r
+import java.util.LinkedHashMap;\r
+import java.util.StringTokenizer;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Combo;\r
+import org.simantics.Simantics;\r
+import org.simantics.browsing.ui.swt.widgets.impl.ComboModifyListenerImpl;\r
+import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
+import org.simantics.browsing.ui.swt.widgets.impl.Widget;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\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.request.Read;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.ArrayExpressionCombo;\r
+import org.simantics.sysdyn.ui.properties.widgets.ExpressionWidget;\r
+import org.simantics.sysdyn.ui.utils.VariableNameUtils;\r
+import org.simantics.utils.ui.ISelectionUtils;\r
+\r
+/**\r
+ * Modification listener ONLY for ArrayExpressionCombos in EquationTabs.\r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class NameAndArrayRangeModifyListener extends ComboModifyListenerImpl<Resource> implements Widget {\r
+\r
+       Resource lastExpression; \r
+       ExpressionWidget expressionWidget;\r
+       ArrayExpressionCombo arrayExpressionCombo;\r
+       Object lastInput;\r
+\r
+       public NameAndArrayRangeModifyListener(WidgetSupport support, ExpressionWidget expressionWidget, ArrayExpressionCombo arrayExpressionCombo) {\r
+               support.register(this);\r
+               this.expressionWidget = expressionWidget;\r
+               this.arrayExpressionCombo = arrayExpressionCombo;\r
+       }\r
+\r
+       @Override\r
+       public void setInput(ISessionContext context, Object input) {\r
+               super.setInput(context, input);\r
+               this.lastInput = input;\r
+       } \r
+               \r
+       public void modifyText(TrackedModifyEvent e) {          \r
+               Combo combo = (Combo)e.getWidget();\r
+               LinkedHashMap<?, ?> data = (LinkedHashMap<?, ?>) combo.getData();\r
+               \r
+               Resource activeExpression = null;\r
+               try {\r
+               final Object input = lastInput;\r
+                       activeExpression = Simantics.getSession().syncRequest(new Read<Resource>() {\r
+                               @Override\r
+                               public Resource perform(ReadGraph graph)\r
+                                               throws DatabaseException {\r
+                                       Resource variable = ISelectionUtils.filterSingleSelection((ISelection)input, Resource.class);\r
+                                       return graph.getPossibleObject(variable, SysdynResource.getInstance(graph).IndependentVariable_activeExpression);\r
+                               }\r
+                               \r
+                       });\r
+               } catch (DatabaseException e1) {\r
+                       e1.printStackTrace();\r
+               }\r
+               \r
+\r
+               Resource expression = (Resource) data.get(combo.getText());\r
+               if(expression != null) {\r
+                       lastExpression = expression;\r
+                       arrayExpressionCombo.setLastSelectedIndex(combo.getSelectionIndex());\r
+               } else {\r
+                       for(Object key : data.keySet()) {\r
+                               int index = arrayExpressionCombo.getLastSelectedIndex() < 0 ? 0 : arrayExpressionCombo.getLastSelectedIndex();\r
+                               if((Integer)combo.getData((String)key) == index) {\r
+                                       lastExpression =  (Resource) data.get((String)key);\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               // If expression has changed (i.e. user actually selects a different item in the combo), save the previous \r
+               if(lastExpression != null && !lastExpression.equals(activeExpression)) {\r
+                       expressionWidget.save();\r
+               }\r
+\r
+               super.modifyText(e);\r
+       }\r
+\r
+       @Override\r
+       public void applyText(WriteGraph graph, final Resource variable, String text)\r
+                       throws DatabaseException {\r
+               StringTokenizer st = new StringTokenizer(text, "[]");\r
+               final String newName = st.nextToken();\r
+               String range = null;\r
+               if(st.hasMoreTokens()) {\r
+                       range = st.nextToken();\r
+               }\r
+               String originalName = graph.getRelatedValue(variable, Layer0.getInstance(graph).HasName);\r
+               if(!originalName.equals(newName)) {\r
+                       VariableNameUtils.renameInEquations(graph, variable, originalName, newName);\r
+                       graph.claimLiteral(variable, Layer0.getInstance(graph).HasName, newName);\r
+               }\r
+\r
+               SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+               if(range != null && lastExpression != null) {\r
+                       String oldRange = graph.getPossibleRelatedValue(lastExpression, sr.Expression_arrayRange);\r
+                       if(oldRange == null || !range.equals(oldRange)) {\r
+                               graph.claimLiteral(lastExpression, sr.Expression_arrayRange, "[" + range + "]");\r
+                       }\r
+               } else if (range == null && lastExpression != null && graph.hasStatement(lastExpression, sr.Expression_arrayRange)) {\r
+                       graph.deny(lastExpression, sr.Expression_arrayRange);\r
+               }\r
+\r
+               Resource activeExpression = graph.getPossibleObject(variable, sr.IndependentVariable_activeExpression);\r
+\r
+               if(lastExpression != null && !lastExpression.equals(activeExpression)) {\r
+                       VirtualGraphSupport support = graph.getService(VirtualGraphSupport.class);\r
+                       final Session session = graph.getSession();\r
+                       session.asyncRequest(new WriteRequest(support.getWorkspacePersistent("expressions")) {\r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       VirtualGraph runtime = graph.getService(VirtualGraph.class);\r
+                                       session.asyncRequest(new WriteRequest(runtime) {\r
+                                               @Override\r
+                                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                                       SysdynResource sr = SysdynResource.getInstance(graph);\r
+                                                       if(graph.hasStatement(variable, sr.IndependentVariable_activeExpression))\r
+                                                               graph.deny(variable, sr.IndependentVariable_activeExpression);\r
+                                                       graph.claim(variable, sr.IndependentVariable_activeExpression, lastExpression);\r
+                                               }\r
+                                       });\r
+                               }\r
+                       });\r
+               }\r
+       }\r
+\r
+}\r
index 4724a0d5c4ae713a228ac509f09e072e6a65019a..c32a30047fe77e5b3241fcfc90c5c429ca046e3a 100644 (file)
@@ -24,6 +24,8 @@ import org.simantics.graphviz.Edge;
 import org.simantics.graphviz.Graph;\r
 import org.simantics.graphviz.Node;\r
 import org.simantics.layer0.Layer0;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 \r
 /**\r
@@ -61,13 +63,21 @@ public class ModuleStructureGraphRequest implements Read<Graph> {
         // Model root was not found, return empty graph\r
         if(model == null)\r
             return g;\r
+        \r
+        // Find the parent module/model of the selected resource\r
+        Resource parentResource = graph.getPossibleObject(resource, l0.PartOf);\r
+        if(graph.isInstanceOf(parentResource, sr.ConfigurationDiagram)) {\r
+               parentResource = graph.getPossibleObject(parentResource, ModelingResources.getInstance(graph).DiagramToComposite);\r
+        } else if(graph.isInstanceOf(parentResource, sr.SysdynModel)) {\r
+               parentResource = graph.getPossibleObject(model, SimulationResource.getInstance(graph).HasConfiguration);\r
+        }\r
 \r
         // Set root node\r
         Node rootNode = new Node(g, NameUtils.getSafeLabel(graph, model));\r
         rootNode.setShape("rectangle");\r
         HashSet<Resource> visited = new HashSet<Resource>();\r
         visited.add(model);\r
-        findChildModules(g, rootNode, graph, model, visited);\r
+        findChildModules(g, rootNode, graph, model, parentResource, visited);\r
 \r
 \r
         return g;\r
@@ -79,17 +89,23 @@ public class ModuleStructureGraphRequest implements Read<Graph> {
      * @param parent Parent module or model\r
      * @param graph ReadGraph\r
      * @param resource Module type or model\r
+     * @param parent2 \r
      * @param visited All visited modules. Needed to check for loops in the structure. Loops are not allowed.\r
      * @throws DatabaseException\r
      */\r
-    private void findChildModules(Graph g, Node parent, ReadGraph graph, Resource resource, HashSet<Resource> visited) throws DatabaseException {\r
+    private void findChildModules(Graph g, Node parent, ReadGraph graph, Resource resource, Resource parentResource, HashSet<Resource> visited) throws DatabaseException {\r
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         Layer0 l0 = Layer0.getInstance(graph);\r
 \r
+        Resource configuration = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, sr.Configuration));\r
+\r
+        // Set the parent color different, if it is the parent of the selected resource\r
+        if(configuration.equals(parentResource))\r
+               parent.setColor("#ff8c00");\r
+        \r
         HashMap<Resource, Integer> modules = new HashMap<Resource, Integer>();\r
 \r
         // Find all module children\r
-        Resource configuration = graph.syncRequest(new PossibleObjectWithType(resource, l0.ConsistsOf, sr.Configuration));\r
         for(Resource m : graph.getObjects(configuration, l0.ConsistsOf)) {\r
             Resource type = graph.getPossibleObject(m, l0.InstanceOf);\r
             if(graph.isInheritedFrom(type, sr.Module)) {\r
@@ -120,8 +136,9 @@ public class ModuleStructureGraphRequest implements Read<Graph> {
                 node.setFontColor("#FF0000");\r
                 continue;\r
             } else {\r
-                visited.add(type);\r
-                findChildModules(g, node, graph, type, visited);\r
+               HashSet<Resource> copy = new HashSet<Resource>(visited);\r
+               copy.add(type);\r
+                findChildModules(g, node, graph, type, parentResource, copy);\r
             }\r
             \r
         }\r
index 6773376db00cc59cd52e50efdc29128113c8ca65..fa3d62ab16084b4861e0a10aaddc0f16035bbe93 100644 (file)
@@ -43,6 +43,7 @@ import org.simantics.sysdyn.representation.Configuration;
 import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.EnumerationIndex;\r
 import org.simantics.sysdyn.representation.IElement;\r
+import org.simantics.sysdyn.representation.Model;\r
 import org.simantics.sysdyn.representation.Module;\r
 import org.simantics.sysdyn.representation.Sheet;\r
 import org.simantics.sysdyn.representation.Variable;\r
@@ -184,6 +185,14 @@ public class ExpressionUtils {
                     for(int i = 0; i < parts.length && current != null; i++) {\r
                         current = getElement(current, parts[i]);\r
                     }\r
+                    \r
+                    if(current == null) {\r
+                       // Sheets are currently located in the model root. Try to find the sheet.\r
+                       current = conf.getModuleType().getParent(); // Get module type parent (should be a model)\r
+                       if(current instanceof Model)\r
+                               current = getElement(((Model)current).getModelConfiguration(), parts[0]); // Try to get the sheet\r
+                    }\r
+                    \r
                     if(current != null && current instanceof Sheet) {\r
                         Sheet sheet = (Sheet) current;\r
                         String e = ef.getExpression();\r
index 62118077067090bc99b6a4a8207ca2b7649cbd7c..63143b0e6000d123a4626142df7e0c82c41c49a9 100644 (file)
@@ -59,7 +59,7 @@ public class VariableRVIUtils {
      * @throws DatabaseException\r
      */\r
     private static void traverseIndexes(ReadGraph g, String rvi, HashMap<String, String> rvis, List<Resource> arrayIndexes) throws DatabaseException {\r
-        traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(0), "", "");\r
+        traverseIndexes(g, rvi, rvis, arrayIndexes, 0, "", "");\r
     }\r
 \r
     /**\r
@@ -76,10 +76,10 @@ public class VariableRVIUtils {
      * @param indexNamesSoFar String representation of the indexes so far in name format\r
      * @throws DatabaseException\r
      */\r
-    private static void traverseIndexes(ReadGraph g, String rvi, HashMap<String, String> rvis, List<Resource> arrayIndexes, Resource currentEnumeration, String indexesSoFar, String indexNamesSoFar) throws DatabaseException {\r
+    private static void traverseIndexes(ReadGraph g, String rvi, HashMap<String, String> rvis, List<Resource> arrayIndexes, int currentIndex, String indexesSoFar, String indexNamesSoFar) throws DatabaseException {\r
         SysdynResource sr = SysdynResource.getInstance(g);\r
         // Enumeration indexes of the current enumeration (e.g. the first EnumIndexes in Var[EnumIndexes, EnumIndexes, EnumIndexes])\r
-        Resource enumerationIndexes = g.getPossibleObject(currentEnumeration, sr.Enumeration_enumerationIndexes);\r
+        Resource enumerationIndexes = g.getPossibleObject(arrayIndexes.get(currentIndex), sr.Enumeration_enumerationIndexes);\r
         if(enumerationIndexes == null)\r
             return;\r
         List<Resource> indexes = OrderedSetUtils.toList(g, enumerationIndexes);\r
@@ -87,12 +87,11 @@ public class VariableRVIUtils {
             Boolean b = g.getPossibleRelatedValue(indexes.get(i), sr.EnumerationIndex_showEnumerationIndexInCharts, Bindings.BOOLEAN);\r
             // If this index is not wanted to be shown in charts, the recursion does not go any further and rvis.put() is not called for this enumeration\r
             if(Boolean.TRUE.equals(b)) {\r
-                int arrayIndex = arrayIndexes.indexOf(currentEnumeration);\r
                 // Get the name of the index\r
                 String name = g.getRelatedValue(indexes.get(i), Layer0.getInstance(g).HasName);\r
-                if(arrayIndex < arrayIndexes.size() - 1)\r
+                if(currentIndex < arrayIndexes.size() - 1)\r
                     // If there are still more EnumIndexes, recursively call the function and add current index to indexesSoFar and indexNamesSoFar\r
-                    traverseIndexes(g, rvi, rvis, arrayIndexes, arrayIndexes.get(arrayIndex + 1)\r
+                    traverseIndexes(g, rvi, rvis, arrayIndexes, currentIndex + 1\r
                             indexesSoFar + (i + 1) +",", indexNamesSoFar + (name) +",");\r
                 else {\r
                     // The last enumeration. Add [rvi[1, 1, 1] = rvi[index1, index1, index1]}and so on to the rvis map\r
@@ -129,7 +128,7 @@ public class VariableRVIUtils {
                     // Find all redeclarations\r
                     for(Resource redeclaration : graph.syncRequest(new ObjectsWithType(module, sr.Module_redeclaration, sr.Redeclaration))) {\r
                         Resource replaced = graph.getSingleObject(redeclaration, sr.Redeclaration_replacedEnumeration);\r
-                        if(enumerations.contains(replaced)) {\r
+                        while(enumerations.contains(replaced)) {\r
                             // Replace the redelcared enumeration in enumerations -list with the replacing enumeration\r
                             enumerations.add(enumerations.indexOf(replaced), graph.getSingleObject(redeclaration, sr.Redeclaration_replacingEnumeration));\r
                             enumerations.remove(replaced);\r
index 9b0d515c1602ec66670c3be8a0ac87a2f9d7bef3..17d8bac1be91b6f6ae2ae2595650f4f2cd8d7d9e 100644 (file)
@@ -49,9 +49,9 @@ import org.simantics.utils.datastructures.Pair;
  */\r
 public class HistoryDatasetResult extends SimulationResult {\r
     @Override\r
-    public void read(File file) {} // Do nothing\r
+    public void read(File file, int interval) {} // Do nothing\r
     @Override\r
-    public void read(InputStream stream) {} // Do nothing\r
+    public void read(InputStream stream, int interval) {} // Do nothing\r
 \r
     private boolean disposed;\r
 \r
index c82649c38b5735a0e2c66a9de16969843f00e7ae..1c1852b1c01a3f553f62e17ef42295e28dc42a41 100644 (file)
@@ -196,17 +196,22 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                Model model = configuration.getModel();\r
                Double startTime = model.getStartTime();\r
                Double stopTime = model.getStopTime();\r
-               Double numberOfIntervals = model.getOutputInterval();\r
                inits.put(SysdynInitKeys.START_VALUE, startTime.toString());\r
                inits.put(SysdynInitKeys.STOP_VALUE, stopTime.toString());\r
                String outputFormat = "\"mat\"";\r
                inits.put(SysdynInitKeys.OUTPUT_FORMAT, outputFormat);\r
-               if(numberOfIntervals != null) {\r
-                       inits.put(SysdynInitKeys.STEP_VALUE, numberOfIntervals.toString());\r
-                       inits.put(SysdynInitKeys.NUMBER_OF_INTERVALS, "" + ((int)((stopTime - startTime) / numberOfIntervals)));\r
+               \r
+               Double simulationStepLength = model.getSimulationStepLength();\r
+               if(simulationStepLength != null) {\r
+                       inits.put(SysdynInitKeys.STEP_VALUE, simulationStepLength.toString());\r
+                       inits.put(SysdynInitKeys.NUMBER_OF_INTERVALS, "" + ((int)((stopTime - startTime) / simulationStepLength)));\r
                } else {\r
                        inits.put(SysdynInitKeys.STEP_VALUE, "" + (stopTime - startTime) / 500);\r
                }\r
+               \r
+               Double outputInterval = model.getOutputInterval();\r
+               inits.put(SysdynInitKeys.OUTPUT_INTERVAL, outputInterval != null ? outputInterval.toString() : inits.get(SysdynInitKeys.STEP_VALUE));\r
+               \r
                String method = "\"" + model.getSolver() + "\"";\r
                inits.put(SysdynInitKeys.METHOD, method);\r
                if(model.getTolerance() != null)\r
@@ -251,7 +256,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                                );\r
                ModelicaManager.printProcessOutput(process, monitor);\r
 \r
-               Thread resultThread = getResultThread(simulationLocation, monitor, progressMonitor);\r
+               Thread resultThread = getResultThread(simulationLocation, inits, monitor, progressMonitor);\r
                resultThread.run();\r
 \r
                process = null;\r
@@ -260,11 +265,12 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
        /**\r
         * Get a thread for reading and saving reuslts from a normal simulation\r
         * @param simulationLocation\r
+        * @param inits \r
         * @param monitor\r
         * @param progressMonitor\r
         * @return\r
         */\r
-       protected Thread getResultThread(final SimulationLocation simulationLocation, final IModelicaMonitor monitor, final IProgressMonitor progressMonitor) {\r
+       protected Thread getResultThread(final SimulationLocation simulationLocation, final HashMap<String, String> inits, final IModelicaMonitor monitor, final IProgressMonitor progressMonitor) {\r
                return new Thread() {\r
                        @Override\r
                        public void run() {\r
@@ -282,7 +288,23 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                                                        result = new SimulationResult();\r
                                                else\r
                                                        result = new MatSimulationResult(); // The latest format\r
-                                               result.read(simulationLocation.outputFile);\r
+                                               \r
+                                               \r
+                                               // The interval of results saved. Every result? Every other result? etc...\r
+                                               int outIntervalInt = 1;\r
+                                               String outputInterval = inits.get(SysdynInitKeys.OUTPUT_INTERVAL);\r
+                                               if(outputInterval != null) {\r
+                                                       String stepTime = inits.get(SysdynInitKeys.STEP_VALUE);\r
+                                                       \r
+                                                       Double step = Double.parseDouble(stepTime);\r
+                                                       Double outInterval = Double.parseDouble(outputInterval);\r
+                                                       \r
+                                                       double nearest = roundUp(outInterval, step);\r
+                                                       outIntervalInt = (int)(nearest / step);\r
+                                                       if(outIntervalInt <= 0) outIntervalInt = 1;\r
+                                               }\r
+                                               \r
+                                               result.read(simulationLocation.outputFile, outIntervalInt);\r
                                                result.readInits(simulationLocation.initFile);\r
                                                result.filter();\r
                                                sysdynModel.getSysdynResult().setResult(result);\r
@@ -305,6 +327,17 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
                        }\r
                };\r
        }\r
+       \r
+       protected static double roundUp(double numToRound, double multiple) {  \r
+               if(multiple == 0) {\r
+                       return numToRound;  \r
+               }\r
+               double remainder = numToRound % multiple; \r
+               if (remainder == 0) {\r
+                       return numToRound; \r
+               }\r
+               return numToRound + multiple - remainder; \r
+       }  \r
 \r
 \r
        /**\r
@@ -319,7 +352,7 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
        protected static SimulationLocation createSimulationFiles(SysdynModel sysdynModel, String modelText, HashMap<String, String> inits, String additionalScript, boolean fmu) throws IOException {\r
                return ModelicaManager.createSimulationFiles(\r
                                sysdynModel.getSimulationDir(),\r
-                               sysdynModel.getConfiguration().getName(),\r
+                               sysdynModel.getConfiguration().getLabel(),\r
                                modelText,\r
                                inits,\r
                                additionalScript,\r
@@ -340,11 +373,11 @@ public class SysdynExperiment extends Experiment implements IDynamicExperiment {
        \r
        protected void storeImportantInits(HashMap<String, String> inits) {\r
                previousImportantInits.clear();\r
-               previousImportantInits.put("start value", inits.get(SysdynInitKeys.START_VALUE));\r
-               previousImportantInits.put("stop value", inits.get(SysdynInitKeys.STOP_VALUE));\r
-               previousImportantInits.put("method", inits.get(SysdynInitKeys.METHOD));\r
-               previousImportantInits.put("outputFormat", inits.get(SysdynInitKeys.OUTPUT_FORMAT));\r
-               previousImportantInits.put("variableFilter", inits.get(SysdynInitKeys.VARIABLE_FILTER));\r
+               previousImportantInits.put(SysdynInitKeys.START_VALUE, inits.get(SysdynInitKeys.START_VALUE));\r
+               previousImportantInits.put(SysdynInitKeys.STOP_VALUE, inits.get(SysdynInitKeys.STOP_VALUE));\r
+               previousImportantInits.put(SysdynInitKeys.METHOD, inits.get(SysdynInitKeys.METHOD));\r
+               previousImportantInits.put(SysdynInitKeys.OUTPUT_FORMAT, inits.get(SysdynInitKeys.OUTPUT_FORMAT));\r
+               previousImportantInits.put(SysdynInitKeys.VARIABLE_FILTER, inits.get(SysdynInitKeys.VARIABLE_FILTER));\r
        }\r
 \r
        /**\r
index 8d82b12f7aacbf39b815e8ff75811766daacbebd..f5918430342fe8f5c4e5cc89513366cb7490802e 100644 (file)
@@ -33,7 +33,7 @@ import org.simantics.modelica.fmi.FMUControlJNI;
 import org.simantics.modelica.fmi.FMUJNIException;\r
 import org.simantics.simulation.experiment.ExperimentState;\r
 import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.utils.datastructures.Pair;\r
+import org.simantics.utils.datastructures.Triple;\r
 \r
 /**\r
  * Game experiment\r
@@ -47,9 +47,11 @@ public class SysdynGameExperiment extends SysdynExperiment {
        private HashMap<String, ArrayList<Double>> results;\r
        private double stepLength = DEFAULT_STEP_LENGTH;\r
        private double stepDuration = DEFAULT_STEP_DURATION;\r
+       private int savePer = 1;\r
        \r
        public static double DEFAULT_STEP_DURATION = 1.0;\r
        public static double DEFAULT_STEP_LENGTH        = 0.1;\r
+       public static int DEFAULT_OUTPUT_INTERVAL       = 1;\r
        \r
        public SysdynGameExperiment(Resource experiment, Resource model) {\r
                super(experiment, model);\r
@@ -71,6 +73,11 @@ public class SysdynGameExperiment extends SysdynExperiment {
                this.stepLength = stepLength;\r
        }\r
        \r
+       public void setOutputInterval(int interval) {\r
+               this.savePer = interval;\r
+       }\r
+\r
+       \r
        public FMUControlJNI getFMUControl() {\r
                return control;\r
        }\r
@@ -84,23 +91,33 @@ public class SysdynGameExperiment extends SysdynExperiment {
                \r
                results = new HashMap<String, ArrayList<Double>>();\r
                \r
-               g.asyncRequest(new Read<Pair<Double, Double>>() {\r
+               g.asyncRequest(new Read<Triple<Double, Double, Double>>() {\r
 \r
                        @Override\r
-                       public Pair<Double, Double> perform(ReadGraph graph)\r
+                       public Triple<Double, Double, Double> perform(ReadGraph graph)\r
                                        throws DatabaseException {\r
                                SysdynResource sr = SysdynResource.getInstance(graph);\r
                                Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration);\r
-                               Double stepLength =graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength);\r
-                               return new Pair<Double, Double>(stepDuration, stepLength);\r
+                               Double stepLength = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength);\r
+                               Double outputInterval = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
+                               return new Triple<Double, Double, Double>(stepDuration, stepLength, outputInterval);\r
                        }\r
-               }, new AsyncListener<Pair<Double, Double>>() {\r
+               }, new AsyncListener<Triple<Double, Double, Double>>() {\r
 \r
                        @Override\r
                        public void execute(AsyncReadGraph graph,\r
-                                       Pair<Double, Double> result) {\r
+                                       Triple<Double, Double, Double> result) {\r
                                setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION);\r
                                setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH);\r
+                               \r
+                               if(result.third == null) {\r
+                                       setOutputInterval(DEFAULT_OUTPUT_INTERVAL);\r
+                               } else {\r
+                                       double nearest = roundUp(result.third, getStepLength());\r
+                                       int interval = (int)(nearest / getStepLength());\r
+                                       if(interval <= 0) interval = 1;\r
+                                       setOutputInterval(interval);\r
+                               }\r
                        }\r
 \r
                        @Override\r
@@ -108,6 +125,7 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                throwable.printStackTrace();\r
                                setStepDuration(DEFAULT_STEP_DURATION);\r
                                setStepLength(DEFAULT_STEP_LENGTH);\r
+                               setOutputInterval(DEFAULT_OUTPUT_INTERVAL);\r
                        }\r
 \r
                        @Override\r
@@ -219,7 +237,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
 \r
                @Override\r
                protected IStatus run(IProgressMonitor monitor) {\r
-                       \r
                        int nSteps = (int)(duration / stepLength); \r
                        int work = 1 + nSteps * 3 + 2; // initialization + number of steps * number of phases per step + set result + call result listeners \r
                        \r
@@ -241,20 +258,26 @@ public class SysdynGameExperiment extends SysdynExperiment {
                                double[] results = new double[subscription.length];\r
                                \r
                                monitor.worked(1);\r
-\r
+                               \r
+                               int stepNumber = 1;\r
                                while(control.getTime() < (eTime - 1e-9)) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers\r
                                        monitor.subTask("Simulate step (time = " + control.getTime() + ")");\r
                                        control.simulateStep();\r
                                        monitor.worked(1);\r
                                        \r
-                                       monitor.subTask("Get results (time = " + control.getTime() + ")");\r
-                                       results = control.getSubscribedResults(results);\r
-                                       monitor.worked(1);\r
-\r
-                                       monitor.subTask("Save results (time = " + control.getTime() + ")");\r
-                                       for(int k = 0; k < subscription.length; k++) {\r
-                                               SysdynGameExperiment.this.results.get(subscription[k]).add(results[k]);\r
+                                       if(stepNumber % savePer == 0) {\r
+                                               monitor.subTask("Get results (time = " + control.getTime() + ")");\r
+                                               results = control.getSubscribedResults(results);\r
+                                               monitor.worked(1);\r
+\r
+                                               monitor.subTask("Save results (time = " + control.getTime() + ")");\r
+                                               for(int k = 0; k < subscription.length; k++) {\r
+                                                       SysdynGameExperiment.this.results.get(subscription[k]).add(results[k]);\r
+                                               }\r
+                                       } else {\r
+                                               monitor.worked(1);\r
                                        }\r
+                                       stepNumber++;\r
                                        monitor.worked(1);\r
                                }\r
                                \r
@@ -268,7 +291,6 @@ public class SysdynGameExperiment extends SysdynExperiment {
                        } catch (FMUJNIException e) {\r
                                System.err.println("SysdynGameExperiment simulateDuration failed: \n\t" + e.getMessage());\r
                        }\r
-                       \r
                        return Status.OK_STATUS;\r
                }\r
        }\r
index 3d405ebd2ea816ee2ccfeeac0b384a5bf0078960..65168bcb5a2f328214a180806374b9a1f92823c6 100644 (file)
@@ -26,5 +26,6 @@ public class SysdynInitKeys {
        public static String METHOD                             = "method";\r
        public static String TOLERANCE                          = "tolerance";\r
        public static String VARIABLE_FILTER            = "variableFilter";\r
+       public static String OUTPUT_INTERVAL            = "outputInterval";\r
 \r
 }\r
index 740ae5a2c3e7f1e86f04324e863ac998cfeb8899..3912a70eecd9cfac669eef243e6e3029ec538d33 100644 (file)
@@ -213,10 +213,6 @@ public class SysdynModel implements IMappingListener, IModel {
                     e.printStackTrace();\r
                 }\r
 \r
-                // Add the current result if there is one\r
-                if(getSysdynResult() != null)\r
-                    activeResults.add(0, getSysdynResult() );\r
-\r
                 return activeResults;\r
             }\r
 \r
@@ -224,6 +220,10 @@ public class SysdynModel implements IMappingListener, IModel {
 \r
             @Override\r
             public void execute(ArrayList<SysdynResult> result) {\r
+                // Add the current result if there is one\r
+                if(result != null && getSysdynResult() != null)\r
+                       result.add(0, getSysdynResult() );\r
+                \r
                 activeResults = result;\r
                 resultChanged();\r
             }\r
@@ -497,7 +497,7 @@ public class SysdynModel implements IMappingListener, IModel {
     public File getSimulationDir() {\r
         if(simulationDir == null) {\r
             File modelsDir = Activator.getBundleContext().getDataFile("models");\r
-            String configName = configuration.getName();\r
+            String configName = configuration.getLabel();\r
             List<String> files = Arrays.asList(modelsDir.list());\r
             if (files.contains(configName)) {\r
                 int i = 2;\r
index 5c8f955cfa3623810c697eb33d63613e8cab6ade..45cebeab791a41245abeef62a0857d85f1ea4d1e 100644 (file)
@@ -232,7 +232,6 @@ public class SysdynPlaybackExperiment extends SysdynExperiment implements IDynam
         SysdynResource sr = SysdynResource.getInstance(graph);\r
         numbers[0] = graph.getRelatedValue(model, sr.SysdynModel_startTime);\r
         numbers[1] = graph.getRelatedValue(model, sr.SysdynModel_stopTime);\r
-        numbers[2] = graph.getPossibleRelatedValue(model, sr.SysdynModel_outputInterval);\r
 \r
         PlaybackConfiguration config = new PlaybackConfiguration();\r
         config.simulationDuration = numbers[1] - numbers[0] - time;\r
index ab41ec5f629ac89cd9f7b0528df5aede8fa75a5c..ea24ec7088d6815aedb3bf656d25eb20dbc7b307 100644 (file)
@@ -50,12 +50,32 @@ public class ModelicaWriter {
         b.append("    parameter Integer size;\n");\r
         b.append("    parameter Integer elements[:];\n");\r
         b.append("end Enumeration_class;\n\n");\r
-\r
+        \r
         for(Configuration conf : configurations)\r
-            writeConfiguration(conf, b);\r
+            writeConfiguration(conf, "SpreadSheetBook", b);\r
+        \r
+        b.append(getGlobalSpreadSheets(configurations));\r
 \r
         return b.toString();\r
     }\r
+    \r
+    /**\r
+     * \r
+     */\r
+    private static String getGlobalSpreadSheets(Collection<Configuration> configurations) {\r
+       StringBuilder sheets = new StringBuilder();\r
+       for(Configuration conf : configurations) {\r
+               if(conf.getModel() != null) {\r
+                       for(IElement e : conf.getElements()) {\r
+                               if(e instanceof Book) {\r
+                                       return ((Book)e).getBook();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       return sheets.toString();\r
+    }\r
 \r
     /**\r
      * Write a single configuration to a given string builder\r
@@ -63,7 +83,7 @@ public class ModelicaWriter {
      * @param configuration Model or module configuration\r
      * @param b String builder\r
      */\r
-    private static void writeConfiguration(Configuration configuration, StringBuilder b) {\r
+    private static void writeConfiguration(Configuration configuration, String spreadSheetClass, StringBuilder b) {\r
         String app;\r
         \r
         boolean game = RepresentationUtils.isGameExperimentActive();\r
@@ -77,7 +97,6 @@ public class ModelicaWriter {
         ArrayList<Dependency> inputDependencies = new ArrayList<Dependency>();\r
         ArrayList<Dependency> outputDependencies = new ArrayList<Dependency>();\r
         HashMap<String, ArrayList<Input>> moduleInputs = new HashMap<String, ArrayList<Input>>();\r
-        Book book = null;\r
 \r
         // Initialize lists\r
         for(IElement element : configuration.getElements()) {\r
@@ -112,9 +131,6 @@ public class ModelicaWriter {
                     // References from child modules\r
                     inputDependencies.add(dependency);\r
                 }\r
-            } else if (element instanceof Book) {\r
-                // Spreadsheet book\r
-                book = (Book)element;\r
             }\r
         }\r
         \r
@@ -125,8 +141,15 @@ public class ModelicaWriter {
 \r
         // If the configuration is model configuration, use model name. Otherwise, use configuration name.\r
         ModuleType mt = configuration.getModuleType();\r
-        String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getName().replace(" ", ""));\r
-        b.append("class ").append(className).append('\n');\r
+        String className = mt != null ? (mt.getName().replace(" ", "")) : (configuration.getLabel().replace(" ", ""));\r
+        \r
+        b.append("class ").append(className);\r
+        \r
+        // Extend spreadsheetclass to get spreadsheet cell info\r
+        if(spreadSheetClass != null && !spreadSheetClass.isEmpty())\r
+               b.append("\n    extends " + spreadSheetClass + ";");\r
+        \r
+        b.append("\n");\r
 \r
         b.append("// Variable definitions\n");\r
         for(IndependentVariable variable : variables) {\r
@@ -164,11 +187,6 @@ public class ModelicaWriter {
             }\r
         }\r
 \r
-        if(book != null) {\r
-            b.append("// Spreadsheet definition\n");\r
-            b.append(book.markBook());\r
-        }\r
-\r
         boolean initialEquations = false;\r
         for(Stock stock : stocks) {\r
             app = stock.getInitialEquation();\r
@@ -221,12 +239,6 @@ public class ModelicaWriter {
 \r
         b.append("end ").append(className).append(";\n\n");\r
 \r
-\r
-        // Update sheet definitions to contain the elements that were used.\r
-        if(book != null) {\r
-            int s = b.indexOf(book.markBook());\r
-            b.replace(s, s + book.markBook().length(), book.getBook());\r
-        }\r
     }\r
     \r
     /**\r
index c4621a7e788f80ea970f2f4972a31a7c6d8443c9..031d4f43c97154f7960e330be6811c1b62e1972e 100644 (file)
@@ -31,9 +31,16 @@ public class Book extends Variable {
     \r
     public String getBook() {\r
         StringBuilder book = new StringBuilder();\r
+        \r
+        book.append("partial class SpreadSheetBook\n");\r
+        \r
         for(Sheet sheet : sheets)\r
             book.append(sheet.getStringRepresentation());\r
+        \r
+        book.append("end SpreadSheetBook;");\r
+        \r
         return book.toString();\r
+        \r
     }\r
 \r
 }\r
index f13b4044d162d906ac156e693663293ca75a0347..00d0efb389b4ce36ef69466b91ceda286406b966 100644 (file)
@@ -75,7 +75,7 @@ public class Configuration {
     }\r
 \r
     public String getLabel() {\r
-        return label;\r
+        return label != null ? label : name;\r
     }\r
     \r
     public ModuleType getModuleType() {\r
index dbda4ea31a56f047dd72efb939c55f1e61cf4817..6e22190f2d3cf0d8a2d75bf60cdc48130a3e2cab 100644 (file)
@@ -16,8 +16,10 @@ import java.util.HashMap;
 \r
 import org.simantics.layer0.Layer0;\r
 import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.objmap.annotations.RelatedElement;\r
 import org.simantics.objmap.annotations.RelatedElements;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.representation.annotations.BuiltinFunctions;\r
 \r
@@ -37,6 +39,9 @@ public class Model {
 \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_outputInterval)\r
     private Double outputInterval;\r
+    \r
+    @RelatedValue(SysdynResource.URIs.SysdynModel_simulationStepLength)\r
+    private Double stepLength;\r
 \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_tolerance)\r
     private Double tolerance;\r
@@ -46,6 +51,9 @@ public class Model {
     \r
     @RelatedValue(SysdynResource.URIs.SysdynModel_variableFilter)\r
     private String variableFilter;\r
+    \r
+    @RelatedElement(SimulationResource.URIs.HasConfiguration)\r
+    private Configuration configuration;\r
 \r
     @RelatedElements(\r
             value = Layer0.URIs.ConsistsOf,\r
@@ -78,13 +86,20 @@ public class Model {
     }\r
 \r
     /**\r
-     * Result output interval\r
+     * Simulation output interval\r
      * @return\r
      */\r
     public Double getOutputInterval() {\r
         return outputInterval;\r
     }\r
 \r
+    /**\r
+     * Simulation step length\r
+     * @return\r
+     */\r
+    public Double getSimulationStepLength() {\r
+       return stepLength;\r
+    }\r
     /**\r
      * \r
      * @return Tolerance for simulation engine\r
@@ -176,4 +191,13 @@ public class Model {
     public FunctionLibrary getBuiltins() {\r
         return builtins;\r
     }\r
+    \r
+    \r
+    /**\r
+     * \r
+     * @return Configuration of this model\r
+     */\r
+    public Configuration getModelConfiguration() {\r
+       return configuration;\r
+    }\r
 }\r
index 241060971fc480b88e57694cbf19fd7ed6729f6b..71a3b7563796eae4d6fb30404e6b878e18331ea3 100644 (file)
@@ -66,7 +66,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
         final StringBuilder clazz = new StringBuilder();\r
         final HashSet<String> possibleRanges = new HashSet<String>();\r
 \r
-        clazz.append("    class " + name + "_class\n        ");\r
+        clazz.append("    class " + name + "_class\n");\r
         \r
         // Write all doubles that have been used in expressions\r
         int counter = 0;\r
@@ -83,7 +83,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
 \r
                 if(value instanceof Double) {\r
                     Double d = (Double)value;\r
-                    clazz.append("constant Real " + key + " = " + d + "; ");\r
+                    clazz.append("        constant Real " + key + " = " + d + "; ");\r
                     counter++;\r
                     if(counter > 10) {\r
                         counter = 0;\r
@@ -116,7 +116,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
                            \r
                             if(array[0].length > 1) {\r
                                 // Has two dimensions     \r
-                                clazz.append("constant Real[" + array.length + ", " + array[0].length + "] ");\r
+                                clazz.append("        constant Real[" + array.length + ", " + array[0].length + "] ");\r
                                 clazz.append(possibleRange.replace(":", "_") + " = {");\r
                                 for(int i = 0; i < array.length; i++) {\r
                                     clazz.append("{");\r
@@ -132,7 +132,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
                                 clazz.append("};\n");\r
                             } else {\r
                                 // Has one dimension\r
-                                clazz.append("constant Real[" + array.length + "] ");\r
+                                clazz.append("        constant Real[" + array.length + "] ");\r
                                 clazz.append(possibleRange.replace(":", "_") + " = {");\r
                                 for(int i = 0; i < array.length; i++) {\r
                                     clazz.append(array[i][0]);\r
@@ -151,7 +151,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
         }\r
         \r
         \r
-        clazz.append("\n    end " + name + "_class;\n");\r
+        clazz.append("    end " + name + "_class;\n");\r
         clazz.append("    " + name + "_class " + name + ";\n");\r
         return clazz.toString();\r
     }\r
@@ -163,7 +163,7 @@ public class Sheet extends org.simantics.sysdyn.representation.Variable {
                 Variant cell = matrix.get(i, j);\r
                 if(cell.getBinding().equals(Bindings.DOUBLE)) {\r
                     array[i][j] = (Double)cell.getValue();\r
-                } else if (cell.getBinding().equals(Bindings.MUTABLE_STRING)) {\r
+                } else if (cell.getBinding().equals(Bindings.MUTABLE_STRING) || (cell.getBinding().equals(Bindings.STRING))) {\r
                     try {\r
                         array[i][j] = Double.parseDouble(cell.getValue().toString());\r
                     } catch (NumberFormatException e) {\r
index 7a5f165bd69f9eecca3a98b6ba16f228d388a7db..e12969f815c37b81fc72c4385aa3de21ed8a366f 100644 (file)
@@ -71,7 +71,6 @@ public enum Variability {
     private static boolean isParameter(IndependentVariable variable, Configuration configuration, String reference, boolean allowVariables) {\r
         // Check if references are references to sheets or enumerations. \r
         // Sheet and Enumeration references are allowed, since sheets contain only constants / parameters\r
-\r
         String r = reference.split("\\.")[0]; \r
         for(IElement element : configuration.getElements()) {\r
             if(element instanceof Module) {\r
@@ -124,6 +123,27 @@ public enum Variability {
                 }\r
             }\r
         }\r
+        \r
+        // Try to find sheet in another way: this might be a module type configuration. Find the model configuration and its sheet\r
+        if(configuration.getModuleType() != null) {\r
+               Object parent = configuration.getModuleType().getParent();\r
+               if(parent != null && parent instanceof Model) {\r
+                       configuration = ((Model)parent).getModelConfiguration();\r
+                for(IElement element : configuration.getElements()) {\r
+                       if(element instanceof Book) {\r
+                        for(Sheet sheet : ((Book)element).getSheets()) {\r
+                            if(r.equals(sheet.getName())) {\r
+                                return true;\r
+                            }\r
+                        }\r
+                        break;\r
+                       }\r
+                }\r
+               }\r
+        }\r
+        \r
+        \r
+        \r
         // If there was no sheet for this reference name, or there was some other problem, return false\r
         return false;\r
     }\r
index 15e3476653d363e5d41925d17e349d6a54bcf23c..f40cc43e35c1ea8886e18829142b1b16b7d8bb9e 100644 (file)
@@ -17,6 +17,7 @@ import org.simantics.sysdyn.SysdynResource;
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
+import org.simantics.sysdyn.representation.utils.SheetFormatUtils;\r
 \r
 /**\r
  * Representation of a withlookup expression\r
@@ -38,7 +39,7 @@ public class WithLookupExpression extends Expression {
        String range = IndexUtils.rangeToIndexes(variable, this.getArrayRange());\r
 \r
         return \r
-        "    " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + lookupTable + ");\n";\r
+        "    " + variable.getName() + (range.equals("[:]") ? "" : range) + " = interpolate(" + equation + ", " + SheetFormatUtils.reformatSheetReferences(variable, lookupTable) + ");\n";\r
     }\r
     \r
     @Override\r
index 918eccbbed34f679cb0c1f48febde7b8b1285ff3..19b14ce88f186a3700574799319254e3520d72ae 100644 (file)
@@ -22,6 +22,8 @@ import org.simantics.sysdyn.expressionParser.ParseException;
 import org.simantics.sysdyn.expressionParser.Token;\r
 import org.simantics.sysdyn.representation.Configuration;\r
 import org.simantics.sysdyn.representation.IElement;\r
+import org.simantics.sysdyn.representation.Model;\r
+import org.simantics.sysdyn.representation.ModuleType;\r
 import org.simantics.sysdyn.representation.Sheet;\r
 import org.simantics.sysdyn.representation.Variable;\r
 \r
@@ -38,6 +40,15 @@ public class SheetFormatUtils {
             for(String key : functionCalls.keySet()) {\r
                 String[] parts = key.split("\\.");\r
                 Object current = v.getParentConfiguration();\r
+                \r
+                // Hack. Sheets can currently exist only in models, not in module types.\r
+                ModuleType moduleType= ((Configuration)current).getModuleType();\r
+                if(moduleType != null) {\r
+                       if(moduleType.getParent() != null && moduleType.getParent() instanceof Model)\r
+                               current = ((Model)moduleType.getParent()).getModelConfiguration();\r
+                }\r
+                // end Hack.\r
+                \r
                 Object found = null;\r
                 for(int i = 0; i < parts.length && current != null; i++) {\r
                     found = null;\r
@@ -62,7 +73,7 @@ public class SheetFormatUtils {
                     String tmp = "";\r
                     int start = 0, end = 0, call = 0;\r
                     String cellOrRange = null;\r
-                    while((call = expression.indexOf(key, end)) >= 0) {\r
+                    while((call = expression.indexOf(key + "(", end)) >= 0) {\r
                         start = expression.indexOf("(", call);\r
                         \r
                         tmp += expression.substring(end, start);\r
@@ -90,7 +101,7 @@ public class SheetFormatUtils {
                         tmp += "." + cellOrRange;\r
                     }\r
                     tmp += expression.substring(end, expression.length());\r
-                    return tmp;\r
+                    expression = tmp;\r
                 }\r
             }\r
 \r
index df6b06ae087fc2d7c445844d9e14deadba8fe1af..ccb4d92e92821d9d05b1a563824976979458591d 100644 (file)
@@ -42,7 +42,7 @@ public class SimulationJob extends Job {
     IModelicaMonitor monitor;\r
 \r
     public SimulationJob(SysdynModel model, Experiment experiment) {\r
-        super("Simulate " + model.getConfiguration().getName());\r
+        super("Simulate " + model.getConfiguration().getLabel());\r
         this.model = model;\r
         this.experiment = experiment;\r
         if(PlatformUI.isWorkbenchRunning()) {\r
@@ -55,8 +55,8 @@ public class SimulationJob extends Job {
 \r
     @Override\r
     protected IStatus run(IProgressMonitor monitor) {\r
-        monitor.beginTask("Simulate " + model.getConfiguration().getName(), 5);        \r
-        this.monitor.message("Simulate " + model.getConfiguration().getName());\r
+        monitor.beginTask("Simulate " + model.getConfiguration().getLabel(), 5);        \r
+        this.monitor.message("Simulate " + model.getConfiguration().getLabel());\r
         try {\r
             model.update();\r
             if(experiment instanceof SysdynExperiment)\r