BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ParticleItem.cpp
6 //! @brief Implements class ParticleItem
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 
34 } // namespace
35 
36 const QString ParticleItem::P_FORM_FACTOR = "Form Factor";
37 const QString ParticleItem::P_ABUNDANCE = QString::fromStdString("Abundance");
38 const QString ParticleItem::P_MATERIAL = "Material";
39 const QString ParticleItem::P_POSITION = "Position Offset";
40 const QString ParticleItem::T_TRANSFORMATION = "Transformation Tag";
41 
43 {
44  addGroupProperty(P_FORM_FACTOR, "Form Factor");
46  ->setToolTip("Material of particle")
47  .setEditorType("ExtMaterialEditor");
48 
50  ->setLimits(RealLimits::limited(0.0, 1.0))
51  .setDecimals(3)
52  .setToolTip(abundance_tooltip);
53  addProperty<VectorItem>(P_POSITION)->setToolTip(position_tooltip);
54 
55  registerTag(T_TRANSFORMATION, 0, 1, QStringList() << "Rotation");
57 
60 
62  [this](SessionItem* newParent) { updatePropertiesAppearance(newParent); });
63 }
64 
66 {
67  return item<VectorItem>(P_POSITION);
68 }
69 
70 std::unique_ptr<Particle> ParticleItem::createParticle() const
71 {
72  auto& ffItem = groupItem<FormFactorItem>(ParticleItem::P_FORM_FACTOR);
73  auto material = TransformToDomain::createDomainMaterial(*this);
74  double abundance = getItemValue(ParticleItem::P_ABUNDANCE).toDouble();
75 
76  auto particle = std::make_unique<Particle>(*material, *ffItem.createFormFactor());
77  particle->setAbundance(abundance);
78 
79  TransformToDomain::setTransformationInfo(particle.get(), *this);
80 
81  return particle;
82 }
83 
84 QVector<SessionItem*> ParticleItem::materialPropertyItems()
85 {
86  auto item = getItem(P_MATERIAL);
87  if (!item)
88  return {};
89  return {item};
90 }
91 
92 //! Updates enabled/disabled for particle position and particle abundance depending on context.
93 
95 {
96  if (SessionItemUtils::HasOwnAbundance(newParent)) {
99  if (isShellParticle()) {
100  auto pos = positionItem();
101  pos->setVector(kvector_t());
102  pos->setEnabled(false);
103  }
104  } else {
106  positionItem()->setEnabled(true);
107  }
108 }
109 
110 //! Returns true if this particle is a shell particle.
111 
113 {
114  if (!parent())
115  return false;
116 
117  return parent()->modelType() == "ParticleCoreShell"
119 }
120 
121 //! Returns true if this particle is directly connected to a ParticleLayout
122 
124 {
125  if (!parent())
126  return false;
127 
128  return parent()->modelType() == "ParticleLayout";
129 }
Defines FormFactorItems classes.
Defines and implements interface IFormFactor.
Defines class MaterialItemUtils.
Defines ModelPath namespace.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class Particle.
Defines namespace SessionItemUtils.
Defines class SessionModel.
Defines class TransformToDomain.
Defines class VectorItem.
BasicVector3D< double > kvector_t
Definition: Vectors3D.h:21
void setOnParentChange(std::function< void(SessionItem *)> f, const void *caller=0)
Calls back when parent has changed, reports newParent.
Definition: ModelMapper.cpp:60
static const QString T_SHELL
VectorItem * positionItem() const
std::unique_ptr< Particle > createParticle() const
static const QString P_MATERIAL
Definition: ParticleItem.h:27
bool isShellParticle() const
Returns true if this particle is a shell particle.
QVector< SessionItem * > materialPropertyItems()
static const QString P_ABUNDANCE
Definition: ParticleItem.h:26
bool parentIsParticleLayout() const
Returns true if this particle is directly connected to a ParticleLayout.
static const QString T_TRANSFORMATION
Definition: ParticleItem.h:29
static const QString P_POSITION
Definition: ParticleItem.h:28
void updatePropertiesAppearance(SessionItem *)
Updates enabled/disabled for particle position and particle abundance depending on context.
static const QString P_FORM_FACTOR
Definition: ParticleItem.h:25
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.
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.
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)
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)
QString modelType() const
Get model type.
QString tagFromItem(const SessionItem *item) const
Returns the tag name of given item when existing.
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)
ExternalProperty defaultMaterialProperty()
bool HasOwnAbundance(const SessionItem *item)
void setTransformationInfo(IParticle *result, const SessionItem &item)
std::unique_ptr< Material > createDomainMaterial(const SessionItem &item)