BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SimulationSetupAssistant.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/SimulationWidgets/SimulationSetupAssistant.cpp
6 //! @brief Implements class SimulationSetupAssistant
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QMessageBox>
21 
22 //! Returns true if given setup is valid for submitting the job
23 
25 
27  const InstrumentItem* instrumentItem,
28  const RealDataItem* realData)
29 {
30  clear();
31 
32  checkMultiLayerItem(multiLayerItem);
33  checkInstrumentItem(instrumentItem);
34  checkFittingSetup(instrumentItem, realData);
35 
36  if (!m_isValid)
37  QMessageBox::warning(nullptr, "Can't run the job",
38  composeMessage()); // #baTODO fix modality
39 
40  return m_isValid;
41 }
42 
44 {
45  m_isValid = true;
46  m_messages.clear();
47 }
48 
50 {
51  if (!multiLayerItem) {
52  m_messages.append("No sample selected");
53  m_isValid = false;
54  } else {
55  SampleValidator sampleValidator;
56  if (!sampleValidator.isValidMultiLayer(multiLayerItem)) {
57  m_isValid = false;
58  m_messages.append(sampleValidator.getValidationMessage());
59  }
60  }
61 }
62 
64 {
65  if (!instrumentItem) {
66  m_messages.append("No instrument selected");
67  m_isValid = false;
68  }
69 }
70 
71 //! Check if setup is suitable for fitting. In the case when there is a realData defined,
72 //! its axes will be compared with current detector item.
73 
75  const RealDataItem* realData)
76 {
77  if (!realData || !instrumentItem || instrumentItem->alignedWith(realData))
78  return;
79 
80  m_isValid = false;
81  m_messages.append("The experimental data does not fit in the selected instrument. Try linking "
82  "them in Import Tab.");
83 }
84 
85 //! Composes the error message for message box.
86 
88 {
89  QString result("Can't run the job with current settings\n\n");
90  for (auto message : m_messages) {
91  QString text = QString("- %1 \n").arg(message);
92  result.append(text);
93  }
94  return result;
95 }
Defines ImportDataUtils namespace.
Defines InstrumentItems classes.
Defines class RealDataItem.
Defines class SampleValidator.
Defines class SimulationSetupAssistant.
virtual bool alignedWith(const RealDataItem *item) const
The RealDataItem class represents intensity data imported from file and intended for fitting.
Definition: RealDataItem.h:35
Validates SampleModel for MultiLayerItem suitable for simulation.
QString getValidationMessage() const
bool isValidMultiLayer(const MultiLayerItem *multilayer)
void checkInstrumentItem(const InstrumentItem *instrumentItem)
QString composeMessage()
Composes the error message for message box.
SimulationSetupAssistant()
Returns true if given setup is valid for submitting the job.
void checkFittingSetup(const InstrumentItem *instrumentItem, const RealDataItem *realData)
Check if setup is suitable for fitting.
void checkMultiLayerItem(const MultiLayerItem *multiLayerItem)
bool isValidSimulationSetup(const MultiLayerItem *multiLayerItem, const InstrumentItem *instrumentItem, const RealDataItem *realData=0)
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: GUIHelpers.cpp:74