BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleCompositionItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ParticleCompositionItem.cpp
6 //! @brief Implements class ParticleCompositionItem
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 
26 
27 namespace {
28 const QString abundance_tooltip = "Proportion of this type of particles normalized to the \n"
29  "total number of particles in the layout";
30 
31 const QString position_tooltip = "Relative position of the particle's reference point \n"
32  "in the coordinate system of the parent (nm)";
33 } // namespace
34 
35 const QString ParticleCompositionItem::T_PARTICLES = "Particle Tag";
36 
37 // TODO make ParticleCoreShellItem and ParticleItem to derive from common base.
38 
40 {
41  setToolTip("Composition of particles with fixed positions");
42 
44  ->setLimits(RealLimits::limited(0.0, 1.0))
45  .setDecimals(3)
46  .setToolTip(abundance_tooltip);
47 
48  addProperty<VectorItem>(ParticleItem::P_POSITION)->setToolTip(position_tooltip);
49 
50  registerTag(T_PARTICLES, 0, -1,
51  QStringList() << "Particle"
52  << "ParticleCoreShell"
53  << "ParticleComposition"
54  << "MesoCrystal");
56  registerTag(ParticleItem::T_TRANSFORMATION, 0, 1, QStringList() << "Rotation");
57 
60 
65  } else {
67  }
68  });
69 }
70 
72 {
73  return item<VectorItem>(ParticleItem::P_POSITION);
74 }
75 
76 std::unique_ptr<ParticleComposition> ParticleCompositionItem::createParticleComposition() const
77 {
78  double abundance = getItemValue(ParticleItem::P_ABUNDANCE).toDouble();
79  auto P_composition = std::make_unique<ParticleComposition>();
80  P_composition->setAbundance(abundance);
81  QVector<SessionItem*> childlist = children();
82  for (int i = 0; i < childlist.size(); ++i) {
83  if (childlist[i]->modelType() == "Particle") {
84  auto* particle_item = static_cast<ParticleItem*>(childlist[i]);
85  auto P_particle = particle_item->createParticle();
86  if (P_particle) {
87  P_composition->addParticle(*P_particle);
88  }
89  } else if (childlist[i]->modelType() == "ParticleCoreShell") {
90  auto* particle_coreshell_item = static_cast<ParticleCoreShellItem*>(childlist[i]);
91  auto P_particle_coreshell = particle_coreshell_item->createParticleCoreShell();
92  if (P_particle_coreshell) {
93  P_composition->addParticle(*P_particle_coreshell);
94  }
95  } else if (childlist[i]->modelType() == "ParticleComposition") {
96  auto* particlecomposition_item = static_cast<ParticleCompositionItem*>(childlist[i]);
97  auto P_child_composition = particlecomposition_item->createParticleComposition();
98  if (P_child_composition) {
99  P_composition->addParticle(*P_child_composition);
100  }
101  } else if (childlist[i]->modelType() == "MesoCrystal") {
102  auto* mesocrystal_item = static_cast<MesoCrystalItem*>(childlist[i]);
103  auto P_child_meso = mesocrystal_item->createMesoCrystal();
104  if (P_child_meso) {
105  P_composition->addParticle(*P_child_meso);
106  }
107  }
108  }
109  TransformToDomain::setTransformationInfo(P_composition.get(), *this);
110 
111  return P_composition;
112 }
Defines class MesoCrystalItem.
Defines class MesoCrystal.
Defines ModelPath namespace.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines ParticleCoreShell.
Defines class ParticleItem.
Defines class Particle.
Defines namespace SessionItemUtils.
Defines class TransformToDomain.
Defines class VectorItem.
std::unique_ptr< MesoCrystal > createMesoCrystal() const
void setOnParentChange(std::function< void(SessionItem *)> f, const void *caller=0)
Calls back when parent has changed, reports newParent.
Definition: ModelMapper.cpp:60
VectorItem * positionItem() const
static const QString T_PARTICLES
std::unique_ptr< ParticleComposition > createParticleComposition() const
std::unique_ptr< ParticleCoreShell > createParticleCoreShell() const
std::unique_ptr< Particle > createParticle() const
static const QString P_ABUNDANCE
Definition: ParticleItem.h:26
static const QString T_TRANSFORMATION
Definition: ParticleItem.h:29
static const QString P_POSITION
Definition: ParticleItem.h:28
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:125
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.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
ModelMapper * mapper()
Returns the current model mapper of this item. Creates new one if necessary.
SessionItem * parent() const
Returns parent of this item.
Definition: SessionItem.cpp:73
void setDefaultTag(const QString &tag)
Set default tag.
void addTranslator(const IPathTranslator &translator)
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
QVector< SessionItem * > children() const
Returns vector of all children.
SessionItem & setToolTip(const QString &tooltip)
QString modelType() const
Get model type.
void setEnabled(bool enabled)
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem & setLimits(const RealLimits &value)
bool HasOwnAbundance(const SessionItem *item)
void setTransformationInfo(IParticle *result, const SessionItem &item)