Skip to content

Commit

Permalink
#3352 - Allow creating new result file when doing re-simulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 12, 2015
1 parent 2ac3e23 commit 146601a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 29 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Editors/TextEditor.cpp
Expand Up @@ -91,7 +91,7 @@ void TextEditor::showContextMenu(QPoint point)
void TextEditor::contentsHasChanged(int position, int charsRemoved, int charsAdded)
{
Q_UNUSED(position);
if (mpModelWidget->isVisible()) {
if (mpModelWidget && mpModelWidget->isVisible()) {
if (charsRemoved == 0 && charsAdded == 0) {
return;
}
Expand Down
27 changes: 14 additions & 13 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -435,17 +435,19 @@ void VariablesTreeModel::insertVariablesItems(QString fileName, QString filePath
mpRootVariablesTreeItem->insertChild(row, pTopVariablesTreeItem);
endInsertRows();
/* open the model_init.xml file for reading */
QString initFileName = QString(fileName).replace(resultTypeRegExp, "_init.xml");
QFile initFile(QString(filePath).append(QDir::separator()).append(initFileName));
if (initFile.open(QIODevice::ReadOnly)) {
QXmlStreamReader initXmlReader(&initFile);
parseInitXml(initXmlReader);
initFile.close();
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(initFile.fileName())
.arg(initFile.errorString()),Helper::scriptingKind, Helper::warningLevel));
if (simulationOptions.isValid()) {
QString initFileName = QString(simulationOptions.getOutputFileName()).append("_init.xml");
QFile initFile(QString(filePath).append(QDir::separator()).append(initFileName));
if (initFile.open(QIODevice::ReadOnly)) {
QXmlStreamReader initXmlReader(&initFile);
parseInitXml(initXmlReader);
initFile.close();
} else {
MessagesWidget *pMessagesWidget = mpVariablesTreeView->getVariablesWidget()->getMainWindow()->getMessagesWidget();
pMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0,
GUIMessages::getMessage(GUIMessages::ERROR_OPENING_FILE).arg(initFile.fileName())
.arg(initFile.errorString()), Helper::scriptingKind, Helper::errorLevel));
}
}
/* open the .mat file */
ModelicaMatReader matReader;
Expand Down Expand Up @@ -1021,9 +1023,8 @@ void VariablesWidget::reSimulate(bool showSetup)
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");
QString initFileName = QString(simulationOptions.getOutputFileName()).append("_init.xml");
QFile initFile(QString(simulationOptions.getWorkingDirectory()).append(QDir::separator()).append(initFileName));
QDomDocument initXmlDocument;
if (initFile.open(QIODevice::ReadOnly)) {
Expand Down
55 changes: 42 additions & 13 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -273,10 +273,15 @@ void SimulationDialog::setUpForm()
mpOutputFormatComboBox = new QComboBox;
mpOutputFormatComboBox->addItems(Helper::ModelicaSimulationOutputFormats.toLower().split(","));
// Output filename
mpFileNameLabel = new Label(tr("File Name (Optional):"));
mpFileNameLabel = new Label(tr("File Name Prefix (Optional):"));
mpFileNameTextBox = new QLineEdit;
mpFileNameTextBox->setToolTip(tr("The name is used as a prefix for the output files. This is just a name not the path.\n"
"If you want to change the output path then update the working directory in Options/Preferences."));
mpResultFileNameLabel = new Label(tr("Result File (Optional):"));
mpResultFileNameTextBox = new QLineEdit;
mpResultFileName = new Label;
connect(mpResultFileNameTextBox, SIGNAL(textEdited(QString)), SLOT(resultFileNameChanged(QString)));
connect(mpOutputFormatComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(resultFileNameChanged(QString)));
// Variable filter
mpVariableFilterLabel = new Label(tr("Variable Filter (Optional):"));
mpVariableFilterTextBox = new QLineEdit(".*");
Expand All @@ -294,17 +299,20 @@ void SimulationDialog::setUpForm()
QGridLayout *pOutputTabLayout = new QGridLayout;
pOutputTabLayout->setAlignment(Qt::AlignTop);
pOutputTabLayout->addWidget(mpNumberofIntervalLabel, 0, 0);
pOutputTabLayout->addWidget(mpNumberofIntervalsSpinBox, 0, 1);
pOutputTabLayout->addWidget(mpNumberofIntervalsSpinBox, 0, 1, 1, 2);
pOutputTabLayout->addWidget(mpOutputFormatLabel, 1, 0);
pOutputTabLayout->addWidget(mpOutputFormatComboBox, 1, 1);
pOutputTabLayout->addWidget(mpOutputFormatComboBox, 1, 1, 1, 2);
pOutputTabLayout->addWidget(mpFileNameLabel, 2, 0);
pOutputTabLayout->addWidget(mpFileNameTextBox, 2, 1);
pOutputTabLayout->addWidget(mpVariableFilterLabel, 3, 0);
pOutputTabLayout->addWidget(mpVariableFilterTextBox, 3, 1);
pOutputTabLayout->addWidget(mpProtectedVariablesCheckBox, 4, 0, 1, 2);
pOutputTabLayout->addWidget(mpEquidistantTimeGridCheckBox, 5, 0, 1, 2);
pOutputTabLayout->addWidget(mpStoreVariablesAtEventsCheckBox, 6, 0, 1, 2);
pOutputTabLayout->addWidget(mpShowGeneratedFilesCheckBox, 7, 0, 1, 2);
pOutputTabLayout->addWidget(mpFileNameTextBox, 2, 1, 1, 2);
pOutputTabLayout->addWidget(mpResultFileNameLabel, 3, 0);
pOutputTabLayout->addWidget(mpResultFileNameTextBox, 3, 1);
pOutputTabLayout->addWidget(mpResultFileName, 3, 2);
pOutputTabLayout->addWidget(mpVariableFilterLabel, 4, 0);
pOutputTabLayout->addWidget(mpVariableFilterTextBox, 4, 1, 1, 2);
pOutputTabLayout->addWidget(mpProtectedVariablesCheckBox, 5, 0, 1, 3);
pOutputTabLayout->addWidget(mpEquidistantTimeGridCheckBox, 6, 0, 1, 3);
pOutputTabLayout->addWidget(mpStoreVariablesAtEventsCheckBox, 7, 0, 1, 3);
pOutputTabLayout->addWidget(mpShowGeneratedFilesCheckBox, 8, 0, 1, 3);
mpOutputTab->setLayout(pOutputTabLayout);
// add Output Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpOutputTab, Helper::output);
Expand Down Expand Up @@ -556,7 +564,6 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
}
mpCflagsTextBox->setEnabled(true);
mpNumberofIntervalsSpinBox->setEnabled(true);
mpOutputFormatComboBox->setEnabled(true);
mpFileNameTextBox->setEnabled(true);
mpSaveSimulationCheckbox->setEnabled(true);
mpSimulateButton->setText(Helper::simulate);
Expand Down Expand Up @@ -603,8 +610,6 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
mpBuildOnlyCheckBox->setChecked(simulationOptions.getBuildOnly());
// Output Interval
mpNumberofIntervalsSpinBox->setValue(simulationOptions.getNumberofIntervals());
// Output Format
mpOutputFormatComboBox->setDisabled(true);
// Output filename
mpFileNameTextBox->setDisabled(true);
// Variable filter
Expand Down Expand Up @@ -740,6 +745,7 @@ SimulationOptions SimulationDialog::createSimulationOptions()
} else if (mClassName.contains('\'')) {
simulationOptions.setFileNamePrefix("_omcQuot_" + QByteArray(mClassName.toStdString().c_str()).toHex());
}
simulationOptions.setResultFileName(mpResultFileName->text());
simulationOptions.setVariableFilter(mpVariableFilterTextBox->text());
simulationOptions.setProtectedVariables(mpProtectedVariablesCheckBox->isChecked());
simulationOptions.setEquidistantTimeGrid(mpEquidistantTimeGridCheckBox->isChecked());
Expand Down Expand Up @@ -786,6 +792,7 @@ SimulationOptions SimulationDialog::createSimulationOptions()
.arg("solver").arg(simulationOptions.getMethod())
.arg("outputFormat").arg(simulationOptions.getOutputFormat())
.arg("variableFilter").arg(simulationOptions.getVariableFilter()));
simulationFlags.append(QString("-r=").append(simulationOptions.getResultFileName()));
// dassl options
if (mpDasslOptionsGroupBox->isEnabled()) {
// dassl jacobian
Expand Down Expand Up @@ -1173,3 +1180,25 @@ void SimulationDialog::simulate()
}
}
}

