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/vector2d.h>
26 
27 #include <geometry/direction45.h>
28 #include <geometry/seg.h>
29 #include <geometry/shape.h>
31 
32 #include "pns_item.h"
33 #include "pns_via.h"
34 
35 namespace PNS {
36 
37 class NODE;
38 class SEGMENT;
39 class VIA;
40 
58 #define PNS_HULL_MARGIN 10
59 
60 class LINE : public ITEM
61 {
62 public:
63  typedef std::vector<SEGMENT*> SEGMENT_REFS;
64 
69  LINE() : ITEM( LINE_T )
70  {
71  m_hasVia = false;
72  m_width = 1; // Dummy value
73  }
74 
75  LINE( const LINE& aOther );
76 
82  LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
83  ITEM( aBase ),
84  m_line( aLine ),
85  m_width( aBase.m_width )
86  {
87  m_net = aBase.m_net;
88  m_layers = aBase.m_layers;
89  m_hasVia = false;
90  }
91 
97  LINE( const VIA& aVia ) :
98  ITEM( LINE_T )
99  {
100  m_hasVia = true;
101  m_via = aVia;
102  m_width = aVia.Diameter();
103  m_net = aVia.Net();
104  m_layers = aVia.Layers();
105  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 
121  void SetShape( const SHAPE_LINE_CHAIN& aLine )
122  {
123  m_line = aLine;
124  }
125 
127  const SHAPE* Shape() const override
128  {
129  return &m_line;
130  }
131 
134  {
135  return m_line;
136  }
137 
139  const SHAPE_LINE_CHAIN& CLine() const
140  {
141  return m_line;
142  }
143 
145  int SegmentCount() const
146  {
147  return m_line.SegmentCount();
148  }
149 
151  int PointCount() const
152  {
153  return m_line.PointCount();
154  }
155 
157  const VECTOR2I& CPoint( int aIdx ) const
158  {
159  return m_line.CPoint( aIdx );
160  }
161 
163  const SEG CSegment( int aIdx ) const
164  {
165  return m_line.CSegment( aIdx );
166  }
167 
169  void SetWidth( int aWidth )
170  {
171  m_width = aWidth;
172  }
173 
175  int Width() const
176  {
177  return m_width;
178  }
179 
181  bool CompareGeometry( const LINE& aOther );
182 
184  void Reverse();
185 
186 
187  /* Linking functions */
188 
190  void LinkSegment( SEGMENT* aSeg )
191  {
192  m_segmentRefs.push_back( aSeg );
193  }
194 
198  {
199  return m_segmentRefs;
200  }
201 
202  bool IsLinked() const
203  {
204  return m_segmentRefs.size() != 0;
205  }
206 
207  bool IsLinkedChecked() const
208  {
209  return IsLinked() && LinkCount() == SegmentCount();
210  }
211 
213  bool ContainsSegment( SEGMENT* aSeg ) const
214  {
215  return std::find( m_segmentRefs.begin(), m_segmentRefs.end(),
216  aSeg ) != m_segmentRefs.end();
217  }
218 
219  SEGMENT* GetLink( int aIndex ) const
220  {
221  return m_segmentRefs[aIndex];
222  }
223 
225  void ClearSegmentLinks();
226 
228  int LinkCount() const
229  {
230  return m_segmentRefs.size();
231  }
232 
235  const LINE ClipToNearestObstacle( NODE* aNode ) const;
236 
238  void ClipVertexRange ( int aStart, int aEnd );
239 
241  int CountCorners( int aAngles ) const;
242 
249  bool Walkaround( SHAPE_LINE_CHAIN aObstacle,
250  SHAPE_LINE_CHAIN& aPre,
251  SHAPE_LINE_CHAIN& aWalk,
252  SHAPE_LINE_CHAIN& aPost,
253  bool aCw ) const;
254 
255  bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
256  SHAPE_LINE_CHAIN& aPath,
257  bool aCw ) const;
258 
259  bool Is45Degree() const;
260 
262  void ShowLinks() const;
263 
264  bool EndsWithVia() const { return m_hasVia; }
265 
266  void AppendVia( const VIA& aVia );
267  void RemoveVia() { m_hasVia = false; }
268 
269  const VIA& Via() const { return m_via; }
270 
271  virtual void Mark( int aMarker ) override;
272  virtual void Unmark( int aMarker = -1 ) override;
273  virtual int Marker() const override;
274 
275  void DragSegment( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
276  void DragCorner( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
277 
278  void SetRank( int aRank ) override;
279  int Rank() const override;
280 
281  bool HasLoops() const;
282  bool HasLockedSegments() const;
283 
284  OPT_BOX2I ChangedArea( const LINE* aOther ) const;
285 
286 private:
287 
288  void dragSegment45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
289  void dragCorner45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
290  void dragSegmentFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
291  void dragCornerFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
292 
294  int aIndex, int aThreshold) const;
295 
296  VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
297  int aIndex, int aThreshold ) const;
298 
300  void copyLinks( const LINE* aParent ) ;
301 
305 
308 
310  int m_width;
311 
313  bool m_hasVia;
314 
317 };
318 
319 }
320 
321 #endif // __PNS_LINE_H
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:139
Class ITEM.
Definition: pns_item.h:53
void DragCorner(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:476
void LinkSegment(SEGMENT *aSeg)
Adds a reference to a segment registered in a NODE that is a part of this line.
Definition: pns_line.h:190
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:82
void dragCorner45(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:446
SEGMENT * GetLink(int aIndex) const
Definition: pns_line.h:219
Class NODE.
Definition: pns_node.h:140
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:874
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:159
LINE()
Constructor Makes an empty line.
Definition: pns_line.h:69
VIA m_via
Via at the end point, if m_hasVia == true
Definition: pns_line.h:316
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:58
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:145
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:163
bool Is45Degree() const
Definition: pns_line.cpp:302
int Rank() const override
Definition: pns_line.cpp:800
void RemoveVia()
Definition: pns_line.h:267
LAYER_RANGE m_layers
Definition: pns_item.h:252
int m_rank
Definition: pns_item.h:257
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:777
void DragSegment(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:488
void dragCornerFree(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:470
int PointCount() const
Function PointCount()
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:151
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:543
bool EndsWithVia() const
Definition: pns_line.h:264
LINE(const VIA &aVia)
Constructor Constructs a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:97
void SetWidth(int aWidth)
Sets line width
Definition: pns_line.h:169
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:157
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:307
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assigns a shape to the line (a polyline/line chain)
Definition: pns_line.h:121
bool IsLinkedChecked() const
Definition: pns_line.h:207
const SHAPE * Shape() const override
Returns the shape of the line
Definition: pns_line.h:127
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
int Diameter() const
Definition: pns_via.h:120
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:769
int Net() const
Definition: pns_item.h:148
void ClipVertexRange(int aStart, int aEnd)
Clips the line to a given range of vertices.
Definition: pns_line.cpp:819
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:117
std::vector< SEGMENT * > SEGMENT_REFS
Definition: pns_line.h:63
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:328
Class SHAPE.
Definition: shape.h:58
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:313
void SetRank(int aRank) override
Definition: pns_line.cpp:790
virtual void Mark(int aMarker) override
Definition: pns_line.cpp:85
int SegmentCount() const
Function SegmentCount()
int m_net
Definition: pns_item.h:255
SHAPE_LINE_CHAIN & Line()
Modifiable accessor to the underlying shape
Definition: pns_line.h:133
void dragSegment45(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:589
Definition: seg.h:36
virtual int Rank() const
Definition: pns_item.h:223
virtual int Marker() const override
Definition: pns_line.cpp:104
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:197
void ClearSegmentLinks()
Erases the linking information. Used to detach the line from the owning node.
Definition: pns_line.cpp:854
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:304
const SEG CSegment(int aIndex) const
Function CSegment()
Class SHAPE_LINE_CHAIN.
bool HasLoops() const
Definition: pns_line.cpp:839
int Width() const
Returns line width
Definition: pns_line.h:175
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:501
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:523
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
bool ContainsSegment(SEGMENT *aSeg) const
Checks if the segment aSeg is a part of the line.
Definition: pns_line.h:213
bool IsLinked() const
Definition: pns_line.h:202
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:110
const VIA & Via() const
Definition: pns_line.h:269
bool CompareGeometry(const LINE &aOther)
Returns true if the line is geometrically identical as line aOther
Definition: pns_line.cpp:763
Push and Shove diff pair dimensions (gap) settings dialog.
void dragSegmentFree(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
virtual LINE * Clone() const override
Function Clone()
Definition: pns_line.cpp:77
virtual void Unmark(int aMarker=-1) override
Definition: pns_line.cpp:95
void ShowLinks() const
Prints out all linked segments
Definition: pns_line.cpp:354
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150
int m_width
our width
Definition: pns_line.h:310
bool HasLockedSegments() const
Definition: pns_line.cpp:955
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:137
int LinkCount() const
Returns the number of segments that were assembled together to form this line.
Definition: pns_line.h:228