BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaterialItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/MaterialItem.cpp
6 //! @brief Implements 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 
21 
22 namespace {
23 const QString magnetization_tooltip = "Magnetization (A/m)";
24 }
25 
26 const QString MaterialItem::P_COLOR = "Color";
27 const QString MaterialItem::P_MATERIAL_DATA = "Material data";
28 const QString MaterialItem::P_MAGNETIZATION = "Magnetization";
29 const QString MaterialItem::P_IDENTIFIER = "Identifier";
30 
32 {
33  setItemName("Material");
34 
36  addProperty(P_COLOR, color.variant())->setEditorType("ExtColorEditor");
37 
38  addGroupProperty(P_MATERIAL_DATA, "Material data group");
39  addProperty<VectorItem>(P_MAGNETIZATION)->setToolTip(magnetization_tooltip);
42 }
43 
44 //! Turns material into refractive index material.
45 
46 void MaterialItem::setRefractiveData(double delta, double beta)
47 {
48  auto refractiveData = setGroupProperty(P_MATERIAL_DATA, "MaterialRefractiveData");
49  refractiveData->setItemValue(MaterialRefractiveDataItem::P_DELTA, delta);
50  refractiveData->setItemValue(MaterialRefractiveDataItem::P_BETA, beta);
51 }
52 
53 //! Turns material into SLD based material.
54 
55 void MaterialItem::setSLDData(double sld_real, double sld_imag)
56 {
57  auto sldData = setGroupProperty(P_MATERIAL_DATA, "MaterialSLDData");
58  sldData->setItemValue(MaterialSLDDataItem::P_SLD_REAL, sld_real);
59  sldData->setItemValue(MaterialSLDDataItem::P_SLD_IMAG, sld_imag);
60 }
61 
62 QString MaterialItem::identifier() const
63 {
64  return getItemValue(P_IDENTIFIER).toString();
65 }
66 
67 QColor MaterialItem::color() const
68 {
70  return property.color();
71 }
72 
73 std::unique_ptr<Material> MaterialItem::createMaterial() const
74 {
75  auto dataItem = getGroupItem(P_MATERIAL_DATA);
76  auto magnetization = item<VectorItem>(P_MAGNETIZATION)->getVector();
77  auto name = itemName().toStdString();
78 
79  if (dataItem->modelType() == "MaterialRefractiveData") {
80  double delta = dataItem->getItemValue(MaterialRefractiveDataItem::P_DELTA).toDouble();
81  double beta = dataItem->getItemValue(MaterialRefractiveDataItem::P_BETA).toDouble();
82  return std::make_unique<Material>(HomogeneousMaterial(name, delta, beta, magnetization));
83 
84  } else if (dataItem->modelType() == "MaterialSLDData") {
85  double sld_real = dataItem->getItemValue(MaterialSLDDataItem::P_SLD_REAL).toDouble();
86  double sld_imag = dataItem->getItemValue(MaterialSLDDataItem::P_SLD_IMAG).toDouble();
87  return std::make_unique<Material>(MaterialBySLD(name, sld_real, sld_imag, magnetization));
88  }
89 
90  throw GUIHelpers::Error("MaterialItem::createMaterial() -> Error. "
91  "Not implemented material type");
92 }
Defines class GUIHelpers functions.
Defines MaterialDataItems classes.
Factory functions used to create material instances.
Defines class MaterialItemUtils.
Defines namespace SessionItemUtils.
Defines class VectorItem.
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QColor color() const
void setRefractiveData(double delta, double beta)
Turns material into refractive index material.
static const QString P_MAGNETIZATION
Definition: MaterialItem.h:26
static const QString P_MATERIAL_DATA
Definition: MaterialItem.h:25
QColor color() const
static const QString P_IDENTIFIER
Definition: MaterialItem.h:27
static const QString P_COLOR
Definition: MaterialItem.h:24
QString identifier() const
std::unique_ptr< Material > createMaterial() const
void setSLDData(double sld_real, double sld_imag)
Turns material into SLD based material.
static const QString P_DELTA
static const QString P_BETA
static const QString P_SLD_REAL
static const QString P_SLD_IMAG
QString itemName() const
Get item name, return display name if no name is set.
void setItemName(const QString &name)
Set item name, add property if necessary.
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
SessionItem * getGroupItem(const QString &groupName) const
Access subitem of group item.
void setVisible(bool enabled)
Flags accessors.
SessionItem & setEditorType(const QString &editorType)
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
SessionItem * addGroupProperty(const QString &groupTag, const QString &groupType)
Creates new group item and register new tag, returns GroupItem.
SessionItem * setGroupProperty(const QString &groupTag, const QString &modelType) const
Set the current type of group item.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
Material HomogeneousMaterial(const std::string &name, complex_t refractive_index, kvector_t magnetization)
Constructs a material with name, refractive_index and magnetization (in A/m).
QString createUuid()
Definition: GUIHelpers.cpp:242
ExternalProperty colorProperty(const QColor &color)
Constructs color property from given color.
QString const & name(EShape k)
Definition: particles.cpp:21