]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Ensured that all module configuration definitions are written into the declaration...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Nov 2012 12:09:18 +0000 (12:09 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Nov 2012 12:09:18 +0000 (12:09 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26445 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java

index 63623124ef222695f98d8c3a8101b22cebda1c70..d65c07b1afa01ac5a024001dc5feb6a76cb0fad7 100644 (file)
@@ -68,11 +68,17 @@ public class ModelicaWriter {
         for(Sheet sheet : getSpreadSheets(configurations))\r
             sheetNames.add(sheet.getName());\r
         \r
+        // Write all module configurations to the declarations part (first)\r
         for(Configuration conf : configurations) {\r
             conf.setIsGameConfiguration(isGame);\r
-            writeConfiguration(conf, sheetNames, b);\r
+            if(!conf.equals(modelConf))\r
+                writeConfiguration(conf, sheetNames, b);\r
         }\r
         \r
+        // Write model configuration last, so that equations-part does not contain module definitions\r
+        modelConf.setIsGameConfiguration(isGame);\r
+        writeConfiguration(modelConf, sheetNames, b);\r
+        \r
         b.append("end " + modelName + ";\n\n");\r
         \r
         b.append(getGlobalSpreadSheets(configurations));\r
@@ -184,7 +190,7 @@ public class ModelicaWriter {
         String className = mt != null ? (mt.getName().replace(" ", "")) : null;\r
         \r
         if(className != null)\r
-            b.append("class ").append(className);\r
+            b.append("\nclass ").append(className);\r
         \r
         // Add spreadsheets to all modules and model. Model is "inner" and modules "outer"\r
         String globalStatus = mt != null ? "outer" : "inner";\r
@@ -242,20 +248,25 @@ public class ModelicaWriter {
             }\r
         }\r
 \r
-        boolean first = true;\r
+        boolean equation = false;\r
         b.append("// Equations\n");\r
         for(IndependentVariable variable : variables) {\r
             app = variable.getEquation();\r
             if (app != null) {\r
-                if(first) {\r
+                if(!equation) {\r
                     b.append("equation\n");\r
-                    first = false;\r
+                    equation = true;\r
                 }\r
                 \r
                 b.append(app);\r
             }\r
         }\r
         \r
+        // If "equation" has not been added but there are still equations to be defined, add "equation"\r
+        if(!equation && (!inputReferences.isEmpty() || !outputDependencies.isEmpty() ||\r
+                !moduleInputs.isEmpty() || !modules.isEmpty()))\r
+            b.append("equation\n");\r
+\r
         // Continous input references\r
         continuousInputReferences(b, inputReferences);\r
         \r