]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
DataSet changed to use List instead of plain array, to make it work with Accessors...
authorjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 26 Aug 2010 06:19:31 +0000 (06:19 +0000)
committerjplaine <jplaine@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 26 Aug 2010 06:19:31 +0000 (06:19 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@17633 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/data/DataSet.java
org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/DefaultVariable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/project/HistoryVariable.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynResult.java

index 9edc793364d81b73e11682929150c45f4f28a3d2..1f35c897745203b7008358687836f93db43368c9 100644 (file)
  *******************************************************************************/\r
 package org.simantics.modelica.data;\r
 \r
+import java.util.List;\r
+\r
 /**\r
  * Simulation result for one variable.\r
  * @author Hannu Niemistö\r
  */\r
 public class DataSet {\r
     public String name;\r
-    public double[] times;\r
-    public double[] values;\r
+    public List<Double> times;\r
+    public List<Double> values;\r
     \r
-    public DataSet(String name, double[] times, double[] values) {\r
+    public DataSet(String name, List<Double> times, List<Double> values) {\r
         this.name = name;\r
         this.times = times;\r
         this.values = values;\r
index f3d22d02d92235de4bccb24de8444d1a15205a5d..89ce4c9b844c6a70ff87f2599a2ee444f7b0a314 100644 (file)
@@ -89,10 +89,14 @@ public class SimulationResult {
         \r
         double startTime = mappedInitials.get("start value");\r
         double stopTime = mappedInitials.get("stop value");\r
-        double[] times = {startTime, stopTime};\r
+        List<Double> times = new ArrayList<Double>(2);\r
+        times.add(startTime);\r
+        times.add(stopTime);\r
         \r
         for(String key : mappedInitials.keySet()) {\r
-            double[] values = {mappedInitials.get(key), mappedInitials.get(key)};\r
+            List<Double> values = new ArrayList<Double>(2);\r
+            values.add(mappedInitials.get(key));\r
+            values.add(mappedInitials.get(key));\r
             initials.add(new DataSet(key, times , values));\r
         }\r
     }\r
@@ -122,8 +126,8 @@ public class SimulationResult {
                 return;\r
             String name = matcher.group(1);\r
 \r
-            TDoubleArrayList times = new TDoubleArrayList();\r
-            TDoubleArrayList values = new TDoubleArrayList();\r
+            List<Double> times = new ArrayList<Double>();\r
+            List<Double> values = new ArrayList<Double>();\r
             while(true) {\r
                 String line = getLine(stream);\r
                 if(line == null)\r
@@ -135,7 +139,7 @@ public class SimulationResult {
                 values.add(Double.parseDouble(nn[1]));\r
             }\r
 \r
-            variables.add(new DataSet(name, times.toNativeArray(), values.toNativeArray()));\r
+            variables.add(new DataSet(name, times, values));\r
         }\r
     }\r
 \r
index 909cab6d65cf0d591b3ecb9b1b12c6e8e79aec0d..0f859dd2aaaab22cb4b0d000e1853d6e24b30246 100644 (file)
@@ -3,6 +3,8 @@ package org.simantics.sysdyn.ui.project;
 import org.simantics.databoard.binding.Binding;\r
 import org.simantics.databoard.binding.java.DoubleBindingDefault;\r
 import org.simantics.databoard.binding.java.StringBindingDefault;\r
+import org.simantics.databoard.type.DataType;\r
+import org.simantics.databoard.type.DoubleType;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
@@ -52,4 +54,10 @@ public class DefaultVariable extends ResourceVariable {
                graph.claimValue(expression, sr.HasEquation, value.toString(), StringBindingDefault.INSTANCE);\r
        }\r
        \r
+       @Override\r
+       public <T> T getInterface(ReadGraph graph, Class<T> clazz)\r
+                       throws DatabaseException {\r
+               if(DataType.class.equals(clazz)) return (T)DoubleType.INSTANCE;\r
+               return super.getInterface(graph, clazz);\r
+       }\r
 }\r
index cd4162ad0bc27d4d4cd7aea42904a30a11729aa0..035f2020d8ed66f5e1da8fa66d14f2c5b4f52931 100644 (file)
@@ -3,7 +3,9 @@ package org.simantics.sysdyn.ui.project;
 import org.simantics.databoard.Accessors;\r
 import org.simantics.databoard.Bindings;\r
 import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.databoard.accessor.RecordAccessor;\r
 import org.simantics.databoard.accessor.error.AccessorConstructionException;\r
+import org.simantics.databoard.accessor.error.AccessorException;\r
 import org.simantics.databoard.binding.error.RuntimeBindingConstructionException;\r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
@@ -23,22 +25,71 @@ public class HistoryVariable extends ResourceVariable {
                super(resource);\r
        }\r
        \r
+//     @Override\r
+//     public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
+//             if(Accessor.class.equals(clazz)) {\r
+//\r
+//                     SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+//                     Resource model = Variables.getModel(graph, this);\r
+//                     Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);\r
+//                     SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+//                     SysdynResult sr = sm.getSysdynResult();\r
+//                     String rvi = Variables.getRVI(graph, this);\r
+//                     System.out.println("HistoryVariable rvi='" + rvi + "'");\r
+//                     rvi = rvi.substring(1).replace("/", ".");\r
+//                     SysdynDataSet ds = sr.getDataSet(rvi);\r
+//                     \r
+//                     try {\r
+//                             return (T)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
+//                     } catch (RuntimeBindingConstructionException e) {\r
+//                             e.printStackTrace();\r
+//                     } catch (AccessorConstructionException e) {\r
+//                             e.printStackTrace();\r
+//                     }\r
+//                     return null;\r
+//                     \r
+//             }\r
+//             return super.getInterface(graph, clazz);\r
+//     }\r
+       \r
        @Override\r
        public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
-               if(Accessor.class.equals(clazz)) {\r
-\r
+               if(RecordAccessor.class.equals(clazz) || Accessor.class.equals(clazz)) {\r
                        SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+                       Builtins b = graph.getBuiltins();\r
                        Resource model = Variables.getModel(graph, this);\r
                        Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);\r
-                       SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
-                       SysdynResult sr = sm.getSysdynResult();\r
-                       String rvi = Variables.getRVI(graph, this);\r
-                       System.out.println("HistoryVariable rvi='" + rvi + "'");\r
-                       rvi = rvi.substring(1).replace("/", ".");\r
-                       SysdynDataSet ds = sr.getDataSet(rvi);\r
+                       final SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+                       SysdynResult sr = new SysdynResult(sm.getSimulationResult()); // TODO: copy or not to copy ...\r
                        \r
+                       String tmp = Variables.getRVI(graph, this);\r
+                       System.out.println("HistoryVariable rvi='" + tmp + "'");\r
+                       final String rvi = tmp.substring(1).replace("/", ".");\r
+                       SysdynDataSet ds = sr.getDataSet(rvi);\r
+                       assert(ds != null);\r
                        try {\r
-                               return (T)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
+                               final RecordAccessor ac = (RecordAccessor)Accessors.getAccessor(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
+                               \r
+                               sm.addResultListener(new Runnable() { // FIXME: remove listener at some point..\r
+                                       @Override\r
+                                       public void run() {\r
+                                               SysdynResult sr = new SysdynResult(sm.getSimulationResult());\r
+                                               SysdynDataSet ds = sr.getDataSet(rvi);\r
+                                               if(ds == null) return;\r
+                                               try {\r
+                                                       if(ds.result == null) ds.result = "";\r
+                                                       ac.setValue(Bindings.getBindingUnchecked(SysdynDataSet.class), ds);\r
+                                               } catch (RuntimeBindingConstructionException e) {\r
+                                                       // TODO Auto-generated catch block\r
+                                                       e.printStackTrace();\r
+                                               } catch (AccessorException e) {\r
+                                                       // TODO Auto-generated catch block\r
+                                                       e.printStackTrace();\r
+                                               }\r
+//                                             System.out.println("===================================================== NEW RESULT =====================================================");\r
+                                               \r
+                                       }});\r
+                               return (T)ac;\r
                        } catch (RuntimeBindingConstructionException e) {\r
                                e.printStackTrace();\r
                        } catch (AccessorConstructionException e) {\r
@@ -49,5 +100,4 @@ public class HistoryVariable extends ResourceVariable {
                }\r
                return super.getInterface(graph, clazz);\r
        }\r
-\r
 }\r
index 6fd478ba51f2ca1a6e7e5b17798656d76ca15ba7..cc6b6077539bfa84f705cbe802d8edf526a1e41c 100644 (file)
@@ -74,17 +74,17 @@ public class TrendView extends ViewPart {
 \r
                @Override\r
                public Number getY(int series, int item) {\r
-                       return sets[series].values[item];\r
+                       return sets[series].values.get(item);\r
                }\r
 \r
                @Override\r
                public Number getX(int series, int item) {\r
-                       return sets[series].times[item];\r
+                       return sets[series].times.get(item);\r
                }\r
 \r
                @Override\r
                public int getItemCount(int series) {\r
-                       return sets[series].times.length;\r
+                       return sets[series].times.size();\r
                }\r
 \r
                @Override\r
index 88ca787a8146d8b368ef889b00d29c20dae2342f..e810fe7aecfa9b8a2162d346338542289e2863be 100644 (file)
@@ -1,12 +1,14 @@
 package org.simantics.sysdyn.manager;\r
 \r
+import java.util.List;\r
+\r
 import org.simantics.modelica.data.DataSet;\r
 \r
 public class SysdynDataSet extends DataSet {\r
 \r
     public String result;\r
 \r
-    public SysdynDataSet(String name, String result, double[] times, double[] values) {\r
+    public SysdynDataSet(String name, String result, List<Double> times, List<Double> values) {\r
         super(name, times, values);\r
         this.result = result;\r
     }\r
index db40e21946e74df9e2f650dc50c6fee9ea5231c6..766d5f13dedf3fa2d89fbf6ddc0f8fa2d1ff9461 100644 (file)
@@ -3,6 +3,7 @@ package org.simantics.sysdyn.manager;
 \r
 import java.io.File;\r
 import java.io.IOException;\r
+import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.TreeMap;\r
 \r
@@ -117,10 +118,10 @@ public class SysdynResult {
         TreeMap<Double, Double> segment = new TreeMap<Double, Double>();\r
         recording.segments = new TreeMap[] { segment };\r
 \r
-        int length = ds.values.length;\r
+        int length = ds.values.size();\r
         for (int i=0; i<length; i++) {\r
-            double time = ds.times[i];\r
-            double value = ds.values[i];\r
+            double time = ds.times.get(i);\r
+            double value = ds.values.get(i);\r
             segment.put(time, value);                      \r
         }\r
         return recording;\r
@@ -180,11 +181,11 @@ public class SysdynResult {
 \r
                 ma.getAll(DoubleBindingDefault.INSTANCE, DoubleBindingDefault.INSTANCE, times, values);\r
 \r
-                double[] times_ = new double[size];\r
-                double[] values_ = new double[size];\r
+                List<Double> times_ = new ArrayList<Double>(size);\r
+                List<Double> values_ = new ArrayList<Double>(size);\r
                 for (int i=0; i<size; i++) {\r
-                    times_[i] = times[i];\r
-                    values_[i] = values[i];\r
+                    times_.add(i, times[i]);\r
+                    values_.add(i, values[i]);\r
                 }\r
 \r
                 return new SysdynDataSet(variable, resultName, times_, values_);\r