Skip to content

Commit

Permalink
Added GUI support for package manager (#7982)
Browse files Browse the repository at this point in the history
* Added GUI support for package manager

* Added missing files

* Removed library management dialog

Added menu item to upgrade installed packages
Ignore some files

* Improved the system libraries menu

Added filters to install library dialog
  • Loading branch information
adeas31 committed Oct 20, 2021
1 parent ba10345 commit a0697d8
Show file tree
Hide file tree
Showing 16 changed files with 620 additions and 75 deletions.
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -3961,6 +3961,17 @@ annotation(
preferredView="text");
end getAvailableLibraries;

function getAvailableLibraryVersions
input TypeName libraryName;
output String[:] librariesAndVersions;
external "builtin";
annotation(
Documentation(info="<html>
Returns the installed versions of a library.
</html>"),
preferredView="text");
end getAvailableLibraryVersions;

function installPackage
input TypeName pkg;
input String version = "";
Expand Down
11 changes: 11 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Expand Up @@ -4168,6 +4168,17 @@ annotation(
preferredView="text");
end getAvailableLibraries;

function getAvailableLibraryVersions
input TypeName libraryName;
output String[:] librariesAndVersions;
external "builtin";
annotation(
Documentation(info="<html>
Returns the installed versions of a library.
</html>"),
preferredView="text");
end getAvailableLibraryVersions;

function installPackage
input TypeName pkg;
input String version = "";
Expand Down
7 changes: 7 additions & 0 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -2289,6 +2289,13 @@ algorithm
then
(cache,v);

case (cache,_,"getAvailableLibraryVersions",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT(str1)))},_)
algorithm
files := PackageManagement.getInstalledLibraryVersions(str1);
v := ValuesUtil.makeArray(List.map(files, ValuesUtil.makeString));
then
(cache,v);

case (cache,_,"installPackage",{Values.CODE(Absyn.C_TYPENAME(Absyn.IDENT(str1))), Values.STRING(str2), Values.BOOL(b)},_)
algorithm
v := Values.BOOL(PackageManagement.installPackage(str1, str2, b));
Expand Down
20 changes: 20 additions & 0 deletions OMCompiler/Compiler/Script/PackageManagement.mo
Expand Up @@ -123,6 +123,26 @@ algorithm
end for;
end getInstalledLibraries;

function getInstalledLibraryVersions
input String libraryName;
output list<String> libraryVersions = {};
protected
AvailableLibraries.Tree tree;
VersionMap.Tree versionTree;
list<SemanticVersion.Version> versions = {};
String versionStr;
algorithm
tree := getInstalledLibraries();
versionTree := AvailableLibraries.get(tree, libraryName);
versions := VersionMap.listKeys(versionTree);
for version in versions loop
versionStr := VersionMap.keyStr(version);
if (stringCompare(versionStr, "") > 0) then
libraryVersions := versionStr::libraryVersions;
end if;
end for;
end getInstalledLibraryVersions;

function getLibrarySubdirectories "This function returns a list of subdirectories that contain a package.mo file."
input String inPath;
output list<String> outSubdirectories = {};
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/.gitignore
Expand Up @@ -42,13 +42,17 @@ OMEdit.pro.*
/OMEditLIB/OMC/Parser/OMCOutputParser.cpp
/OMEditLIB/OMC/Parser/OMCOutputParser.h
/OMEditLIB/OMEditLIB.pro.*
/OMEditLIB/release
/OMEditLIB/debug
/OMEditGUI/.qmake.stash
/OMEditGUI/Makefile
/OMEditGUI/Makefile.Debug
/OMEditGUI/Makefile.Release
/OMEditGUI/object_script.*
/OMEditGUI/OMEditGUI.pro.*
/OMEditGUI/version.h
/OMEditGUI/release
/OMEditGUI/debug
/qjson-0.8.1/build/
/qmake.sh
Makefile.unix
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Debugger/DebuggerConfigurationsDialog.cpp
Expand Up @@ -63,7 +63,7 @@ DebuggerConfigurationPage::DebuggerConfigurationPage(DebuggerConfiguration debug
QFrame *pContainerFrame = new QFrame;
pContainerFrame->setFrameShape(QFrame::StyledPanel);
// Configuration Name
mpNameLabel = new Label(tr("Name:"));
mpNameLabel = new Label(Helper::name);
mpNameTextBox = new QLineEdit(mDebuggerConfiguration.name);
// Program File
mpProgramLabel = new Label(tr("Program:"));
Expand Down
220 changes: 147 additions & 73 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -77,6 +77,7 @@
#include "Interfaces/ModelInterface.h"
#include "omc_config.h"
#include "Util/NetworkAccessManager.h"
#include "Modeling/InstallLibraryDialog.h"

#include <QtSvg/QSvgGenerator>

Expand Down Expand Up @@ -1470,6 +1471,43 @@ void MainWindow::PlotCallbackFunction(void *p, int externalWindow, const char* f
}
}

