BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleCoreShellItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/ParticleCoreShellItem.cpp
6 //! @brief Implements class ParticleCoreShellItem
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 
24 
25 namespace {
26 const QString abundance_tooltip = "Proportion of this type of particles normalized to the \n"
27  "total number of particles in the layout";
28 
29 const QString position_tooltip = "Relative position of the particle's reference point \n"
30  "in the coordinate system of the parent (nm)";
31 
32 } // namespace
33 
34 const QString ParticleCoreShellItem::T_CORE = "Core tag";
35 const QString ParticleCoreShellItem::T_SHELL = "Shell tag";
36 
37 // TODO make ParticleCoreShellItem and ParticleItem to derive from common base.
38 
40 {
41  setToolTip("A particle with a core/shell geometry");
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_CORE, 0, 1, QStringList() << "Particle");
51  registerTag(T_SHELL, 0, 1, QStringList() << "Particle");
52  registerTag(ParticleItem::T_TRANSFORMATION, 0, 1, QStringList() << "Rotation");
53 
56 
61  } else {
63  }
64  });
65 }
66 
68 {
69  return item<VectorItem>(ParticleItem::P_POSITION);
70 }
71 
72 std::unique_ptr<ParticleCoreShell> ParticleCoreShellItem::createParticleCoreShell() const
73 {
74  double abundance = getItemValue(ParticleItem::P_ABUNDANCE).toDouble();
75  std::unique_ptr<Particle> P_core{};
76  std::unique_ptr<Particle> P_shell{};
77  auto core_item = dynamic_cast<ParticleItem*>(getItem(T_CORE));
78  if (core_item)
79  P_core = core_item->createParticle();
80  auto shell_item = dynamic_cast<ParticleItem*>(getItem(T_SHELL));
81  if (shell_item)
82  P_shell = shell_item->createParticle();
83  if (!P_core || !P_shell)
84  throw GUIHelpers::Error("ParticleCoreShellItem::createParticleCoreShell -> Error. Either "
85  "core or shell particle is undefined.");
86  auto P_coreshell = std::make_unique<ParticleCoreShell>(*P_shell, *P_core);
87  P_coreshell->setAbundance(abundance);
88  TransformToDomain::setTransformationInfo(P_coreshell.get(), *this);
89  return P_coreshell;
90 }
91 
93 {
94  QVector<SessionItem*> result;
95  if (auto core = static_cast<ParticleItem*>(getItem(T_CORE)))
96  result.append(core->materialPropertyItems());
97 
98  if (auto shell = static_cast<ParticleItem*>(getItem(T_SHELL)))
99  result.append(shell->materialPropertyItems());
100 
101  return result;
102 }
Defines class GUIHelpers functions.
Defines ModelPath namespace.
Defines class ParticleCoreShellItem.
Defines ParticleCoreShell.
Defines class ParticleItem.
Defines class Particle.
Defines namespace SessionItemUtils.
Defines class TransformToDomain.
Defines class VectorItem.
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_CORE
QVector< SessionItem * > materialPropertyItems()
static const QString T_SHELL
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 addTranslator(const IPathTranslator &translator)
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.
SessionItem & setLimits(const RealLimits &value)
bool HasOwnAbundance(const SessionItem *item)
void setTransformationInfo(IParticle *result, const SessionItem &item)