From 949cd684b9383f488751078123e7324e20fd9b42 Mon Sep 17 00:00:00 2001 From: jkauttio Date: Tue, 17 Jun 2014 11:27:39 +0000 Subject: [PATCH] Fix a bug in vensim import which sometimes confused auxilaries with stocks refs #2924 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29634 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/sysdyn/modelImport/MdlUtil.java | 3 +++ .../modelImport/mdl/SketchVariable.java | 8 +++++--- .../model/expression/DelayExpression.java | 5 +++++ .../expression/EnumerationExpression.java | 5 +++++ .../model/expression/Expression.java | 2 ++ .../model/expression/IntegralExpression.java | 5 +++++ .../model/expression/LookupExpression.java | 5 +++++ .../model/expression/NormalExpression.java | 19 ++++++++++++++++++- 8 files changed, 48 insertions(+), 4 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java index ceef8068..980948d0 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/MdlUtil.java @@ -140,6 +140,9 @@ public class MdlUtil { int closing = expression.indexOf(')', matcher.end()); String parameters = expression.substring(matcher.end(), closing); parameters = parameters.replaceAll("\\*", ".*"); + parameters = parameters.replaceAll("/", "./"); + parameters = parameters.replaceAll("\\+", ".+"); + parameters = parameters.replaceAll("-", ".-"); result.append(parameters); offset = closing; } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java index 48c7ab88..031611d7 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/mdl/SketchVariable.java @@ -7,7 +7,7 @@ import org.simantics.sysdyn.modelImport.MdlUtil; import org.simantics.sysdyn.modelImport.model.Auxiliary; import org.simantics.sysdyn.modelImport.model.Variable; import org.simantics.sysdyn.modelImport.model.Stock; -import org.simantics.sysdyn.modelImport.model.expression.IntegralExpression; +import org.simantics.sysdyn.modelImport.model.expression.Expression; public class SketchVariable extends SketchElement { @@ -51,11 +51,13 @@ public class SketchVariable extends SketchElement { } Variable var; - if ((variable.getExpression() instanceof IntegralExpression)) { + + Expression expr = variable.getExpression(); + if (expr != null && expr.getExpressionTypeString().equals("StockExpression")) var = new Stock(); - } else var = new Auxiliary(); + var.setDimensions(getDimensions()); return variable.initVariable(var); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/DelayExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/DelayExpression.java index f740d201..95e88ef6 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/DelayExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/DelayExpression.java @@ -40,4 +40,9 @@ public class DelayExpression extends Expression { public Resource getExpressionType(ReadGraph graph) { return SysdynResource.getInstance(graph).DelayExpression; } + + @Override + public String getExpressionTypeString() { + return "DelayExpression"; + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java index bfccc31f..5cad2cff 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/EnumerationExpression.java @@ -64,6 +64,11 @@ public class EnumerationExpression extends Expression { return subExpressions.get(0).expression.getExpressionType(graph); } + @Override + public String getExpressionTypeString() { + return subExpressions.get(0).expression.getExpressionTypeString(); + } + @Override public Resource getResource() { return subExpressions.get(0).expression.getResource(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/Expression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/Expression.java index 84eac663..c930084d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/Expression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/Expression.java @@ -39,6 +39,8 @@ public abstract class Expression implements IWriteableObject { } public abstract Resource getExpressionType(ReadGraph graph); + + public abstract String getExpressionTypeString(); @Override public Resource getResource() { diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/IntegralExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/IntegralExpression.java index bc75c359..3ca709f4 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/IntegralExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/IntegralExpression.java @@ -35,4 +35,9 @@ public class IntegralExpression extends Expression { public Resource getExpressionType(ReadGraph graph) { return SysdynResource.getInstance(graph).StockExpression; } + + @Override + public String getExpressionTypeString() { + return "StockExpression"; + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/LookupExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/LookupExpression.java index 8f68915d..efcd9b29 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/LookupExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/LookupExpression.java @@ -57,5 +57,10 @@ public class LookupExpression extends Expression { public Resource getExpressionType(ReadGraph graph) { return SysdynResource.getInstance(graph).WithLookupExpression; } + + @Override + public String getExpressionTypeString() { + return "WithLookupExpression"; + } } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/NormalExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/NormalExpression.java index a940a643..b1efa51d 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/NormalExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelImport/model/expression/NormalExpression.java @@ -29,6 +29,23 @@ public class NormalExpression extends Expression { @Override public Resource getExpressionType(ReadGraph graph) { - return SysdynResource.getInstance(graph).NormalExpression; + try { + Double.parseDouble(expression); + return SysdynResource.getInstance(graph).ParameterExpression; + } + catch (NumberFormatException e) { + return SysdynResource.getInstance(graph).NormalExpression; + } + } + + @Override + public String getExpressionTypeString() { + try { + Double.parseDouble(expression); + return "ParameterExpression"; + } + catch (NumberFormatException e) { + return "NormalExpression"; + } } } -- 2.47.1