From: lempinen Date: Mon, 11 Feb 2013 08:25:48 +0000 (+0000) Subject: Preference pages for selecting OM version. This is difficult to use since preference... X-Git-Tag: simantics-1.10.1~41 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ff28d5b0c6df6501b8deedb9f9152352bd06926e;p=simantics%2Fsysdyn.git Preference pages for selecting OM version. This is difficult to use since preference pages are UI components and Modelica should be headless. There needs to be changes in the Modelica interface. (refs #4061) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@26747 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java index 002c340a..0b8a4137 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java +++ b/org.simantics.modelica/src/org/simantics/modelica/ModelicaManager.java @@ -58,6 +58,9 @@ import org.xml.sax.SAXException; * */ public class ModelicaManager { + + private static String builtInOMVersionName = "1.9.0 beta 4 (r15030)"; + private static String builtInOMVersion = "1.9.0"; public enum OSType { APPLE, LINUX, SUN, WINDOWS, UNKNOWN @@ -133,7 +136,7 @@ public class ModelicaManager { if(entry != null) { URL fileURL = FileLocator.toFileURL(entry); File root = new File( URLDecoder.decode(fileURL.getPath(), "UTF-8") ); - File f = new File(root, "OpenModelica1.8.1"); + File f = new File(root, "OpenModelica" + builtInOMVersion); return f; } } @@ -150,31 +153,61 @@ public class ModelicaManager { case SUN: return new File("/usr/bin/omc"); case WINDOWS: - return new File("c:/OpenModelica1.8.0"); + return new File("c:/OpenModelica" + builtInOMVersion); default: throw new UnsatisfiedLinkError("Unsupported operating system: " + os); } } - + + public static String getInstalledOpenModelicaVersion() { + String dir = System.getenv("OPENMODELICAHOME"); + if(dir != null) { + File omhome = new File(dir); + if(omhome.isDirectory()) + try { + return getOMCVersion(omhome); + } catch (IOException e) {} + } + return null; + } + + public static String getBuiltInOpenModelicaVersion() { + return builtInOMVersionName; + } + private static String omcVersion = getOMCVersion(); /** * Get version of the OpenModelica that is used by this software * @return * @throws IOException */ - public static String getOMCVersion() throws IOException { - // Add OMC as the first parameter - File openModelicaHome = getModelicaHome(); + public static String getOMCVersion() { + if(omcVersion == null) { + // Add OMC as the first parameter + File openModelicaHome = getModelicaHome(); + try { + omcVersion = getOMCVersion(openModelicaHome); + } catch (IOException e) { + omcVersion = null; + } + } + return omcVersion; + } + + private static String getOMCVersion(File OMHome) throws IOException { ArrayList parameters = new ArrayList(); - parameters.add(openModelicaHome + "\\bin\\omc.exe"); + parameters.add(OMHome + "\\bin\\omc.exe"); parameters.add("++v"); // Create the build process ProcessBuilder processBuilder = new ProcessBuilder(parameters) .redirectErrorStream(true); + Map env = processBuilder.environment(); + env.put("OPENMODELICAHOME", OMHome.getAbsolutePath()); + // Start the building process Process process = processBuilder.start(); @@ -184,7 +217,6 @@ public class ModelicaManager { return output; } - /** * Gets the whole process output in one string * @param process Process @@ -576,13 +608,17 @@ public class ModelicaManager { try { ArrayList commands = new ArrayList(); - commands.add(getModelicaHome() + "\\bin\\omc.exe"); + File omHome = getModelicaHome(); + commands.add(omHome + "\\bin\\omc.exe"); commands.add(simulationLocation.fullModel.getAbsolutePath()); // Create the build process ProcessBuilder processBuilder = new ProcessBuilder(commands) .redirectErrorStream(true); + Map env = processBuilder.environment(); + env.put("OPENMODELICAHOME", omHome.getAbsolutePath()); + // Start the building process Process process = processBuilder.start(); diff --git a/org.simantics.sysdyn.ui/plugin.xml b/org.simantics.sysdyn.ui/plugin.xml index e34af3c4..b29bc891 100644 --- a/org.simantics.sysdyn.ui/plugin.xml +++ b/org.simantics.sysdyn.ui/plugin.xml @@ -170,14 +170,12 @@ relationship="right" relative="org.eclipse.ui.editorss"> - + diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java new file mode 100644 index 00000000..2014e3a2 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferenceInitializer.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; +import org.eclipse.jface.preference.IPreferenceStore; +import org.simantics.sysdyn.ui.Activator; + +public class ModelicaPreferenceInitializer extends AbstractPreferenceInitializer { + + public ModelicaPreferenceInitializer() { + } + + @Override + public void initializeDefaultPreferences() { + IPreferenceStore store = Activator.getDefault().getPreferenceStore(); + store.setDefault(ModelicaPreferencePage.OM_VERSION, ModelicaPreferencePage.OM_BUILTIN); + } + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java new file mode 100644 index 00000000..63dbde4e --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/preferences/ModelicaPreferencePage.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.sysdyn.ui.preferences; + +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.RadioGroupFieldEditor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.simantics.modelica.ModelicaManager; +import org.simantics.sysdyn.ui.Activator; + +public class ModelicaPreferencePage extends FieldEditorPreferencePage implements +IWorkbenchPreferencePage { + + public static String OM_VERSION = "OpenModelica Version"; + public static String OM_BUILTIN = "Built-in"; + public static String OM_INSTALLED = "Installed"; + + public ModelicaPreferencePage() { + super(GRID); + + } + + public void createFieldEditors() { + String installed = ModelicaManager.getInstalledOpenModelicaVersion(); + String builtIn = ModelicaManager.getBuiltInOpenModelicaVersion(); + + String[][] options; + if(installed != null) { + options = new String[][] + {{"OpenModelica " + installed + " (local installation)", OM_INSTALLED }, + {"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}}; + } else { + options = new String[][] + {{"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}}; + } + + RadioGroupFieldEditor rg = new RadioGroupFieldEditor(OM_VERSION, + "Choose the used OpenModelica version", 1, + options, getFieldEditorParent()); + + addField(rg); + } + + @Override + public void init(IWorkbench workbench) { + setPreferenceStore(Activator.getDefault().getPreferenceStore()); +// setDescription(""); + } + +}