import java.util.Date;\r
import java.util.List;\r
import java.util.concurrent.TimeUnit;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
\r
import org.eclipse.core.runtime.NullProgressMonitor;\r
import org.simantics.Simantics;\r
import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.exception.MissingVariableException;\r
import org.simantics.db.layer0.util.EvaluatingListener;\r
import org.simantics.db.layer0.util.EvaluatingListener.Criterion;\r
import org.simantics.db.layer0.util.EvaluatingListener.Evaluation;\r
import org.simantics.sysdyn.representation.Variable;\r
import org.simantics.sysdyn.utils.imports.ImportUtils;\r
import org.simantics.utils.DataContainer;\r
+import org.simantics.utils.datastructures.Pair;\r
\r
public class DocumentationUtils {\r
\r
\r
}\r
\r
+ /**\r
+ * Splits indexed variable reference into name and indices part.\r
+ * \r
+ * @param path\r
+ */\r
+ public static Pair<String, String> splitToNameAndIndices(String reference) {\r
+ final Pattern indexPattern = Pattern.compile("^([^\\[]*)\\[([^\\]]*)]$");\r
+ Matcher m = indexPattern.matcher(reference);\r
+ \r
+ if (m.matches()) {\r
+ String name = m.group(1);\r
+ String indices = m.group(2).trim().replaceAll("\\s*,\\s*", ",");\r
+ return Pair.make(name, indices);\r
+ } else {\r
+ return Pair.make(reference, "");\r
+ }\r
+\r
+ }\r
+ \r
+ public static org.simantics.db.layer0.variable.Variable lastValueIndexed(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException {\r
+ \r
+ if(run == null) return null;\r
+\r
+ Pair<String, String> nameAndIndices = splitToNameAndIndices(path);\r
+\r
+ org.simantics.db.layer0.variable.Variable v = run.browsePossible(graph, "/" + nameAndIndices.first + "#value#" + nameAndIndices.second);\r
+ if(v == null) throw new MissingVariableException("No variable for SysDyn reference path: " + path);\r
+ \r
+ return v;\r
+ } \r
+ \r
public static org.simantics.db.layer0.variable.Variable equation(ReadGraph graph, org.simantics.db.layer0.variable.Variable run, String path) throws DatabaseException {\r
\r
if(run == null) return null;\r