LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
polygon.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_POLYGON_H
21 #define LIBREPCB_POLYGON_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 #include "path.h"
33 
34 #include <QtCore>
35 #include <QtWidgets>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 namespace librepcb {
41 
42 /*******************************************************************************
43  * Interface IF_PolygonObserver
44  ******************************************************************************/
45 
53 public:
54  virtual void polygonLayerNameChanged(
55  const GraphicsLayerName& newLayerName) noexcept = 0;
56  virtual void polygonLineWidthChanged(
57  const UnsignedLength& newLineWidth) noexcept = 0;
58  virtual void polygonIsFilledChanged(bool newIsFilled) noexcept = 0;
59  virtual void polygonIsGrabAreaChanged(bool newIsGrabArea) noexcept = 0;
60  virtual void polygonPathChanged(const Path& newPath) noexcept = 0;
61 
62 protected:
63  IF_PolygonObserver() noexcept {}
64  explicit IF_PolygonObserver(const IF_PolygonObserver& other) = delete;
65  virtual ~IF_PolygonObserver() noexcept {}
66  IF_PolygonObserver& operator=(const IF_PolygonObserver& rhs) = delete;
67 };
68 
69 /*******************************************************************************
70  * Class Polygon
71  ******************************************************************************/
72 
76 class Polygon final : public SerializableObject {
77  Q_DECLARE_TR_FUNCTIONS(Polygon)
78 
79 public:
80  // Constructors / Destructor
81  Polygon() = delete;
82  Polygon(const Polygon& other) noexcept;
83  Polygon(const Uuid& uuid, const Polygon& other) noexcept;
84  Polygon(const Uuid& uuid, const GraphicsLayerName& layerName,
85  const UnsignedLength& lineWidth, bool fill, bool isGrabArea,
86  const Path& path) noexcept;
87  explicit Polygon(const SExpression& node);
88  ~Polygon() 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 Path& getPath() const noexcept { return mPath; }
97 
98  // Setters
99  void setLayerName(const GraphicsLayerName& name) noexcept;
100  void setLineWidth(const UnsignedLength& width) noexcept;
101  void setIsFilled(bool isFilled) noexcept;
102  void setIsGrabArea(bool isGrabArea) noexcept;
103  void setPath(const Path& path) noexcept;
104 
105  // General Methods
106  void registerObserver(IF_PolygonObserver& object) const noexcept;
107  void unregisterObserver(IF_PolygonObserver& object) const noexcept;
108 
110  void serialize(SExpression& root) const override;
111 
112  // Operator Overloadings
113  bool operator==(const Polygon& rhs) const noexcept;
114  bool operator!=(const Polygon& rhs) const noexcept { return !(*this == rhs); }
115  Polygon& operator=(const Polygon& rhs) noexcept;
116 
117 private: // Data
121  bool mIsFilled;
124 
125  // Misc
126  mutable QSet<IF_PolygonObserver*>
128 };
129 
130 /*******************************************************************************
131  * Class PolygonList
132  ******************************************************************************/
133 
135  static constexpr const char* tagname = "polygon";
136 };
141 
142 /*******************************************************************************
143  * End of File
144  ******************************************************************************/
145 
146 } // namespace librepcb
147 
148 #endif // LIBREPCB_POLYGON_H
Definition: polygon.h:134
UnsignedLength mLineWidth
Definition: polygon.h:120
Polygon & operator=(const Polygon &rhs) noexcept
Definition: polygon.cpp:154
virtual void polygonIsFilledChanged(bool newIsFilled) noexcept=0
const GraphicsLayerName & getLayerName() const noexcept
Definition: polygon.h:92
void setIsGrabArea(bool isGrabArea) noexcept
Definition: polygon.cpp:103
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
IF_PolygonObserver() noexcept
Definition: polygon.h:63
bool isGrabArea() const noexcept
Definition: polygon.h:95
bool operator!=(const Polygon &rhs) const noexcept
Definition: polygon.h:114
type_safe::constrained_type< QString, GraphicsLayerNameConstraint, GraphicsLayerNameVerifier > GraphicsLayerName
Definition: graphicslayername.h:78
bool mIsFilled
Definition: polygon.h:121
QSet< IF_PolygonObserver * > mObservers
A list of all observer objects.
Definition: polygon.h:127
void setLayerName(const GraphicsLayerName &name) noexcept
Definition: polygon.cpp:79
virtual ~IF_PolygonObserver() noexcept
Definition: polygon.h:65
GraphicsLayerName mLayerName
Definition: polygon.h:119
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
Uuid mUuid
Definition: polygon.h:118
void setLineWidth(const UnsignedLength &width) noexcept
Definition: polygon.cpp:87
virtual void polygonLayerNameChanged(const GraphicsLayerName &newLayerName) noexcept=0
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: polygon.cpp:131
bool operator==(const Polygon &rhs) const noexcept
Definition: polygon.cpp:144
virtual void polygonIsGrabAreaChanged(bool newIsGrabArea) noexcept=0
void setIsFilled(bool isFilled) noexcept
Definition: polygon.cpp:95
Path mPath
Definition: polygon.h:123
static constexpr const char * tagname
Definition: polygon.h:135
The IF_PolygonObserver class.
Definition: polygon.h:52
void registerObserver(IF_PolygonObserver &object) const noexcept
Definition: polygon.cpp:123
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
bool mIsGrabArea
Definition: polygon.h:122
virtual void polygonPathChanged(const Path &newPath) noexcept=0
void setPath(const Path &path) noexcept
Definition: polygon.cpp:111
bool isFilled() const noexcept
Definition: polygon.h:94
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
const Uuid & getUuid() const noexcept
Definition: polygon.h:91
virtual void polygonLineWidthChanged(const UnsignedLength &newLineWidth) noexcept=0
~Polygon() noexcept
Definition: polygon.cpp:72
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
const Path & getPath() const noexcept
Definition: polygon.h:96
The Polygon class.
Definition: polygon.h:76
The SExpression class.
Definition: sexpression.h:60
IF_PolygonObserver & operator=(const IF_PolygonObserver &rhs)=delete
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
const UnsignedLength & getLineWidth() const noexcept
Definition: polygon.h:93
void unregisterObserver(IF_PolygonObserver &object) const noexcept
Definition: polygon.cpp:127