BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
ParticleLayoutItem Class Reference

Description

Definition at line 28 of file ParticleLayoutItem.h.

Collaboration diagram for ParticleLayoutItem:
[legend]

Public Member Functions

 ParticleLayoutItem (const MaterialItems *materials)
 
void addParticle (ItemWithParticles *particle)
 
QVector< ItemWithParticles * > containedItemsWithParticles () const
 Return full hierarchical contained items with particles. More...
 
SelectionDescriptor< InterferenceItem * > interference () const
 
DoubleDescriptor ownDensity () const
 The density value which belonging only to the layout. More...
 
QVector< ItemWithParticles * > particles () const
 The particles this layout contains. More...
 
void removeInterference ()
 
void removeParticle (ItemWithParticles *particle)
 
void serialize (Streamer &s)
 
void setInterference (InterferenceItem *interference)
 
DoubleDescriptor totalDensity () const
 The real density. More...
 
bool totalDensityIsDefinedByInterference () const
 Returns whether total density is defined by the currently selected interference. More...
 
double totalDensityValue () const
 
DoubleDescriptor weight () const
 

Private Attributes

SelectionProperty< InterferenceItem * > m_interference
 
const MaterialItemsm_materials
 
DoubleProperty m_ownDensity
 
QVector< ItemWithParticles * > m_particles
 
DoubleProperty m_weight
 

Constructor & Destructor Documentation

◆ ParticleLayoutItem()

ParticleLayoutItem::ParticleLayoutItem ( const MaterialItems materials)

Definition at line 25 of file ParticleLayoutItem.cpp.

26  : m_materials(materials)
27 {
28  m_ownDensity.init("Total particle density",
29  "Number of particles per area (particle surface density).\n "
30  "Should be defined for disordered and 1d-ordered particle collections.",
31  0.01, Unit::nanometerMinus2, 10, RealLimits::nonnegative(), "density");
32  m_weight.init("Weight",
33  "Weight of this particle layout.\nShould be used when multiple layouts define "
34  "different domains in the sample.",
35  1.0, Unit::unitless, "weight");
36 
37  m_interference.init<InterferenceItemCatalog>("Interference function", "", "interference");
38 }
@ nanometerMinus2
@ unitless
void init(const QString &label, const QString &tooltip, double value, const variant< QString, Unit > &unit, const QString &persistentTag)
SelectionProperty< InterferenceItem * > m_interference
const MaterialItems * m_materials
DoubleProperty m_weight
DoubleProperty m_ownDensity
void init(const QString &label, const QString &tooltip, const QString &persistentTag, ArgsForCreation... argsForCreation)
Initialize by means of a catalog class and optional creation arguments.

References SelectionProperty< T >::init(), DoubleProperty::init(), m_interference, m_ownDensity, m_weight, nanometerMinus2, and unitless.

Here is the call graph for this function:

Member Function Documentation

◆ addParticle()

void ParticleLayoutItem::addParticle ( ItemWithParticles particle)

Definition at line 93 of file ParticleLayoutItem.cpp.

94 {
95  m_particles << particle;
96 }
QVector< ItemWithParticles * > m_particles

References m_particles.

Referenced by SampleEditorController::addParticle(), and GUI::Transform::FromCore::itemizeSample().

◆ containedItemsWithParticles()

QVector< ItemWithParticles * > ParticleLayoutItem::containedItemsWithParticles ( ) const

Return full hierarchical contained items with particles.

See also
particles()

Definition at line 104 of file ParticleLayoutItem.cpp.

105 {
106  QVector<ItemWithParticles*> result;
107  for (auto* p : m_particles)
108  result << p << p->containedItemsWithParticles();
109  return result;
110 }

References m_particles.

Referenced by LayerItem::itemsWithParticles().

◆ interference()

◆ ownDensity()

DoubleDescriptor ParticleLayoutItem::ownDensity ( ) const

The density value which belonging only to the layout.

This is the editable value. If an interference is present, this value may not be the one to be used for building the domain layout or to be presented. For the correct value-to-use, whether an interference is present or not, use totalDensity().

Definition at line 40 of file ParticleLayoutItem.cpp.

41 {
42  return m_ownDensity;
43 }

References m_ownDensity.

Referenced by GUI::Transform::FromCore::itemizeSample(), and totalDensity().

◆ particles()

QVector< ItemWithParticles * > ParticleLayoutItem::particles ( ) const

The particles this layout contains.

Note that this is not a hierarchical search! Only the topmost particles are returned, not their contained particles. For a hierarchical search use containedItemsWithParticles

Definition at line 88 of file ParticleLayoutItem.cpp.

89 {
90  return m_particles;
91 }

References m_particles.

Referenced by ParticleLayoutForm::ParticleLayoutForm(), GUI::RealSpace::BuilderUtils::computeCumulativeAbundances(), ParticleLayoutForm::onAboutToRemoveParticle(), ParticleLayoutForm::onParticleAdded(), GUI::RealSpace::BuilderUtils::particle3DContainerVector(), and RealSpaceBuilder::populateLayout().

◆ removeInterference()

void ParticleLayoutItem::removeInterference ( )

Definition at line 122 of file ParticleLayoutItem.cpp.

123 {
124  m_interference.set(nullptr);
125 }
void set(T t, bool callInitializer=false)
Directly set the new item.

References m_interference, and SelectionProperty< T >::set().

Here is the call graph for this function:

◆ removeParticle()

void ParticleLayoutItem::removeParticle ( ItemWithParticles particle)

