BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItem Class Reference

Description

Definition at line 32 of file MaterialItem.h.

Inheritance diagram for MaterialItem:
[legend]
Collaboration diagram for MaterialItem:
[legend]

Classes

struct  Refractive
 

Signals

void dataChanged () const
 

Public Member Functions

 MaterialItem ()
 
 MaterialItem (const MaterialItem &other)
 Creates a complete copy, also the identifier is the same. More...
 
DoubleDescriptor beta ()
 
QColor color () const
 
std::unique_ptr< Material > createMaterial () const
 
void createNewIdentifier ()
 
DoubleDescriptor delta ()
 
bool hasRefractiveIndex () const
 
QString identifier () const
 
R3 magnetization () const
 
VectorDescriptor magnetizationVector ()
 
QString matItemName () const
 
bool operator!= (const MaterialItem &other) const
 
bool operator== (const MaterialItem &other) const
 Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken into account. More...
 
void readContentFrom (QXmlStreamReader *reader)
 
void serialize (Streamer &s)
 
void setColor (const QColor &color)
 
void setIdentifier (const QString &id)
 
void setMagnetization (const R3 &magnetization)
 
void setMatItemName (const QString &name)
 
void setRefractiveIndex (double delta, double beta)
 Turns material into refractive index material. More...
 
void setScatteringLengthDensity (complex_t sld)
 Turns material into SLD based material. More...
 
DoubleDescriptor sldIm ()
 
DoubleDescriptor sldRe ()
 
void updateFrom (const MaterialItem &other)
 Updates content from the other material. More...
 
void writeContentTo (QXmlStreamWriter *writer) const
 

Private Member Functions

QString uidForDescriptor (const QString &lastPart) const
 Returns a unique identifier for descriptors. More...
 

Private Attributes

QColor m_color
 
std::variant< Refractive, complex_t > m_data
 
QString m_id
 
R3 m_magnetization
 
QString m_name
 

Constructor & Destructor Documentation

◆ MaterialItem() [1/2]

MaterialItem::MaterialItem ( )

Definition at line 48 of file MaterialItem.cpp.

49  : m_data(Refractive(0.0, 0.0))
50 {
51  m_color = Qt::red;
52  m_id = QUuid::createUuid().toString();
53 }
QString m_id
Definition: MaterialItem.h:104
QColor m_color
Definition: MaterialItem.h:105
std::variant< Refractive, complex_t > m_data
Definition: MaterialItem.h:119

References m_color, and m_id.

◆ MaterialItem() [2/2]

MaterialItem::MaterialItem ( const MaterialItem other)

Creates a complete copy, also the identifier is the same.

Note that the base QObject is freshly initialized, not copied from other. Therefore object hierarchy, connections, properties, object name or similar things are not copied. This is of no harm since this class is only derived from QObject to provide data change signaling.

Definition at line 55 of file MaterialItem.cpp.

56  : QObject()
57  , m_name(other.m_name)
58  , m_id(other.m_id)
59  , m_color(other.m_color)
60  , m_data(other.m_data)
61  , m_magnetization(other.m_magnetization)
62 {
63 }
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
QString m_name
Definition: MaterialItem.h:103

References other.

Member Function Documentation

◆ beta()

DoubleDescriptor MaterialItem::beta ( )

Definition at line 101 of file MaterialItem.cpp.

102 {
103  ASSERT(hasRefractiveIndex());
104  const auto setter = [=](double v) {
105  if (m_beta != v) {
106  m_beta = v;
107  emit dataChanged();
108  }
109  };
110 
112  "Beta", "Beta of refractive index (n = 1 - delta + i*beta)", 3, RealLimits::limitless(),
113  setter, [=] { return m_beta; }, Unit::unitless);
114  d.path = [=] { return uidForDescriptor("beta"); };
115  return d;
116 }
#define m_beta
@ unitless
Describes properties of a double value which are necessary to allow GUI representation,...
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
QString uidForDescriptor(const QString &lastPart) const
Returns a unique identifier for descriptors.
bool hasRefractiveIndex() const
void dataChanged() const

References dataChanged(), hasRefractiveIndex(), m_beta, DoubleDescriptor::path, uidForDescriptor(), and unitless.

