Skip to content

Commit

Permalink
Better integration of creation and opening of SSP models in menu (#7233)
Browse files Browse the repository at this point in the history
* Better integration of creation and opening of SSP models in menu

* Show new SSP model window in OMEdit center

Updated usersguide
  • Loading branch information
adeas31 committed Feb 26, 2021
1 parent b7ab7fc commit 88339b4
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 136 deletions.
128 changes: 49 additions & 79 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -1582,10 +1582,21 @@ void MainWindow::createNewModelicaClass()
pModelicaClassDialog->exec();
}

/*!
* \brief MainWindow::createNewSSPModel
* Opens the new SSP model dialog.
*/
void MainWindow::createNewSSPModel()
{
CreateModelDialog *pCreateModelDialog = new CreateModelDialog(this);
pCreateModelDialog->exec();
}


void MainWindow::openModelicaFile()
{
QStringList fileNames;
fileNames = StringHandler::getOpenFileNames(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFiles), NULL, Helper::omFileTypes, NULL);
fileNames = StringHandler::getOpenFileNames(this, QString("%1 - %2").arg(Helper::applicationName, Helper::chooseFiles), NULL, Helper::omFileTypes, NULL);
if (fileNames.isEmpty()) {
return;
}
Expand All @@ -1599,7 +1610,7 @@ void MainWindow::openModelicaFile()
// if file doesn't exists
if (!QFile::exists(file)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(file)));
Expand Down Expand Up @@ -1762,54 +1773,6 @@ void MainWindow::openCompositeModelFile()
hideProgressBar();
}

/*!
* \brief MainWindow::createNewOMSModel
* Opens the new OMSimulator model dialog.
*/
void MainWindow::createNewOMSModel()
{
CreateModelDialog *pCreateModelDialog = new CreateModelDialog;
pCreateModelDialog->exec();
}

/*!
* \brief MainWindow::openOMSModelFile
* Opens the OMSimulator model file(s).\n
* Slot activated when mpOpenOMSModelFileAction triggered signal is raised.
*/
void MainWindow::openOMSModelFile()
{
QStringList fileNames;
fileNames = StringHandler::getOpenFileNames(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFiles), NULL, Helper::omsFileTypes, NULL);
if (fileNames.isEmpty()) {
return;
}
int progressValue = 0;
mpProgressBar->setRange(0, fileNames.size());
showProgressBar();
foreach (QString file, fileNames) {
file = file.replace("\\", "/");
mpStatusBar->showMessage(QString(Helper::loading).append(": ").append(file));
mpProgressBar->setValue(++progressValue);
// if file doesn't exists
if (!QFile::exists(file)) {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::error));
pMessageBox->setIcon(QMessageBox::Critical);
pMessageBox->setAttribute(Qt::WA_DeleteOnClose);
pMessageBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE).arg(file)));
pMessageBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::FILE_NOT_FOUND).arg(file)));
pMessageBox->setStandardButtons(QMessageBox::Ok);
pMessageBox->exec();
} else {
mpLibraryWidget->openFile(file, Helper::utf8);
}
}
mpStatusBar->clearMessage();
hideProgressBar();

}

