LibrePCB Developers Documentation
componentinstance.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_COMPONENTINSTANCE_H
21 #define LIBREPCB_PROJECT_COMPONENTINSTANCE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../erc/if_ercmsgprovider.h"
27 
33 #include <librepcb/common/uuid.h>
34 
35 #include <QtCore>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 namespace librepcb {
41 
42 class DomElement;
43 
44 namespace library {
45 class Component;
46 class ComponentSymbolVariant;
47 } // namespace library
48 
49 namespace project {
50 
51 class Circuit;
52 class ComponentSignalInstance;
53 class BI_Device;
54 class SI_Symbol;
55 class ErcMsg;
56 
57 /*******************************************************************************
58  * Class ComponentInstance
59  ******************************************************************************/
60 
64 class ComponentInstance : public QObject,
65  public AttributeProvider,
66  public IF_ErcMsgProvider,
67  public SerializableObject {
68  Q_OBJECT
70 
71 public:
72  // Constructors / Destructor
73  ComponentInstance() = delete;
74  ComponentInstance(const ComponentInstance& other) = delete;
75  explicit ComponentInstance(Circuit& circuit, const SExpression& node);
76  explicit ComponentInstance(
77  Circuit& circuit, const library::Component& cmp, const Uuid& symbVar,
78  const CircuitIdentifier& name,
79  const tl::optional<Uuid>& defaultDevice = tl::nullopt);
80  ~ComponentInstance() noexcept;
81 
82  // Getters: Attributes
83  const Uuid& getUuid() const noexcept { return mUuid; }
84  const CircuitIdentifier& getName() const noexcept { return mName; }
85  QString getValue(bool replaceAttributes = false) const noexcept;
86  const tl::optional<Uuid>& getDefaultDeviceUuid() const noexcept {
87  return mDefaultDeviceUuid;
88  }
89  const library::Component& getLibComponent() const noexcept {
90  return *mLibComponent;
91  }
93  return *mCompSymbVar;
94  }
96  noexcept {
97  return mSignals.value(signalUuid);
98  }
99  const AttributeList& getAttributes() const noexcept { return *mAttributes; }
100 
101  // Getters: General
102  Circuit& getCircuit() const noexcept { return mCircuit; }
103  int getPlacedSymbolsCount() const noexcept {
104  return mRegisteredSymbols.count();
105  }
106  int getUnplacedSymbolsCount() const noexcept;
107  int getUnplacedRequiredSymbolsCount() const noexcept;
108  int getUnplacedOptionalSymbolsCount() const noexcept;
109  int getRegisteredElementsCount() const noexcept;
110  bool isUsed() const noexcept;
111 
112  // Setters
113 
126  void setName(const CircuitIdentifier& name) noexcept;
127 
135  void setValue(const QString& value) noexcept;
136 
137  void setAttributes(const AttributeList& attributes) noexcept;
138 
146  void setDefaultDeviceUuid(const tl::optional<Uuid>& device) noexcept;
147 
148  // General Methods
149  void addToCircuit();
150  void removeFromCircuit();
151  void registerSymbol(SI_Symbol& symbol);
152  void unregisterSymbol(SI_Symbol& symbol);
153  void registerDevice(BI_Device& device);
154  void unregisterDevice(BI_Device& device);
155 
157  void serialize(SExpression& root) const override;
158 
159  // Inherited from AttributeProvider
161  QString getUserDefinedAttributeValue(const QString& key) const
162  noexcept override;
164  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
166  QVector<const AttributeProvider*> getAttributeProviderParents() const
167  noexcept override;
168 
169  // Operator Overloadings
170  ComponentInstance& operator=(const ComponentInstance& rhs) = delete;
171 
172 signals:
173 
175  void attributesChanged() override;
176 
177 private:
178  void init();
179  bool checkAttributesValidity() const noexcept;
180  void updateErcMessages() noexcept;
181  const QStringList& getLocaleOrder() const noexcept;
182 
183  // General
186 
187  // Attributes
188 
191 
195 
198  QString mValue;
199 
201  tl::optional<Uuid> mDefaultDeviceUuid;
202 
205 
208 
210  QScopedPointer<AttributeList> mAttributes;
211 
213  QMap<Uuid, ComponentSignalInstance*> mSignals;
214 
215  // Registered Elements
216 
226  QHash<Uuid, SI_Symbol*> mRegisteredSymbols;
227 
233  QList<BI_Device*> mRegisteredDevices;
234 
235  // ERC Messages
236 
238  QScopedPointer<ErcMsg> mErcMsgUnplacedRequiredSymbols;
239 
241  QScopedPointer<ErcMsg> mErcMsgUnplacedOptionalSymbols;
242 };
243 
244 /*******************************************************************************
245  * End of File
246  ******************************************************************************/
247 
248 } // namespace project
249 } // namespace librepcb
250 
251 #endif // LIBREPCB_PROJECT_COMPONENTINSTANCE_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:73
QScopedPointer< ErcMsg > mErcMsgUnplacedRequiredSymbols
The ERC message for unplaced required symbols of this component.
Definition: componentinstance.h:238
The SI_Symbol class.
Definition: si_symbol.h:57
#define DECLARE_ERC_MSG_CLASS_NAME(msgOwnerClassName)
Definition: if_ercmsgprovider.h:44
int getPlacedSymbolsCount() const noexcept
Definition: componentinstance.h:103
Circuit & mCircuit
Definition: componentinstance.h:184
Definition: airwiresbuilder.cpp:32
QList< BI_Device * > mRegisteredDevices
All registered devices (of all boards)
Definition: componentinstance.h:233
CircuitIdentifier mName
The unique name of this component instance in the circuit (e.g. "R42")
Definition: componentinstance.h:194
const library::Component * mLibComponent
Pointer to the component in the project&#39;s library.
Definition: componentinstance.h:204
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:59
QScopedPointer< AttributeList > mAttributes
All attributes of this component.
Definition: componentinstance.h:210
const library::ComponentSymbolVariant * mCompSymbVar
Pointer to the used symbol variant of mLibComponent.
Definition: componentinstance.h:207
bool mIsAddedToCircuit
Definition: componentinstance.h:185
const tl::optional< Uuid > & getDefaultDeviceUuid() const noexcept
Definition: componentinstance.h:86
const library::Component & getLibComponent() const noexcept
Definition: componentinstance.h:89
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
Uuid mUuid
The unique UUID of this component instance in the circuit.
Definition: componentinstance.h:190
QString mValue
The value of this component instance in the circuit (e.g. the resistance of a resistor) ...
Definition: componentinstance.h:198
ComponentSignalInstance * getSignalInstance(const Uuid &signalUuid) const noexcept
Definition: componentinstance.h:95
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
const library::ComponentSymbolVariant & getSymbolVariant() const noexcept
Definition: componentinstance.h:92
Circuit & getCircuit() const noexcept
Definition: componentinstance.h:102
QHash< Uuid, SI_Symbol * > mRegisteredSymbols
All registered symbols.
Definition: componentinstance.h:226
QMap< Uuid, ComponentSignalInstance * > mSignals
All signal instances (Key: component signal UUID)
Definition: componentinstance.h:213
The BI_Device class.
Definition: bi_device.h:62
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:58
const CircuitIdentifier & getName() const noexcept
Definition: componentinstance.h:84
QScopedPointer< ErcMsg > mErcMsgUnplacedOptionalSymbols
The ERC message for unplaced optional symbols of this component.
Definition: componentinstance.h:241
The ComponentSignalInstance class.
Definition: componentsignalinstance.h:61
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
tl::optional< Uuid > mDefaultDeviceUuid
THe default device when adding the component to a board.
Definition: componentinstance.h:201
The Component class represents a "generic" device in the library.
Definition: component.h:73
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:57
const Uuid & getUuid() const noexcept
Definition: componentinstance.h:83
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
const AttributeList & getAttributes() const noexcept
Definition: componentinstance.h:99