LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circle.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_CIRCLE_H
21 #define LIBREPCB_CIRCLE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/cmd/cmdlistelementinsert.h"
27 #include "../fileio/cmd/cmdlistelementremove.h"
28 #include "../fileio/cmd/cmdlistelementsswap.h"
29 #include "../fileio/serializableobjectlist.h"
30 #include "../graphics/graphicslayername.h"
31 #include "../units/all_length_units.h"
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 /*******************************************************************************
41  * Interface IF_CircleObserver
42  ******************************************************************************/
43 
51 public:
52  virtual void circleLayerNameChanged(
53  const GraphicsLayerName& newLayerName) noexcept = 0;
54  virtual void circleLineWidthChanged(
55  const UnsignedLength& newLineWidth) noexcept = 0;
56  virtual void circleIsFilledChanged(bool newIsFilled) noexcept = 0;
57  virtual void circleIsGrabAreaChanged(bool newIsGrabArea) noexcept = 0;
58  virtual void circleCenterChanged(const Point& newCenter) noexcept = 0;
59  virtual void circleDiameterChanged(
60  const PositiveLength& newDiameter) noexcept = 0;
61 
62 protected:
63  IF_CircleObserver() noexcept {}
64  explicit IF_CircleObserver(const IF_CircleObserver& other) = delete;
65  virtual ~IF_CircleObserver() noexcept {}
66  IF_CircleObserver& operator=(const IF_CircleObserver& rhs) = delete;
67 };
68 
69 /*******************************************************************************
70  * Class Circle
71  ******************************************************************************/
72 
76 class Circle : public SerializableObject {
77  Q_DECLARE_TR_FUNCTIONS(Circle)
78 
79 public:
80  // Constructors / Destructor
81  Circle() = delete;
82  Circle(const Circle& other) noexcept;
83  Circle(const Uuid& uuid, const Circle& other) noexcept;
84  Circle(const Uuid& uuid, const GraphicsLayerName& layerName,
85  const UnsignedLength& lineWidth, bool fill, bool isGrabArea,
86  const Point& center, const PositiveLength& diameter) noexcept;
87  explicit Circle(const SExpression& node);
88  virtual ~Circle() noexcept;
89 
90  // Getters
91  const Uuid& getUuid() const noexcept { return mUuid; }
92  const GraphicsLayerName& getLayerName() const noexcept { return mLayerName; }
93  const UnsignedLength& getLineWidth() const noexcept { return mLineWidth; }
94  bool isFilled() const noexcept { return mIsFilled; }
95  bool isGrabArea() const noexcept { return mIsGrabArea; }
96  const Point& getCenter() const noexcept { return mCenter; }
97  const PositiveLength& getDiameter() const noexcept { return mDiameter; }
98 
99  // Setters
100  void setLayerName(const GraphicsLayerName& name) noexcept;
101  void setLineWidth(const UnsignedLength& width) noexcept;
102  void setIsFilled(bool isFilled) noexcept;
103  void setIsGrabArea(bool isGrabArea) noexcept;
104  void setCenter(const Point& center) noexcept;
105  void setDiameter(const PositiveLength& dia) noexcept;
106 
107  // Transformations
108  Circle& translate(const Point& offset) noexcept;
109 
110  // General Methods
111  void registerObserver(IF_CircleObserver& object) const noexcept;
112  void unregisterObserver(IF_CircleObserver& object) const noexcept;
113 
115  void serialize(SExpression& root) const override;
116 
117  // Operator Overloadings
118  bool operator==(const Circle& rhs) const noexcept;
119  bool operator!=(const Circle& rhs) const noexcept { return !(*this == rhs); }
120  Circle& operator=(const Circle& rhs) noexcept;
121 
122 private: // Data
126  bool mIsFilled;
130 
131  // Misc
132  mutable QSet<IF_CircleObserver*>
134 };
135 
136 /*******************************************************************************
137  * Class CircleList
138  ******************************************************************************/
139 
141  static constexpr const char* tagname = "circle";
142 };
147 
148 /*******************************************************************************
149  * End of File
150  ******************************************************************************/
151 
152 } // namespace librepcb
153 
154 #endif // LIBREPCB_CIRCLE_H
Uuid mUuid
Definition: circle.h:123
PositiveLength mDiameter
Definition: circle.h:129
GraphicsLayerName mLayerName
Definition: circle.h:124
virtual void circleLineWidthChanged(const UnsignedLength &newLineWidth) noexcept=0
static constexpr const char * tagname
Definition: circle.h:141
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
Circle & operator=(const Circle &rhs) noexcept
Definition: circle.cpp:201
UnsignedLength mLineWidth
Definition: circle.h:125
virtual void circleCenterChanged(const Point &newCenter) noexcept=0
virtual void circleDiameterChanged(const PositiveLength &newDiameter) noexcept=0
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
bool isGrabArea() const noexcept
Definition: circle.h:95
void registerObserver(IF_CircleObserver &object) const noexcept
Definition: circle.cpp:168
bool operator!=(const Circle &rhs) const noexcept
Definition: circle.h:119
const GraphicsLayerName & getLayerName() const noexcept
Definition: circle.h:92
const Uuid & getUuid() const noexcept
Definition: circle.h:91
void setCenter(const Point &center) noexcept
Definition: circle.cpp:139
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: circle.cpp:176
bool operator==(const Circle &rhs) const noexcept
Definition: circle.cpp:190
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
bool isFilled() const noexcept
Definition: circle.h:94
void setLineWidth(const UnsignedLength &width) noexcept
Definition: circle.cpp:115
virtual void circleLayerNameChanged(const GraphicsLayerName &newLayerName) noexcept=0
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
Circle & translate(const Point &offset) noexcept
Definition: circle.cpp:159
const PositiveLength & getDiameter() const noexcept
Definition: circle.h:97
void setLayerName(const GraphicsLayerName &name) noexcept
Definition: circle.cpp:107
const UnsignedLength & getLineWidth() const noexcept
Definition: circle.h:93
IF_CircleObserver & operator=(const IF_CircleObserver &rhs)=delete
void setIsFilled(bool isFilled) noexcept
Definition: circle.cpp:123
The Circle class.
Definition: circle.h:76
virtual ~Circle() noexcept
Definition: circle.cpp:100
Point mCenter
Definition: circle.h:128
virtual void circleIsGrabAreaChanged(bool newIsGrabArea) noexcept=0
bool mIsGrabArea
Definition: circle.h:127
Definition: circle.h:140
QSet< IF_CircleObserver * > mObservers
A list of all observer objects.
Definition: circle.h:133
void unregisterObserver(IF_CircleObserver &object) const noexcept
Definition: circle.cpp:172
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
void setDiameter(const PositiveLength &dia) noexcept
Definition: circle.cpp:147
void setIsGrabArea(bool isGrabArea) noexcept
Definition: circle.cpp:131
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
IF_CircleObserver() noexcept
Definition: circle.h:63
virtual ~IF_CircleObserver() noexcept
Definition: circle.h:65
The IF_CircleObserver class.
Definition: circle.h:50
The SExpression class.
Definition: sexpression.h:60
const Point & getCenter() const noexcept
Definition: circle.h:96
virtual void circleIsFilledChanged(bool newIsFilled) noexcept=0
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
bool mIsFilled
Definition: circle.h:126