Skip to content

Commit

Permalink
- Check all models recursive.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19550 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 12, 2014
1 parent cad390d commit aff3eaf
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 4 deletions.
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/GUI/Containers/ModelWidgetContainer.cpp
Expand Up @@ -3030,6 +3030,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
getMainWindow()->getSimulationSetupAction()->setEnabled(enabled);
getMainWindow()->getInstantiateModelAction()->setEnabled(enabled);
getMainWindow()->getCheckModelAction()->setEnabled(enabled);
getMainWindow()->getCheckAllModelsAction()->setEnabled(enabled);
getMainWindow()->getExportFMUAction()->setEnabled(enabled);
getMainWindow()->getExportXMLAction()->setEnabled(enabled);
getMainWindow()->getExportToOMNotebookAction()->setEnabled(enabled);
Expand Down
61 changes: 59 additions & 2 deletions OMEdit/OMEditGUI/GUI/MainWindow.cpp
Expand Up @@ -766,6 +766,39 @@ void MainWindow::checkModel(LibraryTreeNode *pLibraryTreeNode)
mpStatusBar->clearMessage();
}

void MainWindow::checkAllModels(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeNode->getModelWidget())
{
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextWidget()->getModelicaTextEdit()->validateModelicaText())
return;
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::checkModel).append(" ").append(pLibraryTreeNode->getNameStructure()));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
QString checkModelResult = mpOMCProxy->checkAllModelsRecursive(pLibraryTreeNode->getNameStructure());
if (checkModelResult.length())
{
QString windowTitle = QString(Helper::checkModel).append(" - ").append(pLibraryTreeNode->getName());
InformationDialog *pInformationDialog = new InformationDialog(windowTitle, checkModelResult, false, this);
pInformationDialog->show();
}
else
{
mpMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0,
"Check of " + pLibraryTreeNode->getName() + " failed.",
Helper::scriptingKind, Helper::notificationLevel, 0,
mpMessagesWidget->getMessagesTreeWidget()));
}
// hide progress bar
hideProgressBar();
// clear the status bar message
mpStatusBar->clearMessage();
}

void MainWindow::exportModelFMU(LibraryTreeNode *pLibraryTreeNode)
{
/* if Modelica text is changed manually by user then validate it before saving. */
Expand Down Expand Up @@ -1226,6 +1259,23 @@ void MainWindow::checkModel()
}
}

void MainWindow::checkAllModels()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
LibraryTreeNode *pLibraryTreeNode = pModelWidget->getLibraryTreeNode();
if (pLibraryTreeNode)
checkAllModels(pLibraryTreeNode);
}
else
{
mpMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::NO_MODELICA_CLASS_OPEN)
.arg(tr("checking")), Helper::scriptingKind, Helper::notificationLevel,
0, mpMessagesWidget->getMessagesTreeWidget()));
}
}

