29 #include "ui_SimulationView.h"
30 #include <QButtonGroup>
31 #include <QMessageBox>
37 , m_document(document)
41 setAttribute(Qt::WA_StyledBackground,
true);
42 setProperty(
"stylable",
true);
48 auto* buttonGroup =
new QButtonGroup(
this);
49 buttonGroup->addButton(
m_ui->runPolicyImmediatelyRadio);
50 buttonGroup->addButton(
m_ui->runPolicyBackgroundRadio);
52 auto* computationButtonGroup =
new QButtonGroup(
this);
53 computationButtonGroup->addButton(
m_ui->analyticalRadio);
54 computationButtonGroup->addButton(
m_ui->monteCarloRadio);
56 buttonGroup =
new QButtonGroup(
this);
57 buttonGroup->addButton(
m_ui->ambientLayerRadio);
58 buttonGroup->addButton(
m_ui->averageLayerRadio);
61 const int nthreads =
static_cast<int>(std::thread::hardware_concurrency());
62 m_ui->numberOfThreadsCombo->addItem(QString(
"Max (%1 threads)").arg(nthreads), nthreads);
63 for (
int i = nthreads - 1; i > 1; i--)
64 m_ui->numberOfThreadsCombo->addItem(QString(
"%1 threads").arg(i), i);
65 m_ui->numberOfThreadsCombo->addItem(
"1 thread", 1);
70 connect(
m_ui->exportToPyScriptButton, &QPushButton::clicked,
this,
72 connect(computationButtonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
this,
75 connect(
m_ui->runPolicyImmediatelyRadio, &QRadioButton::toggled,
76 [=]() { document->setModified(); });
78 connect(
m_ui->analyticalRadio, &QRadioButton::toggled, [=]() { document->setModified(); });
80 connect(
m_ui->averageLayerRadio, &QRadioButton::toggled, [=]() { document->setModified(); });
82 connect(
m_ui->numberOfThreadsCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),
83 [=]() { document->setModified(); });
85 connect(
m_ui->numberOfMonteCarloPoints, QOverload<int>::of(&QSpinBox::valueChanged),
86 [=]() { document->setModified(); });
88 connect(
m_ui->includeSpecularCheck, &QCheckBox::toggled, [=]() { document->setModified(); });
101 QSignalBlocker b1(
m_ui->runPolicyImmediatelyRadio);
102 QSignalBlocker b2(
m_ui->analyticalRadio);
103 QSignalBlocker b3(
m_ui->averageLayerRadio);
104 QSignalBlocker b4(
m_ui->numberOfThreadsCombo);
105 QSignalBlocker b5(
m_ui->numberOfMonteCarloPoints);
106 QSignalBlocker b6(
m_ui->includeSpecularCheck);
115 :
m_ui->runPolicyBackgroundRadio->setChecked(
true);
118 :
m_ui->monteCarloRadio->setChecked(
true);
121 :
m_ui->ambientLayerRadio->setChecked(
true);
123 m_ui->numberOfThreadsCombo->setCurrentIndex(
124 m_ui->numberOfThreadsCombo->findData(
optionsItem()->numberOfThreads()));
125 m_ui->numberOfMonteCarloPoints->setValue(
optionsItem()->numberOfMonteCarloPoints());
126 m_ui->includeSpecularCheck->setChecked(
optionsItem()->includeSpecularPeak());
143 "Can't run the job with current settings\n\n" + msg);
149 jobModel->
runJob(jobItem);
157 "Can't export to Python with current settings\n\n" + msg);
161 pythonWidget->show();
162 pythonWidget->raise();
171 if (
m_ui->analyticalRadio->isChecked())
181 m_ui->numberOfMonteCarloPoints->setEnabled(
m_ui->monteCarloRadio->isChecked());
186 const QString previousItem = comboBox->currentText();
189 comboBox->setEnabled(!itemList.isEmpty());
191 if (itemList.isEmpty()) {
192 comboBox->addItem(
"Not yet defined");
197 itemList.insert(-1,
"None");
198 comboBox->addItems(itemList);
199 if (itemList.contains(previousItem))
200 comboBox->setCurrentIndex(itemList.indexOf(previousItem));
206 const auto append = [&](
const QString& m) { messages.append(
"- " + m +
"\n"); };
209 append(
"No sample selected");
217 append(
"No instrument selected");
221 append(
"The experimental data does not fit in the selected instrument. Try linking "
222 "them in Import Tab.");
255 return sampleItems().value(
m_ui->sampleCombo->currentIndex(),
nullptr);
Defines class GroupBoxCollapser.
Defines class InstrumentItem and all its children.
Defines class MultiLayerItem.
Defines class ProjectDocument.
Defines class ProjectManager.
Defines class RealDataItem.
Defines class RealDataModel.
Defines class SampleValidator.
Defines class SimulationOptionsItem.
Defines class SimulationView.
static GroupBoxCollapser * installIntoGroupBox(QGroupBox *groupBox, bool expanded=true)
QVector< InstrumentItem * > collectedItems() const
QStringList instrumentNames() const
Abstract base class for instrument-specific item classes.
virtual bool alignedWith(const RealDataItem *item) const
void runJob(JobItem *jobItem)
JobItem * addJob(const MultiLayerItem *sampleItem, const InstrumentItem *instrumentItem, const RealDataItem *realDataItem, const SimulationOptionsItem &optionItem)
Main method to add a job.
QStringList sampleNames() const
QVector< MultiLayerItem * > sampleItems() const
Project document class handles all data related to the opened project (sample, job,...
JobModel * jobModel() const
RealDataModel * realDataModel() const
InstrumentCollection * collectedItems() const
MultiLayerItems * sampleItems()
bool singleInstrumentMode() const
void modified()
Emitted for any modifications in the document.
SimulationOptionsItem * simulationOptionsItem()
static ProjectManager * instance()
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
QVector< RealDataItem * > realDataItems() const
QStringList realDataNames() const
Validates whether MultiLayerItem is suitable for simulation.
bool isValidMultiLayer(const MultiLayerItem *sample)
QString getValidationMessage() const
The SimulationOptionsItem class holds simulation status (run policy, number of threads,...
bool runImmediately() const
void setRunImmediately(bool runImmediately)
void setUseAverageMaterials(bool useAverageMaterials)
void setNumberOfThreads(unsigned n)
void setIncludeSpecularPeak(bool includeSpecularPeak)
void setUseMonteCarloIntegration(unsigned numberOfPoints)
bool useAverageMaterials() const
bool useAnalytical() const
Widget to define a simulation. Contains:
SimulationOptionsItem * optionsItem() const
QVector< MultiLayerItem * > sampleItems() const
QVector< RealDataItem * > realDataItems() const
Ui::SimulationView * m_ui
const RealDataItem * selectedRealData() const
Returns selected real data item taking into account that there might be several items with the same n...
const InstrumentItem * selectedInstrument() const
Returns selected InstrumentItem taking into account that there might be several instruments with the ...
const MultiLayerItem * selectedSample() const
Returns selected sample (MultiLayerItem) taking into account that there might be several samples with...
QVector< InstrumentItem * > collectedItems() const
void updateFunctionalityNarrowing()
Show/hide UI elements according to settings in current project.
ProjectDocument * m_document
void showEvent(QShowEvent *) override
void updateSelection(QComboBox *comboBox, QStringList itemList, bool allowNone=false)
Updates selection combo with string list while preserving previous selection. If allowNone == true,...
void exportPythonScript()
void writeOptionsToUI()
Write entries in OptionsItem to UI.
void hideEvent(QHideEvent *) override
SimulationView(QWidget *parent, ProjectDocument *document)
QString validateSimulationSetup(bool validateRealData) const
Checks whether selection is correct for running a simulation. Returns empty string if valid,...
void readOptionsFromUI()
Read the entries in the UI and store in OptionsItem.
void updateEnabling()
Update enabling of elements depending on other elements.
static QMainWindow * mainWindow
QString projectDir(const QString &projectFileName)
Returns project directory deduced from project file name.
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)