]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Sorted generated modelica text for easier processing. Fixed shadow variable code...
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 31 Mar 2014 06:41:05 +0000 (06:41 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 31 Mar 2014 06:41:05 +0000 (06:41 +0000)
refs #4765

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29216 ac1ea38d-2e2b-0410-8846-a27921b304fc

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

index 186c92a5655a14fafdcc75775705137494601cb5..fc9415c7cc496a34973603fc321c8d91dfbe59f5 100644 (file)
@@ -14,6 +14,7 @@ package org.simantics.sysdyn.modelica;
 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
@@ -47,7 +48,34 @@ public class ModelicaWriter {
      * @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
@@ -209,6 +237,14 @@ public class ModelicaWriter {
         \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
@@ -239,13 +275,6 @@ public class ModelicaWriter {
         // 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
index 91358b71c093d8dddc72b5826e573800ea61563d..3842234c2c1f62549ae69e66494f0af896e6544c 100644 (file)
@@ -89,5 +89,14 @@ public class Shadow extends Variable {
     public String getDocumentationDefinition(ReadGraph graph) throws DatabaseException {\r
         return null;\r
     }\r
+    \r
+    @Override\r
+    public String getModelicaName() {\r
+        if(getOriginal() != null)\r
+            return getOriginal().getModelicaName();\r
+        else\r
+            return super.getModelicaName();\r
+    }\r
+    \r
 }\r
 \r