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 <[email protected]>
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_ARC, // arc corner
46  MT_EMPTY // no meander (straight line)
47 };
48 
51  MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
52  MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
53 };
54 
59 {
60 public:
61 
63  {
64  m_minAmplitude = 100000;
65  m_maxAmplitude = 1000000;
66  m_step = 50000;
67  m_lenPadToDie = 0;
68  m_spacing = 600000;
69  m_targetLength = 100000000;
70  m_targetSkew = 0;
73  m_lengthTolerance = 100000;
74  }
75 
78 
81 
83  int m_spacing;
84 
86  int m_step;
87 
90 
92  long long int m_targetLength;
93 
96 
99 
102 
105 };
106 
111 {
112 public:
119  MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
120  m_placer( aPlacer ),
121  m_dual( aIsDual ),
122  m_width( aWidth ),
123  m_baselineOffset( 0 )
124  {
125  // Do not leave uninitialized members, and keep static analyzer quiet:
126  m_type = MT_SINGLE;
127  m_amplitude = 0;
128  m_side = false;
129  m_baseIndex = 0;
130  m_currentTarget = nullptr;
131  m_meanCornerRadius = 0;
132  }
133 
137  void SetType( MEANDER_TYPE aType )
138  {
139  m_type = aType;
140  }
141 
146  {
147  return m_type;
148  }
149 
153  void SetBaseIndex( int aIndex )
154  {
155  m_baseIndex = aIndex;
156  }
157 
161  int BaseIndex() const
162  {
163  return m_baseIndex;
164  }
165 
169  int Amplitude() const
170  {
171  return m_amplitude;
172  }
173 
181  void MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 = VECTOR2I( 0, 0 ) );
182 
190  void MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
191 
198  void Resize( int aAmpl );
199 
203  void Recalculate();
204 
208  bool IsDual() const
209  {
210  return m_dual;
211  }
212 
216  bool Side() const
217  {
218  return m_side;
219  }
220 
224  VECTOR2I End() const
225  {
226  return m_clippedBaseSeg.B;
227  }
228 
232  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
233  {
234  return m_shapes[aShape];
235  }
236 
240  void MakeEmpty();
241 
252  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
253 
259  const SEG& BaseSegment() const
260  {
261  return m_clippedBaseSeg;
262  }
263 
267  int BaselineLength() const;
268 
272  int MaxTunableLength() const;
273 
277  const MEANDER_SETTINGS& Settings() const;
278 
282  int Width() const
283  {
284  return m_width;
285  }
286 
293  void SetBaselineOffset( int aOffset )
294  {
295  m_baselineOffset = aOffset;
296  }
297 
298 private:
299  friend class MEANDERED_LINE;
300 
302  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
303 
305  void forward( int aLength );
306 
308  void turn( int aAngle );
309 
311  void miter( int aRadius, bool aSide );
312 
314  void uShape( int aSides, int aCorner, int aTop );
315 
317  SHAPE_LINE_CHAIN makeMiterShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide );
318 
320  SHAPE_LINE_CHAIN genMeanderShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide,
321  MEANDER_TYPE aType, int aAmpl, int aBaselineOffset = 0 );
322 
324  void updateBaseSegment();
325 
327  int cornerRadius() const;
328 
330  int spacing() const;
331 
334 
337 
339  bool m_dual;
340 
342  int m_width;
343 
346 
349 
352 
355 
358 
361 
363  bool m_side;
364 
367 
370 
373 
376 
379 };
380 
381 
386 {
387 public:
389  {
390  // Do not leave uninitialized members, and keep static analyzer quiet:
391  m_placer = nullptr;
392  m_dual = false;
393  m_width = 0;
394  m_baselineOffset = 0;
395  }
396 
401  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
402  m_placer( aPlacer ),
403  m_dual( aIsDual )
404  {
405  // Do not leave uninitialized members, and keep static analyzer quiet:
406  m_width = 0;
407  m_baselineOffset = 0;
408  }
409 
411  {
412  Clear();
413  }
414 
422  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
423 
431  void AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
432 
440  void AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 );
441 
449  void AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 );
450 
456  void AddMeander( MEANDER_SHAPE* aShape );
457 
461  void Clear();
462 
466  void SetWidth( int aWidth )
467  {
468  m_width = aWidth;
469  }
470 
478  void MeanderSegment( const SEG& aSeg, bool aSide, int aBaseIndex = 0 );
479 
481  void SetBaselineOffset( int aOffset )
482  {
483  m_baselineOffset = aOffset;
484  }
485 
489  std::vector<MEANDER_SHAPE*>& Meanders()
490  {
491  return m_meanders;
492  }
493 
501  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
502 
506  const MEANDER_SETTINGS& Settings() const;
507 
508 private:
510 
512  std::vector<MEANDER_SHAPE*> m_meanders;
513 
514  bool m_dual;
515  int m_width;
517 };
518 
519 }
520 
521 #endif // __PNS_MEANDER_H
bool IsDual() const
Definition: pns_meander.h:208
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:293
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:363
The geometry of a single meander.
Definition: pns_meander.h:110
SHAPE_LINE_CHAIN makeMiterShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
Produce a meander shape of given type.
VECTOR2I End() const
Definition: pns_meander.h:224
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:511
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:354
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
void MakeArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
void AddPtAndArc(const VECTOR2I &aPt1, const SHAPE_ARC &aArc2)
Create a dummy meander shape representing an arc corner.
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:378
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:512
void Clear()
Clear the line geometry, removing all corners and meanders.
int Width() const
Definition: pns_meander.h:282
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:369
MEANDER_TYPE Type() const
Definition: pns_meander.h:145
Dimensions for the meandering algorithm.
Definition: pns_meander.h:58
SHAPE_LINE_CHAIN genMeanderShape(const VECTOR2D &aP, const 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.
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:95
void AddArcAndPt(const SHAPE_ARC &aArc1, const VECTOR2I &aPt2)
Create a dummy meander shape representing an arc corner.
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:39
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:466
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.
int m_step
Length PadToDie.
Definition: pns_meander.h:86
int BaseIndex() const
Definition: pns_meander.h:161
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
void AddArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
std::vector< MEANDER_SHAPE * > & Meanders()
Definition: pns_meander.h:489
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:333
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:232
int m_cornerRadiusPercentage
Allowable tuning error.
Definition: pns_meander.h:98
int m_meanCornerRadius
First point of the meandered line.
Definition: pns_meander.h:351
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:259
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:336
void MakeCorner(const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
int m_width
Amplitude of the meander.
Definition: pns_meander.h:342
MEANDER_STYLE
Definition: pns_meander.h:50
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:366
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:89
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:385
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:348
bool Side() const
Definition: pns_meander.h:216
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:345
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 MeanderSegment(const SEG &aSeg, bool aSide, int aBaseIndex=0)
Fit maximum amplitude meanders on a given segment and adds to the current line.
Definition: pns_meander.cpp:45
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
Definition: pns_meander.h:153
int m_lengthTolerance
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:101
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:401
int cornerRadius() const
Return sanitized spacing value.
long long int m_targetLength
Type of corners for the meandered line.
Definition: pns_meander.h:92
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:357
void updateBaseSegment()
Return sanitized corner radius value.
bool m_dual
Width of the line.
Definition: pns_meander.h:339
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:83
int spacing() const
The type of meander.
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:119
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:481
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:375
MEANDER_SETTINGS()
Minimum meandering amplitude.
Definition: pns_meander.h:62
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:137
int Amplitude() const
Definition: pns_meander.h:169
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:360
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:372
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:80
VECTOR2I B
Definition: seg.h:49