Referenced by MaterialEditorModel::data(), serialize(), and setRefractiveIndex().

Here is the call graph for this function:

◆ color()

QColor MaterialItem::color ( ) const

Definition at line 221 of file MaterialItem.cpp.

222 {
223  return m_color;
224 }

References m_color.

Referenced by ItemWithMaterial::materialColor(), setColor(), and RealSpaceCanvas::updateScene().

◆ createMaterial()

std::unique_ptr< Material > MaterialItem::createMaterial ( ) const

Definition at line 247 of file MaterialItem.cpp.

248 {
249  if (hasRefractiveIndex())
250  return std::make_unique<Material>(
251  RefractiveMaterial(matItemName().toStdString(), m_delta, m_beta, m_magnetization));
252 
253  return std::make_unique<Material>(
254  MaterialBySLD(matItemName().toStdString(), m_real, m_imag, m_magnetization));
255 }
#define m_imag
#define m_delta
#define m_real
QString matItemName() const

References hasRefractiveIndex(), m_beta, m_delta, m_imag, m_magnetization, m_real, and matItemName().

Referenced by ParticleItem::createParticle().

Here is the call graph for this function:

◆ createNewIdentifier()

void MaterialItem::createNewIdentifier ( )

Definition at line 215 of file MaterialItem.cpp.

216 {
217  m_id = QUuid::createUuid().toString();
218  // no "emit dataChanged()" here
219 }

References m_id.

◆ dataChanged

◆ delta()

DoubleDescriptor MaterialItem::delta ( )

Definition at line 84 of file MaterialItem.cpp.

85 {
86  ASSERT(hasRefractiveIndex());
87  const auto setter = [=](double v) {
88  if (m_delta != v) {
89  m_delta = v;
90  emit dataChanged();
91  }
92  };
93 
95  "Delta", "Delta of refractive index (n = 1 - delta + i*beta)", 3, RealLimits::limitless(),
96  setter, [=] { return m_delta; }, Unit::unitless);
97  d.path = [=] { return uidForDescriptor("delta"); };
98  return d;
99 }

References dataChanged(), hasRefractiveIndex(), m_delta, DoubleDescriptor::path, uidForDescriptor(), and unitless.

Referenced by MaterialEditorModel::data(), serialize(), and setRefractiveIndex().

Here is the call graph for this function:

◆ hasRefractiveIndex()

bool MaterialItem::hasRefractiveIndex ( ) const
Returns
true if refractive index was given, otherwise SLD was given

Definition at line 186 of file MaterialItem.cpp.

187 {
188  return std::holds_alternative<Refractive>(m_data);
189 }

References m_data.

Referenced by beta(), createMaterial(), MaterialEditorModel::data(), delta(), operator==(), serialize(), setRefractiveIndex(), setScatteringLengthDensity(), sldIm(), sldRe(), and writeContentTo().

◆ identifier()

QString MaterialItem::identifier ( ) const

Definition at line 204 of file MaterialItem.cpp.

205 {
206  return m_id;
207 }

References m_id.

Referenced by MaterialEditorDialog::removeCurrentMaterial(), ItemWithMaterial::setMaterial(), and uidForDescriptor().

◆ magnetization()

R3 MaterialItem::magnetization ( ) const

Definition at line 234 of file MaterialItem.cpp.

235 {
236  return m_magnetization;
237 }

References m_magnetization.

Referenced by MaterialEditorModel::data(), and setMagnetization().

◆ magnetizationVector()

VectorDescriptor MaterialItem::magnetizationVector ( )

Definition at line 152 of file MaterialItem.cpp.

