From eb407585d68b5880ad49ac8c663229acdc2ba7c4 Mon Sep 17 00:00:00 2001 From: villberg Date: Mon, 31 Mar 2014 06:41:05 +0000 Subject: [PATCH] Sorted generated modelica text for easier processing. Fixed shadow variable code generation. refs #4765 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29216 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/modelica/ModelicaWriter.java | 45 +++++++++++++++---- .../sysdyn/representation/Shadow.java | 9 ++++ 2 files changed, 46 insertions(+), 8 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 186c92a5..fc9415c7 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java @@ -14,6 +14,7 @@ package org.simantics.sysdyn.modelica; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -47,7 +48,34 @@ public class ModelicaWriter { * @param Configurations Configurations, one main configuration and possible modules * @return Complete Modelica code of a model */ - public static String write(Collection configurations, boolean isGame, String omVersion) { + public static String write(Collection _configurations, boolean isGame, String omVersion) { + + ArrayList configurations = new ArrayList(_configurations); + Collections.sort(configurations, new Comparator() { + + boolean uses(Configuration o1, Configuration o2) { + ModuleType type = o2.getModuleType(); + if(type == null) return false; + for(IElement e : o1.getElements()) { + if(e instanceof Module) { + Module m = (Module)e; + if(m.getType().equals(type)) { + return true; + } + } + } + return false; + } + + @Override + public int compare(Configuration o1, Configuration o2) { + if(uses(o1, o2)) return 1; + else if(uses(o2, o1)) return -1; + else return 0; + } + + }); + Configuration modelConf = null; for(Configuration conf : configurations) { if(conf.getModel() != null) { @@ -209,6 +237,14 @@ public class ModelicaWriter { b.append("\n"); + + if(!enumerations.isEmpty()) { + b.append("// Enumeration definitions\n"); + for(Enumeration e : enumerations) { + b.append(e.getDeclaration()); + } + } + b.append("// Variable definitions\n"); for(IndependentVariable variable : variables) { app = variable.getDeclaration(); @@ -239,13 +275,6 @@ public class ModelicaWriter { // Input definitions inputDefinitions(b, configuration, inputs, inputReferences); - if(!enumerations.isEmpty()) { - b.append("// Enumeration definitions\n"); - for(Enumeration e : enumerations) { - b.append(e.getDeclaration()); - } - } - boolean initialEquations = false; for(Stock stock : stocks) { app = stock.getInitialEquation(); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java index 91358b71..3842234c 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Shadow.java @@ -89,5 +89,14 @@ public class Shadow extends Variable { public String getDocumentationDefinition(ReadGraph graph) throws DatabaseException { return null; } + + @Override + public String getModelicaName() { + if(getOriginal() != null) + return getOriginal().getModelicaName(); + else + return super.getModelicaName(); + } + } -- 2.47.1