Skip to content

Commit

Permalink
- Made re-simulate more easily accessible for users.
Browse files Browse the repository at this point in the history
- Added new svg icon for re-simulate.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22866 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 22, 2014
1 parent 6705932 commit 30255aa
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 44 deletions.
15 changes: 15 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1711,6 +1711,15 @@ void MainWindow::openRecentModelWidget()
}
}

/*!
Slot activated when Re-simulateAction triggered signal is raised..\n
Re-simulates the model.
*/
void MainWindow::reSimulateModel()
{
mpVariablesWidget->reSimulate();
}

void MainWindow::addNewPlotWindow()
{
mpPlotWindowContainer->addPlotWindow();
Expand Down Expand Up @@ -2126,6 +2135,10 @@ void MainWindow::createActions()
mpModelSwitcherActions[i]->setVisible(false);
connect(mpModelSwitcherActions[i], SIGNAL(triggered()), this, SLOT(openRecentModelWidget()));
}
// resimulate action
mpReSimulateModelAction = new QAction(QIcon(":/Resources/icons/re-simulate.svg"), Helper::reSimulate, this);
mpReSimulateModelAction->setStatusTip(Helper::reSimulateTip);
connect(mpReSimulateModelAction, SIGNAL(triggered()), SLOT(reSimulateModel()));
// 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 @@ -2422,6 +2435,8 @@ void MainWindow::createToolbars()
mpPlotToolBar->setAllowedAreas(Qt::TopToolBarArea);
mpPlotToolBar->setEnabled(false);
// add actions to Plot Toolbar
mpPlotToolBar->addAction(mpReSimulateModelAction);
mpPlotToolBar->addSeparator();
mpPlotToolBar->addAction(mpNewPlotWindowAction);
mpPlotToolBar->addAction(mpNewParametricPlotWindowAction);
mpPlotToolBar->addAction(mpClearPlotWindowAction);
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -268,6 +268,7 @@ class MainWindow : public QMainWindow
// Model Switcher Toolbar Actions
QAction *mpModelSwitcherActions[MaxRecentFiles];
// Plot Toolbar Actions
QAction *mpReSimulateModelAction;
QAction *mpNewPlotWindowAction;
QAction *mpNewParametricPlotWindowAction;
QAction *mpClearPlotWindowAction;
Expand Down Expand Up @@ -331,6 +332,7 @@ public slots:
void openAboutOMEdit();
void toggleShapesButton();
void openRecentModelWidget();
void reSimulateModel();
void addNewPlotWindow();
void addNewParametricPlotWindow();
void clearPlotWindow();
Expand Down
31 changes: 9 additions & 22 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3139,32 +3139,24 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
bool enabled, modelica, text, xml;
ModelWidget *pModelWidget;
LibraryTreeNode *pLibraryTreeNode;
if (pSubWindow)
{
if (pSubWindow) {
enabled = true;
pModelWidget = qobject_cast<ModelWidget*>(pSubWindow->widget());
pLibraryTreeNode = pModelWidget->getLibraryTreeNode();
if (pLibraryTreeNode->getLibraryType() == LibraryTreeNode::Modelica)
{
if (pLibraryTreeNode->getLibraryType() == LibraryTreeNode::Modelica) {
modelica = true;
text = false;
xml = false;
}
else if (pLibraryTreeNode->getLibraryType() == LibraryTreeNode::Text)
{
} else if (pLibraryTreeNode->getLibraryType() == LibraryTreeNode::Text) {
modelica = false;
text = true;
xml = false;
}
else
{
} else {
modelica = false;
text = false;
xml = true;
}
}
else
{
} else {
enabled = false;
modelica = false;
text = false;
Expand Down Expand Up @@ -3194,18 +3186,15 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
getMainWindow()->getExportAsImageAction()->setEnabled(enabled && modelica);
getMainWindow()->getPrintModelAction()->setEnabled(enabled);
/* disable the save actions if class is a system library class. */
if (pModelWidget)
{
if (pModelWidget->getLibraryTreeNode()->isSystemLibrary())
{
if (pModelWidget) {
if (pModelWidget->getLibraryTreeNode()->isSystemLibrary()) {
getMainWindow()->getSaveAction()->setEnabled(false);
getMainWindow()->getSaveAsAction()->setEnabled(false);
getMainWindow()->getSaveAllAction()->setEnabled(false);
}
}
/* enable/disable the find/replace and goto line actions depending on the text editor visibility. */
if (pModelWidget)
{
if (pModelWidget) {
if (pModelWidget->getLibraryTreeNode()->getLibraryType() == LibraryTreeNode::Modelica && pModelWidget->getModelicaTextEditor()->isVisible())
enabled = true;
else if (pModelWidget->getLibraryTreeNode()->getLibraryType() == LibraryTreeNode::Text && pModelWidget->getTextEditor()->isVisible())
Expand All @@ -3214,9 +3203,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
enabled = true;
else
enabled = false;
}
else
{
} else {
enabled = false;
}
getMainWindow()->getFindReplaceAction()->setEnabled(enabled);
Expand Down
55 changes: 35 additions & 20 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -211,6 +211,19 @@ VariablesTreeItem* VariablesTreeItem::parent()
return mpParentVariablesTreeItem;
}

VariablesTreeItem* VariablesTreeItem::rootParent()
{
// since we have global mpRootVariablesTreeItem so we return one level down from this function in order to get the top level item.
VariablesTreeItem *pVariablesTreeItem, *pVariablesTreeItem1;
pVariablesTreeItem = this;
pVariablesTreeItem1 = this;
while (pVariablesTreeItem->mpParentVariablesTreeItem) {
pVariablesTreeItem1 = pVariablesTreeItem;
pVariablesTreeItem = pVariablesTreeItem->mpParentVariablesTreeItem;
}
return pVariablesTreeItem1;
}

VariablesTreeModel::VariablesTreeModel(VariablesTreeView *pVariablesTreeView)
: QAbstractItemModel(pVariablesTreeView)
{
Expand Down Expand Up @@ -1189,10 +1202,8 @@ void VariablesWidget::showContextMenu(QPoint point)
pDeleteResultAction->setStatusTip(tr("Delete the result"));
connect(pDeleteResultAction, SIGNAL(triggered()), mpVariablesTreeModel, SLOT(removeVariableTreeItem()));
/* re-simulate action */
QAction *pReSimulateAction = new QAction(QIcon(":/Resources/icons/simulate.svg"), tr("Re-simulate"), this);
pReSimulateAction->setData(pVariablesTreeItem->getSimulationOptions());
pReSimulateAction->setStatusTip(Helper::simulateTip);
pReSimulateAction->setEnabled(pVariablesTreeItem->getSimulationOptions().isValid());
QAction *pReSimulateAction = new QAction(QIcon(":/Resources/icons/re-simulate.svg"), Helper::reSimulate, this);
pReSimulateAction->setStatusTip(Helper::reSimulateTip);
connect(pReSimulateAction, SIGNAL(triggered()), this, SLOT(reSimulate()));
QMenu menu(this);
menu.addAction(pDeleteResultAction);
Expand Down Expand Up @@ -1220,33 +1231,36 @@ void VariablesWidget::findVariables()

void VariablesWidget::reSimulate()
{
QAction *pAction = qobject_cast<QAction*>(sender());
if (pAction)
{
SimulationOptions simulationOptions = pAction->data().value<SimulationOptions>();
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))
{
if (initFile.open(QIODevice::ReadOnly)) {
if (initXmlDocument.setContent(&initFile)) {
VariablesTreeItem *pTopVariableTreeItem;
pTopVariableTreeItem = mpVariablesTreeModel->findVariablesTreeItem(simulationOptions.getOutputFileName(),
mpVariablesTreeModel->getRootVariablesTreeItem());
if (pTopVariableTreeItem)
{
if (pTopVariableTreeItem) {
QHash<QString, QHash<QString, QString> > variables;
readVariablesAndUpdateXML(pTopVariableTreeItem, simulationOptions.getOutputFileName(), &variables);
findVariableAndUpdateValue(initXmlDocument, variables);
}
}
else
{
} 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")
Expand All @@ -1258,15 +1272,16 @@ void VariablesWidget::reSimulate()
QTextStream textStream(&initFile);
textStream << initXmlDocument.toString();
initFile.close();
}
else
{
} 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);
}
}
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.h
Expand Up @@ -66,14 +66,15 @@ class VariablesTreeItem
void setSimulationOptions(SimulationOptions simulationOptions) {mSimulationOptions = simulationOptions;}
QIcon getVariableTreeItemIcon(QString name) const;
void insertChild(int position, VariablesTreeItem *pVariablesTreeItem);
VariablesTreeItem *child(int row);
VariablesTreeItem* child(int row);
void removeChildren();
void removeChild(VariablesTreeItem *pVariablesTreeItem);
int columnCount() const;
bool setData(int column, const QVariant &value, int role = Qt::EditRole);
QVariant data(int column, int role = Qt::DisplayRole) const;
int row() const;
VariablesTreeItem *parent();
VariablesTreeItem* parent();
VariablesTreeItem* rootParent();
private:
QList<VariablesTreeItem*> mChildren;
VariablesTreeItem *mpParentVariablesTreeItem;
Expand Down Expand Up @@ -160,6 +161,7 @@ class VariablesWidget : public QWidget
MainWindow* getMainWindow() {return mpMainWindow;}
VariableTreeProxyModel* getVariableTreeProxyModel() {return mpVariableTreeProxyModel;}
VariablesTreeModel* getVariablesTreeModel() {return mpVariablesTreeModel;}
VariablesTreeView* getVariablesTreeView() {return mpVariablesTreeView;}
void insertVariablesItemsToTree(QString fileName, QString filePath, QStringList variablesList, SimulationOptions simulationOptions);
void variablesUpdated();
void updateVariablesTreeHelper(QMdiSubWindow *pSubWindow);
Expand Down
71 changes: 71 additions & 0 deletions OMEdit/OMEditGUI/Resources/icons/re-simulate.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 @@ -187,6 +187,8 @@ QString Helper::unloadXMLTip;
QString Helper::refresh;
QString Helper::simulate;
QString Helper::simulateTip;
QString Helper::reSimulate;
QString Helper::reSimulateTip;
QString Helper::simulateWithAlgorithmicDebugger;
QString Helper::simulateWithAlgorithmicDebuggerTip;
QString Helper::simulationSetup;
Expand Down Expand Up @@ -348,6 +350,8 @@ void Helper::initHelperVariables()
Helper::refresh = tr("Refresh");
Helper::simulate = tr("Simulate");
Helper::simulateTip = tr("Simulate the Modelica class");
Helper::reSimulate = tr("Re-simulate");
Helper::reSimulateTip = tr("Re-simulate the Modelica class");
Helper::simulateWithAlgorithmicDebugger = tr("Simulate with Algorithmic Debugger");
Helper::simulateWithAlgorithmicDebuggerTip = tr("Simulate the Modelica class with Algorithmic Debugger");
Helper::simulationSetup = tr("Simulation Setup");
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Util/Helper.h
Expand Up @@ -189,6 +189,8 @@ class Helper : public QObject
static QString refresh;
static QString simulate;
static QString simulateTip;
static QString reSimulate;
static QString reSimulateTip;
static QString simulateWithAlgorithmicDebugger;
static QString simulateWithAlgorithmicDebuggerTip;
static QString simulationSetup;
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/resource_omedit.qrc
Expand Up @@ -92,6 +92,7 @@
<file>Resources/icons/omplot.png</file>
<file>Resources/icons/parametric-plot-window.svg</file>
<file>Resources/icons/plot-window.svg</file>
<file>Resources/icons/re-simulate.svg</file>
<file>Resources/icons/export-fmu.svg</file>
<file>Resources/icons/import-fmu.svg</file>
<file>Resources/icons/libraries.png</file>
Expand Down

0 comments on commit 30255aa

Please sign in to comment.