//! Open Simulation Window
void MainWindow::simulateModel()
{
Expand Down Expand Up @@ -1772,10 +1822,15 @@ void MainWindow::createActions()
mpInstantiateModelAction->setEnabled(false);
connect(mpInstantiateModelAction, SIGNAL(triggered()), SLOT(instantiatesModel()));
// check model action
mpCheckModelAction = new QAction(QIcon(":/Resources/icons/check.png"), tr("Check Model"), this);
mpCheckModelAction->setStatusTip(tr("Check the modelica model"));
mpCheckModelAction = new QAction(QIcon(":/Resources/icons/check.svg"), Helper::checkModel, this);
mpCheckModelAction->setStatusTip(Helper::checkModelTip);
mpCheckModelAction->setEnabled(false);
connect(mpCheckModelAction, SIGNAL(triggered()), SLOT(checkModel()));
// check all models action
mpCheckAllModelsAction = new QAction(QIcon(":/Resources/icons/check-all.svg"), Helper::checkAllModels, this);
mpCheckAllModelsAction->setStatusTip(Helper::checkAllModelsTip);
mpCheckAllModelsAction->setEnabled(false);
connect(mpCheckAllModelsAction, SIGNAL(triggered()), SLOT(checkAllModels()));
// simulate action
mpSimulateModelAction = new QAction(QIcon(":/Resources/icons/simulate.png"), Helper::simulate, this);
mpSimulateModelAction->setStatusTip(Helper::simulateTip);
Expand Down Expand Up @@ -2018,6 +2073,7 @@ void MainWindow::createMenus()
// add actions to Simulation menu
pSimulationMenu->addAction(mpInstantiateModelAction);
pSimulationMenu->addAction(mpCheckModelAction);
pSimulationMenu->addAction(mpCheckAllModelsAction);
pSimulationMenu->addAction(mpSimulateModelAction);
pSimulationMenu->addAction(mpSimulationSetupAction);
// add Simulation menu to menu bar
Expand Down Expand Up @@ -2166,6 +2222,7 @@ void MainWindow::createToolbars()
// add actions to Simulation Toolbar
mpSimulationToolBar->addAction(mpInstantiateModelAction);
mpSimulationToolBar->addAction(mpCheckModelAction);
mpSimulationToolBar->addAction(mpCheckAllModelsAction);
mpSimulationToolBar->addAction(mpSimulateModelAction);
mpSimulationToolBar->addAction(mpSimulationSetupAction);
// Model Swithcer Toolbar
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/GUI/MainWindow.h
Expand Up @@ -122,6 +122,7 @@ class MainWindow : public QMainWindow
QAction* getSimulationSetupAction();
QAction* getInstantiateModelAction();
QAction* getCheckModelAction();
QAction* getCheckAllModelsAction() {return mpCheckAllModelsAction;}
QAction* getExportFMUAction();
QAction* getExportXMLAction();
QAction* getLineShapeAction();
Expand All @@ -148,6 +149,7 @@ class MainWindow : public QMainWindow
void simulationSetup(LibraryTreeNode *pLibraryTreeNode);
void instantiatesModel(LibraryTreeNode *pLibraryTreeNode);
void checkModel(LibraryTreeNode *pLibraryTreeNode);
void checkAllModels(LibraryTreeNode *pLibraryTreeNode);
void exportModelFMU(LibraryTreeNode *pLibraryTreeNode);
void exportModelXML(LibraryTreeNode *pLibraryTreeNode);
void exportModelToOMNotebook(LibraryTreeNode *pLibraryTreeNode);
Expand Down Expand Up @@ -215,6 +217,7 @@ class MainWindow : public QMainWindow
// Simulation Menu
QAction *mpInstantiateModelAction;
QAction *mpCheckModelAction;
QAction *mpCheckAllModelsAction;
QAction *mpSimulateModelAction;
QAction *mpSimulationSetupAction;
// FMI Menu
Expand Down Expand Up @@ -282,6 +285,7 @@ public slots:
void zoomOut();
void instantiatesModel();
void checkModel();
void checkAllModels();
void simulateModel();
void openSimulationDialog();
void openInteractiveSimulation();
Expand Down
17 changes: 16 additions & 1 deletion OMEdit/OMEditGUI/GUI/Widgets/LibraryTreeWidget.cpp
Expand Up @@ -550,9 +550,13 @@ void LibraryTreeWidget::createActions()
mpInstantiateModelAction->setStatusTip(Helper::instantiateModelTip);
connect(mpInstantiateModelAction, SIGNAL(triggered()), SLOT(instantiateModel()));
// check Model Action
mpCheckModelAction = new QAction(QIcon(":/Resources/icons/check.png"), Helper::checkModel, this);
mpCheckModelAction = new QAction(QIcon(":/Resources/icons/check.svg"), Helper::checkModel, this);
mpCheckModelAction->setStatusTip(Helper::checkModelTip);
connect(mpCheckModelAction, SIGNAL(triggered()), SLOT(checkModel()));
// check all Models Action
mpCheckAllModelsAction = new QAction(QIcon(":/Resources/icons/check-all.svg"), Helper::checkAllModels, this);
mpCheckAllModelsAction->setStatusTip(Helper::checkAllModelsTip);
connect(mpCheckAllModelsAction, SIGNAL(triggered()), SLOT(checkAllModels()));
// simulate Action
mpSimulateAction = new QAction(QIcon(":/Resources/icons/simulate.png"), Helper::simulate, this);
mpSimulateAction->setStatusTip(Helper::simulateTip);
Expand Down Expand Up @@ -1319,6 +1323,7 @@ void LibraryTreeWidget::showContextMenu(QPoint point)
menu.addSeparator();
menu.addAction(mpInstantiateModelAction);
menu.addAction(mpCheckModelAction);
menu.addAction(mpCheckAllModelsAction);
menu.addAction(mpSimulateAction);
menu.addAction(mpSimulationSetupAction);
/* If item is OpenModelica or part of it or is search tree item then don't show the unload for it. */
Expand Down Expand Up @@ -1404,6 +1409,16 @@ void LibraryTreeWidget::checkModel()
mpMainWindow->checkModel(pLibraryTreeNode);
}

