Skip to content

Commit

Permalink
Improve handling of MSL (#8720)
Browse files Browse the repository at this point in the history
Change the order of priority of MODELICAPATH, so it looks in the APPDATA directory first, and then in the omlibrary as a fallback option.
Remove initial splash screen with obsolete library explanation.
Do not load any library by default.
Do not load OpenModelica. We have a nice online documentation for the scripting API.
Improved the libraries settings dialog to add system libraries to load startup.
Allow changing the ModelicaPath
  • Loading branch information
adeas31 committed Mar 17, 2022
1 parent 9515961 commit 1d96e42
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 263 deletions.
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/runtime/settingsimpl.c
Expand Up @@ -213,7 +213,7 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
const char *path = runningTestsuite ? NULL : getenv("OPENMODELICALIBRARY");
if (path != NULL)
{
omc_modelicaPath = strdup(path);
omc_modelicaPath = strdup(path);
}
else
{
Expand All @@ -234,7 +234,7 @@ char* SettingsImpl__getModelicaPath(int runningTestsuite) {
} else {
int lenHome = strlen(homePath);
omc_modelicaPath = (char*)omc_alloc_interface.malloc_atomic(lenOmhome+lenHome+41);
snprintf(omc_modelicaPath, lenOmhome+lenHome+41,"%s/lib/omlibrary%s%s/.openmodelica/libraries/", omhome, OMC_GROUP_DELIMITER, homePath);
snprintf(omc_modelicaPath, lenHome+lenOmhome+41,"%s/.openmodelica/libraries/%s%s/lib/omlibrary", homePath, OMC_GROUP_DELIMITER, omhome);
}
}

Expand Down
138 changes: 3 additions & 135 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -358,13 +358,6 @@ void MainWindow::setUpMainWindow(threadData_t *threadData)
mpCentralStackedWidget->addWidget(mpPlotWindowContainer);
//Set the centralwidget
setCentralWidget(mpCentralStackedWidget);
//! @todo Remove the following MSL verison block once we have fixed the MSL handling.
// set MSL version
QSettings *pSettings = Utilities::getApplicationSettings();
if (!isTestsuiteRunning() && (!pSettings->contains("MSLVersion") || !pSettings->value("MSLVersion").toBool())) {
MSLVersionDialog *pMSLVersionDialog = new MSLVersionDialog;
pMSLVersionDialog->exec();
}
// Load and add user defined Modelica libraries into the Library Widget.
mpLibraryWidget->getLibraryTreeModel()->addModelicaLibraries();
// set command line options
Expand All @@ -374,6 +367,7 @@ void MainWindow::setUpMainWindow(threadData_t *threadData)
OptionsDialog::instance()->saveSimulationSettings();
OptionsDialog::instance()->saveNFAPISettings();
// restore OMEdit widgets state
QSettings *pSettings = Utilities::getApplicationSettings();
if (OptionsDialog::instance()->getGeneralSettingsPage()->getPreserveUserCustomizations()) {
restoreGeometry(pSettings->value("application/geometry").toByteArray());
bool restoreMessagesWidget = !MessagesWidget::instance()->getAllMessageWidget()->getMessagesTextBrowser()->toPlainText().isEmpty();
Expand Down Expand Up @@ -2512,10 +2506,10 @@ void MainWindow::exportModelToOMNotebook()
* \brief MainWindow::openInstallLibraryDialog
* Opens the install library dialog.
*/
void MainWindow::openInstallLibraryDialog()
bool MainWindow::openInstallLibraryDialog()
{
InstallLibraryDialog *pInstallLibraryDialog = new InstallLibraryDialog;
pInstallLibraryDialog->exec();
return pInstallLibraryDialog->exec();
}

/*!
Expand Down Expand Up @@ -4740,129 +4734,3 @@ void AboutOMEditDialog::showReportIssue()
CrashReportDialog *pCrashReportDialog = new CrashReportDialog("", true);
pCrashReportDialog->exec();
}

/*!
* \brief MSLVersionDialog::MSLVersionDialog
* \param parent
*/
MSLVersionDialog::MSLVersionDialog(QWidget *parent)
: QDialog(parent)
{
QString title = tr("Setup of Modelica Standard Library version");
setAttribute(Qt::WA_DeleteOnClose);
setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, title));
// heading
Label *pHeadingLabel = Utilities::getHeadingLabel(title);
// horizontal line
QFrame *pHorizontalLine = Utilities::getHeadingLine();
// Information
const QString info = QString("OpenModelica 1.17.x supports both Modelica Standard Library (MSL) v3.2.3 and v4.0.0. Please note that synchronous components in Modelica.Clocked are still not fully reliable, while most other models work fine in both versions.<br /><br />"
"MSL v3.2.3 and v4.0.0 are mutually incompatible, because of changes of class names and paths; for example, Modelica.SIunits became Modelica.Units.SI in v4.0.0 (​<a href=\"https://github.com/modelica/ModelicaStandardLibrary/releases/tag/v4.0.0\">further information</a>). Please note that conversion scripts are not yet available in OpenModelica 1.17.x, so you need to use other Modelica tools to upgrade existing libraries to use MSL v4.0.0. Conversion script support is planned in OpenModelica 1.18.0.<br /><br />"
"On Windows, both versions of the MSL are installed automatically by the installer. On Linux, you need to install them manually, by following the instructions on the <a href=\"https://openmodelica.org/download/download-linux\">OpenModelica download page</a>. We suggest you do it immediately, otherwise OMEdit won't work correctly.<br /><br />"
"You have three startup options:"
"<ol>"
"<li>Automatically load MSL v3.2.3. You can then load other models or packages that use MSL v3.2.3, or start new ones that will use it. If you then open a model or package that uses MSL v4.0.0, errors will occur. This option is recommended if you are not interested in MSL v4.0.0 and you would like to get the same behaviour as in OpenModelica 1.16.x.</li>"
"<li>Automatically load MSL v4.0.0. You can then load other models or packages that use MSL v4.0.0, or start new ones that will use it. If you then open a model or package that uses MSL v3.2.3, errors will occur. This option is recommended if you exclusively use new libraries depending on MSL v4.0.0.</li>"
"<li>Do not load MSL. When you open a model or library, the appropriate version of MSL will be loaded automatically, based on the uses() annotation of library being opened. This option is recommended if you work with different projects, some using MSL v3.2.3 and some others using MSL v4.0.0. It is also recommended if you are a developer of the Modelica Standard Library, so you want to load your own modified version instead of the pre-installed version customized for OpenModelica.</li>"
"</ol>"
"Please choose one startup option:");
Label *pInfoLabel = new Label(info);
pInfoLabel->setWordWrap(true);
pInfoLabel->setTextFormat(Qt::RichText);
pInfoLabel->setTextInteractionFlags(pInfoLabel->textInteractionFlags() | Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
pInfoLabel->setOpenExternalLinks(true);
pInfoLabel->setToolTip("");
// options
mpMSL3RadioButton = new QRadioButton("Load MSL v3.2.3");
mpMSL4RadioButton = new QRadioButton("Load MSL v4.0.0");
mpNoMSLRadioButton = new QRadioButton("Do not load MSL");
QButtonGroup *pButtonGroup = new QButtonGroup;
pButtonGroup->addButton(mpMSL3RadioButton);
pButtonGroup->addButton(mpMSL4RadioButton);
pButtonGroup->addButton(mpNoMSLRadioButton);
// radio buttons layout
QVBoxLayout *pRadioButtonsLayout = new QVBoxLayout;
pRadioButtonsLayout->setAlignment(Qt::AlignTop);
pRadioButtonsLayout->setSpacing(0);
pRadioButtonsLayout->addWidget(mpMSL3RadioButton);
pRadioButtonsLayout->addWidget(mpMSL4RadioButton);
pRadioButtonsLayout->addWidget(mpNoMSLRadioButton);
// more info
Label *pPostInfoLabel = new Label(QString("You can later change this setting by going to Tools | Options | Libraries, where you can add or remove the Modelica library from the list of automatically loaded system libraries, as well as specify which version of the library you want to load. Version tag \"default\" will load the latest installed version (i.e. v4.0.0 for MSL)"));
pPostInfoLabel->setWordWrap(true);
pPostInfoLabel->setToolTip("");
// Create the buttons
QPushButton *pOkButton = new QPushButton(Helper::ok);
connect(pOkButton, SIGNAL(clicked()), SLOT(setMSLVersion()));
// layout
QGridLayout *pMainGridLayout = new QGridLayout;
pMainGridLayout->setAlignment(Qt::AlignTop);
pMainGridLayout->addWidget(pHeadingLabel, 0, 0);
pMainGridLayout->addWidget(pHorizontalLine, 1, 0);
pMainGridLayout->addWidget(pInfoLabel, 2, 0);
pMainGridLayout->addLayout(pRadioButtonsLayout, 3, 0);
pMainGridLayout->addWidget(pPostInfoLabel, 4, 0);
pMainGridLayout->addWidget(pOkButton, 5, 0, Qt::AlignRight);
mpWidget = new QWidget;
mpWidget->setLayout(pMainGridLayout);
QScrollArea *pScrollArea = new QScrollArea;
pScrollArea->setWidgetResizable(true);
pScrollArea->setWidget(mpWidget);
QVBoxLayout *pMainLayout = new QVBoxLayout;
pMainLayout->addWidget(pScrollArea);
setLayout(pMainLayout);
}

/*!
* \brief MSLVersionDialog::setMSLVersion
*/
void MSLVersionDialog::setMSLVersion()
{
// if no option is selected
if (!mpMSL3RadioButton->isChecked() && !mpMSL4RadioButton->isChecked() && !mpNoMSLRadioButton->isChecked()) {
QMessageBox::information(this, QString("%1 - %2").arg(Helper::applicationName, Helper::information), "Please select an option.", Helper::ok);
return;
}
QSettings *pSettings = Utilities::getApplicationSettings();
// First clear any Modelica and ModelicaReference setting
pSettings->beginGroup("libraries");
QStringList libraries = pSettings->childKeys();
foreach (QString lib, libraries) {
if (lib.compare("Modelica") == 0 || lib.compare("ModelicaReference") == 0) {
pSettings->remove(lib);
}
}
pSettings->endGroup();
// set the Modelica version based on user setting.
if (mpMSL3RadioButton->isChecked()) {
pSettings->setValue("libraries/Modelica", "3.2.3");
} else if (mpMSL4RadioButton->isChecked()) {
pSettings->setValue("libraries/Modelica", "4.0.0");
} else { // mpNoMSLRadioButton->isChecked()
pSettings->setValue("forceModelicaLoad", false);
}
pSettings->setValue("MSLVersion", true);
accept();
}

/*!
* \brief MSLVersionDialog::reject
* Override QDialog::reject() so we can't close the dialog.
*/
void MSLVersionDialog::reject()
{
// do nothing here.
}

/*!
* \brief MSLVersionDialog::sizeHint
* \return
*/
QSize MSLVersionDialog::sizeHint() const
{
QSize size = QWidget::sizeHint();
size.rwidth() = mpWidget->width();
size.rheight() = mpWidget->height() + 50; // add 50 for dialog frame and title bar
return size;
}
24 changes: 1 addition & 23 deletions OMEdit/OMEditLIB/MainWindow.h
Expand Up @@ -528,7 +528,7 @@ public slots:
#endif
void runOMSensPlugin();
void exportModelToOMNotebook();
void openInstallLibraryDialog();
bool openInstallLibraryDialog();
void upgradeInstalledLibraries();
void importModelfromOMNotebook();
void importNgspiceNetlist();
Expand Down Expand Up @@ -605,26 +605,4 @@ private slots:
void readOMContributors(QNetworkReply *pNetworkReply);
};

