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;
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,
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.
Definition: pns_line.cpp:1140
void SetViaDrill(int aDrill)
Definition: pns_line.h:211
int FindSegment(const SEGMENT *aSeg) const
Definition: pns_line.cpp:1341
const VECTOR2I & CPoint(int aIdx) const
Definition: pns_line.h:146
ITEM * GetBlockingObstacle() const
Definition: pns_line.h:218
bool HasLoops() const
Definition: pns_line.cpp:1189
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:1218
bool HasLockedSegments() const
Definition: pns_line.cpp:1299
int ArcCount() const
Definition: pns_line.h:142
int Rank() const override
Definition: pns_line.cpp:1120
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.
Definition: pns_line.cpp:1071
const VIA & Via() const
Definition: pns_line.h:200
void LinkVia(VIA *aVia)
Definition: pns_line.cpp:1098
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()
Definition: pns_line.cpp:1318
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
Definition: pns_line.cpp:1110
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)
Definition: pns_line.cpp:1085
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).
Definition: pns_line.cpp:1077
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()
Definition: pns_line.cpp:1310
Keep the router "world" - i.e.
Definition: pns_node.h:232
int Diameter(int aLayer) const
Definition: pns_via.h:208
void SetDiameter(int aLayer, int aDiameter)
Definition: pns_via.h:215
void SetDrill(int aDrill)
Definition: pns_via.h:230
static constexpr int ALL_LAYERS
Definition: pns_via.h:76
void SetStackMode(STACK_MODE aStackMode)
Definition: pns_via.cpp:87
STACK_MODE StackMode() const
Definition: pns_via.h:174
int Start() const
Definition: pns_layerset.h:86
Definition: seg.h:42
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int ShapeCount() const
Return the number of shapes (line segments or arcs) in this line chain.
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
size_t ArcCount() const
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
void SetWidth(int aWidth)
Set the width of all segments in the chain.
An abstract shape on 2D plane.
Definition: shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
@ VIA
Normal via.
Definition: router_tool.cpp:96