]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Unit validation for stock integrals (fixes #4306)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 6 Jun 2013 06:16:02 +0000 (06:16 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 6 Jun 2013 06:16:02 +0000 (06:16 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27508 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Model.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java

index 5403623ec0060f360bb0f06de421c5a3b7cf3577..76f28a476979fd13b025d374a688d7b895820307 100644 (file)
@@ -55,7 +55,10 @@ public class Model {
     \r
     @RelatedElement(SimulationResource.URIs.HasConfiguration)\r
     private Configuration configuration;\r
-\r
+    \r
+    @RelatedValue(SysdynResource.URIs.SysdynModel_timeUnit)\r
+    private String timeUnit;\r
+    \r
     @RelatedElements(\r
             value = Layer0.URIs.ConsistsOf,\r
             composition = true)\r
@@ -243,4 +246,9 @@ public class Model {
     public Configuration getModelConfiguration() {\r
        return configuration;\r
     }\r
+    \r
+    \r
+    public String getTimeUnit() {\r
+        return timeUnit;\r
+    }\r
 }\r
index 17e1a78e6c3cd049134d2367d315114992662a20..9bd2b3dbae5ff086ec76e9f7ee1a7f18beb30cb3 100644 (file)
@@ -15,11 +15,13 @@ import java.io.StringReader;
 import java.util.ArrayList;\r
 import java.util.Set;\r
 \r
+import org.simantics.db.ReadGraph;\r
 import org.simantics.objmap.annotations.GraphType;\r
 import org.simantics.objmap.annotations.RelatedValue;\r
 import org.simantics.sysdyn.SysdynResource;\r
 import org.simantics.sysdyn.expressionParser.ExpressionParser;\r
 import org.simantics.sysdyn.expressionParser.ParseException;\r
+import org.simantics.sysdyn.manager.SysdynModel;\r
 import org.simantics.sysdyn.representation.Book;\r
 import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IElement;\r
@@ -28,6 +30,7 @@ import org.simantics.sysdyn.representation.Stock;
 import org.simantics.sysdyn.representation.Valve;\r
 import org.simantics.sysdyn.representation.utils.FormatUtils;\r
 import org.simantics.sysdyn.representation.utils.IndexUtils;\r
+import org.simantics.sysdyn.representation.utils.UnitUtils;\r
 \r
 /**\r
  * Class representing a stock expression in a variable\r
@@ -174,5 +177,21 @@ public class StockExpression extends Expression {
        return value;\r
     }\r
 \r
-\r
+    \r
+    @Override\r
+    public String validateUnits(ReadGraph graph, SysdynModel model) {\r
+        String result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), initialEquation);\r
+        if(result == null) {\r
+            String integralEquation = getEquation();\r
+            if(integralEquation.contains("="))\r
+                result = UnitUtils.matchUnits(\r
+                        graph, \r
+                        model, \r
+                        parent.getParentConfiguration(), \r
+                        parent.getUnit(), \r
+                        "(" + integralEquation.substring(integralEquation.indexOf("=") + 1, integralEquation.lastIndexOf(";")) +") * time");\r
+        }\r
+        \r
+        return result;\r
+    }\r
 }\r