org.simantics.utils.datastructures;bundle-version="1.1.0"
Export-Package: org.simantics.modelica,
org.simantics.modelica.data,
+ org.simantics.modelica.preferences,
org.simantics.modelica.reader
Bundle-Activator: org.simantics.modelica.Activator
Bundle-ActivationPolicy: lazy
<?xml version="1.0" encoding="UTF-8"?>\r
<?eclipse version="3.4"?>\r
<plugin>\r
+ <extension\r
+ point="org.eclipse.core.runtime.preferences">\r
+ <initializer\r
+ class="org.simantics.modelica.preferences.ModelicaPreferenceInitializer">\r
+ </initializer>\r
+ </extension>\r
\r
\r
</plugin>\r
\r
public class Activator implements BundleActivator {\r
\r
- static BundleContext context;\r
+ public static final String PLUGIN_ID = "org.simantics.modelica";\r
+\r
+ static BundleContext context;\r
\r
@Override\r
public void start(BundleContext context) throws Exception {\r
\r
import org.eclipse.core.runtime.FileLocator;\r
import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
import org.osgi.framework.Bundle;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.modelica.preferences.OpenModelicaPreferences;\r
import org.w3c.dom.Document;\r
import org.w3c.dom.Node;\r
import org.xml.sax.InputSource;\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
* @return\r
*/\r
public static File getModelicaHome() {\r
-\r
- // Get modelica home from environment variable\r
- String dir = System.getenv("OPENMODELICAHOME");\r
- File omhome = null;\r
+ \r
+ // Try preferences\r
+ IScopeContext context = DefaultScope.INSTANCE;\r
+ Preferences node = context.getNode(Activator.PLUGIN_ID);\r
+ String omHomePath = node.get(OpenModelicaPreferences.OM_HOME, null);\r
+ if(omHomePath != null) {\r
+ File omHome = new File(omHomePath);\r
+ if(omHome != null && omHome.isDirectory())\r
+ return omHome;\r
+ }\r
+ \r
+ return getDefaultModelicaHome();\r
+ }\r
+ \r
+ public static File getDefaultModelicaHome() {\r
+ // Try to find installed openModelica\r
+ File omhome = getInstalledOpenModelicaHome();\r
+ if(omhome != null)\r
+ return omhome;\r
\r
// Get operating system\r
- String osName = System.getProperty("os.name");\r
OSType os = calculateOS();\r
-\r
- // operating system unknown\r
- if (os == OSType.UNKNOWN)\r
- throw new UnsatisfiedLinkError("unknown OS '" + osName + "' for running OpenModelica");\r
-\r
- // If OPENMODELICAHOME is found, try to return the folder.\r
- if(dir != null) {\r
- switch (os) {\r
- case APPLE:\r
- case LINUX:\r
- case SUN:\r
- omhome = new File(dir);\r
- if(omhome.isDirectory())\r
- return omhome;\r
- else\r
- break;\r
- case WINDOWS:\r
- omhome = new File(dir);\r
- if(omhome.isDirectory())\r
- return omhome;\r
- else\r
- break;\r
- default:\r
- }\r
- }\r
-\r
+ \r
// OPENMODELICAHOMe was not found or the folder does not exist. Try built-in OpenModelica for windows\r
if(os.equals(OSType.WINDOWS)) {\r
-\r
- Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32");\r
- if (bundle != null) {\r
- try{\r
- URL entry = bundle.getEntry("/");\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, "OpenModelica" + builtInOMVersion);\r
- return f;\r
- }\r
- }\r
- catch (Exception e) {\r
- e.printStackTrace();\r
- }\r
- }\r
+ File builtin = getBuiltinOpenModelicaHome();\r
+ if(builtin != null)\r
+ return builtin;\r
}\r
\r
+\r
// OS was not windows or built-in OpenModelica did not work\r
switch (os) {\r
case APPLE:\r
}\r
}\r
\r
- public static String getInstalledOpenModelicaVersion() {\r
+ public static File getInstalledOpenModelicaHome() {\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
+ return omhome;\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() {\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
+ public static File getBuiltinOpenModelicaHome() {\r
+ Bundle bundle = Platform.getBundle("org.simantics.openmodelica.win32");\r
+ if (bundle != null) {\r
+ try{\r
+ URL entry = bundle.getEntry("/");\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, "OpenModelica" + builtInOMVersion);\r
+ return f;\r
+ }\r
+ }\r
+ catch (Exception e) {\r
+ e.printStackTrace();\r
}\r
}\r
- return omcVersion;\r
+ return null;\r
}\r
\r
\r
- private static String getOMCVersion(File OMHome) throws IOException {\r
+ public static String getOMCVersion(File OMHome) throws IOException {\r
ArrayList<String> parameters = new ArrayList<String>();\r
parameters.add(OMHome + "\\bin\\omc.exe");\r
parameters.add("++v");\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
+ Process process = runOMC(simulationLocation.simulationDir, simulationLocation.omcHome, monitor, parameters);\r
try {\r
process.waitFor();\r
} catch (InterruptedException e) {\r
public static void buildModel(SimulationLocation simulationLocation, IModelicaMonitor monitor) throws ModelicaException {\r
ArrayList<String> parameters = new ArrayList<String>();\r
parameters.add(simulationLocation.mosFile.getAbsolutePath());\r
- runOMC(simulationLocation.simulationDir, monitor, parameters);\r
+ runOMC(simulationLocation.simulationDir, simulationLocation.omcHome, monitor, parameters);\r
createFullMo(simulationLocation, monitor);\r
\r
if(!simulationLocation.executableFile.isFile())\r
* @throws ModelicaException\r
*/\r
public static Process runOMC(File workDir, IModelicaMonitor monitor, List<String> parameters) throws ModelicaException {\r
+ return runOMC(workDir, getModelicaHome(), monitor, parameters);\r
+ }\r
+ /**\r
+ * Generic method for running omc with some parameters\r
+ * \r
+ * @param workDir Working directory. (Usually the directory of scriptfile) \r
+ * @param monitor IModelicaMonitor for printing modelica output\r
+ * @param openModelicaHome OpenModelica home folder\r
+ * @throws ModelicaException\r
+ */\r
+ public static Process runOMC(File workDir, File openModelicaHome, IModelicaMonitor monitor, List<String> parameters) throws ModelicaException {\r
try {\r
// Add OMC as the first parameter\r
- File openModelicaHome = getModelicaHome();\r
parameters.add(0, openModelicaHome + "\\bin\\omc.exe");\r
\r
// Create the build process\r
commands.add(simulationLocation.executableFile.getAbsolutePath());\r
// Write new initial values (parameters). No need to update xml if structure has changed. In that case also xml is up-to-date\r
if(parameterChanges != null) {\r
- String version = getOMCVersion();\r
+ String version = getOMCVersion(simulationLocation.omcHome);\r
if(version.startsWith("1.9")) {\r
// Handled in experiment\r
updateInitFile(simulationLocation, experimentParameters, parameterChanges);\r
ArrayList<String> parameters = new ArrayList<String>();\r
parameters.add(simulationLocation.fullMosFile.getAbsolutePath());\r
\r
- Process process = runOMC(simulationLocation.simulationDir, null, parameters);\r
+ Process process = runOMC(simulationLocation.simulationDir, simulationLocation.omcHome, null, parameters);\r
process.waitFor();\r
\r
trimExtraFromFullModel(simulationLocation);\r
this.initFile = initFile;\r
this.executableFile = exeFile;\r
this.fullModel = new File(getFullModelPath());\r
+ this.omcHome = ModelicaManager.getModelicaHome();\r
}\r
\r
public void setOMCHomeFolder(File omcHome) {\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.modelica.preferences;\r
+\r
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.modelica.Activator;\r
+import org.simantics.modelica.ModelicaManager;\r
+\r
+public class ModelicaPreferenceInitializer extends AbstractPreferenceInitializer { \r
+ \r
+ public ModelicaPreferenceInitializer() { \r
+ \r
+ } \r
+ \r
+ @Override \r
+ public void initializeDefaultPreferences() { \r
+ \r
+ IScopeContext context = DefaultScope.INSTANCE;\r
+ Preferences node = context.getNode(Activator.PLUGIN_ID);\r
+ \r
+ node.putBoolean(OpenModelicaPreferences.OM_AUTO_DETECT, true); \r
+ node.put(OpenModelicaPreferences.OM_HOME, ModelicaManager.getDefaultModelicaHome().getAbsolutePath());\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.modelica.preferences;\r
+\r
+public class OpenModelicaPreferences {\r
+ \r
+ public static String OM_VERSION = "OpenModelica Version";\r
+ public static String OM_AUTO_DETECT = "MODELICA_AUTO_DETECT";\r
+ public static String OM_HOME = "MODELICA_HOME";\r
+\r
+}\r
</page>\r
</extension>\r
-->\r
+ <extension\r
+ point="org.eclipse.core.runtime.preferences">\r
+ <initializer\r
+ class="org.simantics.modelica.preferences.ModelicaPreferenceInitializer">\r
+ </initializer>\r
+ </extension>\r
</plugin>\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.modelica;\r
\r
+import java.io.File;\r
+import java.io.IOException;\r
import java.util.HashSet;\r
import java.util.Set;\r
\r
import org.eclipse.core.runtime.CoreException;\r
import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
import org.eclipse.jface.operation.IRunnableContext;\r
+import org.eclipse.jface.preference.IPreferenceStore;\r
import org.eclipse.jface.text.Document;\r
import org.eclipse.jface.text.IDocument;\r
import org.eclipse.jface.text.PaintManager;\r
import org.eclipse.ui.PartInitException;\r
import org.eclipse.ui.PlatformUI;\r
import org.eclipse.ui.editors.text.TextEditor;\r
+import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
import org.eclipse.ui.texteditor.AbstractDocumentProvider;\r
import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.modelica.ModelicaManager;\r
+import org.simantics.modelica.preferences.OpenModelicaPreferences;\r
import org.simantics.sysdyn.modelica.ModelicaWriter;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
HashSet<Configuration> configurations = new HashSet<Configuration>();\r
configurations.add(configuration);\r
getConfigurations(configuration, configurations);\r
-\r
- return new Document(ModelicaWriter.write(configurations, RepresentationUtils.isGameExperimentActive()));\r
+ \r
+ IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, \r
+ org.simantics.modelica.Activator.PLUGIN_ID); \r
+ String omHome = store.getString(OpenModelicaPreferences.OM_HOME);\r
+ String version = null;\r
+ if(omHome != null) {\r
+ File omHomeDir = new File(omHome);\r
+ if(omHomeDir != null && omHomeDir.isDirectory())\r
+ try {\r
+ version = ModelicaManager.getOMCVersion(omHomeDir);\r
+ } catch (IOException e) { }\r
+ }\r
+ return new Document(ModelicaWriter.write(configurations, RepresentationUtils.isGameExperimentActive(), version));\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
throw new CoreException(STATUS_ERROR);\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
*******************************************************************************/\r
package org.simantics.sysdyn.ui.preferences;\r
\r
+import java.io.File;\r
+import java.io.IOException;\r
+\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
+import org.eclipse.core.runtime.preferences.InstanceScope;\r
+import org.eclipse.jface.preference.DirectoryFieldEditor;\r
import org.eclipse.jface.preference.FieldEditorPreferencePage;\r
+import org.eclipse.jface.preference.IPreferenceStore;\r
import org.eclipse.jface.preference.RadioGroupFieldEditor;\r
import org.eclipse.ui.IWorkbench;\r
import org.eclipse.ui.IWorkbenchPreferencePage;\r
+import org.eclipse.ui.preferences.ScopedPreferenceStore;\r
+import org.osgi.service.prefs.Preferences;\r
+import org.simantics.modelica.Activator;\r
import org.simantics.modelica.ModelicaManager;\r
-import org.simantics.sysdyn.ui.Activator;\r
+import org.simantics.modelica.preferences.OpenModelicaPreferences;\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
+ private static String CUSTOM_PATH = "Custom path";\r
+\r
+ public static String MODELICA_AUTO_DETECT = "MODELICA_AUTO_DETECT";\r
+ public static String MODELICA_HOME = "MODELICA_HOME";\r
+\r
+// private BooleanFieldEditor auto;\r
+ private DirectoryFieldEditor path;\r
+ private RadioGroupFieldEditor rg;\r
+\r
public ModelicaPreferencePage() {\r
super(GRID);\r
\r
+ IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, \r
+ org.simantics.modelica.Activator.PLUGIN_ID); \r
+ setPreferenceStore(store); \r
+\r
+ setDescription("Modelica preferences");\r
}\r
\r
public void createFieldEditors() {\r
- String installed = ModelicaManager.getInstalledOpenModelicaVersion();\r
- String builtIn = ModelicaManager.getBuiltInOpenModelicaVersion();\r
+\r
+// auto = new BooleanFieldEditor(\r
+// OpenModelicaPreferences.OM_AUTO_DETECT,\r
+// "&Autodetect modelica installation folder",\r
+// getFieldEditorParent()) {\r
+// @Override\r
+// public void load() {\r
+// super.load();\r
+// path.setEnabled(!getBooleanValue(), getFieldEditorParent());\r
+// rg.setEnabled(!getBooleanValue(), getFieldEditorParent());\r
+// if (getBooleanValue()) {\r
+// path.setStringValue(ModelicaManager.getDefaultModelicaHome().getAbsolutePath());\r
+// }\r
+// }\r
+//\r
+//\r
+//\r
+// @Override\r
+// public void store() {\r
+// super.store();\r
+// path.setEnabled(!getBooleanValue(), getFieldEditorParent());\r
+// rg.setEnabled(!getBooleanValue(), getFieldEditorParent());\r
+// \r
+// IScopeContext context = DefaultScope.INSTANCE;\r
+// Preferences node = context.getNode(Activator.PLUGIN_ID);\r
+// node.putBoolean(OpenModelicaPreferences.OM_AUTO_DETECT, getBooleanValue());\r
+// \r
+// if (getBooleanValue()) {\r
+// path.setStringValue(ModelicaManager.getDefaultModelicaHome().getAbsolutePath());\r
+// }\r
+// }\r
+//\r
+// @Override\r
+// protected void valueChanged(boolean oldValue,\r
+// boolean newValue) {\r
+// path.setEnabled(!newValue, getFieldEditorParent());\r
+// rg.setEnabled(!getBooleanValue(), getFieldEditorParent());\r
+// if (newValue) {\r
+// String value = ModelicaManager.getDefaultModelicaHome().getAbsolutePath();\r
+// path.setStringValue(value);\r
+// \r
+// IScopeContext context = DefaultScope.INSTANCE;\r
+// Preferences node = context.getNode(Activator.PLUGIN_ID);\r
+// node.put(OpenModelicaPreferences.OM_HOME, value);\r
+// }\r
+// }\r
+// };\r
+// addField(auto);\r
+\r
+\r
+ File installed = ModelicaManager.getInstalledOpenModelicaHome();\r
+ File builtIn = ModelicaManager.getBuiltinOpenModelicaHome();\r
+ String installedVersion = null;\r
+ String builtInVersion = null;\r
+ try {\r
+ if(installed != null)\r
+ installedVersion = ModelicaManager.getOMCVersion(installed);\r
+\r
+ builtInVersion = ModelicaManager.getOMCVersion(builtIn);\r
+ } catch (IOException e) {\r
+ }\r
+\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
+ {{CUSTOM_PATH, CUSTOM_PATH},\r
+ {"Local installation (" + installedVersion + ")", installed.getAbsolutePath() },\r
+ {"Built-in (" + builtInVersion + ")", builtIn.getAbsolutePath()},\r
+ };\r
} else {\r
options = new String[][] \r
- {{"OpenModelica " + builtIn + " (built-in)", OM_BUILTIN}}; \r
+ {{CUSTOM_PATH, CUSTOM_PATH},\r
+ {"Built-in (" + builtInVersion + ")", builtIn.getAbsolutePath()},\r
+ }; \r
}\r
- \r
- RadioGroupFieldEditor rg = new RadioGroupFieldEditor(OM_VERSION,\r
- "Choose the used OpenModelica version", 1,\r
- options, getFieldEditorParent());\r
- \r
+\r
+ rg = new RadioGroupFieldEditor(OpenModelicaPreferences.OM_HOME,\r
+ "&Choose the used OpenModelica version", 1,\r
+ options, getFieldEditorParent()) {\r
+\r
+ @Override\r
+ protected void doStore() {\r
+ // Do nothing. Path handles saving the value\r
+ }\r
+\r
+ @Override\r
+ protected void fireValueChanged(String property, Object oldValue, Object newValue) {\r
+ if(newValue.equals(CUSTOM_PATH)) {\r
+\r
+ } else {\r
+ path.setStringValue((String)newValue);\r
+ } \r
+ }\r
+ };\r
+\r
+\r
+// boolean isAuto = getPreferenceStore().getBoolean(OpenModelicaPreferences.OM_AUTO_DETECT);\r
+// rg.setEnabled(!isAuto, getFieldEditorParent());\r
+\r
addField(rg);\r
+\r
+ path = new DirectoryFieldEditor(OpenModelicaPreferences.OM_HOME, \r
+ "&Modelica Home:", getFieldEditorParent()) {\r
+ @Override\r
+ public void load() {\r
+ super.load();\r
+// if (auto.getBooleanValue()) {\r
+ setStringValue(ModelicaManager.getDefaultModelicaHome().getAbsolutePath());\r
+// }\r
+ }\r
+\r
+ @Override\r
+ public void store() {\r
+ super.store();\r
+ IScopeContext context = DefaultScope.INSTANCE;\r
+ Preferences node = context.getNode(Activator.PLUGIN_ID);\r
+ node.put(OpenModelicaPreferences.OM_HOME, getStringValue());\r
+ }\r
+ };\r
+ addField(path);\r
}\r
\r
@Override\r
public void init(IWorkbench workbench) {\r
- setPreferenceStore(Activator.getDefault().getPreferenceStore());\r
-// setDescription("");\r
+ }\r
+\r
+ @Override\r
+ protected void performDefaults() {\r
+ super.performDefaults();\r
+// rg.setEnabled(!auto.getBooleanValue(), getFieldEditorParent());\r
}\r
\r
}\r
import java.util.concurrent.locks.Lock;\r
\r
import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.preferences.DefaultScope;\r
+import org.eclipse.core.runtime.preferences.IScopeContext;\r
+import org.osgi.service.prefs.Preferences;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
import org.simantics.db.Session;\r
import org.simantics.modelica.data.CSVSimulationResult;\r
import org.simantics.modelica.data.MatSimulationResult;\r
import org.simantics.modelica.data.SimulationResult;\r
+import org.simantics.modelica.preferences.OpenModelicaPreferences;\r
import org.simantics.simulation.data.Datasource;\r
import org.simantics.simulation.experiment.Experiment;\r
import org.simantics.simulation.experiment.ExperimentState;\r
* @param isGame is the experiment a "game experiment". This is needed for modifying the code to work with FMU simulation\r
* @return Modelica code\r
*/\r
- protected String getModelicaCode(IModelicaMonitor monitor, boolean isGame) {\r
+ protected String getModelicaCode(IModelicaMonitor monitor, boolean isGame, String modelicaVersion) {\r
String modelText = null;\r
try {\r
// Write all configurations once\r
- modelText = ModelicaWriter.write(sysdynModel.getModules(), isGame);\r
+ modelText = ModelicaWriter.write(sysdynModel.getModules(), isGame, modelicaVersion);\r
} catch (Exception e) {\r
// Stop experiment and show console\r
/*setExperimentStopped(experiment); =>*/ simulate(false);\r
progressMonitor.subTask("Write modelica classes");\r
\r
// Write Modelica files\r
- String modelText = getModelicaCode(monitor, false);\r
+\r
+ \r
+ String modelText = getModelicaCode(monitor, false, getOpenModelicaVersion());\r
if(modelText == null)\r
return;\r
\r
// Add changed parameters in case that structure has not changed\r
HashMap<String, String> changes = structureChanged ? null : new HashMap<String, String>();\r
if (omcVersion == null) {\r
- omcVersion = ModelicaManager.getOMCVersion();\r
+ omcVersion = ModelicaManager.getOMCVersion(simulationLocation.omcHome);\r
}\r
if(!structureChanged && previousParameters != null && omcVersion.startsWith("1.9")) {\r
try {\r
process = null;\r
}\r
\r
+ /**\r
+ * Get the version of the OpenModelica compiler that is defined to be used\r
+ * in Preferences\r
+ * @return OpenModelica version\r
+ */\r
+ protected String getOpenModelicaVersion() {\r
+ String omVersion = null;\r
+\r
+ try {\r
+ IScopeContext context = DefaultScope.INSTANCE;\r
+ Preferences node = context.getNode(org.simantics.modelica.Activator.PLUGIN_ID);\r
+ String omHome = node.get(OpenModelicaPreferences.OM_HOME, null);\r
+ if(omHome != null) {\r
+ File omHomeDir = new File(omHome);\r
+ if(omHomeDir != null && omHomeDir.isDirectory())\r
+ omVersion = ModelicaManager.getOMCVersion(omHomeDir);\r
+ }\r
+\r
+ if(omVersion == null) {\r
+ omVersion = ModelicaManager.getOMCVersion(ModelicaManager.getModelicaHome());\r
+ }\r
+ \r
+ } catch (IOException e) {\r
+ }\r
+ \r
+ return omVersion;\r
+ }\r
\r
\r
/**\r
\r
progressMonitor.subTask("Write modelica classes");\r
\r
- // Write Modelica files\r
- String modelText = getModelicaCode(monitor, true);\r
+ // Write Modelica files \r
+ String modelText = getModelicaCode(monitor, true, getOpenModelicaVersion());\r
if(modelText == null)\r
return;\r
\r
import java.util.HashSet;\r
import java.util.List;\r
\r
-import org.simantics.modelica.ModelicaManager;\r
import org.simantics.sysdyn.representation.Book;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.Dependency;\r
* @param Configurations Configurations, one main configuration and possible modules\r
* @return Complete Modelica code of a model\r
*/\r
- public static String write(Collection<Configuration> configurations, boolean isGame) {\r
+ public static String write(Collection<Configuration> configurations, boolean isGame, String omVersion) {\r
Configuration modelConf = null;\r
for(Configuration conf : configurations) {\r
if(conf.getModel() != null) {\r
b.append("end " + modelName + ";\n\n");\r
\r
// Insert spreadsheets\r
- String version = null;\r
- version = ModelicaManager.getOMCVersion();\r
- if(version != null && version.startsWith("1.9")) {\r
+ if(omVersion != null && omVersion.startsWith("1.9")) {\r
b.insert(spreadsheetlocation, getGlobalSpreadSheets(configurations));\r
} else {\r
b.append(getGlobalSpreadSheets(configurations));\r