1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file GUI/Model/Mask/MaskItems.h
//! @brief Defines classes MaskItem, RectangleItem, ..., FullframeItem.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
#ifndef BORNAGAIN_GUI_MODEL_MASK_MASKITEMS_H
#define BORNAGAIN_GUI_MODEL_MASK_MASKITEMS_H
#include "Base/Type/OwningVector.h"
#include "GUI/Model/Descriptor/DoubleProperty.h"
#include "GUI/Model/Mask/OverlayItem.h"
#include <QXmlStreamReader>
class IShape2D;
class PointItem;
//! Abstract base class for mask items that describe one specific shape.
class MaskItem : public OverlayItem {
public:
~MaskItem() override;
virtual std::unique_ptr<IShape2D> createShape() const = 0;
bool maskValue() const { return m_mask_value; }
void setMaskValue(bool mask_value);
bool isVisible() const { return m_is_visible; }
void setIsVisible(bool visible);
bool wasVisible() const { return m_was_visible; }
void setWasVisible(bool v) { m_was_visible = v; }
virtual void writeTo(QXmlStreamWriter* w) const;
virtual void readFrom(QXmlStreamReader* r);
protected:
MaskItem();
bool m_mask_value = true;
bool m_is_visible = true;
bool m_was_visible = m_is_visible; // do not serialize
};
class RectangleItem : public MaskItem {
public:
RectangleItem();
std::unique_ptr<IShape2D> createShape() const override;
DoubleProperty& xLow() { return m_x_low; }
const DoubleProperty& xLow() const { return m_x_low; }
void setXLow(double val);
DoubleProperty& yLow() { return m_y_low; }
const DoubleProperty& yLow() const { return m_y_low; }
void setYLow(double val);
DoubleProperty& xUp() { return m_x_up; }
const DoubleProperty& xUp() const { return m_x_up; }
void setXHig(double val);
DoubleProperty& yUp() { return m_y_up; }
const DoubleProperty& yUp() const { return m_y_up; }
void setYHig(double val);
void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* r) override;
private:
DoubleProperty m_x_low;
DoubleProperty m_y_low;
DoubleProperty m_x_up;
DoubleProperty m_y_up;
};
class RegionOfInterestItem : public RectangleItem {
public:
RegionOfInterestItem();
std::unique_ptr<IShape2D> createShape() const override;
};
class PolygonItem : public MaskItem {
public:
PolygonItem();
std::unique_ptr<IShape2D> createShape() const override;
bool isClosed() const { return m_is_closed; }
void setIsClosed(bool closed);
QVector<PointItem*> points() const;
void addPoint(double x, double y);
void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* r) override;
private:
bool m_is_closed = false;
OwningVector<PointItem> m_points;
};
class LineItem : public MaskItem {
public:
LineItem(double pos);
DoubleProperty& pos() { return m_pos; }
const DoubleProperty& pos() const { return m_pos; }
void setPos(double val);
void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* r) override;
virtual Qt::Orientation orientation() const = 0;
protected:
DoubleProperty m_pos;
};
class VerticalLineItem : public LineItem {
public:
VerticalLineItem(double pos);
std::unique_ptr<IShape2D> createShape() const override;
Qt::Orientation orientation() const override { return Qt::Vertical; }
};
class HorizontalLineItem : public LineItem {
public:
HorizontalLineItem(double pos);
std::unique_ptr<IShape2D> createShape() const override;
Qt::Orientation orientation() const override { return Qt::Horizontal; }
};
class EllipseItem : public MaskItem {
public:
EllipseItem();
std::unique_ptr<IShape2D> createShape() const override;
DoubleProperty& xCenter() { return m_x_center; }
const DoubleProperty& xCenter() const { return m_x_center; }
void setXCenter(double val);
DoubleProperty& yCenter() { return m_y_center; }
const DoubleProperty& yCenter() const { return m_y_center; }
void setYCenter(double val);
DoubleProperty& xRadius() { return m_x_radius; }
const DoubleProperty& xRadius() const { return m_x_radius; }
void setXRadius(double val);
DoubleProperty& yRadius() { return m_y_radius; }
const DoubleProperty& yRadius() const { return m_y_radius; }
void setYRadius(double val);
DoubleProperty& angle() { return m_angle; }
const DoubleProperty& angle() const { return m_angle; }
void setAngle(double val);
void writeTo(QXmlStreamWriter* w) const override;
void readFrom(QXmlStreamReader* r) override;
private:
DoubleProperty m_x_center;
DoubleProperty m_y_center;
DoubleProperty m_x_radius;
DoubleProperty m_y_radius;
DoubleProperty m_angle;
};
class FullframeItem : public MaskItem {
public:
FullframeItem();
std::unique_ptr<IShape2D> createShape() const override;
};
#endif // BORNAGAIN_GUI_MODEL_MASK_MASKITEMS_H
|