this.subscriptionManager = getSubscriptionManager();\r
rvi = Variables.getPossibleRVI(graph, this);\r
if(rvi != null)\r
- rvis = VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph)); \r
+ rvis = graph.syncRequest(new VariableRVIUtils.GetActiveRVIs(parent.getParent(graph))); //VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph)); \r
}\r
\r
private Pair<ArrayList<String>,ArrayList<String>> getVariableNameArrays() {\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.sysdyn.manager.SysdynGameExperimentBase;\r
+import org.simantics.sysdyn.manager.SysdynGameExperimentBase.Subscription;\r
import org.simantics.sysdyn.manager.SysdynResult;\r
import org.simantics.sysdyn.solver.ISolver;\r
\r
public ValueIndexVariableBase(ReadGraph graph, Variable parent, String indexes)\r
throws DatabaseException {\r
super(graph, parent, indexes);\r
+ ensureInformationAvailable(graph);\r
+ if(experiment instanceof SysdynGameExperimentBase) {\r
+ s = ((SysdynGameExperimentBase) experiment).subscribe(getVariableNamesWithIndexNumbers());\r
+ }\r
}\r
\r
public static double[] UNRESOLVED = new double[0];\r
\r
+ public Subscription s;\r
+ \r
public double[] getValueFull() {\r
+ \r
if(experiment == null)\r
return UNRESOLVED;\r
\r
+ if(experiment instanceof SysdynGameExperimentBase) {\r
+ double[] arr = new double[s.indexes.length];\r
+ s.getValues(arr);\r
+ return arr;\r
+ }\r
+\r
+ \r
Collection<SysdynResult> results = experiment.getActiveResults();\r
ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
\r
double[] result = new double[variableNames.size()];\r
for(int i = 0; i < variableNames.size(); i++) {\r
for(SysdynResult r : results) { \r
- if(experiment instanceof SysdynGameExperimentBase) {\r
- Double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i)); \r
- result[i] = d != null ? d : 0;\r
- } else {\r
+// if(experiment instanceof SysdynGameExperimentBase) {\r
+// Double d = ((SysdynGameExperimentBase)experiment).getCurrentValue(variableNames.get(i)); \r
+// result[i] = d != null ? d : 0;\r
+// } else {\r
SysdynDataSet ds = r.getDataSet(variableNames.get(i));\r
if(ds != null && ds.values != null && ds.values.length > 0) {\r
result[i] = ds.values[ds.values.length-1];\r
} else {\r
return UNRESOLVED;\r
}\r
- }\r
+// }\r
}\r
}\r
return result;\r
import org.simantics.db.common.request.ObjectsWithType;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.request.VariableRead;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.layer0.variable.Variables;\r
import org.simantics.layer0.Layer0;\r
* @throws DatabaseException\r
*/\r
public static HashMap<String, String> getActiveRVIs(ReadGraph graph, Variable variable) throws DatabaseException {\r
- HashMap<String, String> rvis = new LinkedHashMap<String, String>();\r
-\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
+ return graph.syncRequest(new GetActiveRVIs(variable));\r
+ }\r
+ \r
+ public static class GetActiveRVIs extends VariableRead<HashMap<String, String>> {\r
\r
- String rvi = Variables.getRVI(graph, variable);\r
+ public GetActiveRVIs(Variable variable) {\r
+ super(variable);\r
+ }\r
\r
- Resource r = variable.getRepresents(graph);\r
+ @Override\r
+ public HashMap<String, String> perform(ReadGraph graph) throws DatabaseException {\r
+ HashMap<String, String> rvis = new LinkedHashMap<String, String>();\r
\r
- Resource arrayIndexes = graph.getPossibleObject(r, sr.Variable_arrayIndexesList);\r
- if(arrayIndexes == null) {\r
- // If variable is single-dimensional, use the same rvi\r
- rvis.put(rvi, rvi);\r
- } else {\r
- // If variable is multidimensional, get all indexes that are active and add them to rvis-map\r
- List<Resource> arrayIndexList = ListUtils.toList(graph, arrayIndexes);\r
- resolveActiveArrayIndexes(graph, variable, arrayIndexList);\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ String rvi = Variables.getRVI(graph, variable);\r
+ Resource r = variable.getRepresents(graph);\r
\r
- if(arrayIndexList.size() > 0)\r
- traverseIndexes(graph, rvi, rvis, arrayIndexList);\r
- else\r
+ Resource arrayIndexes = graph.getPossibleObject(r, sr.Variable_arrayIndexesList);\r
+ if(arrayIndexes == null) {\r
+ // If variable is single-dimensional, use the same rvi\r
rvis.put(rvi, rvi);\r
- }\r
+ } else {\r
+ // If variable is multidimensional, get all indexes that are active and add them to rvis-map\r
+ List<Resource> arrayIndexList = ListUtils.toList(graph, arrayIndexes);\r
+ resolveActiveArrayIndexes(graph, variable, arrayIndexList);\r
\r
- return rvis;\r
+ if(arrayIndexList.size() > 0)\r
+ traverseIndexes(graph, rvi, rvis, arrayIndexList);\r
+ else\r
+ rvis.put(rvi, rvi);\r
+ }\r
+ return rvis;\r
+ }\r
}\r
\r
\r
import gnu.trove.list.array.TDoubleArrayList;\r
import gnu.trove.map.hash.THashMap;\r
\r
+import java.util.Collection;\r
import java.util.HashMap;\r
\r
import org.eclipse.core.runtime.IProgressMonitor;\r
\r
THashMap<String, TDoubleArrayList> results;\r
\r
- protected String[] subscription;\r
+ public String[] subscription;\r
\r
public static double DEFAULT_STEP_DURATION = 1.0;\r
public static double DEFAULT_STEP_LENGTH = 0.1;\r
this.savePer = interval;\r
}\r
\r
+ public static class Subscription {\r
+ public SysdynGameExperimentBase exp;\r
+ public int[] indexes;\r
+ public void getValues(double[] data) {\r
+ for(int i=0;i<indexes.length;i++) data[i] = exp.currentValues[indexes[i]];\r
+ }\r
+ }\r
+ \r
+ public Subscription subscribe(Collection<String> names) {\r
+ Subscription result = new Subscription();\r
+ int[] indexes = new int[names.size()];\r
+ int index = 0;\r
+ for(String name : names)\r
+ indexes[index++] = subscriptionIndexes.get(name);\r
+ result.exp = this;\r
+ result.indexes = indexes;\r
+ return result;\r
+ }\r
+ \r
public Double getCurrentValue(String name) {\r
if(subscriptionIndexes != null && name != null) {\r
Integer index = subscriptionIndexes.get(name);\r
import org.simantics.databoard.util.Base64;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.BinaryRead;\r
import org.simantics.db.common.request.ObjectsWithSupertype;\r
import org.simantics.db.common.request.UniqueRead;\r
import org.simantics.db.common.request.WriteRequest;\r
\r
}\r
\r
- public static org.simantics.db.layer0.variable.Variable lastValueIndexed(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException {\r
- \r
- if(run == null) return null;\r
+ public static class LastValueIndexed extends BinaryRead<Resource, String, org.simantics.db.layer0.variable.Variable> {\r
\r
- Pair<String, String> nameAndIndices = splitToNameAndIndices(path);\r
+ public LastValueIndexed(Resource resource, String path) {\r
+ super(resource, path);\r
+ }\r
\r
- org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second);\r
- if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + path);\r
- \r
- return v;\r
+ @Override\r
+ public org.simantics.db.layer0.variable.Variable perform(ReadGraph graph) throws DatabaseException {\r
+ \r
+ org.simantics.db.layer0.variable.Variable run = Variables.getVariable(graph, parameter);\r
+ Pair<String, String> nameAndIndices = splitToNameAndIndices(parameter2);\r
+ org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second);\r
+ if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + parameter2);\r
+ return v;\r
+ }\r
+ }\r
+ \r
+ \r
+ public static org.simantics.db.layer0.variable.Variable lastValueIndexed(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException {\r
+ if(run == null) return null;\r
+ return graph.syncRequest(new LastValueIndexed(run.getRepresents(graph), path));\r
} \r
\r
public static org.simantics.db.layer0.variable.Variable equation(ReadGraph graph, org.simantics.db.layer0.variable.Variable input, String path) throws DatabaseException {\r