SYSDYN.GameExperiment <T SYSDYN.Experiment
>-- SYSDYN.GameExperiment.stepDuration --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.GameExperiment.stepLength --> L0.Double <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.GameExperiment.stepDuration 1.0
SYSDYN.SimulateOnChangeExperiment <T SYSDYN.Experiment
public final Resource GameExperiment;\r
public final Resource GameExperiment_stepDuration;\r
public final Resource GameExperiment_stepDuration_Inverse;\r
+ public final Resource GameExperiment_stepLength;\r
+ public final Resource GameExperiment_stepLength_Inverse;\r
public final Resource HasEquationOrEmpty;\r
public final Resource HasEquationOrEmpty_Inverse;\r
public final Resource HasHead;\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 GameExperiment_stepLength = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepLength";\r
+ public static final String GameExperiment_stepLength_Inverse = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepLength/Inverse";\r
public static final String HasEquationOrEmpty = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty";\r
public static final String HasEquationOrEmpty_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty/Inverse";\r
public static final String HasHead = "http://www.simantics.org/Sysdyn-1.1/HasHead";\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
+ GameExperiment_stepLength = getResourceOrNull(graph, URIs.GameExperiment_stepLength);\r
+ GameExperiment_stepLength_Inverse = getResourceOrNull(graph, URIs.GameExperiment_stepLength_Inverse);\r
HasEquationOrEmpty = getResourceOrNull(graph, URIs.HasEquationOrEmpty);\r
HasEquationOrEmpty_Inverse = getResourceOrNull(graph, URIs.HasEquationOrEmpty_Inverse);\r
HasHead = getResourceOrNull(graph, URIs.HasHead);\r
\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.manager.SysdynGameExperiment;\r
\r
/**\r
* Handler for creating a new Game Experiment\r
protected Resource getExperimentType(ReadGraph g) {\r
return SysdynResource.getInstance(g).GameExperiment;\r
}\r
+ \r
+ /**\r
+ * Override to do experiment-specific alterations\r
+ */\r
+ protected void configureExperiment(WriteGraph graph, Resource experiment) throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ graph.claimLiteral(experiment, sr.GameExperiment_stepDuration, SysdynGameExperiment.DEFAULT_STEP_DURATION);\r
+ graph.claimLiteral(experiment, sr.GameExperiment_stepLength, SysdynGameExperiment.DEFAULT_STEP_LENGTH);\r
+ }\r
\r
protected String getNameSuggestion() {\r
return "Game Experiment";\r
import org.eclipse.swt.widgets.ToolItem;\r
import org.eclipse.ui.actions.CompoundContributionItem;\r
import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TextModifyListener;\r
-import org.simantics.browsing.ui.swt.widgets.impl.TrackedModifyEvent;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupportImpl;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.management.ISessionContext;\r
import org.simantics.project.IProject;\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.manager.SysdynGameExperiment;\r
import org.simantics.sysdyn.ui.properties.SysdynBasicColorProvider;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.utils.ui.validators.DoubleValidator;\r
\r
*/\r
public class GameStepDurationContribution extends CompoundContributionItem {\r
\r
- private TrackedText stepLength;\r
+ private TrackedText stepDuration;\r
private int width = 40;\r
private ToolItem ti;\r
\r
final SysdynGameExperiment game = (SysdynGameExperiment) active;\r
\r
// Create the text\r
- WidgetSupport support = new WidgetSupportImpl(); // Dummy widget support for using tracked text\r
\r
ti = new ToolItem(parent, SWT.SEPARATOR, index);\r
ti.setText("Step Duration");\r
ti.setToolTipText("Step Duration");\r
\r
- stepLength = new TrackedText(parent, support, SWT.BORDER);\r
- stepLength.getWidget().setText("" + game.getStepDuration());\r
- \r
- ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), stepLength.getWidget());\r
- stepLength.setColorProvider(new SysdynBasicColorProvider(resourceManager));\r
- \r
- stepLength.setInputValidator(new DoubleValidator());\r
+ ISessionContext context = SimanticsUI.getSessionContext();\r
+ WidgetSupportImpl support = new WidgetSupportImpl(); // Dummy widget support for using tracked text\r
+\r
+ stepDuration = new TrackedText(parent, support, SWT.BORDER);\r
+ ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), stepDuration.getWidget());\r
+ stepDuration.setColorProvider(new SysdynBasicColorProvider(resourceManager));\r
+ stepDuration.setInputValidator(new DoubleValidator());\r
+ stepDuration.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.GameExperiment_stepDuration));\r
+ stepDuration.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.GameExperiment_stepDuration));\r
\r
- stepLength.addModifyListener(new TextModifyListener() {\r
- \r
- @Override\r
- public void modifyText(TrackedModifyEvent e) {\r
- final Double value = Double.parseDouble(stepLength.getText());\r
- game.setStepDuration(value);\r
- \r
- SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
- \r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
- graph.claimLiteral(\r
- game.getResource(), \r
- SysdynResource.getInstance(graph).GameExperiment_stepDuration, \r
- value);\r
- }\r
- });\r
- }\r
- });\r
+ support.fireInput(context, game.getResource());\r
\r
ti.setWidth(width);\r
- ti.setControl(stepLength.getWidget());\r
+ ti.setControl(stepDuration.getWidget());\r
\r
}\r
\r
--- /dev/null
+package org.simantics.sysdyn.ui.properties;\r
+\r
+import org.eclipse.jface.layout.GridDataFactory;\r
+import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.custom.ScrolledComposite;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Label;\r
+import org.eclipse.ui.IWorkbenchSite;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyFactory;\r
+import org.simantics.browsing.ui.swt.widgets.StringPropertyModifier;\r
+import org.simantics.browsing.ui.swt.widgets.TrackedText;\r
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
+import org.simantics.db.management.ISessionContext;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyFactory;\r
+import org.simantics.sysdyn.ui.properties.widgets.factories.DoublePropertyModifier;\r
+import org.simantics.utils.ui.validators.DoubleValidator;\r
+\r
+/**\r
+ * Tab for displaying game experiment properties\r
+ * \r
+ * @author Teemu Lempinen\r
+ *\r
+ */\r
+public class GameExperimentTab extends LabelPropertyTabContributor {\r
+\r
+ @Override\r
+ public void createControls(Composite body, IWorkbenchSite site,\r
+ ISessionContext context, WidgetSupport support) {\r
+ \r
+ ScrolledComposite sc = new ScrolledComposite(body, SWT.H_SCROLL | SWT.V_SCROLL);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);\r
+ GridLayoutFactory.fillDefaults().applyTo(sc);\r
+ \r
+ Composite composite = new Composite(sc, SWT.NONE);\r
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);\r
+ GridLayoutFactory.fillDefaults().margins(3, 3).numColumns(2).applyTo(composite);\r
+ \r
+ // Label\r
+ Label label = new Label(composite, SWT.NONE);\r
+ label.setText("Name");\r
+ \r
+ TrackedText name = new TrackedText(composite, support, SWT.BORDER);\r
+ name.setTextFactory(new StringPropertyFactory(Layer0.URIs.HasLabel));\r
+ name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasLabel));\r
+ name.addModifyListener(new StringPropertyModifier(context, Layer0.URIs.HasName));\r
+ name.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), name.getWidget())));\r
+\r
+ // Step duration (i.e. how many time units is one step in user's perspective)\r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Step duration");\r
+ \r
+ TrackedText stepDuration = new TrackedText(composite, support, SWT.BORDER);\r
+ stepDuration.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.GameExperiment_stepDuration));\r
+ stepDuration.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.GameExperiment_stepDuration));\r
+ stepDuration.setInputValidator(new DoubleValidator());\r
+ stepDuration.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), stepDuration.getWidget())));\r
+ GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).applyTo(name.getWidget());\r
+\r
+ // Integrator step length (i.e. how long is a integration step in the simulator. This time is stepped until stepDuration is full)\r
+ label = new Label(composite, SWT.NONE);\r
+ label.setText("Integrator step length");\r
+ \r
+ TrackedText integratorStep = new TrackedText(composite, support, SWT.BORDER);\r
+ integratorStep.setTextFactory(new DoublePropertyFactory(SysdynResource.URIs.GameExperiment_stepLength));\r
+ integratorStep.addModifyListener(new DoublePropertyModifier(context, SysdynResource.URIs.GameExperiment_stepLength));\r
+ integratorStep.setInputValidator(new DoubleValidator());\r
+ integratorStep.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), integratorStep.getWidget())));\r
+ \r
+ // Scrolled composite settings\r
+ sc.setContent(composite);\r
+ sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));\r
+ sc.setExpandHorizontal(true);\r
+ sc.setExpandVertical(true);\r
+ \r
+ }\r
+\r
+}\r
0,\r
r,\r
"Experiment Properties"));\r
-\r
+ \r
+ // Game experiment\r
+ if (backend.isInstanceOf(r, sr.GameExperiment))\r
+ return Collections.singleton(\r
+ new ComparableTabContributor(\r
+ new GameExperimentTab(),\r
+ 0,\r
+ r,\r
+ "Experiment Properties"));\r
+ \r
// Default experiment\r
if (backend.isInstanceOf(r, simu.Experiment))\r
return Collections.singleton(\r
import org.simantics.layer0.Layer0;\r
import org.simantics.scl.reflection.annotations.SCLValue;\r
import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.collections.CollectionUtils;\r
\r
/**\r
* Evaluates issues related to Dependencies (arrows)\r
* \r
*/\r
public class DependencyFunction {\r
+ \r
+ // Set containing the names of variables that can be used everywhere, like "time"\r
+ private static Set<String> GLOBAL_VARIABLES = CollectionUtils.toSet("time");\r
\r
/**\r
* Evaluates dependency-related issues for a component.\r
// Check that all references have corresponding arrows\r
if (references != null && dependencies != null) {\r
for (String reference : references) {\r
- if (!dependencies.contains(reference)) {\r
+ if (!dependencies.contains(reference) && !GLOBAL_VARIABLES.contains(reference)) {\r
Resource variable = null;\r
if ((variable = ValidationUtils.reach(graph, component, reference)) != null) {\r
if(isStock) {\r
if (references != null && dependencies != null) {\r
for (String reference : references) {\r
// If dependencies does not contain reference and the reference\r
-// is not reachable from component, add the name\r
+ // is not reachable from component, add the name\r
if (!dependencies.contains(reference) && ValidationUtils.reach(graph, component, reference) == null) {\r
result.add(reference);\r
}\r
import java.util.HashMap;\r
\r
import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.simantics.db.AsyncReadGraph;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.AsyncListener;\r
+import org.simantics.db.request.Read;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.modelica.SimulationLocation;\r
import org.simantics.modelica.data.DataSet;\r
import org.simantics.modelica.data.SimulationResult;\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.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.Pair;\r
\r
/**\r
* Game experiment\r
private FMUControlJNI control;\r
private String[] subscription;\r
private HashMap<String, ArrayList<Double>> results;\r
- private double stepLength = 0.1;\r
- private double stepDuration = 1.0;\r
+ private double stepLength = DEFAULT_STEP_LENGTH;\r
+ private double stepDuration = DEFAULT_STEP_DURATION;\r
+ \r
+ public static double DEFAULT_STEP_DURATION = 1.0;\r
+ public static double DEFAULT_STEP_LENGTH = 0.1;\r
\r
public SysdynGameExperiment(Resource experiment, Resource model) {\r
super(experiment, model);\r
\r
public void setStepLength(double stepLength) {\r
this.stepLength = stepLength;\r
- if(control != null) {\r
- try {\r
- control.setStepLength(this.stepLength);\r
- } catch (FMUJNIException e) {\r
- }\r
- }\r
}\r
\r
@Override\r
\r
results = new HashMap<String, ArrayList<Double>>();\r
\r
- try {\r
- stepDuration = g.getPossibleRelatedValue(experiment, SysdynResource.getInstance(g).GameExperiment_stepDuration);\r
- } catch (DatabaseException e) {\r
- stepDuration = 1.0;\r
- }\r
+ g.asyncRequest(new Read<Pair<Double, Double>>() {\r
+\r
+ @Override\r
+ public Pair<Double, Double> perform(ReadGraph graph)\r
+ throws DatabaseException {\r
+ SysdynResource sr = SysdynResource.getInstance(graph);\r
+ Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration);\r
+ Double stepLength =graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength);\r
+ return new Pair<Double, Double>(stepDuration, stepLength);\r
+ }\r
+ }, new AsyncListener<Pair<Double, Double>>() {\r
+\r
+ @Override\r
+ public void execute(AsyncReadGraph graph,\r
+ Pair<Double, Double> result) {\r
+ setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION);\r
+ setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH);\r
+ }\r
+\r
+ @Override\r
+ public void exception(AsyncReadGraph graph, Throwable throwable) {\r
+ throwable.printStackTrace();\r
+ setStepDuration(DEFAULT_STEP_DURATION);\r
+ setStepLength(DEFAULT_STEP_LENGTH);\r
+ }\r
+\r
+ @Override\r
+ public boolean isDisposed() {\r
+ return getState().equals(ExperimentState.DISPOSED);\r
+ }\r
+ });\r
}\r
\r
@Override\r
if(duration <= 0.0)\r
duration = stepDuration;\r
\r
+ \r
try {\r
+ control.setStepLength(stepLength); // Set step length each time in case there has been changes\r
+\r
double time = control.getTime();\r
double eTime = time + duration;\r
double[] results = new double[subscription.length];\r
\r
import org.simantics.layer0.Layer0;\r
import org.simantics.objmap.annotations.GraphType;\r
+import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid;\r
\r
/**\r
* Dummy class representing any entity.\r
*\r
*/\r
@GraphType(Layer0.URIs.Entity)\r
-public class Entity {\r
+public class Entity implements IElement {\r
+\r
+ @Override\r
+ public void accept(IElementVisitorVoid v) {\r
+ }\r
\r
}\r