BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
VectorDescriptor.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Descriptor/VectorDescriptor.h
6 //! @brief Defines class VectorDescriptor
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 
15 #ifndef BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORDESCRIPTOR_H
16 #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORDESCRIPTOR_H
17 
18 
20 #include <heinz/Vectors3D.h>
21 
22 //! Describes properties of a 3D vector, consisting of three double values.
23 //!
24 //! By using this class, the underlying data scheme is hidden from the user of the data. This e.g.
25 //! eases SessionItem migration. The underlying implementation can be a R3 vector, a member array
26 //! of three doubles, three double members, or any other construction to hold the three values.
27 //!
28 //! \a VectorProperty
29 //! \a DoubleDescriptor
30 //!
32 public:
33  VectorDescriptor() = default;
34 
35  VectorDescriptor(const QString& label, const QString& tooltip, double* xVar, double* yVar,
36  double* zVar, const variant<QString, Unit>& unit)
37  : label(label)
38  , tooltip(tooltip)
39  , x("X", xVar, unit)
40  , y("Y", yVar, unit)
41  , z("Z", zVar, unit)
42  {
43  x.limits = RealLimits::limitless();
44  y.limits = RealLimits::limitless();
45  z.limits = RealLimits::limitless();
46  x.decimals = 3;
47  y.decimals = 3;
48  z.decimals = 3;
49  x.tooltip = tooltip;
50  y.tooltip = tooltip;
51  z.tooltip = tooltip;
52  }
53 
54  VectorDescriptor(const QString& label, const QString& tooltip,
55  const variant<QString, Unit>& unit)
56  : label(label)
57  , tooltip(tooltip)
58  {
59  x.limits = RealLimits::limitless();
60  y.limits = RealLimits::limitless();
61  z.limits = RealLimits::limitless();
62  x.decimals = 3;
63  y.decimals = 3;
64  z.decimals = 3;
65  x.tooltip = tooltip;
66  y.tooltip = tooltip;
67  z.tooltip = tooltip;
68  x.unit = unit;
69  y.unit = unit;
70  z.unit = unit;
71  x.label = "x";
72  y.label = "y";
73  z.label = "z";
74  }
75 
76  void init(const QString& _label, const QString& _tooltip, const R3* vec,
77  const variant<QString, Unit>& _unit)
78  {
79  label = _label;
80  tooltip = _tooltip;
81  x.limits = RealLimits::limitless();
82  y.limits = RealLimits::limitless();
83  z.limits = RealLimits::limitless();
84  x.decimals = 3;
85  y.decimals = 3;
86  z.decimals = 3;
87  x.tooltip = tooltip;
88  y.tooltip = tooltip;
89  z.tooltip = tooltip;
90  x.unit = _unit;
91  y.unit = _unit;
92  z.unit = _unit;
93  x.label = "x";
94  y.label = "y";
95  z.label = "z";
96  x.set = [=](double v) { const_cast<R3*>(vec)->setX(v); };
97  x.get = [=]() { return vec->x(); };
98  x.path = [=] { return uid() + "x"; };
99  y.set = [=](double v) { const_cast<R3*>(vec)->setY(v); };
100  y.get = [=]() { return vec->y(); };
101  y.path = [=] { return uid() + "y"; };
102  z.set = [=](double v) { const_cast<R3*>(vec)->setZ(v); };
103  z.get = [=]() { return vec->z(); };
104  z.path = [=] { return uid() + "z"; };
105  }
106 
107 
108  QString label; //!< A label text (short, no trailing colon)
109  QString tooltip; //!< Tooltip text
113  function<QString()> uid; //!< unique id describing this value. Used e.g. for undo/redo
114 };
115 
116 #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORDESCRIPTOR_H
Defines class DoubleDescriptor.
Describes properties of a double value which are necessary to allow GUI representation,...
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString label
A label text (short, no trailing colon)
function< void(double)> set
function to set the value
RealLimits limits
Limits of the value.
function< double()> get
function to get the current value
QString tooltip
Tooltip text.
int decimals
numbers of decimals to be shown in an edit control
function< QString()> path
Path describing this value. Used e.g. for undo/redo.
Describes properties of a 3D vector, consisting of three double values.
QString tooltip
Tooltip text.
VectorDescriptor(const QString &label, const QString &tooltip, const variant< QString, Unit > &unit)
void init(const QString &_label, const QString &_tooltip, const R3 *vec, const variant< QString, Unit > &_unit)
VectorDescriptor()=default
VectorDescriptor(const QString &label, const QString &tooltip, double *xVar, double *yVar, double *zVar, const variant< QString, Unit > &unit)
DoubleDescriptor y
DoubleDescriptor x
function< QString()> uid
unique id describing this value. Used e.g. for undo/redo
QString label
A label text (short, no trailing colon)
DoubleDescriptor z