BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
LayerItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Sample/LayerItem.cpp
6 //! @brief Implements class LayerItem
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 
22 #include <QColor>
23 
24 namespace {
25 
26 QVector<ItemWithMaterial*> layoutItemsWithMaterial(ParticleLayoutItem* layout)
27 {
28  QVector<ItemWithMaterial*> result;
29 
30  QVector<ItemWithParticles*> itemsWithParticles{layout->particles()};
31  while (!itemsWithParticles.empty()) {
32  auto* item = itemsWithParticles.takeFirst();
33  if (!item)
34  continue;
35 
36  if (auto* p = dynamic_cast<ParticleCompositionItem*>(item))
37  itemsWithParticles << p->particles();
38  else if (auto* p = dynamic_cast<MesoCrystalItem*>(item))
39  itemsWithParticles << p->basisParticle();
40  else if (auto* p = dynamic_cast<ParticleItem*>(item))
41  result << p;
42  else if (auto* p = dynamic_cast<ParticleCoreShellItem*>(item)) {
43  if (p->core())
44  result << p->core();
45  if (p->shell())
46  result << p->shell();
47  } else
48  ASSERT(false);
49  }
50  return result;
51 }
52 
53 } // namespace
54 
56  : ItemWithMaterial(materials)
57 {
58  m_thickness.init("Thickness", "Thickness of the layer", 0.0, Unit::nanometer, 3,
59  RealLimits::lowerLimited(0.0), "thickness");
60 
61  m_numSlices.init("Number of slices",
62  "Number of horizontal slices.\n"
63  "Used for Average Layer Material calculations \n"
64  "when corresponding simulation option is set.",
65  1, Unit::unitless, RealLimits::lowerLimited(0.0), "slices");
66 
67  m_name = "Layer";
68 }
69 
70 void LayerItem::setLayerName(const QString& name)
71 {
72  m_name = name;
73 }
74 
75 QString LayerItem::layerName() const
76 {
77  return m_name;
78 }
79 
80 QVector<ItemWithMaterial*> LayerItem::itemsWithMaterial()
81 {
82  QVector<ItemWithMaterial*> result;
83  result.push_back(this);
84  for (auto* layout : layouts())
85  result.append(layoutItemsWithMaterial(layout));
86  return result;
87 }
88 
89 QVector<ItemWithParticles*> LayerItem::itemsWithParticles() const
90 {
91  QVector<ItemWithParticles*> result;
92  for (auto* layout : layouts())
93  result << layout->containedItemsWithParticles();
94  return result;
95 }
96 
98 {
99  return m_thickness;
100 }
101 
103 {
105  d.label = "Top roughness";
106  d.tooltip = "Roughness of top interface";
107  d.options = QStringList{"No", "Basic"};
108 
109  d.currentIndexSetter = [=](int idx) {
110  if (idx == 0)
111  clearRoughness();
112  else
114  };
115 
116  d.currentIndexGetter = [=]() { return m_topRoughness ? 1 : 0; };
117  d.currentItem = [=] { return m_topRoughness.get(); };
118  return d;
119 }
120 
122 {
124 }
125 
127 {
128  m_topRoughness.reset();
129 }
130 
132 {
133  return m_numSlices;
134 }
135 
136 QVector<ParticleLayoutItem*> LayerItem::layouts() const
137 {
138  return m_layouts;
139 }
140 
142 {
144  return m_layouts.back();
145 }
146 
148 {
149  m_layouts.removeAll(layout);
150  delete layout;
151 }
152 
153 QColor LayerItem::color() const
154 {
155  return m_color;
156 }
157 
158 void LayerItem::setColor(const QColor& color)
159 {
160  m_color = color;
161 }
162 
164 {
165  m_isTopLayer = b;
166 }
167 
169 {
170  return m_isTopLayer;
171 }
172 
174 {
175  m_isBottomLayer = b;
176 }
177 
179 {
180  return m_isBottomLayer;
181 }
182 
184 {
185  s.assertVersion(0);
186  Serialize::rwValue(s, "Name", m_name);
187  Serialize::rwValue(s, "Color", m_color);
188  Serialize::rwValue(s, "MaterialIdentifier", m_materialIdentifier);
191  Serialize::rwOptional(s, "Roughness", m_topRoughness);
193 }
Defines class LayerItem.
Defines class MesoCrystalItem.
Defines class MultiLayerItem.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class ParticleLayoutItem.
@ unitless
@ 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)
QString m_materialIdentifier
const MaterialItems * m_materialItems
QColor m_color
Definition: LayerItem.h:73
LayerItem(const MaterialItems *materials)
Definition: LayerItem.cpp:55
UIntProperty m_numSlices
Definition: LayerItem.h:71
bool m_isBottomLayer
Definition: LayerItem.h:75
void setIsTopLayer(bool b)
Definition: LayerItem.cpp:163
void clearRoughness()
Definition: LayerItem.cpp:126
void setLayerName(const QString &name)
Definition: LayerItem.cpp:70
QColor color() const
Definition: LayerItem.cpp:153
UIntDescriptor numSlices() const
Definition: LayerItem.cpp:131
ParticleLayoutItem * addLayout()
Definition: LayerItem.cpp:141
bool isTopLayer() const
Definition: LayerItem.cpp:168
void setColor(const QColor &color)
Definition: LayerItem.cpp:158
std::unique_ptr< LayerBasicRoughnessItem > m_topRoughness
Definition: LayerItem.h:77
void setIsBottomLayer(bool b)
Definition: LayerItem.cpp:173
void setBasicRoughness()
Definition: LayerItem.cpp:121
DoubleProperty m_thickness
Definition: LayerItem.h:72
QVector< ItemWithParticles * > itemsWithParticles() const
Definition: LayerItem.cpp:89
bool isBottomLayer() const
Definition: LayerItem.cpp:178
QString m_name
Definition: LayerItem.h:70
QVector< ParticleLayoutItem * > layouts() const
Definition: LayerItem.cpp:136
bool m_isTopLayer
Definition: LayerItem.h:74
QVector< ParticleLayoutItem * > m_layouts
Definition: LayerItem.h:76
DoubleDescriptor thickness() const
Definition: LayerItem.cpp:97
void removeLayout(ParticleLayoutItem *layout)
Definition: LayerItem.cpp:147
QVector< ItemWithMaterial * > itemsWithMaterial()
Definition: LayerItem.cpp:80
void serialize(Streamer &s)
Definition: LayerItem.cpp:183
QString layerName() const
Definition: LayerItem.cpp:75
SelectionDescriptor< LayerBasicRoughnessItem * > roughness()
Definition: LayerItem.cpp:102
QVector< ItemWithParticles * > containedItemsWithParticles() const
Return full hierarchical contained items with particles.
QVector< ItemWithParticles * > particles() const
The particles this layout contains.
Describes a selection (various possibilities and the current one).
function< int()> currentIndexGetter
Function to get currently selected option.
QString label
A label text (short, no trailing colon)
function< T()> currentItem
Function to get currently selected item.
function< void(int)> currentIndexSetter
Function to set currently selected option.
QStringList options
List of options, usually presented as combo entries.
QString tooltip
Tooltip text.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
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 uint value which are necessary to allow GUI representation,...
void init(const QString &label, const QString &tooltip, uint value, const variant< QString, Unit > &unit, const QString &persistentTag)
QString const & name(EShape k)
Definition: particles.cpp:20
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 rwOptional(Streamer &s, const QString &tag, std::unique_ptr< ItemClass > &up, ArgsForConstructor... argsForConstructor)
Serializes an optional item of known type. Passes optional arguments to the constructor.
Definition: Serialize.h:142