LibrePCB Developers Documentation
padgeometry.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_PADGEOMETRY_H
21#define LIBREPCB_CORE_PADGEOMETRY_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../types/ratio.h"
27#include "padhole.h"
28#include "path.h"
29
30#include <optional/tl/optional.hpp>
31
32#include <QtCore>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39/*******************************************************************************
40 * Class PadGeometry
41 ******************************************************************************/
42
46class PadGeometry final {
47 Q_DECLARE_TR_FUNCTIONS(PadGeometry)
48
49public:
50 // Types
51 enum class Shape {
52 RoundedRect,
53 RoundedOctagon,
54 Stroke,
55 Custom,
56 };
57
58 // Constructors / Destructor
59 PadGeometry() = delete;
60 PadGeometry(const PadGeometry& other) noexcept;
61 ~PadGeometry() noexcept;
62
63 // Getters
64 Shape getShape() const noexcept { return mShape; }
65 Length getWidth() const noexcept { return mBaseWidth + (mOffset * 2); }
66 Length getHeight() const noexcept { return mBaseHeight + (mOffset * 2); }
67 UnsignedLength getCornerRadius() const noexcept;
68 const Path& getPath() const noexcept { return mPath; }
69 const PadHoleList& getHoles() const noexcept { return mHoles; }
70
71 // General Methods
72 QVector<Path> toOutlines() const;
73 QPainterPath toQPainterPathPx() const noexcept;
74 QPainterPath toFilledQPainterPathPx() const noexcept;
75 QPainterPath toHolesQPainterPathPx() const noexcept;
76 PadGeometry withOffset(const Length& offset) const noexcept;
77 PadGeometry withoutHoles() const noexcept;
78
79 // Static Methods
80 static PadGeometry roundedRect(const PositiveLength& width,
81 const PositiveLength& height,
82 const UnsignedLimitedRatio& radius,
83 const PadHoleList& holes) noexcept;
84 static PadGeometry roundedOctagon(const PositiveLength& width,
85 const PositiveLength& height,
86 const UnsignedLimitedRatio& radius,
87 const PadHoleList& holes) noexcept;
88 static PadGeometry stroke(const PositiveLength& diameter,
89 const NonEmptyPath& path,
90 const PadHoleList& holes) noexcept;
91 static PadGeometry custom(const Path& outline, const PadHoleList& holes);
92 static bool isValidCustomOutline(const Path& path) noexcept;
93
94 // Operator Overloadings
95 bool operator==(const PadGeometry& rhs) const noexcept;
96 bool operator!=(const PadGeometry& rhs) const noexcept {
97 return !(*this == rhs);
98 }
99 PadGeometry& operator=(const PadGeometry& rhs) noexcept;
100
101private: // Methods
102 PadGeometry(Shape shape, const Length& width, const Length& height,
103 const UnsignedLimitedRatio& radius, const Path& path,
104 const Length& offset, const PadHoleList& holes) noexcept;
105
111 static PositiveLength maxArcTolerance() noexcept {
112 return PositiveLength(5000);
113 }
114
115private: // Data
123};
124
125/*******************************************************************************
126 * End of File
127 ******************************************************************************/
128
129} // namespace librepcb
130
131#endif
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
The PadGeometry class describes the shape of a pad.
Definition: padgeometry.h:46
Length getWidth() const noexcept
Definition: padgeometry.h:65
Shape mShape
Definition: padgeometry.h:116
~PadGeometry() noexcept
Definition: padgeometry.cpp:61
static PadGeometry stroke(const PositiveLength &diameter, const NonEmptyPath &path, const PadHoleList &holes) noexcept
Definition: padgeometry.cpp:213
PadHoleList mHoles
Definition: padgeometry.h:122
static bool isValidCustomOutline(const Path &path) noexcept
Definition: padgeometry.cpp:227
PadGeometry withoutHoles() const noexcept
Definition: padgeometry.cpp:188
QPainterPath toHolesQPainterPathPx() const noexcept
Definition: padgeometry.cpp:171
UnsignedLimitedRatio mRadius
Definition: padgeometry.h:119
Length getHeight() const noexcept
Definition: padgeometry.h:66
UnsignedLength getCornerRadius() const noexcept
Definition: padgeometry.cpp:68
static PadGeometry roundedOctagon(const PositiveLength &width, const PositiveLength &height, const UnsignedLimitedRatio &radius, const PadHoleList &holes) noexcept
Definition: padgeometry.cpp:205
const Path & getPath() const noexcept
Definition: padgeometry.h:68
PadGeometry & operator=(const PadGeometry &rhs) noexcept
Definition: padgeometry.cpp:247
const PadHoleList & getHoles() const noexcept
Definition: padgeometry.h:69
Shape
Definition: padgeometry.h:51
static PositiveLength maxArcTolerance() noexcept
Definition: padgeometry.h:111
Length mBaseWidth
Definition: padgeometry.h:117
QPainterPath toQPainterPathPx() const noexcept
Definition: padgeometry.cpp:146
QVector< Path > toOutlines() const
Definition: padgeometry.cpp:79
static PadGeometry custom(const Path &outline, const PadHoleList &holes)
Definition: padgeometry.cpp:221
Path mPath
Definition: padgeometry.h:120
static PadGeometry roundedRect(const PositiveLength &width, const PositiveLength &height, const UnsignedLimitedRatio &radius, const PadHoleList &holes) noexcept
Definition: padgeometry.cpp:197
Length mOffset
Definition: padgeometry.h:121
QPainterPath toFilledQPainterPathPx() const noexcept
Definition: padgeometry.cpp:159
PadGeometry withOffset(const Length &offset) const noexcept
Definition: padgeometry.cpp:183
Length mBaseHeight
Definition: padgeometry.h:118
Shape getShape() const noexcept
Definition: padgeometry.h:64
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< Path, NonEmptyPathConstraint, NonEmptyPathVerifier > NonEmptyPath
Definition: path.h:222
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< Ratio, UnsignedLimitedRatioConstraint, UnsignedLimitedRatioVerifier > UnsignedLimitedRatio
Definition: ratio.h:378