*\r
*/\r
public class ModelicaManager {\r
+ \r
+ private static String builtInOMVersionName = "1.9.0 beta 4 (r15030)";\r
+ private static String builtInOMVersion = "1.9.0";\r
\r
public enum OSType {\r
APPLE, LINUX, SUN, WINDOWS, UNKNOWN\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(root, "OpenModelica1.8.1");\r
+ File f = new File(root, "OpenModelica" + builtInOMVersion);\r
return f;\r
}\r
}\r
case SUN:\r
return new File("/usr/bin/omc");\r
case WINDOWS:\r
- return new File("c:/OpenModelica1.8.0");\r
+ return new File("c:/OpenModelica" + builtInOMVersion);\r
default:\r
throw new UnsatisfiedLinkError("Unsupported operating system: " + os);\r
}\r
}\r
-\r
+ \r
+ public static String getInstalledOpenModelicaVersion() {\r
+ String dir = System.getenv("OPENMODELICAHOME");\r
+ if(dir != null) {\r
+ File omhome = new File(dir);\r
+ if(omhome.isDirectory())\r
+ try {\r
+ return getOMCVersion(omhome);\r
+ } catch (IOException e) {}\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ public static String getBuiltInOpenModelicaVersion() {\r
+ return builtInOMVersionName;\r
+ }\r
\r
\r
+ private static String omcVersion = getOMCVersion();\r
/**\r
* Get version of the OpenModelica that is used by this software\r
* @return\r
* @throws IOException\r
*/\r
- public static String getOMCVersion() throws IOException {\r
- // Add OMC as the first parameter\r
- File openModelicaHome = getModelicaHome();\r
+ public static String getOMCVersion() {\r
+ if(omcVersion == null) {\r
+ // Add OMC as the first parameter\r
+ File openModelicaHome = getModelicaHome();\r
+ try {\r
+ omcVersion = getOMCVersion(openModelicaHome);\r
+ } catch (IOException e) {\r
+ omcVersion = null;\r
+ }\r
+ }\r
+ return omcVersion;\r
+ }\r
\r
+ \r
+ private static String getOMCVersion(File OMHome) throws IOException {\r
ArrayList<String> parameters = new ArrayList<String>();\r
- parameters.add(openModelicaHome + "\\bin\\omc.exe");\r
+ parameters.add(OMHome + "\\bin\\omc.exe");\r
parameters.add("++v");\r
\r
// Create the build process\r
ProcessBuilder processBuilder = new ProcessBuilder(parameters)\r
.redirectErrorStream(true);\r
\r
+ Map<String, String> env = processBuilder.environment();\r
+ env.put("OPENMODELICAHOME", OMHome.getAbsolutePath());\r
+ \r
// Start the building process\r
Process process = processBuilder.start();\r
\r
return output;\r
}\r
\r
-\r
/**\r
* Gets the whole process output in one string\r
* @param process Process\r
\r
try {\r
ArrayList<String> commands = new ArrayList<String>();\r
- commands.add(getModelicaHome() + "\\bin\\omc.exe");\r
+ File omHome = getModelicaHome();\r
+ commands.add(omHome + "\\bin\\omc.exe");\r
commands.add(simulationLocation.fullModel.getAbsolutePath());\r
\r
// Create the build process\r
ProcessBuilder processBuilder = new ProcessBuilder(commands)\r
.redirectErrorStream(true);\r
\r
+ Map<String, String> env = processBuilder.environment();\r
+ env.put("OPENMODELICAHOME", omHome.getAbsolutePath());\r
+ \r
// Start the building process\r
Process process = processBuilder.start();\r
\r
relationship="right"\r
relative="org.eclipse.ui.editorss">\r
</view>\r
- <!--\r
<view\r
id="org.simantics.document.workbench.documentViewer"\r
minimized="true"\r
relationship="stack"\r
- relative="org.simantics.sysdyn.ui.chartPanel">\r
+ relative="org.simantics.jfreechart.chartPanel">\r
</view>\r
- -->\r
</perspectiveExtension>\r
</extension>\r
<extension\r
</visibleWhen>\r
</command>\r
<menu\r
- id="org.simantics.sysdyn.import"\r
+ id="org.simantics.import"\r
label="Import">\r
<command\r
commandId="org.simantics.sysdyn.ui.importModel"\r
</command>\r
</menu>\r
<menu\r
- id="org.simantics.sysdyn.export"\r
+ id="org.simantics.export"\r
label="Export">\r
<command\r
commandId="org.simantics.sysdyn.ui.exportModel"\r
</namespace> \r
</namespace>\r
</extension>\r
+ <!--\r
+ <extension\r
+ point="org.eclipse.ui.preferencePages">\r
+ <page\r
+ class="org.simantics.sysdyn.ui.preferences.ModelicaPreferencePage"\r
+ id="org.simantics.modelica.preferences"\r
+ name="Modelica">\r
+ </page>\r
+ </extension>\r
+ -->\r
</plugin>\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;\r
+import org.eclipse.jface.preference.IPreferenceStore;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+public class ModelicaPreferenceInitializer extends AbstractPreferenceInitializer {\r
+\r
+ public ModelicaPreferenceInitializer() {\r
+ }\r
+\r
+ @Override\r
+ public void initializeDefaultPreferences() {\r
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();\r
+ store.setDefault(ModelicaPreferencePage.OM_VERSION, ModelicaPreferencePage.OM_BUILTIN);\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.ui.preferences;\r
+\r
+import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
+import org.eclipse.jface.preference.RadioGroupFieldEditor;\r
+import org.eclipse.ui.IWorkbench;\r
+import org.eclipse.ui.IWorkbenchPreferencePage;\r
+import org.simantics.modelica.ModelicaManager;\r
+import org.simantics.sysdyn.ui.Activator;\r
+\r
+public class ModelicaPreferencePage extends FieldEditorPreferencePage implements\r
+IWorkbenchPreferencePage {\r
+\r
+ public static String OM_VERSION = "OpenModelica Version";\r
+ public static String OM_BUILTIN = "Built-in";\r
+ public static String OM_INSTALLED = "Installed";\r
+ \r
+ public ModelicaPreferencePage() {\r
+ super(GRID);\r
+\r
+ }\r
+\r
+ public void createFieldEditors() {\r
+ String installed = ModelicaManager.getInstalledOpenModelicaVersion();\r
+ String builtIn = ModelicaManager.getBuiltInOpenModelicaVersion();\r
+\r
+ String[][] options;\r
+ if(installed != null) {\r
+ options = new String[][] \r
+ {{"OpenModelica " + installed + " (local installation)", OM_INSTALLED },\r
+ {"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}};\r
+ } else {\r
+ options = new String[][] \r
+ {{"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}}; \r
+ }\r
+ \r
+ RadioGroupFieldEditor rg = new RadioGroupFieldEditor(OM_VERSION,\r
+ "Choose the used OpenModelica version", 1,\r
+ options, getFieldEditorParent());\r
+ \r
+ addField(rg);\r
+ }\r
+\r
+ @Override\r
+ public void init(IWorkbench workbench) {\r
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());\r
+// setDescription("");\r
+ }\r
+\r
+}\r