LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_LIBRARY_FOOTPRINTPAD_H
21 #define LIBREPCB_LIBRARY_FOOTPRINTPAD_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
32 #include <librepcb/common/uuid.h>
33 
34 #include <QtCore>
35 #include <QtWidgets>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 namespace librepcb {
41 namespace library {
42 
43 class FootprintPadGraphicsItem;
44 
45 /*******************************************************************************
46  * Class FootprintPad
47  ******************************************************************************/
48 
52 class FootprintPad final : public SerializableObject {
53  Q_DECLARE_TR_FUNCTIONS(FootprintPad)
54 
55 public:
56  // Types
57  enum class Shape { ROUND, RECT, OCTAGON };
58  enum class BoardSide { TOP, BOTTOM, THT };
59 
60  // Constructors / Destructor
61  FootprintPad() = delete;
62  FootprintPad(const FootprintPad& other) noexcept;
63  FootprintPad(const Uuid& padUuid, const Point& pos, const Angle& rot,
64  Shape shape, const PositiveLength& width,
65  const PositiveLength& height,
66  const UnsignedLength& drillDiameter, BoardSide side) noexcept;
67  explicit FootprintPad(const SExpression& node);
68  ~FootprintPad() noexcept;
69 
70  // Getters
71  const Uuid& getUuid() const noexcept {
72  return getPackagePadUuid();
73  } // for SerializableObjectList
74  const Uuid& getPackagePadUuid() const noexcept { return mPackagePadUuid; }
75  const Point& getPosition() const noexcept { return mPosition; }
76  const Angle& getRotation() const noexcept { return mRotation; }
77  Shape getShape() const noexcept { return mShape; }
78  const PositiveLength& getWidth() const noexcept { return mWidth; }
79  const PositiveLength& getHeight() const noexcept { return mHeight; }
80  const UnsignedLength& getDrillDiameter() const noexcept {
81  return mDrillDiameter;
82  }
83  BoardSide getBoardSide() const noexcept { return mBoardSide; }
84  QString getLayerName() const noexcept;
85  bool isOnLayer(const QString& name) const noexcept;
86  Path getOutline(const Length& expansion = Length(0)) const noexcept;
87  QPainterPath toQPainterPathPx(const Length& expansion = Length(0)) const
88  noexcept;
89 
90  // Setters
91  void setPackagePadUuid(const Uuid& pad) noexcept;
92  void setPosition(const Point& pos) noexcept;
93  void setRotation(const Angle& rot) noexcept;
94  void setShape(Shape shape) noexcept;
95  void setWidth(const PositiveLength& width) noexcept;
96  void setHeight(const PositiveLength& height) noexcept;
97  void setDrillDiameter(const UnsignedLength& diameter) noexcept;
98  void setBoardSide(BoardSide side) noexcept;
99 
100  // General Methods
101  void registerGraphicsItem(FootprintPadGraphicsItem& item) noexcept;
103 
105  virtual void serialize(SExpression& root) const override;
106 
107  // Operator Overloadings
108  bool operator==(const FootprintPad& rhs) const noexcept;
109  bool operator!=(const FootprintPad& rhs) const noexcept {
110  return !(*this == rhs);
111  }
112  FootprintPad& operator=(const FootprintPad& rhs) noexcept;
113 
114 protected: // Data
121  UnsignedLength mDrillDiameter; // no effect if BoardSide != THT!
124 };
125 
126 /*******************************************************************************
127  * Class FootprintPadList
128  ******************************************************************************/
129 
131  static constexpr const char* tagname = "pad";
132 };
133 using FootprintPadList =
135 using CmdFootprintPadInsert =
137 using CmdFootprintPadRemove =
139 using CmdFootprintPadsSwap =
141 
142 /*******************************************************************************
143  * Non-Member Functions
144  ******************************************************************************/
145 
146 } // namespace library
147 
148 template <>
151  switch (obj) {
153  return SExpression::createToken("top");
155  return SExpression::createToken("bottom");
157  return SExpression::createToken("tht");
158  default:
159  throw LogicError(__FILE__, __LINE__);
160  }
161 }
162 
163 template <>
165  const SExpression& sexpr, bool throwIfEmpty) {
166  QString str = sexpr.getStringOrToken(throwIfEmpty);
167  if (str == QLatin1String("top"))
169  else if (str == QLatin1String("bottom"))
171  else if (str == QLatin1String("tht"))
173  else
174  throw RuntimeError(__FILE__, __LINE__, str);
175 }
176 
177 template <>
179  const library::FootprintPad::Shape& obj) {
180  switch (obj) {
182  return SExpression::createToken("round");
184  return SExpression::createToken("rect");
186  return SExpression::createToken("octagon");
187  default:
188  throw LogicError(__FILE__, __LINE__);
189  }
190 }
191 
192 template <>
194  const SExpression& sexpr, bool throwIfEmpty) {
195  QString str = sexpr.getStringOrToken(throwIfEmpty);
196  if (str == QLatin1String("round"))
198  else if (str == QLatin1String("rect"))
200  else if (str == QLatin1String("octagon"))
202  else
203  throw RuntimeError(__FILE__, __LINE__, str);
204 }
205 
206 /*******************************************************************************
207  * End of File
208  ******************************************************************************/
209 
210 } // namespace librepcb
211 
212 #endif // LIBREPCB_LIBRARY_FOOTPRINTPAD_H
const PositiveLength & getWidth() const noexcept
Definition: footprintpad.h:78
The LogicError class.
Definition: exceptions.h:182
FootprintPadGraphicsItem * mRegisteredGraphicsItem
Definition: footprintpad.h:123
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
PositiveLength mWidth
Definition: footprintpad.h:119
void setPosition(const Point &pos) noexcept
Definition: footprintpad.cpp:159
BoardSide
Definition: footprintpad.h:58
const Point & getPosition() const noexcept
Definition: footprintpad.h:75
void setShape(Shape shape) noexcept
Definition: footprintpad.cpp:173
const PositiveLength & getHeight() const noexcept
Definition: footprintpad.h:79
Angle mRotation
Definition: footprintpad.h:117
Point mPosition
Definition: footprintpad.h:116
Shape getShape() const noexcept
Definition: footprintpad.h:77
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
~FootprintPad() noexcept
Definition: footprintpad.cpp:94
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:79
const Uuid & getPackagePadUuid() const noexcept
Definition: footprintpad.h:74
void setRotation(const Angle &rot) noexcept
Definition: footprintpad.cpp:168
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:93
The CmdListElementsSwap class.
Definition: cmdlistelementsswap.h:44
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
virtual void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: footprintpad.cpp:221
void setPackagePadUuid(const Uuid &pad) noexcept
Definition: footprintpad.cpp:164
UnsignedLength mDrillDiameter
Definition: footprintpad.h:121
const Angle & getRotation() const noexcept
Definition: footprintpad.h:76
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void unregisterGraphicsItem(FootprintPadGraphicsItem &item) noexcept
Definition: footprintpad.cpp:215
const UnsignedLength & getDrillDiameter() const noexcept
Definition: footprintpad.h:80
Shape
Definition: footprintpad.h:57
Shape mShape
Definition: footprintpad.h:118
The RuntimeError class.
Definition: exceptions.h:219
The FootprintPad class represents a pad of a footprint.
Definition: footprintpad.h:52
BoardSide getBoardSide() const noexcept
Definition: footprintpad.h:83
The FootprintPadGraphicsItem class.
Definition: footprintpadgraphicsitem.h:54
Uuid mPackagePadUuid
Definition: footprintpad.h:115
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
PositiveLength mHeight
Definition: footprintpad.h:120
QPainterPath toQPainterPathPx(const Length &expansion=Length(0)) const noexcept
Definition: footprintpad.cpp:145
void setBoardSide(BoardSide side) noexcept
Definition: footprintpad.cpp:197
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
Path getOutline(const Length &expansion=Length(0)) const noexcept
Definition: footprintpad.cpp:124
bool isOnLayer(const QString &name) const noexcept
Definition: footprintpad.cpp:116
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:85
void setWidth(const PositiveLength &width) noexcept
Definition: footprintpad.cpp:179
QString getLayerName() const noexcept
Definition: footprintpad.cpp:102
BoardSide mBoardSide
Definition: footprintpad.h:122
static constexpr const char * tagname
Definition: footprintpad.h:131
The SExpression class.
Definition: sexpression.h:60
FootprintPad & operator=(const FootprintPad &rhs) noexcept
Definition: footprintpad.cpp:248
void setHeight(const PositiveLength &height) noexcept
Definition: footprintpad.cpp:185
const Uuid & getUuid() const noexcept
Definition: footprintpad.h:71
void setDrillDiameter(const UnsignedLength &diameter) noexcept
Definition: footprintpad.cpp:191
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
void registerGraphicsItem(FootprintPadGraphicsItem &item) noexcept
Definition: footprintpad.cpp:209