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  const QHash<Uuid, QString>& netpointLayerMap,
85  const QHash<Uuid, BI_NetLineAnchor*>& netPointAnchorMap);
86  BI_NetLine(BI_NetSegment& segment, BI_NetLineAnchor& startPoint,
87  BI_NetLineAnchor& endPoint, GraphicsLayer& layer,
88  const PositiveLength& width);
89  ~BI_NetLine() noexcept;
90 
91  // Getters
92  BI_NetSegment& getNetSegment() const noexcept { return mNetSegment; }
93  const Uuid& getUuid() const noexcept { return mUuid; }
94  GraphicsLayer& getLayer() const noexcept { return *mLayer; }
95  const PositiveLength& getWidth() const noexcept { return mWidth; }
96  BI_NetLineAnchor& getStartPoint() const noexcept { return *mStartPoint; }
97  BI_NetLineAnchor& getEndPoint() const noexcept { return *mEndPoint; }
98  BI_NetLineAnchor* getOtherPoint(const BI_NetLineAnchor& firstPoint) const
99  noexcept;
100  NetSignal& getNetSignalOfNetSegment() const noexcept;
101  bool isSelectable() const noexcept override;
102  Path getSceneOutline(const Length& expansion = Length(0)) const noexcept;
103 
104  // Setters
105  void setLayer(GraphicsLayer& layer);
106  void setWidth(const PositiveLength& width) noexcept;
107 
108  // General Methods
109  void addToBoard() override;
110  void removeFromBoard() override;
111  void updateLine() noexcept;
112 
114  void serialize(SExpression& root) const override;
115 
116  // Inherited from SI_Base
117  Type_t getType() const noexcept override { return BI_Base::Type_t::NetLine; }
118  const Point& getPosition() const noexcept override { return mPosition; }
119  bool getIsMirrored() const noexcept override { return false; }
120  QPainterPath getGrabAreaScenePx() const noexcept override;
121  void setSelected(bool selected) noexcept override;
122 
123  // Operator Overloadings
124  BI_NetLine& operator=(const BI_NetLine& rhs) = delete;
125 
126 private:
127  void init();
129  const SExpression& root, const QString& oldKey, const QString& newKey,
130  const QHash<Uuid, BI_NetLineAnchor*>& netPointAnchorMap,
131  Uuid& oldPointUuid) const;
132  void serializeAnchor(SExpression& root, BI_NetLineAnchor* anchor) const;
133 
134  // General
136  QScopedPointer<BGI_NetLine> mGraphicsItem;
138  QMetaObject::Connection mHighlightChangedConnection;
139 
140  // Attributes
141  Uuid mUuid;
146 };
147 
148 /*******************************************************************************
149  * End of File
150  ******************************************************************************/
151 
152 } // namespace project
153 } // namespace librepcb
154 
155 #endif // LIBREPCB_PROJECT_BI_NETLINE_H
QMetaObject::Connection mHighlightChangedConnection
Definition: bi_netline.h:138
The GraphicsLayer class represents a graphical layer used in schematics and boards.
Definition: graphicslayer.h:54
void serializeAnchor(SExpression &root, BI_NetLineAnchor *anchor) const
Definition: bi_netline.cpp:304
void init()
Definition: bi_netline.cpp:155
~BI_NetLine() noexcept
Definition: bi_netline.cpp:175
bool isSelectable() const noexceptoverride
Definition: bi_netline.cpp:330
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_netline.cpp:269
void setLayer(GraphicsLayer &layer)
Definition: bi_netline.cpp:212
UnsignedLength getMedianLineWidth() const noexcept
Definition: bi_netline.cpp:66
BI_NetLineAnchor * deserializeAnchor(const SExpression &root, const QString &oldKey, const QString &newKey, const QHash< Uuid, BI_NetLineAnchor * > &netPointAnchorMap, Uuid &oldPointUuid) const
Definition: bi_netline.cpp:277
BI_NetLineAnchor * mStartPoint
Definition: bi_netline.h:142
virtual const Point & getPosition() const noexcept=0
void addToBoard() override
Definition: bi_netline.cpp:234
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:183
virtual void registerNetLine(BI_NetLine &netline)=0
BI_NetLineAnchor & getStartPoint() const noexcept
Definition: bi_netline.h:96
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_netline.cpp:326
void removeFromBoard() override
Definition: bi_netline.cpp:250
virtual ~BI_NetLineAnchor() noexcept=default
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
GraphicsLayer * mLayer
Definition: bi_netline.h:144
void setSelected(bool selected) noexceptoverride
Definition: bi_netline.cpp:334
BI_NetSegment * getNetSegmentOfLines() const noexcept
Definition: bi_netline.cpp:73
The BI_NetSegment class.
Definition: bi_netsegment.h:59
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
PositiveLength mWidth
Definition: bi_netline.h:145
virtual void unregisterNetLine(BI_NetLine &netline)=0
The BGI_NetLine class.
Definition: bgi_netline.h:49
BI_NetLineAnchor & getEndPoint() const noexcept
Definition: bi_netline.h:97
void updateLine() noexcept
Definition: bi_netline.cpp:264
Point mPosition
the center of startpoint and endpoint
Definition: bi_netline.h:137
Uuid mUuid
Definition: bi_netline.h:141
QScopedPointer< BGI_NetLine > mGraphicsItem
Definition: bi_netline.h:136
GraphicsLayer & getLayer() const noexcept
Definition: bi_netline.h:94
BI_NetSegment & mNetSegment
Definition: bi_netline.h:135
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
const Point & getPosition() const noexceptoverride
Definition: bi_netline.h:118
BI_NetLineAnchor * mEndPoint
Definition: bi_netline.h:143
Type_t getType() const noexceptoverride
Definition: bi_netline.h:117
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:194
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
const PositiveLength & getWidth() const noexcept
Definition: bi_netline.h:95
The NetSignal class.
Definition: netsignal.h:56
void setWidth(const PositiveLength &width) noexcept
Definition: bi_netline.cpp:223
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
bool getIsMirrored() const noexceptoverride
Definition: bi_netline.h:119
BI_NetSegment & getNetSegment() const noexcept
Definition: bi_netline.h:92
const Uuid & getUuid() const noexcept
Definition: bi_netline.h:93
Path getSceneOutline(const Length &expansion=Length(0)) const noexcept
Definition: bi_netline.cpp:198
UnsignedLength getMaxLineWidth() const noexcept
Definition: bi_netline.cpp:56
The BI_NetLine class.
Definition: bi_netline.h:74
The SExpression class.
Definition: sexpression.h:60
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662