BornAgain  1.19.79
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/Model/Sample/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 
22 #include "Sample/Particle/Particle.h"
23 #include "Sample/Scattering/Rotations.h"
24 
25 namespace {
26 
27 const QString abundance_tooltip = "Proportion of this type of particles normalized to the \n"
28  "total number of particles in the layout";
29 
30 const QString position_tooltip = "Relative position of the particle's reference point \n"
31  "in the coordinate system of the parent (nm)";
32 
33 } // namespace
34 
36  : ItemWithMaterial(materials)
37  , ItemWithParticles(abundance_tooltip, position_tooltip)
38 {
39  m_formFactor.init<FormFactorItemCatalog>("Form Factor", "", "formFactor");
41 }
42 
44 {
45  s.assertVersion(0);
46  Serialize::rwValue(s, "MaterialIdentifier", m_materialIdentifier);
49  Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
50  Serialize::rwSelected<FormFactorItemCatalog>(s, m_formFactor);
51 }
52 
53 std::unique_ptr<Particle> ParticleItem::createParticle() const
54 {
55  auto domainMaterial = materialItem()->createMaterial();
56 
57  auto particle = std::make_unique<Particle>(*domainMaterial, *m_formFactor->createFormFactor());
58  particle->setAbundance(abundance());
59  particle->setParticlePosition(position());
60  if (auto r = createRotation(); r && !r->isIdentity())
61  particle->setRotation(*r);
62 
63  return particle;
64 }
65 
67 {
68  m_formFactor.set(p);
69 }
70 
72 {
73  return m_formFactor.get();
74 }
75 
76 QVector<ItemWithParticles*> ParticleItem::containedItemsWithParticles() const
77 {
78  return {};
79 }
Defines class FormFactorItemCatalog.
Defines FormFactorItems classes.
Defines class MaterialItem.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class RotationItemCatalog.
Defines class Streamer.
virtual std::unique_ptr< IFormFactor > createFormFactor() const =0
QString m_materialIdentifier
MaterialItem * materialItem() const
Returns the material item this item links to.
VectorProperty m_position
SelectionProperty< RotationItem * > m_rotation
std::unique_ptr< IRotation > createRotation() const
nullptr only if "no rotation". Can contain identity!
DoubleDescriptor abundance() const
DoubleProperty m_abundance
std::unique_ptr< Material > createMaterial() const
SelectionProperty< FormFactorItem * > m_formFactor
Definition: ParticleItem.h:40
std::unique_ptr< Particle > createParticle() const
void serialize(Streamer &s) override
ParticleItem(const MaterialItems *materials)
QVector< ItemWithParticles * > containedItemsWithParticles() const override
Return full hierarchical contained items with particles.
FormFactorItem * formfactor_at_bottom() const
void setFormFactor(FormFactorItem *p)
void set(T t, bool callInitializer=false)
Directly set the new item.
T get() const
Direct access to the stored pointer.
void init(const QString &label, const QString &tooltip, const QString &persistentTag, ArgsForCreation... argsForCreation)
Initialize by means of a catalog class and optional creation arguments.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26
void rwProperty(Streamer &s, DoubleProperty &d)
void rwValue(Streamer &s, const QString &tag, bool &val)
Definition: Serialize.cpp:19