153 {
154  VectorDescriptor d("Magnetization", "Magnetization (A/m)", "A/m");
155 
156  d.x.set = [=](double v) {
157  if (m_magnetization.x() != v) {
158  m_magnetization.setX(v);
159  emit dataChanged();
160  }
161  };
162  d.x.get = [=]() { return m_magnetization.x(); };
163  d.x.path = [=] { return uidForDescriptor("mx"); };
164 
165  d.y.set = [=](double v) {
166  if (m_magnetization.y() != v) {
167  m_magnetization.setY(v);
168  emit dataChanged();
169  }
170  };
171  d.y.get = [=]() { return m_magnetization.y(); };
172  d.y.path = [=] { return uidForDescriptor("my"); };
173 
174  d.z.set = [=](double v) {
175  if (m_magnetization.z() != v) {
176  m_magnetization.setZ(v);
177  emit dataChanged();
178  }
179  };
180  d.z.get = [=]() { return m_magnetization.z(); };
181  d.z.path = [=] { return uidForDescriptor("mz"); };
182  d.uid = [=] { return uidForDescriptor("magnetization"); };
183  return d;
184 }
Describes properties of a 3D vector, consisting of three double values.

References dataChanged(), DoubleDescriptor::get, m_magnetization, DoubleDescriptor::path, DoubleDescriptor::set, VectorDescriptor::uid, uidForDescriptor(), VectorDescriptor::x, VectorDescriptor::y, and VectorDescriptor::z.

Here is the call graph for this function:

◆ matItemName()

QString MaterialItem::matItemName ( ) const

Definition at line 191 of file MaterialItem.cpp.

192 {
193  return m_name;
194 }

References m_name.

Referenced by createMaterial(), MaterialEditorModel::data(), MaterialItems::insertCopy(), and ItemWithMaterial::materialName().

◆ operator!=()

bool MaterialItem::operator!= ( const MaterialItem other) const

Definition at line 338 of file MaterialItem.cpp.

339 {
340  return !operator==(other);
341 }
bool operator==(const MaterialItem &other) const
Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken into acco...

References operator==(), and other.

Here is the call graph for this function:

◆ operator==()

bool MaterialItem::operator== ( const MaterialItem other) const

Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken into account.

Definition at line 343 of file MaterialItem.cpp.

344 {
345  if (hasRefractiveIndex()) {
346  if (std::get<Refractive>(m_data) != std::get<Refractive>(other.m_data))
347  return false;
348  } else if (std::get<complex_t>(m_data) != std::get<complex_t>(other.m_data))
349  return false;
350 
351 
352  return (m_id == other.m_id) && (m_name == other.m_name) && (m_color == other.m_color)
353  && (m_magnetization == other.m_magnetization);
354 }

References hasRefractiveIndex(), m_color, m_data, m_id, m_magnetization, m_name, and other.

Referenced by operator!=().

Here is the call graph for this function:

◆ readContentFrom()

void MaterialItem::readContentFrom ( QXmlStreamReader *  reader)

Definition at line 273 of file MaterialItem.cpp.

274 {
275  const int version = reader->attributes().value(GUI::Session::XML::Version).toInt();
276 
277  if (version < 1)
279 
280  if (version > 1)
282 
284  GUI::Session::XML::readAttribute(reader, Tags::Color, &m_color);
285  GUI::Session::XML::readAttribute(reader, Tags::Name, &m_name);
286  GUI::Session::XML::readAttribute(reader, Tags::Magnetization, &m_magnetization);
287  if (reader->attributes().hasAttribute(Tags::Delta)) {
288  double d, b;
289  GUI::Session::XML::readAttribute(reader, Tags::Delta, &d);
290  GUI::Session::XML::readAttribute(reader, Tags::Beta, &b);
291  m_data = Refractive(d, b);
292  } else {
293  complex_t c;
294  GUI::Session::XML::readAttribute(reader, Tags::Sld, &c);
295  m_data = c;
296  }
297 }
static DeserializationException tooOld()
static DeserializationException tooNew()
void readAttribute(QXmlStreamReader *reader, const QString &attributeName, double *d)
Definition: UtilXML.cpp:193
constexpr auto Version("Version")
constexpr auto Id("id")

References XML::Tags::Id(), m_color, m_data, m_id, m_magnetization, m_name, GUI::Session::XML::readAttribute(), DeserializationException::tooNew(), DeserializationException::tooOld(), and GUI::Session::XML::Version().

Here is the call graph for this function:

◆ serialize()

void MaterialItem::serialize ( Streamer s)

Definition at line 299 of file MaterialItem.cpp.

