From 73766ab85c2f4e2478257767ac65e1cde63c33f2 Mon Sep 17 00:00:00 2001 From: lempinen Date: Fri, 10 May 2013 06:16:13 +0000 Subject: [PATCH] Added time property for sysdyn variables. (refs #4280) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27361 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../src/org/simantics/sysdyn/Functions.java | 2 ++ .../sysdyn/adapter/TimeIndexVariable.java | 6 ++++-- .../sysdyn/manager/SysdynGameExperiment.java | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java index 8391e72f..6a309d35 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/Functions.java @@ -99,6 +99,8 @@ public class Functions { return new ValuesIndexVariable(graph, context, name); else if(TIMES.equals(property)) return new TimesIndexVariable(graph, context, name); + else if(TIME.equals(property)) + return new TimeIndexVariable(graph, context, name); else if(NAMES.equals(property)) return new NamesIndexVariable(graph, context, name); else if(ACTIVE_DATASETS.equals(property)) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java index cee804c0..65c34770 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/TimeIndexVariable.java @@ -4,6 +4,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.variable.Variable; +import org.simantics.sysdyn.manager.SysdynGameExperiment; import org.simantics.sysdyn.manager.SysdynPlaybackExperiment; public class TimeIndexVariable extends IndexVariable { @@ -17,8 +18,9 @@ public class TimeIndexVariable extends IndexVariable { public Double getValue() { if(experiment != null && experiment instanceof SysdynPlaybackExperiment) return ((SysdynPlaybackExperiment)experiment).getTime(); - else - return null; + if(experiment != null && experiment instanceof SysdynGameExperiment) + return ((SysdynGameExperiment)experiment).getTime(); + return null; } @Override 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 c3c2e6f0..b64c5265 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynGameExperiment.java @@ -92,6 +92,17 @@ public class SysdynGameExperiment extends SysdynExperiment { public FMUControlJNI getFMUControl() { return control; } + + public double getTime() { + if(control != null) { + try { + return control.getTime(); + } catch (FMUJNIException e) { + } + } + return 0.0; + } + @Override public void init(ReadGraph g) { @@ -353,7 +364,10 @@ public class SysdynGameExperiment extends SysdynExperiment { monitor.worked(1); int stepNumber = 1; - while(control.getTime() < (eTime - 1e-9) && !canceled) { // Substract a very small number, because OpenModelica is not very precise with its Real numbers + while(control.getTime() < eTime && !canceled) { + if(eTime - control.getTime() < stepLength) + control.setStepLength(eTime - control.getTime()); + monitor.subTask("Simulate step (time = " + control.getTime() + ")"); control.simulateStep(); monitor.worked(1); -- 2.47.1