LibrePCB Developers Documentation
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 };
78 enum class AssemblyType {
79 None,
80 Tht,
81 Smt,
82 Mixed,
83 Other,
84 Auto,
85 };
86
87 // Constructors / Destructor
88 Package() = delete;
89 Package(const Package& other) = delete;
90 Package(const Uuid& uuid, const Version& version, const QString& author,
91 const ElementName& name_en_US, const QString& description_en_US,
92 const QString& keywords_en_US, AssemblyType assemblyType);
93 ~Package() noexcept;
94
95 // Getters
96 const QList<AlternativeName>& getAlternativeNames() const noexcept {
97 return mAlternativeNames;
98 }
99 AssemblyType getAssemblyType(bool resolveAuto) const noexcept;
100 AssemblyType guessAssemblyType() const noexcept;
101 PackagePadList& getPads() noexcept { return mPads; }
102 const PackagePadList& getPads() const noexcept { return mPads; }
103 PackageModelList& getModels() noexcept { return mModels; }
104 const PackageModelList& getModels() const noexcept { return mModels; }
105 QVector<std::shared_ptr<const PackageModel>> getModelsForFootprint(
106 const Uuid& fpt) const noexcept;
108 const FootprintList& getFootprints() const noexcept { return mFootprints; }
109
110 // Setters
111 void setAssemblyType(AssemblyType type) noexcept { mAssemblyType = type; }
112
113 // General Methods
114 virtual RuleCheckMessageList runChecks() const override;
115
116 // Operator Overloadings
117 Package& operator=(const Package& rhs) = delete;
118
119 // Static Methods
120 static std::unique_ptr<Package> open(
121 std::unique_ptr<TransactionalDirectory> directory,
122 bool abortBeforeMigration = false);
123 static QString getShortElementName() noexcept {
124 return QStringLiteral("pkg");
125 }
126 static QString getLongElementName() noexcept {
127 return QStringLiteral("package");
128 }
129
130protected: // Methods
131 virtual void serialize(SExpression& root) const override;
132
133private: // Methods
134 Package(std::unique_ptr<TransactionalDirectory> directory,
135 const SExpression& root);
136
137private: // Data
138 QList<AlternativeName> mAlternativeNames;
143};
144
145/*******************************************************************************
146 * End of File
147 ******************************************************************************/
148
149} // namespace librepcb
150
151Q_DECLARE_METATYPE(librepcb::Package::AssemblyType)
152
153#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:78
Package & operator=(const Package &rhs)=delete
void setAssemblyType(AssemblyType type) noexcept
Definition: package.h:111
AssemblyType guessAssemblyType() const noexcept
Definition: package.cpp:127
virtual RuleCheckMessageList runChecks() const override
Definition: package.cpp:175
const FootprintList & getFootprints() const noexcept
Definition: package.h:108
const QList< AlternativeName > & getAlternativeNames() const noexcept
Definition: package.h:96
QList< AlternativeName > mAlternativeNames
Optional.
Definition: package.h:138
PackagePadList mPads
empty list if the package has no pads
Definition: package.h:140
static std::unique_ptr< Package > open(std::unique_ptr< TransactionalDirectory > directory, bool abortBeforeMigration=false)
Definition: package.cpp:180
AssemblyType getAssemblyType(bool resolveAuto) const noexcept
Definition: package.cpp:118
FootprintList mFootprints
minimum one footprint
Definition: package.h:142
static QString getLongElementName() noexcept
Definition: package.h:126
PackageModelList mModels
3D models (optional)
Definition: package.h:141
AssemblyType mAssemblyType
Package assembly type (metadata)
Definition: package.h:139
~Package() noexcept
Definition: package.cpp:111
virtual void serialize(SExpression &root) const override
Serialize into librepcb::SExpression node.
Definition: package.cpp:212
FootprintList & getFootprints() noexcept
Definition: package.h:107
const PackagePadList & getPads() const noexcept
Definition: package.h:102
PackageModelList & getModels() noexcept
Definition: package.h:103
const PackageModelList & getModels() const noexcept
Definition: package.h:104
QVector< std::shared_ptr< const PackageModel > > getModelsForFootprint(const Uuid &fpt) const noexcept
Definition: package.cpp:158
PackagePadList & getPads() noexcept
Definition: package.h:101
static QString getShortElementName() noexcept
Definition: package.h:123
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:58
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
Definition: occmodel.cpp:77
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition: simplestring.h:80
AttributeKey deserialize(const SExpression &node)
Definition: attributekey.h:105
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84
Definition: package.h:64
SimpleString reference
Definition: package.h:66
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