Skip to content

Commit

Permalink
Enhancements for #3690.
Browse files Browse the repository at this point in the history
Calculate "Number of Intervals" and "Interval" automatically. Enable/disable fields depending on the option selected.
  • Loading branch information
adeas31 committed Feb 21, 2016
1 parent e797eab commit 2a62fa6
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 23 deletions.
96 changes: 73 additions & 23 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -137,13 +137,16 @@ void SimulationDialog::setUpForm()
// Output Interval
mpNumberofIntervalsRadioButton = new QRadioButton(tr("Number of Intervals:"));
mpNumberofIntervalsRadioButton->setChecked(true);
connect(mpNumberofIntervalsRadioButton, SIGNAL(toggled(bool)), SLOT(numberOfIntervalsRadioToggled(bool)));
mpNumberofIntervalsSpinBox = new QSpinBox;
mpNumberofIntervalsSpinBox->setRange(0, std::numeric_limits<int>::max());
mpNumberofIntervalsSpinBox->setSingleStep(100);
mpNumberofIntervalsSpinBox->setValue(500);
// Interval
mpIntervalRadioButton = new QRadioButton(tr("Interval:"));
connect(mpIntervalRadioButton, SIGNAL(toggled(bool)), SLOT(intervalRadioToggled(bool)));
mpIntervalTextBox = new QLineEdit("0.002");
mpIntervalTextBox->setEnabled(false);
// set the layout for simulation interval groupbox
QGridLayout *pSimulationIntervalGridLayout = new QGridLayout;
pSimulationIntervalGridLayout->setColumnStretch(1, 1);
Expand Down Expand Up @@ -596,7 +599,6 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
mpIntervalTextBox->setText(QString::number(simulationOptions.interval));
}
mpCflagsTextBox->setEnabled(true);
mpNumberofIntervalsSpinBox->setEnabled(true);
mpFileNameTextBox->setEnabled(true);
mpSaveSimulationCheckbox->setEnabled(true);
mpSimulateButton->setText(Helper::simulate);
Expand Down Expand Up @@ -641,8 +643,10 @@ void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions sim
mpLaunchAlgorithmicDebuggerCheckBox->setChecked(simulationOptions.getLaunchAlgorithmicDebugger());
// build only
mpBuildOnlyCheckBox->setChecked(simulationOptions.getBuildOnly());
// Output Interval
// Number Of Intervals
mpNumberofIntervalsSpinBox->setValue(simulationOptions.getNumberofIntervals());
// Interval
mpIntervalTextBox->setText(QString::number(simulationOptions.getStepSize()));
// Output filename
mpFileNameTextBox->setDisabled(true);
// Variable filter
Expand Down Expand Up @@ -1118,6 +1122,42 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
}
}

/*!
* \brief SimulationDialog::numberOfIntervalsRadioToggled
* \param toggle
*/
void SimulationDialog::numberOfIntervalsRadioToggled(bool toggle)
{
if (toggle) {
mpNumberofIntervalsSpinBox->setEnabled(true);
mpIntervalTextBox->setEnabled(false);
if (validate()) {
qreal startTime = mpStartTimeTextBox->text().toDouble();
qreal stopTime = mpStopTimeTextBox->text().toDouble();
qreal interval = mpIntervalTextBox->text().toDouble();
qreal numberOfIntervals = (stopTime - startTime) / interval;
mpNumberofIntervalsSpinBox->setValue(numberOfIntervals);
}
}
}

/*!
* \brief SimulationDialog::intervalRadioToggled
* \param toggle
*/
void SimulationDialog::intervalRadioToggled(bool toggle)
{
if (toggle) {
mpNumberofIntervalsSpinBox->setEnabled(false);
mpIntervalTextBox->setEnabled(true);
if (validate()) {
qreal startTime = mpStartTimeTextBox->text().toDouble();
qreal stopTime = mpStopTimeTextBox->text().toDouble();
mpIntervalTextBox->setText(QString::number((stopTime - startTime) / mpNumberofIntervalsSpinBox->value()));
}
}
}

