]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Make sure nested modules are in correct order when writing modelica code 86/4386/2
authorJani Mäkinen <jani.makinen@semantum.fi>
Wed, 19 Aug 2020 11:47:31 +0000 (14:47 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 24 Aug 2020 14:57:10 +0000 (14:57 +0000)
gitlab #59

Change-Id: Id469cdf6cc79f3320398dad8e713643241fb83c1

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

index 97d8494397443b7735ff236d0f74c10d8db8c779..9c0287d60f6cba2ab2e50e87ab09221ef10f3656 100644 (file)
@@ -48,6 +48,15 @@ public class ModelicaWriter {
        public static final String VAR_STOP = "stopTime";
        public static final String VAR_STEP = "timeStep";
 
+       static String configurationName(Configuration c) {
+               ModuleType moduleType = c.getModuleType();
+               if(moduleType == null) {
+                       return "Model";
+               } else {
+                       return moduleType.getName();
+               }
+       }
+       
        /**
         * Write a collection of configurations into a single Modelica code
         * @param isGame 
@@ -57,9 +66,19 @@ public class ModelicaWriter {
         */
        public static String write(Collection<Configuration> _configurations, double startTime, double stopTime, double timeStep, boolean isGame, String omVersion) {
 
+               
                ArrayList<Configuration> configurations = new ArrayList<Configuration>(_configurations);
                Collections.sort(configurations, new Comparator<Configuration>() {
-
+                       
+                       Configuration findConfiguration(ModuleType type) {
+                               for(Configuration c : _configurations) {
+                                       if(type.equals(c.getModuleType())) {
+                                               return c;
+                                       }
+                               }
+                               return null;
+                       }
+                                               
                        boolean uses(Configuration o1, Configuration o2) {
                                ModuleType type = o2.getModuleType();
                                if(type == null) return false;
@@ -68,6 +87,11 @@ public class ModelicaWriter {
                                                Module m = (Module)e;
                                                if(m.getType().equals(type)) {
                                                        return true;
+                                               } else {
+                                                       Configuration c = findConfiguration(m.getType());
+                                                       if(c != null) {
+                                                               return uses(c, o2);
+                                                       }
                                                }
                                        }
                                }
@@ -78,7 +102,7 @@ public class ModelicaWriter {
                        public int compare(Configuration o1, Configuration o2) {
                                if(uses(o1, o2)) return 1;
                                else if(uses(o2, o1)) return -1;
-                               else return 0;
+                               else return configurationName(o1).compareTo(configurationName(o2));
                        }
 
                });