]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Preparing for new OpenModelica release (refs #3878)
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 11 Jan 2013 10:35:59 +0000 (10:35 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 11 Jan 2013 10:35:59 +0000 (10:35 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26597 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java
org.simantics.sysdyn/src/org/simantics/sysdyn/modelica/ModelicaWriter.java
org.simantics.sysdyn/src/org/simantics/sysdyn/representation/utils/FormatUtils.java

index 57baedc46dd9bd1ba8a59250138d3c611ef3b289..002c340a5713eb8d694bc32abe861b251b2ea5ff 100644 (file)
@@ -386,28 +386,27 @@ public class ModelicaManager {
             s.close();\r
     }\r
 \r
-\r
-    public static void createFullMo(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException {\r
-        // Create full .mo for parameter comparison\r
-        ArrayList<String> parameters = new ArrayList<String>();\r
-        parameters.add(simulationLocation.fullMosFile.getAbsolutePath());\r
-        Process process = runOMC(simulationLocation.simulationDir, monitor, parameters);\r
+    private static void trimExtraFromFullModel(SimulationLocation simulationLocation) {\r
         try {\r
-            process.waitFor();\r
-\r
             FileInputStream fs = new FileInputStream(simulationLocation.fullModel);\r
             InputStreamReader in = new InputStreamReader(fs);\r
             BufferedReader br = new BufferedReader(in);\r
             StringBuffer sb = new StringBuffer();\r
 \r
-            boolean OMBlock = false;\r
             String textinLine;\r
+            boolean openmodelicaflag = false;\r
+            int breakpoint = 0;\r
             while((textinLine = br.readLine()) != null) {\r
-                if(textinLine.contains("OpenModelica"))\r
-                    OMBlock = Boolean.FALSE.equals(OMBlock);\r
-                else\r
-                    if(!OMBlock)\r
-                        sb.append(textinLine + "\n"); // if you don\92t put the \n you will have all the code on one line as fer said\r
+                if(openmodelicaflag == true) {\r
+                    breakpoint = sb.length();\r
+                    openmodelicaflag = false;\r
+                }\r
+                \r
+                if(textinLine.contains("end OpenModelica;"))\r
+                    openmodelicaflag = true;\r
+\r
+\r
+                sb.append(textinLine + "\n"); // if you don\92t put the \n you will have all the code on one line as fer said\r
             }\r
 \r
             br.close();\r
@@ -416,15 +415,27 @@ public class ModelicaManager {
 \r
             FileWriter fstream = new FileWriter(simulationLocation.fullModel);\r
             BufferedWriter outobj = new BufferedWriter(fstream);\r
-            outobj.write(sb.toString());\r
+            outobj.write(sb.substring(breakpoint));\r
             outobj.close();\r
             fstream.close();\r
-\r
         } catch (IOException e) {\r
             e.printStackTrace();\r
+        }\r
+    }\r
+\r
+    public static void createFullMo(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException {\r
+        // Create full .mo for parameter comparison\r
+        ArrayList<String> parameters = new ArrayList<String>();\r
+        parameters.add(simulationLocation.fullMosFile.getAbsolutePath());\r
+        Process process = runOMC(simulationLocation.simulationDir, monitor, parameters);\r
+        try {\r
+            process.waitFor();\r
         } catch (InterruptedException e) {\r
             e.printStackTrace();\r
         }\r
+        \r
+        trimExtraFromFullModel(simulationLocation);\r
+        \r
     }\r
     /**\r
      * Builds a model with omc. The location of required files is \r
@@ -584,7 +595,7 @@ public class ModelicaManager {
             while ((line = in.readLine()) != null) {\r
                 line = line.trim();\r
                 if(line.startsWith("parameter") && line.contains("=") && line.contains(";")) {\r
-                    String[] split = line.split("=");\r
+                    String[] split = line.split(" = ");\r
                     name = split[0].trim();\r
                     name = name.substring(name.lastIndexOf(" ") + 1);\r
                     value = split[1].trim();\r
@@ -623,15 +634,18 @@ public class ModelicaManager {
             ArrayList<String> parameters = new ArrayList<String>();\r
             parameters.add(simulationLocation.fullMosFile.getAbsolutePath());\r
             \r
-            Process process = runOMC(simulationLocation.simulationDir, monitor, parameters);\r
+            Process process = runOMC(simulationLocation.simulationDir, null, parameters);\r
             process.waitFor();\r
             \r
+            trimExtraFromFullModel(simulationLocation);\r
+            \r
             // Create simulation files from the full description\r
             parameters.clear();\r
             parameters.add("+s");\r
             parameters.add(simulationLocation.fullModel.getAbsolutePath());\r
            \r
-            Process p = runOMC(simulationLocation.fullModelDir, null, parameters);\r
+            Process p = runOMC(simulationLocation.fullModelDir, monitor, parameters);\r
+            \r
             p.waitFor();\r
 \r
             // Find the new init file\r
index bcf7d3a6d8aaf89ab88df929805a1507a5c4e2cd..2335933421e49d07ff5259d3d3ab9a27bd6bedb9 100644 (file)
@@ -145,6 +145,7 @@ public class ModelicaWriter {
      * @param b String builder\r
      */\r
     private static void writeConfiguration(Configuration configuration, HashSet<String> sheetNames, StringBuilder b) {\r
+        boolean defTime = true;\r
         String app;\r
         \r
         // Lists for storing different configuration elements\r
@@ -220,16 +221,17 @@ public class ModelicaWriter {
             if (app != null) b.append(app);\r
         }\r
         \r
-        \r
-        // Time variable for FMU (game) simulations\r
-        if(configuration.isGameConfiguration()) {\r
-               if(configuration.getModel() != null)\r
-                       // Parameter for model root. Values changed in FMU simulator\r
-                       b.append("    parameter Real time = 0;\n");\r
-               else\r
-                       // Continuous variable for module instances\r
-                       b.append("    Real time;\n");\r
+        if(defTime) {\r
+            // Time variable for FMU (game) simulations\r
+            if(configuration.isGameConfiguration()) {\r
+                if(configuration.getModel() != null)\r
+                    // Parameter for model root. Values changed in FMU simulator\r
+                    b.append("    parameter Real time = 0;\n");\r
+                else\r
+                    // Continuous variable for module instances\r
+                    b.append("    Real time;\n");\r
 \r
+            }\r
         }\r
 \r
         if(!modules.isEmpty()) {\r
@@ -304,11 +306,13 @@ public class ModelicaWriter {
             }\r
         }\r
         \r
-        if(configuration.isGameConfiguration() && !modules.isEmpty()) {\r
-            b.append("// Time values for module\n");\r
-               for(Module m : modules) {\r
-                       b.append("    " + m.getName() + ".time = time;\n");\r
-               }\r
+        if(defTime) {\r
+            if(configuration.isGameConfiguration() && !modules.isEmpty()) {\r
+                b.append("// Time values for module\n");\r
+                for(Module m : modules) {\r
+                    b.append("    " + m.getName() + ".time = time;\n");\r
+                }\r
+            }\r
         }\r
 \r
         if(className != null)\r
index 568774bca80c87afb2cb1f0f4c88a3493884fbc9..0427225a7f2f7c216567681f4033886e6a1a2316 100644 (file)
@@ -11,6 +11,9 @@
  *******************************************************************************/\r
 package org.simantics.sysdyn.representation.utils;\r
 \r
+import java.util.ArrayList;\r
+\r
+import org.simantics.sysdyn.representation.Enumeration;\r
 import org.simantics.sysdyn.representation.IndependentVariable;\r
 import org.simantics.sysdyn.representation.Variability;\r
 import org.simantics.sysdyn.representation.Variable;\r
@@ -87,7 +90,7 @@ public class FormatUtils {
                                                refName + " >= 0 then (";\r
                                }\r
                                \r
-                               String conditionEnd = ") else pre(" + variable.getName() +")";\r
+                               String conditionEnd = ") else " + getZeros(variable);\r
                                expression = condition + expression + conditionEnd;\r
                        }\r
 \r
@@ -95,4 +98,22 @@ public class FormatUtils {
                return expression;\r
        }       \r
 \r
+       private static String getZeros(Variable variable) {\r
+           ArrayList<Enumeration> enumerations = variable.getArrayIndexes();\r
+           if(enumerations == null || enumerations.size() == 0)\r
+               return "0";\r
+           else {\r
+               StringBuilder sb = new StringBuilder();\r
+               sb.append("zeros(");\r
+               boolean first = true;\r
+               for(Enumeration e : enumerations) {\r
+                   if(!first)\r
+                       sb.append(", ");\r
+                   first = false;\r
+                   sb.append(e.getName() + ".size");\r
+               }\r
+               sb.append(")");\r
+               return sb.toString();\r
+           }\r
+       }\r
 }\r