LibrePCB Developers Documentation
Loading...
Searching...
No Matches
package.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_PACKAGE_H
21#define LIBREPCB_CORE_PACKAGE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../types/simplestring.h"
27#include "../libraryelement.h"
28#include "footprint.h"
29#include "packagemodel.h"
30#include "packagepad.h"
31
32#include <QtCore>
33
34#include <memory>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41/*******************************************************************************
42 * Class Package
43 ******************************************************************************/
44
59class Package final : public LibraryElement {
60 Q_OBJECT
61
62public:
63 // Types
67
71 : name(deserialize<ElementName>(node.getChild("@0"))),
72 reference(deserialize<SimpleString>(node.getChild("reference/@0"))) {}
73 void serialize(SExpression& root) const {
74 root.appendChild(name);
75 root.appendChild("reference", reference);
76 }
77 bool operator==(const AlternativeName& rhs) const noexcept = default;
78 };
79 enum class AssemblyType {
80 None,
81 Tht,
82 Smt,
83 Mixed,
84 Other,
85 Auto,
86 // ATTENTION: Update uihelpers.cpp & constants.slint when changing the enum!
87 };
88
89 // Constructors / Destructor
90 Package() = delete;
91 Package(const Package& other) = delete;
92 Package(const Uuid& uuid, const Version& version, const QString& author,
93 const ElementName& name_en_US, const QString& description_en_US,
94 const QString& keywords_en_US, AssemblyType assemblyType);
95 ~Package() noexcept;
96
97 // Getters
98 const QList<AlternativeName>& getAlternativeNames() const noexcept {
99 return mAlternativeNames;
100 }
101 AssemblyType getAssemblyType(bool resolveAuto) const noexcept;
102 AssemblyType guessAssemblyType() const noexcept;
103 const PositiveLength& getGridInterval() const noexcept {
104 return mGridInterval;
105 }
106 const UnsignedLength& getMinCopperClearance() const noexcept {
107 return mMinCopperClearance;
108 }
109 PackagePadList& getPads() noexcept { return mPads; }
110 const PackagePadList& getPads() const noexcept { return mPads; }
111 PackageModelList& getModels() noexcept { return mModels; }
112 const PackageModelList& getModels() const noexcept { return mModels; }
113 QVector<std::shared_ptr<const PackageModel>> getModelsForFootprint(
114 const Uuid& fpt) const noexcept;
116 const FootprintList& getFootprints() const noexcept { return mFootprints; }
117
118 // Setters
119 void setAlternativeNames(const QList<AlternativeName>& names) noexcept {
120 mAlternativeNames = names;
121 }
122 void setAssemblyType(AssemblyType type) noexcept { mAssemblyType = type; }
123 void setGridInterval(const PositiveLength& interval) noexcept {
124 mGridInterval = interval;
125 }
126 void setMinCopperClearance(const UnsignedLength& value) noexcept {
127 mMinCopperClearance = value;
128 }
129
130 // General Methods
131 virtual RuleCheckMessageList runChecks() const override;
132
133 // Operator Overloadings
134 Package& operator=(const Package& rhs) = delete;
135
136 // Static Methods
137 static std::unique_ptr<Package> open(
138 std::unique_ptr<TransactionalDirectory> directory,
139 bool abortBeforeMigration = false);
140 static QString getShortElementName() noexcept {
141 return QStringLiteral("pkg");
142 }
143 static QString getLongElementName() noexcept {
144 return QStringLiteral("package");
145 }
146
147protected: // Methods
148 virtual void serialize(SExpression& root) const override;
149
150private: // Methods
151 Package(std::unique_ptr<TransactionalDirectory> directory,
152 const SExpression& root);
153
154private: // Data
155 QList<AlternativeName> mAlternativeNames;
162};
163
164/*******************************************************************************
165 * End of File
166 ******************************************************************************/
167
168} // namespace librepcb
169
170Q_DECLARE_METATYPE(librepcb::Package::AssemblyType)
171
172#endif
The LibraryElement class extends the LibraryBaseElement class with some attributes and methods which ...
Definition libraryelement.h:45
The Package class represents a package of a component (including footprint and 3D model)
Definition package.h:59
Package(const Package &other)=delete
AssemblyType
Definition package.h:79
@ Auto
Auto detection (deprecated, only for file format migration!)
@ Other
Anything special, e.g. mechanical parts.
@ Mixed
Mixed THT/SMT package.
@ None
Nothing to mount (i.e. not a package, just a footprint)
Package & operator=(const Package &rhs)=delete
void setMinCopperClearance(const UnsignedLength &value) noexcept
Definition package.h:126
PositiveLength mGridInterval
Definition package.h:157
void setAssemblyType(AssemblyType type) noexcept
Definition package.h:122
const PositiveLength & getGridInterval() const noexcept
Definition package.h:103
AssemblyType guessAssemblyType() const noexcept
Definition package.cpp:133
virtual RuleCheckMessageList runChecks() const override
Definition package.cpp:181
void setAlternativeNames(const QList< AlternativeName > &names) noexcept
Definition package.h:119
const FootprintList & getFootprints() const noexcept
Definition package.h:116
const QList< AlternativeName > & getAlternativeNames() const noexcept
Definition package.h:98
QList< AlternativeName > mAlternativeNames
Optional.
Definition package.h:155
PackagePadList mPads
empty list if the package has no pads
Definition package.h:159
static std::unique_ptr< Package > open(std::unique_ptr< TransactionalDirectory > directory, bool abortBeforeMigration=false)
Definition package.cpp:186
AssemblyType getAssemblyType(bool resolveAuto) const noexcept
Definition package.cpp:124
FootprintList mFootprints
minimum one footprint
Definition package.h:161
static QString getLongElementName() noexcept
Definition package.h:143
PackageModelList mModels
3D models (optional)
Definition package.h:160
AssemblyType mAssemblyType
Package assembly type (metadata)
Definition package.h:156
const UnsignedLength & getMinCopperClearance() const noexcept
Definition package.h:106
~Package() noexcept
Definition package.cpp:117
virtual void serialize(SExpression &root) const override
Serialize into librepcb::SExpression node.
Definition package.cpp:218
FootprintList & getFootprints() noexcept
Definition package.h:115
const PackagePadList & getPads() const noexcept
Definition package.h:110
PackageModelList & getModels() noexcept
Definition package.h:111
const PackageModelList & getModels() const noexcept
Definition package.h:112
void setGridInterval(const PositiveLength &interval) noexcept
Definition package.h:123
QVector< std::shared_ptr< const PackageModel > > getModelsForFootprint(const Uuid &fpt) const noexcept
Definition package.cpp:164
PackagePadList & getPads() noexcept
Definition package.h:109
static QString getShortElementName() noexcept
Definition package.h:140
UnsignedLength mMinCopperClearance
For the package checks.
Definition package.h:158
The SExpression class.
Definition sexpression.h:69
void appendChild(std::unique_ptr< SExpression > child)
Definition sexpression.cpp:217
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
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< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition length.h:694
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition rulecheckmessage.h:104
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition simplestring.h:79
AttributeKey deserialize(const SExpression &node)
Definition attributekey.h:99
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition elementname.h:84
Definition package.h:64
SimpleString reference
Definition package.h:66
bool operator==(const AlternativeName &rhs) const noexcept=default
AlternativeName(const SExpression &node)
Definition package.h:70
ElementName name
Definition package.h:65
void serialize(SExpression &root) const
Definition package.h:73
AlternativeName(const ElementName &name, const SimpleString &reference)
Definition package.h:68