/*!
* \brief SimulationDialog::updateMethodToolTip
* Updates the Method combobox tooltip.
Expand All @@ -1129,9 +1169,11 @@ void SimulationDialog::updateMethodToolTip(int index)
}

/*!
Slot activated when mpMethodComboBox currentIndexChanged signal is raised.\n
Enables/disables the Dassl options group box
*/
* \brief SimulationDialog::enableDasslOptions
* Slot activated when mpMethodComboBox currentIndexChanged signal is raised.\n
* Enables/disables the Dassl options group box
* \param method
*/
void SimulationDialog::enableDasslOptions(QString method)
{
if (method.compare("dassl") == 0) {
Expand All @@ -1144,9 +1186,10 @@ void SimulationDialog::enableDasslOptions(QString method)
}

/*!
Slot activated when mpMehtodHelpButton clicked signal is raised.\n
Opens the IntegrationAlgorithms.pdf file.
*/
* \brief SimulationDialog::showIntegrationHelp
* Slot activated when mpMehtodHelpButton clicked signal is raised.\n
* Opens the IntegrationAlgorithms.pdf file.
*/
void SimulationDialog::showIntegrationHelp()
{
QUrl integrationAlgorithmsPath (QString("file:///").append(QString(Helper::OpenModelicaHome).replace("\\", "/"))
Expand All @@ -1159,37 +1202,43 @@ void SimulationDialog::showIntegrationHelp()
}

/*!
Slot activated when mpBuildOnlyCheckBox checkbox is checked.\n
Makes sure that we only build the modelica model and don't run the simulation.
*/
* \brief SimulationDialog::buildOnly
* Slot activated when mpBuildOnlyCheckBox checkbox is checked.\n
* Makes sure that we only build the modelica model and don't run the simulation.
* \param checked
*/
void SimulationDialog::buildOnly(bool checked)
{
mpLaunchAlgorithmicDebuggerCheckBox->setEnabled(!checked);
mpSimulationFlagsTab->setEnabled(!checked);
}

/*!
Slot activated when mpModelSetupFileBrowseButton clicked signal is raised.\n
Allows user to select Model Setup File.
*/
* \brief SimulationDialog::browseModelSetupFile
* Slot activated when mpModelSetupFileBrowseButton clicked signal is raised.\n
* Allows user to select Model Setup File.
*/
void SimulationDialog::browseModelSetupFile()
{
mpModelSetupFileTextBox->setText(StringHandler::getOpenFileName(this,QString(Helper::applicationName).append(" - ").append(Helper::chooseFile), NULL, Helper::xmlFileTypes, NULL));
}

/*!
Slot activated when mpEquationSystemInitializationFileBrowseButton clicked signal is raised.\n
Allows user to select Equation System Initialization File.
*/
* \brief SimulationDialog::browseEquationSystemInitializationFile
* Slot activated when mpEquationSystemInitializationFileBrowseButton clicked signal is raised.\n
* Allows user to select Equation System Initialization File.
*/
void SimulationDialog::browseEquationSystemInitializationFile()
{
mpEquationSystemInitializationFileTextBox->setText(StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile), NULL, Helper::matFileTypes, NULL));
}

/*!
Slot activated when mpArchivedSimulationsListWidget itemDoubleClicked signal is raised.\n
Shows the archived SimulationOutputWidget.
*/
* \brief SimulationDialog::showArchivedSimulation
* Slot activated when mpArchivedSimulationsListWidget itemDoubleClicked signal is raised.\n
* Shows the archived SimulationOutputWidget.
* \param pTreeWidgetItem
*/
void SimulationDialog::showArchivedSimulation(QTreeWidgetItem *pTreeWidgetItem)
{
ArchivedSimulationItem *pArchivedSimulationItem = dynamic_cast<ArchivedSimulationItem*>(pTreeWidgetItem);
Expand All @@ -1202,9 +1251,10 @@ void SimulationDialog::showArchivedSimulation(QTreeWidgetItem *pTreeWidgetItem)
}

/*!
Slot activated when mpSimulateButton clicked signal is raised.\n
Reads the simulation options set by the user and sends them to OMC by calling buildModel.
*/
* \brief SimulationDialog::simulate
* Slot activated when mpSimulateButton clicked signal is raised.\n
* Reads the simulation options set by the user and sends them to OMC by calling buildModel.
*/
void SimulationDialog::simulate()
{
SimulationOptions simulationOptions;
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.h
Expand Up @@ -211,6 +211,8 @@ class SimulationDialog : public QDialog
void showAlgorithmicDebugger(SimulationOptions simulationOptions);
void simulationProcessFinished(SimulationOptions simulationOptions, QDateTime resultFileLastModifiedDateTime);
public slots:
void numberOfIntervalsRadioToggled(bool toggle);
void intervalRadioToggled(bool toggle);
void updateMethodToolTip(int index);
void enableDasslOptions(QString method);
void showIntegrationHelp();
Expand Down

0 comments on commit 2a62fa6

Please sign in to comment.