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 
92  ~LINE();
93 
94  static inline bool ClassOf( const ITEM* aItem )
95  {
96  return aItem && LINE_T == aItem->Kind();
97  }
98 
100  virtual LINE* Clone() const override;
101 
102  const LINE& operator=( const LINE& aOther );
103 
105  void SetShape( const SHAPE_LINE_CHAIN& aLine )
106  {
107  m_line = aLine;
108  }
109 
111  const SHAPE* Shape() const override
112  {
113  return &m_line;
114  }
115 
118  {
119  return m_line;
120  }
121 
123  const SHAPE_LINE_CHAIN& CLine() const
124  {
125  return m_line;
126  }
127 
129  int SegmentCount() const
130  {
131  return m_line.SegmentCount();
132  }
133 
135  int PointCount() const
136  {
137  return m_line.PointCount();
138  }
139 
141  const VECTOR2I& CPoint( int aIdx ) const
142  {
143  return m_line.CPoint( aIdx );
144  }
145 
147  const SEG CSegment( int aIdx ) const
148  {
149  return m_line.CSegment( aIdx );
150  }
151 
153  void SetWidth( int aWidth )
154  {
155  m_width = aWidth;
156  }
157 
159  int Width() const
160  {
161  return m_width;
162  }
163 
165  bool CompareGeometry( const LINE& aOther );
166 
168  void Reverse();
169 
170 
171  /* Linking functions */
172 
174  void LinkSegment( SEGMENT* aSeg )
175  {
176  m_segmentRefs.push_back( aSeg );
177  }
178 
181  SEGMENT_REFS& LinkedSegments()
182  {
183  return m_segmentRefs;
184  }
185 
186  bool IsLinked() const
187  {
188  return m_segmentRefs.size() != 0;
189  }
190 
191  bool IsLinkedChecked() const
192  {
193  return IsLinked() && LinkCount() == SegmentCount();
194  }
195 
197  bool ContainsSegment( SEGMENT* aSeg ) const
198  {
199  return std::find( m_segmentRefs.begin(), m_segmentRefs.end(),
200  aSeg ) != m_segmentRefs.end();
201  }
202 
203  SEGMENT* GetLink( int aIndex ) const
204  {
205  return m_segmentRefs[aIndex];
206  }
207 
209  void ClearSegmentLinks();
210 
212  int LinkCount() const
213  {
214  return m_segmentRefs.size();
215  }
216 
219  const LINE ClipToNearestObstacle( NODE* aNode ) const;
220 
222  void ClipVertexRange ( int aStart, int aEnd );
223 
225  int CountCorners( int aAngles ) const;
226 
233  bool Walkaround( SHAPE_LINE_CHAIN aObstacle,
234  SHAPE_LINE_CHAIN& aPre,
235  SHAPE_LINE_CHAIN& aWalk,
236  SHAPE_LINE_CHAIN& aPost,
237  bool aCw ) const;
238 
239  void Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
240  SHAPE_LINE_CHAIN& aPath,
241  bool aCw ) const;
242 
243  bool Is45Degree() const;
244 
246  void ShowLinks() const;
247 
248  bool EndsWithVia() const { return m_hasVia; }
249 
250  void AppendVia( const VIA& aVia );
251  void RemoveVia() { m_hasVia = false; }
252 
253  const VIA& Via() const { return m_via; }
254 
255  virtual void Mark( int aMarker ) override;
256  virtual void Unmark( int aMarker = -1 ) override;
257  virtual int Marker() const override;
258 
259  void DragSegment( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
260  void DragCorner( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
261 
262  void SetRank( int aRank ) override;
263  int Rank() const override;
264 
265  bool HasLoops() const;
266  bool HasLockedSegments() const;
267 
268  OPT_BOX2I ChangedArea( const LINE* aOther ) const;
269 
270 private:
271 
272  void dragSegment45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
273  void dragCorner45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
274  void dragSegmentFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
275  void dragCornerFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
276 
278  int aIndex, int aThreshold) const;
279 
280  VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
281  int aIndex, int aThreshold ) const;
282 
284  void copyLinks( const LINE* aParent ) ;
285 
288  SEGMENT_REFS m_segmentRefs;
289 
292 
294  int m_width;
295 
297  bool m_hasVia;
298 
301 };
302 
303 }
304 
305 #endif // __PNS_LINE_H
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:123
Class ITEM.
Definition: pns_item.h:53
void DragCorner(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:436
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:174
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:406
const VIA & Via() const
Definition: pns_line.h:253
Class NODE.
Definition: pns_node.h:137
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:300
const LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:58
int PointCount() const
Function PointCount()
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:833
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:503
int Rank() const override
Definition: pns_line.cpp:759
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:158
void RemoveVia()
Definition: pns_line.h:251
LAYER_RANGE m_layers
Definition: pns_item.h:350
void AppendVia(const VIA &aVia)
Definition: pns_line.cpp:736
void DragSegment(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:448
void dragCornerFree(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:430
SEGMENT * GetLink(int aIndex) const
Definition: pns_line.h:203
bool ContainsSegment(SEGMENT *aSeg) const
Checks if the segment aSeg is a part of the line.
Definition: pns_line.h:197
int Width() const
Returns line width
Definition: pns_line.h:159
void SetWidth(int aWidth)
Sets line width
Definition: pns_line.h:153
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:135
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:291
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assigns a shape to the line (a polyline/line chain)
Definition: pns_line.h:105
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:136
const SHAPE * Shape() const override
Returns the shape of the line
Definition: pns_line.h:111
const SEG CSegment(int aIndex) const
Function CSegment()
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:728
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:129
void ClipVertexRange(int aStart, int aEnd)
Clips the line to a given range of vertices.
Definition: pns_line.cpp:778
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:116
std::vector< SEGMENT * > SEGMENT_REFS
Definition: pns_line.h:63
bool EndsWithVia() const
Definition: pns_line.h:248
bool HasLockedSegments() const
Definition: pns_line.cpp:912
Class SHAPE.
Definition: shape.h:57
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:297
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:461
void SetRank(int aRank) override
Definition: pns_line.cpp:749
virtual void Mark(int aMarker) override
Definition: pns_line.cpp:84
int m_net
Definition: pns_item.h:353
SHAPE_LINE_CHAIN & Line()
Modifiable accessor to the underlying shape
Definition: pns_line.h:117
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:120
void dragSegment45(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:549
Definition: seg.h:36
bool Is45Degree() const
Definition: pns_line.cpp:271
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:147
virtual int Marker() const override
Definition: pns_line.cpp:103
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:181
void ClearSegmentLinks()
Erases the linking information. Used to detach the line from the owning node.
Definition: pns_line.cpp:813
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:288
Class SHAPE_LINE_CHAIN.
bool HasLoops() const
Definition: pns_line.cpp:798
bool IsLinkedChecked() const
Definition: pns_line.h:191
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:297
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:471
void ShowLinks() const
Prints out all linked segments
Definition: pns_line.cpp:323
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:94
bool CompareGeometry(const LINE &aOther)
Returns true if the line is geometrically identical as line aOther
Definition: pns_line.cpp:722
Push and Shove diff pair dimensions (gap) settings dialog.
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void dragSegmentFree(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
int LinkCount() const
Returns the number of segments that were assembled together to form this line.
Definition: pns_line.h:212
virtual LINE * Clone() const override
Function Clone()
Definition: pns_line.cpp:76
virtual void Unmark(int aMarker=-1) override
Definition: pns_line.cpp:94
int SegmentCount() const
Function SegmentCount()
int m_width
our width
Definition: pns_line.h:294
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:141
bool IsLinked() const
Definition: pns_line.h:186