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 <tomasz.wlostowski@cern.ch>
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 
29 #include <geometry/direction45.h>
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 
38 namespace PNS {
39 
40 class LINKED_ITEM;
41 class NODE;
42 class VIA;
43 
44 #define PNS_HULL_MARGIN 10
45 
60 class LINE : public LINK_HOLDER
61 {
62 public:
66  LINE() :
68  m_blockingObstacle( nullptr )
69  {
70  m_hasVia = false;
71  m_width = 1; // Dummy value
72  m_snapThreshhold = 0;
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();
105  m_snapThreshhold = 0;
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() == SegmentCount();
123  }
124 
126  void SetShape( const SHAPE_LINE_CHAIN& aLine )
127  {
128  m_line = aLine;
130  }
131 
133  const SHAPE* Shape() const override { return &m_line; }
134 
136  SHAPE_LINE_CHAIN& Line() { return m_line; }
137  const SHAPE_LINE_CHAIN& CLine() const { return m_line; }
138 
139  int SegmentCount() const { return m_line.SegmentCount(); }
140  int PointCount() const { return m_line.PointCount(); }
141  int ArcCount() const { return m_line.ArcCount(); }
142  int ShapeCount() const { return m_line.ShapeCount(); }
143 
145  const VECTOR2I& CPoint( int aIdx ) const { return m_line.CPoint( aIdx ); }
146  const SEG CSegment( int aIdx ) const { return m_line.CSegment( aIdx ); }
147 
149  void SetWidth( int aWidth )
150  {
151  m_width = aWidth;
152  m_line.SetWidth( aWidth );
153  }
154 
156  int Width() const { return m_width; }
157 
159  bool CompareGeometry( const LINE& aOther );
160 
162  void Reverse();
163 
166  const LINE ClipToNearestObstacle( NODE* aNode ) const;
167 
169  void ClipVertexRange ( int aStart, int aEnd );
170 
172  int CountCorners( int aAngles ) const;
173 
181  bool Walkaround( SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN& aPre, SHAPE_LINE_CHAIN& aWalk,
182  SHAPE_LINE_CHAIN& aPost, bool aCw ) const;
183 
184  bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle, SHAPE_LINE_CHAIN& aPath, bool aCw ) const;
185 
186  bool Is45Degree() const;
187 
189  void ShowLinks() const;
190 
191  bool EndsWithVia() const { return m_hasVia; }
192 
193  void AppendVia( const VIA& aVia );
194  void RemoveVia() { m_hasVia = false; }
195 
196  const VIA& Via() const { return m_via; }
197 
198  void SetViaDiameter( int aDiameter ) { m_via.SetDiameter( aDiameter ); }
199  void SetViaDrill( int aDrill ) { m_via.SetDrill( aDrill ); }
200 
201  virtual void Mark( int aMarker ) const override;
202  virtual void Unmark( int aMarker = -1 ) const override;
203  virtual int Marker() const override;
204 
205  void SetBlockingObstacle( ITEM* aObstacle ) { m_blockingObstacle = aObstacle; }
207 
208  void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
209  void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
210 
211  void SetRank( int aRank ) override;
212  int Rank() const override;
213 
214  bool HasLoops() const;
215  bool HasLockedSegments() const;
216 
217  void Clear();
218 
219  OPT_BOX2I ChangedArea( const LINE* aOther ) const;
220 
221  void SetSnapThreshhold( int aThreshhold )
222  {
223  m_snapThreshhold = aThreshhold;
224  }
225 
226  int GetSnapThreshhold() const
227  {
228  return m_snapThreshhold;
229  }
230 
231 private:
232  void dragSegment45( const VECTOR2I& aP, int aIndex );
233  void dragCorner45( const VECTOR2I& aP, int aIndex );
234  void dragSegmentFree( const VECTOR2I& aP, int aIndex );
235  void dragCornerFree( const VECTOR2I& aP, int aIndex );
236 
238  int aIndex ) const;
239 
240  VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP,
241  int aIndex ) const;
242 
244  int m_width;
245 
246 
248 
249  bool m_hasVia;
251 
253 };
254 
255 }
256 
257 #endif // __PNS_LINE_H
const SHAPE_LINE_CHAIN & CLine() const
Definition: pns_line.h:137
Base class for PNS router board items.
Definition: pns_item.h:55
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
Definition: track.h:343
void SetViaDiameter(int aDiameter)
Definition: pns_line.h:198
Keep the router "world" - i.e.
Definition: pns_node.h:149
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:1008
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).
LINE()
Makes an empty line.
Definition: pns_line.h:66
VIA m_via
Definition: pns_line.h:250
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:606
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:61
int SegmentCount() const
Definition: pns_line.h:139
const SEG CSegment(int aIdx) const
Set line width.
Definition: pns_line.h:146
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:660
bool Is45Degree() const
Print out all linked segments.
Definition: pns_line.cpp:427
int Rank() const override
Definition: pns_line.cpp:893
void RemoveVia()
Definition: pns_line.h:194
LAYER_RANGE m_layers
Definition: pns_item.h:239
int m_rank
Definition: pns_item.h:244
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:870
size_t ArcCount() const
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:60
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
int PointCount() const
Function PointCount()
int PointCount() const
Definition: pns_line.h:140
bool EndsWithVia() const
Definition: pns_line.h:191
LINE(const VIA &aVia)
Construct a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:95
ITEM * m_blockingObstacle
For mark obstacle mode.
Definition: pns_line.h:252
void SetWidth(int aWidth)
Return line width.
Definition: pns_line.h:149
const VECTOR2I & CPoint(int aIdx) const
Definition: pns_line.h:145
SHAPE_LINE_CHAIN m_line
The actual shape of the line.
Definition: pns_line.h:243
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Return the shape of the line.
Definition: pns_line.h:126
void SetDiameter(int aDiameter)
Definition: pns_via.h:109
bool IsLinkedChecked() const
Assign a shape to the line (a polyline/line chain).
Definition: pns_line.h:120
int GetSnapThreshhold() const
Definition: pns_line.h:226
const SHAPE * Shape() const override
Modifiable accessor to the underlying shape.
Definition: pns_line.h:133
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetWidth(int aWidth)
Sets the width of all segments in the chain.
int ArcCount() const
Definition: pns_line.h:141
int Diameter() const
Definition: pns_via.h:107
void Reverse()
Clip the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition: pns_line.cpp:862
int Net() const
Definition: pns_item.h:148
void ClipVertexRange(int aStart, int aEnd)
Return the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:912
const LINE ClipToNearestObstacle(NODE *aNode) const
Clip the line to a given range of vertices.
Definition: pns_line.cpp:456
int ShapeCount() const
Returns the number of shapes (line segments or arcs) in this line chain.
An abstract shape on 2D plane.
Definition: shape.h:116
bool m_hasVia
Optional via at the end point.
Definition: pns_line.h:249
void SetRank(int aRank) override
Definition: pns_line.cpp:883
int SegmentCount() const
Function SegmentCount()
int m_net
Definition: pns_item.h:242
void dragCorner45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:565
SHAPE_LINE_CHAIN & Line()
Definition: pns_line.h:136
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:594
Definition: seg.h:41
void SetViaDrill(int aDrill)
Definition: pns_line.h:199
int ShapeCount() const
Return the aIdx-th point of the line.
Definition: pns_line.h:142
virtual int Rank() const
Definition: pns_item.h:211
virtual int Marker() const override
Definition: pns_line.cpp:109
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
int m_snapThreshhold
Width to smooth out jagged segments.
Definition: pns_line.h:247
bool HasLoops() const
Definition: pns_line.cpp:979
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:156
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:525
void SetDrill(int aDrill)
Definition: pns_via.h:116
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:126
ITEM * GetBlockingObstacle() const
Definition: pns_line.h:206
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:705
void Clear()
Definition: pns_line.cpp:1099
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:110
const VIA & Via() const
Definition: pns_line.h:196
bool CompareGeometry(const LINE &aOther)
Reverse the point/vertex order.
Definition: pns_line.cpp:856
Push and Shove diff pair dimensions (gap) settings dialog.
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:588
virtual LINE * Clone() const override
Return a deep copy of the item.
Definition: pns_line.cpp:82
void ShowLinks() const
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150
int m_width
Our width.
Definition: pns_line.h:244
virtual void Unmark(int aMarker=-1) const override
Definition: pns_line.cpp:100
void SetSnapThreshhold(int aThreshhold)
Definition: pns_line.h:221
bool HasLockedSegments() const
Definition: pns_line.cpp:1089
int CountCorners(int aAngles) const
Definition: pns_line.cpp:136
virtual void Mark(int aMarker) const override
Definition: pns_line.cpp:90
void SetBlockingObstacle(ITEM *aObstacle)
Definition: pns_line.h:205
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:618