LibrePCB Developers Documentation
componentsignalinstance.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_PROJECT_COMPONENTSIGNALINSTANCE_H
21 #define LIBREPCB_PROJECT_COMPONENTSIGNALINSTANCE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../erc/if_ercmsgprovider.h"
27 
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class DomElement;
40 
41 namespace library {
42 class ComponentSignal;
43 }
44 
45 namespace project {
46 
47 class ComponentInstance;
48 class SI_SymbolPin;
49 class BI_FootprintPad;
50 class NetSignal;
51 class Circuit;
52 class ErcMsg;
53 
54 /*******************************************************************************
55  * Class ComponentSignalInstance
56  ******************************************************************************/
57 
61 class ComponentSignalInstance final : public QObject,
62  public IF_ErcMsgProvider,
63  public SerializableObject {
64  Q_OBJECT
66 
67 public:
68  // Constructors / Destructor
69  ComponentSignalInstance() = delete;
70  ComponentSignalInstance(const ComponentSignalInstance& other) = delete;
71  explicit ComponentSignalInstance(Circuit& circuit,
72  ComponentInstance& cmpInstance,
73  const SExpression& node);
74  explicit ComponentSignalInstance(Circuit& circuit,
75  ComponentInstance& cmpInstance,
76  const library::ComponentSignal& cmpSignal,
77  NetSignal* netsignal = nullptr);
78  ~ComponentSignalInstance() noexcept;
79 
80  // Getters
81  Circuit& getCircuit() const noexcept { return mCircuit; }
82  const library::ComponentSignal& getCompSignal() const noexcept {
83  return *mComponentSignal;
84  }
85  NetSignal* getNetSignal() const noexcept { return mNetSignal; }
87  return mComponentInstance;
88  }
89  bool isNetSignalNameForced() const noexcept;
90  QString getForcedNetSignalName() const noexcept;
91  const QList<SI_SymbolPin*>& getRegisteredSymbolPins() const noexcept {
92  return mRegisteredSymbolPins;
93  }
94  const QList<BI_FootprintPad*>& getRegisteredFootprintPads() const noexcept {
95  return mRegisteredFootprintPads;
96  }
97  int getRegisteredElementsCount() const noexcept;
98  bool isUsed() const noexcept { return (getRegisteredElementsCount() > 0); }
99  bool arePinsOrPadsUsed() const noexcept;
100 
101  // Setters
102 
114  void setNetSignal(NetSignal* netsignal);
115 
116  // General Methods
117  void addToCircuit();
118  void removeFromCircuit();
119  void registerSymbolPin(SI_SymbolPin& pin);
120  void unregisterSymbolPin(SI_SymbolPin& pin);
121  void registerFootprintPad(BI_FootprintPad& pad);
122  void unregisterFootprintPad(BI_FootprintPad& pad);
123 
125  void serialize(SExpression& root) const override;
126 
127  // Operator Overloadings
128  ComponentSignalInstance& operator=(const ComponentSignalInstance& rhs) =
129  delete;
130 
131 signals:
132  void netSignalChanged(NetSignal* from, NetSignal* to);
133 
134 private slots:
135 
136  void netSignalNameChanged(const CircuitIdentifier& newName) noexcept;
137  void updateErcMessages() noexcept;
138 
139 private:
140  void init();
141  bool checkAttributesValidity() const noexcept;
142 
143  // General
148 
149  // Attributes
151 
152  // Registered Elements
153  QList<SI_SymbolPin*> mRegisteredSymbolPins;
154  QList<BI_FootprintPad*> mRegisteredFootprintPads;
155 
156  // ERC Messages
158  QScopedPointer<ErcMsg> mErcMsgUnconnectedRequiredSignal;
160  QScopedPointer<ErcMsg> mErcMsgForcedNetSignalNameConflict;
161 };
162 
163 /*******************************************************************************
164  * End of File
165  ******************************************************************************/
166 
167 } // namespace project
168 } // namespace librepcb
169 
170 #endif // LIBREPCB_PROJECT_COMPONENTSIGNALINSTANCE_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:73
#define DECLARE_ERC_MSG_CLASS_NAME(msgOwnerClassName)
Definition: if_ercmsgprovider.h:44
QList< SI_SymbolPin * > mRegisteredSymbolPins
Definition: componentsignalinstance.h:153
Circuit & mCircuit
Definition: componentsignalinstance.h:144
The ComponentSignal class represents one signal of a component.
Definition: componentsignal.h:49
Definition: airwiresbuilder.cpp:32
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:59
ComponentInstance & getComponentInstance() const noexcept
Definition: componentsignalinstance.h:86
QScopedPointer< ErcMsg > mErcMsgUnconnectedRequiredSignal
The ERC message for an unconnected required component signal.
Definition: componentsignalinstance.h:158
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
ComponentInstance & mComponentInstance
Definition: componentsignalinstance.h:145
The SI_SymbolPin class.
Definition: si_symbolpin.h:58
QList< BI_FootprintPad * > mRegisteredFootprintPads
Definition: componentsignalinstance.h:154
const QList< BI_FootprintPad * > & getRegisteredFootprintPads() const noexcept
Definition: componentsignalinstance.h:94
const library::ComponentSignal * mComponentSignal
Definition: componentsignalinstance.h:146
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
NetSignal * mNetSignal
Definition: componentsignalinstance.h:150
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:90
QScopedPointer< ErcMsg > mErcMsgForcedNetSignalNameConflict
The ERC message for a global net signal name mismatch.
Definition: componentsignalinstance.h:160
bool isUsed() const noexcept
Definition: componentsignalinstance.h:98
Circuit & getCircuit() const noexcept
Definition: componentsignalinstance.h:81
The NetSignal class.
Definition: netsignal.h:56
const QList< SI_SymbolPin * > & getRegisteredSymbolPins() const noexcept
Definition: componentsignalinstance.h:91
The ComponentSignalInstance class.
Definition: componentsignalinstance.h:61
bool mIsAddedToCircuit
Definition: componentsignalinstance.h:147
NetSignal * getNetSignal() const noexcept
Definition: componentsignalinstance.h:85
const library::ComponentSignal & getCompSignal() const noexcept
Definition: componentsignalinstance.h:82
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:57