]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fix a bug in vensim import which sometimes confused auxilaries with stocks
authorjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Jun 2014 11:27:39 +0000 (11:27 +0000)
committerjkauttio <jkauttio@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 17 Jun 2014 11:27:39 +0000 (11:27 +0000)
refs #2924

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29634 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/DelayExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/Expression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/IntegralExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/LookupExpression.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/NormalExpression.java

index ceef806803dcdf8024cb645e47d09f1458b5fb8a..980948d03808fa179e8cdd9d9181cb591cf25f08 100644 (file)
@@ -140,6 +140,9 @@ public class MdlUtil {
                                int closing = expression.indexOf(')', matcher.end());\r
                                String parameters = expression.substring(matcher.end(), closing);\r
                                parameters = parameters.replaceAll("\\*", ".*");\r
+                               parameters = parameters.replaceAll("/", "./");\r
+                               parameters = parameters.replaceAll("\\+", ".+");\r
+                               parameters = parameters.replaceAll("-", ".-");\r
                                result.append(parameters);\r
                                offset = closing;\r
                        }\r
index 48c7ab88b0c2d7365971d3466d8924de0b2b6ea5..031611d75448806f4d7d59b3f8816fe9ba187c87 100644 (file)
@@ -7,7 +7,7 @@ import org.simantics.sysdyn.modelImport.MdlUtil;
 import org.simantics.sysdyn.modelImport.model.Auxiliary;\r
 import org.simantics.sysdyn.modelImport.model.Variable;\r
 import org.simantics.sysdyn.modelImport.model.Stock;\r
-import org.simantics.sysdyn.modelImport.model.expression.IntegralExpression;\r
+import org.simantics.sysdyn.modelImport.model.expression.Expression;\r
 \r
 public class SketchVariable extends SketchElement {\r
        \r
@@ -51,11 +51,13 @@ public class SketchVariable extends SketchElement {
                }\r
                \r
                Variable var;\r
-               if ((variable.getExpression() instanceof IntegralExpression)) {\r
+               \r
+               Expression expr = variable.getExpression();\r
+               if (expr != null && expr.getExpressionTypeString().equals("StockExpression"))\r
                        var = new Stock();\r
-               }\r
                else\r
                        var = new Auxiliary();\r
+               \r
                var.setDimensions(getDimensions());\r
                \r
                return variable.initVariable(var);\r
index f740d2012e75034c90fcb8d4216b484df466c2e7..95e88ef6b10fd8f25289c10a91052b0535c13649 100644 (file)
@@ -40,4 +40,9 @@ public class DelayExpression extends Expression {
        public Resource getExpressionType(ReadGraph graph) {\r
                return SysdynResource.getInstance(graph).DelayExpression;\r
        }\r
+       \r
+       @Override\r
+       public String getExpressionTypeString() {\r
+               return "DelayExpression";\r
+       }\r
 }\r
index bfccc31fec928e7fd28341790158b8e70c881c37..5cad2cff23dbf3e92ffd0ea4c7ee2e71e5b6b81f 100644 (file)
@@ -64,6 +64,11 @@ public class EnumerationExpression extends Expression {
                return subExpressions.get(0).expression.getExpressionType(graph);\r
        }\r
        \r
+       @Override\r
+       public String getExpressionTypeString() {\r
+               return subExpressions.get(0).expression.getExpressionTypeString();\r
+       }\r
+       \r
        @Override\r
        public Resource getResource() {\r
                return subExpressions.get(0).expression.getResource();\r
index 84eac6638fae61bb0ad7bc043fa17b01ffa53c04..c930084dcb71ffeb8a4af43a281c6b537f6698d9 100644 (file)
@@ -39,6 +39,8 @@ public abstract class Expression implements IWriteableObject {
        }\r
        \r
        public abstract Resource getExpressionType(ReadGraph graph);\r
+       \r
+       public abstract String getExpressionTypeString();\r
 \r
        @Override\r
        public Resource getResource() {\r
index bc75c359c5040b98787eeeb63b97df4007635c80..3ca709f4a446134ebbe2d2e989ccbedbe6af54cc 100644 (file)
@@ -35,4 +35,9 @@ public class IntegralExpression extends Expression {
        public Resource getExpressionType(ReadGraph graph) {\r
                return SysdynResource.getInstance(graph).StockExpression;\r
        }\r
+       \r
+       @Override\r
+       public String getExpressionTypeString() {\r
+               return "StockExpression";\r
+       }\r
 }\r
index 8f68915d9239b7b437766c9eb6d1303dec2095d5..efcd9b29d46ca0b35710edadc561e8944ccac90f 100644 (file)
@@ -57,5 +57,10 @@ public class LookupExpression extends Expression {
        public Resource getExpressionType(ReadGraph graph) {\r
                return SysdynResource.getInstance(graph).WithLookupExpression;\r
        }\r
+       \r
+       @Override\r
+       public String getExpressionTypeString() {\r
+               return "WithLookupExpression";\r
+       }\r
 \r
 }\r
index a940a643456e94adc49479ca57b255fe4bc72bc2..b1efa51d08eaf5e4b58b7bf2dc57c62e5c5018bd 100644 (file)
@@ -29,6 +29,23 @@ public class NormalExpression extends Expression {
        \r
        @Override\r
        public Resource getExpressionType(ReadGraph graph) {\r
-               return SysdynResource.getInstance(graph).NormalExpression;\r
+               try {\r
+                       Double.parseDouble(expression);\r
+                       return SysdynResource.getInstance(graph).ParameterExpression;\r
+               }\r
+               catch (NumberFormatException e) {\r
+                       return SysdynResource.getInstance(graph).NormalExpression;\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public String getExpressionTypeString() {\r
+               try {\r
+                       Double.parseDouble(expression);\r
+                       return "ParameterExpression";\r
+               }\r
+               catch (NumberFormatException e) {\r
+                       return "NormalExpression";\r
+               }\r
        }\r
 }\r