KiCad PCB EDA Suite
pns_meander.h
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2015 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_MEANDER_H
23 #define __PNS_MEANDER_H
24 
25 #include <math/vector2d.h>
26 
27 #include <geometry/shape.h>
29 
30 namespace PNS {
31 
32 class MEANDER_PLACER_BASE;
33 
36  MT_SINGLE, // _|^|_, single-sided
37  MT_START, // _|^|
38  MT_FINISH, // |^|_
39  MT_TURN, // |^| or |_|
40  MT_CHECK_START, // try fitting a start type, but don't produce a line
41  MT_CHECK_FINISH, // try fitting a finish type, but don't produce a line
42  MT_CORNER, // line corner
43  MT_EMPTY // no meander (straight line)
44 };
45 
48  MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
49  MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
50 };
51 
58 {
59 public:
60 
62  {
63  m_minAmplitude = 100000;
64  m_maxAmplitude = 1000000;
65  m_step = 50000;
66  m_spacing = 600000;
67  m_targetLength = 100000000;
68  m_targetSkew = 0;
71  m_lengthTolerance = 100000;
73  }
74 
80  int m_spacing;
82  int m_step;
95 };
96 
97 class MEANDERED_LINE;
98 
105 {
106 public:
115  MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
116  m_placer( aPlacer ),
117  m_dual( aIsDual ),
118  m_width( aWidth ),
119  m_baselineOffset( 0 )
120  {
121  // Do not leave unitialized members, and keep static analyser quiet:
122  m_type = MT_SINGLE;
123  m_amplitude = 0;
124  m_side = false;
125  m_baseIndex = 0;
126  m_currentTarget = NULL;
127  m_meanCornerRadius = 0;
128  }
129 
135  void SetType( MEANDER_TYPE aType )
136  {
137  m_type = aType;
138  }
139 
146  {
147  return m_type;
148  }
149 
155  void SetBaseIndex( int aIndex )
156  {
157  m_baseIndex = aIndex;
158  }
159 
165  int BaseIndex() const
166  {
167  return m_baseIndex;
168  }
169 
175  int Amplitude() const
176  {
177  return m_amplitude;
178  }
179 
188  void MakeCorner( VECTOR2I aP1, VECTOR2I aP2 = VECTOR2I( 0, 0 ) );
189 
197  void Resize( int aAmpl );
198 
204  void Recalculate();
205 
211  bool IsDual() const
212  {
213  return m_dual;
214  }
215 
221  bool Side() const
222  {
223  return m_side;
224  }
225 
231  VECTOR2I End() const
232  {
233  return m_clippedBaseSeg.B;
234  }
235 
241  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
242  {
243  return m_shapes[aShape];
244  }
245 
252  void MakeEmpty();
253 
265  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
266 
273  const SEG& BaseSegment() const
274  {
275  return m_clippedBaseSeg;
276  }
277 
284  int BaselineLength() const;
285 
291  int MaxTunableLength() const;
292 
298  const MEANDER_SETTINGS& Settings() const;
299 
305  int Width() const
306  {
307  return m_width;
308  }
309 
317  void SetBaselineOffset( int aOffset )
318  {
319  m_baselineOffset = aOffset;
320  }
321 
322 private:
323  friend class MEANDERED_LINE;
324 
326  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
328  void forward( int aLength );
330  void turn( int aAngle );
332  void miter( int aRadius, bool aSide );
334  void uShape( int aSides, int aCorner, int aTop );
335 
337  SHAPE_LINE_CHAIN makeMiterShape( VECTOR2D aP, VECTOR2D aDir, bool aSide );
338 
340  VECTOR2I reflect( VECTOR2I aP, const SEG& aLine );
341 
343  SHAPE_LINE_CHAIN genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset = 0 );
344 
347  void updateBaseSegment();
348 
350  int cornerRadius() const;
351 
353  int spacing() const;
354 
360  bool m_dual;
362  int m_width;
376  bool m_side;
387 };
388 
389 
396 {
397 public:
399  {
400  // Do not leave unitialized members, and keep static analyser quiet:
401  m_placer = NULL;
402  m_dual = false;
403  m_width = 0;
404  m_baselineOffset = 0;
405  }
406 
413  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
414  m_placer( aPlacer ),
415  m_dual( aIsDual )
416  {
417  // Do not leave unitialized members, and keep static analyser quiet:
418  m_width = 0;
419  m_baselineOffset = 0;
420  }
421 
423  {
424  Clear();
425  }
426 
435  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
436 
443  void AddMeander( MEANDER_SHAPE* aShape );
444 
450  void Clear();
451 
457  void SetWidth( int aWidth )
458  {
459  m_width = aWidth;
460  }
461 
470  void MeanderSegment( const SEG& aSeg, int aBaseIndex = 0 );
471 
473  void SetBaselineOffset( int aOffset )
474  {
475  m_baselineOffset = aOffset;
476  }
477 
483  std::vector<MEANDER_SHAPE*>& Meanders()
484  {
485  return m_meanders;
486  }
487 
497  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
498 
504  const MEANDER_SETTINGS& Settings() const;
505 
506 private:
508 
510  std::vector<MEANDER_SHAPE*> m_meanders;
511 
512  bool m_dual;
513  int m_width;
515 };
516 
517 }
518 
519 #endif // __PNS_MEANDER_H
int spacing() const
returns sanitized spacing value
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
produces a meander shape of given type
Class MEANDER_PLACER_BASE.
int m_minAmplitude
minimum meandering amplitude
Definition: pns_meander.h:76
bool IsDual() const
Function IsDual()
Definition: pns_meander.h:211
void uShape(int aSides, int aCorner, int aTop)
tells the turtle to draw an U-like shape
void SetBaselineOffset(int aOffset)
Function SetBaselineOffset()
Definition: pns_meander.h:317
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Function CheckSelfIntersections()
bool m_side
side (true = right)
Definition: pns_meander.h:376
Class MEANDER_SETTINGS.
Definition: pns_meander.h:104
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:509
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:35
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:370
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Function AddCorner()
void MeanderSegment(const SEG &aSeg, int aBaseIndex=0)
Function MeanderSegment()
Definition: pns_meander.cpp:46
const SEG & BaseSegment() const
Function BaseSegment()
Definition: pns_meander.h:273
int m_targetSkew
target skew value for diff pair de-skewing
Definition: pns_meander.h:94
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:386
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:510
void Clear()
Function Clear()
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:380
Class MEANDER_SETTINGS.
Definition: pns_meander.h:57
VECTOR2I End() const
Function End()
Definition: pns_meander.h:231
void Recalculate()
Function Recalculate()
int BaselineLength() const
Function BaselineLength()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
MEANDER_STYLE m_cornerStyle
type of corners for the meandered line
Definition: pns_meander.h:86
bool Side() const
Function Side()
Definition: pns_meander.h:221
void SetWidth(int aWidth)
Function SetWidth()
Definition: pns_meander.h:457
void Resize(int aAmpl)
Function Resize()
void miter(int aRadius, bool aSide)
tells the turtle to draw a mitered corner of given radius and turn direction
void MakeCorner(VECTOR2I aP1, VECTOR2I aP2=VECTOR2I(0, 0))
Function MakeCorner()
int m_step
amplitude/spacing adjustment step
Definition: pns_meander.h:82
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
starts turtle drawing
std::vector< MEANDER_SHAPE * > & Meanders()
Function Meanders()
Definition: pns_meander.h:483
MEANDER_TYPE Type() const
Function Type()
Definition: pns_meander.h:145
void AddMeander(MEANDER_SHAPE *aShape)
Function AddMeander()
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:356
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
generates a 90-degree circular arc
int m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:88
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:368
void turn(int aAngle)
turns the turtle by aAngle
int cornerRadius() const
returns sanitized corner radius value
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:358
int m_width
width of the line
Definition: pns_meander.h:362
MEANDER_STYLE
meander corner shape
Definition: pns_meander.h:47
SHAPE_LINE_CHAIN m_shapes[2]
the actual shapes (0 used for single, both for dual)
Definition: pns_meander.h:378
void forward(int aLength)
moves turtle forward by aLength
Class MEANDERED_LINE.
Definition: pns_meander.h:395
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:366
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:364
bool Fit(MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
Function Fit()
Definition: seg.h:37
int m_cornerArcSegments
number of line segments for arc approximation
Definition: pns_meander.h:92
void MakeEmpty()
Function MakeEmpty()
void SetBaseIndex(int aIndex)
Function SetBaseIndex()
Definition: pns_meander.h:155
int m_lengthTolerance
allowable tuning error
Definition: pns_meander.h:90
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:40
Class SHAPE_LINE_CHAIN.
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:413
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:372
VECTOR2I reflect(VECTOR2I aP, const SEG &aLine)
reflects a point onto other side of a given segment
void updateBaseSegment()
recalculates the clipped baseline after the parameters of the meander have been changed.
int m_targetLength
desired length of the tuned line/diff pair
Definition: pns_meander.h:84
bool m_dual
dual or single line
Definition: pns_meander.h:360
int m_spacing
meandering period/spacing (see dialog picture for explanation)
Definition: pns_meander.h:80
int Width() const
Function Width()
Definition: pns_meander.h:305
int Amplitude() const
Function Amplitude()
Definition: pns_meander.h:175
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:115
Push and Shove diff pair dimensions (gap) settings dialog.
int BaseIndex() const
Function BaseIndex()
Definition: pns_meander.h:165
void SetBaselineOffset(int aOffset)
Function SetBaselineOffset()
Definition: pns_meander.h:473
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:384
void SetType(MEANDER_TYPE aType)
Function SetType()
Definition: pns_meander.h:135
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:374
int MaxTunableLength() const
Function MaxTunableLength()
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:382
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:241
int m_maxAmplitude
maximum meandering amplitude
Definition: pns_meander.h:78
VECTOR2I B
Definition: seg.h:48