/*!
* \brief MainWindow::loadExternalModels
* Loads the external model(s) for TLM meta-modeling.\n
Expand Down Expand Up @@ -3250,10 +3213,14 @@ void MainWindow::createActions()
/* Menu Actions */
// File Menu
// create new Modelica class action
mpNewModelicaClassAction = new QAction(QIcon(":/Resources/icons/new.svg"), Helper::newModelicaClass, this);
mpNewModelicaClassAction = new QAction(Helper::newModelicaClass, this);
mpNewModelicaClassAction->setStatusTip(Helper::createNewModelicaClass);
mpNewModelicaClassAction->setShortcut(QKeySequence("Ctrl+n"));
connect(mpNewModelicaClassAction, SIGNAL(triggered()), SLOT(createNewModelicaClass()));
// create new SSP Model action
mpNewSSPModelAction = new QAction(Helper::newOMSimulatorModel, this);
mpNewSSPModelAction->setStatusTip(Helper::newOMSimulatorModelTip);
connect(mpNewSSPModelAction, SIGNAL(triggered()), SLOT(createNewSSPModel()));
// open Modelica file action
mpOpenModelicaFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), Helper::openModelicaFiles, this);
mpOpenModelicaFileAction->setShortcut(QKeySequence("Ctrl+o"));
Expand Down Expand Up @@ -3292,15 +3259,6 @@ void MainWindow::createActions()
mpLoadExternModelAction = new QAction(tr("Load External Model(s)"), this);
mpLoadExternModelAction->setStatusTip(tr("Loads the External Model(s) for the TLM co-simulation"));
connect(mpLoadExternModelAction, SIGNAL(triggered()), SLOT(loadExternalModels()));
// create new OMSimulator Model action
mpNewOMSimulatorModelAction = new QAction(QIcon(":/Resources/icons/new.svg"), Helper::newOMSimulatorModel, this);
mpNewOMSimulatorModelAction->setStatusTip(Helper::newOMSimulatorModelTip);
mpNewOMSimulatorModelAction->setShortcut(QKeySequence("Ctrl+t"));
connect(mpNewOMSimulatorModelAction, SIGNAL(triggered()), SLOT(createNewOMSModel()));
// open OMSimulator Model file action
mpOpenOMSModelFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), tr("Open SSP Model(s)"), this);
mpOpenOMSModelFileAction->setStatusTip(tr("Opens the SSP model file(s)"));
connect(mpOpenOMSModelFileAction, SIGNAL(triggered()), SLOT(openOMSModelFile()));
// open the directory action
mpOpenDirectoryAction = new QAction(tr("Open Directory"), this);
mpOpenDirectoryAction->setStatusTip(tr("Opens the directory"));
Expand Down Expand Up @@ -3770,7 +3728,7 @@ void MainWindow::createMenus()
pFileMenu->setObjectName("menuFile");
pFileMenu->setTitle(tr("&File"));
// add actions to File menu
pFileMenu->addAction(mpNewModelicaClassAction);
pFileMenu->addMenu(mpNewModelMenu);
pFileMenu->addAction(mpOpenModelicaFileAction);
pFileMenu->addAction(mpOpenModelicaFileWithEncodingAction);
pFileMenu->addAction(mpLoadModelicaLibraryAction);
Expand Down Expand Up @@ -3941,24 +3899,21 @@ void MainWindow::createMenus()
// add Debug menu to menu bar
menuBar()->addAction(pDebugMenu->menuAction());
// OMSimulator menu
QMenu *pOMSimulatorMenu = new QMenu(menuBar());
pOMSimulatorMenu->setTitle(tr("&SSP"));
// add actions to OMSimulator menu
pOMSimulatorMenu->addAction(mpNewOMSimulatorModelAction);
pOMSimulatorMenu->addAction(mpOpenOMSModelFileAction);
pOMSimulatorMenu->addSeparator();
pOMSimulatorMenu->addAction(mpAddSystemAction);
pOMSimulatorMenu->addSeparator();
pOMSimulatorMenu->addAction(mpAddOrEditIconAction);
pOMSimulatorMenu->addAction(mpDeleteIconAction);
pOMSimulatorMenu->addSeparator();
pOMSimulatorMenu->addAction(mpAddConnectorAction);
pOMSimulatorMenu->addAction(mpAddBusAction);
pOMSimulatorMenu->addAction(mpAddTLMBusAction);
pOMSimulatorMenu->addSeparator();
pOMSimulatorMenu->addAction(mpAddSubModelAction);
QMenu *pSSPMenu = new QMenu(menuBar());
pSSPMenu->setTitle(tr("&SSP"));
// add actions to SSP menu
pSSPMenu->addAction(mpAddSystemAction);
pSSPMenu->addSeparator();
pSSPMenu->addAction(mpAddOrEditIconAction);
pSSPMenu->addAction(mpDeleteIconAction);
pSSPMenu->addSeparator();
pSSPMenu->addAction(mpAddConnectorAction);
pSSPMenu->addAction(mpAddBusAction);
pSSPMenu->addAction(mpAddTLMBusAction);
pSSPMenu->addSeparator();
pSSPMenu->addAction(mpAddSubModelAction);
// add OMSimulator menu to menu bar
menuBar()->addAction(pOMSimulatorMenu->menuAction());
menuBar()->addAction(pSSPMenu->menuAction());
#ifndef Q_OS_MAC
// Sensitivity Optimization menu
QMenu *pSensitivityOptimizationMenu = new QMenu(menuBar());
Expand Down Expand Up @@ -4287,7 +4242,22 @@ void MainWindow::createToolbars()
mpFileToolBar->setObjectName("File Toolbar");
mpFileToolBar->setAllowedAreas(Qt::TopToolBarArea);
// add actions to File Toolbar
mpFileToolBar->addAction(mpNewModelicaClassAction);
// New Menu
mpNewModelMenu = new QMenu;
mpNewModelMenu = new QMenu(menuBar());
mpNewModelMenu->setObjectName("NewModelMenu");
mpNewModelMenu->setTitle(tr("&New"));
mpNewModelMenu->setIcon(QIcon(":/Resources/icons/new.svg"));
mpNewModelMenu->addAction(mpNewModelicaClassAction);
mpNewModelMenu->addAction(mpNewSSPModelAction);
// new ToolButton
QToolButton *pNewToolButton = new QToolButton;
pNewToolButton->setMenu(mpNewModelMenu);
pNewToolButton->setPopupMode(QToolButton::MenuButtonPopup);
// Don't change the order of following two lines otherwise the icon of toolbar button is overwritten by default action.
pNewToolButton->setDefaultAction(mpNewModelicaClassAction);
pNewToolButton->setIcon(QIcon(":/Resources/icons/new.svg"));
mpFileToolBar->addWidget(pNewToolButton);
mpFileToolBar->addAction(mpOpenModelicaFileAction);
mpFileToolBar->addAction(mpSaveAction);
mpFileToolBar->addAction(mpSaveAsAction);
Expand Down
9 changes: 4 additions & 5 deletions OMEdit/OMEditLIB/MainWindow.h
Expand Up @@ -209,6 +209,7 @@ class MainWindow : public QMainWindow
QAction* getCommitFilesAction() {return mpCommitFilesAction;}
QAction* getRevertCommitAction() {return mpRevertCommitAction;}
QAction* getCleanWorkingDirectoryAction() {return mpCleanWorkingDirectoryAction;}
QMenu* getNewModelMenu() const {return mpNewModelMenu;}
QToolBar* getShapesToolBar() const {return mpShapesToolBar;}
QToolBar* getCheckToolBar() const {return mpCheckToolBar;}
QToolBar* getSimulationToolBar() const {return mpSimulationToolBar;}
Expand Down Expand Up @@ -306,6 +307,7 @@ class MainWindow : public QMainWindow
// File Menu
// Modelica File Actions
QAction *mpNewModelicaClassAction;
QAction *mpNewSSPModelAction;
QAction *mpOpenModelicaFileAction;
QAction *mpOpenModelicaFileWithEncodingAction;
QAction *mpLoadModelicaLibraryAction;
Expand All @@ -316,9 +318,6 @@ class MainWindow : public QMainWindow
QAction *mpNewCompositeModelFileAction;
QAction *mpOpenCompositeModelFileAction;
QAction *mpLoadExternModelAction;
// OMSimulator File Actions
QAction *mpNewOMSimulatorModelAction;
QAction *mpOpenOMSModelFileAction;
QAction *mpOpenDirectoryAction;
QAction *mpSaveAction;
QAction *mpSaveAsAction;
Expand Down Expand Up @@ -440,6 +439,7 @@ class MainWindow : public QMainWindow
QAction *mpAddSubModelAction;
QAction *mpOMSSimulateAction;
// Toolbars
QMenu *mpNewModelMenu;
QMenu *mpRecentFilesMenu;
QMenu *mpLibrariesMenu;
QToolBar *mpFileToolBar;
Expand Down Expand Up @@ -467,6 +467,7 @@ public slots:
void switchToAlgorithmicDebuggingPerspectiveSlot();
void showSearchBrowser();
void createNewModelicaClass();
void createNewSSPModel();
void openModelicaFile();
void showOpenModelicaFileDialog();
void loadModelicaLibrary();
Expand All @@ -476,8 +477,6 @@ public slots:
void createNewCompositeModelFile();
void openCompositeModelFile();
void loadExternalModels();
void createNewOMSModel();
void openOMSModelFile();
void openDirectory();
void loadSystemLibrary();
void writeOutputFileData(QString data);
Expand Down
45 changes: 5 additions & 40 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -2971,11 +2971,6 @@ void LibraryTreeView::createActions()
mpNewModelicaClassAction = new QAction(QIcon(":/Resources/icons/new.svg"), Helper::newModelicaClass, this);
mpNewModelicaClassAction->setStatusTip(Helper::createNewModelicaClass);
connect(mpNewModelicaClassAction, SIGNAL(triggered()), SLOT(createNewModelicaClass()));
// new Modelica Class Empty Action
mpNewModelicaClassEmptyAction = new QAction(QIcon(":/Resources/icons/new.svg"), Helper::newModelicaClass, this);
mpNewModelicaClassEmptyAction->setStatusTip(Helper::createNewModelicaClass);
mpNewModelicaClassEmptyAction->setShortcut(QKeySequence("Ctrl+n"));
connect(mpNewModelicaClassEmptyAction, SIGNAL(triggered()), SLOT(createNewModelicaClassEmpty()));
// save Action
mpSaveAction = new QAction(QIcon(":/Resources/icons/save.svg"), Helper::save, this);
mpSaveAction->setStatusTip(Helper::saveTip);
Expand Down Expand Up @@ -3132,11 +3127,6 @@ void LibraryTreeView::createActions()
mpTLMCoSimulationAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::tlmCoSimulationSetup, this);
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
connect(mpTLMCoSimulationAction, SIGNAL(triggered()), SLOT(TLMSimulate()));
// create new OMSimulator Model action
mpNewOMSimulatorModelEmptyAction = new QAction(QIcon(":/Resources/icons/new.svg"), Helper::newOMSimulatorModel, this);
mpNewOMSimulatorModelEmptyAction->setStatusTip(Helper::newOMSimulatorModelTip);
mpNewOMSimulatorModelEmptyAction->setShortcut(QKeySequence("Ctrl+t"));
connect(mpNewOMSimulatorModelEmptyAction, SIGNAL(triggered()), SLOT(createNewOMSModelEmpty()));
// OMSimulator rename Action
mpOMSRenameAction = new QAction(Helper::rename, this);
mpOMSRenameAction->setStatusTip(Helper::OMSRenameTip);
Expand Down Expand Up @@ -3404,9 +3394,7 @@ void LibraryTreeView::showContextMenu(QPoint point)
}
}
} else {
menu.addAction(mpNewModelicaClassEmptyAction);
menu.addSeparator();
menu.addAction(mpNewOMSimulatorModelEmptyAction);
menu.addMenu(MainWindow::instance()->getNewModelMenu());
menu.addSeparator();
menu.addAction(mpNewFileEmptyAction);
menu.addAction(mpNewFolderEmptyAction);
Expand Down Expand Up @@ -3465,16 +3453,6 @@ void LibraryTreeView::createNewModelicaClass()
}
}

