KiCad PCB EDA Suite
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-2021 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;
43
44#define PNS_HULL_MARGIN 10
45
60class LINE : public LINK_HOLDER
61{
62public:
66 LINE() :
68 m_blockingObstacle( nullptr )
69 {
70 m_hasVia = false;
71 m_width = 1; // Dummy value
73 }
74
75 LINE( const LINE& aOther );
76
80 LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
81 LINK_HOLDER( aBase ),
82 m_line( aLine ),
83 m_width( aBase.m_width ),
85 m_blockingObstacle( nullptr )
86 {
87 m_net = aBase.m_net;
88 m_layers = aBase.m_layers;
89 m_hasVia = false;
90 }
91
95 LINE( const VIA& aVia ) :
97 m_blockingObstacle( nullptr )
98 {
99 m_hasVia = true;
100 m_via = aVia;
101 m_width = aVia.Diameter();
102 m_net = aVia.Net();
103 m_layers = aVia.Layers();
104 m_rank = aVia.Rank();
106 }
107
108 ~LINE();
109
110 static inline bool ClassOf( const ITEM* aItem )
111 {
112 return aItem && LINE_T == aItem->Kind();
113 }
114
116 virtual LINE* Clone() const override;
117
118 LINE& operator=( const LINE& aOther );
119
120 bool IsLinkedChecked() const
121 {
122 return IsLinked() && LinkCount() == ShapeCount();
123 }
124
126 void SetShape( const SHAPE_LINE_CHAIN& aLine )
127 {
128 m_line = aLine;
130
131 if( m_hasVia && m_line.PointCount() > 0 )
132 {
133 m_via.SetPos( m_line.CPoint( -1 ) );
134 }
135 }
136
138 const SHAPE* Shape() 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 SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
152
154 void SetWidth( int aWidth )
155 {
156 m_width = aWidth;
157 m_line.SetWidth( aWidth );
158 }
159
161 int Width() const { return m_width; }
162
164 bool CompareGeometry( const LINE& aOther );
165
167 void Reverse();
168
171 const LINE ClipToNearestObstacle( NODE* aNode ) const;
172
174 void ClipVertexRange ( int aStart, int aEnd );
175
177 int CountCorners( int aAngles ) const;
178
187 SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
188
189 bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
190
192 void ShowLinks() const;
193
194 bool EndsWithVia() const { return m_hasVia; }
195
196 void AppendVia( const VIA& aVia );
197 void RemoveVia() { m_hasVia = false; }
198
199 const VIA& Via() const { return m_via; }
200
201 void SetViaDiameter( int aDiameter ) { m_via.SetDiameter( aDiameter ); }
202 void SetViaDrill( int aDrill ) { m_via.SetDrill( aDrill ); }
203
204 virtual void Mark( int aMarker ) const override;
205 virtual void Unmark( int aMarker = -1 ) const override;
206 virtual int Marker() const override;
207
208 void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
210
211 void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
212 void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
213
214 void SetRank( int aRank ) override;
215 int Rank() const override;
216
217 bool HasLoops() const;
218 bool HasLockedSegments() const;
219
220 void Clear();
221
222 OPT_BOX2I ChangedArea( const LINE* aOther ) const;
223
224 void SetSnapThreshhold( int aThreshhold )
225 {
226 m_snapThreshhold = aThreshhold;
227 }
228
230 {
231 return m_snapThreshhold;
232 }
233
234private:
235 void dragSegment45( const VECTOR2I& aP, int aIndex );
236 void dragCorner45( const VECTOR2I& aP, int aIndex );
237 void dragSegmentFree( const VECTOR2I& aP, int aIndex );
238 void dragCornerFree( const VECTOR2I& aP, int aIndex );
239
241 int aIndex ) const;
242
243 VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
244 int aIndex ) const;
245
248
249
251
252 bool m_hasVia;
254
256};
257
258}
259
260#endif // __PNS_LINE_H
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:850
Base class for PNS router board items.
Definition: pns_item.h:56
virtual int Rank() const
Definition: pns_item.h:217
int m_net
Definition: pns_item.h:261
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:132
LAYER_RANGE m_layers
Definition: pns_item.h:258
@ LINE_T
Definition: pns_item.h:64
const LAYER_RANGE & Layers() const
Definition: pns_item.h:156
int Net() const
Definition: pns_item.h:154
int m_rank
Definition: pns_item.h:263
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
void SetViaDrill(int aDrill)
Definition: pns_line.h:202
virtual void Unmark(int aMarker=-1) const override
Definition: pns_line.cpp:99
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:847
const VECTOR2I & CPoint(int aIdx) const
Definition: pns_line.h:150
ITEM * GetBlockingObstacle() const
Definition: pns_line.h:209
LINE(const VIA &aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:95
int ArcCount() const
Definition: pns_line.h:146
const SHAPE * Shape() const override
Modifiable accessor to the underlying shape.
Definition: pns_line.h:138
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition: pns_line.h:126
int m_width
Our width.
Definition: pns_line.h:247
virtual void Mark(int aMarker) const override
Definition: pns_line.cpp:89
void ClipVertexRange(int aStart, int aEnd)
Return the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:1074
void RemoveVia()
Definition: pns_line.h:197
int CountCorners(int aAngles) const
Definition: pns_line.cpp:135
bool HasLoops() const
Definition: pns_line.cpp:1123
const VIA & Via() const
Definition: pns_line.h:199
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition: pns_line.h:255
const SHAPE_LINE_CHAIN & CLine() const
Definition: pns_line.h:142
void SetRank(int aRank) override
Definition: pns_line.cpp:1044
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:1152
bool m_hasVia
Optional via at the end point.
Definition: pns_line.h:252
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:80
LINE()
Makes an empty line.
Definition: pns_line.h:66
bool HasLockedSegments() const
Definition: pns_line.cpp:1233
void Clear()
Definition: pns_line.cpp:1244
SHAPE_LINE_CHAIN & Line()
Definition: pns_line.h:141
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:81
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition: pns_line.cpp:1023
void ShowLinks() const
void dragCorner45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:677
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition: pns_line.cpp:551
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:60
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:734
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:110
void SetSnapThreshhold(int aThreshhold)
Definition: pns_line.h:224
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:802
int SegmentCount() const
Definition: pns_line.h:144
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:748
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition: pns_line.h:120
void SetViaDiameter(int aDiameter)
Definition: pns_line.h:201
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:760
virtual int Marker() const override
Definition: pns_line.cpp:108
int PointCount() const
Definition: pns_line.h:145
int m_snapThreshhold
Width to smooth out jagged segments.
Definition: pns_line.h:250
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
Definition: pns_line.cpp:1017
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:246
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:1031
void SetWidth(int aWidth)
Return line width.
Definition: pns_line.h:154
int GetSnapThreshhold() const
Definition: pns_line.h:229
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:208
bool EndsWithVia() const
Definition: pns_line.h:194
VIA m_via
Definition: pns_line.h:253
const SEG CSegment(int aIdx) const
Set line width.
Definition: pns_line.h:151
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:161
int Rank() const override
Definition: pns_line.cpp:1054
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:707
Keep the router "world" - i.e.
Definition: pns_node.h:156
int Diameter() const
Definition: pns_via.h:112
void SetDiameter(int aDiameter)
Definition: pns_via.h:114
void SetPos(const VECTOR2I &aPos)
Definition: pns_via.h:102
void SetDrill(int aDrill)
Definition: pns_via.h:122
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:123
Push and Shove diff pair dimensions (gap) settings dialog.