Definition at line 98 of file ParticleLayoutItem.cpp.

99 {
100  m_particles.removeAll(particle);
101  delete particle;
102 }

References m_particles.

◆ serialize()

void ParticleLayoutItem::serialize ( Streamer s)

Definition at line 133 of file ParticleLayoutItem.cpp.

134 {
135  s.assertVersion(0);
138  Serialize::rwSelected<InterferenceItemCatalog>(s, m_interference);
139  Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, "Particles", m_particles, m_materials);
140 }
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)

References Streamer::assertVersion(), m_interference, m_materials, m_ownDensity, m_particles, m_weight, and Serialize::rwProperty().

Here is the call graph for this function:

◆ setInterference()

void ParticleLayoutItem::setInterference ( InterferenceItem interference)

Definition at line 117 of file ParticleLayoutItem.cpp.

118 {
120 }
SelectionDescriptor< InterferenceItem * > interference() const

References interference(), m_interference, and SelectionProperty< T >::set().

Here is the call graph for this function:

◆ totalDensity()

DoubleDescriptor ParticleLayoutItem::totalDensity ( ) const

The real density.

Returns ownDensity() if the interference is not influencing the density. If the interference is defining the density, this is the interference-calculated density.

Definition at line 45 of file ParticleLayoutItem.cpp.

46 {
47  // create descriptor with same value as own density, then change the getter and setter
49  d.set = [=](double d) {
51  const_cast<DoubleProperty*>(&m_ownDensity)->set(d);
52  };
53  d.get = [=]() { return totalDensityValue(); };
54  d.path = [=]() { return m_ownDensity.uid() + "/totalDensity"; };
55  return d;
56 }
Describes properties of a double value which are necessary to allow GUI representation,...
function< void(double)> set
function to set the value
function< double()> get
function to get the current value
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
Class for representing a double value, its attributes and its accessors.
QString uid() const
Unique id of this double property.
void set(double d)
Set the contained value.
DoubleDescriptor ownDensity() const
The density value which belonging only to the layout.
bool totalDensityIsDefinedByInterference() const
Returns whether total density is defined by the currently selected interference.
double totalDensityValue() const

References DoubleDescriptor::get, m_ownDensity, ownDensity(), DoubleDescriptor::path, DoubleDescriptor::set, DoubleProperty::set(), totalDensityIsDefinedByInterference(), totalDensityValue(), and DoubleProperty::uid().

Referenced by ParticleLayoutForm::ParticleLayoutForm(), and RealSpaceBuilder::populateLayout().

Here is the call graph for this function:

◆ totalDensityIsDefinedByInterference()

bool ParticleLayoutItem::totalDensityIsDefinedByInterference ( ) const

Returns whether total density is defined by the currently selected interference.

Two dimensional interference calculates density automatically; in these cases the "own" total density value should not be edited but set by the one from the interference.

Definition at line 127 of file ParticleLayoutItem.cpp.

128 {
129  return dynamic_cast<const Interference2DAbstractLatticeItem*>(m_interference.get())
130  || dynamic_cast<const InterferenceHardDiskItem*>(m_interference.get());
131 }
T get() const
Direct access to the stored pointer.

References SelectionProperty< T >::get(), and m_interference.

Referenced by totalDensity(), totalDensityValue(), and ParticleLayoutForm::updateDensityEnabling().

Here is the call graph for this function:

◆ totalDensityValue()

double ParticleLayoutItem::totalDensityValue ( ) const

Definition at line 58 of file ParticleLayoutItem.cpp.

59 {
61  return m_ownDensity;
62 
63  ASSERT(m_interference.get());
64 
65  if (const auto* interLatticeItem =
66  dynamic_cast<const Interference2DAbstractLatticeItem*>(m_interference.get())) {
67  Lattice2DItem* latticeItem = interLatticeItem->latticeType().currentItem();
68  try {
69  const double area = latticeItem->unitCellArea();
70  return area == 0.0 ? 0.0 : 1.0 / area;
71  } catch (const std::exception&) {
72  // nothing to do here; new exception will be caught during job execution
73  return 0.0;
74  }
75  }
76 
77  if (const auto* hd = dynamic_cast<const InterferenceHardDiskItem*>(m_interference.get()))
78  return hd->density();
79 
80  ASSERT(false);
81 }
double unitCellArea() const

References SelectionProperty< T >::get(), m_interference, m_ownDensity, totalDensityIsDefinedByInterference(), and Lattice2DItem::unitCellArea().

Referenced by totalDensity().

Here is the call graph for this function:

◆ weight()

DoubleDescriptor ParticleLayoutItem::weight ( ) const

Definition at line 83 of file ParticleLayoutItem.cpp.

84 {
85  return m_weight;
86 }

References m_weight.

Referenced by ParticleLayoutForm::ParticleLayoutForm(), and GUI::Transform::FromCore::itemizeSample().

Member Data Documentation

◆ m_interference

◆ m_materials

const MaterialItems* ParticleLayoutItem::m_materials
private

Definition at line 77 of file ParticleLayoutItem.h.

Referenced by serialize().

◆ m_ownDensity

DoubleProperty ParticleLayoutItem::m_ownDensity
private

◆ m_particles

QVector<ItemWithParticles*> ParticleLayoutItem::m_particles
private

◆ m_weight

DoubleProperty ParticleLayoutItem::m_weight
private

Definition at line 74 of file ParticleLayoutItem.h.

Referenced by ParticleLayoutItem(), serialize(), and weight().


The documentation for this class was generated from the following files: