BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
JobItem.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Job/JobItem.h
6 //! @brief Defines class JobItem
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 
15 #ifndef BORNAGAIN_GUI_MODEL_JOB_JOBITEM_H
16 #define BORNAGAIN_GUI_MODEL_JOB_JOBITEM_H
17 
21 #include "GUI/Model/Model/SessionModel.h" // call to model() from templated fct
24 #include "GUI/Support/Data/JobStatus.h" // enum cannot be forward declared
26 #include <QDateTime>
27 #include <optional>
28 
29 class Data1DViewItem;
30 class DataItem;
32 class FitSuiteItem;
33 class ISimulation;
34 class Instrument2DItem;
35 class InstrumentItem;
36 class IntensityDataItem;
37 class MaterialItemContainer;
39 class RealDataItem;
41 class SimulationResult;
42 
43 class BA_CORE_API_ JobItem : public QObject, public SessionItem {
44  Q_OBJECT
45 private:
46  static constexpr auto P_IDENTIFIER{"Identifier"};
47  static constexpr auto P_INSTRUMENT_NAME{"Instrument"};
48  static constexpr auto P_WITH_FITTING{"With fitting"};
49  static constexpr auto P_STATUS{"Status"};
50  static constexpr auto P_BEGIN_TIME{"Begin time"};
51  static constexpr auto P_END_TIME{"End time"};
52  static constexpr auto P_COMMENTS{"Comments"};
53  static constexpr auto P_PROGRESS{"Progress"};
54  static constexpr auto P_PRESENTATION_TYPE{"Presentation type"};
55  static constexpr auto T_MATERIAL_CONTAINER{"Material container tag"};
56  static constexpr auto T_OUTPUT{"Output tag"};
57  static constexpr auto T_REALDATA{"Real Data tag"};
58  static constexpr auto T_DATAVIEW{"Data View tag"};
59  static constexpr auto T_FIT_SUITE{"Fit suite tag"};
60 
61 public:
62  static constexpr auto M_TYPE{"JobItem"};
63 
64  JobItem();
65  ~JobItem();
66 
67  QString getIdentifier() const;
68  void setIdentifier(const QString& identifier);
69 
70  QString jobName() const;
71  void setJobName(const QString& name);
72 
74  DataItem* dataItem();
75  template <typename T>
76  T* setDataType();
77 
78  JobStatus getStatus() const;
79  void setStatus(JobStatus status);
80 
81  bool isIdle() const;
82  bool isRunning() const;
83  bool isCompleted() const;
84  bool isCanceled() const;
85  bool isFailed() const;
86  bool isFitting() const;
87  bool isValidForFitting();
88 
89  QDateTime beginTime() const;
90  void setBeginTime(const QDateTime& begin_time);
91 
92  QDateTime endTime() const;
93  void setEndTime(const QDateTime& end_time);
94 
95  /// if begin and end time are both available the duration in ms, otherwise empty
96  std::optional<size_t> duration() const;
97 
98  QString getComments() const;
99  void setComments(const QString& comments);
100 
101  int getProgress() const;
102  void setProgress(int progress);
103 
104  bool runImmediately() const;
105  bool runInBackground() const;
106 
107  MultiLayerItem* sampleItem();
108  MultiLayerItem* copySampleIntoJob(const MultiLayerItem* sample);
109 
110  Instrument2DItem* instrument2DItem();
111  InstrumentItem* instrumentItem() const;
112  InstrumentItem* copyInstrumentIntoJob(const InstrumentItem* instrument);
113 
114  const SimulationOptionsItem& simulationOptionsItem() const;
115  void copySimulationOptionsIntoJob(const SimulationOptionsItem& options);
116 
117  void setResults(const SimulationResult& result);
118 
119  FitSuiteItem* fitSuiteItem();
120  FitSuiteItem* createFitSuiteItem();
121 
122  ParameterContainerItem* parameterContainerItem();
123  const ParameterContainerItem* parameterContainerItem() const;
124  FitParameterContainerItem* fitParameterContainerItem();
125 
126  RealDataItem* realDataItem();
127  RealDataItem* copyRealDataIntoJob(const RealDataItem* real_data);
128  RealDataItem* createRealDataItem();
129 
130  Data1DViewItem* dataItemView();
131  void addDataViewItem(Data1DViewItem* data_view);
132  Data1DViewItem* createDataViewItem();
133 
134  QString sampleName() const;
135 
136  QString instrumentName() const;
137  void setInstrumentName(const QString& name);
138 
139  QString presentationType() const;
140  void setPresentationType(const QString& type);
141 
142  void writeNonSessionItems(QXmlStreamWriter* writer) const override;
143  void readNonSessionItems(QXmlStreamReader* reader) override;
144 
145  bool isSpecularJob() const;
146 
147  friend class JobModel;
148 
149 signals:
150  void jobDestroyed();
151  void jobNameChanged(const QString& name);
152  void jobStatusChanged(const JobStatus status);
153  void jobBeginTimeChanged(const QDateTime& begin_time);
154  void jobEndTimeChanged(const QDateTime& end_time);
155  void jobIdentifierChanged(const QString& identifier);
156  void jobCommentsChanged(const QString& comments);
157  void jobProgressChanged(int progress);
158  void jobInstrumentNameChanged(const QString& name);
159  void jobPresentationTypeChanged(const QString& type);
160 
161 private:
162  void updateIntensityDataFileName();
163 
167  std::unique_ptr<InstrumentItem> m_instrument;
168 };
169 
170 template <typename T>
172 {
173  static_assert(std::is_base_of<DataItem, T>::value, "Class must be derived from DataItem");
174 
175  return model()->insertItem<T>(this, -1, T_OUTPUT);
176 }
177 
178 #endif // BORNAGAIN_GUI_MODEL_JOB_JOBITEM_H
Defines class InstrumentItem and all its children.
Defines enum JobStatus.
JobStatus
The JobStatus enum lists the possible states of a job.
Definition: JobStatus.h:22
Defines class MaterialItems.
Defines class MultiLayerItem.
Defines classes for ParameterTreeItems.
Defines class SessionItem.
Defines class SessionModel.
Defines class SimulationOptionsItem.
View model for 1D DataItem. Can represent several items at once. In current implementation the first ...
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
The FitParameterContainerItem class is a collection of all defined fit parameters in JobItem.
Abstract base class for instrument-specific item classes.
void jobStatusChanged(const JobStatus status)
void jobCommentsChanged(const QString &comments)
void jobEndTimeChanged(const QDateTime &end_time)
ParameterContainerItem m_parameterContainer
Definition: JobItem.h:165
void jobBeginTimeChanged(const QDateTime &begin_time)
void jobProgressChanged(int progress)
SimulationOptionsItem m_simulationOptionsItem
Definition: JobItem.h:164
void jobNameChanged(const QString &name)
void jobDestroyed()
void jobPresentationTypeChanged(const QString &type)
void jobIdentifierChanged(const QString &identifier)
static constexpr auto T_OUTPUT
Definition: JobItem.h:56
T * setDataType()
Definition: JobItem.h:171
void jobInstrumentNameChanged(const QString &name)
MultiLayerItem m_sampleItem
Definition: JobItem.h:166
std::unique_ptr< InstrumentItem > m_instrument
Definition: JobItem.h:167
The ParameterContainerItem is a top item to hold all ParameterItem, represents an entry point to para...
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
Base class for a GUI data item.
Definition: SessionItem.h:204
SessionModel * model() const
Returns model of this item.
Definition: SessionItem.cpp:60
virtual void writeNonSessionItems(QXmlStreamWriter *writer) const
virtual void readNonSessionItems(QXmlStreamReader *reader)
T * insertItem(SessionItem *parent=nullptr, int row=-1, QString tag="")
Definition: SessionModel.h:137
The SimulationOptionsItem class holds simulation status (run policy, number of threads,...
IntensityDataItem * intensityDataItem(SessionItem *parent)
Returns IntensityDataItem contained as a child in givent parent.
void setResults(DataItem *intensityItem, const SimulationResult &result)
Sets simulation results into the DataItem.
QString const & name(EShape k)
Definition: particles.cpp:20