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 LINE& operator=( const LINE& aOther );
120
121 bool IsLinkedChecked() const
122 {
123 return IsLinked() && LinkCount() == ShapeCount();
124 }
125
127 void SetShape( const SHAPE_LINE_CHAIN& aLine )
128 {
129 m_line = aLine;
130 m_line.SetWidth( m_width );
131 }
132
134 const SHAPE* Shape( int aLayer ) const override { return &m_line; }
135
138 const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
139
140 int SegmentCount() const { return m_line.SegmentCount(); }
141 int PointCount() const { return m_line.PointCount(); }
142 int ArcCount() const { return m_line.ArcCount(); }
143 int ShapeCount() const { return m_line.ShapeCount(); }
144
146 const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
147 const VECTOR2I& CLastPoint() const { return m_line.CLastPoint(); }
148 const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
149
151 void SetWidth( int aWidth )
152 {
153 m_width = aWidth;
154 m_line.SetWidth( aWidth );
155 }
156
158 int Width() const { return m_width; }
159
161 bool CompareGeometry( const LINE& aOther );
162
164 void Reverse();
165
168 const LINE ClipToNearestObstacle( NODE* aNode ) const;
169
171 void ClipVertexRange ( int aStart, int aEnd );
172
174 int CountCorners( int aAngles ) const;
175
184 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
185
186 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
187
189 void ShowLinks() const;
190
191 bool EndsWithVia() const { return m_via != nullptr; }
192
193 int FindSegment( const SEGMENT* aSeg ) const;
194
195 void AppendVia( const VIA& aVia );
196 void LinkVia( VIA* aVia );
197 void RemoveVia();
198
199 VIA& Via() { return *m_via; }
200 const VIA& Via() const { return *m_via; }
201
202 void SetViaDiameter( int aDiameter )
203 {
204 wxCHECK( m_via, /* void */ );
205 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
206 m_via->SetStackMode( VIA::STACK_MODE::NORMAL ),
207 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
208
209 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
210 }
211 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
212
213 virtual void Mark( int aMarker ) const override;
214 virtual void Unmark( int aMarker = -1 ) const override;
215 virtual int Marker() const override;
216
217 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
219
220 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
221 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false, DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
222
223 void SetRank( int aRank ) override;
224 int Rank() const override;
225
226 bool HasLoops() const;
227 bool HasLockedSegments() const;
228
229 void Clear();
230
231 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
232
233 void SetSnapThreshhold( int aThreshhold )
234 {
235 m_snapThreshhold = aThreshhold;
236 }
237
239 {
240 return m_snapThreshhold;
241 }
242
243private:
244 void dragSegment45( const VECTOR2I& aP, int aIndex );
245 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
246 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
247 void dragCornerFree( const VECTOR2I& aP, int aIndex );
248
250 int aIndex ) const;
251
252 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
253 int aIndex ) const;
254
257
258
260
263};
264
265}
266
267#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:856
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:211
int FindSegment(const SEGMENT *aSeg) const
const VECTOR2I & CPoint(int aIdx) const
Definition pns_line.h:146
ITEM * GetBlockingObstacle() const
Definition pns_line.h:218
bool HasLoops() const
OPT_BOX2I ChangedArea(const LINE *aOther) const
bool HasLockedSegments() const
int ArcCount() const
Definition pns_line.h:142
int Rank() const override
void dragCorner45(const VECTOR2I &aP, int aIndex, DIRECTION_45 aPreferredEndingDirection)
Definition pns_line.cpp:727
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition pns_line.cpp:583
VIA * m_via
Definition pns_line.h:261
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition pns_line.h:127
virtual void Mark(int aMarker) const override
Definition pns_line.cpp:127
int m_width
Our width.
Definition pns_line.h:256
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
const VIA & Via() const
Definition pns_line.h:200
void LinkVia(VIA *aVia)
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition pns_line.h:262
const SHAPE_LINE_CHAIN & CLine() const
Definition pns_line.h:138
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition pns_line.cpp:814
LINE & operator=(const LINE &aOther)
Definition pns_line.cpp:79
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:901
const VECTOR2I & CLastPoint() const
Definition pns_line.h:147
void RemoveVia()
int CountCorners(int aAngles) const
Definition pns_line.cpp:171
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:137
const SHAPE * Shape(int aLayer) const override
Modifiable accessor to the underlying shape.
Definition pns_line.h:134
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false, DIRECTION_45 aPreferredEndingDirection=DIRECTION_45())
Definition pns_line.cpp:788
void ShowLinks() const
virtual int Marker() const override
Definition pns_line.cpp:146
void AppendVia(const VIA &aVia)
static bool ClassOf(const ITEM *aItem)
Definition pns_line.h:111
VIA & Via()
Definition pns_line.h:199
void SetSnapThreshhold(int aThreshhold)
Definition pns_line.h:233
int SegmentCount() const
Definition pns_line.h:140
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition pns_line.h:121
void SetViaDiameter(int aDiameter)
Definition pns_line.h:202
virtual void Unmark(int aMarker=-1) const override
Definition pns_line.cpp:137
int PointCount() const
Definition pns_line.h:141
int m_snapThreshhold
Width to smooth out jagged segments.
Definition pns_line.h:259
int ShapeCount() const
Return the aIdx-th point of the line.
Definition pns_line.h:143
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition pns_line.h:255
void SetWidth(int aWidth)
Return line width.
Definition pns_line.h:151
int GetSnapThreshhold() const
Definition pns_line.h:238
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition pns_line.cpp:802
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:217
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:191
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:148
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition pns_line.cpp:761
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition pns_line.cpp:119
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition pns_line.h:158
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