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  // Signals
61  enum class Event {
70  };
73 
74  // Constructors / Destructor
75  FootprintPad() = delete;
76  FootprintPad(const FootprintPad& other) noexcept;
77  FootprintPad(const Uuid& padUuid, const Point& pos, const Angle& rot,
78  Shape shape, const PositiveLength& width,
79  const PositiveLength& height,
80  const UnsignedLength& drillDiameter, BoardSide side) noexcept;
81  explicit FootprintPad(const SExpression& node);
82  ~FootprintPad() noexcept;
83 
84  // Getters
85  const Uuid& getUuid() const noexcept {
86  return getPackagePadUuid();
87  } // for SerializableObjectList
88  const Uuid& getPackagePadUuid() const noexcept { return mPackagePadUuid; }
89  const Point& getPosition() const noexcept { return mPosition; }
90  const Angle& getRotation() const noexcept { return mRotation; }
91  Shape getShape() const noexcept { return mShape; }
92  const PositiveLength& getWidth() const noexcept { return mWidth; }
93  const PositiveLength& getHeight() const noexcept { return mHeight; }
94  const UnsignedLength& getDrillDiameter() const noexcept {
95  return mDrillDiameter;
96  }
97  BoardSide getBoardSide() const noexcept { return mBoardSide; }
98  QString getLayerName() const noexcept;
99  bool isOnLayer(const QString& name) const noexcept;
100  Path getOutline(const Length& expansion = Length(0)) const noexcept;
101  QPainterPath toQPainterPathPx(const Length& expansion = Length(0)) const
102  noexcept;
103 
104  // Setters
105  bool setPackagePadUuid(const Uuid& pad) noexcept;
106  bool setPosition(const Point& pos) noexcept;
107  bool setRotation(const Angle& rot) noexcept;
108  bool setShape(Shape shape) noexcept;
109  bool setWidth(const PositiveLength& width) noexcept;
110  bool setHeight(const PositiveLength& height) noexcept;
111  bool setDrillDiameter(const UnsignedLength& diameter) noexcept;
112  bool setBoardSide(BoardSide side) noexcept;
113 
114  // General Methods
115  void registerGraphicsItem(FootprintPadGraphicsItem& item) noexcept;
117 
119  virtual void serialize(SExpression& root) const override;
120 
121  // Operator Overloadings
122  bool operator==(const FootprintPad& rhs) const noexcept;
123  bool operator!=(const FootprintPad& rhs) const noexcept {
124  return !(*this == rhs);
125  }
126  FootprintPad& operator=(const FootprintPad& rhs) noexcept;
127 
128 protected: // Data
135  UnsignedLength mDrillDiameter; // no effect if BoardSide != THT!
138 };
139 
140 /*******************************************************************************
141  * Class FootprintPadList
142  ******************************************************************************/
143 
145  static constexpr const char* tagname = "pad";
146 };
147 using FootprintPadList =
150 using CmdFootprintPadInsert =
153 using CmdFootprintPadRemove =
156 using CmdFootprintPadsSwap =
159 
160 /*******************************************************************************
161  * Non-Member Functions
162  ******************************************************************************/
163 
164 } // namespace library
165 
166 template <>
169  switch (obj) {
171  return SExpression::createToken("top");
173  return SExpression::createToken("bottom");
175  return SExpression::createToken("tht");
176  default:
177  throw LogicError(__FILE__, __LINE__);
178  }
179 }
180 
181 template <>
183  const SExpression& sexpr, bool throwIfEmpty) {
184  QString str = sexpr.getStringOrToken(throwIfEmpty);
185  if (str == QLatin1String("top"))
187  else if (str == QLatin1String("bottom"))
189  else if (str == QLatin1String("tht"))
191  else
192  throw RuntimeError(__FILE__, __LINE__, str);
193 }
194 
195 template <>
197  const library::FootprintPad::Shape& obj) {
198  switch (obj) {
200  return SExpression::createToken("round");
202  return SExpression::createToken("rect");
204  return SExpression::createToken("octagon");
205  default:
206  throw LogicError(__FILE__, __LINE__);
207  }
208 }
209 
210 template <>
212  const SExpression& sexpr, bool throwIfEmpty) {
213  QString str = sexpr.getStringOrToken(throwIfEmpty);
214  if (str == QLatin1String("round"))
216  else if (str == QLatin1String("rect"))
218  else if (str == QLatin1String("octagon"))
220  else
221  throw RuntimeError(__FILE__, __LINE__, str);
222 }
223 
224 /*******************************************************************************
225  * End of File
226  ******************************************************************************/
227 
228 } // namespace librepcb
229 
230 #endif // LIBREPCB_LIBRARY_FOOTPRINTPAD_H
const PositiveLength & getWidth() const noexcept
Definition: footprintpad.h:92
The LogicError class.
Definition: exceptions.h:182
FootprintPadGraphicsItem * mRegisteredGraphicsItem
Definition: footprintpad.h:137
bool setDrillDiameter(const UnsignedLength &diameter) noexcept
Definition: footprintpad.cpp:221
The CmdListElementRemove class.
Definition: cmdlistelementremove.h:44
PositiveLength mWidth
Definition: footprintpad.h:133
Event
Definition: footprintpad.h:61
BoardSide
Definition: footprintpad.h:58
bool setShape(Shape shape) noexcept
Definition: footprintpad.cpp:185
const Point & getPosition() const noexcept
Definition: footprintpad.h:89
const PositiveLength & getHeight() const noexcept
Definition: footprintpad.h:93
Angle mRotation
Definition: footprintpad.h:131
Point mPosition
Definition: footprintpad.h:130
Shape getShape() const noexcept
Definition: footprintpad.h:91
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
~FootprintPad() noexcept
Definition: footprintpad.cpp:85
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
Signal< FootprintPad, Event > onEdited
Definition: footprintpad.h:71
const Uuid & getPackagePadUuid() const noexcept
Definition: footprintpad.h:88
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
Slot< FootprintPad, Event > OnEditedSlot
Definition: footprintpad.h:72
bool setWidth(const PositiveLength &width) noexcept
Definition: footprintpad.cpp:197
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:90
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:263
UnsignedLength mDrillDiameter
Definition: footprintpad.h:135
bool setBoardSide(BoardSide side) noexcept
Definition: footprintpad.cpp:233
const Angle & getRotation() const noexcept
Definition: footprintpad.h:90
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void unregisterGraphicsItem(FootprintPadGraphicsItem &item) noexcept
Definition: footprintpad.cpp:257
const UnsignedLength & getDrillDiameter() const noexcept
Definition: footprintpad.h:94
bool setRotation(const Angle &rot) noexcept
Definition: footprintpad.cpp:174
Shape
Definition: footprintpad.h:57
Shape mShape
Definition: footprintpad.h:132
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:97
The FootprintPadGraphicsItem class.
Definition: footprintpadgraphicsitem.h:53
Uuid mPackagePadUuid
Definition: footprintpad.h:129
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:134
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
QPainterPath toQPainterPathPx(const Length &expansion=Length(0)) const noexcept
Definition: footprintpad.cpp:136
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:780
The CmdListElementInsert class.
Definition: cmdlistelementinsert.h:44
bool setHeight(const PositiveLength &height) noexcept
Definition: footprintpad.cpp:209
Path getOutline(const Length &expansion=Length(0)) const noexcept
Definition: footprintpad.cpp:115
bool isOnLayer(const QString &name) const noexcept
Definition: footprintpad.cpp:107
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:82
bool setPosition(const Point &pos) noexcept
Definition: footprintpad.cpp:150
QString getLayerName() const noexcept
Definition: footprintpad.cpp:93
BoardSide mBoardSide
Definition: footprintpad.h:136
static constexpr const char * tagname
Definition: footprintpad.h:145
The Slot class is used to receive signals from non-QObject derived classes.
Definition: signalslot.h:36
The SExpression class.
Definition: sexpression.h:57
bool setPackagePadUuid(const Uuid &pad) noexcept
Definition: footprintpad.cpp:161
FootprintPad & operator=(const FootprintPad &rhs) noexcept
Definition: footprintpad.cpp:290
const Uuid & getUuid() const noexcept
Definition: footprintpad.h:85
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659
void registerGraphicsItem(FootprintPadGraphicsItem &item) noexcept
Definition: footprintpad.cpp:251