From 3b9ce4bfb9f2685879fae7707024b23ce2a1d5f5 Mon Sep 17 00:00:00 2001 From: "jussi.koskela" Date: Wed, 18 Jun 2014 13:50:38 +0000 Subject: [PATCH] refs #4971 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29656 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn/scl/Sysdyn.scl | 1 + .../sysdyn/utils/DocumentationUtils.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/org.simantics.sysdyn/scl/Sysdyn.scl b/org.simantics.sysdyn/scl/Sysdyn.scl index 7b48a7f4..12e7ef77 100644 --- a/org.simantics.sysdyn/scl/Sysdyn.scl +++ b/org.simantics.sysdyn/scl/Sysdyn.scl @@ -92,6 +92,7 @@ importJava "org.simantics.sysdyn.utils.DocumentationUtils" where lastValue :: Resource -> String -> String -> Double lastValue2 :: Variable -> String -> Variable + lastValueIndexed :: Variable -> String -> Variable equation :: Variable -> String -> Variable importJava "org.simantics.sysdyn.manager.SysdynExperiments" where diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java index 0d5c6131..28ec9bf6 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/utils/DocumentationUtils.java @@ -7,6 +7,8 @@ import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.core.runtime.NullProgressMonitor; import org.simantics.Simantics; @@ -19,6 +21,7 @@ import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.util.EvaluatingListener; import org.simantics.db.layer0.util.EvaluatingListener.Criterion; import org.simantics.db.layer0.util.EvaluatingListener.Evaluation; @@ -43,6 +46,7 @@ import org.simantics.sysdyn.representation.Variability; import org.simantics.sysdyn.representation.Variable; import org.simantics.sysdyn.utils.imports.ImportUtils; import org.simantics.utils.DataContainer; +import org.simantics.utils.datastructures.Pair; public class DocumentationUtils { @@ -568,6 +572,37 @@ public class DocumentationUtils { } + /** + * Splits indexed variable reference into name and indices part. + * + * @param path + */ + public static Pair splitToNameAndIndices(String reference) { + final Pattern indexPattern = Pattern.compile("^([^\\[]*)\\[([^\\]]*)]$"); + Matcher m = indexPattern.matcher(reference); + + if (m.matches()) { + String name = m.group(1); + String indices = m.group(2).trim().replaceAll("\\s*,\\s*", ","); + return Pair.make(name, indices); + } else { + return Pair.make(reference, ""); + } + + } + + public static org.simantics.db.layer0.variable.Variable lastValueIndexed(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException { + + if(run == null) return null; + + Pair nameAndIndices = splitToNameAndIndices(path); + + org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second); + if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + path); + + return v; + } + public static org.simantics.db.layer0.variable.Variable equation(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException { if(run == null) return null; -- 2.47.1