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;
73  }
74 
77 
80 
82  int m_spacing;
83 
85  int m_step;
86 
89 
91  long long int m_targetLength;
92 
95 
98 
101 
104 };
105 
110 {
111 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 uninitialized members, and keep static analyzer quiet:
125  m_type = MT_SINGLE;
126  m_amplitude = 0;
127  m_side = false;
128  m_baseIndex = 0;
129  m_currentTarget = nullptr;
130  m_meanCornerRadius = 0;
131  }
132 
136  void SetType( MEANDER_TYPE aType )
137  {
138  m_type = aType;
139  }
140 
145  {
146  return m_type;
147  }
148 
152  void SetBaseIndex( int aIndex )
153  {
154  m_baseIndex = aIndex;
155  }
156 
160  int BaseIndex() const
161  {
162  return m_baseIndex;
163  }
164 
168  int Amplitude() const
169  {
170  return m_amplitude;
171  }
172 
180  void MakeCorner( VECTOR2I aP1, VECTOR2I aP2 = VECTOR2I( 0, 0 ) );
181 
188  void Resize( int aAmpl );
189 
193  void Recalculate();
194 
198  bool IsDual() const
199  {
200  return m_dual;
201  }
202 
206  bool Side() const
207  {
208  return m_side;
209  }
210 
214  VECTOR2I End() const
215  {
216  return m_clippedBaseSeg.B;
217  }
218 
222  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
223  {
224  return m_shapes[aShape];
225  }
226 
230  void MakeEmpty();
231 
242  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
243 
249  const SEG& BaseSegment() const
250  {
251  return m_clippedBaseSeg;
252  }
253 
257  int BaselineLength() const;
258 
262  int MaxTunableLength() const;
263 
267  const MEANDER_SETTINGS& Settings() const;
268 
272  int Width() const
273  {
274  return m_width;
275  }
276 
283  void SetBaselineOffset( int aOffset )
284  {
285  m_baselineOffset = aOffset;
286  }
287 
288 private:
289  friend class MEANDERED_LINE;
290 
292  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
293 
295  void forward( int aLength );
296 
298  void turn( int aAngle );
299 
301  void miter( int aRadius, bool aSide );
302 
304  void uShape( int aSides, int aCorner, int aTop );
305 
307  SHAPE_LINE_CHAIN makeMiterShape( VECTOR2D aP, VECTOR2D aDir, bool aSide );
308 
310  SHAPE_LINE_CHAIN genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType,
311  int aAmpl, int aBaselineOffset = 0 );
312 
314  void updateBaseSegment();
315 
317  int cornerRadius() const;
318 
320  int spacing() const;
321 
324 
327 
329  bool m_dual;
330 
332  int m_width;
333 
336 
339 
342 
345 
348 
351 
353  bool m_side;
354 
357 
360 
363 
366 
369 };
370 
371 
376 {
377 public:
379  {
380  // Do not leave uninitialized members, and keep static analyzer quiet:
381  m_placer = nullptr;
382  m_dual = false;
383  m_width = 0;
384  m_baselineOffset = 0;
385  }
386 
391  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
392  m_placer( aPlacer ),
393  m_dual( aIsDual )
394  {
395  // Do not leave uninitialized members, and keep static analyzer quiet:
396  m_width = 0;
397  m_baselineOffset = 0;
398  }
399 
401  {
402  Clear();
403  }
404 
412  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
413 
419  void AddMeander( MEANDER_SHAPE* aShape );
420 
424  void Clear();
425 
429  void SetWidth( int aWidth )
430  {
431  m_width = aWidth;
432  }
433 
440  void MeanderSegment( const SEG& aSeg, int aBaseIndex = 0 );
441 
443  void SetBaselineOffset( int aOffset )
444  {
445  m_baselineOffset = aOffset;
446  }
447 
451  std::vector<MEANDER_SHAPE*>& Meanders()
452  {
453  return m_meanders;
454  }
455 
463  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
464 
468  const MEANDER_SETTINGS& Settings() const;
469 
470 private:
472 
474  std::vector<MEANDER_SHAPE*> m_meanders;
475 
476  bool m_dual;
477  int m_width;
479 };
480 
481 }
482 
483 #endif // __PNS_MEANDER_H
bool IsDual() const
Definition: pns_meander.h:198
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:76
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:283
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:353
The geometry of a single meander.
Definition: pns_meander.h:109
VECTOR2I End() const
Definition: pns_meander.h:214
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:473
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:344
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
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:368
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:474
void Clear()
Clear the line geometry, removing all corners and meanders.
int Width() const
Definition: pns_meander.h:272
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:359
MEANDER_TYPE Type() const
Definition: pns_meander.h:144
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:94
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:39
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:429
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:85
int BaseIndex() const
Definition: pns_meander.h:160
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:451
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:323
SHAPE_LINE_CHAIN makeMiterShape(VECTOR2D aP, VECTOR2D aDir, bool aSide)
Produce a meander shape of given type.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:222
int m_cornerRadiusPercentage
Allowable tuning error.
Definition: pns_meander.h:97
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:341
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:249
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:326
int m_width
Amplitude of the meander.
Definition: pns_meander.h:332
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:356
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:88
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:375
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:338
bool Side() const
Definition: pns_meander.h:206
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:335
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:40
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:152
int m_lengthTolerance
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:100
Represent a polyline (an zero-thickness chain of connected line segments).
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:391
int cornerRadius() const
Return sanitized spacing value.
long long int m_targetLength
Type of corners for the meandered line.
Definition: pns_meander.h:91
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:347
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:329
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:82
int spacing() const
The type of meander.
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:118
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:443
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:365
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:136
int Amplitude() const
Definition: pns_meander.h:168
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:350
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:362
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:79
VECTOR2I B
Definition: seg.h:49