Skip to content

Commit

Permalink
Fixes #3690. Added interval in the simulation dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 19, 2016
1 parent b63cdc0 commit b7defb4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
91 changes: 58 additions & 33 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -134,13 +134,27 @@ void SimulationDialog::setUpForm()
mpStartTimeTextBox = new QLineEdit("0");
mpStopTimeLabel = new Label(tr("Stop Time:"));
mpStopTimeTextBox = new QLineEdit("1");
// Output Interval
mpNumberofIntervalsRadioButton = new QRadioButton(tr("Number of Intervals:"));
mpNumberofIntervalsRadioButton->setChecked(true);
mpNumberofIntervalsSpinBox = new QSpinBox;
mpNumberofIntervalsSpinBox->setRange(0, std::numeric_limits<int>::max());
mpNumberofIntervalsSpinBox->setSingleStep(100);
mpNumberofIntervalsSpinBox->setValue(500);
// Interval
mpIntervalRadioButton = new QRadioButton(tr("Interval:"));
mpIntervalTextBox = new QLineEdit("0.002");
// set the layout for simulation interval groupbox
QGridLayout *pSimulationIntervalGridLayout = new QGridLayout;
pSimulationIntervalGridLayout->setColumnStretch(1, 1);
pSimulationIntervalGridLayout->addWidget(mpStartTimeLabel, 0, 0);
pSimulationIntervalGridLayout->addWidget(mpStartTimeTextBox, 0, 1);
pSimulationIntervalGridLayout->addWidget(mpStopTimeLabel, 1, 0);
pSimulationIntervalGridLayout->addWidget(mpStopTimeTextBox, 1, 1);
pSimulationIntervalGridLayout->addWidget(mpNumberofIntervalsRadioButton, 2, 0);
pSimulationIntervalGridLayout->addWidget(mpNumberofIntervalsSpinBox, 2, 1);
pSimulationIntervalGridLayout->addWidget(mpIntervalRadioButton, 3, 0);
pSimulationIntervalGridLayout->addWidget(mpIntervalTextBox, 3, 1);
mpSimulationIntervalGroupBox->setLayout(pSimulationIntervalGridLayout);
// Integration
mpIntegrationGroupBox = new QGroupBox(tr("Integration"));
Expand Down Expand Up @@ -258,12 +272,6 @@ void SimulationDialog::setUpForm()
mpSimulationTabWidget->addTab(mpGeneralTab, Helper::general);
// Output Tab
mpOutputTab = new QWidget;
// Output Interval
mpNumberofIntervalLabel = new Label(tr("Number of Intervals:"));
mpNumberofIntervalsSpinBox = new QSpinBox;
mpNumberofIntervalsSpinBox->setRange(0, std::numeric_limits<int>::max());
mpNumberofIntervalsSpinBox->setSingleStep(100);
mpNumberofIntervalsSpinBox->setValue(500);
// Output Format
mpOutputFormatLabel = new Label(tr("Output Format:"));
mpOutputFormatComboBox = new QComboBox;
Expand Down Expand Up @@ -294,21 +302,19 @@ void SimulationDialog::setUpForm()
// set Output Tab Layout
QGridLayout *pOutputTabLayout = new QGridLayout;
pOutputTabLayout->setAlignment(Qt::AlignTop);
pOutputTabLayout->addWidget(mpNumberofIntervalLabel, 0, 0);
pOutputTabLayout->addWidget(mpNumberofIntervalsSpinBox, 0, 1, 1, 2);
pOutputTabLayout->addWidget(mpOutputFormatLabel, 1, 0);
pOutputTabLayout->addWidget(mpOutputFormatComboBox, 1, 1, 1, 2);
pOutputTabLayout->addWidget(mpFileNameLabel, 2, 0);
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);
pOutputTabLayout->addWidget(mpOutputFormatLabel, 0, 0);
pOutputTabLayout->addWidget(mpOutputFormatComboBox, 0, 1, 1, 2);
pOutputTabLayout->addWidget(mpFileNameLabel, 1, 0);
pOutputTabLayout->addWidget(mpFileNameTextBox, 1, 1, 1, 2);
pOutputTabLayout->addWidget(mpResultFileNameLabel, 2, 0);
pOutputTabLayout->addWidget(mpResultFileNameTextBox, 2, 1);
pOutputTabLayout->addWidget(mpResultFileName, 2, 2);
pOutputTabLayout->addWidget(mpVariableFilterLabel, 3, 0);
pOutputTabLayout->addWidget(mpVariableFilterTextBox, 3, 1, 1, 2);
pOutputTabLayout->addWidget(mpProtectedVariablesCheckBox, 4, 0, 1, 3);
pOutputTabLayout->addWidget(mpEquidistantTimeGridCheckBox, 5, 0, 1, 3);
pOutputTabLayout->addWidget(mpStoreVariablesAtEventsCheckBox, 6, 0, 1, 3);
pOutputTabLayout->addWidget(mpShowGeneratedFilesCheckBox, 7, 0, 1, 3);
mpOutputTab->setLayout(pOutputTabLayout);
// add Output Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpOutputTab, Helper::output);
Expand Down Expand Up @@ -520,6 +526,7 @@ void SimulationDialog::setUpForm()
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
mpStartTimeTextBox->setValidator(pDoubleValidator);
mpStopTimeTextBox->setValidator(pDoubleValidator);
mpIntervalTextBox->setValidator(pDoubleValidator);
mpToleranceTextBox->setValidator(pDoubleValidator);
// Create the buttons
mpSimulateButton = new QPushButton(Helper::simulate);
Expand Down Expand Up @@ -549,16 +556,16 @@ void SimulationDialog::setUpForm()
*/
bool SimulationDialog::validate()
{
if (mpStartTimeTextBox->text().isEmpty())
{
if (mpStartTimeTextBox->text().isEmpty()) {
mpStartTimeTextBox->setText("0");
}
if (mpStopTimeTextBox->text().isEmpty())
{
if (mpStopTimeTextBox->text().isEmpty()) {
mpStopTimeTextBox->setText("1");
}
if (mpStartTimeTextBox->text().toDouble() > mpStopTimeTextBox->text().toDouble())
{
if (mpIntervalRadioButton->isChecked() && mpIntervalTextBox->text().isEmpty()) {
mpIntervalTextBox->setText("0.002");
}
if (mpStartTimeTextBox->text().toDouble() > mpStopTimeTextBox->text().toDouble()) {
QMessageBox::critical(mpMainWindow, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::SIMULATION_STARTTIME_LESSTHAN_STOPTIME), Helper::ok);
return false;
Expand Down Expand Up @@ -586,6 +593,7 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
mpStopTimeTextBox->setText(QString::number(simulationOptions.stopTime));
mpToleranceTextBox->setText(QString::number(simulationOptions.tolerance));
mpNumberofIntervalsSpinBox->setValue(simulationOptions.numberOfIntervals);
mpIntervalTextBox->setText(QString::number(simulationOptions.interval));
}
mpCflagsTextBox->setEnabled(true);
mpNumberofIntervalsSpinBox->setEnabled(true);
Expand Down Expand Up @@ -763,7 +771,11 @@ SimulationOptions SimulationDialog::createSimulationOptions()
simulationOptions.setNumberofIntervals(mpNumberofIntervalsSpinBox->value());
qreal startTime = mpStartTimeTextBox->text().toDouble();
qreal stopTime = mpStopTimeTextBox->text().toDouble();
simulationOptions.setStepSize((stopTime - startTime)/mpNumberofIntervalsSpinBox->value());
if (mpNumberofIntervalsRadioButton->isChecked()) {
simulationOptions.setStepSize((stopTime - startTime)/mpNumberofIntervalsSpinBox->value());
} else {
simulationOptions.setStepSize(mpIntervalTextBox->text().toDouble());
}
simulationOptions.setOutputFormat(mpOutputFormatComboBox->currentText());
if (!mpFileNameTextBox->text().isEmpty()) {
simulationOptions.setFileNamePrefix(mpFileNameTextBox->text());
Expand Down Expand Up @@ -1031,10 +1043,14 @@ void SimulationDialog::saveSimulationOptions()
newExperimentAnnotation.append("Tolerance=").append(mpToleranceTextBox->text()).append(",");
double interval, stopTime, startTime;
int numberOfIntervals;
stopTime = mpStopTimeTextBox->text().toDouble();
startTime = mpStartTimeTextBox->text().toDouble();
numberOfIntervals = mpNumberofIntervalsSpinBox->value();
interval = (numberOfIntervals == 0) ? 0 : (stopTime - startTime) / numberOfIntervals;
if (mpNumberofIntervalsRadioButton->isChecked()) {
stopTime = mpStopTimeTextBox->text().toDouble();
startTime = mpStartTimeTextBox->text().toDouble();
numberOfIntervals = mpNumberofIntervalsSpinBox->value();
interval = (numberOfIntervals == 0) ? 0 : (stopTime - startTime) / numberOfIntervals;
} else {
interval = mpIntervalTextBox->text().toDouble();
}
newExperimentAnnotation.append("Interval=").append(QString::number(interval));
newExperimentAnnotation.append(")");
// if we have ModelWidget for class then put the change on undo stack.
Expand Down Expand Up @@ -1197,7 +1213,16 @@ void SimulationDialog::simulate()
/* build the simulation parameters */
simulationParameters.append("startTime=").append(mpStartTimeTextBox->text());
simulationParameters.append(", stopTime=").append(mpStopTimeTextBox->text());
simulationParameters.append(", numberOfIntervals=").append(QString::number(mpNumberofIntervalsSpinBox->value()));
QString numberOfIntervals;
if (mpNumberofIntervalsRadioButton->isChecked()) {
numberOfIntervals = QString::number(mpNumberofIntervalsSpinBox->value());
} else {
qreal startTime = mpStartTimeTextBox->text().toDouble();
qreal stopTime = mpStopTimeTextBox->text().toDouble();
qreal interval = mpIntervalTextBox->text().toDouble();
numberOfIntervals = QString::number((stopTime - startTime) / interval);
}
simulationParameters.append(", numberOfIntervals=").append(numberOfIntervals);
simulationParameters.append(", method=").append("\"").append(mpMethodComboBox->currentText()).append("\"");
if (!mpToleranceTextBox->text().isEmpty()) {
simulationParameters.append(", tolerance=").append(mpToleranceTextBox->text());
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.h
Expand Up @@ -90,6 +90,10 @@ class SimulationDialog : public QDialog
QLineEdit *mpStartTimeTextBox;
Label *mpStopTimeLabel;
QLineEdit *mpStopTimeTextBox;
QRadioButton *mpNumberofIntervalsRadioButton;
QSpinBox *mpNumberofIntervalsSpinBox;
QRadioButton *mpIntervalRadioButton;
QLineEdit *mpIntervalTextBox;
QGroupBox *mpIntegrationGroupBox;
Label *mpMethodLabel;
QComboBox *mpMethodComboBox;
Expand Down Expand Up @@ -118,8 +122,6 @@ class SimulationDialog : public QDialog
QCheckBox *mpLaunchAlgorithmicDebuggerCheckBox;
// Output Tab
QWidget *mpOutputTab;
Label *mpNumberofIntervalLabel;
QSpinBox *mpNumberofIntervalsSpinBox;
Label *mpOutputFormatLabel;
QComboBox *mpOutputFormatComboBox;
Label *mpFileNameLabel;
Expand Down

0 comments on commit b7defb4

Please sign in to comment.