Skip to content

Commit

Permalink
- Compilation and simulation is done in a separate thread now. So par…
Browse files Browse the repository at this point in the history
…allel simulation is possible.

#2844
- the simulation output window is not modal anymore.
#2596
- Re-simulate with changed options
#2264
- Archive the simulation output windows and allow user to re open them later.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23532 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 24, 2014
1 parent 4e1ed68 commit 7ee4238
Show file tree
Hide file tree
Showing 13 changed files with 1,171 additions and 1,209 deletions.
33 changes: 23 additions & 10 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -151,7 +151,6 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
mpSimulationDialog = new SimulationDialog(this);
// Create an object of PlotWindowContainer
mpPlotWindowContainer = new PlotWindowContainer(this);
mpPlotWindowContainer->addPlotWindow(true);
// create an object of VariablesWidget
mpVariablesWidget = new VariablesWidget(this);
mpVariablesDockWidget->setWidget(mpVariablesWidget);
Expand Down Expand Up @@ -710,7 +709,7 @@ void MainWindow::simulate(LibraryTreeNode *pLibraryTreeNode)
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
return;
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, false, false);
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, false);
}

void MainWindow::simulateWithTransformationalDebugger(LibraryTreeNode *pLibraryTreeNode)
Expand All @@ -721,7 +720,7 @@ void MainWindow::simulateWithTransformationalDebugger(LibraryTreeNode *pLibraryT
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
return;
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, true, false);
mpSimulationDialog->directSimulate(pLibraryTreeNode, true, false);
}

void MainWindow::simulateWithAlgorithmicDebugger(LibraryTreeNode *pLibraryTreeNode)
Expand All @@ -732,7 +731,7 @@ void MainWindow::simulateWithAlgorithmicDebugger(LibraryTreeNode *pLibraryTreeNo
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
return;
}
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, false, true);
mpSimulationDialog->directSimulate(pLibraryTreeNode, false, true);
}

void MainWindow::simulationSetup(LibraryTreeNode *pLibraryTreeNode)
Expand All @@ -743,7 +742,7 @@ void MainWindow::simulationSetup(LibraryTreeNode *pLibraryTreeNode)
if (!pLibraryTreeNode->getModelWidget()->getModelicaTextEditor()->validateModelicaText())
return;
}
mpSimulationDialog->show(pLibraryTreeNode, false);
mpSimulationDialog->show(pLibraryTreeNode, false, SimulationOptions());
}

void MainWindow::instantiatesModel(LibraryTreeNode *pLibraryTreeNode)
Expand Down Expand Up @@ -1452,11 +1451,11 @@ void MainWindow::simulateModelWithAlgorithmicDebugger()
void MainWindow::openSimulationDialog()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
if (pModelWidget) {
LibraryTreeNode *pLibraryTreeNode = pModelWidget->getLibraryTreeNode();
if (pLibraryTreeNode)
if (pLibraryTreeNode) {
simulationSetup(pLibraryTreeNode);
}
}
}

Expand Down Expand Up @@ -1793,7 +1792,16 @@ void MainWindow::openRecentModelWidget()
*/
void MainWindow::reSimulateModel()
{
mpVariablesWidget->reSimulate();
mpVariablesWidget->directReSimulate();
}

/*!
Slot activated when Re-simulateSetupAction triggered signal is raised.\n
Shows the simulation setup for re-simulation.
*/
void MainWindow::showReSimulateSetup()
{
mpVariablesWidget->showReSimulateSetup();
}

