BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
BeamAngleItems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/BeamAngleItems.cpp
6 //! @brief Implements class BeamAngleItems
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 
16 #include "Base/Const/Units.h"
19 
21 {
23  "Distribution", "", "distribution", DistributionItemCatalog::types(), initDistribution);
24 }
25 
27 {
28  s.assertVersion(0);
29  Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution);
30 
31  if (s.xmlReader()) {
32  m_distribution->setLimits(RealLimits::limited(-90.0, 90.0));
34  }
35 }
36 
38  const DistributionItem* currentDistribution)
39 {
40  newDistribution->setLimits(RealLimits::limited(-90.0, 90.0));
41  newDistribution->setUnit(Unit::degree);
42 
43  double meanVal = 0.0;
44  if (auto* cd = dynamic_cast<const SymmetricResolutionItem*>(currentDistribution))
45  meanVal = cd->mean();
46 
47  if (auto* nd = dynamic_cast<SymmetricResolutionItem*>(newDistribution)) {
48  nd->setMean(meanVal);
49  nd->setMeanDecimals(3);
50  }
51 
52  newDistribution->initDistribution(meanVal);
53 };
54 
56 {
58 }
59 
61 {
62  return Units::deg;
63 }
64 
65 // ------------------------------------------------------------------------------------------------
66 
68 {
70  "Distribution", "", "distribution", DistributionItemCatalog::types(), initDistribution);
71 }
72 
73 
75 {
76  s.assertVersion(0);
77  Serialize::rwSelected<DistributionItemCatalog>(s, m_distribution);
78 
79  if (s.xmlReader()) {
80  m_distribution->setLimits(RealLimits::limited(-90.0, 90.0));
82  }
83 }
84 
86 {
88 }
89 
91 {
92  return Units::deg;
93 }
94 
96  const DistributionItem* currentDistribution)
97 {
98  newDistribution->setLimits(RealLimits::limited(-90.0, 90.0));
99  newDistribution->setUnit(Unit::degree);
100 
101  double meanVal = 0.2;
102  if (auto* cd = dynamic_cast<const SymmetricResolutionItem*>(currentDistribution))
103  meanVal = cd->mean();
104 
105  if (auto* nd = dynamic_cast<SymmetricResolutionItem*>(newDistribution)) {
106  nd->setMean(meanVal);
107  nd->setMeanDecimals(3);
108  }
109 
110  newDistribution->initDistribution(meanVal);
111 }
Defines class BeamAngleItems.
Defines class DistributionItemCatalog.
Defines class Streamer.
@ degree
static void initDistribution(DistributionItem *newDistribution, const DistributionItem *currentDistribution)
double azimuthalAngle() const
double scaleFactor() const override
void serialize(Streamer &s) override
SelectionProperty< DistributionItem * > m_distribution
virtual double meanValue() const
void serialize(Streamer &s) override
double inclinationAngle() const
double scaleFactor() const override
static void initDistribution(DistributionItem *newDistribution, const DistributionItem *currentDistribution)
static QVector< Type > types()
Available types of items.
virtual void setLimits(const RealLimits &limits)
virtual void initDistribution(double)
virtual void setUnit(const variant< QString, Unit > &unit)=0
Set the unit of the distributed value.
void initWithInitializer(const QString &label, const QString &tooltip, const QString &persistentTag, std::function< void(T newItem, const T oldItem)> initializer)
Initialize by means of a catalog class and an initializer function.
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
Definition: Streamer.h:48
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
Definition: Streamer.cpp:26