LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bi_netline.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_NETLINE_H
21 #define LIBREPCB_PROJECT_BI_NETLINE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphicsitems/bgi_netline.h"
27 #include "bi_base.h"
28 
31 #include <librepcb/common/uuid.h>
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class GraphicsLayer;
41 
42 namespace project {
43 
44 class NetSignal;
45 class BI_NetSegment;
46 
47 /*******************************************************************************
48  * Class BI_NetLineAnchor
49  ******************************************************************************/
50 
52 public:
53  BI_NetLineAnchor() noexcept = default;
54  virtual ~BI_NetLineAnchor() noexcept = default;
55 
56  virtual void registerNetLine(BI_NetLine& netline) = 0;
57  virtual void unregisterNetLine(BI_NetLine& netline) = 0;
58  virtual const QSet<BI_NetLine*>& getNetLines() const noexcept = 0;
59  virtual const Point& getPosition() const noexcept = 0;
60 
61  std::vector<PositiveLength> getLineWidths() const noexcept;
62  UnsignedLength getMaxLineWidth() const noexcept;
63  UnsignedLength getMedianLineWidth() const noexcept;
64  BI_NetSegment* getNetSegmentOfLines() const noexcept;
65 };
66 
67 /*******************************************************************************
68  * Class BI_NetLine
69  ******************************************************************************/
70 
74 class BI_NetLine final : public BI_Base, public SerializableObject {
75  Q_OBJECT
76 
77 public:
78  // Constructors / Destructor
79  BI_NetLine() = delete;
80  BI_NetLine(const BI_NetLine& other) = delete;
81  BI_NetLine(BI_NetSegment& segment, const BI_NetLine& other,
82  BI_NetLineAnchor& startPoint, BI_NetLineAnchor& endPoint);
83  BI_NetLine(BI_NetSegment& segment, const SExpression& node);
84  BI_NetLine(BI_NetSegment& segment, BI_NetLineAnchor& startPoint,
85  BI_NetLineAnchor& endPoint, GraphicsLayer& layer,
86  const PositiveLength& width);
87  ~BI_NetLine() noexcept;
88 
89  // Getters
90  BI_NetSegment& getNetSegment() const noexcept { return mNetSegment; }
91  const Uuid& getUuid() const noexcept { return mUuid; }
92  GraphicsLayer& getLayer() const noexcept { return *mLayer; }
93  const PositiveLength& getWidth() const noexcept { return mWidth; }
94  BI_NetLineAnchor& getStartPoint() const noexcept { return *mStartPoint; }
95  BI_NetLineAnchor& getEndPoint() const noexcept { return *mEndPoint; }
96  BI_NetLineAnchor* getOtherPoint(const BI_NetLineAnchor& firstPoint) const
97  noexcept;
98  NetSignal& getNetSignalOfNetSegment() const noexcept;
99  bool isSelectable() const noexcept override;
100  Path getSceneOutline(const Length& expansion = Length(0)) const noexcept;
101  UnsignedLength getLength() const noexcept;
102 
103  // Setters
104  void setLayer(GraphicsLayer& layer);
105  void setWidth(const PositiveLength& width) noexcept;
106 
107  // General Methods
108  void addToBoard() override;
109  void removeFromBoard() override;
110  void updateLine() noexcept;
111 
113  void serialize(SExpression& root) const override;
114 
115  // Inherited from SI_Base
116  Type_t getType() const noexcept override { return BI_Base::Type_t::NetLine; }
117  const Point& getPosition() const noexcept override { return mPosition; }
118  bool getIsMirrored() const noexcept override { return false; }
119  QPainterPath getGrabAreaScenePx() const noexcept override;
120  void setSelected(bool selected) noexcept override;
121 
122  // Operator Overloadings
123  BI_NetLine& operator=(const BI_NetLine& rhs) = delete;
124 
125 private:
126  void init();
128  const QString& key) const;
129  void serializeAnchor(SExpression& root, BI_NetLineAnchor* anchor) const;
130 
131  // General
133  QScopedPointer<BGI_NetLine> mGraphicsItem;
135  QMetaObject::Connection mHighlightChangedConnection;
136 
137  // Attributes
143 };
144 
145 /*******************************************************************************
146  * End of File
147  ******************************************************************************/
148 
149 } // namespace project
150 } // namespace librepcb
151 
152 #endif // LIBREPCB_PROJECT_BI_NETLINE_H
QMetaObject::Connection mHighlightChangedConnection
Definition: bi_netline.h:135
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:50
void serializeAnchor(SExpression &root, BI_NetLineAnchor *anchor) const
Definition: bi_netline.cpp:288
void init()
Definition: bi_netline.cpp:146
~BI_NetLine() noexcept
Definition: bi_netline.cpp:166
bool isSelectable() const noexceptoverride
Definition: bi_netline.cpp:314
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_netline.cpp:264
void setLayer(GraphicsLayer &layer)
Definition: bi_netline.cpp:207
UnsignedLength getMedianLineWidth() const noexcept
Definition: bi_netline.cpp:66
BI_NetLineAnchor * mStartPoint
Definition: bi_netline.h:139
virtual const Point & getPosition() const noexcept=0
void addToBoard() override
Definition: bi_netline.cpp:229
Type_t
Definition: bi_base.h:57
librepcb::project::BI_NetLine
std::vector< PositiveLength > getLineWidths() const noexcept
Definition: bi_netline.cpp:48
BI_NetLineAnchor * getOtherPoint(const BI_NetLineAnchor &firstPoint) const noexcept
Definition: bi_netline.cpp:174
virtual void registerNetLine(BI_NetLine &netline)=0
BI_NetLineAnchor & getStartPoint() const noexcept
Definition: bi_netline.h:94
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_netline.cpp:310
void removeFromBoard() override
Definition: bi_netline.cpp:245
virtual ~BI_NetLineAnchor() noexcept=default
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
GraphicsLayer * mLayer
Definition: bi_netline.h:141
void setSelected(bool selected) noexceptoverride
Definition: bi_netline.cpp:318
BI_NetSegment * getNetSegmentOfLines() const noexcept
Definition: bi_netline.cpp:73
The BI_NetSegment class.
Definition: bi_netsegment.h:57
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
PositiveLength mWidth
Definition: bi_netline.h:142
virtual void unregisterNetLine(BI_NetLine &netline)=0
UnsignedLength getLength() const noexcept
Definition: bi_netline.cpp:199
The BGI_NetLine class.
Definition: bgi_netline.h:49
BI_NetLineAnchor & getEndPoint() const noexcept
Definition: bi_netline.h:95
void updateLine() noexcept
Definition: bi_netline.cpp:259
Point mPosition
the center of startpoint and endpoint
Definition: bi_netline.h:134
Uuid mUuid
Definition: bi_netline.h:138
QScopedPointer< BGI_NetLine > mGraphicsItem
Definition: bi_netline.h:133
GraphicsLayer & getLayer() const noexcept
Definition: bi_netline.h:92
BI_NetLineAnchor * deserializeAnchor(const SExpression &root, const QString &key) const
Definition: bi_netline.cpp:272
BI_NetSegment & mNetSegment
Definition: bi_netline.h:132
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
const Point & getPosition() const noexceptoverride
Definition: bi_netline.h:117
BI_NetLineAnchor * mEndPoint
Definition: bi_netline.h:140
Type_t getType() const noexceptoverride
Definition: bi_netline.h:116
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
virtual const QSet< BI_NetLine * > & getNetLines() const noexcept=0
Definition: bi_netline.h:51
NetSignal & getNetSignalOfNetSegment() const noexcept
Definition: bi_netline.cpp:185
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:780
const PositiveLength & getWidth() const noexcept
Definition: bi_netline.h:93
The NetSignal class.
Definition: netsignal.h:56
void setWidth(const PositiveLength &width) noexcept
Definition: bi_netline.cpp:218
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 getIsMirrored() const noexceptoverride
Definition: bi_netline.h:118
BI_NetSegment & getNetSegment() const noexcept
Definition: bi_netline.h:90
const Uuid & getUuid() const noexcept
Definition: bi_netline.h:91
Path getSceneOutline(const Length &expansion=Length(0)) const noexcept
Definition: bi_netline.cpp:189
UnsignedLength getMaxLineWidth() const noexcept
Definition: bi_netline.cpp:56
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:57
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659