From f817854b60aecf75151a4a3a62cd84b8fe3bbdd7 Mon Sep 17 00:00:00 2001 From: lempinen Date: Mon, 26 Nov 2012 12:09:18 +0000 Subject: [PATCH] Ensured that all module configuration definitions are written into the declaration part of a model (fixes #3875) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26445 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/modelica/ModelicaWriter.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java index 63623124..d65c07b1 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -68,11 +68,17 @@ public class ModelicaWriter { for(Sheet sheet : getSpreadSheets(configurations)) sheetNames.add(sheet.getName()); + // Write all module configurations to the declarations part (first) for(Configuration conf : configurations) { conf.setIsGameConfiguration(isGame); - writeConfiguration(conf, sheetNames, b); + if(!conf.equals(modelConf)) + writeConfiguration(conf, sheetNames, b); } + // Write model configuration last, so that equations-part does not contain module definitions + modelConf.setIsGameConfiguration(isGame); + writeConfiguration(modelConf, sheetNames, b); + b.append("end " + modelName + ";\n\n"); b.append(getGlobalSpreadSheets(configurations)); @@ -184,7 +190,7 @@ public class ModelicaWriter { String className = mt != null ? (mt.getName().replace(" ", "")) : null; if(className != null) - b.append("class ").append(className); + b.append("\nclass ").append(className); // Add spreadsheets to all modules and model. Model is "inner" and modules "outer" String globalStatus = mt != null ? "outer" : "inner"; @@ -242,20 +248,25 @@ public class ModelicaWriter { } } - boolean first = true; + boolean equation = false; b.append("// Equations\n"); for(IndependentVariable variable : variables) { app = variable.getEquation(); if (app != null) { - if(first) { + if(!equation) { b.append("equation\n"); - first = false; + equation = true; } b.append(app); } } + // If "equation" has not been added but there are still equations to be defined, add "equation" + if(!equation && (!inputReferences.isEmpty() || !outputDependencies.isEmpty() || + !moduleInputs.isEmpty() || !modules.isEmpty())) + b.append("equation\n"); + // Continous input references continuousInputReferences(b, inputReferences); -- 2.47.1