BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItem.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Sample/MaterialItem.h
6 //! @brief Defines class MaterialItem
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_SAMPLE_MATERIALITEM_H
16 #define BORNAGAIN_GUI_MODEL_SAMPLE_MATERIALITEM_H
17 
18 #include <QColor>
19 #include <QObject>
20 #include <heinz/Complex.h>
21 #include <heinz/Vectors3D.h>
22 #include <memory>
23 #include <variant>
24 
25 class Material;
26 class DoubleDescriptor;
27 class VectorDescriptor;
28 class QXmlStreamReader;
29 class QXmlStreamWriter;
30 class Streamer;
31 
32 class MaterialItem : public QObject {
33  Q_OBJECT
34 
35 public:
36  MaterialItem();
37 
38  //! Creates a complete copy, also the identifier is the same.
39  //!
40  //! Note that the base QObject is freshly initialized, not copied from \a other. Therefore
41  //! object hierarchy, connections, properties, object name or similar things are not copied.
42  //! This is of no harm since this class is only derived from QObject to provide data change
43  //! signaling.
45 
46  //! Turns material into refractive index material.
47  //!
48  //! Set refractive index as in 1 - delta + i * beta
49  void setRefractiveIndex(double delta, double beta);
50 
51  //! Turns material into SLD based material.
52  void setScatteringLengthDensity(complex_t sld);
53 
59 
60  /// \return true if refractive index was given, otherwise SLD was given
61  bool hasRefractiveIndex() const;
62 
63  QString matItemName() const;
64  void setMatItemName(const QString& name);
65 
66  QString identifier() const;
67  void setIdentifier(const QString& id);
68  void createNewIdentifier();
69 
70  QColor color() const;
71  void setColor(const QColor& color);
72 
73  R3 magnetization() const;
74  void setMagnetization(const R3& magnetization);
75 
76  std::unique_ptr<Material> createMaterial() const;
77 
78  //! Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken
79  //! into account.
80  bool operator==(const MaterialItem& other) const;
81  bool operator!=(const MaterialItem& other) const;
82 
83  void writeContentTo(QXmlStreamWriter* writer) const;
84  void readContentFrom(QXmlStreamReader* reader);
85  void serialize(Streamer& s);
86 
87  //! Updates content from the other material.
88  //!
89  //! Does NOT change the identifier.
90  //! emits dataChanged, if differences exist.
91  void updateFrom(const MaterialItem& other);
92 
93 private:
94  //! Returns a unique identifier for descriptors.
95  //!
96  //! lastPart will be attached to identify the relevant descriptor.
97  QString uidForDescriptor(const QString& lastPart) const;
98 
99 signals:
100  void dataChanged() const;
101 
102 private:
103  QString m_name;
104  QString m_id;
105  QColor m_color;
106 
107  struct Refractive {
108  Refractive(double d, double b)
109  : delta(d)
110  , beta(b)
111  {
112  }
113  double delta = 0.0;
114  double beta = 0.0;
115  bool operator==(const Refractive& o) const { return delta == o.delta && beta == o.beta; }
116  bool operator!=(const Refractive& o) const { return !operator==(o); }
117  };
118 
119  std::variant<Refractive, complex_t> m_data;
121 };
122 
123 #endif // BORNAGAIN_GUI_MODEL_SAMPLE_MATERIALITEM_H
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
Describes properties of a double value which are necessary to allow GUI representation,...
QString m_id
Definition: MaterialItem.h:104
QString uidForDescriptor(const QString &lastPart) const
Returns a unique identifier for descriptors.
QColor m_color
Definition: MaterialItem.h:105
bool hasRefractiveIndex() const
void serialize(Streamer &s)
void createNewIdentifier()
QString m_name
Definition: MaterialItem.h:103
void setScatteringLengthDensity(complex_t sld)
Turns material into SLD based material.
DoubleDescriptor sldIm()
DoubleDescriptor beta()
void readContentFrom(QXmlStreamReader *reader)
bool operator!=(const MaterialItem &other) const
QString matItemName() const
QColor color() const
void setIdentifier(const QString &id)
R3 magnetization() const
std::variant< Refractive, complex_t > m_data
Definition: MaterialItem.h:119
void setMagnetization(const R3 &magnetization)
void updateFrom(const MaterialItem &other)
Updates content from the other material.
bool operator==(const MaterialItem &other) const
Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken into acco...
QString identifier() const
void setRefractiveIndex(double delta, double beta)
Turns material into refractive index material.
std::unique_ptr< Material > createMaterial() const
DoubleDescriptor sldRe()
void setMatItemName(const QString &name)
DoubleDescriptor delta()
void dataChanged() const
VectorDescriptor magnetizationVector()
void setColor(const QColor &color)
void writeContentTo(QXmlStreamWriter *writer) const
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
Describes properties of a 3D vector, consisting of three double values.
QString const & name(EShape k)
Definition: particles.cpp:20
Refractive(double d, double b)
Definition: MaterialItem.h:108
bool operator==(const Refractive &o) const
Definition: MaterialItem.h:115
bool operator!=(const Refractive &o) const
Definition: MaterialItem.h:116