Horizon
pns_meander.h
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>
29 #include <geometry/shape_line_chain.h>
30 
31 namespace PNS {
32 
33 class MEANDER_PLACER_BASE;
34 class MEANDERED_LINE;
35 
37 enum MEANDER_TYPE {
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 
50 enum MEANDER_STYLE {
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;
71  m_cornerStyle = MEANDER_STYLE_ROUND;
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 
95  MEANDER_STYLE m_cornerStyle;
96 
99 
102 
104  int m_targetSkew;
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 
145  MEANDER_TYPE Type() const
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 
333  MEANDER_TYPE m_type;
334 
336  MEANDER_PLACER_BASE* m_placer;
337 
339  bool m_dual;
340 
342  int m_width;
343 
345  int m_amplitude;
346 
348  int m_baselineOffset;
349 
351  int m_meanCornerRadius;
352 
354  VECTOR2I m_p0;
355 
357  SEG m_baseSeg;
358 
360  SEG m_clippedBaseSeg;
361 
363  bool m_side;
364 
366  SHAPE_LINE_CHAIN m_shapes[2];
367 
369  int m_baseIndex;
370 
372  VECTOR2D m_currentDir;
373 
375  VECTOR2D m_currentPos;
376 
378  SHAPE_LINE_CHAIN* m_currentTarget;
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 
410  ~MEANDERED_LINE()
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:
509  VECTOR2I m_last;
510 
511  MEANDER_PLACER_BASE* m_placer;
512  std::vector<MEANDER_SHAPE*> m_meanders;
513 
514  bool m_dual;
515  int m_width;
516  int m_baselineOffset;
517 };
518 
519 }
520 
521 #endif // __PNS_MEANDER_H
Represent a set of meanders fitted over a single or two lines.
Definition: pns_meander.h:386
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
Definition: pns_meander.cpp:628
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:481
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:466
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Definition: pns_meander.cpp:566
void Clear()
Clear the line geometry, removing all corners and meanders.
Definition: pns_meander.cpp:635
std::vector< MEANDER_SHAPE * > & Meanders()
Definition: pns_meander.h:489
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 AddArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
Definition: pns_meander.cpp:577
void AddArcAndPt(const SHAPE_ARC &aArc1, const VECTOR2I &aPt2)
Create a dummy meander shape representing an arc corner.
Definition: pns_meander.cpp:588
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Check if the given shape is intersecting with any other meander in the current line.
Definition: pns_meander.cpp:404
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:39
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:401
void AddPtAndArc(const VECTOR2I &aPt1, const SHAPE_ARC &aArc2)
Create a dummy meander shape representing an arc corner.
Definition: pns_meander.cpp:596
Base class for Single trace & Differential pair meandering tools, as both of them share a lot of code...
Definition: pns_meander_placer_base.h:47
Dimensions for the meandering algorithm.
Definition: pns_meander.h:59
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:77
MEANDER_SETTINGS()
Minimum meandering amplitude.
Definition: pns_meander.h:62
int m_cornerRadiusPercentage
Allowable tuning error.
Definition: pns_meander.h:98
long long int m_targetLength
Type of corners for the meandered line.
Definition: pns_meander.h:92
int m_lengthTolerance
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:101
int m_step
Length PadToDie.
Definition: pns_meander.h:86
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:95
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:80
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
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:83
The geometry of a single meander.
Definition: pns_meander.h:111
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:119
int Amplitude() const
Definition: pns_meander.h:169
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:137
VECTOR2I End() const
Definition: pns_meander.h:224
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:259
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
Definition: pns_meander.h:153
int BaseIndex() const
Definition: pns_meander.h:161
bool Side() const
Definition: pns_meander.h:216
void MakeArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
Definition: pns_meander.cpp:616
void Recalculate()
Recalculate the line chain representing the meander's shape.
Definition: pns_meander.cpp:527
void Resize(int aAmpl)
Change the amplitude of the meander shape to aAmpl and recalculates the resulting line chain.
Definition: pns_meander.cpp:540
int Width() const
Definition: pns_meander.h:282
bool IsDual() const
Definition: pns_meander.h:208
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:293
MEANDER_TYPE Type() const
Definition: pns_meander.h:145
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:232
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
void MakeEmpty()
Replace the meander with straight bypass line(s), effectively clearing it.
Definition: pns_meander.cpp:551
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: pns_meander.cpp:432
int MaxTunableLength() const
Definition: pns_meander.cpp:652
int BaselineLength() const
Definition: pns_meander.cpp:646
void MakeCorner(const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Definition: pns_meander.cpp:604
Definition: seg.h:41
Definition: shape_arc.h:36
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Definition: shape_line_chain.h:81