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
\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
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
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
* @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
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
}\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
*******************************************************************************/\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
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
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