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-2022 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
31namespace PNS {
32
33class MEANDER_PLACER_BASE;
34class 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{
60public:
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_singleSided = false;
74 m_lengthTolerance = 100000;
75 }
76
79
82
85
87 int m_step;
88
91
93 long long int m_targetLength;
94
97
100
103
106
109};
110
115{
116public:
123 MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
124 m_placer( aPlacer ),
125 m_dual( aIsDual ),
126 m_width( aWidth ),
128 {
129 // Do not leave uninitialized members, and keep static analyzer quiet:
131 m_amplitude = 0;
132 m_targetBaseLen = 0;
133 m_side = false;
134 m_baseIndex = 0;
135 m_currentTarget = nullptr;
137 }
138
142 void SetType( MEANDER_TYPE aType )
143 {
144 m_type = aType;
145 }
146
151 {
152 return m_type;
153 }
154
158 void SetBaseIndex( int aIndex )
159 {
160 m_baseIndex = aIndex;
161 }
162
166 int BaseIndex() const
167 {
168 return m_baseIndex;
169 }
170
174 int Amplitude() const
175 {
176 return m_amplitude;
177 }
178
186 void MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 = VECTOR2I( 0, 0 ) );
187
195 void MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
196
203 void Resize( int aAmpl );
204
208 void Recalculate();
209
213 bool IsDual() const
214 {
215 return m_dual;
216 }
217
221 bool Side() const
222 {
223 return m_side;
224 }
225
229 VECTOR2I End() const
230 {
231 return m_clippedBaseSeg.B;
232 }
233
237 const SHAPE_LINE_CHAIN& CLine( int aShape ) const
238 {
239 return m_shapes[aShape];
240 }
241
245 void MakeEmpty();
246
257 bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
258
264 const SEG& BaseSegment() const
265 {
266 return m_clippedBaseSeg;
267 }
268
272 int BaselineLength() const;
273
277 long long int CurrentLength() const;
278
282 long long int MinTunableLength() const;
283
287 int MinAmplitude() const;
288
292 const MEANDER_SETTINGS& Settings() const;
293
297 int Width() const
298 {
299 return m_width;
300 }
301
308 void SetBaselineOffset( int aOffset )
309 {
310 m_baselineOffset = aOffset;
311 }
312
319 void SetTargetBaselineLength( int aLength ) { m_targetBaseLen = aLength; }
320
321private:
322 friend class MEANDERED_LINE;
323
325 void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
326
328 void forward( int aLength );
329
331 void turn( const EDA_ANGLE& aAngle );
332
334 void miter( int aRadius, bool aSide );
335
337 void uShape( int aSides, int aCorner, int aTop );
338
340 SHAPE_LINE_CHAIN makeMiterShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide );
341
343 SHAPE_LINE_CHAIN genMeanderShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide,
344 MEANDER_TYPE aType, int aBaselineOffset = 0 );
345
347 void updateBaseSegment();
348
350 int cornerRadius() const;
351
353 int spacing() const;
354
357
360
362 bool m_dual;
363
366
369
372
375
378
381
384
387
389 bool m_side;
390
393
396
399
402
405};
406
407
412{
413public:
415 {
416 // Do not leave uninitialized members, and keep static analyzer quiet:
417 m_placer = nullptr;
418 m_dual = false;
419 m_width = 0;
421 }
422
427 MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
428 m_placer( aPlacer ),
429 m_dual( aIsDual )
430 {
431 // Do not leave uninitialized members, and keep static analyzer quiet:
432 m_width = 0;
434 }
435
437 {
438 Clear();
439 }
440
448 void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
449
457 void AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
458
466 void AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 );
467
475 void AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 );
476
482 void AddMeander( MEANDER_SHAPE* aShape );
483
487 void Clear();
488
492 void SetWidth( int aWidth )
493 {
494 m_width = aWidth;
495 }
496
504 void MeanderSegment( const SEG& aSeg, bool aSide, int aBaseIndex = 0 );
505
507 void SetBaselineOffset( int aOffset )
508 {
509 m_baselineOffset = aOffset;
510 }
511
515 std::vector<MEANDER_SHAPE*>& Meanders()
516 {
517 return m_meanders;
518 }
519
527 bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
528
532 const MEANDER_SETTINGS& Settings() const;
533
534private:
536
538 std::vector<MEANDER_SHAPE*> m_meanders;
539
540 bool m_dual;
543};
544
545}
546
547#endif // __PNS_MEANDER_H
Represent a set of meanders fitted over a single or two lines.
Definition: pns_meander.h:412
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:537
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:507
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:492
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
void Clear()
Clear the line geometry, removing all corners and meanders.
std::vector< MEANDER_SHAPE * > m_meanders
Definition: pns_meander.h:538
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.
void AddArcAndPt(const SHAPE_ARC &aArc1, const VECTOR2I &aPt2)
Create a dummy meander shape representing an arc corner.
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Check if the given shape is intersecting with any other meander in the current line.
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:39
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:427
std::vector< MEANDER_SHAPE * > & Meanders()
Definition: pns_meander.h:515
void AddPtAndArc(const VECTOR2I &aPt1, const SHAPE_ARC &aArc2)
Create a dummy meander shape representing an arc corner.
Base class for Single trace & Differential pair meandering tools, as both of them share a lot of code...
Dimensions for the meandering algorithm.
Definition: pns_meander.h:59
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:78
MEANDER_SETTINGS()
Minimum meandering amplitude.
Definition: pns_meander.h:62
int m_cornerRadiusPercentage
Place meanders on one side.
Definition: pns_meander.h:99
bool m_singleSided
Allowable tuning error.
Definition: pns_meander.h:102
long long int m_targetLength
Type of corners for the meandered line.
Definition: pns_meander.h:93
int m_lengthTolerance
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:105
int m_step
Length PadToDie.
Definition: pns_meander.h:87
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:96
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:81
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:90
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:84
The geometry of a single meander.
Definition: pns_meander.h:115
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:356
int MinAmplitude() const
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:359
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:383
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:123
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:386
int Amplitude() const
Definition: pns_meander.h:174
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:142
int m_targetBaseLen
First point of the meandered line.
Definition: pns_meander.h:377
VECTOR2I End() const
Definition: pns_meander.h:229
SHAPE_LINE_CHAIN genMeanderShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide, MEANDER_TYPE aType, int aBaselineOffset=0)
Recalculate the clipped baseline after the parameters of the meander have been changed.
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Move turtle forward by aLength.
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
Definition: pns_meander.h:158
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:371
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:398
int m_width
Amplitude of the meander.
Definition: pns_meander.h:365
int BaseIndex() const
Definition: pns_meander.h:166
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:401
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:392
long long int CurrentLength() const
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:389
bool Side() const
Definition: pns_meander.h:221
void updateBaseSegment()
Return sanitized corner radius value.
SHAPE_LINE_CHAIN makeMiterShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
Produce a meander shape of given type.
void MakeArc(const SHAPE_ARC &aArc1, const SHAPE_ARC &aArc2=SHAPE_ARC())
Create a dummy meander shape representing an arc corner.
void SetTargetBaselineLength(int aLength)
Sets the target length of the baseline.
Definition: pns_meander.h:319
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:395
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:404
bool m_dual
Width of the line.
Definition: pns_meander.h:362
void Recalculate()
Recalculate the line chain representing the meander's shape.
void miter(int aRadius, bool aSide)
Tell the turtle to draw an U-like shape.
long long int MinTunableLength() const
void Resize(int aAmpl)
Change the amplitude of the meander shape to aAmpl and recalculates the resulting line chain.
int m_meanCornerRadius
Minimum length of the base segment to target when resizing.
Definition: pns_meander.h:374
int Width() const
Definition: pns_meander.h:297
int spacing() const
The type of meander.
bool IsDual() const
Definition: pns_meander.h:213
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:368
int cornerRadius() const
Return sanitized spacing value.
void turn(const EDA_ANGLE &aAngle)
Tell the turtle to draw a mitered corner of given radius and turn direction.
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:308
void forward(int aLength)
Turn the turtle by aAngle.
MEANDER_TYPE Type() const
Definition: pns_meander.h:150
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:380
const MEANDER_SETTINGS & Settings() const
Definition: pns_meander.cpp:33
void MakeEmpty()
Replace the meander with straight bypass line(s), effectively clearing it.
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...
void uShape(int aSides, int aCorner, int aTop)
Generate a 90-degree circular arc.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Definition: pns_meander.h:237
int BaselineLength() const
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:264
void MakeCorner(const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Definition: seg.h:42
VECTOR2I B
Definition: seg.h:50
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Push and Shove diff pair dimensions (gap) settings dialog.
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:37
@ MT_ARC
Definition: pns_meander.h:45
@ MT_TURN
Definition: pns_meander.h:41
@ MT_CHECK_START
Definition: pns_meander.h:42
@ MT_CHECK_FINISH
Definition: pns_meander.h:43
@ MT_START
Definition: pns_meander.h:39
@ MT_FINISH
Definition: pns_meander.h:40
@ MT_EMPTY
Definition: pns_meander.h:46
@ MT_CORNER
Definition: pns_meander.h:44
@ MT_SINGLE
Definition: pns_meander.h:38
MEANDER_STYLE
Definition: pns_meander.h:50
@ MEANDER_STYLE_ROUND
Definition: pns_meander.h:51
@ MEANDER_STYLE_CHAMFER
Definition: pns_meander.h:52
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618