/*!
* \brief SimulationDialog::resultFileNameChanged
* \param text
* Slot activated when mpResultFileNameTextBox textEdited OR mpOutputFormatComboBox currentIndexChanged signal is raised.\n
* Sets the result file name label.
*/
void SimulationDialog::resultFileNameChanged(QString text)
{
QLineEdit *pLineEditSender = qobject_cast<QLineEdit*>(sender());
QComboBox *pComboBoxSender = qobject_cast<QComboBox*>(sender());

if (pLineEditSender) {
if (text.isEmpty()) {
mpResultFileName->clear();
} else {
mpResultFileName->setText(QString("%1_res.%2").arg(text).arg(mpOutputFormatComboBox->currentText()));
}
} else if (pComboBoxSender && !mpResultFileNameTextBox->text().isEmpty()) {
mpResultFileName->setText(QString("%1_res.%2").arg(mpResultFileNameTextBox->text()).arg(mpOutputFormatComboBox->currentText()));
}
}
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.h
Expand Up @@ -125,6 +125,9 @@ class SimulationDialog : public QDialog
QComboBox *mpOutputFormatComboBox;
Label *mpFileNameLabel;
QLineEdit *mpFileNameTextBox;
Label *mpResultFileNameLabel;
QLineEdit *mpResultFileNameTextBox;
Label *mpResultFileName;
Label *mpVariableFilterLabel;
QLineEdit *mpVariableFilterTextBox;
QCheckBox *mpProtectedVariablesCheckBox;
Expand Down Expand Up @@ -214,6 +217,8 @@ public slots:
void browseEquationSystemInitializationFile();
void showArchivedSimulation(QTreeWidgetItem *pTreeWidgetItem);
void simulate();
private slots:
void resultFileNameChanged(QString text);
};

