LibrePCB Developers Documentation
devicepadsignalmap.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_CORE_DEVICEPADSIGNALMAP_H
21#define LIBREPCB_CORE_DEVICEPADSIGNALMAP_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../serialization/serializableobjectlist.h"
27
28#include <QtCore>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34
35/*******************************************************************************
36 * Class DevicePadSignalMapItem
37 ******************************************************************************/
38
43public:
44 // Signals
45 enum class Event {
46 PadUuidChanged,
47 SignalUuidChanged,
48 };
51
52 // Constructors / Destructor
56 const tl::optional<Uuid>& signal) noexcept;
57 explicit DevicePadSignalMapItem(const SExpression& node);
58 ~DevicePadSignalMapItem() noexcept;
59
60 // Getters
61 const Uuid& getUuid() const noexcept {
62 return mPadUuid;
63 } // used for UuidObjectMap
64 const Uuid& getPadUuid() const noexcept { return mPadUuid; }
65 const tl::optional<Uuid>& getSignalUuid() const noexcept {
66 return mSignalUuid;
67 }
68
69 // Setters
70 bool setSignalUuid(const tl::optional<Uuid>& uuid) noexcept;
71
72 // General Methods
73
79 void serialize(SExpression& root) const;
80
81 // Operator Overloadings
82 bool operator==(const DevicePadSignalMapItem& rhs) const noexcept;
83 bool operator!=(const DevicePadSignalMapItem& rhs) const noexcept {
84 return !(*this == rhs);
85 }
87
88private: // Data
90 tl::optional<Uuid> mSignalUuid;
91};
92
93/*******************************************************************************
94 * Class DevicePadSignalMap
95 ******************************************************************************/
96
98 static constexpr const char* tagname = "pad";
99};
104
105/*******************************************************************************
106 * Class DevicePadSignalMapHelpers
107 ******************************************************************************/
108
110public:
111 DevicePadSignalMapHelpers() = delete; // disable instantiation
112
113 static tl::optional<Uuid> tryGetSignalUuid(const DevicePadSignalMap& map,
114 const Uuid& pad) noexcept {
115 std::shared_ptr<const DevicePadSignalMapItem> item = map.find(pad);
116 return item ? item->getSignalUuid() : tl::nullopt;
117 }
118
119 static DevicePadSignalMap create(const QSet<Uuid> pads) noexcept {
121 foreach (const Uuid& pad, pads) {
122 map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
123 }
124 return map;
125 }
126
127 static void setPads(DevicePadSignalMap& map, QSet<Uuid> pads) noexcept {
128 foreach (const Uuid& pad, map.getUuidSet() - pads) {
129 map.remove(pad);
130 }
131 foreach (const Uuid& pad, pads - map.getUuidSet()) {
132 map.append(std::make_shared<DevicePadSignalMapItem>(pad, tl::nullopt));
133 }
134 Q_ASSERT(map.getUuidSet() == pads);
135 }
136};
137
138/*******************************************************************************
139 * End of File
140 ******************************************************************************/
141
142} // namespace librepcb
143
144#endif
Definition: devicepadsignalmap.h:109
static DevicePadSignalMap create(const QSet< Uuid > pads) noexcept
Definition: devicepadsignalmap.h:119
static void setPads(DevicePadSignalMap &map, QSet< Uuid > pads) noexcept
Definition: devicepadsignalmap.h:127
static tl::optional< Uuid > tryGetSignalUuid(const DevicePadSignalMap &map, const Uuid &pad) noexcept
Definition: devicepadsignalmap.h:113
The DevicePadSignalMapItem class.
Definition: devicepadsignalmap.h:42
~DevicePadSignalMapItem() noexcept
Definition: devicepadsignalmap.cpp:52
DevicePadSignalMapItem & operator=(const DevicePadSignalMapItem &rhs) noexcept
Definition: devicepadsignalmap.cpp:90
Slot< DevicePadSignalMapItem, Event > OnEditedSlot
Definition: devicepadsignalmap.h:50
Event
Definition: devicepadsignalmap.h:45
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: devicepadsignalmap.cpp:74
const Uuid & getUuid() const noexcept
Definition: devicepadsignalmap.h:61
Signal< DevicePadSignalMapItem, Event > onEdited
Definition: devicepadsignalmap.h:49
bool operator!=(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.h:83
Uuid mPadUuid
must be valid
Definition: devicepadsignalmap.h:89
const tl::optional< Uuid > & getSignalUuid() const noexcept
Definition: devicepadsignalmap.h:65
bool operator==(const DevicePadSignalMapItem &rhs) const noexcept
Definition: devicepadsignalmap.cpp:83
bool setSignalUuid(const tl::optional< Uuid > &uuid) noexcept
Definition: devicepadsignalmap.cpp:59
const Uuid & getPadUuid() const noexcept
Definition: devicepadsignalmap.h:64
tl::optional< Uuid > mSignalUuid
tl::nullopt if not connected to a signal
Definition: devicepadsignalmap.h:90
The SExpression class.
Definition: sexpression.h:69
int append(const std::shared_ptr< T > &obj) noexcept
Definition: serializableobjectlist.h:342
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:170
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
Definition: devicepadsignalmap.h:97
static constexpr const char * tagname
Definition: devicepadsignalmap.h:98