BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularBeamInclinationItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/SpecularBeamInclinationItem.cpp
6 //! @brief Implements class SpecularBeamInclinationItem
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 
20 namespace {
21 void setupDistributionMean(SessionItem* distribution);
22 void setAxisPresentationDefaults(SessionItem* axis_item, const QString& type);
23 } // namespace
24 
25 const QString SpecularBeamInclinationItem::P_ALPHA_AXIS = "Alpha axis";
26 
28  : BeamDistributionItem("SpecularBeamInclinationAxis", m_show_mean)
29 {
30  register_distribution_group("Symmetric distribution group");
32  setupDistributionMean(getGroupItem(P_DISTRIBUTION));
33 
35 }
36 
38 
40 {
41  return Units::deg;
42 }
43 
45 {
46  auto group_item = item<GroupItem>(P_ALPHA_AXIS);
47  auto axis_item = group_item->getChildOfType("PointwiseAxis");
48  axis_item->setItemValue(PointwiseAxisItem::P_FILE_NAME, filename);
49 }
50 
52 {
53  auto group_item = dynamic_cast<GroupItem*>(this->addGroupProperty(P_ALPHA_AXIS, "Axes group"));
54 
55  // Both underlying axis items are created, since it
56  // strongly simplifies their representation and state
57  // handling (no signal emulation required).
58  // Basic axis item is the default one.
59 
60  group_item->setCurrentType("PointwiseAxis");
61  setAxisPresentationDefaults(group_item->currentItem(), group_item->currentType());
62 
63  group_item->setCurrentType("BasicAxis");
64  setAxisPresentationDefaults(group_item->currentItem(), group_item->currentType());
65 
66  group_item->setToolTip("Axis type selected");
67  group_item->setDisplayName("Axis type");
68  group_item->setEnabled(false);
69  group_item->mapper()->setOnValueChange(
70  [group_item]() {
71  if (group_item->currentItem()->modelType() == "PointwiseAxis")
72  group_item->setEnabled(true);
73  },
74  this);
75 }
76 
77 namespace {
78 void setupDistributionMean(SessionItem* distribution)
79 {
80  ASSERT(distribution);
81 
82  SessionItem* valueItem = distribution->getItem(DistributionNoneItem::P_MEAN);
83  ASSERT(valueItem);
84 
85  valueItem->setLimits(RealLimits::limited(-90.0, 90.0));
86  valueItem->setDecimals(3);
87  valueItem->setValue(0.0);
88 }
89 
90 void setAxisPresentationDefaults(SessionItem* item, const QString& type)
91 {
92  auto axis_item = dynamic_cast<BasicAxisItem*>(item);
93  Q_ASSERT(axis_item);
94 
95  axis_item->getItem(BasicAxisItem::P_TITLE)->setVisible(false);
96  axis_item->setTitle("alpha_i");
97  axis_item->getItem(BasicAxisItem::P_NBINS)->setToolTip("Number of points in scan");
98  axis_item->getItem(BasicAxisItem::P_MIN_DEG)->setToolTip("Starting value [deg]");
99  axis_item->getItem(BasicAxisItem::P_MAX_DEG)->setToolTip("Ending value [deg]");
100  axis_item->getItem(BasicAxisItem::P_MIN_DEG)->setLimits(RealLimits::limited(0., 90.));
101  axis_item->getItem(BasicAxisItem::P_MAX_DEG)->setLimits(RealLimits::limited(0., 90.));
102 
103  if (type == "BasicAxis") {
104  axis_item->setLowerBound(0.0);
105  axis_item->setUpperBound(3.0);
106  axis_item->setBinCount(500);
107  } else if (type == "PointwiseAxis") {
108  axis_item->getItem(BasicAxisItem::P_MIN_DEG)->setEnabled(false);
109  axis_item->getItem(BasicAxisItem::P_MAX_DEG)->setEnabled(false);
110  axis_item->getItem(BasicAxisItem::P_NBINS)->setEnabled(false);
111  }
112 }
113 } // namespace
#define ASSERT(condition)
Definition: Assert.h:31
Defines class GroupItem.
Defines pointwise axis item.
Declares the class SpecularBeamInclinationItem.
Defines some unit conversion factors and other constants in namespace Units.
static const QString P_NBINS
Definition: AxesItems.h:26
static const QString P_MAX_DEG
Definition: AxesItems.h:28
static const QString P_TITLE
Definition: AxesItems.h:29
static const QString P_MIN_DEG
Definition: AxesItems.h:27
The BeamDistributionItem handles wavelength, inclination and azimuthal parameter distribution for Bea...
void initDistributionItem(bool show_mean)
Propagates the value and limits stored in DistributionNone type into alls distributions.
static const QString P_DISTRIBUTION
void register_distribution_group(const QString &group_type)
SessionItem * setCurrentType(const QString &modelType)
Definition: GroupItem.cpp:51
static const QString P_FILE_NAME
static RealLimits limited(double left_bound_value, double right_bound_value)
Creates an object bounded from the left and right.
Definition: RealLimits.cpp:125
SessionItem & setDecimals(int n)
SessionItem * getGroupItem(const QString &groupName) const
Access subitem of group item.
bool setValue(QVariant value)
Set value, ensure that variant types match.
SessionItem * addGroupProperty(const QString &groupTag, const QString &groupType)
Creates new group item and register new tag, returns GroupItem.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem & setLimits(const RealLimits &value)
double scaleFactor() const override
Scales the values provided by distribution (to perform deg->rad conversion in the case of AngleDistri...
void updateFileName(const QString &filename)
~SpecularBeamInclinationItem() override
static const QString P_MEAN
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
static constexpr double deg
Definition: Units.h:46