*******************************************************************************/\r
package org.simantics.modelica;\r
\r
+import java.io.BufferedWriter;\r
import java.io.File;\r
import java.io.FileInputStream;\r
import java.io.FileNotFoundException;\r
+import java.io.FileWriter;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.io.PrintStream;\r
return OSType.SUN;\r
return OSType.UNKNOWN;\r
}\r
-\r
- public static File getModelicaExecutable() {\r
-\r
+ \r
+ public static File getModelicaHome() {\r
\r
String dir = System.getenv("OPENMODELICAHOME");\r
\r
if(entry != null) {\r
URL fileURL = FileLocator.toFileURL(entry);\r
File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") );\r
- File f = new File(new File(root, "OpenModelica1.5.0"), "om.bat");\r
+ File f = new File(root, "OpenModelica1.7.0");\r
return f;\r
}\r
}\r
case SUN:\r
return new File("/usr/bin/omc");\r
case WINDOWS:\r
- return new File("c:/OpenModelica1.5.0/bin/omc.exe");\r
+ return new File("c:/OpenModelica1.7.0");\r
default:\r
throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
}\r
case APPLE:\r
case LINUX:\r
case SUN:\r
- return new File(dir+"/bin/omc");\r
+ return new File(dir);\r
case WINDOWS:\r
- return new File(dir+"/bin/omc.exe");\r
+ return new File(dir);\r
default:\r
throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
}\r
}\r
}\r
\r
+ public static File getModelicaExecutable(File simulationDir) {\r
+\r
+ File modelicaHome = getModelicaHome();\r
+ \r
+ if(!modelicaHome.isDirectory())\r
+ throw new UnsatisfiedLinkError("OpenModelica probably not installed. Tried to find it from: " + modelicaHome.getAbsolutePath());\r
+ \r
+ try {\r
+ File omBat = new File(simulationDir, "om.bat");\r
+ FileWriter fw = new FileWriter(omBat);\r
+ BufferedWriter out = new BufferedWriter(fw);\r
+ out.write("@echo off");\r
+ out.newLine();\r
+ out.write("set OPENMODELICAHOME=" + modelicaHome.getAbsolutePath());\r
+ out.newLine();\r
+ out.write("set OPENMODELICALIBRARY=%OPENMODELICAHOME%\\lib\\omlibrary\\msl31");\r
+ out.newLine();\r
+ out.write("%OPENMODELICAHOME%\\bin\\omc.exe %*");\r
+ out.newLine();\r
+ out.close();\r
+ fw.close();\r
+ \r
+ return omBat;\r
+ } catch (IOException e) {\r
+ e.printStackTrace();\r
+ throw new UnsatisfiedLinkError("OpenModelica probably not installed. Tried to find it from: " + modelicaHome.getAbsolutePath());\r
+ }\r
+ }\r
+ \r
+ public static File getSimulationExecutableBat(File exeFile) {\r
+ \r
+ File modelicaHome = getModelicaHome();\r
+ \r
+ File folder = new File(exeFile.getParent());\r
+\r
+ try {\r
+ File exeBat = new File(folder, exeFile.getName() + ".bat");\r
+ FileWriter fw = new FileWriter(exeBat);\r
+ BufferedWriter out = new BufferedWriter(fw);\r
+ \r
+ out.write("@echo off");\r
+ out.newLine();\r
+ out.write("set OPENMODELICAHOME=" + modelicaHome.getAbsolutePath());\r
+ out.newLine();\r
+ out.write("set OPENMODELICALIBRARY=%OPENMODELICAHOME%\\lib\\omlibrary\\msl31");\r
+ out.newLine();\r
+ out.write("set OMPATH=%OPENMODELICAHOME%\\bin");\r
+ out.newLine();\r
+ out.write("echo %PATH%|findstr /i %OMPATH% >nul:");\r
+ out.newLine();\r
+ out.write("if %errorlevel%==1 set PATH=%PATH%;%OMPATH%");\r
+ out.newLine();\r
+ out.write(exeFile.getAbsolutePath() + " %*");\r
+ out.newLine();\r
+ \r
+ out.close();\r
+ fw.close();\r
+ return exeBat;\r
+ }\r
+ catch (IOException e) {\r
+ e.printStackTrace();\r
+ throw new UnsatisfiedLinkError("Creating bat for the exe failed");\r
+ }\r
+ }\r
+\r
protected static File createTempDirectory() throws IOException {\r
final File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));\r
if(!(temp.delete()))\r
\r
public static void buildModel(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException {\r
try {\r
- File omc = getModelicaExecutable();\r
+ File omc = getModelicaExecutable(simulationLocation.simulationDir);\r
\r
if(omc == null) {\r
monitor.message("OpenModelica not found! Install it from www.openmodelica.org");\r
\r
Process process = new ProcessBuilder(\r
omc.getAbsolutePath(),\r
- "+showErrorMessages",\r
- "+d=usedep",\r
simulationLocation.inputFile.getAbsolutePath()\r
)\r
.directory(simulationLocation.simulationDir.getAbsoluteFile())\r
writeInits(simulationLocation, inits);\r
\r
Process process = new ProcessBuilder(\r
- simulationLocation.exeFile.getAbsolutePath()\r
+ getSimulationExecutableBat(simulationLocation.exeFile).getAbsolutePath()\r
)\r
.directory(simulationLocation.simulationDir.getAbsoluteFile())\r
.redirectErrorStream(true)\r