"http://www.simantics.org/SelectionView-1.1" : L0.URI
SYSDYN.SharedFunctionOntology <T L0.Ontology
-SYSDYN.SharedModuleOntolofgy <T L0.Ontology
+SYSDYN.SharedModuleOntolofgy <T L0.Ontology
+
+FUNCTIONS = SYSDYN.Functions : L0.Library
+ @L0.new
//#####################################################################
// Model
STR.AllowsConnectionType SYSDYN.SysdynConnectionType
STR.HasAttachmentRelation DIA.HasArrowConnector
@L0.assert L0.HasDataType $Double
+ >-- SYSDYN.Variable.value <R L0.HasProperty : L0.FunctionalRelation
+ @L0.assert SYSDYN.Variable.value
+ _ : L0.Value
+ L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ >-- SYSDYN.Variable.values <R L0.HasProperty : L0.FunctionalRelation
+ @L0.assert SYSDYN.Variable.values
+ _ : L0.Value
+ L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ >-- SYSDYN.Variable.times <R L0.HasProperty : L0.FunctionalRelation
+ @L0.assert SYSDYN.Variable.times
+ _ : L0.Value
+ L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ >-- SYSDYN.Variable.names <R L0.HasProperty : L0.FunctionalRelation
+ @L0.assert SYSDYN.Variable.names
+ _ : L0.Value
+ L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+ >-- SYSDYN.Variable.activeDatasets <R L0.HasProperty : L0.FunctionalRelation
+ @L0.assert SYSDYN.Variable.activeDatasets
+ _ : L0.Value
+ L0.domainProperties FUNCTIONS.valuePropertyProperties : L0.ExternalValue
+ L0.valueAccessor FUNCTIONS.valuePropertyValue : L0.ExternalValue
+
+FUNCTIONS.runChildren : L0.ExternalValue
+
SYSDYN.HasUnit <R L0.HasProperty
L0.HasRange L0.String
>-- SYSDYN.GameExperiment.stepLength --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.GameExperiment.stepDuration 1.0
+FUNCTIONS.runChildren : L0.ExternalValue
+SYSDYN.Experiment.Run <T SIMU.Run
+ @L0.assert L0.domainChildren FUNCTIONS.runChildren
+
SYSDYN.SimulateOnChangeExperiment <T SYSDYN.Experiment
SYSDYN.PlaybackExperiment <T SYSDYN.Experiment
public final Resource Enumeration_isReplaceable;\r
public final Resource Enumeration_isReplaceable_Inverse;\r
public final Resource Experiment;\r
+ public final Resource Experiment_Run;\r
public final Resource Experiment_result;\r
public final Resource Experiment_result_Inverse;\r
public final Resource ExportModuleTree;\r
public final Resource Flow;\r
public final Resource FlowConnection;\r
public final Resource FunctionTree;\r
+ public final Resource Functions;\r
+ public final Resource Functions_runChildren;\r
+ public final Resource Functions_valuePropertyProperties;\r
+ public final Resource Functions_valuePropertyValue;\r
public final Resource GameExperiment;\r
public final Resource GameExperiment_stepDuration;\r
public final Resource GameExperiment_stepDuration_Inverse;\r
public final Resource Variable;\r
public final Resource Variable_HasHead;\r
public final Resource Variable_HasTail;\r
+ public final Resource Variable_activeDatasets;\r
+ public final Resource Variable_activeDatasets_Inverse;\r
public final Resource Variable_arrayIndexes;\r
public final Resource Variable_arrayIndexes_Inverse;\r
public final Resource Variable_expressions;\r
public final Resource Variable_expressions_Inverse;\r
public final Resource Variable_isHeadOf;\r
public final Resource Variable_isTailOf;\r
+ public final Resource Variable_names;\r
+ public final Resource Variable_names_Inverse;\r
+ public final Resource Variable_times;\r
+ public final Resource Variable_times_Inverse;\r
public final Resource Variable_type;\r
public final Resource Variable_type_Inverse;\r
public final Resource Variable_unit;\r
public final Resource Variable_unit_Inverse;\r
+ public final Resource Variable_value;\r
+ public final Resource Variable_value_Inverse;\r
+ public final Resource Variable_values;\r
+ public final Resource Variable_values_Inverse;\r
public final Resource Variable_variability;\r
public final Resource Variable_variability_Inverse;\r
public final Resource Vertical;\r
public static final String Enumeration_isReplaceable = "http://www.simantics.org/Sysdyn-1.1/Enumeration/isReplaceable";\r
public static final String Enumeration_isReplaceable_Inverse = "http://www.simantics.org/Sysdyn-1.1/Enumeration/isReplaceable/Inverse";\r
public static final String Experiment = "http://www.simantics.org/Sysdyn-1.1/Experiment";\r
+ public static final String Experiment_Run = "http://www.simantics.org/Sysdyn-1.1/Experiment/Run";\r
public static final String Experiment_result = "http://www.simantics.org/Sysdyn-1.1/Experiment/result";\r
public static final String Experiment_result_Inverse = "http://www.simantics.org/Sysdyn-1.1/Experiment/result/Inverse";\r
public static final String ExportModuleTree = "http://www.simantics.org/Sysdyn-1.1/ExportModuleTree";\r
public static final String Flow = "http://www.simantics.org/Sysdyn-1.1/Flow";\r
public static final String FlowConnection = "http://www.simantics.org/Sysdyn-1.1/FlowConnection";\r
public static final String FunctionTree = "http://www.simantics.org/Sysdyn-1.1/FunctionTree";\r
+ public static final String Functions = "http://www.simantics.org/Sysdyn-1.1/Functions";\r
+ public static final String Functions_runChildren = "http://www.simantics.org/Sysdyn-1.1/Functions/runChildren";\r
+ public static final String Functions_valuePropertyProperties = "http://www.simantics.org/Sysdyn-1.1/Functions/valuePropertyProperties";\r
+ public static final String Functions_valuePropertyValue = "http://www.simantics.org/Sysdyn-1.1/Functions/valuePropertyValue";\r
public static final String GameExperiment = "http://www.simantics.org/Sysdyn-1.1/GameExperiment";\r
public static final String GameExperiment_stepDuration = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepDuration";\r
public static final String GameExperiment_stepDuration_Inverse = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepDuration/Inverse";\r
public static final String Variable = "http://www.simantics.org/Sysdyn-1.1/Variable";\r
public static final String Variable_HasHead = "http://www.simantics.org/Sysdyn-1.1/Variable/HasHead";\r
public static final String Variable_HasTail = "http://www.simantics.org/Sysdyn-1.1/Variable/HasTail";\r
+ public static final String Variable_activeDatasets = "http://www.simantics.org/Sysdyn-1.1/Variable/activeDatasets";\r
+ public static final String Variable_activeDatasets_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/activeDatasets/Inverse";\r
public static final String Variable_arrayIndexes = "http://www.simantics.org/Sysdyn-1.1/Variable/arrayIndexes";\r
public static final String Variable_arrayIndexes_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/arrayIndexes/Inverse";\r
public static final String Variable_expressions = "http://www.simantics.org/Sysdyn-1.1/Variable/expressions";\r
public static final String Variable_expressions_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/expressions/Inverse";\r
public static final String Variable_isHeadOf = "http://www.simantics.org/Sysdyn-1.1/Variable/isHeadOf";\r
public static final String Variable_isTailOf = "http://www.simantics.org/Sysdyn-1.1/Variable/isTailOf";\r
+ public static final String Variable_names = "http://www.simantics.org/Sysdyn-1.1/Variable/names";\r
+ public static final String Variable_names_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/names/Inverse";\r
+ public static final String Variable_times = "http://www.simantics.org/Sysdyn-1.1/Variable/times";\r
+ public static final String Variable_times_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/times/Inverse";\r
public static final String Variable_type = "http://www.simantics.org/Sysdyn-1.1/Variable/type";\r
public static final String Variable_type_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/type/Inverse";\r
public static final String Variable_unit = "http://www.simantics.org/Sysdyn-1.1/Variable/unit";\r
public static final String Variable_unit_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/unit/Inverse";\r
+ public static final String Variable_value = "http://www.simantics.org/Sysdyn-1.1/Variable/value";\r
+ public static final String Variable_value_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/value/Inverse";\r
+ public static final String Variable_values = "http://www.simantics.org/Sysdyn-1.1/Variable/values";\r
+ public static final String Variable_values_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/values/Inverse";\r
public static final String Variable_variability = "http://www.simantics.org/Sysdyn-1.1/Variable/variability";\r
public static final String Variable_variability_Inverse = "http://www.simantics.org/Sysdyn-1.1/Variable/variability/Inverse";\r
public static final String Vertical = "http://www.simantics.org/Sysdyn-1.1/Vertical";\r
Enumeration_isReplaceable = getResourceOrNull(graph, URIs.Enumeration_isReplaceable);\r
Enumeration_isReplaceable_Inverse = getResourceOrNull(graph, URIs.Enumeration_isReplaceable_Inverse);\r
Experiment = getResourceOrNull(graph, URIs.Experiment);\r
+ Experiment_Run = getResourceOrNull(graph, URIs.Experiment_Run);\r
Experiment_result = getResourceOrNull(graph, URIs.Experiment_result);\r
Experiment_result_Inverse = getResourceOrNull(graph, URIs.Experiment_result_Inverse);\r
ExportModuleTree = getResourceOrNull(graph, URIs.ExportModuleTree);\r
Flow = getResourceOrNull(graph, URIs.Flow);\r
FlowConnection = getResourceOrNull(graph, URIs.FlowConnection);\r
FunctionTree = getResourceOrNull(graph, URIs.FunctionTree);\r
+ Functions = getResourceOrNull(graph, URIs.Functions);\r
+ Functions_runChildren = getResourceOrNull(graph, URIs.Functions_runChildren);\r
+ Functions_valuePropertyProperties = getResourceOrNull(graph, URIs.Functions_valuePropertyProperties);\r
+ Functions_valuePropertyValue = getResourceOrNull(graph, URIs.Functions_valuePropertyValue);\r
GameExperiment = getResourceOrNull(graph, URIs.GameExperiment);\r
GameExperiment_stepDuration = getResourceOrNull(graph, URIs.GameExperiment_stepDuration);\r
GameExperiment_stepDuration_Inverse = getResourceOrNull(graph, URIs.GameExperiment_stepDuration_Inverse);\r
Variable = getResourceOrNull(graph, URIs.Variable);\r
Variable_HasHead = getResourceOrNull(graph, URIs.Variable_HasHead);\r
Variable_HasTail = getResourceOrNull(graph, URIs.Variable_HasTail);\r
+ Variable_activeDatasets = getResourceOrNull(graph, URIs.Variable_activeDatasets);\r
+ Variable_activeDatasets_Inverse = getResourceOrNull(graph, URIs.Variable_activeDatasets_Inverse);\r
Variable_arrayIndexes = getResourceOrNull(graph, URIs.Variable_arrayIndexes);\r
Variable_arrayIndexes_Inverse = getResourceOrNull(graph, URIs.Variable_arrayIndexes_Inverse);\r
Variable_expressions = getResourceOrNull(graph, URIs.Variable_expressions);\r
Variable_expressions_Inverse = getResourceOrNull(graph, URIs.Variable_expressions_Inverse);\r
Variable_isHeadOf = getResourceOrNull(graph, URIs.Variable_isHeadOf);\r
Variable_isTailOf = getResourceOrNull(graph, URIs.Variable_isTailOf);\r
+ Variable_names = getResourceOrNull(graph, URIs.Variable_names);\r
+ Variable_names_Inverse = getResourceOrNull(graph, URIs.Variable_names_Inverse);\r
+ Variable_times = getResourceOrNull(graph, URIs.Variable_times);\r
+ Variable_times_Inverse = getResourceOrNull(graph, URIs.Variable_times_Inverse);\r
Variable_type = getResourceOrNull(graph, URIs.Variable_type);\r
Variable_type_Inverse = getResourceOrNull(graph, URIs.Variable_type_Inverse);\r
Variable_unit = getResourceOrNull(graph, URIs.Variable_unit);\r
Variable_unit_Inverse = getResourceOrNull(graph, URIs.Variable_unit_Inverse);\r
+ Variable_value = getResourceOrNull(graph, URIs.Variable_value);\r
+ Variable_value_Inverse = getResourceOrNull(graph, URIs.Variable_value_Inverse);\r
+ Variable_values = getResourceOrNull(graph, URIs.Variable_values);\r
+ Variable_values_Inverse = getResourceOrNull(graph, URIs.Variable_values_Inverse);\r
Variable_variability = getResourceOrNull(graph, URIs.Variable_variability);\r
Variable_variability_Inverse = getResourceOrNull(graph, URIs.Variable_variability_Inverse);\r
Vertical = getResourceOrNull(graph, URIs.Vertical);\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.scenegraph.g2d.G2DParentNode;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.adapter.ChildVariable;\r
-import org.simantics.sysdyn.adapter.ConfigurationVariable;\r
-import org.simantics.sysdyn.adapter.RunVariable;\r
import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
\r
public class InputFactory extends SysdynElementFactory {\r
\r
try {\r
Variable v = Variables.getVariable(graph, variable);\r
- if(v instanceof ChildVariable) {\r
- module = ((ChildVariable)v).getRepresents(graph);\r
+ if(v != null) {\r
+ module = v.getRepresents(graph);\r
}\r
if(module != null)\r
for(Resource dep : graph.getObjects(module, sr.Variable_isHeadOf)) {\r
refersTo = graph.getSingleObject(dep, sr.Variable_HasTail);\r
referenceName = (String) graph.getPossibleRelatedValue(refersTo, l0.HasName);\r
Variable parent = null;\r
- if(v instanceof ChildVariable)\r
- parent = ((ChildVariable)v).getParent(graph);\r
- if(parent != null && !(parent instanceof RunVariable) && !(parent instanceof ConfigurationVariable)) {\r
- String parentURI = parent.getURI(graph);\r
- Resource p = graph.getPossibleResource(parentURI);\r
- if(p != null)\r
- moduleName = (String) graph.getPossibleRelatedValue(p, l0.HasName);\r
+ parent = v.getParent(graph);\r
+ if(parent != null && !graph.isInstanceOf(parent.getRepresents(graph), sr.Configuration)) {\r
+ moduleName = parent.getName(graph);\r
}\r
break;\r
}\r
import org.simantics.scl.runtime.tuple.Tuple2;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
-import org.simantics.sysdyn.adapter.SysdynVariableProperties;\r
+import org.simantics.sysdyn.Functions;\r
import org.simantics.sysdyn.adapter.VariableRVIUtils;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
\r
// Get simulation result values for this component\r
// Get values\r
- Object object = var.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
+ Variable dsVariable = var.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#");\r
+ Object object = null;\r
+ if(dsVariable != null)\r
+ object = dsVariable.getValue(graph);\r
if(object == null || !(object instanceof ArrayList<?>))\r
return null;\r
\r
return null;\r
\r
// Get playback time from the experiment\r
- Double time = var.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE);\r
+ Double time = rootVariable.getPossiblePropertyValue(graph, Functions.TIME , Bindings.DOUBLE);\r
if(time == null)\r
return null;\r
\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.handlers.newComponents;\r
\r
+import java.util.UUID;\r
+\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.document.DocumentResource;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.sysdyn.SysdynResource;\r
@Override\r
public void perform(WriteGraph g) throws DatabaseException {\r
Layer0 l0 = Layer0.getInstance(g);\r
- DocumentResource DOC = DocumentResource.getInstance(g);\r
- Resource report = GraphUtils.create2(g, DOC.Report, DOC.HasDocumentation, "===Report===");\r
-\r
- String name = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, "%s%d");\r
-\r
+ String label = NameUtils.findFreshName(g, getNameSuggestion(), model, l0.ConsistsOf, l0.HasLabel, "%s%d");\r
Resource experiment = GraphUtils.create2(g, getExperimentType(g),\r
- l0.HasName, name,\r
- l0.HasLabel, name,\r
- DOC.HasReportFactory, report,\r
+ l0.HasName, UUID.randomUUID().toString(),\r
+ l0.HasLabel, label,\r
l0.PartOf, model);\r
- \r
configureExperiment(g, experiment);\r
}\r
});\r
import org.eclipse.swt.widgets.Label;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.WriteResultRequest;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.variable.Variable;\r
import org.simantics.db.request.Read;\r
-import org.simantics.modelica.fmi.FMUJNIException;\r
import org.simantics.simulation.experiment.IExperiment;\r
import org.simantics.simulation.project.IExperimentManager;\r
import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.adapter.HistoryVariable;\r
import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
import org.simantics.sysdyn.ui.utils.ExpressionUtils;\r
import org.simantics.ui.SimanticsUI;\r
@Override\r
public Double perform(ReadGraph graph) throws DatabaseException {\r
try {\r
- return ((HistoryVariable)variable).getParameterValue(graph);\r
+ Variable valuesVariable = variable.browsePossible(graph, "#values#");\r
+ double[] res = valuesVariable.getValue(graph);\r
+ if(res != null && res.length > 0)\r
+ return res[0];\r
+ else\r
+ return null;\r
} catch (DatabaseException e) {\r
throw new DatabaseException(e.getMessage());\r
- } catch (FMUJNIException e) {\r
- System.err.println("ParameterExpression.java: " + e.getMessage());\r
- return null;\r
- }\r
+ } \r
}\r
});\r
if(value != null)\r
\r
IExperimentManager manager = SimanticsUI.getProject().getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
IExperiment experiment = manager.getActiveExperiment();\r
- if(experiment != null && experiment instanceof SysdynGameExperiment && variable instanceof HistoryVariable) {\r
+ if(experiment != null && experiment instanceof SysdynGameExperiment) {\r
final String currentText = this.expression.getExpression();\r
final String oldEquation = (String)data.get("equation");\r
if(oldEquation == null || \r
if(ExpressionUtils.isParameter(currentText)) {\r
Boolean success = false;\r
try {\r
- success = SimanticsUI.getSession().syncRequest(new Read<Boolean>() {\r
+ success = SimanticsUI.getSession().syncRequest(new WriteResultRequest<Boolean>() {\r
\r
@Override\r
- public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+ public Boolean perform(WriteGraph graph)\r
+ throws DatabaseException {\r
try {\r
- ((HistoryVariable)variable).setParameterValue(graph, Double.parseDouble(currentText));\r
+ Variable valuesVariable = variable.browsePossible(graph, "#values#");\r
+ if(valuesVariable == null)\r
+ return false;\r
+ valuesVariable.setValue(graph, new double[] {Double.parseDouble(currentText)});\r
return true;\r
} catch (Exception e) {\r
return false;\r
}\r
-\r
}\r
+\r
});\r
} catch (DatabaseException e) {\r
}\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.request.PossibleActiveExperiment;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.operation.Layer0X;\r
+import org.simantics.sysdyn.Functions;\r
import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.sysdyn.adapter.SysdynVariableProperties;\r
import org.simantics.sysdyn.adapter.VariableRVIUtils;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.ui.SimanticsUI;\r
try {\r
// Get a variable for the series\r
Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
-\r
+ System.out.println(v.getName(graph));\r
// Get values\r
- Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
+ Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#");\r
+ if(dsVariable == null)\r
+ return series;\r
+ \r
+ Object object = dsVariable.getValue(graph);\r
+ \r
if(object == null || !(object instanceof ArrayList<?>))\r
return series;\r
\r
Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE);\r
if(time == null)\r
time = chartTime;\r
- if(time == null)\r
- time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE);\r
+ if(time == null) {\r
+ Variable realization = Variables.getVariable(graph, realizationURI);\r
+ \r
+ System.out.println(\r
+ NameUtils.getSafeName(graph, realization.getRepresents(graph)) + " : " + \r
+ NameUtils.getSafeName(graph, graph.getPossibleObject(realization.getRepresents(graph), Layer0.getInstance(graph).InstanceOf))\r
+ );\r
+ \r
+ time = realization.getPossiblePropertyValue(graph, Functions.TIME, Bindings.DOUBLE);\r
+ }\r
\r
// Value\r
Double value = null;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.operation.Layer0X;\r
+import org.simantics.sysdyn.Functions;\r
import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.sysdyn.adapter.SysdynVariableProperties;\r
import org.simantics.sysdyn.adapter.VariableRVIUtils;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.ui.SimanticsUI;\r
Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
\r
// Get values\r
- Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
+ Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#");\r
+ if(dsVariable == null)\r
+ return series;\r
+ \r
+ Object object = dsVariable.getValue(graph);\r
if(object == null || !(object instanceof ArrayList<?>))\r
return series;\r
\r
Double time = graph.getPossibleRelatedValue(r, jfree.Series_time, Bindings.DOUBLE);\r
if(time == null)\r
time = chartTime;\r
- if(time == null)\r
- time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME, Bindings.DOUBLE);\r
-\r
+ if(time == null) {\r
+ Variable realization = Variables.getVariable(graph, realizationURI);\r
+ time = realization.getPossiblePropertyValue(graph, Functions.TIME, Bindings.DOUBLE);\r
+ }\r
+ \r
// Value\r
Double value = null;\r
if(time == null) {\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modeling.ModelingResources;\r
import org.simantics.operation.Layer0X;\r
+import org.simantics.sysdyn.Functions;\r
import org.simantics.sysdyn.JFreeChartResource;\r
-import org.simantics.sysdyn.adapter.SysdynVariableProperties;\r
import org.simantics.sysdyn.adapter.VariableRVIUtils;\r
import org.simantics.sysdyn.manager.SysdynDataSet;\r
import org.simantics.ui.SimanticsUI;\r
if(rvi != null && !rvi.isEmpty()) {\r
try {\r
Variable domainVariable = Variables.getVariable(graph, realizationURI + rvi);\r
- domainValues = domainVariable.getPossiblePropertyValue(graph, SysdynVariableProperties.VALUES , Bindings.DOUBLE_ARRAY);\r
+ Variable valuesVariable = domainVariable.browsePossible(graph, "#values#");\r
+ if(valuesVariable != null) {\r
+ double[][] valuesArray = valuesVariable.getValue(graph);\r
+ if(valuesArray.length > 0)\r
+ domainValues = valuesArray[0];\r
+ }\r
} catch(MissingVariableException e) {\r
//Do nothing, use time as domain axis\r
e.printStackTrace();\r
return new Pair<ArrayList<TempSeries>, IRenderer>(series, renderer);\r
\r
// Get values\r
- Object object = v.getPossiblePropertyValue(graph, SysdynVariableProperties.ACTIVE_DATASETS , Bindings.VARIANT);\r
+ Variable dsVariable = v.browsePossible(graph, "#" + Functions.ACTIVE_DATASETS + "#");\r
+ Object object = null;\r
+ if(dsVariable != null)\r
+ object = dsVariable.getValue(graph);\r
+\r
if(object == null || !(object instanceof ArrayList<?>))\r
return new Pair<ArrayList<TempSeries>, IRenderer>(series, renderer);\r
\r
if(rvi == null)\r
continue;\r
try {\r
- // Get a variable for the series\r
- Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
- if(v == null)\r
- return null;\r
- Double time = v.getPossiblePropertyValue(graph, SysdynVariableProperties.TIME , Bindings.DOUBLE);\r
- return time;\r
+ // Get a variable for the series\r
+ Variable v = Variables.getVariable(graph, realizationURI + rvi);\r
+ if(v == null)\r
+ return null;\r
+ Variable realization = Variables.getVariable(graph, realizationURI);\r
+ if(realization == null)\r
+ return null;\r
+ return realization.getPossiblePropertyValue(graph, Functions.TIME, Bindings.DOUBLE);\r
} catch (MissingVariableException e) {\r
- // Do nothing, if variable was not found.\r
+ // Do nothing, if variable was not found.\r
}\r
}\r
}\r
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Simantics System Dynamics
-Bundle-SymbolicName: org.simantics.sysdyn
+Bundle-SymbolicName: org.simantics.sysdyn;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.simantics.objmap;bundle-version="0.1.0",
</type>\r
</target>-->\r
\r
+ <!-- \r
<target interface="org.simantics.db.layer0.variable.Variable">\r
+\r
<adapter uri="http://www.simantics.org/Sysdyn-0.0/Configuration"\r
contextClass="org.simantics.db.layer0.variable.Variable"\r
adapterClass="org.simantics.sysdyn.adapter.ConfigurationVariableAdapter"/>\r
- <adapter uri="http://www.simantics.org/Simulation-1.0/Run"\r
- contextClass="org.simantics.db.layer0.variable.Variable"\r
- adapterClass="org.simantics.sysdyn.adapter.RunVariableAdapter"/>\r
<adapter uri="http://www.simantics.org/Sysdyn-0.0/Variable"\r
contextClass="org.simantics.db.layer0.variable.Variable"\r
adapterClass="org.simantics.sysdyn.adapter.ChildVariableAdapter"/>\r
<adapter uri="http://www.simantics.org/Sysdyn-0.0/Module"\r
contextClass="org.simantics.db.layer0.variable.Variable"\r
adapterClass="org.simantics.sysdyn.adapter.ChildVariableAdapter"/>\r
+ <adapter uri="http://www.simantics.org/Simulation-1.0/Run"\r
+ contextClass="org.simantics.db.layer0.variable.Variable"\r
+ adapterClass="org.simantics.sysdyn.adapter.RunVariableAdapter"/>\r
</target>\r
+ -->\r
\r
</adapters>
\ No newline at end of file
output.. = bin/\r
bin.includes = META-INF/,\\r
.,\\r
- adapters.xml\r
+ adapters.xml,\\r
+ plugin.xml\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<?eclipse version="3.4"?>\r
+<plugin>\r
+\r
+ <extension point="org.simantics.scl.reflection.binding">\r
+ <namespace path="http://www.simantics.org/Sysdyn-1.1/Functions">\r
+ <externalClass className="org.simantics.db.Resource"/>\r
+ <externalClass className="org.simantics.db.ReadGraph"/>\r
+ <externalClass className="org.simantics.db.WriteGraph"/>\r
+ <externalClass className="org.simantics.db.Issue"/>\r
+ <externalClass className="org.simantics.databoard.binding.Binding"/>\r
+ <externalClass className="org.simantics.db.layer0.variable.Variable"/>\r
+ <externalClass className="org.simantics.db.layer0.variable.ValueAccessor"/>\r
+ <externalClass className="org.simantics.db.layer0.variable.VariableMap"/>\r
+ <class className="org.simantics.sysdyn.Functions"/>\r
+ </namespace>\r
+ </extension>\r
+\r
+</plugin>\r
--- /dev/null
+package org.simantics.sysdyn;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
+import org.simantics.db.layer0.variable.ValueAccessor;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.VariableMap;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.operation.Layer0X;\r
+import org.simantics.scl.reflection.annotations.SCLValue;\r
+import org.simantics.structural.stubs.StructuralResource2;\r
+import org.simantics.sysdyn.adapter.ActiveDatasetsIndexVariable;\r
+import org.simantics.sysdyn.adapter.NamesIndexVariable;\r
+import org.simantics.sysdyn.adapter.TimesIndexVariable;\r
+import org.simantics.sysdyn.adapter.ValueIndexVariable;\r
+import org.simantics.sysdyn.adapter.ValuesIndexVariable;\r
+\r
+public class Functions {\r
+ \r
+ public static String VALUE = "value";\r
+ public static String VALUES = "values";\r
+ public static String TIME = "time";\r
+ public static String TIMES = "times";\r
+ public static String NAMES = "names"; \r
+ public static String ACTIVE_DATASETS = "activeDatasets"; \r
+ \r
+ @SCLValue(type = "ValueAccessor")\r
+ public static ValueAccessor valuePropertyValue = new ValueAccessor() {\r
+\r
+ @Override\r
+ public Object getValue(ReadGraph graph, Variable context)\r
+ throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Object getValue(ReadGraph graph, Variable context,\r
+ Binding binding) throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void setValue(WriteGraph graph, Variable context, Object value)\r
+ throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+\r
+ @Override\r
+ public void setValue(WriteGraph graph, Variable context, Object value,\r
+ Binding binding) throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+ \r
+ };\r
+\r
+ @SCLValue(type = "VariableMap")\r
+ public static VariableMap valuePropertyProperties = new VariableMap() {\r
+ \r
+ @Override\r
+ public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {\r
+ \r
+ String property = context.getName(graph);\r
+ if(VALUE.equals(property))\r
+ return new ValueIndexVariable(graph, context, name);\r
+ else if(VALUES.equals(property))\r
+ return new ValuesIndexVariable(graph, context, name);\r
+ else if(TIMES.equals(property))\r
+ return new TimesIndexVariable(graph, context, name);\r
+ else if(NAMES.equals(property))\r
+ return new NamesIndexVariable(graph, context, name);\r
+ else if(ACTIVE_DATASETS.equals(property))\r
+ return new ActiveDatasetsIndexVariable(graph, context, name);\r
+ else\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public void getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {\r
+// Collections.emptyList();\r
+// StandardGraphChildVariable variable = (StandardGraphChildVariable)context;\r
+// collectPropertiesFromContext(graph, variable, variable.resource, map);\r
+ }\r
+ \r
+ };\r
+ \r
+ \r
+ @SCLValue(type = "VariableMap")\r
+ public static VariableMap runChildren = new VariableMap() {\r
+ \r
+ @Override\r
+ public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {\r
+ StandardGraphChildVariable variable = (StandardGraphChildVariable)context;\r
+ Map<String, Resource> children = graph.syncRequest(new StructuralChildMapOfResource(getConfiguration(graph, variable)));\r
+ Resource child = children.get(name);\r
+ if(child == null) return null;\r
+ return graph.getPossibleContextualAdapter(child, variable, Variable.class, Variable.class);\r
+ }\r
+\r
+ @Override\r
+ public void getVariables(ReadGraph graph, Variable context, Map<String, Variable> map) throws DatabaseException {\r
+ StandardGraphChildVariable variable = (StandardGraphChildVariable)context;\r
+ for(Map.Entry<String, Resource> entry : graph.syncRequest(new StructuralChildMapOfResource(getConfiguration(graph, variable))).entrySet()) {\r
+ String name = entry.getKey();\r
+ Resource child = entry.getValue();\r
+ Variable var = graph.getPossibleContextualAdapter(child, variable, Variable.class, Variable.class);\r
+ if(var != null) {\r
+ map.put(name, var);\r
+ } else {\r
+ System.err.println("No adapter for " + child + " in " + variable.getURI(graph));\r
+ }\r
+ }\r
+ }\r
+ \r
+ Resource getConfiguration(ReadGraph graph, Variable run) throws DatabaseException {\r
+ Layer0 L0 = Layer0.getInstance(graph);\r
+ Layer0X L0X = Layer0X.getInstance(graph);\r
+ Resource experiment = graph.getPossibleObject(run.getRepresents(graph), L0.PartOf);\r
+ Resource model = graph.getPossibleObject(experiment, L0.PartOf);\r
+ return graph.getPossibleObject(model, L0X.HasBaseRealization);\r
+ }\r
+ \r
+ };\r
+ \r
+ \r
+ static class StructuralChildMapOfResource extends ResourceRead<Map<String, Resource>> {\r
+\r
+ public StructuralChildMapOfResource(Resource resource) {\r
+ super(resource);\r
+ }\r
+\r
+ @Override\r
+ public Map<String, Resource> perform(ReadGraph graph) throws DatabaseException {\r
+ \r
+ StructuralResource2 STR = StructuralResource2.getInstance(graph);\r
+ Map<String, Resource> directChildren = graph.syncRequest(new UnescapedChildMapOfResource(resource));\r
+ Resource type = graph.getPossibleType(resource, STR.Component);\r
+ if(type != null) {\r
+ Resource definition = graph.getPossibleObject(type, STR.IsDefinedBy);\r
+ if(definition != null) {\r
+ return graph.syncRequest(new UnescapedChildMapOfResource(definition));\r
+ }\r
+ }\r
+\r
+ return directChildren;\r
+ \r
+ }\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.modelica.data.DataSet;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+\r
+public class ActiveDatasetsIndexVariable extends IndexVariable< ArrayList<DataSet>> {\r
+\r
+ public ActiveDatasetsIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ }\r
+\r
+ @Override\r
+ public ArrayList<DataSet> getValue() {\r
+ ArrayList<DataSet> result = new ArrayList<DataSet>();\r
+ SysdynResult sr = model.getSysdynResult();\r
+ ArrayList<String> variableNamesWithIndexes = getVariableNamesWithIndexNumbers();\r
+ ArrayList<String> variableNames = getVariableNames();\r
+\r
+ for(int i = 0; i < variableNamesWithIndexes.size(); i++) {\r
+ SysdynDataSet ds = sr.getDataSet(variableNamesWithIndexes.get(i));\r
+ if(ds != null) {\r
+ ds.name = variableNames.get(i);\r
+ result.add(ds);\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ \r
+ }\r
+\r
+}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import java.util.List;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Datatypes;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.util.ObjectUtils;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.OrderedSetUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.AbstractChildVariable;\r
-import org.simantics.db.layer0.variable.DatatypePropertyVariable;\r
-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.operation.Layer0X;\r
-import org.simantics.sysdyn.SysdynResource;\r
-\r
-public class ChildVariable extends AbstractChildVariable {\r
-\r
- protected Variable parent;\r
- protected Resource resource;\r
- \r
- public ChildVariable(Variable parent, Resource resource) {\r
- this.parent = parent;\r
- this.resource = resource;\r
- }\r
- \r
- // FIXME: Support properties! This is just for the system to work like it used to. \r
- @Override\r
- public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- if(this.resource == null) return null;\r
- //FIXME: doesn't support multiple expressions\r
- Resource expressions = graph.getPossibleObject(this.resource, sr.Variable_expressions);\r
- if(expressions == null) return null;\r
- List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
- Resource expression = expressionList.get(0);\r
- if(expression == null) return null;\r
- if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return null;\r
- String text = graph.getPossibleRelatedValue(expression, sr.Expression_equation);\r
- if(text == null) return null;\r
- Double value = Double.parseDouble(text); \r
- return (T)value;\r
- }\r
- \r
- // FIXME: Support properties! This is just for the system to work like it used to. \r
- @Override\r
- public void setValue(WriteGraph graph, Object object, Binding binding) throws DatabaseException {\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- if(this.resource == null) return;\r
- //FIXME: doesn't support multiple expressions\r
- Resource expressions = graph.getPossibleObject(this.resource, sr.Variable_expressions);\r
- if(expressions == null) return;\r
- List<Resource> expressionList = OrderedSetUtils.toList(graph, expressions);\r
- Resource expression = expressionList.get(0);\r
- if(expression == null) return;\r
- if(!graph.isInstanceOf(expression, sr.ParameterExpression)) return;\r
- graph.claimLiteral(expression, sr.Expression_equation, object.toString(), Bindings.STRING);\r
- }\r
- \r
- // FIXME: Support properties! This is just for the system to work like it used to. \r
- @Override\r
- public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
- if(Datatype.class.equals(clazz)) {\r
- return (T)Datatypes.DOUBLE;\r
- }\r
- return super.getInterface(graph, clazz);\r
- }\r
- \r
- @Override\r
- public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException {\r
- if(Variables.DATATYPE.equals(name)) {\r
- return new DatatypePropertyVariable(this);\r
- }\r
- return super.getPossibleExtraProperty(graph, name);\r
- }\r
- /*\r
- * \r
- * \r
- */\r
- \r
- \r
- @Override\r
- public Variable getParent(ReadGraph graph) throws DatabaseException {\r
- if(parent == null)\r
- return null; // TODO is this correct thing to do?\r
- else\r
- return parent; \r
- }\r
- \r
- @Override\r
- public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
- Layer0X L0X = Layer0X.getInstance(graph);\r
- Resource represents = graph.getPossibleObject(resource, L0X.Represents);\r
- if(represents != null) return represents;\r
- else return resource;\r
- }\r
- \r
- @Override\r
- public String getName(ReadGraph graph) throws DatabaseException {\r
- return graph.getRelatedValue(resource, graph.getService(Layer0.class).HasName, Bindings.STRING);\r
- }\r
- \r
- \r
- @Override\r
- public String getSerialized(ReadGraph graph) throws DatabaseException {\r
- return getURI(graph);\r
- }\r
- \r
- @Override\r
- public String getURI(ReadGraph graph) throws DatabaseException {\r
- if(parent == null)\r
- return getName(graph);\r
- else\r
- return parent.getURI(graph) + "/" + encodeString(getName(graph));\r
- }\r
- \r
- \r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + resource.hashCode();\r
- result = prime * result + ObjectUtils.hashCode(parent);\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- ChildVariable other = (ChildVariable) obj;\r
- if (!resource.equals(other.resource))\r
- return false;\r
- return ObjectUtils.objectEquals(parent, other.parent);\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.adaption.SimpleContextualAdapter;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.sysdyn.SysdynResource;\r
-\r
-public class ChildVariableAdapter extends SimpleContextualAdapter<Variable, Variable>{\r
-\r
- @Override\r
- public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException {\r
- if(context instanceof HistoryVariable) {\r
- return new HistoryVariable(context, source);\r
- } else {\r
- if(g.isInstanceOf(source, SysdynResource.getInstance(g).Module))\r
- return new ModuleVariable(context, source); \r
- else \r
- return new ChildVariable(context, source);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
-import org.simantics.db.exception.AdaptionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
-import org.simantics.db.layer0.variable.Variable;\r
-\r
-public class ConfigurationVariable extends StandardGraphChildVariable {\r
-\r
- public ConfigurationVariable(Variable parent, Resource resource) {\r
- super(parent, resource);\r
- }\r
-\r
- @Override\r
- public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
- Map<String, Variable> result = new HashMap<String, Variable>();\r
- for(Map.Entry<String, Resource> entry : graph.syncRequest(new UnescapedChildMapOfResource(resource)).entrySet()) {\r
- String name = entry.getKey();\r
- Resource child = entry.getValue();\r
- try {\r
- result.put(name, graph.adaptContextual(child, this, Variable.class, Variable.class));\r
- } catch (AdaptionException e) {\r
- }\r
- }\r
- collectSpecialChildren(graph, result);\r
- return result.values();\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.adaption.SimpleContextualAdapter;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-\r
-public class ConfigurationVariableAdapter extends SimpleContextualAdapter<Variable, Variable>{\r
-\r
- @Override\r
- public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException {\r
- return new ConfigurationVariable(context, source);\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.modelica.fmi.FMUJNIException;\r
-\r
-/**\r
- * Interface for game parameter providers\r
- * @author Teemu Lempinen\r
- *\r
- */\r
-public interface GameParameterProvider {\r
- \r
- double getParameterValue(ReadGraph graph) throws FMUJNIException, DatabaseException ;\r
- \r
- void setParameterValue(ReadGraph graph, double value) throws FMUJNIException, DatabaseException ;\r
-\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.databoard.Accessors;\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.Datatypes;\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.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.ParametrizedPrimitiveRead;\r
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.MissingVariableException;\r
-import org.simantics.db.layer0.variable.ConstantPropertyVariable;\r
-import org.simantics.db.layer0.variable.RVI;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.db.layer0.variable.Variables;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.db.request.ExternalRead;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modelica.data.DataSet;\r
-import org.simantics.modelica.fmi.FMUControlJNI;\r
-import org.simantics.modelica.fmi.FMUJNIException;\r
-import org.simantics.simulation.experiment.ExperimentState;\r
-import org.simantics.simulation.ontology.SimulationResource;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-import org.simantics.sysdyn.SysdynResource;\r
-import org.simantics.sysdyn.manager.SysdynDataSet;\r
-import org.simantics.sysdyn.manager.SysdynExperiment;\r
-import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
-import org.simantics.sysdyn.manager.SysdynModel;\r
-import org.simantics.sysdyn.manager.SysdynModelManager;\r
-import org.simantics.sysdyn.manager.SysdynPlaybackExperiment;\r
-import org.simantics.sysdyn.manager.SysdynResult;\r
-\r
-/**\r
- * \r
- * Variable implementation for Sysdyn variables. History\r
- * variables are used when there is an active experiment.\r
- * \r
- * @author Teemu Lempinen\r
- */\r
-public class HistoryVariable extends ChildVariable implements PropertyProvider, GameParameterProvider {\r
-\r
- static Boolean DEBUG = false;\r
-\r
- private SysdynExperiment experiment;\r
- private SysdynModel model = null;\r
- private String rvi = null;\r
- private HashMap<String, String> rvis = null;\r
-\r
- /**\r
- * Variable representing a variable with some history (active experiment)\r
- * \r
- * @param parent Parent variable\r
- * @param resource Resource that the variable represents\r
- */\r
- public HistoryVariable(Variable parent, Resource resource) {\r
- super(parent, resource);\r
- experiment = SysdynExperiment.INSTANCE;\r
- }\r
-\r
-\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
- /*\r
- * Implementation for OperatingInterfaces (and Tacton integration?)\r
- * Should get rid of this and use only properties.\r
- */\r
- if(RecordAccessor.class.equals(clazz) || Accessor.class.equals(clazz)) {\r
- SimulationResource SIMU = SimulationResource.getInstance(graph);\r
- Resource model = Variables.getModel(graph, this);\r
- Resource configuration = graph.getPossibleObject(model, SIMU.HasConfiguration);\r
- final SysdynModel sm = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
- SysdynResult sr = sm.getSysdynResult();\r
-\r
- String tmp = Variables.getRVI(graph, this);\r
- if(DEBUG)\r
- System.out.println("HistoryVariable rvi='" + tmp + "'");\r
- final String rvi = tmp.substring(1).replace("/", ".");\r
- SysdynDataSet ds = sr.getDataSet(rvi);\r
- if(ds == null) ds = new SysdynDataSet("", "", new double[0], new double[0]); // We need a dataset, so if not set, create it\r
- try {\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
- if(HistoryVariable.this.experiment.getState().equals(ExperimentState.DISPOSED))\r
- return;\r
-\r
- SysdynResult sr = sm.getSysdynResult();\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
- }});\r
- return (T)ac;\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 Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
- try {\r
- return getChild(graph, name);\r
- } catch (DatabaseException e) {\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public Variable getChild(ReadGraph graph, String name) throws DatabaseException {\r
- // If the variable represents a module, it may have children\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- Resource instanceOf = graph.getSingleObject(this.resource, l0.InstanceOf);\r
- if(graph.isInheritedFrom(instanceOf, sr.Module)) {\r
- // Find the configuration of the module\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- if(instanceOf == null)\r
- throw new MissingVariableException("No instanceof for resource " + NameUtils.getSafeName(graph, resource));\r
- Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
- if(configuration == null)\r
- throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf));\r
- // Get the components in the configuration and find the child\r
- Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(configuration));\r
- Resource child = children.get(name);\r
- return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
- } else {\r
- return super.getChild(graph, name);\r
- }\r
- }\r
-\r
-\r
- @Override\r
- public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
- // If the variable represents a module, it may have children\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf);\r
- if(graph.isInheritedFrom(instanceOf, sr.Module)) {\r
- ArrayList<Variable> result = new ArrayList<Variable>();\r
- if(instanceOf == null)\r
- return result;\r
- // Find the configuration of the model\r
- Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
- if(configuration == null)\r
- return result;\r
- // Add all children to the result\r
- for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values())\r
- result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
- return result;\r
- } else {\r
- return super.browseChildren(graph);\r
- }\r
- }\r
-\r
- @Override\r
- public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException {\r
- if(SysdynVariableProperties.TIME.equals(name)) {\r
- // Get current time\r
- return graph.syncRequest(new PropertyRequest(this, name));\r
- } else if(SysdynVariableProperties.VALUES.equals(name) || SysdynVariableProperties.TIMES.equals(name) ||\r
- SysdynVariableProperties.ACTIVE_DATASETS.equals(name)) {\r
- // For these requests, we need to make sure that model and rvi exist\r
- if(model == null) {\r
- SimulationResource SIMU = SimulationResource.getInstance(graph);\r
- Resource modelResource = Variables.getModel(graph, this);\r
- Resource configuration = graph.getPossibleObject(modelResource, SIMU.HasConfiguration);\r
- model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
- // Update active results\r
- model.getActiveResults();\r
- }\r
- if(rvi == null) {\r
- rvi = Variables.getRVI(graph, this).substring(1).replace("/", ".");\r
- }\r
-\r
- rvis = VariableRVIUtils.getActiveRVIs(graph, this); \r
-\r
- if(SysdynVariableProperties.TIMES.equals(name))\r
- // If times were requested, just return them without listening\r
- return getProperty(name);\r
- else\r
- // Otherwise make a request and listen for changes in the result\r
- return graph.syncRequest(new PropertyRequest(this, name));\r
- }\r
- return super.getPossibleExtraProperty(graph, name);\r
- }\r
-\r
- /**\r
- * Register a property subscription\r
- * \r
- * @param request PropertyRequest\r
- * @param procedure \r
- * @param property Name of the requested property\r
- * @return\r
- */\r
- protected VariableValueSubscription registerSubscription(ExternalRead<?> request, Listener<Variable> procedure, String property) {\r
- if(SysdynVariableProperties.TIME.equals(property)) {\r
- // Current time is requested from experiment\r
- VariableValueSubscription subscription = new VariableValueSubscription(request, this, property, procedure);\r
- experiment.addVariableValueSubscription(subscription);\r
- subscription.update();\r
- return subscription;\r
- } else if(model != null && (\r
- SysdynVariableProperties.VALUES.equals(property) || \r
- SysdynVariableProperties.TIMES.equals(property) ||\r
- SysdynVariableProperties.ACTIVE_DATASETS.equals(property))) {\r
- // Other properties are requested from model (they listen to new simulation results)\r
- VariableValueSubscription subscription = new VariableValueSubscription(request, this, property, procedure);\r
- model.addVariableValueSubscription(subscription);\r
- subscription.update();\r
- return subscription;\r
- } else {\r
- return null;\r
- }\r
- }\r
-\r
- /**\r
- * Unregisters a subscription\r
- * @param subscription\r
- */\r
- protected void unregisterSubscription(VariableValueSubscription subscription) {\r
- subscription.setListener(null);\r
- if(SysdynVariableProperties.TIME.equals(subscription.property))\r
- // Time was registered from experiment\r
- experiment.removeVariableValueSubscription(subscription);\r
- else if(SysdynVariableProperties.TIMES.equals(subscription.property) \r
- || SysdynVariableProperties.VALUES.equals(subscription.property)\r
- || SysdynVariableProperties.ACTIVE_DATASETS.equals(subscription.property))\r
- // Other properties were requested from model\r
- model.removeVariableValueSubscription(subscription);\r
- }\r
-\r
- @Override\r
- public Variable getProperty(String name) {\r
- if(SysdynVariableProperties.TIME.equals(name)){\r
- // Get current time from experiment\r
- if(experiment instanceof SysdynPlaybackExperiment) {\r
- SysdynPlaybackExperiment exp = (SysdynPlaybackExperiment) experiment;\r
- return new ConstantPropertyVariable(this, name, exp.getTime(), Datatypes.DOUBLE);\r
- } else {\r
- // Experiment is not compatible, return time = 0\r
- return null;\r
- }\r
- } else if(SysdynVariableProperties.VALUES.equals(name)) {\r
- // Get the values of this variable from the currently active experiment\r
- SysdynResult sr = model.getSysdynResult();\r
- SysdynDataSet ds = sr.getDataSet(rvi);\r
- if(ds == null)\r
- return new ConstantPropertyVariable(this, name, new double[0], Datatypes.DOUBLE_ARRAY);\r
- else\r
- return new ConstantPropertyVariable(this, name, ds.values, Datatypes.DOUBLE_ARRAY);\r
- } else if(SysdynVariableProperties.TIMES.equals(name)) {\r
- // Get the times of this variable from the currently active experiment\r
- SysdynResult sr = model.getSysdynResult();\r
- SysdynDataSet ds = sr.getDataSet(rvi);\r
- if(ds == null)\r
- return new ConstantPropertyVariable(this, name, new double[0], Datatypes.DOUBLE_ARRAY);\r
- else\r
- return new ConstantPropertyVariable(this, name, ds.times, Datatypes.DOUBLE_ARRAY);\r
- } else if(SysdynVariableProperties.ACTIVE_DATASETS.equals(name)) {\r
- // Get all active datasets for this variable (currentyl active experiment and all active saved results)\r
- Collection<SysdynResult> activeResults = model.getActiveResults();\r
- ArrayList<DataSet> result = new ArrayList<DataSet>();\r
- for(SysdynResult sysdynResult : activeResults) {\r
- for(String currvi : rvis.keySet()) {\r
- SysdynDataSet sds = sysdynResult.getDataSet(currvi.substring(1).replace("/", "."));\r
- if(sds != null) {\r
- sds.name = rvis.get(currvi).substring(1).replace("/", ".");\r
- result.add(sds);\r
- }\r
- }\r
- }\r
- return new ConstantPropertyVariable(this, name, result, Datatypes.VARIANT);\r
- }\r
- return null;\r
- }\r
-\r
- /**\r
- * Class for supporting requests with different property parameters. Equals-method has been modified \r
- * from ParametrizedPrivimiteRead to check also the property value.\r
- * \r
- * @author Teemu Lempinen\r
- *\r
- */\r
- class PropertyRequest extends ParametrizedPrimitiveRead<Variable, Variable> {\r
-\r
- String property;\r
-\r
- public PropertyRequest(Variable parameter, String property) {\r
- super(parameter);\r
- this.property = property;\r
- }\r
-\r
- VariableValueSubscription subscription;\r
-\r
- @Override\r
- public void register(Listener<Variable> procedure) {\r
- subscription = registerSubscription(this, procedure, property);\r
- }\r
- @Override\r
- public void unregistered() {\r
- unregisterSubscription(subscription);\r
- subscription = null;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object object) {\r
- if(object instanceof PropertyRequest && super.equals(object)) {\r
- return this.property.equals(((PropertyRequest)object).property);\r
- } else {\r
- return super.equals(object);\r
- }\r
- }\r
-\r
- }\r
-\r
- @Override\r
- public double getParameterValue(ReadGraph graph) throws FMUJNIException, DatabaseException {\r
- if(this.experiment instanceof SysdynGameExperiment) {\r
- FMUControlJNI control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
- RVI rvi = this.getRVI(graph);\r
- String name = rvi.toString();\r
- if(name.length() > 0)\r
- name = name.substring(1).replace("/", ".");\r
- return control.getRealValue(name);\r
- } else {\r
- throw new FMUJNIException("Parameter value cannot be obtained");\r
- }\r
- }\r
-\r
-\r
- @Override\r
- public void setParameterValue(ReadGraph graph, double value) throws FMUJNIException, DatabaseException {\r
- if(this.experiment instanceof SysdynGameExperiment) {\r
- FMUControlJNI control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
- RVI rvi = this.getRVI(graph);\r
- String name = rvi.toString();\r
- if(name.length() > 0)\r
- name = name.substring(1).replace("/", ".");\r
- control.setRealValue(name, value);\r
- \r
- // Set value for all referred variables in modules\r
- SysdynResource sr = SysdynResource.getInstance(graph);\r
- for(Resource dependency : graph.getObjects(this.resource, sr.Variable_isTailOf)) {\r
- Resource head = graph.getPossibleObject(dependency, sr.Variable_HasHead);\r
- Resource ref = graph.getPossibleObject(dependency, sr.Dependency_refersTo);\r
- if(ref != null && head != null) {\r
- String module = "";\r
- if(name.indexOf(".") > 0)\r
- module = name.substring(0, name.lastIndexOf(".") + 1);\r
- String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref);\r
- control.setRealValue(refName, value);\r
- } \r
- }\r
- }\r
- }\r
-}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+\r
+import org.simantics.Simantics;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.type.Datatype;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ParametrizedPrimitiveRead;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.AbstractPropertyVariable;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.db.layer0.variable.Variables;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.request.ExternalRead;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.project.IProject;\r
+import org.simantics.simulation.experiment.IExperiment;\r
+import org.simantics.simulation.ontology.SimulationResource;\r
+import org.simantics.simulation.project.IExperimentManager;\r
+import org.simantics.sysdyn.manager.SysdynExperiment;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
+import org.simantics.sysdyn.manager.SysdynModelManager;\r
+import org.simantics.sysdyn.manager.VariableSubscriptionManager;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+public abstract class IndexVariable<T> extends AbstractPropertyVariable {\r
+\r
+ protected Variable parent;\r
+ protected SysdynModel model;\r
+ protected SysdynExperiment experiment;\r
+ protected String rvi;\r
+ protected HashMap<String, String> rvis;\r
+ protected String indexes;\r
+ protected VariableSubscriptionManager subscriptionManager;\r
+ \r
+ public IndexVariable(ReadGraph graph, Variable parent, String indexes) throws DatabaseException {\r
+ this.parent = parent;\r
+ this.indexes = indexes;\r
+ }\r
+ \r
+ \r
+ protected VariableSubscriptionManager getSubscriptionManager() {\r
+ return this.model;\r
+ }\r
+\r
+ public String getIndexes() {\r
+ return this.indexes;\r
+ }\r
+\r
+ /**\r
+ * Register a property subscription\r
+ * \r
+ * @param request PropertyRequest\r
+ * @param procedure \r
+ * @return\r
+ */\r
+ protected VariableValueSubscription<T> registerSubscription(ExternalRead<?> request, Listener<T> procedure) {\r
+ // Other properties are requested from model (they listen to new simulation results)\r
+ VariableValueSubscription<T> subscription = new VariableValueSubscription<T>(request, this, procedure);\r
+ subscriptionManager.addVariableValueSubscription(subscription);\r
+ subscription.update();\r
+ return subscription;\r
+ }\r
+\r
+ /**\r
+ * Unregisters a subscription\r
+ * @param subscription\r
+ */\r
+ protected void unregisterSubscription(VariableValueSubscription<T> subscription) {\r
+ subscription.setListener(null);\r
+ subscriptionManager.removeVariableValueSubscription(subscription);\r
+ }\r
+ \r
+ \r
+\r
+ /**\r
+ * Class for supporting requests with different property parameters. Equals-method has been modified \r
+ * from ParametrizedPrivimiteRead to check also the property value.\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+ class PropertyRequest extends ParametrizedPrimitiveRead<Variable, T> {\r
+\r
+\r
+ public PropertyRequest(Variable indexVariable) {\r
+ super(indexVariable);\r
+ }\r
+\r
+ VariableValueSubscription<T> subscription;\r
+\r
+ @Override\r
+ public void register(Listener<T> procedure) {\r
+ subscription = registerSubscription(this, procedure);\r
+ }\r
+ @Override\r
+ public void unregistered() {\r
+ unregisterSubscription(subscription);\r
+ subscription = null;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public boolean equals(Object object) {\r
+ if(object instanceof IndexVariable.PropertyRequest && super.equals(object)) {\r
+ return this.parameter.equals(((PropertyRequest)object).parameter);\r
+ } else {\r
+ return super.equals(object);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Resource getContainerResource(ReadGraph graph) throws DatabaseException {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ public Variable getPredicate(ReadGraph graph) throws DatabaseException {\r
+ return null;\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <U> U getValue(ReadGraph graph) throws DatabaseException {\r
+ return (U) getValue(graph, Bindings.DOUBLE);\r
+ }\r
+\r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <U> U getValue(ReadGraph graph, Binding binding) throws DatabaseException {\r
+ ensureInformationAvailable(graph);\r
+ // Do something before request, e.g. calculate some variables used in the request\r
+ beforeRequest(graph);\r
+ \r
+ return (U) graph.syncRequest(new PropertyRequest(this));\r
+ \r
+ }\r
+ \r
+ protected void beforeRequest(ReadGraph graph) throws DatabaseException {\r
+\r
+ }\r
+ \r
+ private void ensureInformationAvailable(ReadGraph graph) throws DatabaseException {\r
+ SimulationResource SIMU = SimulationResource.getInstance(graph);\r
+ ModelingResources MOD = ModelingResources.getInstance(graph);\r
+ \r
+ if(model == null) {\r
+ Resource modelResource = Variables.getModel(graph, parent);\r
+ Resource configuration = graph.getPossibleObject(modelResource, SIMU.HasConfiguration);\r
+ model = SysdynModelManager.getInstance(graph.getSession()).getModel(graph, configuration);\r
+ }\r
+ \r
+ System.out.println(parent.getName(graph));\r
+ Variable var = parent.getParent(graph);\r
+ Resource represents = var.getRepresents(graph);\r
+ Resource experiment = null;\r
+ while(represents != null && !graph.isInstanceOf(represents, MOD.StructuralModel)) {\r
+ System.out.println(var.getName(graph));\r
+\r
+ if(graph.isInstanceOf(represents, SIMU.Experiment)) {\r
+ experiment = represents;\r
+ break;\r
+ }\r
+ \r
+ var = var.getParent(graph);\r
+ represents = var.getRepresents(graph);\r
+ }\r
+\r
+ if(experiment != null) {\r
+ IProject project = Simantics.peekProject();\r
+ IExperimentManager expMan = project.getHint(IExperimentManager.KEY_EXPERIMENT_MANAGER);\r
+ IExperiment e = expMan.getExperiment(NameUtils.getSafeName(graph, experiment));\r
+ if(e instanceof SysdynExperiment)\r
+ this.experiment = (SysdynExperiment)e;\r
+ }\r
+ \r
+ this.subscriptionManager = getSubscriptionManager();\r
+ \r
+ rvi = Variables.getRVI(graph, this);\r
+ rvis = VariableRVIUtils.getActiveRVIs(graph, parent.getParent(graph)); \r
+ }\r
+ \r
+ private Pair<ArrayList<String>,ArrayList<String>> getVariableNameArrays() {\r
+ Pair<ArrayList<String>,ArrayList<String>> result = new Pair<ArrayList<String>,ArrayList<String>>(new ArrayList<String>(), new ArrayList<String>());\r
+ \r
+ if(rvi.indexOf('#') > 0)\r
+ rvi = rvi.substring(0, rvi.indexOf('#'));\r
+ \r
+ String test = rvi;\r
+ if(indexes != null && !indexes.isEmpty()) {\r
+ String regexIndexes = indexes.trim().replace('.', ',').replaceAll("\\b_\\b", "[a-zA-Z0-9_]*");\r
+ test = rvi + "\\[" + regexIndexes + "\\]";\r
+ } else {\r
+ test = rvi + "(\\[.*\\])?";\r
+ }\r
+ for(String k : rvis.keySet()) {\r
+ if(k.matches(test)) {\r
+ String value = rvis.get(k);\r
+ result.first.add(k.substring(1).replace("/", "."));\r
+ result.second.add(value.substring(1).replace("/", "."));\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ \r
+ }\r
+ \r
+ protected ArrayList<String> getVariableNames() {\r
+ return getVariableNameArrays().second;\r
+ }\r
+ \r
+ protected ArrayList<String> getVariableNamesWithIndexNumbers() {\r
+ return getVariableNameArrays().first;\r
+ }\r
+ \r
+ abstract public T getValue();\r
+\r
+ @Override\r
+ public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
+ setValue(graph, value);\r
+ }\r
+ \r
+ @Override\r
+ public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
+ ensureInformationAvailable(graph);\r
+ setIndexedValue(graph, value);\r
+ }\r
+\r
+ abstract protected void setIndexedValue(WriteGraph graph, Object value) throws DatabaseException;\r
+ \r
+\r
+\r
+ @Override\r
+ public String getName(ReadGraph graph) throws DatabaseException {\r
+ return indexes;\r
+ }\r
+\r
+ @Override\r
+ public Object getSerialized(ReadGraph graph) throws DatabaseException {\r
+ return indexes;\r
+ }\r
+\r
+ @Override\r
+ public Variable getParent(ReadGraph graph) throws DatabaseException {\r
+ return parent;\r
+ }\r
+\r
+}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.AdaptionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.exception.MissingVariableException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.structural.stubs.StructuralResource2;\r
-\r
-public class ModuleVariable extends ChildVariable {\r
-\r
- public ModuleVariable(Variable parent, Resource resource) {\r
- super(parent, resource);\r
- }\r
-\r
- @Override\r
- public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf);\r
- if(instanceOf == null)\r
- throw new MissingVariableException("No instanceof for resource " + NameUtils.getSafeName(graph, resource));\r
- Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
- if(configuration == null)\r
- throw new MissingVariableException("No configuration for " + NameUtils.getSafeName(graph, instanceOf));\r
- Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(configuration));\r
- Resource child = children.get(name);\r
- if(child == null)\r
- return null;\r
- else\r
- return graph.adaptContextual(child, this, Variable.class, Variable.class);\r
- }\r
-\r
-\r
- @Override\r
- public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
- StructuralResource2 sr2 = StructuralResource2.getInstance(graph);\r
- Layer0 l0 = Layer0.getInstance(graph);\r
- ArrayList<Variable> result = new ArrayList<Variable>();\r
- \r
- Resource instanceOf = graph.getPossibleObject(this.resource, l0.InstanceOf);\r
- if(instanceOf == null)\r
- return result;\r
- Resource configuration = graph.getPossibleObject(instanceOf, sr2.IsDefinedBy);\r
- if(configuration == null)\r
- return result;\r
- \r
- for(Resource child : graph.syncRequest(new UnescapedChildMapOfResource(configuration)).values()) {\r
- try {\r
- result.add(graph.adaptContextual(child, this, Variable.class, Variable.class));\r
- } catch (AdaptionException e) {\r
- }\r
- }\r
- \r
- return result;\r
- }\r
- \r
-}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+\r
+public class NamesIndexVariable extends IndexVariable<String[]> {\r
+\r
+ public NamesIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ }\r
+\r
+ @Override\r
+ public String[] getValue() {\r
+ ArrayList<String> names = getVariableNames();\r
+ return names.toArray(new String[names.size()]);\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ // TODO Auto-generated method stub\r
+ \r
+ }\r
+}\r
+++ /dev/null
-package org.simantics.sysdyn.adapter;\r
-\r
-import org.simantics.databoard.adapter.AdaptException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-\r
-public interface PropertyProvider {\r
-\r
- Variable getProperty(String name) throws DatabaseException, AdaptException;\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.uri.UnescapedChildMapOfResource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.StandardGraphChildVariable;\r
-import org.simantics.db.layer0.variable.Variable;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.operation.Layer0X;\r
-\r
-public class RunVariable extends StandardGraphChildVariable {\r
-\r
- public RunVariable(Variable parent, Resource resource) {\r
- super(parent, resource);\r
- }\r
-\r
- @Override\r
- public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
- Resource config = getConfiguration(graph);\r
- Map<String, Resource> children = graph.syncRequest(new UnescapedChildMapOfResource(config));\r
- Resource child = children.get(name);\r
- if(child == null) {\r
- return getPossibleSpecialChild(graph, name);\r
- }\r
- else return new HistoryVariable(this, child);\r
- }\r
-\r
-\r
- @Override\r
- public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
- Map<String, Variable> result = new HashMap<String, Variable>();\r
- Resource config = getConfiguration(graph);\r
- for(Map.Entry<String, Resource> entry : graph.syncRequest(new UnescapedChildMapOfResource(config)).entrySet()) {\r
- String name = entry.getKey();\r
- Resource child = entry.getValue();\r
- result.put(name, new HistoryVariable(this, child));\r
- }\r
- collectSpecialChildren(graph, result);\r
- return result.values();\r
- }\r
-\r
- Resource getConfiguration(ReadGraph graph) throws DatabaseException {\r
- Layer0 L0 = Layer0.getInstance(graph);\r
- Layer0X L0X = Layer0X.getInstance(graph);\r
- Resource experiment = graph.getPossibleObject(resource, L0.PartOf);\r
- Resource model = graph.getPossibleObject(experiment, L0.PartOf);\r
- return graph.getPossibleObject(model, L0X.HasBaseRealization);\r
- }\r
- \r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.adaption.SimpleContextualAdapter;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.Variable;\r
-\r
-public class RunVariableAdapter extends SimpleContextualAdapter<Variable, Variable>{\r
-\r
- @Override\r
- public Variable adapt(ReadGraph g, Resource source, Variable context) throws DatabaseException {\r
- return new RunVariable(context, source);\r
- }\r
-}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.adapter;\r
-\r
-/**\r
- * Properties that can be requested from Sysdyn variables\r
- * @author Teemu Lempinen\r
- *\r
- */\r
-public class SysdynVariableProperties {\r
- \r
- final public static String VALUES = "VALUES";\r
- final public static String TIME = "TIME";\r
- final public static String TIMES = "TIMES";\r
- final public static String ACTIVE_DATASETS = "ACTIVE_DATASETS";\r
-\r
-}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+\r
+public class TimeIndexVariable extends IndexVariable<double[]> {\r
+\r
+ public TimeIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ }\r
+\r
+ @Override\r
+ public double[] getValue() {\r
+ SysdynResult sr = model.getSysdynResult();\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ \r
+ double[] result = new double[variableNames.size()];\r
+ for(int i = 0; i < variableNames.size(); i++) {\r
+ SysdynDataSet ds = sr.getDataSet(variableNames.get(i));\r
+ if(ds != null && ds.times != null && ds.times.length > 0) {\r
+ result[i] = ds.times[ds.times.length-1];\r
+ } else {\r
+ result[i] = 0;\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ \r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+\r
+public class TimesIndexVariable extends IndexVariable<double[][]> {\r
+\r
+ public TimesIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ // TODO Auto-generated constructor stub\r
+ }\r
+\r
+ @Override\r
+ public double[][] getValue() {\r
+ SysdynResult sr = model.getSysdynResult();\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ \r
+ double[][] result = new double[variableNames.size()][];\r
+ for(int i = 0; i < variableNames.size(); i++) {\r
+ SysdynDataSet ds = sr.getDataSet(variableNames.get(i));\r
+ if(ds != null && ds.times != null) {\r
+ result[i] = new double[ds.times.length];\r
+ for(int j = 0; j < ds.times.length; j++) {\r
+ result[i][j] = ds.times[j];\r
+ }\r
+ } else {\r
+ result[i] = new double[0];\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.modelica.fmi.FMUControlJNI;\r
+import org.simantics.modelica.fmi.FMUJNIException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+\r
+public class ValueIndexVariable extends IndexVariable<double[]> {\r
+\r
+ public ValueIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ }\r
+\r
+ @Override\r
+ public double[] getValue() {\r
+ FMUControlJNI control = null;\r
+ if(experiment instanceof SysdynGameExperiment) {\r
+ control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
+ }\r
+ \r
+ SysdynResult sr = model.getSysdynResult();\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ \r
+ double[] result = new double[variableNames.size()];\r
+ for(int i = 0; i < variableNames.size(); i++) {\r
+ if(control != null) {\r
+ try {\r
+ result[i] = control.getRealValue(variableNames.get(i));\r
+ } catch (FMUJNIException e) {\r
+ result[i] = 0;\r
+ }\r
+ } else {\r
+ SysdynDataSet ds = sr.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
+ result[i] = 0;\r
+ }\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ Variable var = parent.getParent(graph);\r
+ Resource resource = var.getRepresents(graph);\r
+ \r
+ if(!(value instanceof double[]) || resource == null)\r
+ return;\r
+ \r
+ double[] values = (double[]) value;\r
+ \r
+ FMUControlJNI control = null;\r
+ if(experiment instanceof SysdynGameExperiment) { // Support only game experiments for now..\r
+ control = ((SysdynGameExperiment)this.experiment).getFMUControl();\r
+ if(control == null) \r
+ return;\r
+ \r
+ \r
+\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ for(int i = 0; i < variableNames.size() && i < values.length; i++) {\r
+ if(values[i] == Double.NaN)\r
+ continue;\r
+ \r
+ try {\r
+ String name = variableNames.get(i);\r
+ control.setRealValue(name, values[i]);\r
+ \r
+ // Set value for all referred variables in modules\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ for(Resource dependency : graph.getObjects(resource, sr.Variable_isTailOf)) {\r
+ Resource head = graph.getPossibleObject(dependency, sr.Variable_HasHead);\r
+ Resource ref = graph.getPossibleObject(dependency, sr.Dependency_refersTo);\r
+ if(ref != null && head != null) {\r
+ String module = "";\r
+ if(name.indexOf(".") > 0)\r
+ module = name.substring(0, name.lastIndexOf(".") + 1);\r
+ String refName = module + NameUtils.getSafeName(graph, head) + "." + NameUtils.getSafeName(graph, ref);\r
+ control.setRealValue(refName, values[i]);\r
+ } \r
+ }\r
+ } catch (FMUJNIException e) {\r
+ }\r
+ } \r
+ }\r
+ }\r
+\r
+}\r
--- /dev/null
+package org.simantics.sysdyn.adapter;\r
+\r
+import java.util.ArrayList;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+import org.simantics.sysdyn.manager.SysdynDataSet;\r
+import org.simantics.sysdyn.manager.SysdynResult;\r
+\r
+public class ValuesIndexVariable extends IndexVariable<double[][]> {\r
+\r
+ public ValuesIndexVariable(ReadGraph graph, Variable parent, String indexes)\r
+ throws DatabaseException {\r
+ super(graph, parent, indexes);\r
+ }\r
+\r
+ @Override\r
+ public double[][] getValue() {\r
+ SysdynResult sr = model.getSysdynResult();\r
+ ArrayList<String> variableNames = getVariableNamesWithIndexNumbers();\r
+ \r
+ double[][] result = new double[variableNames.size()][];\r
+ for(int i = 0; i < variableNames.size(); i++) {\r
+ SysdynDataSet ds = sr.getDataSet(variableNames.get(i));\r
+ if(ds != null && ds.values != null) {\r
+ result[i] = new double[ds.values.length];\r
+ for(int j = 0; j < ds.values.length; j++) {\r
+ result[i][j] = ds.values[j];\r
+ }\r
+ } else {\r
+ result[i] = new double[0];\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+ @Override\r
+ public void setIndexedValue(WriteGraph graph, Object value)\r
+ throws DatabaseException {\r
+ \r
+ }\r
+}\r
import java.util.Collection;\r
import java.util.concurrent.atomic.AtomicBoolean;\r
\r
-import org.simantics.databoard.adapter.AdaptException;\r
import org.simantics.db.Session;\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.layer0.variable.Variable;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.ExternalRead;\r
import org.simantics.db.service.QueryControl;\r
import org.simantics.utils.datastructures.Callback;\r
\r
-public class VariableValueSubscription {\r
+public class VariableValueSubscription<T> {\r
\r
- public static final long SUBSCRIPTION_COLLECTION_INTERVAL = 2000L;\r
-\r
- protected ExternalRead<?> request;\r
- protected PropertyProvider provider;\r
- protected String property;\r
- protected Listener<Variable> listener;\r
-\r
- /**\r
- * To protect against invoking listener.exception multiple times which is\r
- * forbidden.\r
- */\r
- protected AtomicBoolean excepted = new AtomicBoolean(false);\r
-\r
- public VariableValueSubscription(ExternalRead<?> request, PropertyProvider variable, String property, Listener<Variable> listener) {\r
- this.request = request;\r
- this.provider = variable;\r
- this.property = property;\r
- this.listener = listener;\r
- }\r
-\r
- public ExternalRead<?> getRequest() {\r
- return request;\r
- }\r
-\r
- public void update() {\r
- update(property);\r
- }\r
-\r
- public void update(String property) {\r
- try {\r
- Variable value = provider.getProperty(property);\r
- fireValue(value);\r
- } catch (DatabaseException e) {\r
- fireException(e);\r
- } catch (AdaptException e) {\r
- fireException(e);\r
- }\r
- }\r
-\r
- void fireValue(Variable value) {\r
- if (listener != null)\r
- listener.execute(value);\r
- }\r
-\r
- void fireException(Throwable t) {\r
- if (listener != null && excepted.compareAndSet(false, true))\r
- listener.exception(t);\r
- }\r
-\r
- public void setListener(Listener<Variable> listener) {\r
- this.listener = listener;\r
- }\r
-\r
- /**\r
- * This makes sure that subscriptions regarding performed DB external reads\r
- * are abolished from DB client caches when no longer needed.\r
- * \r
- * @param session \r
- * @param subscriptions\r
- */\r
- public static void collectSubscriptions(Session session, final VariableValueSubscription[] subscriptions, final ExternalRead<?>... extraReads) {\r
- if (subscriptions.length == 0 && extraReads.length == 0)\r
- return;\r
-\r
- session.asyncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- Collection<ExternalRead<?>> requests = new ArrayList<ExternalRead<?>>(subscriptions.length + extraReads.length);\r
- for (VariableValueSubscription subscription : subscriptions)\r
- requests.add(subscription.getRequest());\r
- for (ExternalRead<?> read : extraReads)\r
- requests.add(read);\r
- graph.getService(QueryControl.class).gc(graph, requests);\r
- }\r
- }, new Callback<DatabaseException>() {\r
- @Override\r
- public void run(DatabaseException e) {\r
- if (e != null)\r
- e.printStackTrace();\r
- }\r
- });\r
- }\r
+ public static final long SUBSCRIPTION_COLLECTION_INTERVAL = 2000L;\r
+\r
+ protected ExternalRead<?> request;\r
+ protected IndexVariable<T> variable;\r
+ protected Listener<T> listener;\r
+\r
+ /**\r
+ * To protect against invoking listener.exception multiple times which is\r
+ * forbidden.\r
+ */\r
+ protected AtomicBoolean excepted = new AtomicBoolean(false);\r
+\r
+ public VariableValueSubscription(ExternalRead<?> request, IndexVariable<T> variable, Listener<T> listener) {\r
+ this.request = request;\r
+ this.variable = variable;\r
+ this.listener = listener;\r
+ }\r
+\r
+ public ExternalRead<?> getRequest() {\r
+ return request;\r
+ }\r
+\r
+\r
+ public void update() {\r
+ T value = variable.getValue();\r
+ fireValue(value);\r
+ }\r
+\r
+ void fireValue(T value) {\r
+ if (listener != null)\r
+ listener.execute(value);\r
+ }\r
+\r
+ void fireException(Throwable t) {\r
+ if (listener != null && excepted.compareAndSet(false, true))\r
+ listener.exception(t);\r
+ }\r
+\r
+ public void setListener(Listener<T> listener) {\r
+ this.listener = listener;\r
+ }\r
+\r
+ /**\r
+ * This makes sure that subscriptions regarding performed DB external reads\r
+ * are abolished from DB client caches when no longer needed.\r
+ * \r
+ * @param session \r
+ * @param subscriptions\r
+ */\r
+ @SuppressWarnings("rawtypes") \r
+ public static void collectSubscriptions(Session session, final VariableValueSubscription[] subscriptions, final ExternalRead<?>... extraReads) {\r
+ if (subscriptions.length == 0 && extraReads.length == 0)\r
+ return;\r
+\r
+ session.asyncRequest(new WriteRequest() {\r
+ @Override\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
+ Collection<ExternalRead<?>> requests = new ArrayList<ExternalRead<?>>(subscriptions.length + extraReads.length);\r
+ for (VariableValueSubscription subscription : subscriptions)\r
+ requests.add(subscription.getRequest());\r
+ for (ExternalRead<?> read : extraReads)\r
+ requests.add(read);\r
+ graph.getService(QueryControl.class).gc(graph, requests);\r
+ }\r
+ }, new Callback<DatabaseException>() {\r
+ @Override\r
+ public void run(DatabaseException e) {\r
+ if (e != null)\r
+ e.printStackTrace();\r
+ }\r
+ });\r
+ }\r
+\r
\r
}\r
import org.simantics.sysdyn.simulation.SimulationScheduler;\r
import org.simantics.sysdyn.manager.SysdynInitKeys;\r
\r
-public class SysdynExperiment extends Experiment implements IDynamicExperiment {\r
+public class SysdynExperiment extends Experiment implements IDynamicExperiment, VariableSubscriptionManager {\r
\r
protected Session session;\r
protected Runnable modificationListener;\r
protected SysdynModel sysdynModel;\r
protected boolean toggled = false;\r
+ @SuppressWarnings("rawtypes")\r
protected THashSet<VariableValueSubscription> variableValueSubscriptions = new THashSet<VariableValueSubscription>();\r
+ @SuppressWarnings("rawtypes")\r
protected volatile VariableValueSubscription[] variableValueSubscriptionsSnapshot = null;\r
\r
protected HashMap<String, String> previousImportantInits = new HashMap<String, String>();\r
\r
public static SysdynExperiment INSTANCE;\r
\r
- public SysdynExperiment(Resource experiment, Resource model) {\r
- super(experiment, model);\r
+ public SysdynExperiment(Resource experiment, Resource model, String identifier) {\r
+ super(experiment, model, identifier);\r
INSTANCE = this;\r
}\r
\r
\r
/* Result subscriptions */\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @param subscription\r
*/\r
+ @Override\r
public void addVariableValueSubscription(VariableValueSubscription subscription) {\r
assert subscription != null;\r
synchronized (variableValueSubscriptions) {\r
}\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @param subscription\r
*/\r
+ @Override\r
public void removeVariableValueSubscription(VariableValueSubscription subscription) {\r
assert subscription != null;\r
synchronized (variableValueSubscriptions) {\r
}\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @return\r
*/\r
- private VariableValueSubscription[] getListenerSnapshot() {\r
+ @Override\r
+ public VariableValueSubscription[] getListenerSnapshot() {\r
VariableValueSubscription[] snapshot = variableValueSubscriptionsSnapshot;\r
if (snapshot == null) {\r
synchronized (variableValueSubscriptions) {\r
skippedVariableUpdate = true;\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Modified copy from AporsExperiment\r
*/\r
- private void updateSubscriptions() {\r
+ @Override\r
+ public void updateSubscriptions() {\r
for(VariableValueSubscription subscription : getListenerSnapshot())\r
subscription.update();\r
skippedVariableUpdate = false;\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
+ public SysdynGameExperiment(Resource experiment, Resource model, String identifier) {\r
+ super(experiment, model, identifier);\r
}\r
\r
public double getStepDuration() {\r
import org.simantics.db.exception.ServiceException;\r
import org.simantics.db.procedure.Listener;\r
import org.simantics.db.request.Read;\r
+import org.simantics.db.service.VirtualGraphSupport;\r
import org.simantics.layer0.Layer0;\r
import org.simantics.modelica.data.SimulationResult;\r
import org.simantics.objmap.IMapping;\r
* Maintains a Java representation of system dynamic model.\r
* @author Hannu Niemistö, Teemu Lempinen\r
*/\r
-public class SysdynModel implements IMappingListener, IModel {\r
+public class SysdynModel implements IMappingListener, IModel, VariableSubscriptionManager {\r
\r
private Session session;\r
\r
private CopyOnWriteArrayList<Runnable> resultListeners =\r
new CopyOnWriteArrayList<Runnable>();\r
\r
+ @SuppressWarnings("rawtypes")\r
protected THashSet<VariableValueSubscription> variableValueSubscriptions = new THashSet<VariableValueSubscription>();\r
+ @SuppressWarnings("rawtypes")\r
protected volatile VariableValueSubscription[] variableValueSubscriptionsSnapshot = null;\r
\r
@SuppressWarnings("rawtypes")\r
// Create a new experiment based on the experiment resource type\r
SysdynResource sr = SysdynResource.getInstance(g);\r
IDynamicExperiment exp;\r
+ \r
+ String name = NameUtils.getSafeName(g, experiment);\r
if(g.isInstanceOf(experiment, sr.PlaybackExperiment)) {\r
- exp = new SysdynPlaybackExperiment(experiment, modelResource);\r
+ exp = new SysdynPlaybackExperiment(experiment, modelResource, name);\r
} else if(g.isInstanceOf(experiment, sr.GameExperiment)) {\r
- exp = new SysdynGameExperiment(experiment, modelResource);\r
+ exp = new SysdynGameExperiment(experiment, modelResource, name);\r
} else if(g.isInstanceOf(experiment, sr.BasicExperiment)) {\r
- exp = new SysdynExperiment(experiment, modelResource);\r
+ exp = new SysdynExperiment(experiment, modelResource, name);\r
} else {\r
return null;\r
}\r
\r
((SysdynExperiment)exp).init(g);\r
\r
- ExperimentRuns.createRun(g.getSession(), experiment, exp, listener, null);\r
+ \r
+ VirtualGraphSupport support = g.getSession().getService(VirtualGraphSupport.class);\r
+ ExperimentRuns.createRun(g.getSession(), support.getWorkspacePersistent("experiments"), experiment, exp, SysdynResource.URIs.Experiment_Run, listener, null);\r
if(listener != null)\r
listener.onExperimentActivated(exp);\r
return exp;\r
}\r
\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @param subscription\r
*/\r
+ @Override\r
public void addVariableValueSubscription(VariableValueSubscription subscription) {\r
assert subscription != null;\r
synchronized (variableValueSubscriptions) {\r
}\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @param subscription\r
*/\r
- public void removeVariableValueSubscription(VariableValueSubscription subscription) {\r
+ @Override\r
+ public void removeVariableValueSubscription(VariableValueSubscription subscription) {\r
assert subscription != null;\r
synchronized (variableValueSubscriptions) {\r
//System.out.println("REMOVE listener " + subscription);\r
}\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Copy from AprosExperiment\r
* @return\r
*/\r
- private VariableValueSubscription[] getListenerSnapshot() {\r
+ @Override\r
+ public VariableValueSubscription[] getListenerSnapshot() {\r
VariableValueSubscription[] snapshot = variableValueSubscriptionsSnapshot;\r
if (snapshot == null) {\r
synchronized (variableValueSubscriptions) {\r
return snapshot;\r
}\r
\r
+ @SuppressWarnings("rawtypes")\r
/**\r
* Modified copy from AporsExperiment\r
*/\r
- private void updateSubscriptions() {\r
+ @Override\r
+ public void updateSubscriptions() {\r
VariableValueSubscription[] snapShot = getListenerSnapshot();\r
for(VariableValueSubscription subscription : snapShot)\r
subscription.update();\r
ScheduledExecutorService playbackExecutionService;\r
PlaybackConfiguration playbackConfiguration;\r
\r
- public SysdynPlaybackExperiment(Resource experiment, Resource model) {\r
- super(experiment, model);\r
+ public SysdynPlaybackExperiment(Resource experiment, Resource model, String identifier) {\r
+ super(experiment, model, identifier);\r
this.time = 0;\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.manager;\r
+\r
+import org.simantics.sysdyn.adapter.VariableValueSubscription;\r
+\r
+@SuppressWarnings("rawtypes") \r
+public interface VariableSubscriptionManager {\r
+ \r
+ public void addVariableValueSubscription(VariableValueSubscription subscription);\r
+ \r
+ public void removeVariableValueSubscription(VariableValueSubscription subscription);\r
+ \r
+ public VariableValueSubscription[] getListenerSnapshot();\r
+ \r
+ public void updateSubscriptions();\r
+\r
+}\r