LibrePCB Developers Documentation
Loading...
Searching...
No Matches
NetSegmentSimplifier Class Referencefinal

Algorithm to clean/simplify net segment lines. More...

#include <netsegmentsimplifier.h>

+ Collaboration diagram for NetSegmentSimplifier:

Classes

struct  Anchor
 
struct  Line
 
struct  Result
 

Public Types

enum class  AnchorType : int
 

Public Member Functions

 NetSegmentSimplifier () noexcept
 Default constructor.
 
 NetSegmentSimplifier (const NetSegmentSimplifier &other)=delete
 Copy constructor.
 
 ~NetSegmentSimplifier () noexcept
 
int addAnchor (AnchorType type, const Point &pos, const Layer *start, const Layer *end) noexcept
 Add a line anchor.
 
int addLine (int p1, int p2, const Layer *layer, const Length &width) noexcept
 Add a line between two anchors.
 
Result simplify () noexcept
 Perform the simplification.
 
NetSegmentSimplifieroperator= (const NetSegmentSimplifier &rhs)=delete
 

Private Member Functions

QSet< int > getConnectedFixedAnchors () const noexcept
 
void addJunctionsAtLineIntersections () noexcept
 
void splitLinesAtAnchors () noexcept
 
void removeDuplicateJunctions () noexcept
 
void removeRedundantLines () noexcept
 
bool mergeNextLines () noexcept
 
const AnchorfindAnchor (const Point &pos, const Layer *layer) noexcept
 

Static Private Member Functions

static bool isAnchorOnLayer (const Anchor &anchor, const Layer *layer) noexcept
 
static bool isStraightLine (const Point &p0, const Point &p1, const Point &p2) noexcept
 

Private Attributes

QList< AnchormAnchors
 
QMap< int, LinemLines
 
int mNextFreeLineId
 
QHash< Point, QVector< Anchor > > mAnchorMap
 
QSet< int > mPinsOrPads
 
bool mModified
 

Detailed Description

Algorithm to clean/simplify net segment lines.

Performed operations:

  • Remove redundant junctions (same position, same layer)
  • Remove redundant lines (same anchors, same layer), keeping the thickest
  • Remove zero-length lines
  • Remove useless junctions within straight line segments (join line segments into the same direction to a single line)
  • Split lines to connect with junctions on the path between start and end points
  • Split intersecting lines, placing a new junction to connect them (only orthogonal intersections for now)

Member Enumeration Documentation

◆ AnchorType

enum class AnchorType : int
strong
Enumerator
Via 
Fixed 
Junction 

Constructor & Destructor Documentation

◆ NetSegmentSimplifier() [1/2]

NetSegmentSimplifier ( )
noexcept

Default constructor.

◆ NetSegmentSimplifier() [2/2]

NetSegmentSimplifier ( const NetSegmentSimplifier other)
delete

Copy constructor.

Parameters
otherAnother librepcb::NetSegmentSimplifier object

◆ ~NetSegmentSimplifier()

~NetSegmentSimplifier ( )
noexcept

Destructor

Member Function Documentation

◆ addAnchor()

int addAnchor ( AnchorType  type,
const Point pos,
const Layer start,
const Layer end 
)
noexcept

Add a line anchor.

Parameters
typeType of the anchor.
posPosition.
startStart (most upper) layer of the anchors or nullptr for schematic netsegment simplifications
endEnd (most lower) layer of the anchors or nullptr for schematic netsegment simplifications
Returns
The ID of the added anchors.
+ Here is the caller graph for this function:

◆ addLine()

int addLine ( int  p1,
int  p2,
const Layer layer,
const Length width 
)
noexcept

Add a line between two anchors.

Parameters
p1ID of first anchors.
p2ID of second anchors.
layerLayer of the line (nullptr for schematic netsegment simplification).
widthLine width.
Returns
The ID of the added line.
+ Here is the caller graph for this function:

◆ simplify()

NetSegmentSimplifier::Result simplify ( )
noexcept

Perform the simplification.

Note
This method also resets the state, so the object can be reused for the next net segment.
Attention
When lines are split, new anchor- and line IDs will be generated on the fly! So the returned lines may contain IDs which you didn't know yet from addAnchor() and addLine()!.
Returns
Any remaining lines after the simplification.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

NetSegmentSimplifier & operator= ( const NetSegmentSimplifier rhs)
delete

◆ getConnectedFixedAnchors()

QSet< int > getConnectedFixedAnchors ( ) const
privatenoexcept
+ Here is the caller graph for this function:

◆ addJunctionsAtLineIntersections()

void addJunctionsAtLineIntersections ( )
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ splitLinesAtAnchors()

void splitLinesAtAnchors ( )
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeDuplicateJunctions()

void removeDuplicateJunctions ( )
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeRedundantLines()

void removeRedundantLines ( )
privatenoexcept
+ Here is the caller graph for this function:

◆ mergeNextLines()

bool mergeNextLines ( )
privatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findAnchor()

const NetSegmentSimplifier::Anchor * findAnchor ( const Point pos,
const Layer layer 
)
privatenoexcept
+ Here is the caller graph for this function:

◆ isAnchorOnLayer()

bool isAnchorOnLayer ( const Anchor anchor,
const Layer layer 
)
staticprivatenoexcept
+ Here is the caller graph for this function:

◆ isStraightLine()

bool isStraightLine ( const Point p0,
const Point p1,
const Point p2 
)
staticprivatenoexcept
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ mAnchors

QList<Anchor> mAnchors
private

◆ mLines

QMap<int, Line> mLines
private

◆ mNextFreeLineId

int mNextFreeLineId
private

◆ mAnchorMap

QHash<Point, QVector<Anchor> > mAnchorMap
private

◆ mPinsOrPads

QSet<int> mPinsOrPads
private

◆ mModified

bool mModified
private

The documentation for this class was generated from the following files: