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_CORE_COMPONENTINSTANCE_H
21#define LIBREPCB_CORE_COMPONENTINSTANCE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../attribute/attribute.h"
27#include "../../types/circuitidentifier.h"
28#include "../../types/uuid.h"
30
31#include <QtCore>
32
33#include <memory>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40class BI_Device;
41class Circuit;
42class Component;
43class ComponentSignalInstance;
44class ComponentSymbolVariant;
45class SI_Symbol;
46
47/*******************************************************************************
48 * Class ComponentInstance
49 ******************************************************************************/
50
54class ComponentInstance : public QObject {
55 Q_OBJECT
56
57public:
58 // Constructors / Destructor
60 ComponentInstance(const ComponentInstance& other) = delete;
61 explicit ComponentInstance(Circuit& circuit, const Uuid& uuid,
62 const Component& cmp, const Uuid& symbVar,
63 const CircuitIdentifier& name);
64 ~ComponentInstance() noexcept;
65
66 // Getters: Attributes
67 const Uuid& getUuid() const noexcept { return mUuid; }
68 const CircuitIdentifier& getName() const noexcept { return mName; }
69 const QString& getValue() const noexcept { return mValue; }
70 const QPointer<const BI_Device>& getPrimaryDevice() const noexcept {
71 return mPrimaryDevice;
72 }
73 const Component& getLibComponent() const noexcept { return mLibComponent; }
74 const ComponentSymbolVariant& getSymbolVariant() const noexcept {
75 return *mCompSymbVar;
76 }
77 const QMap<Uuid, ComponentSignalInstance*>& getSignals() const noexcept {
78 return mSignals;
79 }
81 const Uuid& signalUuid) const noexcept {
82 return mSignals.value(signalUuid);
83 }
84 const AttributeList& getAttributes() const noexcept { return *mAttributes; }
86 return mAssemblyOptions;
87 }
88 QSet<Uuid> getCompatibleDevices() const noexcept;
89 QVector<std::shared_ptr<const Part>> getParts(
90 const tl::optional<Uuid>& assemblyVariant) const noexcept;
91 bool getLockAssembly() const noexcept { return mLockAssembly; }
92
93 // Getters: General
94 Circuit& getCircuit() const noexcept { return mCircuit; }
95 const QHash<Uuid, SI_Symbol*>& getSymbols() const noexcept {
96 return mRegisteredSymbols;
97 }
98 const QList<BI_Device*>& getDevices() const noexcept {
99 return mRegisteredDevices;
100 }
101 QSet<Uuid> getUsedDeviceUuids() const noexcept;
102 int getRegisteredElementsCount() const noexcept;
103 bool isUsed() const noexcept;
104 bool isAddedToCircuit() const noexcept { return mIsAddedToCircuit; }
105
106 // Setters
107
118 void setName(const CircuitIdentifier& name) noexcept;
119
125 void setValue(const QString& value) noexcept;
126
127 void setAttributes(const AttributeList& attributes) noexcept;
128
129 void setAssemblyOptions(const ComponentAssemblyOptionList& options) noexcept;
130
131 void setLockAssembly(bool lock) noexcept { mLockAssembly = lock; }
132
133 // General Methods
134 void addToCircuit();
135 void removeFromCircuit();
136 void registerSymbol(SI_Symbol& symbol);
137 void unregisterSymbol(SI_Symbol& symbol);
138 void registerDevice(BI_Device& device);
139 void unregisterDevice(BI_Device& device);
140
146 void serialize(SExpression& root) const;
147
148 // Operator Overloadings
150
151signals:
153 void primaryDeviceChanged(const BI_Device* device);
154
155private:
156 void updatePrimaryDevice() noexcept;
157 bool checkAttributesValidity() const noexcept;
158 const QStringList& getLocaleOrder() const noexcept;
159
160 // General
163
164 // Attributes
165
168
172
175 QString mValue;
176
179
182
184 QScopedPointer<AttributeList> mAttributes;
185
188
191
195
196 // Registered Elements
197
208
215
216 // Cached Properties
217 QPointer<const BI_Device> mPrimaryDevice;
218};
219
220/*******************************************************************************
221 * End of File
222 ******************************************************************************/
223
224} // namespace librepcb
225
226#endif
The BI_Device class.
Definition: bi_device.h:57
The Circuit class represents all electrical connections in a project (drawn in the schematics)
Definition: circuit.h:70
The Component class represents a "generic" device in the library.
Definition: component.h:73
The ComponentInstance class.
Definition: componentinstance.h:54
ComponentInstance & operator=(const ComponentInstance &rhs)=delete
const Component & mLibComponent
Reference to the component in the project's library.
Definition: componentinstance.h:178
QSet< Uuid > getCompatibleDevices() const noexcept
Definition: componentinstance.cpp:93
bool isAddedToCircuit() const noexcept
Definition: componentinstance.h:104
QList< BI_Device * > mRegisteredDevices
All registered devices (of all boards)
Definition: componentinstance.h:214
QScopedPointer< AttributeList > mAttributes
All attributes of this component.
Definition: componentinstance.h:184
const QList< BI_Device * > & getDevices() const noexcept
Definition: componentinstance.h:98
void setAssemblyOptions(const ComponentAssemblyOptionList &options) noexcept
Definition: componentinstance.cpp:172
~ComponentInstance() noexcept
Definition: componentinstance.cpp:81
Circuit & mCircuit
Definition: componentinstance.h:161
void unregisterSymbol(SI_Symbol &symbol)
Definition: componentinstance.cpp:248
QHash< Uuid, SI_Symbol * > mRegisteredSymbols
All registered symbols.
Definition: componentinstance.h:207
void setValue(const QString &value) noexcept
Set the value of this component instance in the circuit.
Definition: componentinstance.cpp:157
int getRegisteredElementsCount() const noexcept
Definition: componentinstance.cpp:127
Uuid mUuid
The unique UUID of this component instance in the circuit.
Definition: componentinstance.h:167
bool isUsed() const noexcept
Definition: componentinstance.cpp:134
bool mLockAssembly
Whether mAssemblyOptions can be modified from the board editor or not.
Definition: componentinstance.h:194
bool getLockAssembly() const noexcept
Definition: componentinstance.h:91
QVector< std::shared_ptr< const Part > > getParts(const tl::optional< Uuid > &assemblyVariant) const noexcept
Definition: componentinstance.cpp:101
ComponentSignalInstance * getSignalInstance(const Uuid &signalUuid) const noexcept
Definition: componentinstance.h:80
bool checkAttributesValidity() const noexcept
Definition: componentinstance.cpp:321
void updatePrimaryDevice() noexcept
Definition: componentinstance.cpp:306
const AttributeList & getAttributes() const noexcept
Definition: componentinstance.h:84
const CircuitIdentifier & getName() const noexcept
Definition: componentinstance.h:68
const Component & getLibComponent() const noexcept
Definition: componentinstance.h:73
QPointer< const BI_Device > mPrimaryDevice
Definition: componentinstance.h:217
void setName(const CircuitIdentifier &name) noexcept
Set the name of this component instance in the circuit.
Definition: componentinstance.cpp:150
QString mValue
The value of this component instance in the circuit (e.g. the resistance of a resistor)
Definition: componentinstance.h:175
const ComponentSymbolVariant & getSymbolVariant() const noexcept
Definition: componentinstance.h:74
const QString & getValue() const noexcept
Definition: componentinstance.h:69
ComponentAssemblyOptionList mAssemblyOptions
Assembly options including MPNs.
Definition: componentinstance.h:190
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: componentinstance.cpp:277
const Uuid & getUuid() const noexcept
Definition: componentinstance.h:67
void registerDevice(BI_Device &device)
Definition: componentinstance.cpp:257
void removeFromCircuit()
Definition: componentinstance.cpp:197
Circuit & getCircuit() const noexcept
Definition: componentinstance.h:94
ComponentInstance(const ComponentInstance &other)=delete
void setAttributes(const AttributeList &attributes) noexcept
Definition: componentinstance.cpp:164
void registerSymbol(SI_Symbol &symbol)
Definition: componentinstance.cpp:216
const QHash< Uuid, SI_Symbol * > & getSymbols() const noexcept
Definition: componentinstance.h:95
const QPointer< const BI_Device > & getPrimaryDevice() const noexcept
Definition: componentinstance.h:70
void primaryDeviceChanged(const BI_Device *device)
const QMap< Uuid, ComponentSignalInstance * > & getSignals() const noexcept
Definition: componentinstance.h:77
CircuitIdentifier mName
The unique name of this component instance in the circuit (e.g. "R42")
Definition: componentinstance.h:171
const QStringList & getLocaleOrder() const noexcept
Definition: componentinstance.cpp:326
QMap< Uuid, ComponentSignalInstance * > mSignals
All signal instances (Key: component signal UUID)
Definition: componentinstance.h:187
bool mIsAddedToCircuit
Definition: componentinstance.h:162
void addToCircuit()
Definition: componentinstance.cpp:184
void setLockAssembly(bool lock) noexcept
Definition: componentinstance.h:131
QSet< Uuid > getUsedDeviceUuids() const noexcept
Definition: componentinstance.cpp:119
const ComponentSymbolVariant * mCompSymbVar
Pointer to the used symbol variant of mLibComponent.
Definition: componentinstance.h:181
const ComponentAssemblyOptionList & getAssemblyOptions() const noexcept
Definition: componentinstance.h:85
void unregisterDevice(BI_Device &device)
Definition: componentinstance.cpp:268
The ComponentSignalInstance class.
Definition: componentsignalinstance.h:49
The ComponentSymbolVariant class represents a symbol variant of a component.
Definition: componentsymbolvariant.h:53
The Part class.
Definition: part.h:46
The SExpression class.
Definition: sexpression.h:69
The SI_Symbol class.
Definition: si_symbol.h:54
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:96
Definition: uuid.h:183