27 #include <boost/property_tree/exceptions.hpp>
28 #include <boost/property_tree/xml_parser.hpp>
30 #include <QFormLayout>
33 #include <QListWidget>
34 #include <QMessageBox>
35 #include <QRadioButton>
38 #include <QVBoxLayout>
48 ParamPage::ParamPage(
const std::shared_ptr<Exploration> &exploration)
49 : m_exploration(exploration), m_current_index(-1)
52 setTitle(
"Parameter selection");
53 setSubTitle(
"Please specify the required parameters");
56 QVBoxLayout* layout =
new QVBoxLayout;
58 m_parameters =
new QComboBox;
59 layout->addWidget(m_parameters);
62 QHBoxLayout* originalLayout =
new QHBoxLayout;
63 m_original_select =
new QRadioButton(
"Original");
64 m_original_select->setChecked(
true);
65 originalLayout->addWidget(m_original_select);
66 m_original =
new QLineEdit();
67 originalLayout->addWidget(m_original);
68 m_original->setReadOnly(
true);
71 QVBoxLayout* listLayout =
new QVBoxLayout;
72 m_list_select =
new QRadioButton(
"List");
73 listLayout->addWidget(m_list_select);
74 m_list =
new QLineEdit;
75 listLayout->addWidget(m_list);
78 QDoubleValidator* doubleValidator =
new QDoubleValidator(
this);
80 QVBoxLayout* loopLayout =
new QVBoxLayout;
81 m_loop_select =
new QRadioButton(
"Loop");
82 loopLayout->addWidget(m_loop_select);
84 QFormLayout* loopFormLayout =
new QFormLayout;
86 m_from =
new QLineEdit;
87 m_from->setValidator(doubleValidator);
88 loopFormLayout->addRow(
"From", m_from);
91 m_to->setValidator(doubleValidator);
92 loopFormLayout->addRow(
"To", m_to);
94 m_step =
new QLineEdit;
95 m_step->setValidator(doubleValidator);
96 loopFormLayout->addRow(
"Step", m_step);
98 loopLayout->addLayout(loopFormLayout);
100 layout->addLayout(originalLayout);
101 layout->addLayout(listLayout);
102 layout->addLayout(loopLayout);
107 connect(m_parameters, SIGNAL(currentIndexChanged(
int)),
this, SLOT(SelectParameter(
int)));
108 connect(m_original_select, SIGNAL(toggled(
bool)),
this, SLOT(UpdateOriginal(
bool)));
109 connect(m_list_select, SIGNAL(toggled(
bool)),
this, SLOT(UpdateList(
bool)));
110 connect(m_loop_select, SIGNAL(toggled(
bool)),
this, SLOT(UpdateLoop(
bool)));
112 UpdateOriginal(
true);
118 void ParamPage::UpdateOriginal(
bool checked)
120 m_original->setEnabled(checked);
124 void ParamPage::UpdateList(
bool checked)
126 m_list->setEnabled(checked);
130 void ParamPage::UpdateLoop(
bool checked)
132 m_from->setEnabled(checked);
133 m_to->setEnabled(checked);
134 m_step->setEnabled(checked);
138 void ParamPage::SelectParameter(
int index)
140 ParameterExploration *parameterExploration =
dynamic_cast<ParameterExploration*
>(m_exploration.get());
141 assert(parameterExploration &&
"Exploration wasn't a ParameterExploration");
143 if (index == m_current_index) {
145 }
else if (!SaveParameter()) {
146 m_parameters->setCurrentIndex(m_current_index);
150 m_current_index = index;
153 m_original->setText(
"");
159 std::string parameter = m_parameters->currentText().toStdString();
160 const ISweep *sweep = parameterExploration->GetSweep(parameter);
162 if (sweep ==
nullptr) {
163 m_original_select->setChecked(
true);
164 m_original->setText(QString::fromStdString(parameterExploration->GetOriginalValue(parameter)));
165 }
else if (
const ListSweep *listSweep = dynamic_cast<const ListSweep*>(sweep)) {
166 m_list_select->setChecked(
true);
169 for (
unsigned int i = 0; i < listSweep->GetNumberOfValues(); ++i) {
173 listString += QString::fromStdString(listSweep->GetValue(i));
175 m_list->setText(listString);
176 }
else if (
const RangeSweep *rangeSweep = dynamic_cast<const RangeSweep*>(sweep)) {
177 m_loop_select->setChecked(
true);
179 m_from->setText(QString::number(rangeSweep->GetFrom()));
180 m_to->setText(QString::number(rangeSweep->GetTo()));
181 m_step->setText(QString::number(rangeSweep->GetStep()));
183 assert(
false &&
"I wouldn't know what kind of sweep this is");
188 void ParamPage::initializePage()
190 ParameterExploration *parameterExploration =
dynamic_cast<ParameterExploration*
>(m_exploration.get());
191 assert(parameterExploration &&
"Exploration wasn't a ParameterExploration");
193 std::vector<std::string> parameters = parameterExploration->GetPossibleParameters();
195 if (parameters.size() > 0)
197 for (
const std::string ¶meter : parameters) {
198 m_parameters->addItem(QString::fromStdString(parameter));
201 m_parameters->setEnabled(
false);
202 UpdateOriginal(
false);
209 bool ParamPage::validatePage()
211 return SaveParameter();
215 bool ParamPage::SaveParameter()
217 ParameterExploration *parameterExploration =
dynamic_cast<ParameterExploration*
>(m_exploration.get());
218 assert(parameterExploration &&
"Exploration wasn't a ParameterExploration");
220 if (m_current_index == -1)
223 std::string parameter = m_parameters->itemText(m_current_index).toStdString();
225 if (m_original_select->isChecked()) {
226 parameterExploration->RemoveSweep(parameter);
227 }
else if (m_list_select->isChecked()) {
228 QStringList qlist = m_list->text().split(QRegExp(
" *, *"), QString::SkipEmptyParts);
230 QMessageBox::warning(
this,
"Cannot save parameters",
"The list does not contain any strings");
234 if (!m_list->isModified()) {
238 std::vector<std::string> list;
239 for (
const auto &e : qlist) {
240 list.push_back(e.toStdString());
242 parameterExploration->SetSweep(parameter,
new ListSweep(list));
244 m_list->setModified(
false);
245 }
else if (m_loop_select->isChecked()) {
247 double from = m_from->text().toDouble(&ok);
248 if (!m_from->hasAcceptableInput() || !ok) {
249 QMessageBox::warning(
this,
"Cannot save parameters",
"'From' does not contain a valid number");
253 double to = m_to->text().toDouble(&ok);
254 if (!m_to->hasAcceptableInput() || !ok) {
255 QMessageBox::warning(
this,
"Cannot save parameters",
"'To' does not contain a valid number");
259 double step = m_step->text().toDouble(&ok);
260 if (!m_step->hasAcceptableInput() || !ok) {
261 QMessageBox::warning(
this,
"Cannot save parameters",
"'Step' does not contain a valid number");
266 QMessageBox::warning(
this,
"Cannot save parameters",
"This is not a valid range: 'from' is greater than 'to'");
268 }
else if (step <= 0) {
269 QMessageBox::warning(
this,
"Cannot save parameters",
"This is not a valid range: 'step' is smaller or equal to zero");
273 if (!m_from->isModified() && !m_to->isModified() && !m_step->isModified()) {
277 parameterExploration->SetSweep(parameter,
new RangeSweep(from, to, step));
279 m_from->setModified(
false);
280 m_to->setModified(
false);
281 m_step->setModified(
false);
Interface for RangeSweep.
Namespace for SimPT parameter explorer package.
Interface for ParameterExploration.
Interface for FileExploration.