BornAgain  1.19.79
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/Model/Sample/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 2021
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
22 #include "Sample/Particle/MesoCrystal.h"
23 #include "Sample/Particle/Particle.h"
24 #include "Sample/Particle/ParticleCoreShell.h"
25 #include "Sample/Scattering/Rotations.h"
26 
27 namespace {
28 
29 const QString abundance_tooltip = "Proportion of this type of particles normalized to the \n"
30  "total number of particles in the layout";
31 
32 const QString position_tooltip = "Relative position of the particle's reference point \n"
33  "in the coordinate system of the parent (nm)";
34 
35 } // namespace
36 
37 
39  : ItemWithParticles(abundance_tooltip, position_tooltip)
40  , m_materials(materials)
41 {
42  ASSERT(m_materials);
43 }
44 
46 {
47  s.assertVersion(0);
50  Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
51  Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, "Particles", m_particles, m_materials);
52 }
53 
54 std::unique_ptr<ParticleComposition> ParticleCompositionItem::createParticleComposition() const
55 {
56  auto P_composition = std::make_unique<ParticleComposition>();
57  P_composition->setAbundance(abundance());
58  for (auto* p : m_particles) {
59  if (auto* particleItem = dynamic_cast<ParticleItem*>(p)) {
60  if (auto P_particle = particleItem->createParticle())
61  P_composition->addParticle(*P_particle);
62  } else if (auto* coreShellItem = dynamic_cast<ParticleCoreShellItem*>(p)) {
63  if (auto P_particle_coreshell = coreShellItem->createParticleCoreShell())
64  P_composition->addParticle(*P_particle_coreshell);
65  } else if (auto* compositionItem = dynamic_cast<ParticleCompositionItem*>(p)) {
66  if (auto P_child_composition = compositionItem->createParticleComposition())
67  P_composition->addParticle(*P_child_composition);
68  } else if (auto* mesoCrystalItem = dynamic_cast<MesoCrystalItem*>(p)) {
69  if (auto P_meso = mesoCrystalItem->createMesoCrystal())
70  P_composition->addParticle(*P_meso);
71  }
72  }
73 
74  P_composition->setParticlePosition(position());
75  if (const auto r = createRotation(); r && !r->isIdentity())
76  P_composition->setRotation(*r);
77 
78  return P_composition;
79 }
80 
81 QVector<ItemWithParticles*> ParticleCompositionItem::particles() const
82 {
83  return m_particles;
84 }
85 
87 {
88  m_particles << particle;
89 }
90 
92 {
93  m_particles.removeAll(particle);
94  delete particle;
95 }
96 
97 QVector<ItemWithParticles*> ParticleCompositionItem::containedItemsWithParticles() const
98 {
99  QVector<ItemWithParticles*> result;
100  for (auto* particle : m_particles)
101  result << particle << particle->containedItemsWithParticles();
102  return result;
103 }
Defines class ItemWithParticlesCatalog.
Defines class MesoCrystalItem.
Defines class ParticleCompositionItem.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines class RotationItemCatalog.
Defines class Streamer.
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
QVector< ItemWithParticles * > containedItemsWithParticles() const override
Return full hierarchical contained items with particles.
void addParticle(ItemWithParticles *particle)
QVector< ItemWithParticles * > particles() const
const MaterialItems * m_materials
ParticleCompositionItem(const MaterialItems *materials)
void serialize(Streamer &s) override
void removeParticle(ItemWithParticles *particle)
QVector< ItemWithParticles * > m_particles
std::unique_ptr< ParticleComposition > createParticleComposition() const
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)