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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef __PNS_LINE_H
23 #define __PNS_LINE_H
24 
25 #include <math/box2.h>
26 #include <math/vector2d.h>
27 
28 #include <geometry/direction45.h>
29 #include <geometry/seg.h>
30 #include <geometry/shape.h>
32 
33 #include "pns_item.h"
34 #include "pns_via.h"
35 
36 namespace PNS {
37 
38 class LINKED_ITEM;
39 class NODE;
40 class VIA;
41 
59 #define PNS_HULL_MARGIN 10
60 
61 class LINE : public ITEM
62 {
63 public:
64  typedef std::vector<LINKED_ITEM*> SEGMENT_REFS;
65 
70  LINE() : ITEM( LINE_T )
71  {
72  m_hasVia = false;
73  m_width = 1; // Dummy value
74  m_snapThreshhold = 0;
75  }
76 
77  LINE( const LINE& aOther );
78 
84  LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine )
85  : ITEM( aBase ),
86  m_line( aLine ),
87  m_width( aBase.m_width ),
89  {
90  m_net = aBase.m_net;
91  m_layers = aBase.m_layers;
92  m_hasVia = false;
93  }
94 
100  LINE( const VIA& aVia ) :
101  ITEM( LINE_T )
102  {
103  m_hasVia = true;
104  m_via = aVia;
105  m_width = aVia.Diameter();
106  m_net = aVia.Net();
107  m_layers = aVia.Layers();
108  m_rank = aVia.Rank();
109  m_snapThreshhold = 0;
110  }
111 
112  ~LINE();
113 
114  static inline bool ClassOf( const ITEM* aItem )
115  {
116  return aItem && LINE_T == aItem->Kind();
117  }
118 
120  virtual LINE* Clone() const override;
121 
122  LINE& operator=( const LINE& aOther );
123 
125  void SetShape( const SHAPE_LINE_CHAIN& aLine )
126  {
127  m_line = aLine;
129  }
130 
132  const SHAPE* Shape() const override
133  {
134  return &m_line;
135  }
136 
139  {
140  return m_line;
141  }
142 
144  const SHAPE_LINE_CHAIN& CLine() const
145  {
146  return m_line;
147  }
148 
150  int SegmentCount() const
151  {
152  return m_line.SegmentCount();
153  }
154 
156  int PointCount() const
157  {
158  return m_line.PointCount();
159  }
160 
162  int ArcCount() const
163  {
164  return m_line.ArcCount();
165  }
166 
168  const VECTOR2I& CPoint( int aIdx ) const
169  {
170  return m_line.CPoint( aIdx );
171  }
172 
174  const SEG CSegment( int aIdx ) const
175  {
176  return m_line.CSegment( aIdx );
177  }
178 
180  void SetWidth( int aWidth )
181  {
182  m_width = aWidth;
183  m_line.SetWidth( aWidth );
184  }
185 
187  int Width() const
188  {
189  return m_width;
190  }
191 
193  bool CompareGeometry( const LINE& aOther );
194 
196  void Reverse();
197 
198 
199  /* Linking functions */
200 
202  void LinkSegment( LINKED_ITEM* aSeg )
203  {
204  m_segmentRefs.push_back( aSeg );
205  }
206 
210  {
211  return m_segmentRefs;
212  }
213 
214  bool IsLinked() const
215  {
216  return m_segmentRefs.size() != 0;
217  }
218 
219  bool IsLinkedChecked() const
220  {
221  return IsLinked() && LinkCount() == SegmentCount();
222  }
223 
225  bool ContainsSegment( LINKED_ITEM* aSeg ) const
226  {
227  return std::find( m_segmentRefs.begin(), m_segmentRefs.end(),
228  aSeg ) != m_segmentRefs.end();
229  }
230 
231  LINKED_ITEM* GetLink( int aIndex ) const
232  {
233  return m_segmentRefs[aIndex];
234  }
235 
237  void ClearSegmentLinks();
238 
240  int LinkCount() const
241  {
242  return m_segmentRefs.size();
243  }
244 
247  const LINE ClipToNearestObstacle( NODE* aNode ) const;
248 
250  void ClipVertexRange ( int aStart, int aEnd );
251 
253  int CountCorners( int aAngles ) const;
254 
261  bool Walkaround( SHAPE_LINE_CHAIN aObstacle,
262  SHAPE_LINE_CHAIN& aPre,
263  SHAPE_LINE_CHAIN& aWalk,
264  SHAPE_LINE_CHAIN& aPost,
265  bool aCw ) const;
266 
267  bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
268  SHAPE_LINE_CHAIN& aPath,
269  bool aCw ) const;
270 
271  bool Is45Degree() const;
272 
274  void ShowLinks() const;
275 
276  bool EndsWithVia() const { return m_hasVia; }
277 
278  void AppendVia( const VIA& aVia );
279  void RemoveVia() { m_hasVia = false; }
280 
281  const VIA& Via() const { return m_via; }
282 
283  virtual void Mark( int aMarker ) override;
284  virtual void Unmark( int aMarker = -1 ) override;
285  virtual int Marker() const override;
286 
287  void DragSegment( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
288  void DragCorner( const VECTOR2I& aP, int aIndex, bool aFreeAngle = false );
289 
290  void SetRank( int aRank ) override;
291  int Rank() const override;
292 
293  bool HasLoops() const;
294  bool HasLockedSegments() const;
295 
296  void Clear();
297  void Merge ( const LINE& aOther );
298 
299  OPT_BOX2I ChangedArea( const LINE* aOther ) const;
300 
301  void SetSnapThreshhold( int aThreshhold )
302  {
303  m_snapThreshhold = aThreshhold;
304  }
305 
306  int GetSnapThreshhold() const
307  {
308  return m_snapThreshhold;
309  }
310 
311 private:
312  void dragSegment45( const VECTOR2I& aP, int aIndex );
313  void dragCorner45( const VECTOR2I& aP, int aIndex );
314  void dragSegmentFree( const VECTOR2I& aP, int aIndex );
315  void dragCornerFree( const VECTOR2I& aP, int aIndex );
316 
318  const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP, int aIndex ) const;
319 
321  const SHAPE_LINE_CHAIN& aPath, const VECTOR2I& aP, int aIndex ) const;
322 
324  void copyLinks( const LINE* aParent ) ;
325 
329 
332 
334  int m_width;
335 
337  bool m_hasVia;
338 
341 
344 };
345 
346 }
347 
348 #endif // __PNS_LINE_H
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:144
ITEM.
Definition: pns_item.h:53
LINE(const LINE &aBase, const SHAPE_LINE_CHAIN &aLine)
Constructor Copies properties (net, layers, etc.) from a base line and replaces the shape by another.
Definition: pns_line.h:84
NODE.
Definition: pns_node.h:145
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:956
bool Walkaround(SHAPE_LINE_CHAIN aObstacle, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aWalk, SHAPE_LINE_CHAIN &aPost, bool aCw) const
Calculates a line thightly wrapping a convex hull of an obstacle object (aObstacle).
Definition: pns_line.cpp:162
LINE()
Constructor Makes an empty line.
Definition: pns_line.h:70
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:343
void DragSegment(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:595
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:60
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:150
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:174
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:649
bool Is45Degree() const
Definition: pns_line.cpp:408
int Rank() const override
Definition: pns_line.cpp:882
LINKED_ITEM * GetLink(int aIndex) const
Definition: pns_line.h:231
void Merge(const LINE &aOther)
void RemoveVia()
Definition: pns_line.h:279
LAYER_RANGE m_layers
Definition: pns_item.h:253
int m_rank
Definition: pns_item.h:258
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:859
size_t ArcCount() const
void dragSegmentFree(const VECTOR2I &aP, int aIndex)
int PointCount() const
Function PointCount()
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:156
bool EndsWithVia() const
Definition: pns_line.h:276
LINE(const VIA &aVia)
Constructor Constructs a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:100
void SetWidth(int aWidth)
Sets line width
Definition: pns_line.h:180
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:168
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:331
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assigns a shape to the line (a polyline/line chain)
Definition: pns_line.h:125
bool IsLinkedChecked() const
Definition: pns_line.h:219
int GetSnapThreshhold() const
Definition: pns_line.h:306
const SHAPE * Shape() const override
Returns the shape of the line
Definition: pns_line.h:132
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetWidth(int aWidth)
Sets the width of all segments in the chain.
int ArcCount() const
Returns the number of arcs in the line
Definition: pns_line.h:162
int Diameter() const
Definition: pns_via.h:121
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:851
int Net() const
Definition: pns_item.h:149
void ClipVertexRange(int aStart, int aEnd)
Clips the line to a given range of vertices.
Definition: pns_line.cpp:901
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:120
const LINE ClipToNearestObstacle(NODE *aNode) const
Clips the line to the nearest obstacle, traversing from the line's start vertex (0).
Definition: pns_line.cpp:437
void LinkSegment(LINKED_ITEM *aSeg)
Adds a reference to a segment registered in a NODE that is a part of this line.
Definition: pns_line.h:202
SHAPE.
Definition: shape.h:74
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:337
std::vector< LINKED_ITEM * > SEGMENT_REFS
Definition: pns_line.h:64
void SetRank(int aRank) override
Definition: pns_line.cpp:872
virtual void Mark(int aMarker) override
Definition: pns_line.cpp:88
int SegmentCount() const
Function SegmentCount()
int m_net
Definition: pns_item.h:256
void dragCorner45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:554
SHAPE_LINE_CHAIN & Line()
Modifiable accessor to the underlying shape
Definition: pns_line.h:138
void DragCorner(const VECTOR2I &aP, int aIndex, bool aFreeAngle=false)
Definition: pns_line.cpp:583
Definition: seg.h:39
bool ContainsSegment(LINKED_ITEM *aSeg) const
Checks if the segment aSeg is a part of the line.
Definition: pns_line.h:225
virtual int Rank() const
Definition: pns_item.h:224
virtual int Marker() const override
Definition: pns_line.cpp:107
SEGMENT_REFS & LinkedSegments()
Returns the list of segments from the owning node that constitute this line (or NULL if the line is n...
Definition: pns_line.h:209
void ClearSegmentLinks()
Erases the linking information. Used to detach the line from the owning node.
Definition: pns_line.cpp:936
SEGMENT_REFS m_segmentRefs
List of segments in the owning NODE (ITEM::m_owner) that constitute this line, or NULL if the line is...
Definition: pns_line.h:328
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
int m_snapThreshhold
Width to smooth out jagged segments
Definition: pns_line.h:340
bool HasLoops() const
Definition: pns_line.cpp:921
int Width() const
Returns line width
Definition: pns_line.h:187
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
void dragSegment45(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:694
void Clear()
Definition: pns_line.cpp:1047
bool IsLinked() const
Definition: pns_line.h:214
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:114
const VIA & Via() const
Definition: pns_line.h:281
bool CompareGeometry(const LINE &aOther)
Returns true if the line is geometrically identical as line aOther
Definition: pns_line.cpp:845
Push and Shove diff pair dimensions (gap) settings dialog.
void dragCornerFree(const VECTOR2I &aP, int aIndex)
Definition: pns_line.cpp:577
virtual LINE * Clone() const override
Function Clone()
Definition: pns_line.cpp:80
virtual void Unmark(int aMarker=-1) override
Definition: pns_line.cpp:98
void ShowLinks() const
Prints out all linked segments
Definition: pns_line.cpp:463
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151
int m_width
our width
Definition: pns_line.h:334
void SetSnapThreshhold(int aThreshhold)
Definition: pns_line.h:301
bool HasLockedSegments() const
Definition: pns_line.cpp:1037
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:140
int LinkCount() const
Returns the number of segments that were assembled together to form this line.
Definition: pns_line.h:240
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex) const
Definition: pns_line.cpp:607