]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fix to Sysdyn unit validator: stock variables with whitespace in their names (refs...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Jan 2014 07:50:11 +0000 (07:50 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 16 Jan 2014 07:50:11 +0000 (07:50 +0000)
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
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/expressions/StockExpression.java

index b71d836ee1ec5854857e241697f3141e610c1151..e90bae08b3142174ba207d57f7ef630e74d89b79 100644 (file)
       <menuContribution\r
             locationURI="popup:#ExternalFunctionFileBrowser?after=wbStart">\r
       </menuContribution>\r
+      <menuContribution\r
+            allPopups="false"\r
+            locationURI="menu:sFile?after=#FileNewMenu">\r
+         <command\r
+               commandId="org.simantics.sysdyn.ui.importModel"\r
+               label="Import Model"\r
+               style="push">\r
+         </command>\r
+      </menuContribution>\r
       <menuContribution\r
             allPopups="false"\r
             locationURI="menu:#FileNewMenu">\r
index 18cd0632a9cded1cc13caa4cd4c25326d81aac6a..95a3a5bd1d4edcb6a66fc99046e675af1e27f2c5 100644 (file)
@@ -60,6 +60,10 @@ public class StockExpression extends Expression {
     \r
     @Override\r
     public String getEquation() {\r
+        return getEquation(true);\r
+    }\r
+    \r
+    private String getEquation(boolean modelicaEquation) {\r
         \r
         // Build range e.g. Stock[2,3]\r
        String range = IndexUtils.rangeToIndexes(parent, this.getArrayRange());\r
@@ -67,13 +71,17 @@ public class StockExpression extends Expression {
        // Stock equation is always der(Stock)\r
         StringBuilder b = new StringBuilder();\r
         b.append("    der(")\r
-        .append(parent.getModelicaName() + range)\r
+        .append(modelicaEquation ? parent.getModelicaName() : parent.getName() + range)\r
         .append(") = ");\r
         \r
         if (integralEquation != null) {\r
-               String equation = FormatUtils.replaceWhitespace(this.integralEquation);\r
-               equation = FormatUtils.formatExpressionForModelica(parent, equation);\r
-               b.append(equation).append(";\n");\r
+               if (modelicaEquation) {\r
+                       String equation = FormatUtils.replaceWhitespace(this.integralEquation);\r
+                       equation = FormatUtils.formatExpressionForModelica(parent, equation);\r
+               b.append(equation).append(";\n");\r
+               } else {\r
+                       b.append(integralEquation).append(";\n");\r
+               }\r
         } else {\r
                // Stock equation is formed automatically using incoming and outgoing flows (actually the nearest valves in those flows)\r
                    ArrayList<Valve> incoming = ((Stock)parent).getIncomingValves();\r
@@ -86,7 +94,7 @@ public class StockExpression extends Expression {
                        } else {\r
                            b.append(" zeros(");\r
                            for(int i = 0; i < enumerations.size(); i++) {\r
-                               b.append(enumerations.get(i).getModelicaName() + ".size");\r
+                               b.append(modelicaEquation ? enumerations.get(i).getModelicaName() : enumerations.get(i).getName() + ".size");\r
                                if(i != enumerations.size() - 1)\r
                                    b.append(", ");\r
                            }\r
@@ -96,9 +104,9 @@ public class StockExpression extends Expression {
                    } else {\r
                        // incoming valves add and outgoing valves reduce the stock\r
                        for(Valve valve : outgoing)\r
-                           b.append("\n        - ").append(valve.getModelicaName() + range);\r
+                           b.append("\n        - ").append(modelicaEquation ? valve.getModelicaName() : valve.getName() + range);\r
                        for(Valve valve : incoming)\r
-                           b.append("\n        + ").append(valve.getModelicaName() + range);\r
+                           b.append("\n        + ").append(modelicaEquation ? valve.getModelicaName() : valve.getName() + range);\r
                    }\r
                    b.append(";\n");\r
         }\r
@@ -197,7 +205,7 @@ public class StockExpression extends Expression {
     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
+               String integralEquation = getEquation(false);\r
             if(integralEquation.contains("="))\r
                 result = UnitUtils.matchUnits(\r
                         graph, \r