#endif // SIMULATIONDIALOG_H
5 changes: 4 additions & 1 deletion OMEdit/OMEditGUI/Simulation/SimulationOptions.h
Expand Up @@ -66,6 +66,7 @@ class SimulationOptions
setStepSize(0.002);
setOutputFormat("mat");
setFileNamePrefix("");
setResultFileName("");
setVariableFilter("");
setProtectedVariables(false);
setEquidistantTimeGrid(true);
Expand Down Expand Up @@ -149,7 +150,8 @@ class SimulationOptions
void setFileNamePrefix(QString fileNamePrefix) {mFileNamePrefix = fileNamePrefix;}
QString getFileNamePrefix() {return mFileNamePrefix;}
QString getOutputFileName() const {return mFileNamePrefix.isEmpty() ? mClassName : mFileNamePrefix;}
QString getResultFileName() {return getOutputFileName() + "_res." + mOutputFormat;}
void setResultFileName(QString resultFileName) {mResultFileName = resultFileName;}
QString getResultFileName() {return mResultFileName.isEmpty() ? getOutputFileName() + "_res." + mOutputFormat : mResultFileName;}
void setVariableFilter(QString variableFilter) {mVariableFilter = variableFilter;}
QString getVariableFilter() {return mVariableFilter.isEmpty() ? ".*" : mVariableFilter;}
void setProtectedVariables(bool protectedVariables) {mProtectedVariables = protectedVariables;}
Expand Down Expand Up @@ -254,6 +256,7 @@ class SimulationOptions
qreal mStepSize;
QString mOutputFormat;
QString mFileNamePrefix;
QString mResultFileName;
QString mVariableFilter;
bool mProtectedVariables;
bool mEquidistantTimeGrid;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -75,7 +75,7 @@ QString Helper::modelicaFileFormat = "text/uri-list";
qreal Helper::shapesStrokeWidth = 2.0;
int Helper::headingFontSize = 18;
QString Helper::ModelicaInitializationMethods = ",none,symbolic";
QString Helper::ModelicaSimulationOutputFormats = "mat,plt,csv,empty";
QString Helper::ModelicaSimulationOutputFormats = "mat,plt,csv";
QString Helper::clockOptions = ",RT,CYC,CPU";
QString Helper::linearSolvers = ",lapack";
QString Helper::nonLinearSolvers = ",hybrid,kinsol,newton";
Expand Down

0 comments on commit 146601a

Please sign in to comment.