300 {
301  bool hasRefractive = hasRefractiveIndex();
302  double val1 = hasRefractiveIndex() ? delta() : sldRe();
303  double val2 = hasRefractiveIndex() ? beta() : sldIm();
304 
305  s.assertVersion(0);
306  Serialize::rwValue(s, "name", m_name);
307  Serialize::rwValue(s, "id", m_id);
308  Serialize::rwValue(s, "color", m_color);
309  Serialize::rwValue(s, "magnetization", m_magnetization);
310  Serialize::rwValue(s, "refr", hasRefractive);
311  Serialize::rwValue(s, "val1", val1);
312  Serialize::rwValue(s, "val2", val2);
313 
314  if (s.xmlReader()) {
315  if (hasRefractive)
316  m_data = Refractive(val1, val2);
317  else
318  m_data = complex_t(val1, val2);
319  }
320 }
DoubleDescriptor sldIm()
DoubleDescriptor beta()
DoubleDescriptor sldRe()
DoubleDescriptor delta()
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
void rwValue(Streamer &s, const QString &tag, bool &val)
Definition: Serialize.cpp:19

References Streamer::assertVersion(), beta(), delta(), hasRefractiveIndex(), m_color, m_data, m_id, m_magnetization, m_name, Serialize::rwValue(), sldIm(), sldRe(), and Streamer::xmlReader().

Here is the call graph for this function:

◆ setColor()

void MaterialItem::setColor ( const QColor &  color)

Definition at line 226 of file MaterialItem.cpp.

227 {
228  if (m_color != color) {
229  m_color = color;
230  emit dataChanged();
231  }
232 }
QColor color() const

References color(), dataChanged(), and m_color.

Referenced by MaterialEditorModel::setColor().

Here is the call graph for this function:

◆ setIdentifier()

void MaterialItem::setIdentifier ( const QString &  id)

Definition at line 209 of file MaterialItem.cpp.

210 {
211  m_id = id;
212  // no "emit dataChanged()" here
213 }

References m_id.

◆ setMagnetization()

void MaterialItem::setMagnetization ( const R3 &  magnetization)

Definition at line 239 of file MaterialItem.cpp.

240 {
243  emit dataChanged();
244  }
245 }
R3 magnetization() const

References dataChanged(), m_magnetization, and magnetization().

Here is the call graph for this function:

◆ setMatItemName()

void MaterialItem::setMatItemName ( const QString &  name)

Definition at line 196 of file MaterialItem.cpp.

197 {
198  if (m_name != name) {
199  m_name = name;
200  emit dataChanged();
201  }
202 }
QString const & name(EShape k)
Definition: particles.cpp:20

References dataChanged(), m_name, and GUI::RealSpace::Particles::name().

Referenced by MaterialEditorModel::setMaterialItemName().

Here is the call graph for this function:

◆ setRefractiveIndex()

void MaterialItem::setRefractiveIndex ( double  delta,
double  beta 
)

Turns material into refractive index material.

Set refractive index as in 1 - delta + i * beta

Definition at line 65 of file MaterialItem.cpp.

66 {
67  const Refractive r(delta, beta);
68  if (hasRefractiveIndex() && std::get<Refractive>(m_data) == r)
69  return;
70 
71  m_data = r;
72  emit dataChanged();
73 }

References beta(), dataChanged(), delta(), hasRefractiveIndex(), and m_data.

Here is the call graph for this function:

◆ setScatteringLengthDensity()

void MaterialItem::setScatteringLengthDensity ( complex_t  sld)

Turns material into SLD based material.

Definition at line 75 of file MaterialItem.cpp.

76 {
77  if (!hasRefractiveIndex() && std::get<complex_t>(m_data) == sld)
78  return;
79 
80  m_data = sld;
81  emit dataChanged();
82 }

References dataChanged(), hasRefractiveIndex(), and m_data.

Here is the call graph for this function:

◆ sldIm()

DoubleDescriptor MaterialItem::sldIm ( )

Definition at line 135 of file MaterialItem.cpp.

