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  Component(const FilePath& elementDirectory, bool readOnly);
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  const AttributeList& getAttributes() const noexcept { return mAttributes; }
94  void setAttributes(const AttributeList& attributes) noexcept {
95  mAttributes = attributes;
96  }
97 
98  // Default Value Methods
99  const QString& getDefaultValue() const noexcept { return mDefaultValue; }
100  void setDefaultValue(const QString& value) noexcept { mDefaultValue = value; }
101 
102  // Prefix Methods
103  const NormDependentPrefixMap& getPrefixes() const noexcept {
104  return mPrefixes;
105  }
106  void setPrefixes(const NormDependentPrefixMap& prefixes) noexcept {
107  mPrefixes = prefixes;
108  }
109 
110  // Signal Methods
111  ComponentSignalList& getSignals() noexcept { return mSignals; }
112  const ComponentSignalList& getSignals() const noexcept { return mSignals; }
113 
114  // Symbol Variant Methods
116  return mSymbolVariants;
117  }
119  return mSymbolVariants;
120  }
121 
122  // Convenience Methods
123  std::shared_ptr<ComponentSignal> getSignalOfPin(const Uuid& symbVar,
124  const Uuid& item,
125  const Uuid& pin);
126  std::shared_ptr<const ComponentSignal> getSignalOfPin(const Uuid& symbVar,
127  const Uuid& item,
128  const Uuid& pin) const;
129  std::shared_ptr<ComponentSymbolVariantItem> getSymbVarItem(
130  const Uuid& symbVar, const Uuid& item);
131  std::shared_ptr<const ComponentSymbolVariantItem> getSymbVarItem(
132  const Uuid& symbVar, const Uuid& item) const;
133 
134  // General Methods
135  virtual LibraryElementCheckMessageList runChecks() const override;
136 
137  // Operator Overloadings
138  Component& operator=(const Component& rhs) = delete;
139 
140  // Static Methods
141  static QString getShortElementName() noexcept {
142  return QStringLiteral("cmp");
143  }
144  static QString getLongElementName() noexcept {
145  return QStringLiteral("component");
146  }
147 
148 private: // Methods
150  void serialize(SExpression& root) const override;
151 
152 private: // Data
154  QString mDefaultValue;
160 };
161 
162 /*******************************************************************************
163  * End of File
164  ******************************************************************************/
165 
166 } // namespace library
167 } // namespace librepcb
168 
169 #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:82
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
ComponentSymbolVariantList & getSymbolVariants() noexcept
Definition: component.h:115
static QString getShortElementName() noexcept
Definition: component.h:141
QVector< std::shared_ptr< const LibraryElementCheckMessage > > LibraryElementCheckMessageList
Definition: libraryelementcheckmessage.h:96
static QString getLongElementName() noexcept
Definition: component.h:144
NormDependentPrefixMap mPrefixes
Definition: component.h:156
const NormDependentPrefixMap & getPrefixes() const noexcept
Definition: component.h:103
ComponentSymbolVariantList mSymbolVariants
Definition: component.h:159
void setAttributes(const AttributeList &attributes) noexcept
Definition: component.h:94
const AttributeList & getAttributes() const noexcept
Definition: component.h:93
void setIsSchematicOnly(bool schematicOnly) noexcept
Definition: component.h:88
std::shared_ptr< ComponentSymbolVariantItem > getSymbVarItem(const Uuid &symbVar, const Uuid &item)
Definition: component.cpp:109
const QString & getDefaultValue() const noexcept
Definition: component.h:99
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: component.cpp:132
~Component() noexcept
Definition: component.cpp:75
const ComponentSignalList & getSignals() const noexcept
Definition: component.h:112
AttributeList mAttributes
all attributes in a specific order
Definition: component.h:157
void setDefaultValue(const QString &value) noexcept
Definition: component.h:100
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:155
Component & operator=(const Component &rhs)=delete
const ComponentSymbolVariantList & getSymbolVariants() const noexcept
Definition: component.h:118
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
bool mSchematicOnly
Definition: component.h:153
ComponentSignalList & getSignals() noexcept
Definition: component.h:111
static constexpr const char * tagname
Definition: component.h:48
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:123
void setPrefixes(const NormDependentPrefixMap &prefixes) noexcept
Definition: component.h:106
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:158
The Component class represents a "generic" device in the library.
Definition: component.h:73
The SExpression class.
Definition: sexpression.h:60
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92