void MainWindow::addNewPlotWindow()
Expand Down Expand Up @@ -2233,6 +2241,10 @@ void MainWindow::createActions()
mpReSimulateModelAction = new QAction(QIcon(":/Resources/icons/re-simulate.svg"), Helper::reSimulate, this);
mpReSimulateModelAction->setStatusTip(Helper::reSimulateTip);
connect(mpReSimulateModelAction, SIGNAL(triggered()), SLOT(reSimulateModel()));
// resimulate setup action
mpReSimulateSetupAction = new QAction(QIcon(":/Resources/icons/re-simulation-center.svg"), Helper::reSimulateSetup, this);
mpReSimulateSetupAction->setStatusTip(Helper::reSimulateSetupTip);
connect(mpReSimulateSetupAction, SIGNAL(triggered()), SLOT(showReSimulateSetup()));
// new plot window action
mpNewPlotWindowAction = new QAction(QIcon(":/Resources/icons/plot-window.svg"), tr("New Plot Window"), this);
mpNewPlotWindowAction->setStatusTip(tr("Inserts new plot window"));
Expand Down Expand Up @@ -2482,7 +2494,7 @@ void MainWindow::switchToPlottingPerspective()
mpModelSwitcherToolButton->setEnabled(false);
// if not plotwindow is opened then open one for user
if (mpPlotWindowContainer->subWindowList().size() == 0) {
mpPlotWindowContainer->addPlotWindow();
mpPlotWindowContainer->addPlotWindow(true);
}
mpVariablesDockWidget->show();
mpPlotToolBar->setEnabled(true);
Expand Down Expand Up @@ -2605,6 +2617,7 @@ void MainWindow::createToolbars()
mpPlotToolBar->setAllowedAreas(Qt::TopToolBarArea);
// add actions to Plot Toolbar
mpPlotToolBar->addAction(mpReSimulateModelAction);
mpPlotToolBar->addAction(mpReSimulateSetupAction);
mpPlotToolBar->addSeparator();
mpPlotToolBar->addAction(mpNewPlotWindowAction);
mpPlotToolBar->addAction(mpNewParametricPlotWindowAction);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -278,6 +278,7 @@ class MainWindow : public QMainWindow
QAction *mpModelSwitcherActions[MaxRecentFiles];
// Plot Toolbar Actions
QAction *mpReSimulateModelAction;
QAction *mpReSimulateSetupAction;
QAction *mpNewPlotWindowAction;
QAction *mpNewParametricPlotWindowAction;
QAction *mpClearPlotWindowAction;
Expand Down Expand Up @@ -348,6 +349,7 @@ public slots:
void toggleShapesButton();
void openRecentModelWidget();
void reSimulateModel();
void showReSimulateSetup();
void addNewPlotWindow();
void addNewParametricPlotWindow();
void clearPlotWindow();
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -87,6 +87,8 @@ SOURCES += main.cpp \
Component/Transformation.cpp \
Modeling/DocumentationWidget.cpp \
Simulation/SimulationDialog.cpp \
Simulation/SimulationOutputWidget.cpp \
Simulation/SimulationProcessThread.cpp \
FMI/ImportFMUDialog.cpp \
Plotting/VariablesWidget.cpp \
Options/NotificationsDialog.cpp \
Expand Down Expand Up @@ -143,6 +145,8 @@ HEADERS += Util/backtrace.h \
Component/Transformation.h \
Modeling/DocumentationWidget.h \
Simulation/SimulationDialog.h \
Simulation/SimulationOutputWidget.h \
Simulation/SimulationProcessThread.h \
FMI/ImportFMUDialog.h \
Plotting/VariablesWidget.h \
Options/NotificationsDialog.h \
Expand Down
139 changes: 82 additions & 57 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -968,6 +968,74 @@ void VariablesWidget::findVariableAndUpdateValue(QDomDocument xmlDocument, QHash
}
}

