BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MultiLayerItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Sample/MultiLayerItem.cpp
6 //! @brief Implements class MultiLayerItem
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 
17 #include "GUI/Support/XML/Backup.h"
19 #include <QXmlStreamWriter>
20 
22 {
23  m_name = "Sample";
24  m_crossCorrelationLength.init("Cross-correlation length",
25  "Cross correlation length of roughnesses between interfaces", 0.0,
26  Unit::nanometer, 5, RealLimits::nonnegative(), "cross");
27  m_externalField.init("External field", "External field (A/m)", "A/m", "extField");
28 }
29 
31 {
33 }
34 
35 QVector<ItemWithMaterial*> MultiLayerItem::itemsWithMaterial() const
36 {
37  QVector<ItemWithMaterial*> result;
38  for (auto* layer : m_layers)
39  result.append(layer->itemsWithMaterial());
40  return result;
41 }
42 
44 {
45  m_materials.addRefractiveMaterial("Default", 1e-3, 1e-5);
46  m_materials.addRefractiveMaterial("Vacuum", 0.0, 0.0);
47  m_materials.addRefractiveMaterial("Particle", 6e-4, 2e-8);
48  m_materials.addRefractiveMaterial("Substrate", 6e-6, 2e-8);
49 }
50 
52 {
53  return m_name;
54 }
55 
56 void MultiLayerItem::setSampleName(const QString& name)
57 {
58  m_name = name;
59 }
60 
62 {
63  return m_description;
64 }
65 
66 void MultiLayerItem::setDescription(const QString& description)
67 {
69 }
70 
72 {
74 }
75 
77 {
78  return m_externalField;
79 }
80 
81 void MultiLayerItem::setExternalField(const R3& externalField)
82 {
84 }
85 
87 {
88  return m_externalField;
89 }
90 
91 QVector<LayerItem*> MultiLayerItem::layers() const
92 {
93  return m_layers;
94 }
95 
97 {
98  if (index < 0)
99  index = m_layers.size();
100 
101  auto* layer = new LayerItem(&m_materials);
102  m_layers.insert(index, layer);
103  layer->setIsTopLayer(m_layers.first() == layer);
104  layer->setIsBottomLayer(m_layers.last() == layer);
105  return layer;
106 }
107 
109 {
110  m_layers.removeAll(layer);
111  delete layer;
112 
113  if (!m_layers.isEmpty()) {
114  m_layers.first()->setIsTopLayer(true);
115  m_layers.last()->setIsBottomLayer(true);
116  }
117 }
118 
119 void MultiLayerItem::moveLayer(LayerItem* layer, LayerItem* beforeThisLayer)
120 {
121  m_layers.removeAll(layer);
122  int index = m_layers.size(); // move to end
123  if (beforeThisLayer != nullptr)
124  index = m_layers.indexOf(beforeThisLayer);
125  m_layers.insert(index, layer);
126  for (auto* l : m_layers) {
127  l->setIsTopLayer(m_layers.first() == l);
128  l->setIsBottomLayer(m_layers.last() == l);
129  }
130 }
131 
132 void MultiLayerItem::writeContentTo(QXmlStreamWriter* writer) const
133 {
134  Streamer s(writer);
135  const_cast<MultiLayerItem*>(this)->serialize(s);
136 }
137 
138 void MultiLayerItem::readContentFrom(QXmlStreamReader* reader)
139 {
140  Streamer s(reader);
141  serialize(s);
142 }
143 
145 {
146  s.assertVersion(0);
147  Serialize::rwValue(s, "Name", m_name);
148  Serialize::rwValue(s, "Description", m_description);
151  Serialize::rwClass(s, "Materials", m_materials);
152  Serialize::rwVector(s, "Layers", m_layers, &m_materials);
153 
154  if (s.xmlReader()) {
155  // set non-stored infos
156  for (auto* l : m_layers) {
157  l->setIsTopLayer(m_layers.first() == l);
158  l->setIsBottomLayer(m_layers.last() == l);
159  }
160  }
161 }
162 
164 {
165  return m_materials;
166 }
167 
169 {
170  return m_materials;
171 }
Defines GUI::Util namespace.
Defines class LayerItem.
Defines class MultiLayerItem.
Defines class Streamer.
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
@ nanometer
Describes properties of a double value which are necessary to allow GUI representation,...
void init(const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, const QString &persistentTag)
MaterialItem * addRefractiveMaterial(const QString &name, double delta, double beta)
QString sampleName() const
void setDescription(const QString &description)
LayerItem * addLayer(int index=-1)
Creates and inserts a layer at given index.
MaterialItems & materialItems()
void setSampleName(const QString &name)
QVector< LayerItem * > m_layers
void initFrom(const MultiLayerItem *other)
void addStandardMaterials()
void removeLayer(LayerItem *item)
MaterialItems m_materials
void writeContentTo(QXmlStreamWriter *writer) const
DoubleProperty m_crossCorrelationLength
QVector< LayerItem * > layers() const
R3 externalField() const
QVector< ItemWithMaterial * > itemsWithMaterial() const
void serialize(Streamer &s)
QString m_description
QString description() const
void readContentFrom(QXmlStreamReader *reader)
DoubleDescriptor crossCorrLength() const
VectorProperty m_externalField
void moveLayer(LayerItem *item, LayerItem *beforeThisLayer)
void setExternalField(const R3 &externalField)
VectorDescriptor externalFieldVector() const
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
Describes properties of a 3D vector, consisting of three double values.
void set(const R3 &d)
void init(const QString &label, const QString &tooltip, const variant< QString, Unit > &unit, const QString &persistentTag)
QString const & name(EShape k)
Definition: particles.cpp:20
void copyContents(const T *source, T *dest)
Definition: Backup.h:46
void rwVector(Streamer &s, const QString &tag, QVector< T > &vec, Args... argsForConstructor)
Serializes a list of items of known and fixed type. Passes optional arguments to the constructor.
Definition: Serialize.h:93
void rwProperty(Streamer &s, DoubleProperty &d)
void rwValue(Streamer &s, const QString &tag, bool &val)
Definition: Serialize.cpp:19
void rwClass(Streamer &s, const QString &tag, T &t)
Serializes an item from a class that provides the function void serialize(Streamer&).
Definition: Serialize.h:77