import java.util.ArrayList;\r
import java.util.Collection;\r
import java.util.Collections;\r
+import java.util.Comparator;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.List;\r
* @param Configurations Configurations, one main configuration and possible modules\r
* @return Complete Modelica code of a model\r
*/\r
- public static String write(Collection<Configuration> configurations, boolean isGame, String omVersion) {\r
+ public static String write(Collection<Configuration> _configurations, boolean isGame, String omVersion) {\r
+ \r
+ ArrayList<Configuration> configurations = new ArrayList<Configuration>(_configurations);\r
+ Collections.sort(configurations, new Comparator<Configuration>() {\r
+\r
+ boolean uses(Configuration o1, Configuration o2) {\r
+ ModuleType type = o2.getModuleType();\r
+ if(type == null) return false;\r
+ for(IElement e : o1.getElements()) {\r
+ if(e instanceof Module) {\r
+ Module m = (Module)e;\r
+ if(m.getType().equals(type)) {\r
+ return true;\r
+ }\r
+ }\r
+ }\r
+ return false;\r
+ }\r
+ \r
+ @Override\r
+ public int compare(Configuration o1, Configuration o2) {\r
+ if(uses(o1, o2)) return 1;\r
+ else if(uses(o2, o1)) return -1;\r
+ else return 0;\r
+ }\r
+ \r
+ });\r
+ \r
Configuration modelConf = null;\r
for(Configuration conf : configurations) {\r
if(conf.getModel() != null) {\r
\r
b.append("\n");\r
\r
+\r
+ if(!enumerations.isEmpty()) {\r
+ b.append("// Enumeration definitions\n");\r
+ for(Enumeration e : enumerations) {\r
+ b.append(e.getDeclaration());\r
+ }\r
+ }\r
+\r
b.append("// Variable definitions\n");\r
for(IndependentVariable variable : variables) {\r
app = variable.getDeclaration();\r
// Input definitions\r
inputDefinitions(b, configuration, inputs, inputReferences);\r
\r
- if(!enumerations.isEmpty()) {\r
- b.append("// Enumeration definitions\n");\r
- for(Enumeration e : enumerations) {\r
- b.append(e.getDeclaration());\r
- }\r
- }\r
-\r
boolean initialEquations = false;\r
for(Stock stock : stocks) {\r
app = stock.getInitialEquation();\r