136 {
137  ASSERT(!hasRefractiveIndex());
138  const auto setter = [=](double v) {
139  if (m_imag != v) {
140  std::get<complex_t>(m_data).imag(v);
141  emit dataChanged();
142  }
143  };
144 
146  "SLD, imaginary", "Imaginary part of SLD (SLD = real - i*imag), AA^{-2}", 3,
147  RealLimits::limitless(), setter, [=] { return m_imag; }, Unit::unitless);
148  d.path = [=] { return uidForDescriptor("im"); };
149  return d;
150 }

References dataChanged(), hasRefractiveIndex(), m_data, m_imag, DoubleDescriptor::path, uidForDescriptor(), and unitless.

Referenced by MaterialEditorModel::data(), and serialize().

Here is the call graph for this function:

◆ sldRe()

DoubleDescriptor MaterialItem::sldRe ( )

Definition at line 118 of file MaterialItem.cpp.

119 {
120  ASSERT(!hasRefractiveIndex());
121  const auto setter = [=](double v) {
122  if (m_real != v) {
123  std::get<complex_t>(m_data).real(v);
124  emit dataChanged();
125  }
126  };
127 
129  "SLD, real", "Real part of SLD (SLD = real - i*imag), AA^{-2}", 3, RealLimits::limitless(),
130  setter, [=] { return m_real; }, Unit::unitless);
131  d.path = [=] { return uidForDescriptor("re"); };
132  return d;
133 }

References dataChanged(), hasRefractiveIndex(), m_data, m_real, DoubleDescriptor::path, uidForDescriptor(), and unitless.

Referenced by MaterialEditorModel::data(), and serialize().

Here is the call graph for this function:

◆ uidForDescriptor()

QString MaterialItem::uidForDescriptor ( const QString &  lastPart) const
private

Returns a unique identifier for descriptors.

lastPart will be attached to identify the relevant descriptor.

Definition at line 333 of file MaterialItem.cpp.

334 {
335  return "material/" + identifier() + "/" + lastPart;
336 }
QString identifier() const

References identifier().

Referenced by beta(), delta(), magnetizationVector(), sldIm(), and sldRe().

Here is the call graph for this function:

◆ updateFrom()

void MaterialItem::updateFrom ( const MaterialItem other)

Updates content from the other material.

Does NOT change the identifier. emits dataChanged, if differences exist.

Definition at line 322 of file MaterialItem.cpp.

323 {
324  if (operator!=(other)) {
325  m_name = other.m_name;
326  m_color = other.m_color;
327  m_data = other.m_data;
328  m_magnetization = other.m_magnetization;
329  emit dataChanged();
330  }
331 }

References dataChanged(), m_color, m_data, m_magnetization, m_name, and other.

◆ writeContentTo()

void MaterialItem::writeContentTo ( QXmlStreamWriter *  writer) const

Definition at line 257 of file MaterialItem.cpp.

258 {
260 
262  GUI::Session::XML::writeAttribute(writer, Tags::Color, m_color);
263  GUI::Session::XML::writeAttribute(writer, Tags::Name, m_name);
264  GUI::Session::XML::writeAttribute(writer, Tags::Magnetization, m_magnetization);
265 
266  if (hasRefractiveIndex()) {
267  GUI::Session::XML::writeAttribute(writer, Tags::Delta, m_delta);
268  GUI::Session::XML::writeAttribute(writer, Tags::Beta, m_beta);
269  } else
270  GUI::Session::XML::writeAttribute(writer, Tags::Sld, std::get<complex_t>(m_data));
271 }
void writeAttribute(QXmlStreamWriter *writer, const QString &attributeName, const QVariant &variant)
Write the variant's value as an attribute.
Definition: UtilXML.cpp:65

References hasRefractiveIndex(), XML::Tags::Id(), m_beta, m_color, m_data, m_delta, m_id, m_magnetization, m_name, GUI::Session::XML::Version(), and GUI::Session::XML::writeAttribute().

Here is the call graph for this function:

Member Data Documentation

◆ m_color

QColor MaterialItem::m_color
private

◆ m_data

std::variant<Refractive, complex_t> MaterialItem::m_data
private

◆ m_id

QString MaterialItem::m_id
private

◆ m_magnetization

R3 MaterialItem::m_magnetization
private

◆ m_name

QString MaterialItem::m_name
private

The documentation for this class was generated from the following files: