LibrePCB Developers Documentation
footprintpad.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_FOOTPRINTPAD_H
21 #define LIBREPCB_CORE_FOOTPRINTPAD_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../exceptions.h"
27 #include "../../geometry/padgeometry.h"
28 #include "../../geometry/padhole.h"
29 #include "../../geometry/path.h"
30 #include "../../qtcompat.h"
31 #include "../../serialization/serializableobjectlist.h"
32 #include "../../types/angle.h"
33 #include "../../types/length.h"
34 #include "../../types/maskconfig.h"
35 #include "../../types/point.h"
36 #include "../../types/ratio.h"
37 #include "../../types/uuid.h"
38 
39 #include <QtCore>
40 
41 /*******************************************************************************
42  * Namespace / Forward Declarations
43  ******************************************************************************/
44 namespace librepcb {
45 
46 class Layer;
47 
48 /*******************************************************************************
49  * Class FootprintPad
50  ******************************************************************************/
51 
55 class FootprintPad final {
56  Q_DECLARE_TR_FUNCTIONS(FootprintPad)
57 
58 public:
59  // Types
60  enum class Shape {
63  Custom,
64  };
65 
66  enum class ComponentSide {
67  Top,
68  Bottom,
69  };
70 
71  enum class Function {
72  Unspecified = 0,
73  StandardPad,
74  PressFitPad,
75  ThermalPad,
76  BgaPad,
77  EdgeConnectorPad,
78  TestPad,
79  LocalFiducial,
80  GlobalFiducial,
81  _COUNT,
82  };
83 
84  // Signals
85  enum class Event {
86  UuidChanged,
87  PackagePadUuidChanged,
88  PositionChanged,
89  RotationChanged,
90  ShapeChanged,
91  WidthChanged,
92  HeightChanged,
93  RadiusChanged,
94  CustomShapeOutlineChanged,
95  StopMaskConfigChanged,
96  SolderPasteConfigChanged,
97  CopperClearanceChanged,
98  ComponentSideChanged,
99  FunctionChanged,
100  HolesEdited,
101  };
104 
105  // Constructors / Destructor
106  FootprintPad() = delete;
107  FootprintPad(const FootprintPad& other) noexcept;
108  FootprintPad(const Uuid& uuid, const tl::optional<Uuid>& pkgPadUuid,
109  const Point& pos, const Angle& rot, Shape shape,
110  const PositiveLength& width, const PositiveLength& height,
111  const UnsignedLimitedRatio& radius,
112  const Path& customShapeOutline, const MaskConfig& autoStopMask,
113  const MaskConfig& autoSolderPaste,
114  const UnsignedLength& copperClearance, ComponentSide side,
115  Function function, const PadHoleList& holes) noexcept;
116  explicit FootprintPad(const SExpression& node);
117  ~FootprintPad() noexcept;
118 
119  // Getters
120  const Uuid& getUuid() const noexcept { return mUuid; }
121  const tl::optional<Uuid>& getPackagePadUuid() const noexcept {
122  return mPackagePadUuid;
123  }
124  const Point& getPosition() const noexcept { return mPosition; }
125  const Angle& getRotation() const noexcept { return mRotation; }
126  Shape getShape() const noexcept { return mShape; }
127  const PositiveLength& getWidth() const noexcept { return mWidth; }
128  const PositiveLength& getHeight() const noexcept { return mHeight; }
129  const UnsignedLimitedRatio& getRadius() const noexcept { return mRadius; }
130  const Path& getCustomShapeOutline() const noexcept {
131  return mCustomShapeOutline;
132  }
133  const MaskConfig& getStopMaskConfig() const noexcept {
134  return mStopMaskConfig;
135  }
136  const MaskConfig& getSolderPasteConfig() const noexcept {
137  return mSolderPasteConfig;
138  }
139  const UnsignedLength& getCopperClearance() const noexcept {
140  return mCopperClearance;
141  }
142  ComponentSide getComponentSide() const noexcept { return mComponentSide; }
143  Function getFunction() const noexcept { return mFunction; }
144  bool getFunctionIsFiducial() const noexcept;
145  bool getFunctionNeedsSoldering() const noexcept;
146  const PadHoleList& getHoles() const noexcept { return mHoles; }
147  PadHoleList& getHoles() noexcept { return mHoles; }
148  bool isTht() const noexcept;
149  bool isOnLayer(const Layer& layer) const noexcept;
150  const Layer& getSmtLayer() const noexcept;
151  bool hasTopCopper() const noexcept;
152  bool hasBottomCopper() const noexcept;
153  bool hasAutoTopStopMask() const noexcept;
154  bool hasAutoBottomStopMask() const noexcept;
155  bool hasAutoTopSolderPaste() const noexcept;
156  bool hasAutoBottomSolderPaste() const noexcept;
157  PadGeometry getGeometry() const noexcept;
158  QHash<const Layer*, QList<PadGeometry>> buildPreviewGeometries()
159  const noexcept;
160 
161  // Setters
162  bool setPackagePadUuid(const tl::optional<Uuid>& pad) noexcept;
163  bool setPosition(const Point& pos) noexcept;
164  bool setRotation(const Angle& rot) noexcept;
165  bool setShape(Shape shape) noexcept;
166  bool setWidth(const PositiveLength& width) noexcept;
167  bool setHeight(const PositiveLength& height) noexcept;
168  bool setRadius(const UnsignedLimitedRatio& radius) noexcept;
169  bool setCustomShapeOutline(const Path& outline) noexcept;
170  bool setStopMaskConfig(const MaskConfig& config) noexcept;
171  bool setSolderPasteConfig(const MaskConfig& config) noexcept;
172  bool setCopperClearance(const UnsignedLength& clearance) noexcept;
173  bool setComponentSide(ComponentSide side) noexcept;
174  bool setFunction(Function function) noexcept;
175 
176  // General Methods
177 
183  void serialize(SExpression& root) const;
184 
185  // Operator Overloadings
186  bool operator==(const FootprintPad& rhs) const noexcept;
187  bool operator!=(const FootprintPad& rhs) const noexcept {
188  return !(*this == rhs);
189  }
190  FootprintPad& operator=(const FootprintPad& rhs) noexcept;
191 
192  // Static Methods
194  const PositiveLength& width, const PositiveLength& height) noexcept;
195  static QString getFunctionDescriptionTr(Function function) noexcept;
196 
197 private: // Methods
198  void holesEdited(const PadHoleList& list, int index,
199  const std::shared_ptr<const PadHole>& hole,
200  PadHoleList::Event event) noexcept;
201 
202 private: // Data
204 
210  tl::optional<Uuid> mPackagePadUuid;
224 
225  // Slots
227 };
228 
229 /*******************************************************************************
230  * Non-Member Functions
231  ******************************************************************************/
232 
234  QtCompat::Hash seed = 0) noexcept {
235  return ::qHash(static_cast<int>(key), seed);
236 }
237 
238 /*******************************************************************************
239  * Class FootprintPadList
240  ******************************************************************************/
241 
243  static constexpr const char* tagname = "pad";
244 };
245 using FootprintPadList =
248 
249 /*******************************************************************************
250  * End of File
251  ******************************************************************************/
252 
253 } // namespace librepcb
254 
255 Q_DECLARE_METATYPE(librepcb::FootprintPad::Function)
256 
257 #endif
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
Function getFunction() const noexcept
Definition: footprintpad.h:143
bool setPosition(const Point &pos) noexcept
Definition: footprintpad.cpp:351
const Uuid & getUuid() const noexcept
Definition: footprintpad.h:120
bool hasAutoTopStopMask() const noexcept
Definition: footprintpad.cpp:275
const Point & getPosition() const noexcept
Definition: footprintpad.h:124
bool setRotation(const Angle &rot) noexcept
Definition: footprintpad.cpp:371
const Layer & getSmtLayer() const noexcept
Definition: footprintpad.cpp:259
bool setWidth(const PositiveLength &width) noexcept
Definition: footprintpad.cpp:391
Shape
Definition: footprintpad.h:60
bool setSolderPasteConfig(const MaskConfig &config) noexcept
Definition: footprintpad.cpp:441
bool getFunctionIsFiducial() const noexcept
Definition: footprintpad.cpp:230
The MaskConfig class defines how to add automatic stop mask or solder paste.
Definition: maskconfig.h:45
const PositiveLength & getWidth() const noexcept
Definition: footprintpad.h:127
Definition: footprintpad.h:242
UnsignedLength mCopperClearance
Definition: footprintpad.h:220
bool isTht() const noexcept
Definition: footprintpad.cpp:247
Definition: occmodel.cpp:77
The Layer class provides all supported geometry layers.
Definition: layer.h:40
bool hasAutoBottomSolderPaste() const noexcept
Definition: footprintpad.cpp:290
PadHoleList::OnEditedSlot mHolesEditedSlot
Definition: footprintpad.h:226
bool setPackagePadUuid(const tl::optional< Uuid > &pad) noexcept
Definition: footprintpad.cpp:361
Slot< FootprintPad, Event > OnEditedSlot
Definition: footprintpad.h:103
Angle mRotation
Definition: footprintpad.h:212
The PadGeometry class describes the shape of a pad.
Definition: padgeometry.h:46
bool hasTopCopper() const noexcept
Definition: footprintpad.cpp:267
bool isOnLayer(const Layer &layer) const noexcept
Definition: footprintpad.cpp:251
The FootprintPad class represents a pad of a footprint.
Definition: footprintpad.h:55
bool setRadius(const UnsignedLimitedRatio &radius) noexcept
Definition: footprintpad.cpp:411
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
PadHoleList & getHoles() noexcept
Definition: footprintpad.h:147
Shape mShape
Definition: footprintpad.h:213
Uuid mUuid
Definition: footprintpad.h:203
PadGeometry getGeometry() const noexcept
Definition: footprintpad.cpp:295
Point mPosition
Definition: footprintpad.h:211
bool setCopperClearance(const UnsignedLength &clearance) noexcept
Definition: footprintpad.cpp:451
bool setHeight(const PositiveLength &height) noexcept
Definition: footprintpad.cpp:401
ComponentSide
Definition: footprintpad.h:66
FootprintPad & operator=(const FootprintPad &rhs) noexcept
Definition: footprintpad.cpp:532
const PositiveLength & getHeight() const noexcept
Definition: footprintpad.h:128
const tl::optional< Uuid > & getPackagePadUuid() const noexcept
Definition: footprintpad.h:121
Shape getShape() const noexcept
Definition: footprintpad.h:126
bool hasAutoBottomStopMask() const noexcept
Definition: footprintpad.cpp:280
PositiveLength mHeight
Definition: footprintpad.h:215
bool setStopMaskConfig(const MaskConfig &config) noexcept
Definition: footprintpad.cpp:431
bool operator==(const FootprintPad &rhs) const noexcept
Definition: footprintpad.cpp:513
void holesEdited(const PadHoleList &list, int index, const std::shared_ptr< const PadHole > &hole, PadHoleList::Event event) noexcept
Definition: footprintpad.cpp:601
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
Signal< FootprintPad, Event > onEdited
Definition: footprintpad.h:102
tl::optional< Uuid > mPackagePadUuid
Definition: footprintpad.h:210
const PadHoleList & getHoles() const noexcept
Definition: footprintpad.h:146
ComponentSide mComponentSide
Definition: footprintpad.h:221
static QString getFunctionDescriptionTr(Function function) noexcept
Definition: footprintpad.cpp:569
bool hasBottomCopper() const noexcept
Definition: footprintpad.cpp:271
Function
Definition: footprintpad.h:71
const MaskConfig & getStopMaskConfig() const noexcept
Definition: footprintpad.h:133
Event
Definition: footprintpad.h:85
MaskConfig mStopMaskConfig
Definition: footprintpad.h:218
static UnsignedLimitedRatio getRecommendedRadius(const PositiveLength &width, const PositiveLength &height) noexcept
Definition: footprintpad.cpp:558
bool operator!=(const FootprintPad &rhs) const noexcept
Definition: footprintpad.h:187
PadHoleList mHoles
If not empty, it&#39;s a THT pad.
Definition: footprintpad.h:223
const Angle & getRotation() const noexcept
Definition: footprintpad.h:125
~FootprintPad() noexcept
Definition: footprintpad.cpp:223
UnsignedLimitedRatio mRadius
Definition: footprintpad.h:216
Path mCustomShapeOutline
Empty if not needed; Implicitly closed.
Definition: footprintpad.h:217
const MaskConfig & getSolderPasteConfig() const noexcept
Definition: footprintpad.h:136
bool getFunctionNeedsSoldering() const noexcept
Definition: footprintpad.cpp:235
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:58
ComponentSide getComponentSide() const noexcept
Definition: footprintpad.h:142
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
uint Hash
Return type of Qt&#39;s qHash() function.
Definition: qtcompat.h:58
const UnsignedLength & getCopperClearance() const noexcept
Definition: footprintpad.h:139
type_safe::constrained_type< Ratio, UnsignedLimitedRatioConstraint, UnsignedLimitedRatioVerifier > UnsignedLimitedRatio
Definition: ratio.h:378
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
QtCompat::Hash qHash(const FootprintPad::Function &key, QtCompat::Hash seed=0) noexcept
Definition: footprintpad.h:233
const Path & getCustomShapeOutline() const noexcept
Definition: footprintpad.h:130
QHash< const Layer *, QList< PadGeometry > > buildPreviewGeometries() const noexcept
Definition: footprintpad.cpp:311
bool setCustomShapeOutline(const Path &outline) noexcept
Definition: footprintpad.cpp:421
Function mFunction
Definition: footprintpad.h:222
bool setComponentSide(ComponentSide side) noexcept
Definition: footprintpad.cpp:462
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
PositiveLength mWidth
Definition: footprintpad.h:214
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: footprintpad.cpp:486
bool hasAutoTopSolderPaste() const noexcept
Definition: footprintpad.cpp:285
const UnsignedLimitedRatio & getRadius() const noexcept
Definition: footprintpad.h:129
The SExpression class.
Definition: sexpression.h:69
bool setShape(Shape shape) noexcept
Definition: footprintpad.cpp:381
bool setFunction(Function function) noexcept
Definition: footprintpad.cpp:472
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
MaskConfig mSolderPasteConfig
Definition: footprintpad.h:219