BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleLayoutItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ParticleLayoutItem.cpp
6 //! @brief Implements class ParticleLayoutItem
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 
19 #include <QDebug>
20 
21 namespace {
22 
23 //! Returns true if name is related to 2D interference functions.
24 bool isInterference2D(const QString& name)
25 {
26  if (name == "Interference2DLattice" || name == "Interference2DParaCrystal"
27  || name == "InterferenceFinite2DLattice" || name == "InterferenceHardDisk")
28  return true;
29  return false;
30 }
31 
32 //! Returns true if name is related to 2D interference functions.
33 bool isLattice2D(SessionItem* item)
34 {
35  return dynamic_cast<Lattice2DItem*>(item);
36 }
37 
38 const QString density_tooltip =
39  "Number of particles per square nanometer (particle surface density).\n "
40  "Should be defined for disordered and 1d-ordered particle collections.";
41 const QString weight_tooltip =
42  "Weight of this particle layout.\n"
43  "Should be used when multiple layouts define different domains in the sample.";
44 } // namespace
45 
46 const QString ParticleLayoutItem::P_TOTAL_DENSITY = QString::fromStdString("TotalParticleDensity");
47 const QString ParticleLayoutItem::P_WEIGHT = QString::fromStdString("Weight");
48 const QString ParticleLayoutItem::T_PARTICLES = "Particle Tag";
49 const QString ParticleLayoutItem::T_INTERFERENCE = "Interference Tag";
50 
52 {
53  setToolTip("A layout of particles");
54 
55  addProperty(P_TOTAL_DENSITY, 0.01)->setToolTip(density_tooltip);
57  addProperty(P_WEIGHT, 1.0)->setToolTip(weight_tooltip);
58 
59  registerTag(T_PARTICLES, 0, -1,
60  QStringList() << "Particle"
61  << "ParticleCoreShell"
62  << "ParticleComposition"
63  << "MesoCrystal"
64  << "ParticleDistribution");
67  QStringList() << "Interference1DLattice"
68  << "Interference2DLattice"
69  << "Interference2DParaCrystal"
70  << "InterferenceFinite2DLattice"
71  << "InterferenceHardDisk"
72  << "InterferenceRadialParaCrystal");
73 
77  });
78 
80  if (isLattice2D(item) || (item && isLattice2D(item->parent())))
82  });
83 }
84 
85 //! Disables/enables total density property, depending on type of interference function.
86 //! Two dimensional interference calculates density automatically, so property should
87 //! be disabled.
88 
90 {
92  if (auto interferenceItem = getItem(T_INTERFERENCE))
93  if (isInterference2D(interferenceItem->modelType()))
95 }
96 
97 //! Updates the value of TotalSurfaceDensity on lattice type change.
98 
100 {
101  if (auto interferenceItem = getItem(T_INTERFERENCE)) {
102  if (interferenceItem->isTag(InterferenceFunction2DLatticeItem::P_LATTICE_TYPE)) {
103  auto& latticeItem = interferenceItem->groupItem<Lattice2DItem>(
105  double area = 0.0;
106  try {
107  area = latticeItem.unitCellArea();
108  } catch (const std::exception&) {
109  // nothing to do here; new exception will be caught during job execution
110  }
111  setItemValue(P_TOTAL_DENSITY, area == 0.0 ? 0.0 : 1.0 / area);
112  } else if (interferenceItem->isTag(InterferenceFunctionHardDiskItem::P_DENSITY)) {
113  double density =
114  interferenceItem->getItemValue(InterferenceFunctionHardDiskItem::P_DENSITY)
115  .toDouble();
116  setItemValue(P_TOTAL_DENSITY, density);
117  }
118  }
119 }
Defines class ComboProperty.
Defines InterferenceFunctionItems's classes.
Defines classes Lattice2DItems.
Defines class ParticleLayoutItem.
double unitCellArea() const
void setOnAnyChildChange(std::function< void(SessionItem *)> f, const void *caller=0)
Calls back on any change in children (number of children or their properties), reports childItem.
Definition: ModelMapper.cpp:82
void setOnChildrenChange(std::function< void(SessionItem *)> f, const void *caller=0)
Calls back when number of children has changed, reports newChild.
Definition: ModelMapper.cpp:68
static const QString T_PARTICLES
static const QString T_INTERFERENCE
static const QString P_TOTAL_DENSITY
void updateDensityValue()
Updates the value of TotalSurfaceDensity on lattice type change.
void updateDensityAppearance()
Disables/enables total density property, depending on type of interference function.
static const QString P_WEIGHT
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
SessionItem & setDecimals(int n)
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
void setDefaultTag(const QString &tag)
Set default tag.
T * item(const QString &tag) const
Definition: SessionItem.h:151
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
SessionItem & setToolTip(const QString &tooltip)
void setEnabled(bool enabled)
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
QString const & name(EShape k)
Definition: particles.cpp:21