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 /*******************************************************************************
21  *  Includes
22  ******************************************************************************/
23 #include "componentpinsignalmap.h"
24 
25 #include <QtCore>
26 
27 /*******************************************************************************
28  *  Namespace
29  ******************************************************************************/
30 namespace librepcb {
31 namespace library {
32 
33 /*******************************************************************************
34  *  Constructors / Destructor
35  ******************************************************************************/
36 
ComponentPinSignalMapItem(const ComponentPinSignalMapItem & other)37 ComponentPinSignalMapItem::ComponentPinSignalMapItem(
38     const ComponentPinSignalMapItem& other) noexcept
39   : onEdited(*this),
40     mPinUuid(other.mPinUuid),
41     mSignalUuid(other.mSignalUuid),
42     mDisplayType(other.mDisplayType) {
43 }
44 
ComponentPinSignalMapItem(const Uuid & pin,const tl::optional<Uuid> & signal,const CmpSigPinDisplayType & displayType)45 ComponentPinSignalMapItem::ComponentPinSignalMapItem(
46     const Uuid& pin, const tl::optional<Uuid>& signal,
47     const CmpSigPinDisplayType& displayType) noexcept
48   : onEdited(*this),
49     mPinUuid(pin),
50     mSignalUuid(signal),
51     mDisplayType(displayType) {
52 }
53 
ComponentPinSignalMapItem(const SExpression & node,const Version & fileFormat)54 ComponentPinSignalMapItem::ComponentPinSignalMapItem(const SExpression& node,
55                                                      const Version& fileFormat)
56   : onEdited(*this),
57     mPinUuid(deserialize<Uuid>(node.getChild("@0"), fileFormat)),
58     mSignalUuid(deserialize<tl::optional<Uuid>>(node.getChild("signal/@0"),
59                                                 fileFormat)),
60     mDisplayType(deserialize<const CmpSigPinDisplayType&>(
61         node.getChild("text/@0"), fileFormat)) {
62 }
63 
~ComponentPinSignalMapItem()64 ComponentPinSignalMapItem::~ComponentPinSignalMapItem() noexcept {
65 }
66 
67 /*******************************************************************************
68  *  Setters
69  ******************************************************************************/
70 
setSignalUuid(const tl::optional<Uuid> & uuid)71 bool ComponentPinSignalMapItem::setSignalUuid(
72     const tl::optional<Uuid>& uuid) noexcept {
73   if (uuid == mSignalUuid) {
74     return false;
75   }
76 
77   mSignalUuid = uuid;
78   onEdited.notify(Event::SignalUuidChanged);
79   return true;
80 }
setDisplayType(const CmpSigPinDisplayType & type)81 bool ComponentPinSignalMapItem::setDisplayType(
82     const CmpSigPinDisplayType& type) noexcept {
83   if (type == mDisplayType) {
84     return false;
85   }
86 
87   mDisplayType = type;
88   onEdited.notify(Event::DisplayTypeChanged);
89   return true;
90 }
91 
92 /*******************************************************************************
93  *  General Methods
94  ******************************************************************************/
95 
serialize(SExpression & root) const96 void ComponentPinSignalMapItem::serialize(SExpression& root) const {
97   root.appendChild(mPinUuid);
98   root.appendChild("signal", mSignalUuid, false);
99   root.appendChild("text", mDisplayType, false);
100 }
101 
102 /*******************************************************************************
103  *  Operator Overloadings
104  ******************************************************************************/
105 
operator ==(const ComponentPinSignalMapItem & rhs) const106 bool ComponentPinSignalMapItem::operator==(
107     const ComponentPinSignalMapItem& rhs) const noexcept {
108   if (mPinUuid != rhs.mPinUuid) return false;
109   if (mSignalUuid != rhs.mSignalUuid) return false;
110   if (mDisplayType != rhs.mDisplayType) return false;
111   return true;
112 }
113 
operator =(const ComponentPinSignalMapItem & rhs)114 ComponentPinSignalMapItem& ComponentPinSignalMapItem::operator=(
115     const ComponentPinSignalMapItem& rhs) noexcept {
116   if (mPinUuid != rhs.mPinUuid) {
117     mPinUuid = rhs.mPinUuid;
118     onEdited.notify(Event::PinUuidChanged);
119   }
120   setSignalUuid(rhs.mSignalUuid);
121   setDisplayType(rhs.mDisplayType);
122   return *this;
123 }
124 
125 /*******************************************************************************
126  *  End of File
127  ******************************************************************************/
128 
129 }  // namespace library
130 }  // namespace librepcb
131