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_lenPadToDie = 0;
67  m_spacing = 600000;
68  m_targetLength = 100000000;
69  m_targetSkew = 0;
72  m_lengthTolerance = 100000;
74  }
75 
81  int m_spacing;
83  int m_step;
87  long long int m_targetLength;
98 };
99 
100 class MEANDERED_LINE;
101 
108 {
109 public:
118  MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
119  m_placer( aPlacer ),
120  m_dual( aIsDual ),
121  m_width( aWidth ),
122  m_baselineOffset( 0 )
123  {
124  // Do not leave unitialized members, and keep static analyser quiet:
125  m_type = MT_SINGLE;
126  m_amplitude = 0;
127  m_side = false;
128  m_baseIndex = 0;
129  m_currentTarget = NULL;
130  m_meanCornerRadius = 0;
131  }
132 
138  void SetType( MEANDER_TYPE aType )
139  {
140  m_type = aType;
141  }
142 
149  {
150  return m_type;
151  }
152 
158  void SetBaseIndex( int aIndex )
159  {
160  m_baseIndex = aIndex;
161  }
162 
168  int BaseIndex() const
169  {
170  return m_baseIndex;
171  }
172 
178  int Amplitude() const
179  {
180  return m_amplitude;
181  }
182 
191  void MakeCorner( VECTOR2I aP1, VECTOR2I aP2 = VECTOR2I( 0, 0 ) );
192 
200  void Resize( int aAmpl );
201 
207  void Recalculate();
208 
214  bool IsDual() const
215  {
216  return m_dual;
217  }
218 
224  bool Side() const
225  {
226  return m_side;
227  }
228 
234  VECTOR2I End() const
235  {
236  return m_clippedBaseSeg.B;
237  }
238 
244  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
245  {
246  return m_shapes[aShape];
247  }
248 
255  void MakeEmpty();
256 
268  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
269 
276  const SEG& BaseSegment() const
277  {
278  return m_clippedBaseSeg;
279  }
280 
287  int BaselineLength() const;
288 
294  int MaxTunableLength() const;
295 
301  const MEANDER_SETTINGS& Settings() const;
302 
308  int Width() const
309  {
310  return m_width;
311  }
312 
320  void SetBaselineOffset( int aOffset )
321  {
322  m_baselineOffset = aOffset;
323  }
324 
325 private:
326  friend class MEANDERED_LINE;
327 
329  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
331  void forward( int aLength );
333  void turn( int aAngle );
335  void miter( int aRadius, bool aSide );
337  void uShape( int aSides, int aCorner, int aTop );
338 
340  SHAPE_LINE_CHAIN makeMiterShape( VECTOR2D aP, VECTOR2D aDir, bool aSide );
341 
343  VECTOR2I reflect( VECTOR2I aP, const SEG& aLine );
344 
346  SHAPE_LINE_CHAIN genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset = 0 );
347 
350  void updateBaseSegment();
351 
353  int cornerRadius() const;
354 
356  int spacing() const;
357 
363  bool m_dual;
365  int m_width;
379  bool m_side;
390 };
391 
392 
399 {
400 public:
402  {
403  // Do not leave unitialized members, and keep static analyser quiet:
404  m_placer = NULL;
405  m_dual = false;
406  m_width = 0;
407  m_baselineOffset = 0;
408  }
409 
416  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
417  m_placer( aPlacer ),
418  m_dual( aIsDual )
419  {
420  // Do not leave unitialized members, and keep static analyser quiet:
421  m_width = 0;
422  m_baselineOffset = 0;
423  }
424 
426  {
427  Clear();
428  }
429 
438  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
439 
446  void AddMeander( MEANDER_SHAPE* aShape );
447 
453  void Clear();
454 
460  void SetWidth( int aWidth )
461  {
462  m_width = aWidth;
463  }
464 
473  void MeanderSegment( const SEG& aSeg, int aBaseIndex = 0 );
474 
476  void SetBaselineOffset( int aOffset )
477  {
478  m_baselineOffset = aOffset;
479  }
480 
486  std::vector<MEANDER_SHAPE*>& Meanders()
487  {
488  return m_meanders;
489  }
490 
500  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
501 
507  const MEANDER_SETTINGS& Settings() const;
508 
509 private:
511 
513  std::vector<MEANDER_SHAPE*> m_meanders;
514 
515  bool m_dual;
516  int m_width;
518 };
519 
520 }
521 
522 #endif // __PNS_MEANDER_H
bool IsDual() const
Function IsDual()
Definition: pns_meander.h:214
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:77
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:320
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Function CheckSelfIntersections()
int BaselineLength() const
Function BaselineLength()
bool m_side
side (true = right)
Definition: pns_meander.h:379
Class MEANDER_SETTINGS.
Definition: pns_meander.h:107
VECTOR2I End() const
Function End()
Definition: pns_meander.h:234
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:512
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:35
VECTOR2I m_p0
first point of the meandered line
Definition: pns_meander.h:373
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Function AddCorner()
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
void MeanderSegment(const SEG &aSeg, int aBaseIndex=0)
Function MeanderSegment()
Definition: pns_meander.cpp:46
int m_targetSkew
target skew value for diff pair de-skewing
Definition: pns_meander.h:97
SHAPE_LINE_CHAIN * m_currentTarget
the line the turtle is drawing on
Definition: pns_meander.h:389
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:513
void Clear()
Function Clear()
int Width() const
Function Width()
Definition: pns_meander.h:308
int m_baseIndex
index of the meandered segment in the base line
Definition: pns_meander.h:383
MEANDER_TYPE Type() const
Function Type()
Definition: pns_meander.h:148
Class MEANDER_SETTINGS.
Definition: pns_meander.h:57
void Recalculate()
Function Recalculate()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
MEANDER_STYLE m_cornerStyle
type of corners for the meandered line
Definition: pns_meander.h:89
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:40
void SetWidth(int aWidth)
Function SetWidth()
Definition: pns_meander.h:460
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:83
int BaseIndex() const
Function BaseIndex()
Definition: pns_meander.h:168
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:486
void AddMeander(MEANDER_SHAPE *aShape)
Function AddMeander()
MEANDER_TYPE m_type
the type
Definition: pns_meander.h:359
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
generates a 90-degree circular arc
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:244
int m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:91
int m_meanCornerRadius
average radius of meander corners (for correction of DP meanders)
Definition: pns_meander.h:371
const SEG & BaseSegment() const
Function BaseSegment()
Definition: pns_meander.h:276
void turn(int aAngle)
turns the turtle by aAngle
MEANDER_PLACER_BASE * m_placer
the placer that placed this meander
Definition: pns_meander.h:361
int m_width
width of the line
Definition: pns_meander.h:365
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:381
int MaxTunableLength() const
Function MaxTunableLength()
int m_lenPadToDie
length PadToDie
Definition: pns_meander.h:85
void forward(int aLength)
moves turtle forward by aLength
Class MEANDERED_LINE.
Definition: pns_meander.h:398
int m_baselineOffset
offset wrs the base segment (dual only)
Definition: pns_meander.h:369
bool Side() const
Function Side()
Definition: pns_meander.h:224
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
int m_amplitude
amplitude of the meander
Definition: pns_meander.h:367
bool Fit(MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
Function Fit()
Definition: seg.h:36
int m_cornerArcSegments
number of line segments for arc approximation
Definition: pns_meander.h:95
void MakeEmpty()
Function MakeEmpty()
void SetBaseIndex(int aIndex)
Function SetBaseIndex()
Definition: pns_meander.h:158
int m_lengthTolerance
allowable tuning error
Definition: pns_meander.h:93
Class SHAPE_LINE_CHAIN.
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:416
int cornerRadius() const
returns sanitized corner radius value
long long int m_targetLength
desired length of the tuned line/diff pair (this is in nm, so allow more than board width)
Definition: pns_meander.h:87
SEG m_baseSeg
base segment (unclipped)
Definition: pns_meander.h:375
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.
bool m_dual
dual or single line
Definition: pns_meander.h:363
int m_spacing
meandering period/spacing (see dialog picture for explanation)
Definition: pns_meander.h:81
int spacing() const
returns sanitized spacing value
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:118
Push and Shove diff pair dimensions (gap) settings dialog.
void SetBaselineOffset(int aOffset)
Function SetBaselineOffset()
Definition: pns_meander.h:476
VECTOR2D m_currentPos
current turtle position
Definition: pns_meander.h:387
void SetType(MEANDER_TYPE aType)
Function SetType()
Definition: pns_meander.h:138
int Amplitude() const
Function Amplitude()
Definition: pns_meander.h:178
SEG m_clippedBaseSeg
base segment (clipped)
Definition: pns_meander.h:377
VECTOR2D m_currentDir
current turtle direction
Definition: pns_meander.h:385
int m_maxAmplitude
maximum meandering amplitude
Definition: pns_meander.h:79
VECTOR2I B
Definition: seg.h:45