BornAgain  1.19.79
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/Model/Sample/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 
20 #include "GUI/Util/Error.h"
21 #include "Sample/Particle/Particle.h"
22 #include "Sample/Particle/ParticleCoreShell.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  : ItemWithParticles(abundance_tooltip, position_tooltip)
37  , m_materials(materials)
38 {
39 }
40 
42 {
43  s.assertVersion(0);
48 }
49 
50 std::unique_ptr<ParticleCoreShell> ParticleCoreShellItem::createParticleCoreShell() const
51 {
52  std::unique_ptr<Particle> P_core{};
53  std::unique_ptr<Particle> P_shell{};
54  if (m_core)
55  P_core = m_core->createParticle();
56  if (m_shell)
57  P_shell = m_shell->createParticle();
58  if (!P_core || !P_shell)
59  throw Error("ParticleCoreShellItem::createParticleCoreShell -> Error. Either "
60  "core or shell particle is undefined.");
61  auto P_coreshell = std::make_unique<ParticleCoreShell>(*P_shell, *P_core);
62  P_coreshell->setAbundance(abundance());
63  P_coreshell->setParticlePosition(position());
64  if (auto r = createRotation(); r && !r->isIdentity())
65  P_coreshell->setRotation(*r);
66 
67  return P_coreshell;
68 }
69 
71 {
72  return m_core.get();
73 }
74 
76 {
77  m_core.reset();
78 }
79 
81 {
82  m_core.reset(new ParticleItem(materials));
83  m_core->setMaterial(materials->defaultMaterial());
84  return m_core.get();
85 }
86 
88 {
89  return m_shell.get();
90 }
91 
93 {
94  m_shell.reset();
95 }
96 
98 {
99  m_shell.reset(new ParticleItem(materials));
100  m_shell->setMaterial(materials->defaultMaterial());
101 
102  // position is not used for shell item
103  m_shell->setPosition({});
104  return m_shell.get();
105 }
106 
107 QVector<ItemWithParticles*> ParticleCoreShellItem::containedItemsWithParticles() const
108 {
109  QVector<ItemWithParticles*> result;
110  if (core())
111  result << core() << core()->containedItemsWithParticles();
112  if (shell())
113  result << shell() << shell()->containedItemsWithParticles();
114  return result;
115 }
Defines class DoubleDescriptor.
Defines error class.
Defines class MaterialItems.
Defines class ParticleCoreShellItem.
Defines class ParticleItem.
Defines namespace GUI::Util::Variant.
VectorProperty m_position
std::unique_ptr< IRotation > createRotation() const
nullptr only if "no rotation". Can contain identity!
DoubleDescriptor abundance() const
DoubleProperty m_abundance
MaterialItem * defaultMaterial() const
ParticleItem * shell() const
ParticleItem * core() const
std::unique_ptr< ParticleItem > m_core
std::unique_ptr< ParticleItem > m_shell
ParticleCoreShellItem(const MaterialItems *materials)
void serialize(Streamer &s) override
ParticleItem * createShell(const MaterialItems *materials)
const MaterialItems * m_materials
QVector< ItemWithParticles * > containedItemsWithParticles() const override
Return full hierarchical contained items with particles.
std::unique_ptr< ParticleCoreShell > createParticleCoreShell() const
ParticleItem * createCore(const MaterialItems *materials)
QVector< ItemWithParticles * > containedItemsWithParticles() const override
Return full hierarchical contained items with particles.
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 rwOptional(Streamer &s, const QString &tag, std::unique_ptr< ItemClass > &up, ArgsForConstructor... argsForConstructor)
Serializes an optional item of known type. Passes optional arguments to the constructor.
Definition: Serialize.h:142