From ad4eda5768b186895da7600da5c272ecabb82dff Mon Sep 17 00:00:00 2001 From: miettinen Date: Thu, 16 Jan 2014 07:50:11 +0000 Subject: [PATCH] Fix to Sysdyn unit validator: stock variables with whitespace in their names (refs #4548). Import Model to file menu (refs #4665). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28642 ac1ea38d-2e2b-0410-8846-a27921b304fc --- org.simantics.sysdyn.ui/plugin.xml | 9 +++++++ .../expressions/StockExpression.java | 24 ++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index b71d836e..e90bae08 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -1355,6 +1355,15 @@ + + + + diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java index 18cd0632..95a3a5bd 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java @@ -60,6 +60,10 @@ public class StockExpression extends Expression { @Override public String getEquation() { + return getEquation(true); + } + + private String getEquation(boolean modelicaEquation) { // Build range e.g. Stock[2,3] String range = IndexUtils.rangeToIndexes(parent, this.getArrayRange()); @@ -67,13 +71,17 @@ public class StockExpression extends Expression { // Stock equation is always der(Stock) StringBuilder b = new StringBuilder(); b.append(" der(") - .append(parent.getModelicaName() + range) + .append(modelicaEquation ? parent.getModelicaName() : parent.getName() + range) .append(") = "); if (integralEquation != null) { - String equation = FormatUtils.replaceWhitespace(this.integralEquation); - equation = FormatUtils.formatExpressionForModelica(parent, equation); - b.append(equation).append(";\n"); + if (modelicaEquation) { + String equation = FormatUtils.replaceWhitespace(this.integralEquation); + equation = FormatUtils.formatExpressionForModelica(parent, equation); + b.append(equation).append(";\n"); + } else { + b.append(integralEquation).append(";\n"); + } } else { // Stock equation is formed automatically using incoming and outgoing flows (actually the nearest valves in those flows) ArrayList incoming = ((Stock)parent).getIncomingValves(); @@ -86,7 +94,7 @@ public class StockExpression extends Expression { } else { b.append(" zeros("); for(int i = 0; i < enumerations.size(); i++) { - b.append(enumerations.get(i).getModelicaName() + ".size"); + b.append(modelicaEquation ? enumerations.get(i).getModelicaName() : enumerations.get(i).getName() + ".size"); if(i != enumerations.size() - 1) b.append(", "); } @@ -96,9 +104,9 @@ public class StockExpression extends Expression { } else { // incoming valves add and outgoing valves reduce the stock for(Valve valve : outgoing) - b.append("\n - ").append(valve.getModelicaName() + range); + b.append("\n - ").append(modelicaEquation ? valve.getModelicaName() : valve.getName() + range); for(Valve valve : incoming) - b.append("\n + ").append(valve.getModelicaName() + range); + b.append("\n + ").append(modelicaEquation ? valve.getModelicaName() : valve.getName() + range); } b.append(";\n"); } @@ -197,7 +205,7 @@ public class StockExpression extends Expression { public String validateUnits(ReadGraph graph, SysdynModel model) { String result = UnitUtils.matchUnits(graph, model, parent.getParentConfiguration(), parent.getUnit(), initialEquation); if(result == null) { - String integralEquation = getEquation(); + String integralEquation = getEquation(false); if(integralEquation.contains("=")) result = UnitUtils.matchUnits( graph, -- 2.47.1