/*!
* \brief MainWindow::addSystemLibraries
* Add the system libraries to the menu.
*/
void MainWindow::addSystemLibraries()
{
mpLibrariesMenu->clear();
// get the available libraries and versions.
QStringList libraries = MainWindow::instance()->getOMCProxy()->getAvailableLibraries();
libraries.append("OpenModelica");
libraries.sort();
foreach (QString library, libraries) {
QStringList versions;
if (library.compare(QStringLiteral("OpenModelica")) != 0) {
versions = MainWindow::instance()->getOMCProxy()->getAvailableLibraryVersions(library);
}
if (versions.isEmpty()) {
QAction *pAction = new QAction(library, this);
pAction->setData(QStringList() << library << "");
connect(pAction, SIGNAL(triggered()), SLOT(loadSystemLibrary()));
mpLibrariesMenu->addAction(pAction);
} else {
QMenu *pLibraryMenu = new QMenu(library);
foreach (QString version, versions) {
QAction *pAction = new QAction(version, this);
pAction->setData(QStringList() << library << version);
if ((library.compare(QStringLiteral("Modelica")) == 0) && (version.compare(QStringLiteral("4.0.0")) == 0)) {
pAction->setShortcut(QKeySequence("Ctrl+m"));
}
connect(pAction, SIGNAL(triggered()), SLOT(loadSystemLibrary()));
pLibraryMenu->addAction(pAction);
}
mpLibrariesMenu->addMenu(pLibraryMenu);
}
}
}

/*!
* \brief MainWindow::showMessagesBrowser
* Slot activated when MessagesWidget::MessageAdded signal is raised.\n
Expand Down Expand Up @@ -1813,34 +1851,50 @@ void MainWindow::loadSystemLibrary()
{
QAction *pAction = qobject_cast<QAction*>(sender());
if (pAction) {
/* check if library is already loaded. */
QString library = pAction->data().toString();
LibraryTreeModel *pLibraryTreeModel = mpLibraryWidget->getLibraryTreeModel();
if (pLibraryTreeModel->findLibraryTreeItemOneLevel(library)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::information));
pMessageBox->setIcon(QMessageBox::Information);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(library)));
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES))
.arg(library).append("\n")
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg(library)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
} else { /* if library is not loaded then load it. */
mpProgressBar->setRange(0, 0);
showProgressBar();
mpStatusBar->showMessage(QString(Helper::loading).append(": ").append(library));

if (library.compare("OpenModelica") == 0) {
pLibraryTreeModel->createLibraryTreeItem(library, pLibraryTreeModel->getRootLibraryTreeItem(), true, true, true);
pLibraryTreeModel->checkIfAnyNonExistingClassLoaded();
} else if (mpOMCProxy->loadModel(library)) {
mpLibraryWidget->getLibraryTreeModel()->loadDependentLibraries(mpOMCProxy->getClassNames());
}
mpStatusBar->clearMessage();
hideProgressBar();
QStringList actionData = pAction->data().toStringList();
if (actionData.size() > 1) {
loadSystemLibrary(actionData.at(0), actionData.at(1));
}
}
}

