BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
InstrumentItems.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/InstrumentItems.h
6 //! @brief Defines class InstrumentItem and all its children
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_DEVICE_INSTRUMENTITEMS_H
16 #define BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTITEMS_H
17 
23 #include "GUI/Model/Device/BeamItems.h" // inheritance prevents forward declaration
25 #include <functional>
26 #include <memory>
27 
28 class BackgroundItem;
29 class DataItem;
30 class DepthProbeSimulation;
31 class ICoordSystem;
32 class Instrument;
33 class MaskContainerItem;
34 class MultiLayer;
35 class RealDataItem;
36 class OffspecSimulation;
37 class ScatteringSimulation;
38 
39 //! Abstract base class for instrument-specific item classes.
40 
42 public:
44  virtual ~InstrumentItem() = default;
45 
46  //! Creates an exact copy; also ID is the same!
47  InstrumentItem* createCopy() const;
48 
49  virtual void serialize(Streamer& s);
50 
51  QString id() const;
52  void setId(const QString& id);
53 
54  void setInstrumentName(const QString& instrumentName);
55  QString instrumentName() const;
56 
57  //! The type as how to show it on the UI. Do not use for type checking or similar!
58  virtual QString instrumentType() const = 0;
59 
60  template <typename T>
61  bool is() const
62  {
63  return dynamic_cast<const T*>(this) != nullptr;
64  }
65 
66  QString description() const;
67  void setDescription(const QString& description);
68 
69  virtual BeamItem* beamItem() const;
71 
72  template <typename T>
73  T* setBackgroundType();
75 
76  virtual std::vector<int> shape() const = 0;
77 
78  virtual void importMasks(const MaskContainerItem*) {}
79 
80  virtual void updateToRealData(const RealDataItem* item) = 0;
81  virtual bool alignedWith(const RealDataItem* item) const;
82 
83  //! The default user visible name when creating an instrument
84  virtual QString defaultName() const = 0;
85 
86  virtual ICoordSystem* createCoordSystem() const = 0;
87 
88  bool withPolarizerAnalyzer() const;
89  void setWithPolarizerAnalyzer(bool with);
90 
91  VECTOR_PROPERTY(polarization, Polarization);
92  VECTOR_PROPERTY(analyzerDirection, AnalyzerDirection);
93  DOUBLE_PROPERTY(analyzerEfficiency, AnalyzerEfficiency)
94  DOUBLE_PROPERTY(analyzerTotalTransmission, AnalyzerTotalTransmission);
95 
96 protected:
97  explicit InstrumentItem(const QString& modelType);
98 
99  template <typename T>
100  T* beam() const;
101 
102  QString m_id;
103  QString m_name;
104  QString m_description;
107  std::unique_ptr<BeamItem> m_beamItem;
108 };
109 
110 
112 public:
114 
115  SpecularBeamItem* beamItem() const override;
116 
117  std::vector<int> shape() const override;
118  void updateToRealData(const RealDataItem* item) override;
119  bool alignedWith(const RealDataItem* item) const override;
120  QString defaultName() const override;
121  QString instrumentType() const override;
122 
123  ICoordSystem* createCoordSystem() const override;
124 };
125 
126 
128 public:
130  void serialize(Streamer& s) override;
131 
132  SpecularBeamItem* beamItem() const override;
133 
134  std::vector<int> shape() const override;
135  void updateToRealData(const RealDataItem* item) override;
136  QString defaultName() const override;
137  QString instrumentType() const override;
138 
139  // FIXME switch to base ISimulation class after InstrumentItem refactoring and
140  // after ISimulation gets createCoordSystem method
141  DepthProbeSimulation* createSimulation(const MultiLayer& sample) const;
142 
143  ICoordSystem* createCoordSystem() const override;
144 
146 };
147 
148 
150 public:
151  void serialize(Streamer& s) override;
152 
153  DetectorItem* detectorItem() const;
155  template <typename T>
156  T* setDetectorType();
157  SelectionDescriptor<DetectorItem*> detectorSelection() const;
158 
159  void importMasks(const MaskContainerItem* maskContainer) override;
160 
161  std::unique_ptr<Instrument> createInstrument() const;
162  ScatteringSimulation* createScatteringSimulation(const MultiLayer& sample) const;
163  OffspecSimulation* createOffspecSimulation(const MultiLayer& sample) const;
164 
165  static bool isDetectorPropertyName(const QString& name);
166 
167 protected:
169 
171 };
172 
173 
175 public:
176  std::vector<int> shape() const override;
177  void updateToRealData(const RealDataItem* item) override;
178  QString defaultName() const override;
179  QString instrumentType() const override;
180 
181  ICoordSystem* createCoordSystem() const override;
182 };
183 
184 
186 public:
188  void serialize(Streamer& s) override;
189 
190  std::vector<int> shape() const override;
191  void updateToRealData(const RealDataItem* item) override;
192  QString defaultName() const override;
193  QString instrumentType() const override;
194 
195  ICoordSystem* createCoordSystem() const override;
196 
197  AXIS_PROPERTY(alphaAxis);
198 };
199 
200 // ************************************************************************************************
201 // templated functions implementation
202 // ************************************************************************************************
203 
204 template <typename T>
206 {
207  m_backgroundItem.set<T>();
208  return dynamic_cast<T*>(m_backgroundItem.get());
209 }
210 
211 template <typename T>
213 {
214  m_detectorItem.set<T>();
215  return dynamic_cast<T*>(m_detectorItem.get());
216 }
217 
218 #endif // BORNAGAIN_GUI_MODEL_DEVICE_INSTRUMENTITEMS_H
Defines class AxisProperty.
Defines BackgroundItem classes.
Defines BeamItem hierarchy.
Defines classes DetectorItems.
Defines class SelectionDescriptor.
Defines class SelectionProperty.
Defines class VectorProperty.
Abstract base class for IntensityDataItem and SpecularDataItem. Owns one simulated data set of type D...
Definition: DataItem.h:34
static bool isDetectorPropertyName(const QString &name)
SelectionProperty< DetectorItem * > m_detectorItem
GroupItem * detectorGroup()
Abstract base class for instrument-specific item classes.
virtual void updateToRealData(const RealDataItem *item)=0
InstrumentItem * createCopy() const
Creates an exact copy; also ID is the same!
bool is() const
virtual QString defaultName() const =0
The default user visible name when creating an instrument.
QString instrumentName() const
bool withPolarizerAnalyzer() const
QString id() const
void setId(const QString &id)
VECTOR_PROPERTY(analyzerDirection, AnalyzerDirection)
virtual std::vector< int > shape() const =0
void setDescription(const QString &description)
virtual BeamItem * beamItem() const
std::unique_ptr< BeamItem > m_beamItem
virtual ICoordSystem * createCoordSystem() const =0
void setWithPolarizerAnalyzer(bool with)
virtual QString instrumentType() const =0
The type as how to show it on the UI. Do not use for type checking or similar!
DOUBLE_PROPERTY(analyzerTotalTransmission, AnalyzerTotalTransmission)
SelectionDescriptor< BackgroundItem * > backgroundSelection() const
VECTOR_PROPERTY(polarization, Polarization)
void setInstrumentName(const QString &instrumentName)
virtual void serialize(Streamer &s)
SelectionProperty< BackgroundItem * > m_backgroundItem
virtual bool alignedWith(const RealDataItem *item) const
BackgroundItem * backgroundItem() const
virtual void importMasks(const MaskContainerItem *)
bool m_withPolarizerAnalyzer
virtual ~InstrumentItem()=default
QString description() const
Assembles beam, detector and their relative positions with respect to the sample.
Definition: Instrument.h:26
Container holding various masks as children.
Definition: MaskItems.h:202
AXIS_PROPERTY(alphaAxis)
Provides access to experimental data, for display and fitting. Owns an AbstractDataLoader.
Definition: RealDataItem.h:33
Describes a selection (various possibilities and the current one).
Class for representing a selection, its attributes and its accessors.
void set(T t, bool callInitializer=false)
Directly set the new item.
T get() const
Direct access to the stored pointer.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
QString const & name(EShape k)
Definition: particles.cpp:20