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