/*!
* \brief LibraryTreeView::createNewModelicaClassEmpty
* Opens the create new ModelicaClassDialog for creating a new top level class.
*/
void LibraryTreeView::createNewModelicaClassEmpty()
{
ModelicaClassDialog *pModelicaClassDialog = new ModelicaClassDialog(MainWindow::instance());
pModelicaClassDialog->exec();
}

/*!
* \brief LibraryTreeView::saveClass
* Saves the class.
Expand Down Expand Up @@ -3906,16 +3884,6 @@ void LibraryTreeView::TLMSimulate()
}
}

/*!
* \brief LibraryTreeView::createNewOMSModelEmpty
* Opens the new OMSimulator model dialog.
*/
void LibraryTreeView::createNewOMSModelEmpty()
{
CreateModelDialog *pCreateModelDialog = new CreateModelDialog;
pCreateModelDialog->exec();
}

/*!
* \brief LibraryTreeView::OMSRename
* Opens the RenameItemDialog.
Expand Down Expand Up @@ -4991,8 +4959,7 @@ bool LibraryWidget::saveTextLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
QString fileName;
if (pLibraryTreeItem->getFileName().isEmpty()) {
QString name = pLibraryTreeItem->getName();
fileName = StringHandler::getSaveFileName(this, QString(Helper::applicationName).append(" - ").append(tr("Save File")), NULL,
Helper::txtFileTypes, NULL, "txt", &name);
fileName = StringHandler::getSaveFileName(this, QString("%1 - %2").arg(Helper::applicationName, Helper::saveFile), NULL, Helper::txtFileTypes, NULL, "txt", &name);
if (fileName.isEmpty()) { // if user press ESC
return false;
}
Expand Down Expand Up @@ -5026,7 +4993,7 @@ bool LibraryWidget::saveOMSLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
QString fileName;
if (pLibraryTreeItem->getFileName().isEmpty()) {
QString name = pLibraryTreeItem->getName();
fileName = StringHandler::getSaveFileName(this, QString(Helper::applicationName).append(" - ").append(tr("Save File")), NULL, Helper::omsFileTypes, NULL, "ssp", &name);
fileName = StringHandler::getSaveFileName(this, QString("%1 - %2").arg(Helper::applicationName, Helper::saveFile), NULL, Helper::omFileTypes, NULL, "ssp", &name);
if (fileName.isEmpty()) { // if user press ESC
return false;
}
Expand Down Expand Up @@ -5088,8 +5055,7 @@ bool LibraryWidget::saveAsCompositeModelLibraryTreeItem(LibraryTreeItem *pLibrar
{
QString fileName;
QString name = pLibraryTreeItem->getName();
fileName = StringHandler::getSaveFileName(this, QString(Helper::applicationName).append(" - ").append(tr("Save File")), NULL,
Helper::xmlFileTypes, NULL, "xml", &name);
fileName = StringHandler::getSaveFileName(this, QString("%1 - %2").arg(Helper::applicationName, Helper::saveFile), NULL, Helper::xmlFileTypes, NULL, "xml", &name);
if (fileName.isEmpty()) { // if user press ESC
return false;
}
Expand All @@ -5106,8 +5072,7 @@ bool LibraryWidget::saveAsOMSLibraryTreeItem(LibraryTreeItem *pLibraryTreeItem)
{
QString fileName;
QString name = pLibraryTreeItem->getName();
fileName = StringHandler::getSaveFileName(this, QString(Helper::applicationName).append(" - ").append(tr("Save File")), NULL,
Helper::omsFileTypes, NULL, "ssp", &name);
fileName = StringHandler::getSaveFileName(this, QString("%1 - %2").arg(Helper::applicationName, Helper::saveFile), NULL, Helper::omFileTypes, NULL, "ssp", &name);
if (fileName.isEmpty()) { // if user press ESC
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions OMEdit/OMEditLIB/Modeling/LibraryTreeWidget.h
Expand Up @@ -371,7 +371,6 @@ class LibraryTreeView : public QTreeView
QAction *mpOpenClassAction;
QAction *mpInformationAction;
QAction *mpNewModelicaClassAction;
QAction *mpNewModelicaClassEmptyAction;
QAction *mpSaveAction;
QAction *mpSaveAsAction;
QAction *mpSaveTotalAction;
Expand Down Expand Up @@ -409,7 +408,6 @@ class LibraryTreeView : public QTreeView
QAction *mpGenerateVerificationScenariosAction;
QAction *mpFetchInterfaceDataAction;
QAction *mpTLMCoSimulationAction;
QAction *mpNewOMSimulatorModelEmptyAction;
QAction *mpOMSRenameAction;
QAction *mpUnloadOMSModelAction;
void createActions();
Expand All @@ -422,7 +420,6 @@ public slots:
void openClass();
void openInformationDialog();
void createNewModelicaClass();
void createNewModelicaClassEmpty();
void saveClass();
void saveAsClass();
void saveTotalClass();
Expand Down Expand Up @@ -457,7 +454,6 @@ public slots:
void generateVerificationScenarios();
void fetchInterfaceData();
void TLMSimulate();
void createNewOMSModelEmpty();
void OMSRename();
void unloadOMSModel();
protected:
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Modeling/ModelicaClassDialog.cpp
Expand Up @@ -172,7 +172,7 @@ ModelicaClassDialog::ModelicaClassDialog(QWidget *pParent)
: QDialog(pParent)
{
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::createNewModelicaClass));
setWindowTitle(QString("%1 - %2").arg(Helper::applicationName).arg(Helper::createNewModelicaClass));
setMinimumWidth(400);
// Create the name label and text box
mpNameLabel = new Label(Helper::name);
Expand Down

0 comments on commit 88339b4

Please sign in to comment.