LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bi_via.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_PROJECT_BI_VIA_H
21 #define LIBREPCB_PROJECT_BI_VIA_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphicsitems/bgi_via.h"
27 #include "./bi_netline.h"
28 #include "bi_base.h"
29 
32 #include <librepcb/common/uuid.h>
33 
34 #include <QtCore>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 namespace project {
41 
42 /*******************************************************************************
43  * Class BI_Via
44  ******************************************************************************/
45 
49 class BI_Via final : public BI_Base,
50  public BI_NetLineAnchor,
51  public SerializableObject {
52  Q_OBJECT
53 
54 public:
55  // Public Types
56  enum class Shape { Round, Square, Octagon };
57 
58  // Constructors / Destructor
59  BI_Via() = delete;
60  BI_Via(const BI_Via& other) = delete;
61  BI_Via(BI_NetSegment& netsegment, const BI_Via& other);
62  BI_Via(BI_NetSegment& netsegment, const SExpression& node);
63  BI_Via(BI_NetSegment& netsegment, const Point& position, BI_Via::Shape shape,
64  const PositiveLength& size, const PositiveLength& drillDiameter);
65  ~BI_Via() noexcept;
66 
67  // Getters
68  BI_NetSegment& getNetSegment() const noexcept { return mNetSegment; }
69  NetSignal& getNetSignalOfNetSegment() const noexcept;
70  const Uuid& getUuid() const noexcept { return mUuid; }
71  Shape getShape() const noexcept { return mShape; }
72  const PositiveLength& getDrillDiameter() const noexcept {
73  return mDrillDiameter;
74  }
75  const PositiveLength& getSize() const noexcept { return mSize; }
76  bool isUsed() const noexcept { return (mRegisteredNetLines.count() > 0); }
77  bool isOnLayer(const QString& layerName) const noexcept;
78  bool isSelectable() const noexcept override;
79  Path getOutline(const Length& expansion = Length(0)) const noexcept;
80  Path getSceneOutline(const Length& expansion = Length(0)) const noexcept;
81  QPainterPath toQPainterPathPx(const Length& expansion = Length(0)) const
82  noexcept;
83 
84  // Setters
85  void setPosition(const Point& position) noexcept;
86  void setShape(Shape shape) noexcept;
87  void setSize(const PositiveLength& size) noexcept;
88  void setDrillDiameter(const PositiveLength& diameter) noexcept;
89 
90  // General Methods
91  void addToBoard() override;
92  void removeFromBoard() override;
93 
95  void serialize(SExpression& root) const override;
96 
97  // Inherited from BI_Base
98  Type_t getType() const noexcept override { return BI_Base::Type_t::Via; }
99  const Point& getPosition() const noexcept override { return mPosition; }
100  bool getIsMirrored() const noexcept override { return false; }
101  QPainterPath getGrabAreaScenePx() const noexcept override;
102  void setSelected(bool selected) noexcept override;
103 
104  // Inherited from BI_NetLineAnchor
105  void registerNetLine(BI_NetLine& netline) override;
106  void unregisterNetLine(BI_NetLine& netline) override;
107  const QSet<BI_NetLine*>& getNetLines() const noexcept override {
108  return mRegisteredNetLines;
109  }
110 
111  // Operator Overloadings
112  BI_Via& operator=(const BI_Via& rhs) = delete;
113  bool operator==(const BI_Via& rhs) noexcept { return (this == &rhs); }
114  bool operator!=(const BI_Via& rhs) noexcept { return (this != &rhs); }
115 
116 private:
117  void init();
118  void boardAttributesChanged();
119 
120  // General
122  QScopedPointer<BGI_Via> mGraphicsItem;
123  QMetaObject::Connection mHighlightChangedConnection;
124 
125  // Attributes
131 
132  // Registered Elements
133  QSet<BI_NetLine*> mRegisteredNetLines;
134 };
135 
136 /*******************************************************************************
137  * Non-Member Functions
138  ******************************************************************************/
139 
140 } // namespace project
141 
142 template <>
144  switch (obj) {
146  return SExpression::createToken("round");
148  return SExpression::createToken("square");
150  return SExpression::createToken("octagon");
151  default:
152  throw LogicError(__FILE__, __LINE__);
153  }
154 }
155 
156 template <>
158  const SExpression& sexpr, bool throwIfEmpty) {
159  QString str = sexpr.getStringOrToken(throwIfEmpty);
160  if (str == "round")
162  else if (str == "square")
164  else if (str == "octagon")
166  else
167  throw RuntimeError(
168  __FILE__, __LINE__,
169  QString(project::BI_Via::tr("Unknown via shape: \"%1\"")).arg(str));
170 }
171 
172 /*******************************************************************************
173  * End of File
174  ******************************************************************************/
175 
176 } // namespace librepcb
177 
178 #endif // LIBREPCB_PROJECT_BI_VIA_H
The LogicError class.
Definition: exceptions.h:182
void setShape(Shape shape) noexcept
Definition: bi_via.cpp:154
PositiveLength mSize
Definition: bi_via.h:129
void init()
Definition: bi_via.cpp:82
bool isSelectable() const noexceptoverride
Definition: bi_via.cpp:234
~BI_Via() noexcept
Definition: bi_via.cpp:92
QSet< BI_NetLine * > mRegisteredNetLines
Definition: bi_via.h:133
void unregisterNetLine(BI_NetLine &netline) override
Definition: bi_via.cpp:209
QScopedPointer< BGI_Via > mGraphicsItem
Definition: bi_via.h:122
Type_t
Definition: bi_base.h:57
Shape mShape
Definition: bi_via.h:128
librepcb::project::BI_Via
void setDrillDiameter(const PositiveLength &diameter) noexcept
Definition: bi_via.cpp:168
QPainterPath toQPainterPathPx(const Length &expansion=Length(0)) const noexcept
Definition: bi_via.cpp:131
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
void setSelected(bool selected) noexceptoverride
Definition: bi_via.cpp:238
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:79
bool getIsMirrored() const noexceptoverride
Definition: bi_via.h:100
void setPosition(const Point &position) noexcept
Definition: bi_via.cpp:143
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
bool operator!=(const BI_Via &rhs) noexcept
Definition: bi_via.h:114
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:93
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:274
void registerNetLine(BI_NetLine &netline) override
Definition: bi_via.cpp:199
void boardAttributesChanged()
Definition: bi_via.cpp:247
The BI_NetSegment class.
Definition: bi_netsegment.h:59
BI_NetSegment & mNetSegment
Definition: bi_via.h:121
const Uuid & getUuid() const noexcept
Definition: bi_via.h:70
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void addToBoard() override
Definition: bi_via.cpp:179
PositiveLength mDrillDiameter
Definition: bi_via.h:130
Path getSceneOutline(const Length &expansion=Length(0)) const noexcept
Definition: bi_via.cpp:127
Type_t getType() const noexceptoverride
Definition: bi_via.h:98
bool operator==(const BI_Via &rhs) noexcept
Definition: bi_via.h:113
Point mPosition
Definition: bi_via.h:127
const QSet< BI_NetLine * > & getNetLines() const noexceptoverride
Definition: bi_via.h:107
Shape
Definition: bi_via.h:56
The RuntimeError class.
Definition: exceptions.h:219
const PositiveLength & getSize() const noexcept
Definition: bi_via.h:75
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_via.cpp:230
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_via.cpp:218
const Point & getPosition() const noexceptoverride
Definition: bi_via.h:99
Path getOutline(const Length &expansion=Length(0)) const noexcept
Definition: bi_via.cpp:108
bool isOnLayer(const QString &layerName) const noexcept
Definition: bi_via.cpp:104
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
BI_Via & operator=(const BI_Via &rhs)=delete
bool isUsed() const noexcept
Definition: bi_via.h:76
Uuid mUuid
Definition: bi_via.h:126
Definition: bi_netline.h:51
void removeFromBoard() override
Definition: bi_via.cpp:190
Shape getShape() const noexcept
Definition: bi_via.h:71
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
NetSignal & getNetSignalOfNetSegment() const noexcept
Definition: bi_via.cpp:100
The NetSignal class.
Definition: netsignal.h:56
BI_NetSegment & getNetSegment() const noexcept
Definition: bi_via.h:68
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
QMetaObject::Connection mHighlightChangedConnection
Definition: bi_via.h:123
const PositiveLength & getDrillDiameter() const noexcept
Definition: bi_via.h:72
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:60
The BI_Via class.
Definition: bi_via.h:49
void setSize(const PositiveLength &size) noexcept
Definition: bi_via.cpp:161