LibrePCB Developers Documentation
Loading...
Searching...
No Matches
netsegmentsimplifier.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_CORE_NETSEGMENTSIMPLIFIER_H
21#define LIBREPCB_CORE_NETSEGMENTSIMPLIFIER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../types/point.h"
27
28#include <QtCore>
29
30/*******************************************************************************
31 * Namespace / Forward Declarations
32 ******************************************************************************/
33namespace librepcb {
34
35class Layer;
36
37/*******************************************************************************
38 * Class NetSegmentSimplifier
39 ******************************************************************************/
40
56 Q_DECLARE_TR_FUNCTIONS(NetSegmentSimplifier)
57
58public:
59 // Types
60 enum class AnchorType : int {
61 // Value is important for the sort algorithm, do not change!
62 Via = 0,
63 Fixed = 1,
64 Junction = 2,
65 };
66 struct Line {
67 int id = 0;
68 int p1 = 0;
69 int p2 = 0;
70 const Layer* layer = nullptr;
72 bool modified = false;
73 };
74 struct Result {
75 QList<Line> lines;
76 QMap<int, Point> newJunctions;
78 bool modified = false;
79 };
80
81 // Constructors / Destructor
82
86 NetSegmentSimplifier() noexcept;
87
94
98 ~NetSegmentSimplifier() noexcept;
99
112 int addAnchor(AnchorType type, const Point& pos, const Layer* start,
113 const Layer* end) noexcept;
114
126 int addLine(int p1, int p2, const Layer* layer, const Length& width) noexcept;
127
140 Result simplify() noexcept;
141
142 // Operator overloadings
143 NetSegmentSimplifier& operator=(const NetSegmentSimplifier& rhs) = delete;
144
145private:
146 // Types
147 struct Anchor {
148 int id = 0;
151 const Layer* startLayer = nullptr;
152 const Layer* endLayer = nullptr;
153 bool isNew = false;
154 };
155
156 // Methods
157 QSet<int> getConnectedFixedAnchors() const noexcept;
158 void addJunctionsAtLineIntersections() noexcept;
159 void splitLinesAtAnchors() noexcept;
160 void removeDuplicateJunctions() noexcept;
161 void removeRedundantLines() noexcept;
162 bool mergeNextLines() noexcept;
163 const Anchor* findAnchor(const Point& pos, const Layer* layer) noexcept;
164 static bool isAnchorOnLayer(const Anchor& anchor,
165 const Layer* layer) noexcept;
166 static bool isStraightLine(const Point& p0, const Point& p1,
167 const Point& p2) noexcept;
168
169 // Data input
171 QMap<int, Line> mLines;
173
174 // State
175 QHash<Point, QVector<Anchor>> mAnchorMap;
176 QSet<int> mPinsOrPads;
178};
179
180/*******************************************************************************
181 * End of File
182 ******************************************************************************/
183
184} // namespace librepcb
185
186#endif
The Junction class represents the connection point between netlines or traces.
Definition junction.h:47
The Layer class provides all supported geometry layers.
Definition layer.h:42
The Length class is used to represent a length (for example 12.75 millimeters)
Definition length.h:82
Algorithm to clean/simplify net segment lines.
Definition netsegmentsimplifier.h:55
bool mergeNextLines() noexcept
Definition netsegmentsimplifier.cpp:321
const Anchor * findAnchor(const Point &pos, const Layer *layer) noexcept
Definition netsegmentsimplifier.cpp:395
QSet< int > mPinsOrPads
Definition netsegmentsimplifier.h:176
QSet< int > getConnectedFixedAnchors() const noexcept
Definition netsegmentsimplifier.cpp:142
QHash< Point, QVector< Anchor > > mAnchorMap
Definition netsegmentsimplifier.h:175
bool mModified
Definition netsegmentsimplifier.h:177
void splitLinesAtAnchors() noexcept
Definition netsegmentsimplifier.cpp:211
Result simplify() noexcept
Perform the simplification.
Definition netsegmentsimplifier.cpp:68
void removeRedundantLines() noexcept
Definition netsegmentsimplifier.cpp:302
static bool isAnchorOnLayer(const Anchor &anchor, const Layer *layer) noexcept
Definition netsegmentsimplifier.cpp:405
NetSegmentSimplifier() noexcept
Default constructor.
Definition netsegmentsimplifier.cpp:39
QMap< int, Line > mLines
Definition netsegmentsimplifier.h:171
int mNextFreeLineId
Definition netsegmentsimplifier.h:172
int addAnchor(AnchorType type, const Point &pos, const Layer *start, const Layer *end) noexcept
Add a line anchor.
Definition netsegmentsimplifier.cpp:50
void removeDuplicateJunctions() noexcept
Definition netsegmentsimplifier.cpp:275
static bool isStraightLine(const Point &p0, const Point &p1, const Point &p2) noexcept
Definition netsegmentsimplifier.cpp:412
int addLine(int p1, int p2, const Layer *layer, const Length &width) noexcept
Add a line between two anchors.
Definition netsegmentsimplifier.cpp:58
QList< Anchor > mAnchors
Definition netsegmentsimplifier.h:170
void addJunctionsAtLineIntersections() noexcept
Definition netsegmentsimplifier.cpp:151
AnchorType
Definition netsegmentsimplifier.h:60
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Via class represents a via of a board.
Definition via.h:55
Definition occmodel.cpp:77
Definition netsegmentsimplifier.h:147
Point pos
Definition netsegmentsimplifier.h:150
Definition netsegmentsimplifier.h:66
int p2
Definition netsegmentsimplifier.h:69
bool modified
Definition netsegmentsimplifier.h:72
int p1
Definition netsegmentsimplifier.h:68
Length width
Definition netsegmentsimplifier.h:71
const Layer * layer
Definition netsegmentsimplifier.h:70
Definition netsegmentsimplifier.h:74
QList< Line > lines
Definition netsegmentsimplifier.h:75
QMap< int, Point > newJunctions
Definition netsegmentsimplifier.h:76
bool modified
Definition netsegmentsimplifier.h:78
QSet< int > disconnectedFixedAnchors
Definition netsegmentsimplifier.h:77