From: lempinen Date: Fri, 27 Apr 2012 09:00:22 +0000 (+0000) Subject: Step property controls to game experiment tab (refs #3398) X-Git-Tag: simantics-1.6~6^2~18 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=c4c4ccf46d7b398416abf5b8b50859947b8200b3;p=simantics%2Fsysdyn.git Step property controls to game experiment tab (refs #3398) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@24831 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.sysdyn.ontology/graph.tg b/org.simantics.sysdyn.ontology/graph.tg index 4e7c067d..a9b8ca8a 100644 Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ diff --git a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph index 1fdfb7e1..54086f8a 100644 --- a/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph +++ b/org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph @@ -269,6 +269,7 @@ SYSDYN.BasicExperiment -- SYSDYN.GameExperiment.stepDuration --> L0.Double -- SYSDYN.GameExperiment.stepLength --> L0.Double GLOBAL_VARIABLES = CollectionUtils.toSet("time"); /** * Evaluates dependency-related issues for a component. @@ -124,7 +128,7 @@ public class DependencyFunction { // Check that all references have corresponding arrows if (references != null && dependencies != null) { for (String reference : references) { - if (!dependencies.contains(reference)) { + if (!dependencies.contains(reference) && !GLOBAL_VARIABLES.contains(reference)) { Resource variable = null; if ((variable = ValidationUtils.reach(graph, component, reference)) != null) { if(isStock) { @@ -241,7 +245,7 @@ public class DependencyFunction { if (references != null && dependencies != null) { for (String reference : references) { // If dependencies does not contain reference and the reference -// is not reachable from component, add the name + // is not reachable from component, add the name if (!dependencies.contains(reference) && ValidationUtils.reach(graph, component, reference) == null) { result.add(reference); } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java index 6721ad51..673bf856 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -16,16 +16,21 @@ import java.util.ArrayList; import java.util.HashMap; import org.eclipse.core.runtime.IProgressMonitor; +import org.simantics.db.AsyncReadGraph; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.procedure.AsyncListener; +import org.simantics.db.request.Read; import org.simantics.modelica.IModelicaMonitor; import org.simantics.modelica.SimulationLocation; import org.simantics.modelica.data.DataSet; import org.simantics.modelica.data.SimulationResult; import org.simantics.modelica.fmi.FMUControlJNI; import org.simantics.modelica.fmi.FMUJNIException; +import org.simantics.simulation.experiment.ExperimentState; import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.Pair; /** * Game experiment @@ -37,8 +42,11 @@ public class SysdynGameExperiment extends SysdynExperiment { private FMUControlJNI control; private String[] subscription; private HashMap> results; - private double stepLength = 0.1; - private double stepDuration = 1.0; + private double stepLength = DEFAULT_STEP_LENGTH; + private double stepDuration = DEFAULT_STEP_DURATION; + + public static double DEFAULT_STEP_DURATION = 1.0; + public static double DEFAULT_STEP_LENGTH = 0.1; public SysdynGameExperiment(Resource experiment, Resource model) { super(experiment, model); @@ -58,12 +66,6 @@ public class SysdynGameExperiment extends SysdynExperiment { public void setStepLength(double stepLength) { this.stepLength = stepLength; - if(control != null) { - try { - control.setStepLength(this.stepLength); - } catch (FMUJNIException e) { - } - } } @Override @@ -75,11 +77,37 @@ public class SysdynGameExperiment extends SysdynExperiment { results = new HashMap>(); - try { - stepDuration = g.getPossibleRelatedValue(experiment, SysdynResource.getInstance(g).GameExperiment_stepDuration); - } catch (DatabaseException e) { - stepDuration = 1.0; - } + g.asyncRequest(new Read>() { + + @Override + public Pair perform(ReadGraph graph) + throws DatabaseException { + SysdynResource sr = SysdynResource.getInstance(graph); + Double stepDuration = graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepDuration); + Double stepLength =graph.getPossibleRelatedValue(experiment, sr.GameExperiment_stepLength); + return new Pair(stepDuration, stepLength); + } + }, new AsyncListener>() { + + @Override + public void execute(AsyncReadGraph graph, + Pair result) { + setStepDuration(result.first != null ? result.first : DEFAULT_STEP_DURATION); + setStepLength(result.second != null ? result.second : DEFAULT_STEP_LENGTH); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + throwable.printStackTrace(); + setStepDuration(DEFAULT_STEP_DURATION); + setStepLength(DEFAULT_STEP_LENGTH); + } + + @Override + public boolean isDisposed() { + return getState().equals(ExperimentState.DISPOSED); + } + }); } @Override @@ -159,7 +187,10 @@ public class SysdynGameExperiment extends SysdynExperiment { if(duration <= 0.0) duration = stepDuration; + try { + control.setStepLength(stepLength); // Set step length each time in case there has been changes + double time = control.getTime(); double eTime = time + duration; double[] results = new double[subscription.length]; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java index 433848f6..ec61ed05 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Entity.java @@ -13,6 +13,7 @@ package org.simantics.sysdyn.representation; import org.simantics.layer0.Layer0; import org.simantics.objmap.annotations.GraphType; +import org.simantics.sysdyn.representation.visitors.IElementVisitorVoid; /** * Dummy class representing any entity. @@ -20,6 +21,10 @@ import org.simantics.objmap.annotations.GraphType; * */ @GraphType(Layer0.URIs.Entity) -public class Entity { +public class Entity implements IElement { + + @Override + public void accept(IElementVisitorVoid v) { + } }