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 m_ownsVia = false;
75 }
76
77 LINE( const LINE& aOther );
78
82 LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
83 LINK_HOLDER( aBase ),
84 m_line( aLine ),
85 m_width( aBase.m_width ),
87 m_blockingObstacle( nullptr )
88 {
89 m_net = aBase.m_net;
90 m_layers = aBase.m_layers;
91 m_via = nullptr;
92 m_ownsVia = false;
93 }
94
98 LINE( VIA* aVia ) :
100 m_blockingObstacle( nullptr )
101 {
102 m_via = aVia;
103 m_ownsVia = false;
104 // TODO(JE) Padstacks - does this matter?
105 m_width = aVia->Diameter( aVia->Layers().Start() );
106 m_net = aVia->Net();
107 m_layers = aVia->Layers();
108 m_rank = aVia->Rank();
110 }
111
112 ~LINE();
113
114 static inline bool ClassOf( const ITEM* aItem )
115 {
116 return aItem && LINE_T == aItem->Kind();
117 }
118
120 virtual LINE* Clone() const override;
121
122 // Copy operator
123 LINE& operator=( const LINE& aOther );
124
125 // Move assignment operator
126 LINE& operator=( LINE&& aOther ) noexcept;
127
128 bool IsLinkedChecked() const
129 {
130 return IsLinked() && LinkCount() == ShapeCount();
131 }
132
134 SEGMENT* FindLinkedSegment( const SEG& aSeg ) const;
135
136
138 void SetShape( const SHAPE_LINE_CHAIN& aLine )
139 {
140 m_line = aLine;
141 m_line.SetWidth( m_width );
142 }
143
145 const SHAPE* Shape( int aLayer ) const override { return &m_line; }
146
149 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
150
151 int SegmentCount() const { return m_line.SegmentCount(); }
152 int PointCount() const { return m_line.PointCount(); }
153 int ArcCount() const { return m_line.ArcCount(); }
154 int ShapeCount() const { return m_line.ShapeCount(); }
155
157 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
158 const VECTOR2I& CLastPoint() const { return m_line.CLastPoint(); }
159 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
160
162 void SetWidth( int aWidth )
163 {
164 m_width = aWidth;
165 m_line.SetWidth( aWidth );
166 }
167
169 int Width() const { return m_width; }
170
172 bool CompareGeometry( const LINE& aOther );
173
175 void Reverse();
176
179 const LINE ClipToNearestObstacle( NODE* aNode ) const;
180
182 void ClipVertexRange ( int aStart, int aEnd );
183
185 int CountCorners( int aAngles ) const;
186
197 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
198
199 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
200
202 void ShowLinks() const;
203
204 bool EndsWithVia() const { return m_via != nullptr; }
205
206 int FindSegment( const SEGMENT* aSeg ) const;
207
208 void AppendVia( const VIA& aVia );
209 void LinkVia( VIA* aVia );
210 void RemoveVia();
211
212 VIA& Via() { return *m_via; }
213 const VIA& Via() const { return *m_via; }
214
215 void SetViaDiameter( int aDiameter )
216 {
217 wxCHECK( m_via, /* void */ );
218 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
219 m_via->SetStackMode( VIA::STACK_MODE::NORMAL ),
220 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
221
222 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
223 }
224 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
225
226 virtual void Mark( int aMarker ) const override;
227 virtual void Unmark( int aMarker = -1 ) const override;
228 virtual int Marker() const override;
229
230 virtual VECTOR2I Anchor( int n ) const override
231 {
232 if( m_line.PointCount() < 1 )
233 return VECTOR2I();
234
235 return ( n == 0 ) ? m_line.CPoint( 0 ) : m_line.CPoint( -1 );
236 }
237
238 virtual int AnchorCount() const override
239 {
240 return ( m_line.PointCount() >= 2 ) ? 2 : m_line.PointCount();
241 }
242
243 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
245
246 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
247 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false,
248 DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
249
250 void DragArc( const VECTOR2I& aP, int aIndex );
251
252 void SetRank( int aRank ) override;
253 int Rank() const override;
254
255 bool HasLoops() const;
256 bool HasLockedSegments() const;
257
258 void Clear();
259
260 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
261
262 void SetSnapThreshhold( int aThreshhold )
263 {
264 m_snapThreshhold = aThreshhold;
265 }
266
268 {
269 return m_snapThreshhold;
270 }
271
272 SEGMENT* FindLinkContainingVertex( const VECTOR2I& aP ) const;
273
274private:
275 void dragSegment45( const VECTOR2I& aP, int aIndex );
276 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
277 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
278 void dragCornerFree( const VECTOR2I& aP, int aIndex );
279
285 void restoreUntouchedArcs( SHAPE_LINE_CHAIN& aPath, const SHAPE_LINE_CHAIN& aOriginal ) const;
286
288 int aIndex ) const;
289
290 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
291 int aIndex ) const;
292
295
296
298
300 void copyVia( const LINE& aOther );
301
303 void dropVia();
304
306
310
312};
313
314}
315
316#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:224
int FindSegment(const SEGMENT *aSeg) const
const VECTOR2I & CPoint(int aIdx) const
Return the aIdx-th point of the line.
Definition pns_line.h:157
ITEM * GetBlockingObstacle() const
Definition pns_line.h:244
bool HasLoops() const
OPT_BOX2I ChangedArea(const LINE *aOther) const
bool HasLockedSegments() const
int ArcCount() const
Definition pns_line.h:153
void dropVia()
Free a via this line owns and forget whichever via it had.
Definition pns_line.cpp:89
int Rank() const override
void dragCorner45(const VECTOR2I &aP, int aIndex, DIRECTION_45 aPreferredEndingDirection)
Definition pns_line.cpp:817
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:673
VIA * m_via
Definition pns_line.h:305
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assign a shape to the line (a polyline/line chain).
Definition pns_line.h:138
void DragArc(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:905
virtual void Mark(int aMarker) const override
Definition pns_line.cpp:168
int m_width
Our width.
Definition pns_line.h:294
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:230
const VIA & Via() const
Definition pns_line.h:213
void LinkVia(VIA *aVia)
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition pns_line.h:311
const SHAPE_LINE_CHAIN & CLine() const
Definition pns_line.h:149
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
LINE & operator=(const LINE &aOther)
Definition pns_line.cpp:100
void dragSegment45(const VECTOR2I &aP, int aIndex)
const VECTOR2I & CLastPoint() const
Definition pns_line.h:158
void RemoveVia()
int CountCorners(int aAngles) const
Return the number of corners of angles specified by mask aAngles.
Definition pns_line.cpp:212
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:82
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:148
const SHAPE * Shape(int aLayer) const override
Return the shape of the line.
Definition pns_line.h:145
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false, DIRECTION_45 aPreferredEndingDirection=DIRECTION_45())
Definition pns_line.cpp:878
void ShowLinks() const
Print out all linked segments.
bool m_ownsVia
A via made by AppendVia() or copied from a line that owned its via is ours to free.
Definition pns_line.h:309
virtual int Marker() const override
Definition pns_line.cpp:187
void AppendVia(const VIA &aVia)
static bool ClassOf(const ITEM *aItem)
Definition pns_line.h:114
VIA & Via()
Definition pns_line.h:212
void SetSnapThreshhold(int aThreshhold)
Definition pns_line.h:262
int SegmentCount() const
Definition pns_line.h:151
virtual int AnchorCount() const override
Definition pns_line.h:238
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Definition pns_line.h:128
void SetViaDiameter(int aDiameter)
Definition pns_line.h:215
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:178
int PointCount() const
Definition pns_line.h:152
SEGMENT * FindLinkContainingVertex(const VECTOR2I &aP) const
int m_snapThreshhold
Width to smooth out jagged segments.
Definition pns_line.h:297
int ShapeCount() const
Definition pns_line.h:154
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition pns_line.h:293
void SetWidth(int aWidth)
Set line width.
Definition pns_line.h:162
int GetSnapThreshhold() const
Definition pns_line.h:267
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition pns_line.cpp:892
void SetBlockingObstacle(ITEM *aObstacle)
Definition pns_line.h:243
LINE(VIA *aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition pns_line.h:98
bool EndsWithVia() const
Definition pns_line.h:204
void Reverse()
Reverse the point/vertex order.
const SEG CSegment(int aIdx) const
Definition pns_line.h:159
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:851
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:160
void copyVia(const LINE &aOther)
Take a copy of another line's via if it owns one, or share the via it borrows.
Definition pns_line.cpp:70
int Width() const
Return line width.
Definition pns_line.h:169
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:249
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