KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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#include <core/minoptmax.h>
28
29#include <geometry/shape.h>
31
32namespace PNS {
33
34class MEANDER_PLACER_BASE;
35class MEANDERED_LINE;
36
39 MT_SINGLE, // _|^|_, single-sided
40 MT_START, // _|^|
41 MT_FINISH, // |^|_
42 MT_TURN, // |^| or |_|
43 MT_CHECK_START, // try fitting a start type, but don't produce a line
44 MT_CHECK_FINISH, // try fitting a finish type, but don't produce a line
45 MT_CORNER, // line corner
46 MT_ARC, // arc corner
47 MT_EMPTY // no meander (straight line)
48};
49
52 MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
53 MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
54};
55
58{
62};
63
68{
69public:
70 static const long long int DEFAULT_TOLERANCE;
71 static const long long int LENGTH_UNCONSTRAINED;
72 static const int SKEW_UNCONSTRAINED;
73
75
76 void SetTargetLength( long long int aOpt );
77 void SetTargetLength( const MINOPTMAX<int>& aConstraint );
78
79 void SetTargetSkew( int aOpt );
80 void SetTargetSkew( const MINOPTMAX<int>& aConstraint );
81
84
87
90
92 int m_step;
93
96
99
102
104
107
110
113
116
119
122};
123
128{
129public:
136 MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
137 m_placer( aPlacer ),
138 m_dual( aIsDual ),
139 m_width( aWidth ),
141 {
142 // Do not leave uninitialized members, and keep static analyzer quiet:
144 m_amplitude = 0;
145 m_targetBaseLen = 0;
146 m_side = false;
147 m_baseIndex = 0;
148 m_currentTarget = nullptr;
150 }
151
155 void SetType( MEANDER_TYPE aType )
156 {
157 m_type = aType;
158 }
159
164 {
165 return m_type;
166 }
167
171 void SetBaseIndex( int aIndex )
172 {
173 m_baseIndex = aIndex;
174 }
175
179 int BaseIndex() const
180 {
181 return m_baseIndex;
182 }
183
187 int Amplitude() const
188 {
189 return m_amplitude;
190 }
191
199 void MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 = VECTOR2I( 0, 0 ) );
200
208 void MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
209
216 void Resize( int aAmpl );
217
221 void Recalculate();
222
226 bool IsDual() const
227 {
228 return m_dual;
229 }
230
234 bool Side() const
235 {
236 return m_side;
237 }
238
242 VECTOR2I End() const
243 {
244 return m_clippedBaseSeg.B;
245 }
246
250 const SHAPE_LINE_CHAIN& CLine( int aShape ) const
251 {
252 return m_shapes[aShape];
253 }
254
258 void MakeEmpty();
259
270 bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
271
277 const SEG& BaseSegment() const
278 {
279 return m_clippedBaseSeg;
280 }
281
285 int BaselineLength() const;
286
290 long long int CurrentLength() const;
291
295 long long int MinTunableLength() const;
296
300 int MinAmplitude() const;
301
305 const MEANDER_SETTINGS& Settings() const;
306
310 int Width() const
311 {
312 return m_width;
313 }
314
321 void SetBaselineOffset( int aOffset )
322 {
323 m_baselineOffset = aOffset;
324 }
325
332 void SetTargetBaselineLength( int aLength ) { m_targetBaseLen = aLength; }
333
334private:
335 friend class MEANDERED_LINE;
336
338 void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
339
341 void forward( int aLength );
342
344 void turn( const EDA_ANGLE& aAngle );
345
347 void miter( int aRadius, bool aSide );
348
350 void uShape( int aSides, int aCorner, int aTop );
351
353 SHAPE_LINE_CHAIN makeMiterShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide );
354
356 SHAPE_LINE_CHAIN genMeanderShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide,
357 MEANDER_TYPE aType, int aBaselineOffset = 0 );
358
360 void updateBaseSegment();
361
363 int cornerRadius() const;
364
366 int spacing() const;
367
370
373
375 bool m_dual;
376
379
382
385
388
391
394
397
400
402 bool m_side;
403
406
409
412
415
418};
419
420
425{
426public:
428 {
429 // Do not leave uninitialized members, and keep static analyzer quiet:
430 m_placer = nullptr;
431 m_dual = false;
432 m_width = 0;
434 }
435
440 MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
441 m_placer( aPlacer ),
442 m_dual( aIsDual )
443 {
444 // Do not leave uninitialized members, and keep static analyzer quiet:
445 m_width = 0;
447 }
448
450 {
451 Clear();
452 }
453
461 void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
462
470 void AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
471
479 void AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 );
480
488 void AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 );
489
495 void AddMeander( MEANDER_SHAPE* aShape );
496
500 void Clear();
501
505 void SetWidth( int aWidth )
506 {
507 m_width = aWidth;
508 }
509
517 void MeanderSegment( const SEG& aSeg, bool aSide, int aBaseIndex = 0 );
518
520 void SetBaselineOffset( int aOffset )
521 {
522 m_baselineOffset = aOffset;
523 }
524
528 std::vector<MEANDER_SHAPE*>& Meanders()
529 {
530 return m_meanders;
531 }
532
540 bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
541
545 const MEANDER_SETTINGS& Settings() const;
546
547private:
549
551 std::vector<MEANDER_SHAPE*> m_meanders;
552
553 bool m_dual;
556};
557
558}
559
560#endif // __PNS_MEANDER_H
Represent a set of meanders fitted over a single or two lines.
Definition: pns_meander.h:425
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
MEANDER_PLACER_BASE * m_placer
Definition: pns_meander.h:550
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
Definition: pns_meander.h:520
void SetWidth(int aWidth)
Set the line width.
Definition: pns_meander.h:505
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:551
void MeanderSegment(const SEG &aSeg, bool aSide, int aBaseIndex=0)
Fit maximum amplitude meanders on a given segment and adds to the current line.
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
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Definition: pns_meander.h:440
std::vector< MEANDER_SHAPE * > & Meanders()
Definition: pns_meander.h:528
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:68
int m_minAmplitude
Maximum meandering amplitude.
Definition: pns_meander.h:83
void SetTargetLength(long long int aOpt)
Definition: pns_meander.cpp:55
static const long long int LENGTH_UNCONSTRAINED
Definition: pns_meander.h:71
int m_cornerRadiusPercentage
Place meanders on one side.
Definition: pns_meander.h:109
MEANDER_SIDE m_initialSide
Allowable tuning error.
Definition: pns_meander.h:115
bool m_singleSided
Initial side when placing meanders at segment.
Definition: pns_meander.h:112
static const int SKEW_UNCONSTRAINED
Definition: pns_meander.h:72
MINOPTMAX< long long int > m_targetLength
Target skew value for diff pair de-skewing.
Definition: pns_meander.h:98
void SetTargetSkew(int aOpt)
Definition: pns_meander.cpp:84
int m_lengthTolerance
Keep vertices between pre, tuned and post parts of the line.
Definition: pns_meander.h:118
int m_step
Length PadToDie.
Definition: pns_meander.h:92
MINOPTMAX< int > m_targetSkew
Definition: pns_meander.h:101
static const long long int DEFAULT_TOLERANCE
Definition: pns_meander.h:70
MEANDER_STYLE m_cornerStyle
Rounding percentage (0 - 100).
Definition: pns_meander.h:106
int m_maxAmplitude
Meandering period/spacing (see dialog picture for explanation).
Definition: pns_meander.h:86
bool m_overrideCustomRules
Type of corners for the meandered line.
Definition: pns_meander.h:103
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:95
int m_spacing
Amplitude/spacing adjustment step.
Definition: pns_meander.h:89
The geometry of a single meander.
Definition: pns_meander.h:128
MEANDER_TYPE m_type
The placer that placed this meander.
Definition: pns_meander.h:369
int MinAmplitude() const
MEANDER_PLACER_BASE * m_placer
Dual or single line.
Definition: pns_meander.h:372
SEG m_baseSeg
Base segment (clipped).
Definition: pns_meander.h:396
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Definition: pns_meander.h:136
SEG m_clippedBaseSeg
Side (true = right).
Definition: pns_meander.h:399
int Amplitude() const
Definition: pns_meander.h:187
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
Definition: pns_meander.h:155
int m_targetBaseLen
First point of the meandered line.
Definition: pns_meander.h:390
VECTOR2I End() const
Definition: pns_meander.h:242
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:171
int m_baselineOffset
Average radius of meander corners (for correction of DP meanders).
Definition: pns_meander.h:384
VECTOR2D m_currentDir
The current turtle position.
Definition: pns_meander.h:411
int m_width
Amplitude of the meander.
Definition: pns_meander.h:378
int BaseIndex() const
Definition: pns_meander.h:179
VECTOR2D m_currentPos
The line the turtle is drawing on.
Definition: pns_meander.h:414
SHAPE_LINE_CHAIN m_shapes[2]
Index of the meandered segment in the base line.
Definition: pns_meander.h:405
long long int CurrentLength() const
bool m_side
The actual shapes (0 used for single, both for dual).
Definition: pns_meander.h:402
bool Side() const
Definition: pns_meander.h:234
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:332
int m_baseIndex
The current turtle direction.
Definition: pns_meander.h:408
SHAPE_LINE_CHAIN * m_currentTarget
Definition: pns_meander.h:417
bool m_dual
Width of the line.
Definition: pns_meander.h:375
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:387
int Width() const
Definition: pns_meander.h:310
int spacing() const
The type of meander.
bool IsDual() const
Definition: pns_meander.h:226
int m_amplitude
Offset wrs the base segment (dual only).
Definition: pns_meander.h:381
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:321
void forward(int aLength)
Turn the turtle by aAngle.
MEANDER_TYPE Type() const
Definition: pns_meander.h:163
VECTOR2I m_p0
Base segment (unclipped).
Definition: pns_meander.h:393
const MEANDER_SETTINGS & Settings() const
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:250
int BaselineLength() const
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
Definition: pns_meander.h:277
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:38
@ MT_ARC
Definition: pns_meander.h:46
@ MT_TURN
Definition: pns_meander.h:42
@ MT_CHECK_START
Definition: pns_meander.h:43
@ MT_CHECK_FINISH
Definition: pns_meander.h:44
@ MT_START
Definition: pns_meander.h:40
@ MT_FINISH
Definition: pns_meander.h:41
@ MT_EMPTY
Definition: pns_meander.h:47
@ MT_CORNER
Definition: pns_meander.h:45
@ MT_SINGLE
Definition: pns_meander.h:39
MEANDER_SIDE
Definition: pns_meander.h:58
@ MEANDER_SIDE_RIGHT
Definition: pns_meander.h:61
@ MEANDER_SIDE_DEFAULT
Definition: pns_meander.h:60
@ MEANDER_SIDE_LEFT
Definition: pns_meander.h:59
MEANDER_STYLE
Definition: pns_meander.h:51
@ MEANDER_STYLE_ROUND
Definition: pns_meander.h:52
@ MEANDER_STYLE_CHAMFER
Definition: pns_meander.h:53
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691