void VariablesWidget::reSimulate(bool showSetup)
{
QModelIndexList indexes = mpVariablesTreeView->selectionModel()->selectedIndexes();
if (indexes.isEmpty()) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
tr("You must select a class to re-simulate."), Helper::ok);
return;
}
QModelIndex index = indexes.at(0);
index = mpVariableTreeProxyModel->mapToSource(index);
VariablesTreeItem *pVariablesTreeItem = static_cast<VariablesTreeItem*>(index.internalPointer());
pVariablesTreeItem = pVariablesTreeItem->rootParent();
SimulationOptions simulationOptions = pVariablesTreeItem->getSimulationOptions();
if (simulationOptions.isValid()) {
simulationOptions.setReSimulate(true);
updateInitXmlFile(simulationOptions);
if (showSetup) {
mpMainWindow->getSimulationDialog()->show(0, true, simulationOptions);
} else {
mpMainWindow->getSimulationDialog()->reSimulate(simulationOptions);
}
} else {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
tr("You cannot re-simulate this class.<br />This is just a result file loaded via menu <b>File->Open Result File(s)</b>."), Helper::ok);
}
}

void VariablesWidget::updateInitXmlFile(SimulationOptions simulationOptions)
{
/* Update the _init.xml file with new values. */
QRegExp resultTypeRegExp("(_res.mat|_res.plt|_res.csv)");
/* open the model_init.xml file for writing */
QString initFileName = QString(simulationOptions.getResultFileName()).replace(resultTypeRegExp, "_init.xml");
QFile initFile(QString(simulationOptions.getWorkingDirectory()).append(QDir::separator()).append(initFileName));
QDomDocument initXmlDocument;
if (initFile.open(QIODevice::ReadOnly)) {
if (initXmlDocument.setContent(&initFile)) {
VariablesTreeItem *pTopVariableTreeItem;
pTopVariableTreeItem = mpVariablesTreeModel->findVariablesTreeItem(simulationOptions.getResultFileName(),
mpVariablesTreeModel->getRootVariablesTreeItem());
if (pTopVariableTreeItem) {
QHash<QString, QHash<QString, QString> > variables;
readVariablesAndUpdateXML(pTopVariableTreeItem, simulationOptions.getResultFileName(), &variables);
findVariableAndUpdateValue(initXmlDocument, variables);
}
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0,
tr("Unable to set the content of QDomDocument from file %1")
.arg(initFile.fileName()), Helper::scriptingKind, Helper::errorLevel, 0,
pMessagesWidget->getMessagesTreeWidget()));
}
initFile.close();
initFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
QTextStream textStream(&initFile);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << initXmlDocument.toString();
initFile.close();
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(initFile.fileName())
.arg(initFile.errorString()), Helper::scriptingKind, Helper::errorLevel, 0,
pMessagesWidget->getMessagesTreeWidget()));
}
}

void VariablesWidget::plotVariables(const QModelIndex &index, qreal curveThickness, int curveStyle, PlotCurve *pPlotCurve,
PlotWindow *pPlotWindow)
{
Expand Down Expand Up @@ -1211,10 +1279,16 @@ void VariablesWidget::showContextMenu(QPoint point)
/* re-simulate action */
QAction *pReSimulateAction = new QAction(QIcon(":/Resources/icons/re-simulate.svg"), Helper::reSimulate, this);
pReSimulateAction->setStatusTip(Helper::reSimulateTip);
connect(pReSimulateAction, SIGNAL(triggered()), this, SLOT(reSimulate()));
connect(pReSimulateAction, SIGNAL(triggered()), this, SLOT(directReSimulate()));
/* re-simulate action */
QAction *pReSimulateSetupAction = new QAction(QIcon(":/Resources/icons/re-simulation-center.svg"), Helper::reSimulateSetup, this);
pReSimulateSetupAction->setStatusTip(Helper::reSimulateSetupTip);
connect(pReSimulateSetupAction, SIGNAL(triggered()), this, SLOT(showReSimulateSetup()));

QMenu menu(this);
menu.addAction(pDeleteResultAction);
menu.addAction(pReSimulateAction);
menu.addAction(pReSimulateSetupAction);
point.setY(point.y() + adjust);
menu.exec(mpVariablesTreeView->mapToGlobal(point));
}
Expand All @@ -1236,61 +1310,12 @@ void VariablesWidget::findVariables()
mpVariablesTreeView->expandAll();
}

