LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 {
48 };
51
52 // Constructors / Destructor
56 const std::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 std::optional<Uuid>& getSignalUuid() const noexcept {
66 return mSignalUuid;
67 }
68
69 // Setters
70 bool setSignalUuid(const std::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 std::optional<Uuid>
92};
93
94/*******************************************************************************
95 * Class DevicePadSignalMap
96 ******************************************************************************/
97
99 static constexpr const char* tagname = "pad";
100};
105
106/*******************************************************************************
107 * Class DevicePadSignalMapHelpers
108 ******************************************************************************/
109
111public:
112 DevicePadSignalMapHelpers() = delete; // disable instantiation
113
114 static std::optional<Uuid> tryGetSignalUuid(const DevicePadSignalMap& map,
115 const Uuid& pad) noexcept {
116 std::shared_ptr<const DevicePadSignalMapItem> item = map.find(pad);
117 return item ? item->getSignalUuid() : std::nullopt;
118 }
119
120 static DevicePadSignalMap create(const QSet<Uuid> pads) noexcept {
122 foreach (const Uuid& pad, pads) {
123 map.append(std::make_shared<DevicePadSignalMapItem>(pad, std::nullopt));
124 }
125 return map;
126 }
127
128 static void setPads(DevicePadSignalMap& map, QSet<Uuid> pads) noexcept {
129 foreach (const Uuid& pad, map.getUuidSet() - pads) {
130 map.remove(pad);
131 }
132 foreach (const Uuid& pad, pads - map.getUuidSet()) {
133 map.append(std::make_shared<DevicePadSignalMapItem>(pad, std::nullopt));
134 }
135 Q_ASSERT(map.getUuidSet() == pads);
136 }
137};
138
139/*******************************************************************************
140 * End of File
141 ******************************************************************************/
142
143} // namespace librepcb
144
145#endif
Definition devicepadsignalmap.h:110
static DevicePadSignalMap create(const QSet< Uuid > pads) noexcept
Definition devicepadsignalmap.h:120
static void setPads(DevicePadSignalMap &map, QSet< Uuid > pads) noexcept
Definition devicepadsignalmap.h:128
static std::optional< Uuid > tryGetSignalUuid(const DevicePadSignalMap &map, const Uuid &pad) noexcept
Definition devicepadsignalmap.h:114
The DevicePadSignalMapItem class.
Definition devicepadsignalmap.h:42
std::optional< Uuid > mSignalUuid
std::nullopt if not connected to a signal
Definition devicepadsignalmap.h:91
~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
bool operator==(const DevicePadSignalMapItem &rhs) const noexcept
Definition devicepadsignalmap.cpp:83
bool setSignalUuid(const std::optional< Uuid > &uuid) noexcept
Definition devicepadsignalmap.cpp:59
const Uuid & getPadUuid() const noexcept
Definition devicepadsignalmap.h:64
const std::optional< Uuid > & getSignalUuid() const noexcept
Definition devicepadsignalmap.h:65
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:56
Definition occmodel.cpp:76
Definition devicepadsignalmap.h:98
static constexpr const char * tagname
Definition devicepadsignalmap.h:99