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_NETLABEL_H
21 #define LIBREPCB_NETLABEL_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  *  Class NetLabel
41  ******************************************************************************/
42 
43 /**
44  * @brief The NetLabel class represents a net text label of a schematic
45  *
46  * The main purpose of this class is to serialize and deserialize net labels
47  * contained in schematics.
48  */
49 class NetLabel final : public SerializableObject {
50   Q_DECLARE_TR_FUNCTIONS(NetLabel)
51 
52 public:
53   // Signals
54   enum class Event {
55     UuidChanged,
56     PositionChanged,
57     RotationChanged,
58   };
59   Signal<NetLabel, Event> onEdited;
60   typedef Slot<NetLabel, Event> OnEditedSlot;
61 
62   // Constructors / Destructor
63   NetLabel() = delete;
64   NetLabel(const NetLabel& other) noexcept;
65   NetLabel(const Uuid& uuid, const NetLabel& other) noexcept;
66   NetLabel(const Uuid& uuid, const Point& position,
67            const Angle& rotation) noexcept;
68   NetLabel(const SExpression& node, const Version& fileFormat);
69   ~NetLabel() noexcept;
70 
71   // Getters
getUuid()72   const Uuid& getUuid() const noexcept { return mUuid; }
getPosition()73   const Point& getPosition() const noexcept { return mPosition; }
getRotation()74   const Angle& getRotation() const noexcept { return mRotation; }
75 
76   // Setters
77   bool setUuid(const Uuid& uuid) noexcept;
78   bool setPosition(const Point& position) noexcept;
79   bool setRotation(const Angle& rotation) noexcept;
80 
81   /// @copydoc librepcb::SerializableObject::serialize()
82   void serialize(SExpression& root) const override;
83 
84   // Operator Overloadings
85   bool operator==(const NetLabel& rhs) const noexcept;
86   bool operator!=(const NetLabel& rhs) const noexcept {
87     return !(*this == rhs);
88   }
89   NetLabel& operator=(const NetLabel& rhs) noexcept;
90 
91 private:  // Data
92   Uuid mUuid;
93   Point mPosition;
94   Angle mRotation;
95 };
96 
97 /*******************************************************************************
98  *  Class NetLabelList
99  ******************************************************************************/
100 
101 struct NetLabelListNameProvider {
102   static constexpr const char* tagname = "label";
103 };
104 using NetLabelList =
105     SerializableObjectList<NetLabel, NetLabelListNameProvider, NetLabel::Event>;
106 using CmdNetLabelInsert =
107     CmdListElementInsert<NetLabel, NetLabelListNameProvider, NetLabel::Event>;
108 using CmdNetLabelRemove =
109     CmdListElementRemove<NetLabel, NetLabelListNameProvider, NetLabel::Event>;
110 using CmdNetLabelsSwap =
111     CmdListElementsSwap<NetLabel, NetLabelListNameProvider, NetLabel::Event>;
112 
113 /*******************************************************************************
114  *  End of File
115  ******************************************************************************/
116 
117 }  // namespace librepcb
118 
119 #endif
120