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
192 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
193
194 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
195
197 void ShowLinks() const;
198
199 bool EndsWithVia() const { return m_via != nullptr; }
200
201 int FindSegment( const SEGMENT* aSeg ) const;
202
203 void AppendVia( const VIA& aVia );
204 void LinkVia( VIA* aVia );
205 void RemoveVia();
206
207 VIA& Via() { return *m_via; }
208 const VIA& Via() const { return *m_via; }
209
210 void SetViaDiameter( int aDiameter )
211 {
212 wxCHECK( m_via, /* void */ );
213 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
214 m_via->SetStackMode( VIA::STACK_MODE::NORMAL ),
215 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
216
217 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
218 }
219 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
220
221 virtual void Mark( int aMarker ) const override;
222 virtual void Unmark( int aMarker = -1 ) const override;
223 virtual int Marker() const override;
224
225 virtual VECTOR2I Anchor( int n ) const override
226 {
227 if( m_line.PointCount() < 1 )
228 return VECTOR2I();
229
230 return ( n == 0 ) ? m_line.CPoint( 0 ) : m_line.CPoint( -1 );
231 }
232
233 virtual int AnchorCount() const override
234 {
235 return ( m_line.PointCount() >= 2 ) ? 2 : m_line.PointCount();
236 }
237
238 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
240
241 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
242 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false, DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
243
244 void DragArc( const VECTOR2I& aP, int aIndex );
245
246 void SetRank( int aRank ) override;
247 int Rank() const override;
248
249 bool HasLoops() const;
250 bool HasLockedSegments() const;
251
252 void Clear();
253
254 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
255
256 void SetSnapThreshhold( int aThreshhold )
257 {
258 m_snapThreshhold = aThreshhold;
259 }
260
262 {
263 return m_snapThreshhold;
264 }
265
266 SEGMENT* FindLinkContainingVertex( const VECTOR2I& aP ) const;
267
268private:
269 void dragSegment45( const VECTOR2I& aP, int aIndex );
270 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
271 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
272 void dragCornerFree( const VECTOR2I& aP, int aIndex );
273
279 void restoreUntouchedArcs( SHAPE_LINE_CHAIN& aPath, const SHAPE_LINE_CHAIN& aOriginal ) const;
280
282 int aIndex ) const;
283
284 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
285 int aIndex ) const;
286
289
290
292
295};
296
297}
298
299#endif // __PNS_LINE_H
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:931
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:266
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:323
PnsKind Kind() const
Return the type (kind) of the item.
Definition pns_item.h:173
NET_HANDLE m_net
Definition pns_item.h:326
int m_rank
Definition pns_item.h:328
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)
Return the number of corners of angles specified by mask aAngles.
void SetViaDrill(int aDrill)
Definition pns_line.h:219
int FindSegment(const SEGMENT *aSeg) const
const VECTOR2I & CPoint(int aIdx) const
Definition pns_line.h:154
ITEM * GetBlockingObstacle() const
Definition pns_line.h:239
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 a given range of vertices.
Definition pns_line.cpp:679
VIA * m_via
Definition pns_line.h:293
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
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:288
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
virtual VECTOR2I Anchor(int n) const override
Definition pns_line.h:225
const VIA & Via() const
Definition pns_line.h:208
void LinkVia(VIA *aVia)
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition pns_line.h:294
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
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
SHAPE_LINE_CHAIN & Line()
Definition pns_line.h:145
const SHAPE * Shape(int aLayer) const override
Modifiable accessor to the underlying shape.
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
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:207
void SetSnapThreshhold(int aThreshhold)
Definition pns_line.h:256
int SegmentCount() const
Definition pns_line.h:148
virtual int AnchorCount() const override
Definition pns_line.h:233
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Finds a linked SEGMENT whose endpoints match aSeg (either direction)
Definition pns_line.h:125
void SetViaDiameter(int aDiameter)
Definition pns_line.h:210
SEGMENT * FindLinkedSegment(const SEG &aSeg) const
Assign a shape to the line (a polyline/line chain).
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:291
int ShapeCount() const
Return the aIdx-th point of the line.
Definition pns_line.h:151
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition pns_line.h:287
void SetWidth(int aWidth)
Return line width.
Definition pns_line.h:159
int GetSnapThreshhold() const
Definition pns_line.h:261
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition pns_line.cpp:898
bool Walkaround(SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
Calculate a line tightly wrapping a convex hull of an obstacle object (aObstacle).
void SetBlockingObstacle(ITEM *aObstacle)
Definition pns_line.h:238
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:199
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
const SEG CSegment(int aIdx) const
Set line width.
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 true if the line is geometrically identical as line aOther.
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:243
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:683