BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskItems.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/MaskItems.cpp
6 //! @brief Implements MaskItems classes
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 "Device/Mask/Ellipse.h"
18 #include "Device/Mask/Line.h"
19 #include "Device/Mask/Polygon.h"
20 #include "Device/Mask/Rectangle.h"
22 
24 {
25  const QString T_MASKS = "Mask Tag";
26  QStringList allowedMasks = QStringList() << "RectangleMask"
27  << "PolygonMask"
28  << "EllipseMask"
29  << "VerticalLineMask"
30  << "HorizontalLineMask"
31  << "MaskAllMask"
32  << "RegionOfInterest";
33  registerTag(T_MASKS, 0, -1, allowedMasks);
34  setDefaultTag(T_MASKS);
35 }
36 
37 /* ------------------------------------------------------------------------- */
38 
39 const QString MaskItem::P_MASK_VALUE = "Mask value";
40 const QString MaskItem::P_IS_VISIBLE = "Visibility";
41 
43 {
46 }
47 
48 std::unique_ptr<IShape2D> MaskItem::createShape(double scale) const
49 {
50  Q_UNUSED(scale);
51  throw GUIHelpers::Error("MaskItem::createShape() -> Not implemented.");
52 }
53 
54 /* ------------------------------------------------------------------------- */
55 const QString RectangleItem::P_XLOW = "xlow";
56 const QString RectangleItem::P_YLOW = "ylow";
57 const QString RectangleItem::P_XUP = "xup";
58 const QString RectangleItem::P_YUP = "yup";
59 
60 RectangleItem::RectangleItem(const QString& modelType) : MaskItem(modelType)
61 {
67 }
68 
69 std::unique_ptr<IShape2D> RectangleItem::createShape(double scale) const
70 {
71  double xlow = scale * getItemValue(P_XLOW).toDouble();
72  double ylow = scale * getItemValue(P_YLOW).toDouble();
73  double xup = scale * getItemValue(P_XUP).toDouble();
74  double yup = scale * getItemValue(P_YUP).toDouble();
75  return std::make_unique<Rectangle>(xlow, ylow, xup, yup);
76 }
77 
78 /* ------------------------------------------------------------------------- */
79 
81 {
82  setItemValue(P_MASK_VALUE, false);
83 }
84 
85 /* ------------------------------------------------------------------------- */
86 
87 const QString PolygonPointItem::P_POSX = "X position";
88 const QString PolygonPointItem::P_POSY = "Y position";
89 
91 {
92  setItemName("PolygonPoint");
95 }
96 
97 /* ------------------------------------------------------------------------- */
98 
99 const QString PolygonItem::P_ISCLOSED = "Is closed";
100 
102 {
103  setItemName("PolygonMask");
104  const QString T_POINTS = "Point tag";
105  registerTag(T_POINTS, 0, -1, QStringList() << "PolygonPoint");
106  setDefaultTag(T_POINTS);
107  addProperty(P_ISCLOSED, false)->setVisible(false);
108 }
109 
110 std::unique_ptr<IShape2D> PolygonItem::createShape(double scale) const
111 {
112  std::vector<double> x, y;
113  for (auto item : this->getChildrenOfType("PolygonPoint")) {
114  x.push_back(scale * item->getItemValue(PolygonPointItem::P_POSX).toDouble());
115  y.push_back(scale * item->getItemValue(PolygonPointItem::P_POSY).toDouble());
116  }
117  return std::make_unique<Polygon>(x, y);
118 }
119 
120 /* ------------------------------------------------------------------------- */
121 const QString VerticalLineItem::P_POSX = "X position";
122 
124 {
125  setItemName("VerticalLineMask");
127 }
128 
129 std::unique_ptr<IShape2D> VerticalLineItem::createShape(double scale) const
130 {
131  return std::make_unique<VerticalLine>(scale
132  * getItemValue(VerticalLineItem::P_POSX).toDouble());
133 }
134 
135 /* ------------------------------------------------------------------------- */
136 const QString HorizontalLineItem::P_POSY = "Y position";
137 
139 {
140  setItemName("HorizontalLineMask");
142 }
143 
144 std::unique_ptr<IShape2D> HorizontalLineItem::createShape(double scale) const
145 {
146  return std::make_unique<HorizontalLine>(scale
148 }
149 
150 /* ------------------------------------------------------------------------- */
151 
152 const QString EllipseItem::P_XCENTER = "X position";
153 const QString EllipseItem::P_YCENTER = "Y position";
154 const QString EllipseItem::P_XRADIUS = "X radius";
155 const QString EllipseItem::P_YRADIUS = "Y radius";
156 const QString EllipseItem::P_ANGLE = "Angle";
157 
159 {
160  setItemName("EllipseMask");
163  addProperty(P_XRADIUS, 0.0);
164  addProperty(P_YRADIUS, 0.0);
166 }
167 
168 std::unique_ptr<IShape2D> EllipseItem::createShape(double scale) const
169 {
170  double xcenter = scale * getItemValue(EllipseItem::P_XCENTER).toDouble();
171  double ycenter = scale * getItemValue(EllipseItem::P_YCENTER).toDouble();
172  double xradius = scale * getItemValue(EllipseItem::P_XRADIUS).toDouble();
173  double yradius = scale * getItemValue(EllipseItem::P_YRADIUS).toDouble();
174  double angle = scale * getItemValue(EllipseItem::P_ANGLE).toDouble();
175 
176  return std::make_unique<Ellipse>(xcenter, ycenter, xradius, yradius, angle);
177 }
178 
179 /* ------------------------------------------------------------------------- */
180 
182 {
183  setItemName("MaskAllMask");
185 }
186 
187 std::unique_ptr<IShape2D> MaskAllItem::createShape(double scale) const
188 {
189  Q_UNUSED(scale);
190  return std::make_unique<InfinitePlane>();
191 }
Defines class Rectangle.
Defines class GUIHelpers functions.
Defines class InfinitePlane.
Defines class Line.
Defines MaskItems classes.
Defines class Polygon.
Defines class Rectangle.
static const QString P_XRADIUS
Definition: MaskItems.h:91
static const QString P_YRADIUS
Definition: MaskItems.h:92
static const QString P_XCENTER
Definition: MaskItems.h:89
static const QString P_ANGLE
Definition: MaskItems.h:93
static const QString P_YCENTER
Definition: MaskItems.h:90
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:168
static const QString P_POSY
Definition: MaskItems.h:81
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:144
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:187
A base class for all mask items.
Definition: MaskItems.h:31
MaskItem(const QString &name)
Definition: MaskItems.cpp:42
static const QString P_IS_VISIBLE
Definition: MaskItems.h:34
static const QString P_MASK_VALUE
Definition: MaskItems.h:33
virtual std::unique_ptr< IShape2D > createShape(double scale=1.0) const
Definition: MaskItems.cpp:48
static const QString P_ISCLOSED
Definition: MaskItems.h:65
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:110
static const QString P_POSX
Definition: MaskItems.h:57
static const QString P_POSY
Definition: MaskItems.h:58
static RealLimits limitless()
Creates an object withoud bounds (default)
Definition: RealLimits.cpp:130
static const QString P_XUP
Definition: MaskItems.h:43
static const QString P_YLOW
Definition: MaskItems.h:42
RectangleItem(const QString &modelType="RectangleMask")
Definition: MaskItems.cpp:60
static const QString P_YUP
Definition: MaskItems.h:44
static const QString P_XLOW
Definition: MaskItems.h:41
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:69
void setItemName(const QString &name)
Set item name, add property if necessary.
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
bool registerTag(const QString &name, int min=0, int max=-1, QStringList modelTypes={})
Add new tag to this item with given name, min, max and types.
void setVisible(bool enabled)
Flags accessors.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setDefaultTag(const QString &tag)
Set default tag.
T * item(const QString &tag) const
Definition: SessionItem.h:151
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
QVector< SessionItem * > getChildrenOfType(const QString &model_type) const
Returns a vector of all children of the given type.
QString modelType() const
Get model type.
void setEnabled(bool enabled)
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
SessionItem & setLimits(const RealLimits &value)
virtual std::unique_ptr< IShape2D > createShape(double scale) const
Definition: MaskItems.cpp:129
static const QString P_POSX
Definition: MaskItems.h:73
QString const & name(EShape k)
Definition: particles.cpp:21