void VariablesWidget::reSimulate()
void VariablesWidget::directReSimulate()
{
QModelIndexList indexes = mpVariablesTreeView->selectionModel()->selectedIndexes();
if (indexes.isEmpty()) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
tr("You must select a class to re-simulate."), Helper::ok);
return;
}
QModelIndex index = indexes.at(0);
index = mpVariableTreeProxyModel->mapToSource(index);
VariablesTreeItem *pVariablesTreeItem = static_cast<VariablesTreeItem*>(index.internalPointer());
pVariablesTreeItem = pVariablesTreeItem->rootParent();
SimulationOptions simulationOptions = pVariablesTreeItem->getSimulationOptions();
if (simulationOptions.isValid()) {
simulationOptions.setReSimulate(true);
/* Update the _init.xml file with new values. */
QRegExp resultTypeRegExp("(_res.mat|_res.plt|_res.csv)");
/* open the model_init.xml file for writing */
QString initFileName = QString(simulationOptions.getOutputFileName()).replace(resultTypeRegExp, "_init.xml");
QFile initFile(QString(simulationOptions.getWorkingDirectory()).append(QDir::separator()).append(initFileName));
QDomDocument initXmlDocument;
if (initFile.open(QIODevice::ReadOnly)) {
if (initXmlDocument.setContent(&initFile)) {
VariablesTreeItem *pTopVariableTreeItem;
pTopVariableTreeItem = mpVariablesTreeModel->findVariablesTreeItem(simulationOptions.getOutputFileName(),
mpVariablesTreeModel->getRootVariablesTreeItem());
if (pTopVariableTreeItem) {
QHash<QString, QHash<QString, QString> > variables;
readVariablesAndUpdateXML(pTopVariableTreeItem, simulationOptions.getOutputFileName(), &variables);
findVariableAndUpdateValue(initXmlDocument, variables);
}
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0,
tr("Unable to set the content of QDomDocument from file %1")
.arg(initFile.fileName()), Helper::scriptingKind, Helper::errorLevel, 0,
pMessagesWidget->getMessagesTreeWidget()));
}
initFile.close();
initFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
QTextStream textStream(&initFile);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << initXmlDocument.toString();
initFile.close();
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(new MessagesTreeItem("", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(initFile.fileName())
.arg(initFile.errorString()), Helper::scriptingKind, Helper::errorLevel, 0,
pMessagesWidget->getMessagesTreeWidget()));
}
mpMainWindow->getSimulationDialog()->runSimulationExecutable(simulationOptions);
} else {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
tr("You cannot re-simulate this class.<br />This is just a result file loaded via menu <b>File->Open Result File(s)</b>."), Helper::ok);
}
reSimulate(false);
}

void VariablesWidget::showReSimulateSetup()
{
reSimulate(true);
}
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Plotting/VariablesWidget.h
Expand Up @@ -169,6 +169,8 @@ class VariablesWidget : public QWidget
void readVariablesAndUpdateXML(VariablesTreeItem *pVariablesTreeItem, QString outputFileName,
QHash<QString, QHash<QString, QString> > *variables);
void findVariableAndUpdateValue(QDomDocument xmlDocument, QHash<QString, QHash<QString, QString> > variables);
void reSimulate(bool showSetup);
void updateInitXmlFile(SimulationOptions simulationOptions);
private:
MainWindow *mpMainWindow;
QLineEdit *mpFindVariablesTextBox;
Expand All @@ -188,7 +190,8 @@ public slots:
void updateVariablesTree(QMdiSubWindow *pSubWindow);
void showContextMenu(QPoint point);
void findVariables();
void reSimulate();
void directReSimulate();
void showReSimulateSetup();
};

#endif // VARIABLESWIDGET_H

0 comments on commit 7ee4238

Please sign in to comment.