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 (C) 2016-2023 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 SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
148
150 void SetWidth( int aWidth )
151 {
152 m_width = aWidth;
153 m_line.SetWidth( aWidth );
154 }
155
157 int Width() const { return m_width; }
158
160 bool CompareGeometry( const LINE& aOther );
161
163 void Reverse();
164
167 const LINE ClipToNearestObstacle( NODE* aNode ) const;
168
170 void ClipVertexRange ( int aStart, int aEnd );
171
173 int CountCorners( int aAngles ) const;
174
183 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
184
185 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
186
188 void ShowLinks() const;
189
190 bool EndsWithVia() const { return m_via != nullptr; }
191
192 int FindSegment( const SEGMENT* aSeg ) const;
193
194 void AppendVia( const VIA& aVia );
195 void LinkVia( VIA* aVia );
196 void RemoveVia();
197
198 VIA& Via() { return *m_via; }
199 const VIA& Via() const { return *m_via; }
200
201 void SetViaDiameter( int aDiameter )
202 {
203 wxCHECK( m_via, /* void */ );
204 wxCHECK2_MSG( m_via->StackMode() == VIA::STACK_MODE::NORMAL,
206 wxS( "Warning: converting a complex viastack to normal in PNS_LINE" ) );
207
208 m_via->SetDiameter( VIA::ALL_LAYERS, aDiameter );
209 }
210 void SetViaDrill( int aDrill ) { assert(m_via); m_via->SetDrill( aDrill ); }
211
212 virtual void Mark( int aMarker ) const override;
213 virtual void Unmark( int aMarker = -1 ) const override;
214 virtual int Marker() const override;
215
216 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
218
219 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
220 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false, DIRECTION_45 aPreferredEndingDirection = DIRECTION_45() );
221
222 void SetRank( int aRank ) override;
223 int Rank() const override;
224
225 bool HasLoops() const;
226 bool HasLockedSegments() const;
227
228 void Clear();
229
230 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
231
232 void SetSnapThreshhold( int aThreshhold )
233 {
234 m_snapThreshhold = aThreshhold;
235 }
236
238 {
239 return m_snapThreshhold;
240 }
241
242private:
243 void dragSegment45( const VECTOR2I& aP, int aIndex );
244 void dragCorner45( const VECTOR2I& aP, int aIndex, DIRECTION_45 aPreferredEndingDirection );
245 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
246 void dragCornerFree( const VECTOR2I& aP, int aIndex );
247
249 int aIndex ) const;
250
251 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
252 int aIndex ) const;
253
256
257
259
262};
263
264}
265
266#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:97
virtual int Rank() const
Definition: pns_item.h:253
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
PNS_LAYER_RANGE m_layers
Definition: pns_item.h:306
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:170
NET_HANDLE m_net
Definition: pns_item.h:309
int m_rank
Definition: pns_item.h:311
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:853
void ClipVertexRange(int aStart, int aEnd)
Return the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:1137
void SetViaDrill(int aDrill)
Definition: pns_line.h:210
int FindSegment(const SEGMENT *aSeg) const
Definition: pns_line.cpp:1338
const VECTOR2I & CPoint(int aIdx) const
Definition: pns_line.h:146
ITEM * GetBlockingObstacle() const
Definition: pns_line.h:217
bool HasLoops() const
Definition: pns_line.cpp:1186
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:1215
bool HasLockedSegments() const
Definition: pns_line.cpp:1296
int ArcCount() const
Definition: pns_line.h:142
int Rank() const override
Definition: pns_line.cpp:1117
void dragCorner45(const VECTOR2I &aP, int aIndex, DIRECTION_45 aPreferredEndingDirection)
Definition: pns_line.cpp:724
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition: pns_line.cpp:580
VIA * m_via
Definition: pns_line.h:260
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:123
int m_width
Our width.
Definition: pns_line.h:255
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
Definition: pns_line.cpp:1068
const VIA & Via() const
Definition: pns_line.h:199
void LinkVia(VIA *aVia)
Definition: pns_line.cpp:1095
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition: pns_line.h:261
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:811
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:79
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:898
void RemoveVia()
Definition: pns_line.cpp:1315
int CountCorners(int aAngles) const
Definition: pns_line.cpp:167
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:1107
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:785
void ShowLinks() const
virtual int Marker() const override
Definition: pns_line.cpp:142
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:1082
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:111
VIA & Via()
Definition: pns_line.h:198
void SetSnapThreshhold(int aThreshhold)
Definition: pns_line.h:232
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:201
virtual void Unmark(int aMarker=-1) const override
Definition: pns_line.cpp:133
int PointCount() const
Definition: pns_line.h:141
int m_snapThreshhold
Width to smooth out jagged segments.
Definition: pns_line.h:258
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:254
void SetWidth(int aWidth)
Return line width.
Definition: pns_line.h:150
int GetSnapThreshhold() const
Definition: pns_line.h:237
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:799
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:216
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:190
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition: pns_line.cpp:1074
const SEG CSegment(int aIdx) const
Set line width.
Definition: pns_line.h:147
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:758
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:115
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:157
void Clear()
Definition: pns_line.cpp:1307
Keep the router "world" - i.e.
Definition: pns_node.h:231
int Diameter(int aLayer) const
Definition: pns_via.h:191
void SetDiameter(int aLayer, int aDiameter)
Definition: pns_via.h:198
void SetDrill(int aDrill)
Definition: pns_via.h:213
static constexpr int ALL_LAYERS
Definition: pns_via.h:76
void SetStackMode(STACK_MODE aStackMode)
Definition: pns_via.cpp:78
STACK_MODE StackMode() const
Definition: pns_via.h:165
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.
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