void LibraryTreeWidget::checkAllModels()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
if (selectedItemsList.isEmpty())
return;
LibraryTreeNode *pLibraryTreeNode = dynamic_cast<LibraryTreeNode*>(selectedItemsList.at(0));
if (pLibraryTreeNode)
mpMainWindow->checkAllModels(pLibraryTreeNode);
}

void LibraryTreeWidget::unloadClass()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/GUI/Widgets/LibraryTreeWidget.h
Expand Up @@ -181,6 +181,7 @@ class LibraryTreeWidget : public QTreeWidget
QAction *mpNewModelicaClassAction;
QAction *mpInstantiateModelAction;
QAction *mpCheckModelAction;
QAction *mpCheckAllModelsAction;
QAction *mpSimulateAction;
QAction *mpSimulationSetupAction;
QAction *mpUnloadClassAction;
Expand All @@ -203,6 +204,7 @@ public slots:
void simulationSetup();
void instantiateModel();
void checkModel();
void checkAllModels();
void unloadClass();
void refresh();
void exportModelFMU();
Expand Down
11 changes: 11 additions & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2033,6 +2033,17 @@ QString OMCProxy::checkModel(QString className)
return getResult();
}

/*!
Checks all nested modelica classes. Checks model balance in terms of number of variables and equations.
\param className - the name of the class.
\return the model check result
*/
QString OMCProxy::checkAllModelsRecursive(QString className)
{
sendCommand("checkAllModelsRecursive(" + className + ")", true, className);
return getResult();
}

/*!
Instantiates the model.
\param className - the name of the class.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -188,6 +188,7 @@ class OMCProxy : public QObject
QStringList readSimulationResultVars(QString fileName);
bool closeSimulationResultFile();
QString checkModel(QString className);
QString checkAllModelsRecursive(QString className);
bool isExperiment(QString className);
QStringList getSimulationOptions(QString className, double defaultTolerance = 1e-4);
bool translateModelFMU(QString className);
Expand Down
78 changes: 78 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/check-all.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed OMEdit/OMEditGUI/Resources/icons/check.png
Binary file not shown.
72 changes: 72 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/check.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -123,6 +123,8 @@ QString Helper::information;
QString Helper::rename;
QString Helper::checkModel;
QString Helper::checkModelTip;
QString Helper::checkAllModels;
QString Helper::checkAllModelsTip;
QString Helper::instantiateModel;
QString Helper::instantiateModelTip;
QString Helper::exportFMU;
Expand Down Expand Up @@ -252,6 +254,8 @@ void Helper::initHelperVariables()
Helper::rename = tr("rename");
Helper::checkModel = tr("Check Model");
Helper::checkModelTip = tr("Check the Modelica class");
Helper::checkAllModels = tr("Check All Models");
Helper::checkAllModelsTip = tr("Checks all nested modelica classes");
Helper::instantiateModel = tr("Instantiate Model");
Helper::instantiateModelTip = tr("Instantiate/Flatten the Modelica class");
Helper::exportFMU = tr("Export FMU");
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -129,6 +129,8 @@ class Helper : public QObject
static QString rename;
static QString checkModel;
static QString checkModelTip;
static QString checkAllModels;
static QString checkAllModelsTip;
static QString instantiateModel;
static QString instantiateModelTip;
static QString exportFMU;
Expand Down

0 comments on commit aff3eaf

Please sign in to comment.