LibrePCB Developers Documentation
component.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_COMPONENT_H
21#define LIBREPCB_CORE_COMPONENT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../attribute/attribute.h"
27#include "../../serialization/serializablekeyvaluemap.h"
28#include "../libraryelement.h"
29#include "componentprefix.h"
30#include "componentsignal.h"
32
33#include <QtCore>
34
35#include <memory>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42/*******************************************************************************
43 * Class NormDependentPrefixMap
44 ******************************************************************************/
45
48 static constexpr const char* tagname = "prefix";
49 static constexpr const char* keyname = "norm";
50};
53
54/*******************************************************************************
55 * Class Component
56 ******************************************************************************/
57
73class Component final : public LibraryElement {
74 Q_OBJECT
75
76public:
77 // Constructors / Destructor
78 Component() = delete;
79 Component(const Component& other) = delete;
80 Component(const Uuid& uuid, const Version& version, const QString& author,
81 const ElementName& name_en_US, const QString& description_en_US,
82 const QString& keywords_en_US);
83 ~Component() noexcept;
84
85 // General
86 bool isSchematicOnly() const noexcept { return mSchematicOnly; }
87 void setIsSchematicOnly(bool schematicOnly) noexcept {
88 mSchematicOnly = schematicOnly;
89 }
90
91 // Attribute Methods
92 AttributeList& getAttributes() noexcept { return mAttributes; }
93 const AttributeList& getAttributes() const noexcept { return mAttributes; }
94
95 // Default Value Methods
96 const QString& getDefaultValue() const noexcept { return mDefaultValue; }
97 void setDefaultValue(const QString& value) noexcept { mDefaultValue = value; }
98
99 // Prefix Methods
100 const NormDependentPrefixMap& getPrefixes() const noexcept {
101 return mPrefixes;
102 }
103 void setPrefixes(const NormDependentPrefixMap& prefixes) noexcept {
104 mPrefixes = prefixes;
105 }
106
107 // Signal Methods
109 const ComponentSignalList& getSignals() const noexcept { return mSignals; }
110
111 // Symbol Variant Methods
113 return mSymbolVariants;
114 }
116 return mSymbolVariants;
117 }
118
119 // Convenience Methods
120 std::shared_ptr<ComponentSignal> getSignalOfPin(const Uuid& symbVar,
121 const Uuid& item,
122 const Uuid& pin);
123 std::shared_ptr<const ComponentSignal> getSignalOfPin(const Uuid& symbVar,
124 const Uuid& item,
125 const Uuid& pin) const;
126 int getSymbolVariantIndexByNorm(const QStringList& normOrder) const noexcept;
127 std::shared_ptr<ComponentSymbolVariantItem> getSymbVarItem(
128 const Uuid& symbVar, const Uuid& item);
129 std::shared_ptr<const ComponentSymbolVariantItem> getSymbVarItem(
130 const Uuid& symbVar, const Uuid& item) const;
131
132 // General Methods
133 virtual RuleCheckMessageList runChecks() const override;
134
135 // Operator Overloadings
136 Component& operator=(const Component& rhs) = delete;
137
138 // Static Methods
139 static std::unique_ptr<Component> open(
140 std::unique_ptr<TransactionalDirectory> directory,
141 bool abortBeforeMigration = false);
142 static QString getShortElementName() noexcept {
143 return QStringLiteral("cmp");
144 }
145 static QString getLongElementName() noexcept {
146 return QStringLiteral("component");
147 }
148
149protected: // Methods
150 virtual void serialize(SExpression& root) const override;
151
152private: // Methods
153 Component(std::unique_ptr<TransactionalDirectory> directory,
154 const SExpression& root);
155 static QString cleanNorm(QString norm) noexcept;
156
157private: // Data
165};
166
167/*******************************************************************************
168 * End of File
169 ******************************************************************************/
170
171} // namespace librepcb
172
173#endif
The Component class represents a "generic" device in the library.
Definition: component.h:73
ComponentSymbolVariantList & getSymbolVariants() noexcept
Definition: component.h:112
std::shared_ptr< ComponentSymbolVariantItem > getSymbVarItem(const Uuid &symbVar, const Uuid &item)
Definition: component.cpp:109
const ComponentSymbolVariantList & getSymbolVariants() const noexcept
Definition: component.h:115
ComponentSignalList mSignals
Definition: component.h:163
ComponentSymbolVariantList mSymbolVariants
Definition: component.h:164
virtual RuleCheckMessageList runChecks() const override
Definition: component.cpp:123
std::shared_ptr< ComponentSignal > getSignalOfPin(const Uuid &symbVar, const Uuid &item, const Uuid &pin)
Definition: component.cpp:69
static std::unique_ptr< Component > open(std::unique_ptr< TransactionalDirectory > directory, bool abortBeforeMigration=false)
Definition: component.cpp:128
const ComponentSignalList & getSignals() const noexcept
Definition: component.h:109
Component & operator=(const Component &rhs)=delete
AttributeList & getAttributes() noexcept
Definition: component.h:92
void setDefaultValue(const QString &value) noexcept
Definition: component.h:97
static QString cleanNorm(QString norm) noexcept
Definition: component.cpp:183
const AttributeList & getAttributes() const noexcept
Definition: component.h:93
QString mDefaultValue
Definition: component.h:160
Component(const Component &other)=delete
const QString & getDefaultValue() const noexcept
Definition: component.h:96
bool isSchematicOnly() const noexcept
Definition: component.h:86
NormDependentPrefixMap mPrefixes
Definition: component.h:161
bool mSchematicOnly
Definition: component.h:158
AttributeList mAttributes
all attributes in a specific order
Definition: component.h:162
~Component() noexcept
Definition: component.cpp:62
static QString getLongElementName() noexcept
Definition: component.h:145
ComponentSignalList & getSignals() noexcept
Definition: component.h:108
const NormDependentPrefixMap & getPrefixes() const noexcept
Definition: component.h:100
int getSymbolVariantIndexByNorm(const QStringList &normOrder) const noexcept
Definition: component.cpp:96
void setIsSchematicOnly(bool schematicOnly) noexcept
Definition: component.h:87
virtual void serialize(SExpression &root) const override
Serialize into librepcb::SExpression node.
Definition: component.cpp:160
static QString getShortElementName() noexcept
Definition: component.h:142
void setPrefixes(const NormDependentPrefixMap &prefixes) noexcept
Definition: component.h:103
The LibraryElement class extends the LibraryBaseElement class with some attributes and methods which ...
Definition: libraryelement.h:45
The SExpression class.
Definition: sexpression.h:69
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition: componentprefix.h:85
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84
Definition: component.h:46
static constexpr const char * keyname
Definition: component.h:49
ComponentPrefix ValueType
Definition: component.h:47
static constexpr const char * tagname
Definition: component.h:48