*******************************************************************************/\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
\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
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
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
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
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
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
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
}\r
return super.getInterface(graph, clazz);\r
}\r
-\r
}\r
\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
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
\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
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
\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