KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_line.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software: you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef __PNS_LINE_H
24#define __PNS_LINE_H
25
26#include <math/box2.h>
27#include <math/vector2d.h>
28
30#include <geometry/seg.h>
31#include <geometry/shape.h>
33
34#include "pns_item.h"
35#include "pns_via.h"
36#include "pns_link_holder.h"
37
38namespace PNS {
39
40class LINKED_ITEM;
41class NODE;
42class VIA;
43class SEGMENT;
44
45#define PNS_HULL_MARGIN 10
46
61class LINE : public LINK_HOLDER
62{
63public:
67 LINE() :
69 m_blockingObstacle( nullptr )
70 {
71 m_width = 1; // Dummy value
73 m_via = nullptr;
74 }
75
76 LINE( const LINE& aOther );
77
81 LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
82 LINK_HOLDER( aBase ),
83 m_line( aLine ),
84 m_width( aBase.m_width ),
86 m_blockingObstacle( nullptr )
87 {
88 m_net = aBase.m_net;
89 m_layers = aBase.m_layers;
90 m_via = nullptr;
91 }
92
96 LINE( VIA* aVia ) :
98 m_blockingObstacle( nullptr )
99 {
100 m_via = aVia;
101 // TODO(JE) Padstacks - does this matter?
102 m_width = aVia->Diameter( aVia->Layers().Start() );
103 m_net = aVia->Net();
104 m_layers = aVia->Layers();
105 m_rank = aVia->Rank();
107 }
108
109 ~LINE();
110
111 static inline bool ClassOf( const ITEM* aItem )
112 {
113 return aItem && LINE_T == aItem->Kind();
114 }
115
117 virtual LINE* Clone() const override;
118
119 // Copy operator
120 LINE& operator=( const LINE& aOther );
121
122 // Move assignment operator
123 LINE& operator=( LINE&& aOther ) noexcept;
124
125 bool IsLinkedChecked() const
126 {
127 return IsLinked() && LinkCount() == ShapeCount();
128 }
129
131 SEGMENT* FindLinkedSegment( const SEG& aSeg ) const;
132
133
135 void SetShape( const SHAPE_LINE_CHAIN& aLine )
136 {
137 m_line = aLine;
138 m_line.SetWidth( m_width );
139 }
140
142 const SHAPE* Shape( int aLayer ) const override { return &m_line; }
143
146 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
147
148 int SegmentCount() const { return m_line.SegmentCount(); }
149 int PointCount() const { return m_line.PointCount(); }
150 int ArcCount() const { return m_line.ArcCount(); }
151 int ShapeCount() const { return m_line.ShapeCount(); }
152
154 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
155 const VECTOR2I& CLastPoint() const { return m_line.CLastPoint(); }
156 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
157
159 void SetWidth( int aWidth )
160 {
161 m_width = aWidth;
162 m_line.SetWidth( aWidth );
163 }
164
166 int Width() const { return m_width; }
167
169 bool CompareGeometry( const LINE& aOther );
170
172 void Reverse();
173
176 const LINE ClipToNearestObstacle( NODE* aNode ) const;
177
179 void ClipVertexRange ( int aStart, int aEnd );
180
182 int CountCorners( int aAngles ) const;
183
194 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
195
196 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
197
199 void ShowLinks() const;
200
201 bool EndsWithVia() const { return m_via != nullptr; }
202
203 int FindSegment( const SEGMENT* aSeg ) const;
204
205 void AppendVia( const VIA& aVia );
206 void LinkVia( VIA* aVia );
207 void RemoveVia();
208
209 VIA& Via() { return *m_via; }
210 const VIA& Via() const { return *m_via; }
211
212 void SetViaDiameter( int aDiameter )
213 {
214 wxCHECK( m_via, /* void */ );
215 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
216 m_via->SetStackMode( VIA::STACK_MODE::NORMAL ),
217 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
218
219 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
220 }
221 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
222
223 virtual void Mark( int aMarker ) const override;
224 virtual void Unmark( int aMarker = -1 ) const override;
225 virtual int Marker() const override;
226
227 virtual VECTOR2I Anchor( int n ) const override
228 {
229 if( m_line.PointCount() < 1 )
230 return VECTOR2I();
231
232 return ( n == 0 ) ? m_line.CPoint( 0 ) : m_line.CPoint( -1 );
233 }
234
235 virtual int AnchorCount() const override
236 {
237 return ( m_line.PointCount() >= 2 ) ? 2 : m_line.PointCount();
238 }
239
240 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
242
243 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
244 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false,
245 DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
246
247 void DragArc( const VECTOR2I& aP, int aIndex );
248
249 void SetRank( int aRank ) override;
250 int Rank() const override;
251
252 bool HasLoops() const;
253 bool HasLockedSegments() const;
254
255 void Clear();
256
257 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
258
259 void SetSnapThreshhold( int aThreshhold )
260 {
261 m_snapThreshhold = aThreshhold;
262 }
263
265 {
266 return m_snapThreshhold;
267 }
268
269 SEGMENT* FindLinkContainingVertex( const VECTOR2I& aP ) const;
270
271private:
272 void dragSegment45( const VECTOR2I& aP, int aIndex );
273 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
274 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
275 void dragCornerFree( const VECTOR2I& aP, int aIndex );
276
282 void restoreUntouchedArcs( SHAPE_LINE_CHAIN& aPath, const SHAPE_LINE_CHAIN& aOriginal ) const;
283
285 int aIndex ) const;
286
287 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
288 int aIndex ) const;
289
292
293
295
298};
299
300}
301
302#endif // __PNS_LINE_H
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:918
Represent route directions & corner angles in a 45-degree metric.
Definition direction45.h:37
Base class for PNS router board items.
Definition pns_item.h:98
virtual int Rank() const
Definition pns_item.h:270
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
virtual NET_HANDLE Net() const
Definition pns_item.h:210
PNS_LAYER_RANGE m_layers
Definition pns_item.h:327
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:173
NET_HANDLE m_net
Definition pns_item.h:330
int m_rank
Definition pns_item.h:332
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
void ClipVertexRange(int aStart, int aEnd)
Clip the line to a given range of vertices.
void SetViaDrill(int aDrill)
Definition pns_line.h:221
int FindSegment(const SEGMENT *aSeg) const
const VECTOR2I & CPoint(int aIdx) const
Return the aIdx-th point of the line.
Definition pns_line.h:154
ITEM * GetBlockingObstacle() const
Definition pns_line.h:241
bool HasLoops() const
OPT_BOX2I ChangedArea(const LINE *aOther) const
bool HasLockedSegments() const
int ArcCount() const
Definition pns_line.h:150
int Rank() const override
void dragCorner45(const VECTOR2I &aP, int aIndex, DIRECTION_45 aPreferredEndingDirection)
Definition pns_line.cpp:823
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition pns_line.cpp:679
VIA * m_via
Definition pns_line.h:296
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assign a shape to the line (a polyline/line chain).
Definition pns_line.h:135
void DragArc(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:911
virtual void Mark(int aMarker) const override
Definition pns_line.cpp:174
int m_width
Our width.
Definition pns_line.h:291
bool CompareGeometry(const LINE &aOther)
Return true if the line is geometrically identical as line aOther.
virtual VECTOR2I Anchor(int n) const override
Definition pns_line.h:227
const VIA & Via() const
Definition pns_line.h:210
void LinkVia(VIA *aVia)
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition pns_line.h:297
const SHAPE_LINE_CHAIN & CLine() const
Definition pns_line.h:146
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
LINE & operator=(const LINE &aOther)
Definition pns_line.cpp:83
void dragSegment45(const VECTOR2I &aP, int aIndex)
const VECTOR2I & CLastPoint() const
Definition pns_line.h:155
void RemoveVia()
int CountCorners(int aAngles) const
Return the number of corners of angles specified by mask aAngles.
Definition pns_line.cpp:218
LINE(const LINE &aBase, const SHAPE_LINE_CHAIN &aLine)
Copy properties (net, layers, etc.) from a base line and replaces the shape by another.
Definition pns_line.h:81
void SetRank(int aRank) override
LINE()
Makes an empty line.
Definition pns_line.h:67
bool Walkaround(SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPrePath, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
Calculate a line tightly wrapping a convex hull of an obstacle object (aObstacle).
SHAPE_LINE_CHAIN & Line()
Modifiable accessor to the underlying shape.
Definition pns_line.h:145
const SHAPE * Shape(int aLayer) const override
Return the shape of the line.
Definition pns_line.h:142
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false, DIRECTION_45 aPreferredEndingDirection=DIRECTION_45())
Definition pns_line.cpp:884
void ShowLinks() const
Print out all linked segments.
virtual int Marker() const override
Definition pns_line.cpp:193
void AppendVia(const VIA &aVia)
static bool ClassOf(const ITEM *aItem)
Definition pns_line.h:111
VIA & Via()
Definition pns_line.h:209
void SetSnapThreshhold(int aThreshhold)
Definition pns_line.h:259
int SegmentCount() const
Definition pns_line.h:148
virtual int AnchorCount() const override
Definition pns_line.h:235
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Definition pns_line.h:125
void SetViaDiameter(int aDiameter)
Definition pns_line.h:212
SEGMENT * FindLinkedSegment(const SEG &aSeg) const
Finds a linked SEGMENT whose endpoints match aSeg (either direction)
virtual void Unmark(int aMarker=-1) const override
Definition pns_line.cpp:184
int PointCount() const
Definition pns_line.h:149
SEGMENT * FindLinkContainingVertex(const VECTOR2I &aP) const
int m_snapThreshhold
Width to smooth out jagged segments.
Definition pns_line.h:294
int ShapeCount() const
Definition pns_line.h:151
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition pns_line.h:290
void SetWidth(int aWidth)
Set line width.
Definition pns_line.h:159
int GetSnapThreshhold() const
Definition pns_line.h:264
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition pns_line.cpp:898
void SetBlockingObstacle(ITEM *aObstacle)
Definition pns_line.h:240
LINE(VIA *aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition pns_line.h:96
bool EndsWithVia() const
Definition pns_line.h:201
void Reverse()
Reverse the point/vertex order.
const SEG CSegment(int aIdx) const
Definition pns_line.h:156
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:857
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:166
int Width() const
Return line width.
Definition pns_line.h:166
void Clear()
void restoreUntouchedArcs(SHAPE_LINE_CHAIN &aPath, const SHAPE_LINE_CHAIN &aOriginal) const
Used to rebuild arcs in the walkaround since the graph only stores vertices.
Definition pns_line.cpp:255
Keep the router "world" - i.e.
Definition pns_node.h:244
int Diameter(int aLayer) const
Definition pns_via.h:227
static constexpr int ALL_LAYERS
Definition pns_via.h:78
int Start() const
Definition seg.h:38
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
An abstract shape on 2D plane.
Definition shape.h:124
Push and Shove diff pair dimensions (gap) settings dialog.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708