BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskItems.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/Model/Device/MaskItems.h
6 //! @brief Defines 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 
15 #ifndef BORNAGAIN_GUI_MODEL_DEVICE_MASKITEMS_H
16 #define BORNAGAIN_GUI_MODEL_DEVICE_MASKITEMS_H
17 
21 
22 class IShape2D;
23 class Streamer;
24 
25 //! A base class for all mask items
26 
27 class MaskItem : public SessionItem {
28 protected:
29  static constexpr auto P_MASK_VALUE{"Mask value"};
30  static constexpr auto P_IS_VISIBLE{"Visibility"};
31 
32 public:
33  virtual std::unique_ptr<IShape2D> createShape(double scale) const = 0;
34 
35  QString maskName() const;
36  void setMaskName(const QString& name);
37 
38  bool maskValue() const;
39  void setMaskValue(bool mask_value);
40  static bool isMaskValuePropertyName(const QString& name);
41 
42  bool isVisibleValue() const;
43  void setIsVisibleValue(bool visible);
44  static bool isIsVisiblePropertyName(const QString& name);
45 
46  virtual void serialize(Streamer& s) = 0;
47 
48 protected:
49  explicit MaskItem(const QString& name);
50  SessionItem* maskValueItem() const;
51 };
52 
53 class RectangleItem : public MaskItem {
54 private:
55  static constexpr auto P_XLOW{"xlow"};
56  static constexpr auto P_YLOW{"ylow"};
57  static constexpr auto P_XUP{"xup"};
58  static constexpr auto P_YUP{"yup"};
59 
60 public:
61  static constexpr auto M_TYPE{"RectangleMask"};
62 
63  explicit RectangleItem();
64  std::unique_ptr<IShape2D> createShape(double scale) const override;
65 
66  DoubleDescriptor xLow() const;
67  void setXLow(double x_low);
68  DoubleDescriptor yLow() const;
69  void setYLow(double y_low);
70  DoubleDescriptor xUp() const;
71  void setXUp(double x_up);
72  DoubleDescriptor yUp() const;
73  void setYUp(double y_up);
74 
75  void serialize(Streamer& s) override;
76 
77 protected:
78  explicit RectangleItem(const QString& modelType);
79 };
80 
82 public:
83  static constexpr auto M_TYPE{"RegionOfInterest"};
84 
86  std::unique_ptr<IShape2D> createShape(double scale) const override;
87 };
88 
89 class PolygonPointItem : public SessionItem {
90 private:
91  static constexpr auto P_POSX{"X position"};
92  static constexpr auto P_POSY{"Y position"};
93 
94 public:
95  static constexpr auto M_TYPE{"PolygonPoint"};
96 
98 
99  double posX() const;
100  void setPosX(double pos_x);
101  double posY() const;
102  void setPosY(double pos_y);
103 
104  void serialize(Streamer& s);
105 };
106 
107 class PolygonItem : public MaskItem {
108 private:
109  static constexpr auto P_ISCLOSED{"Is closed"};
110 
111 public:
112  static constexpr auto M_TYPE{"PolygonMask"};
113 
114  PolygonItem();
115  std::unique_ptr<IShape2D> createShape(double scale) const override;
116 
117  bool isClosed() const;
118  void setIsClosed(bool closed);
119 
120  QVector<PolygonPointItem*> points() const;
121  void addPoint(double x, double y);
122 
123  void serialize(Streamer& s) override;
124 };
125 
126 class VerticalLineItem : public MaskItem {
127 private:
128  static constexpr auto P_POSX{"X position"};
129 
130 public:
131  static constexpr auto M_TYPE{"VerticalLineMask"};
132 
134  std::unique_ptr<IShape2D> createShape(double scale) const override;
135 
136  DoubleDescriptor posX() const;
137  void setPosX(double pos_x);
138 
139  void serialize(Streamer& s) override;
140 };
141 
142 class HorizontalLineItem : public MaskItem {
143 private:
144  static constexpr auto P_POSY{"Y position"};
145 
146 public:
147  static constexpr auto M_TYPE{"HorizontalLineMask"};
148 
150  std::unique_ptr<IShape2D> createShape(double scale) const override;
151 
152  DoubleDescriptor posY() const;
153  void setPosY(double pos_y);
154 
155  void serialize(Streamer& s) override;
156 };
157 
158 class EllipseItem : public MaskItem {
159 private:
160  static constexpr auto P_XCENTER{"X position"};
161  static constexpr auto P_YCENTER{"Y position"};
162  static constexpr auto P_XRADIUS{"X radius"};
163  static constexpr auto P_YRADIUS{"Y radius"};
164  static constexpr auto P_ANGLE{"Angle"};
165 
166 public:
167  static constexpr auto M_TYPE{"EllipseMask"};
168 
169  EllipseItem();
170  std::unique_ptr<IShape2D> createShape(double scale) const override;
171 
172  DoubleDescriptor xCenter() const;
173  void setXCenter(double x_center);
174 
175  DoubleDescriptor yCenter() const;
176  void setYCenter(double y_center);
177 
178  DoubleDescriptor xRadius() const;
179  void setXRadius(double x_radius);
180 
181  DoubleDescriptor yRadius() const;
182  void setYRadius(double y_radius);
183 
184  DoubleDescriptor angle() const;
185  void setAngle(double angle);
186 
187  void serialize(Streamer& s) override;
188 };
189 
190 class MaskAllItem : public MaskItem {
191 public:
192  static constexpr auto M_TYPE{"MaskAllMask"};
193 
194  MaskAllItem();
195  std::unique_ptr<IShape2D> createShape(double scale) const override;
196 
197  void serialize(Streamer& s) override;
198 };
199 
200 //! Container holding various masks as children
201 
203 public:
204  static constexpr auto M_TYPE{"MaskContainer"};
205 
207 
208  QVector<MaskItem*> maskItems() const;
209 
210  //! Insert mask at given row.
211  void insertMask(int row, MaskItem* maskItem);
212 
213  void addMask(MaskItem* maskItem);
214 
215  //! Can be nullptr.
217 
218  //! Remove all masks
219  void clear();
220 };
221 
222 
223 //! List of MaskItems
224 //!
225 //! Makes it possible to keep a list of MaskItems in a class which itself is *not* using
226 //! SessionModel and which is *not* derived from SessionItem.
227 //!
228 //! This class is only for migration away from SessionModel. To keep a list of items which are
229 //! derived from SessionItem, right now a containing SessionModel is necessary. Once MaskItem is not
230 //! derived from SessionItem any more, this class can be replaced by e.g. a simple
231 //! QVector<MaskItem*>
232 class MaskItems : protected SessionModel {
233 public:
234  MaskItems();
235 
236  //! Takes ownership of \a maskItem
237  void insertMask(int index, MaskItem* maskItem);
238 
239  QVector<MaskItem*> maskItems() const;
240 
241  //! Copy the mask items stored in the given maskContainer.
242  //!
243  //! maskContainer can be nullptr.
244  void copy(const MaskContainerItem* maskContainer);
245 
246  //! Removes all maskItems
247  void clear();
248 
249  void serialize(Streamer& s);
250 
251 private:
253 };
254 
255 #endif // BORNAGAIN_GUI_MODEL_DEVICE_MASKITEMS_H
Defines class DoubleDescriptor.
Defines class SessionItem.
Defines class SessionModel.
Describes properties of a double value which are necessary to allow GUI representation,...
static constexpr auto P_XCENTER
Definition: MaskItems.h:160
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:395
static constexpr auto P_XRADIUS
Definition: MaskItems.h:162
void setAngle(double angle)
Definition: MaskItems.cpp:451
DoubleDescriptor yRadius() const
Definition: MaskItems.cpp:436
DoubleDescriptor xRadius() const
Definition: MaskItems.cpp:426
static constexpr auto P_YCENTER
Definition: MaskItems.h:161
static constexpr auto P_ANGLE
Definition: MaskItems.h:164
void setYRadius(double y_radius)
Definition: MaskItems.cpp:441
DoubleDescriptor xCenter() const
Definition: MaskItems.cpp:406
void serialize(Streamer &s) override
Definition: MaskItems.cpp:456
DoubleDescriptor angle() const
Definition: MaskItems.cpp:446
void setYCenter(double y_center)
Definition: MaskItems.cpp:421
void setXCenter(double x_center)
Definition: MaskItems.cpp:411
void setXRadius(double x_radius)
Definition: MaskItems.cpp:431
DoubleDescriptor yCenter() const
Definition: MaskItems.cpp:416
static constexpr auto M_TYPE
Definition: MaskItems.h:167
static constexpr auto P_YRADIUS
Definition: MaskItems.h:163
void setPosY(double pos_y)
Definition: MaskItems.cpp:369
static constexpr auto M_TYPE
Definition: MaskItems.h:147
void serialize(Streamer &s) override
Definition: MaskItems.cpp:374
static constexpr auto P_POSY
Definition: MaskItems.h:144
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:358
DoubleDescriptor posY() const
Definition: MaskItems.cpp:364
void serialize(Streamer &s) override
Definition: MaskItems.cpp:482
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:477
static constexpr auto M_TYPE
Definition: MaskItems.h:192
Container holding various masks as children.
Definition: MaskItems.h:202
void clear()
Remove all masks.
Definition: MaskItems.cpp:63
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:38
static constexpr auto M_TYPE
Definition: MaskItems.h:204
RegionOfInterestItem * regionOfInterestItem() const
Can be nullptr.
Definition: MaskItems.cpp:58
void addMask(MaskItem *maskItem)
Definition: MaskItems.cpp:53
void insertMask(int row, MaskItem *maskItem)
Insert mask at given row.
Definition: MaskItems.cpp:48
A base class for all mask items.
Definition: MaskItems.h:27
virtual std::unique_ptr< IShape2D > createShape(double scale) const =0
static bool isIsVisiblePropertyName(const QString &name)
Definition: MaskItems.cpp:105
MaskItem(const QString &name)
Definition: MaskItems.cpp:110
static bool isMaskValuePropertyName(const QString &name)
Definition: MaskItems.cpp:90
static constexpr auto P_IS_VISIBLE
Definition: MaskItems.h:30
QString maskName() const
Definition: MaskItems.cpp:68
void setMaskValue(bool mask_value)
Definition: MaskItems.cpp:85
void setMaskName(const QString &name)
Definition: MaskItems.cpp:73
void setIsVisibleValue(bool visible)
Definition: MaskItems.cpp:100
static constexpr auto P_MASK_VALUE
Definition: MaskItems.h:29
bool isVisibleValue() const
Definition: MaskItems.cpp:95
bool maskValue() const
Definition: MaskItems.cpp:80
SessionItem * maskValueItem() const
Definition: MaskItems.cpp:117
virtual void serialize(Streamer &s)=0
List of MaskItems.
Definition: MaskItems.h:232
MaskContainerItem * m_maskContainer
Definition: MaskItems.h:252
void clear()
Removes all maskItems.
Definition: MaskItems.cpp:515
void copy(const MaskContainerItem *maskContainer)
Copy the mask items stored in the given maskContainer.
Definition: MaskItems.cpp:507
void insertMask(int index, MaskItem *maskItem)
Takes ownership of maskItem.
Definition: MaskItems.cpp:497
void serialize(Streamer &s)
Definition: MaskItems.cpp:521
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:502
static constexpr auto P_ISCLOSED
Definition: MaskItems.h:109
void setIsClosed(bool closed)
Definition: MaskItems.cpp:278
void addPoint(double x, double y)
Definition: MaskItems.cpp:289
static constexpr auto M_TYPE
Definition: MaskItems.h:112
QVector< PolygonPointItem * > points() const
Definition: MaskItems.cpp:284
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:263
void serialize(Streamer &s) override
Definition: MaskItems.cpp:297
bool isClosed() const
Definition: MaskItems.cpp:273
void serialize(Streamer &s)
Definition: MaskItems.cpp:244
void setPosY(double pos_y)
Definition: MaskItems.cpp:239
static constexpr auto P_POSY
Definition: MaskItems.h:92
void setPosX(double pos_x)
Definition: MaskItems.cpp:229
static constexpr auto P_POSX
Definition: MaskItems.h:91
static constexpr auto M_TYPE
Definition: MaskItems.h:95
double posX() const
Definition: MaskItems.cpp:224
double posY() const
Definition: MaskItems.cpp:234
void serialize(Streamer &s) override
Definition: MaskItems.cpp:188
DoubleDescriptor xLow() const
Definition: MaskItems.cpp:148
static constexpr auto P_XUP
Definition: MaskItems.h:57
DoubleDescriptor yUp() const
Definition: MaskItems.cpp:178
static constexpr auto P_YUP
Definition: MaskItems.h:58
void setXLow(double x_low)
Definition: MaskItems.cpp:153
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:139
DoubleDescriptor yLow() const
Definition: MaskItems.cpp:158
DoubleDescriptor xUp() const
Definition: MaskItems.cpp:168
void setXUp(double x_up)
Definition: MaskItems.cpp:173
void setYLow(double y_low)
Definition: MaskItems.cpp:163
void setYUp(double y_up)
Definition: MaskItems.cpp:183
static constexpr auto P_YLOW
Definition: MaskItems.h:56
static constexpr auto P_XLOW
Definition: MaskItems.h:55
static constexpr auto M_TYPE
Definition: MaskItems.h:61
static constexpr auto M_TYPE
Definition: MaskItems.h:83
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:207
Base class for a GUI data item.
Definition: SessionItem.h:204
QString modelType() const
Get model type.
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42
QModelIndex index(int row, int column, const QModelIndex &parent) const override
Supports serialization to or deserialization from QXmlStream.
Definition: Streamer.h:36
static constexpr auto M_TYPE
Definition: MaskItems.h:131
void serialize(Streamer &s) override
Definition: MaskItems.cpp:341
std::unique_ptr< IShape2D > createShape(double scale) const override
Definition: MaskItems.cpp:325
void setPosX(double pos_x)
Definition: MaskItems.cpp:336
static constexpr auto P_POSX
Definition: MaskItems.h:128
DoubleDescriptor posX() const
Definition: MaskItems.cpp:331
QString const & name(EShape k)
Definition: particles.cpp:20