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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  *
9  * This program is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation, either version 3 of the License, or (at your
12  * option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef __PNS_MEANDER_H
24 #define __PNS_MEANDER_H
25 
26 #include <math/vector2d.h>
27 
28 #include <geometry/shape.h>
30 
31 namespace PNS {
32 
33 class MEANDER_PLACER_BASE;
34 class MEANDERED_LINE;
35 
38  MT_SINGLE, // _|^|_, single-sided
39  MT_START, // _|^|
40  MT_FINISH, // |^|_
41  MT_TURN, // |^| or |_|
42  MT_CHECK_START, // try fitting a start type, but don't produce a line
43  MT_CHECK_FINISH, // try fitting a finish type, but don't produce a line
44  MT_CORNER, // line corner
45  MT_EMPTY // no meander (straight line)
46 };
47 
50  MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
51  MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
52 };
53 
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 
104 {
105 public:
112  MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
113  m_placer( aPlacer ),
114  m_dual( aIsDual ),
115  m_width( aWidth ),
116  m_baselineOffset( 0 )
117  {
118  // Do not leave uninitialized members, and keep static analyzer quiet:
119  m_type = MT_SINGLE;
120  m_amplitude = 0;
121  m_side = false;
122  m_baseIndex = 0;
124  m_meanCornerRadius = 0;
125  }
126 
130  void SetType( MEANDER_TYPE aType )
131  {
132  m_type = aType;
133  }
134 
139  {
140  return m_type;
141  }
142 
146  void SetBaseIndex( int aIndex )
147  {
148  m_baseIndex = aIndex;
149  }
150 
154  int BaseIndex() const
155  {
156  return m_baseIndex;
157  }
158 
162  int Amplitude() const
163  {
164  return m_amplitude;
165  }
166 
174  void MakeCorner( VECTOR2I aP1, VECTOR2I aP2 = VECTOR2I( 0, 0 ) );
175 
182  void Resize( int aAmpl );
183 
187  void Recalculate();
188 
192  bool IsDual() const
193  {
194  return m_dual;
195  }
196 
200  bool Side() const
201  {
202  return m_side;
203  }
204 
208  VECTOR2I End() const
209  {
210  return m_clippedBaseSeg.B;
211  }
212 
216  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
217  {
218  return m_shapes[aShape];
219  }
220 
224  void MakeEmpty();
225 
236  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
237 
243  const SEG& BaseSegment() const
244  {
245  return m_clippedBaseSeg;
246  }
247 
251  int BaselineLength() const;
252 
256  int MaxTunableLength() const;
257 
261  const MEANDER_SETTINGS& Settings() const;
262 
266  int Width() const
267  {
268  return m_width;
269  }
270 
277  void SetBaselineOffset( int aOffset )
278  {
279  m_baselineOffset = aOffset;
280  }
281 
282 private:
283  friend class MEANDERED_LINE;
284 
286  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
287 
289  void forward( int aLength );
290 
292  void turn( int aAngle );
293 
295  void miter( int aRadius, bool aSide );
296 
298  void uShape( int aSides, int aCorner, int aTop );
299 
301  SHAPE_LINE_CHAIN makeMiterShape( VECTOR2D aP, VECTOR2D aDir, bool aSide );
302 
304  VECTOR2I reflect( VECTOR2I aP, const SEG& aLine );
305 
307  SHAPE_LINE_CHAIN genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType,
308  int aAmpl, int aBaselineOffset = 0 );
309 
311  void updateBaseSegment();
312 
314  int cornerRadius() const;
315 
317  int spacing() const;
318 
321 
324 
326  bool m_dual;
327 
329  int m_width;
330 
333 
336 
339 
342 
345 
348 
350  bool m_side;
351 
354 
357 
360 
363 
366 };
367 
368 
373 {
374 public:
376  {
377  // Do not leave uninitialized members, and keep static analyzer quiet:
378  m_placer = NULL;
379  m_dual = false;
380  m_width = 0;
381  m_baselineOffset = 0;
382  }
383 
388  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
389  m_placer( aPlacer ),
390  m_dual( aIsDual )
391  {
392  // Do not leave uninitialized members, and keep static analyzer quiet:
393  m_width = 0;
394  m_baselineOffset = 0;
395  }
396 
398  {
399  Clear();
400  }
401 
409  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
410 
416  void AddMeander( MEANDER_SHAPE* aShape );
417 
421  void Clear();
422 
426  void SetWidth( int aWidth )
427  {
428  m_width = aWidth;
429  }
430 
437  void MeanderSegment( const SEG& aSeg, int aBaseIndex = 0 );
438 
440  void SetBaselineOffset( int aOffset )
441  {
442  m_baselineOffset = aOffset;
443  }
444 
448  std::vector<MEANDER_SHAPE*>& Meanders()
449  {
450  return m_meanders;
451  }
452 
460  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
461 
465  const MEANDER_SETTINGS& Settings() const;
466 
467 private:
469 
471  std::vector<MEANDER_SHAPE*> m_meanders;
472 
473  bool m_dual;
474  int m_width;
476 };
477 
478 }
479 
480 #endif // __PNS_MEANDER_H
bool IsDual() const
Definition: pns_meander.h:192
SHAPE_LINE_CHAIN genMeanderShape(VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
Base class for Single trace & Differential pair meandering tools, as both of them share a lot of code...
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:77
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:277
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Check if the given shape is intersecting with any other meander in the current line.
int BaselineLength() const
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:350
The geometry of a single meander.
Definition: pns_meander.h:103
VECTOR2I End() const
Definition: pns_meander.h:208
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:470
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:341
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Define a general 2D-vector/point.
Definition: vector2d.h:61
void MeanderSegment(const SEG &aSeg, int aBaseIndex=0)
Fit maximum amplitude meanders on a given segment and adds to the current line.
Definition: pns_meander.cpp:45
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:365
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:471
void Clear()
Clear the line geometry, removing all corners and meanders.
int Width() const
Definition: pns_meander.h:266
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:356
MEANDER_TYPE Type() const
Definition: pns_meander.h:138
Dimensions for the meandering algorithm.
Definition: pns_meander.h:57
void Recalculate()
Recalculate the line chain representing the meander's shape.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:89
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:39
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:426
void Resize(int aAmpl)
Change the amplitude of the meander shape to aAmpl and recalculates the resulting line chain.
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
void MakeCorner(VECTOR2I aP1, VECTOR2I aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
int m_step
Length PadToDie.
Definition: pns_meander.h:83
int BaseIndex() const
Definition: pns_meander.h:154
#define NULL
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
std::vector< MEANDER_SHAPE * > & Meanders()
Definition: pns_meander.h:448
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape the the meandered line.
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:320
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
Reflect a point onto other side of a given segment.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:216
int m_cornerRadiusPercentage
Allowable tuning error.
Definition: pns_meander.h:91
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:338
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:243
void turn(int aAngle)
Tell the turtle to draw a mitered corner of given radius and turn direction.
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:323
int m_width
Amplitude of the meander.
Definition: pns_meander.h:329
MEANDER_STYLE
Definition: pns_meander.h:49
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:353
int MaxTunableLength() const
int m_lenPadToDie
Desired length of the tuned line/diff pair (this is in nm, so allow more than board width).
Definition: pns_meander.h:85
void forward(int aLength)
Turn the turtle by aAngle.
Represent a set of meanders fitted over a single or two lines.
Definition: pns_meander.h:372
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:335
bool Side() const
Definition: pns_meander.h:200
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:332
bool Fit(MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
Attempt to fit a meander of a given type onto a segment, avoiding collisions with other board feature...
Definition: seg.h:41
int m_cornerArcSegments
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:95
void MakeEmpty()
Replace the meander with straight bypass line(s), effectively clearing it.
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
Definition: pns_meander.h:146
int m_lengthTolerance
Number of line segments for arc approximation.
Definition: pns_meander.h:93
SHAPE_LINE_CHAIN.
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:388
int cornerRadius() const
Return sanitized spacing value.
long long int m_targetLength
Type of corners for the meandered line.
Definition: pns_meander.h:87
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:344
VECTOR2I reflect(VECTOR2I aP, const SEG &aLine)
Produce a meander shape of given type.
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:326
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:81
int spacing() const
The type of meander.
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:112
Push and Shove diff pair dimensions (gap) settings dialog.
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:440
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:362
MEANDER_SETTINGS()
Minimum meandering amplitude.
Definition: pns_meander.h:61
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:130
int Amplitude() const
Definition: pns_meander.h:162
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:347
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:359
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:79
VECTOR2I B
Definition: seg.h:50