class MSLVersionDialog : public QDialog
{
Q_OBJECT
public:
MSLVersionDialog(QWidget *parent = 0);
private:
QRadioButton *mpMSL3RadioButton;
QRadioButton *mpMSL4RadioButton;
QRadioButton *mpNoMSLRadioButton;
QWidget *mpWidget;
private slots:
void setMSLVersion();

// QDialog interface
public slots:
virtual void reject() override;

// QWidget interface
public:
virtual QSize sizeHint() const override;
};

#endif // MAINWINDOW_H
18 changes: 8 additions & 10 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1417,13 +1417,13 @@ void LibraryTreeModel::addModelicaLibraries()
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
pOMCProxy->loadSystemLibraries();
QStringList systemLibs = pOMCProxy->getClassNames();
if (OptionsDialog::instance()->getLibrariesPage()->getLoadOpenModelicaLibraryCheckBox()->isChecked()) {
systemLibs.prepend("OpenModelica");
}
foreach (QString lib, systemLibs) {
SplashScreen::instance()->showMessage(QString(Helper::loading).append(" ").append(lib), Qt::AlignRight, Qt::white);
createLibraryTreeItem(lib, mpRootLibraryTreeItem, true, true, true);
checkIfAnyNonExistingClassLoaded();
foreach (QString systemLib, systemLibs) {
LibraryTreeItem *pLibraryTreeItem = findLibraryTreeItem(systemLib);
if (!pLibraryTreeItem) {
SplashScreen::instance()->showMessage(QString("%1 %2").arg(Helper::loading, systemLib), Qt::AlignRight, Qt::white);
createLibraryTreeItem(systemLib, mpRootLibraryTreeItem, true, true, true);
checkIfAnyNonExistingClassLoaded();
}
}
// load Modelica User Libraries.
pOMCProxy->loadUserLibraries();
Expand Down Expand Up @@ -4707,9 +4707,7 @@ void LibraryWidget::saveTotalLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
void LibraryWidget::openLibraryTreeItem(QString nameStructure)
{
LibraryTreeItem *pLibraryTreeItem = mpLibraryTreeModel->findLibraryTreeItem(nameStructure);
if (!pLibraryTreeItem) {
return;
} else {
if (pLibraryTreeItem) {
mpLibraryTreeModel->showModelWidget(pLibraryTreeItem);
}
}
Expand Down
32 changes: 13 additions & 19 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -268,8 +268,7 @@ bool OMCProxy::initializeOMC(threadData_t *threadData)
#endif
/* set the tmp directory as the working directory */
changeDirectory(tmpPath);
// set the OpenModelicaLibrary variable.
Helper::OpenModelicaLibrary = getModelicaPath();
// set the user home directory variable.
Helper::userHomeDirectory = getHomeDirectoryPath();
return true;
}
Expand Down Expand Up @@ -722,27 +721,10 @@ void OMCProxy::loadSystemLibraries()
loadModel("Modelica", "default");
loadModel("ModelicaReference", "default");
} else {
bool forceModelicaLoad = true;
QSettings *pSettings = Utilities::getApplicationSettings();
if (pSettings->contains("forceModelicaLoad")) {
forceModelicaLoad = pSettings->value("forceModelicaLoad").toBool();
}
pSettings->beginGroup("libraries");
QStringList libraries = pSettings->childKeys();
pSettings->endGroup();
/* Only force loading of Modelica & ModelicaReference if user is using OMEdit for the first time.
* Later user must use the libraries options dialog.
*/
if (forceModelicaLoad) {
if (!pSettings->contains("libraries/Modelica")) {
pSettings->setValue("libraries/Modelica","default");
libraries.prepend("Modelica");
}
if (!pSettings->contains("libraries/ModelicaReference")) {
pSettings->setValue("libraries/ModelicaReference","default");
libraries.prepend("ModelicaReference");
}
}
foreach (QString lib, libraries) {
QString version = pSettings->value("libraries/" + lib).toString();
loadModel(lib, version);
Expand Down Expand Up @@ -2773,6 +2755,18 @@ QString OMCProxy::uriToFilename(QString uri)
}
}

/*!
* \brief OMCProxy::setModelicaPath
* Sets the Modelica library path.
* \param path
*/
bool OMCProxy::setModelicaPath(const QString &path)
{
bool result = mpOMCInterface->setModelicaPath(path);
printMessagesStringInternal();
return result;
}

/*!
* \brief OMCProxy::getModelicaPath
* Gets the modelica library path
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/OMC/OMCProxy.h
Expand Up @@ -230,6 +230,7 @@ class OMCProxy : public QObject
bool disableNewInstantiation();
QString makeDocumentationUriToFileName(QString documentation);
QString uriToFilename(QString uri);
bool setModelicaPath(const QString &path);
QString getModelicaPath();
QString getHomeDirectoryPath();
QStringList getAvailableLibraries();
Expand Down

0 comments on commit 1d96e42

Please sign in to comment.