/*!
* \brief MainWindow::loadSystemLibrary
* Loads a system library.
* \param library
* \param version
*/
void MainWindow::loadSystemLibrary(const QString &library, QString version)
{
/* check if library is already loaded. */
LibraryTreeModel *pLibraryTreeModel = mpLibraryWidget->getLibraryTreeModel();
if (pLibraryTreeModel->findLibraryTreeItemOneLevel(library)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, Helper::information));
pMessageBox->setIcon(QMessageBox::Information);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(library)));
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFINING_EXISTING_CLASSES)).arg(library).append("\n")
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD).arg(library)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
} else { /* if library is not loaded then load it. */
mpProgressBar->setRange(0, 0);
showProgressBar();
mpStatusBar->showMessage(QString(Helper::loading).append(": ").append(library));

if (version.isEmpty()) {
version = QString("default");
}

if (library.compare("OpenModelica") == 0) {
pLibraryTreeModel->createLibraryTreeItem(library, pLibraryTreeModel->getRootLibraryTreeItem(), true, true, true);
pLibraryTreeModel->checkIfAnyNonExistingClassLoaded();
} else if (mpOMCProxy->loadModel(library, version)) {
mpLibraryWidget->getLibraryTreeModel()->loadDependentLibraries(mpOMCProxy->getClassNames());
}
mpStatusBar->clearMessage();
hideProgressBar();
}
}

Expand Down Expand Up @@ -2439,6 +2493,28 @@ void MainWindow::exportModelToOMNotebook()
}
}

/*!
* \brief MainWindow::openInstallLibraryDialog
* Opens the install library dialog.
*/
void MainWindow::openInstallLibraryDialog()
{
InstallLibraryDialog *pInstallLibraryDialog = new InstallLibraryDialog;
pInstallLibraryDialog->exec();
}

/*!
* \brief MainWindow::upgradeInstalledLibraries
* Upgrades the installed libraries.
*/
void MainWindow::upgradeInstalledLibraries()
{
if (mpOMCProxy->upgradeInstalledPackages(true)) {
mpOMCProxy->updatePackageIndex();
addSystemLibraries();
}
}

