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  ******************************************************************************/
39 namespace librepcb {
40 
41 /*******************************************************************************
42  * Class Package
43  ******************************************************************************/
44 
59 class Package final : public LibraryElement {
60  Q_OBJECT
61 
62 public:
63  // Types
64  struct AlternativeName {
67 
68  AlternativeName(const ElementName& name, const SimpleString& reference)
69  : name(name), reference(reference) {}
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;
107  FootprintList& getFootprints() noexcept { return mFootprints; }
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 
130 protected: // Methods
131  virtual void serialize(SExpression& root) const override;
132 
133 private: // Methods
134  Package(std::unique_ptr<TransactionalDirectory> directory,
135  const SExpression& root);
136 
137 private: // Data
138  QList<AlternativeName> mAlternativeNames;
143 };
144 
145 /*******************************************************************************
146  * End of File
147  ******************************************************************************/
148 
149 } // namespace librepcb
150 
151 Q_DECLARE_METATYPE(librepcb::Package::AssemblyType)
152 
153 #endif
QVector< std::shared_ptr< const PackageModel > > getModelsForFootprint(const Uuid &fpt) const noexcept
Definition: package.cpp:158
The Version class represents a version number in the format "1.42.7".
Definition: version.h:58
const QList< AlternativeName > & getAlternativeNames() const noexcept
Definition: package.h:96
const PackagePadList & getPads() const noexcept
Definition: package.h:102
Definition: occmodel.cpp:77
PackagePadList mPads
empty list if the package has no pads
Definition: package.h:140
Definition: package.h:64
~Package() noexcept
Definition: package.cpp:111
QVector< std::shared_ptr< const RuleCheckMessage > > RuleCheckMessageList
Definition: rulecheckmessage.h:104
QList< AlternativeName > mAlternativeNames
Optional.
Definition: package.h:138
AlternativeName(const SExpression &node)
Definition: package.h:70
static QString getLongElementName() noexcept
Definition: package.h:126
type_safe::constrained_type< QString, SimpleStringConstraint, SimpleStringVerifier > SimpleString
Definition: simplestring.h:80
AlternativeName(const ElementName &name, const SimpleString &reference)
Definition: package.h:68
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:59
AssemblyType mAssemblyType
Package assembly type (metadata)
Definition: package.h:139
SimpleString reference
Definition: package.h:66
PackageModelList mModels
3D models (optional)
Definition: package.h:141
AssemblyType guessAssemblyType() const noexcept
Definition: package.cpp:127
PackageModelList & getModels() noexcept
Definition: package.h:103
static QString getShortElementName() noexcept
Definition: package.h:123
AssemblyType
Definition: package.h:78
Package & operator=(const Package &rhs)=delete
void appendChild(std::unique_ptr< SExpression > child)
Definition: sexpression.cpp:217
FootprintList mFootprints
minimum one footprint
Definition: package.h:142
The LibraryElement class extends the LibraryBaseElement class with some attributes and methods which ...
Definition: libraryelement.h:45
void setAssemblyType(AssemblyType type) noexcept
Definition: package.h:111
AttributeKey deserialize(const SExpression &node)
Definition: attributekey.h:105
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
void serialize(SExpression &root) const
Definition: package.h:73
PackagePadList & getPads() noexcept
Definition: package.h:101
FootprintList & getFootprints() noexcept
Definition: package.h:107
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
const PackageModelList & getModels() const noexcept
Definition: package.h:104
virtual RuleCheckMessageList runChecks() const override
Definition: package.cpp:175
The SExpression class.
Definition: sexpression.h:69
ElementName name
Definition: package.h:65
const FootprintList & getFootprints() const noexcept
Definition: package.h:108
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84