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 along
20 * with this program. If not, see <http://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 void SetShape( const SHAPE_LINE_CHAIN& aLine )
132 {
133 m_line = aLine;
134 m_line.SetWidth( m_width );
135 }
136
138 const SHAPE* Shape( int aLayer ) const override { return &m_line; }
139
142 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
143
144 int SegmentCount() const { return m_line.SegmentCount(); }
145 int PointCount() const { return m_line.PointCount(); }
146 int ArcCount() const { return m_line.ArcCount(); }
147 int ShapeCount() const { return m_line.ShapeCount(); }
148
150 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
151 const VECTOR2I& CLastPoint() const { return m_line.CLastPoint(); }
152 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
153
155 void SetWidth( int aWidth )
156 {
157 m_width = aWidth;
158 m_line.SetWidth( aWidth );
159 }
160
162 int Width() const { return m_width; }
163
165 bool CompareGeometry( const LINE& aOther );
166
168 void Reverse();
169
172 const LINE ClipToNearestObstacle( NODE* aNode ) const;
173
175 void ClipVertexRange ( int aStart, int aEnd );
176
178 int CountCorners( int aAngles ) const;
179
188 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
189
190 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
191
193 void ShowLinks() const;
194
195 bool EndsWithVia() const { return m_via != nullptr; }
196
197 int FindSegment( const SEGMENT* aSeg ) const;
198
199 void AppendVia( const VIA& aVia );
200 void LinkVia( VIA* aVia );
201 void RemoveVia();
202
203 VIA& Via() { return *m_via; }
204 const VIA& Via() const { return *m_via; }
205
206 void SetViaDiameter( int aDiameter )
207 {
208 wxCHECK( m_via, /* void */ );
209 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
210 m_via->SetStackMode( VIA::STACK_MODE::NORMAL ),
211 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
212
213 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
214 }
215 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
216
217 virtual void Mark( int aMarker ) const override;
218 virtual void Unmark( int aMarker = -1 ) const override;
219 virtual int Marker() const override;
220
221 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
223
224 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
225 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false, DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
226
227 void SetRank( int aRank ) override;
228 int Rank() const override;
229
230 bool HasLoops() const;
231 bool HasLockedSegments() const;
232
233 void Clear();
234
235 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
236
237 void SetSnapThreshhold( int aThreshhold )
238 {
239 m_snapThreshhold = aThreshhold;
240 }
241
243 {
244 return m_snapThreshhold;
245 }
246
247private:
248 void dragSegment45( const VECTOR2I& aP, int aIndex );
249 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
250 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
251 void dragCornerFree( const VECTOR2I& aP, int aIndex );
252
254 int aIndex ) const;
255
256 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
257 int aIndex ) const;
258
261
262
264
267};
268
269}
270
271#endif // __PNS_LINE_H
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:926
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
Definition pns_line.cpp:899
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:215
int FindSegment(const SEGMENT *aSeg) const
const VECTOR2I & CPoint(int aIdx) const
Definition pns_line.h:150
ITEM * GetBlockingObstacle() const
Definition pns_line.h:222
bool HasLoops() const
OPT_BOX2I ChangedArea(const LINE *aOther) const
bool HasLockedSegments() const
int ArcCount() const
Definition pns_line.h:146
int Rank() const override
void dragCorner45(const VECTOR2I &aP, int aIndex, DIRECTION_45 aPreferredEndingDirection)
Definition pns_line.cpp:770
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition pns_line.cpp:626
VIA * m_via
Definition pns_line.h:265
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition pns_line.h:131
virtual void Mark(int aMarker) const override
Definition pns_line.cpp:170
int m_width
Our width.
Definition pns_line.h:260
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
const VIA & Via() const
Definition pns_line.h:204
void LinkVia(VIA *aVia)
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition pns_line.h:266
const SHAPE_LINE_CHAIN & CLine() const
Definition pns_line.h:142
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition pns_line.cpp:857
LINE & operator=(const LINE &aOther)
Definition pns_line.cpp:79
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:944
const VECTOR2I & CLastPoint() const
Definition pns_line.h:151
void RemoveVia()
int CountCorners(int aAngles) const
Definition pns_line.cpp:214
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:141
const SHAPE * Shape(int aLayer) const override
Modifiable accessor to the underlying shape.
Definition pns_line.h:138
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false, DIRECTION_45 aPreferredEndingDirection=DIRECTION_45())
Definition pns_line.cpp:831
void ShowLinks() const
virtual int Marker() const override
Definition pns_line.cpp:189
void AppendVia(const VIA &aVia)
static bool ClassOf(const ITEM *aItem)
Definition pns_line.h:111
VIA & Via()
Definition pns_line.h:203
void SetSnapThreshhold(int aThreshhold)
Definition pns_line.h:237
int SegmentCount() const
Definition pns_line.h:144
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition pns_line.h:125
void SetViaDiameter(int aDiameter)
Definition pns_line.h:206
virtual void Unmark(int aMarker=-1) const override
Definition pns_line.cpp:180
int PointCount() const
Definition pns_line.h:145
int m_snapThreshhold
Width to smooth out jagged segments.
Definition pns_line.h:263
int ShapeCount() const
Return the aIdx-th point of the line.
Definition pns_line.h:147
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition pns_line.h:259
void SetWidth(int aWidth)
Return line width.
Definition pns_line.h:155
int GetSnapThreshhold() const
Definition pns_line.h:242
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition pns_line.cpp:845
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:221
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:195
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:152
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:804
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:162
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition pns_line.h:162
void Clear()
Keep the router "world" - i.e.
Definition pns_node.h:232
int Diameter(int aLayer) const
Definition pns_via.h:208
static constexpr int ALL_LAYERS
Definition pns_via.h:76
int Start() const
Definition seg.h:42
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:126
Push and Shove diff pair dimensions (gap) settings dialog.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695