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 NODE;
39 class SEGMENT;
40 class VIA;
41 
59 #define PNS_HULL_MARGIN 10
60 
61 class LINE : public ITEM
62 {
63 public:
64  typedef std::vector<SEGMENT*> SEGMENT_REFS;
65 
70  LINE() : ITEM( LINE_T )
71  {
72  m_hasVia = false;
73  m_width = 1; // Dummy value
74  }
75 
76  LINE( const LINE& aOther );
77 
83  LINE( const LINE& aBase, const SHAPE_LINE_CHAIN& aLine ) :
84  ITEM( aBase ),
85  m_line( aLine ),
86  m_width( aBase.m_width )
87  {
88  m_net = aBase.m_net;
89  m_layers = aBase.m_layers;
90  m_hasVia = false;
91  }
92 
98  LINE( const VIA& aVia ) :
99  ITEM( LINE_T )
100  {
101  m_hasVia = true;
102  m_via = aVia;
103  m_width = aVia.Diameter();
104  m_net = aVia.Net();
105  m_layers = aVia.Layers();
106  m_rank = aVia.Rank();
107  }
108 
109  ~LINE();
110 
111  static inline bool ClassOf( const ITEM* aItem )
112  {
113  return aItem && LINE_T == aItem->Kind();
114  }
115 
117  virtual LINE* Clone() const override;
118 
119  LINE& operator=( const LINE& aOther );
120 
122  void SetShape( const SHAPE_LINE_CHAIN& aLine )
123  {
124  m_line = aLine;
126  }
127 
129  const SHAPE* Shape() const override
130  {
131  return &m_line;
132  }
133 
136  {
137  return m_line;
138  }
139 
141  const SHAPE_LINE_CHAIN& CLine() const
142  {
143  return m_line;
144  }
145 
147  int SegmentCount() const
148  {
149  return m_line.SegmentCount();
150  }
151 
153  int PointCount() const
154  {
155  return m_line.PointCount();
156  }
157 
159  const VECTOR2I& CPoint( int aIdx ) const
160  {
161  return m_line.CPoint( aIdx );
162  }
163 
165  const SEG CSegment( int aIdx ) const
166  {
167  return m_line.CSegment( aIdx );
168  }
169 
171  void SetWidth( int aWidth )
172  {
173  m_width = aWidth;
174  m_line.SetWidth( aWidth );
175  }
176 
178  int Width() const
179  {
180  return m_width;
181  }
182 
184  bool CompareGeometry( const LINE& aOther );
185 
187  void Reverse();
188 
189 
190  /* Linking functions */
191 
193  void LinkSegment( SEGMENT* aSeg )
194  {
195  m_segmentRefs.push_back( aSeg );
196  }
197 
201  {
202  return m_segmentRefs;
203  }
204 
205  bool IsLinked() const
206  {
207  return m_segmentRefs.size() != 0;
208  }
209 
210  bool IsLinkedChecked() const
211  {
212  return IsLinked() && LinkCount() == SegmentCount();
213  }
214 
216  bool ContainsSegment( SEGMENT* aSeg ) const
217  {
218  return std::find( m_segmentRefs.begin(), m_segmentRefs.end(),
219  aSeg ) != m_segmentRefs.end();
220  }
221 
222  SEGMENT* GetLink( int aIndex ) const
223  {
224  return m_segmentRefs[aIndex];
225  }
226 
228  void ClearSegmentLinks();
229 
231  int LinkCount() const
232  {
233  return m_segmentRefs.size();
234  }
235 
238  const LINE ClipToNearestObstacle( NODE* aNode ) const;
239 
241  void ClipVertexRange ( int aStart, int aEnd );
242 
244  int CountCorners( int aAngles ) const;
245 
252  bool Walkaround( SHAPE_LINE_CHAIN aObstacle,
253  SHAPE_LINE_CHAIN& aPre,
254  SHAPE_LINE_CHAIN& aWalk,
255  SHAPE_LINE_CHAIN& aPost,
256  bool aCw ) const;
257 
258  bool Walkaround( const SHAPE_LINE_CHAIN& aObstacle,
259  SHAPE_LINE_CHAIN& aPath,
260  bool aCw ) const;
261 
262  bool Is45Degree() const;
263 
265  void ShowLinks() const;
266 
267  bool EndsWithVia() const { return m_hasVia; }
268 
269  void AppendVia( const VIA& aVia );
270  void RemoveVia() { m_hasVia = false; }
271 
272  const VIA& Via() const { return m_via; }
273 
274  virtual void Mark( int aMarker ) override;
275  virtual void Unmark( int aMarker = -1 ) override;
276  virtual int Marker() const override;
277 
278  void DragSegment( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
279  void DragCorner( const VECTOR2I& aP, int aIndex, int aSnappingThreshold = 0, bool aFreeAngle = false );
280 
281  void SetRank( int aRank ) override;
282  int Rank() const override;
283 
284  bool HasLoops() const;
285  bool HasLockedSegments() const;
286 
287  OPT_BOX2I ChangedArea( const LINE* aOther ) const;
288 
289 private:
290 
291  void dragSegment45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
292  void dragCorner45( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
293  void dragSegmentFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
294  void dragCornerFree( const VECTOR2I& aP, int aIndex, int aSnappingThreshold );
295 
297  int aIndex, int aThreshold) const;
298 
299  VECTOR2I snapDraggedCorner( const SHAPE_LINE_CHAIN& aPath, const VECTOR2I &aP,
300  int aIndex, int aThreshold ) const;
301 
303  void copyLinks( const LINE* aParent ) ;
304 
308 
311 
313  int m_width;
314 
316  bool m_hasVia;
317 
320 };
321 
322 }
323 
324 #endif // __PNS_LINE_H
const SHAPE_LINE_CHAIN & CLine() const
Const accessor to the underlying shape
Definition: pns_line.h:141
ITEM.
Definition: pns_item.h:53
void DragCorner(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:477
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:193
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:83
void dragCorner45(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:447
SEGMENT * GetLink(int aIndex) const
Definition: pns_line.h:222
NODE.
Definition: pns_node.h:140
OPT_BOX2I ChangedArea(const LINE *aOther) const
Definition: pns_line.cpp:875
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:160
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:319
LINE & operator=(const LINE &aOther)
Definition: pns_line.cpp:59
int SegmentCount() const
Returns the number of segments in the line
Definition: pns_line.h:147
const SEG CSegment(int aIdx) const
Returns the aIdx-th segment of the line
Definition: pns_line.h:165
bool Is45Degree() const
Definition: pns_line.cpp:303
int Rank() const override
Definition: pns_line.cpp:801
void RemoveVia()
Definition: pns_line.h:270
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:778
void DragSegment(const VECTOR2I &aP, int aIndex, int aSnappingThreshold=0, bool aFreeAngle=false)
Definition: pns_line.cpp:489
void dragCornerFree(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:471
int PointCount() const
Function PointCount()
int PointCount() const
Returns the number of points in the line
Definition: pns_line.h:153
VECTOR2I snapToNeighbourSegments(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:544
bool EndsWithVia() const
Definition: pns_line.h:267
LINE(const VIA &aVia)
Constructor Constructs a LINE for a lone VIA (ie a stitching via).
Definition: pns_line.h:98
void SetWidth(int aWidth)
Sets line width
Definition: pns_line.h:171
const VECTOR2I & CPoint(int aIdx) const
Returns the aIdx-th point of the line
Definition: pns_line.h:159
SHAPE_LINE_CHAIN m_line
The actual shape of the line
Definition: pns_line.h:310
void SetShape(const SHAPE_LINE_CHAIN &aLine)
Assigns a shape to the line (a polyline/line chain)
Definition: pns_line.h:122
bool IsLinkedChecked() const
Definition: pns_line.h:210
const SHAPE * Shape() const override
Returns the shape of the line
Definition: pns_line.h:129
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetWidth(int aWidth)
Sets the width of all segments in the chain.
int Diameter() const
Definition: pns_via.h:121
void Reverse()
Reverses the point/vertex order
Definition: pns_line.cpp:770
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:820
void copyLinks(const LINE *aParent)
Copies m_segmentRefs from the line aParent.
Definition: pns_line.cpp:118
std::vector< SEGMENT * > SEGMENT_REFS
Definition: pns_line.h:64
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:329
SHAPE.
Definition: shape.h:60
bool m_hasVia
If true, the line ends with a via
Definition: pns_line.h:316
void SetRank(int aRank) override
Definition: pns_line.cpp:791
virtual void Mark(int aMarker) override
Definition: pns_line.cpp:86
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:135
void dragSegment45(const VECTOR2I &aP, int aIndex, int aSnappingThreshold)
Definition: pns_line.cpp:590
Definition: seg.h:39
virtual int Rank() const
Definition: pns_item.h:223
virtual int Marker() const override
Definition: pns_line.cpp:105
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:200
void ClearSegmentLinks()
Erases the linking information. Used to detach the line from the owning node.
Definition: pns_line.cpp:855
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:307
const SEG CSegment(int aIndex) const
Function CSegment()
SHAPE_LINE_CHAIN.
bool HasLoops() const
Definition: pns_line.cpp:840
int Width() const
Returns line width
Definition: pns_line.h:178
VECTOR2I snapDraggedCorner(const SHAPE_LINE_CHAIN &aPath, const VECTOR2I &aP, int aIndex, int aThreshold) const
Definition: pns_line.cpp:502
OPT< BOX2I > OPT_BOX2I
Definition: box2.h:524
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:216
bool IsLinked() const
Definition: pns_line.h:205
static bool ClassOf(const ITEM *aItem)
Definition: pns_line.h:111
const VIA & Via() const
Definition: pns_line.h:272
bool CompareGeometry(const LINE &aOther)
Returns true if the line is geometrically identical as line aOther
Definition: pns_line.cpp:764
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:78
virtual void Unmark(int aMarker=-1) override
Definition: pns_line.cpp:96
void ShowLinks() const
Prints out all linked segments
Definition: pns_line.cpp:355
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150
int m_width
our width
Definition: pns_line.h:313
bool HasLockedSegments() const
Definition: pns_line.cpp:956
int CountCorners(int aAngles) const
Returns the number of corners of angles specified by mask aAngles.
Definition: pns_line.cpp:138
int LinkCount() const
Returns the number of segments that were assembled together to form this line.
Definition: pns_line.h:231