//! Imports the models from OMNotebook.
//! @see exportModelToOMNotebook();
void MainWindow::importModelfromOMNotebook()
Expand Down Expand Up @@ -3360,6 +3436,14 @@ void MainWindow::createActions()
mpExportToOMNotebookAction->setStatusTip(Helper::exportToOMNotebookTip);
mpExportToOMNotebookAction->setEnabled(false);
connect(mpExportToOMNotebookAction, SIGNAL(triggered()), SLOT(exportModelToOMNotebook()));
// install library action
mpInstallLibraryAction = new QAction(tr("Install Library"), this);
mpInstallLibraryAction->setStatusTip(tr("Opens the install library window"));
connect(mpInstallLibraryAction, SIGNAL(triggered()), SLOT(openInstallLibraryDialog()));
// upgrade installed libraries action
mpUpgradeInstalledLibrariesAction = new QAction(tr("Upgrade Installed Libraries"), this);
mpUpgradeInstalledLibrariesAction->setStatusTip(tr("Upgrades the installed libraries"));
connect(mpUpgradeInstalledLibrariesAction, SIGNAL(triggered()), SLOT(upgradeInstalledLibraries()));
// clear recent files action
mpClearRecentFilesAction = new QAction(Helper::clearRecentFiles, this);
mpClearRecentFilesAction->setStatusTip(tr("Clears the recent files list"));
Expand Down Expand Up @@ -3759,29 +3843,29 @@ void MainWindow::createMenus()
//Create the menubar
//Create the menus
// File menu
QMenu *pFileMenu = new QMenu(menuBar());
pFileMenu->setObjectName("menuFile");
pFileMenu->setTitle(tr("&File"));
mpFileMenu = new QMenu(menuBar());
mpFileMenu->setObjectName("menuFile");
mpFileMenu->setTitle(tr("&File"));
// add actions to File menu
pFileMenu->addMenu(mpNewModelMenu);
pFileMenu->addAction(mpOpenModelicaFileAction);
pFileMenu->addAction(mpOpenModelicaFileWithEncodingAction);
pFileMenu->addAction(mpLoadModelicaLibraryAction);
pFileMenu->addAction(mpLoadEncryptedLibraryAction);
pFileMenu->addAction(mpOpenResultFileAction);
pFileMenu->addAction(mpOpenTransformationFileAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpNewCompositeModelFileAction);
pFileMenu->addAction(mpOpenCompositeModelFileAction);
pFileMenu->addAction(mpLoadExternModelAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpOpenDirectoryAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpSaveAction);
pFileMenu->addAction(mpSaveAsAction);
mpFileMenu->addMenu(mpNewModelMenu);
mpFileMenu->addAction(mpOpenModelicaFileAction);
mpFileMenu->addAction(mpOpenModelicaFileWithEncodingAction);
mpFileMenu->addAction(mpLoadModelicaLibraryAction);
mpFileMenu->addAction(mpLoadEncryptedLibraryAction);
mpFileMenu->addAction(mpOpenResultFileAction);
mpFileMenu->addAction(mpOpenTransformationFileAction);
mpFileMenu->addSeparator();
mpFileMenu->addAction(mpNewCompositeModelFileAction);
mpFileMenu->addAction(mpOpenCompositeModelFileAction);
mpFileMenu->addAction(mpLoadExternModelAction);
mpFileMenu->addSeparator();
mpFileMenu->addAction(mpOpenDirectoryAction);
mpFileMenu->addSeparator();
mpFileMenu->addAction(mpSaveAction);
mpFileMenu->addAction(mpSaveAsAction);
//menuFile->addAction(saveAllAction);
pFileMenu->addAction(mpSaveTotalAction);
pFileMenu->addSeparator();
mpFileMenu->addAction(mpSaveTotalAction);
mpFileMenu->addSeparator();
// Import menu
QMenu *pImportMenu = new QMenu(menuBar());
pImportMenu->setTitle(tr("Import"));
Expand All @@ -3790,7 +3874,7 @@ void MainWindow::createMenus()
pImportMenu->addAction(mpImportFMUModelDescriptionAction);
pImportMenu->addAction(mpImportFromOMNotebookAction);
pImportMenu->addAction(mpImportNgspiceNetlistAction);
pFileMenu->addMenu(pImportMenu);
mpFileMenu->addMenu(pImportMenu);
// Export menu
QMenu *pExportMenu = new QMenu(menuBar());
pExportMenu->setTitle(Helper::exportt);
Expand All @@ -3803,39 +3887,29 @@ void MainWindow::createMenus()
pExportMenu->addAction(mpExportXMLAction);
pExportMenu->addAction(mpExportFigaroAction);
pExportMenu->addAction(mpExportToOMNotebookAction);
pFileMenu->addMenu(pExportMenu);
pFileMenu->addSeparator();
mpFileMenu->addMenu(pExportMenu);
mpFileMenu->addSeparator();
// System libraries menu
mpLibrariesMenu = new QMenu(menuBar());
mpLibrariesMenu->setObjectName("LibrariesMenu");
mpLibrariesMenu->setTitle(tr("&System Libraries"));
// get the available libraries.
QStringList libraries = mpOMCProxy->getAvailableLibraries();
libraries.append("OpenModelica");
libraries.sort();
for (int i = 0; i < libraries.size(); ++i) {
QAction *pAction = new QAction(libraries[i], this);
pAction->setData(libraries[i]);
if (libraries[i].compare("Modelica") == 0) {
pAction->setShortcut(QKeySequence("Ctrl+m"));
}
connect(pAction, SIGNAL(triggered()), SLOT(loadSystemLibrary()));
mpLibrariesMenu->addAction(pAction);
}
pFileMenu->addMenu(mpLibrariesMenu);
pFileMenu->addSeparator();
addSystemLibraries();
mpFileMenu->addMenu(mpLibrariesMenu);
mpFileMenu->addAction(mpInstallLibraryAction);
mpFileMenu->addAction(mpUpgradeInstalledLibrariesAction);
mpFileMenu->addSeparator();
mpRecentFilesMenu = new QMenu(menuBar());
mpRecentFilesMenu->setObjectName("RecentFilesMenu");
mpRecentFilesMenu->setTitle(tr("Recent &Files"));
// we don't create the recent files actions here. It will be done when WelcomePageWidget is created and updateRecentFileActionsAndList() is called.
pFileMenu->addMenu(mpRecentFilesMenu);
pFileMenu->addAction(mpClearRecentFilesAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpPrintModelAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpQuitAction);
mpFileMenu->addMenu(mpRecentFilesMenu);
mpFileMenu->addAction(mpClearRecentFilesAction);
mpFileMenu->addSeparator();
mpFileMenu->addAction(mpPrintModelAction);
mpFileMenu->addSeparator();
mpFileMenu->addAction(mpQuitAction);
// add File menu to menu bar
menuBar()->addAction(pFileMenu->menuAction());
menuBar()->addAction(mpFileMenu->menuAction());
// Edit menu
QMenu *pEditMenu = new QMenu(menuBar());
pEditMenu->setTitle(tr("&Edit"));
Expand Down

0 comments on commit a0697d8

Please sign in to comment.