LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hole.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_HOLE_H
21 #define LIBREPCB_HOLE_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 "../units/all_length_units.h"
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 /*******************************************************************************
40  * Interface IF_HoleObserver
41  ******************************************************************************/
42 
50 public:
51  virtual void holePositionChanged(const Point& newPos) noexcept = 0;
52  virtual void holeDiameterChanged(
53  const PositiveLength& newDiameter) noexcept = 0;
54 
55 protected:
56  IF_HoleObserver() noexcept {}
57  explicit IF_HoleObserver(const IF_HoleObserver& other) = delete;
58  virtual ~IF_HoleObserver() noexcept {}
59  IF_HoleObserver& operator=(const IF_HoleObserver& rhs) = delete;
60 };
61 
62 /*******************************************************************************
63  * Class Hole
64  ******************************************************************************/
65 
69 class Hole final : public SerializableObject {
70  Q_DECLARE_TR_FUNCTIONS(Hole)
71 
72 public:
73  // Constructors / Destructor
74  Hole() = delete;
75  Hole(const Hole& other) noexcept;
76  Hole(const Uuid& uuid, const Hole& other) noexcept;
77  Hole(const Uuid& uuid, const Point& position,
78  const PositiveLength& diameter) noexcept;
79  explicit Hole(const SExpression& node);
80  ~Hole() noexcept;
81 
82  // Getters
83  const Uuid& getUuid() const noexcept { return mUuid; }
84  const Point& getPosition() const noexcept { return mPosition; }
85  const PositiveLength& getDiameter() const noexcept { return mDiameter; }
86 
87  // Setters
88  void setPosition(const Point& position) noexcept;
89  void setDiameter(const PositiveLength& diameter) noexcept;
90 
91  // General Methods
92  void registerObserver(IF_HoleObserver& object) const noexcept;
93  void unregisterObserver(IF_HoleObserver& object) const noexcept;
94 
96  void serialize(SExpression& root) const override;
97 
98  // Operator Overloadings
99  bool operator==(const Hole& rhs) const noexcept;
100  bool operator!=(const Hole& rhs) const noexcept { return !(*this == rhs); }
101  Hole& operator=(const Hole& rhs) noexcept;
102 
103 private: // Data
107 
108  // Misc
109  mutable QSet<IF_HoleObserver*>
111 };
112 
113 /*******************************************************************************
114  * Class HoleList
115  ******************************************************************************/
116 
118  static constexpr const char* tagname = "hole";
119 };
124 
125 /*******************************************************************************
126  * End of File
127  ******************************************************************************/
128 
129 } // namespace librepcb
130 
131 #endif // LIBREPCB_HOLE_H
Uuid mUuid
Definition: hole.h:104
void setDiameter(const PositiveLength &diameter) noexcept
Definition: hole.cpp:87
IF_HoleObserver & operator=(const IF_HoleObserver &rhs)=delete
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
Hole & operator=(const Hole &rhs) noexcept
Definition: hole.cpp:124
PositiveLength mDiameter
Definition: hole.h:106
The Hole class.
Definition: hole.h:69
The IF_HoleObserver class.
Definition: hole.h:49
static constexpr const char * tagname
Definition: hole.h:118
bool operator==(const Hole &rhs) const noexcept
Definition: hole.cpp:117
void unregisterObserver(IF_HoleObserver &object) const noexcept
Definition: hole.cpp:103
virtual void holePositionChanged(const Point &newPos) noexcept=0
virtual ~IF_HoleObserver() noexcept
Definition: hole.h:58
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
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: hole.cpp:107
void setPosition(const Point &position) noexcept
Definition: hole.cpp:79
Definition: hole.h:117
QSet< IF_HoleObserver * > mObservers
A list of all observer objects.
Definition: hole.h:110
bool operator!=(const Hole &rhs) const noexcept
Definition: hole.h:100
const PositiveLength & getDiameter() const noexcept
Definition: hole.h:85
IF_HoleObserver() noexcept
Definition: hole.h:56
virtual void holeDiameterChanged(const PositiveLength &newDiameter) noexcept=0
~Hole() noexcept
Definition: hole.cpp:71
const Point & getPosition() const noexcept
Definition: hole.h:84
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void registerObserver(IF_HoleObserver &object) const noexcept
Definition: hole.cpp:99
The SExpression class.
Definition: sexpression.h:60
const Uuid & getUuid() const noexcept
Definition: hole.h:83
Point mPosition
Definition: hole.h:105