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 The 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
20 * along with this program. If not, see <https://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
32class NETCLASS;
33
34namespace PNS {
35
37class MEANDERED_LINE;
38
41 MT_SINGLE, // _|^|_, single-sided
42 MT_START, // _|^|
43 MT_FINISH, // |^|_
44 MT_TURN, // |^| or |_|
45 MT_CHECK_START, // try fitting a start type, but don't produce a line
46 MT_CHECK_FINISH, // try fitting a finish type, but don't produce a line
47 MT_CORNER, // line corner
48 MT_ARC, // arc corner
49 MT_EMPTY // no meander (straight line)
50};
51
54 MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
55 MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
56};
57
65
70{
71public:
72 static const long long int DEFAULT_LENGTH_TOLERANCE;
73 static const long long int LENGTH_UNCONSTRAINED;
74
75 static const long long int DEFAULT_DELAY_TOLERANCE;
76 static const long long int DELAY_UNCONSTRAINED;
77
78 static const int SKEW_UNCONSTRAINED;
79
81
82 void SetTargetLength( long long int aOpt );
83 void SetTargetLength( const MINOPTMAX<int>& aConstraint );
84
85 void SetTargetSignalLength( long long int aOpt );
86 void SetTargetSignalLength( const MINOPTMAX<int>& aConstraint );
87
88 void SetTargetLengthDelay( long long int aOpt );
89 void SetTargetLengthDelay( const MINOPTMAX<int>& aConstraint );
90
91 void SetTargetSkew( int aOpt );
92 void SetTargetSkew( const MINOPTMAX<int>& aConstraint );
93
94 void SetTargetSkewDelay( int aOpt );
95 void SetTargetSkewDelay( const MINOPTMAX<int>& aConstraint );
96
97 void SetTargetSignalLengthDelay( long long int aOpt );
98 void SetTargetSignalLengthDelay( const MINOPTMAX<int>& aConstraint );
99
102
105
108
111
114
117 long long int m_signalExtraLength;
118
122 long long int m_signalExtraDelay;
123
126
129
132
135
138
141
143
146
149
152
155
158
161
164
167};
168
173{
174public:
181 MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
182 m_placer( aPlacer ),
183 m_dual( aIsDual ),
184 m_width( aWidth ),
186 {
187 // Do not leave uninitialized members, and keep static analyzer quiet:
189 m_amplitude = 0;
190 m_targetBaseLen = 0;
191 m_side = false;
192 m_baseIndex = 0;
193 m_currentTarget = nullptr;
195 }
196
200 void SetType( MEANDER_TYPE aType )
201 {
202 m_type = aType;
203 }
204
209 {
210 return m_type;
211 }
212
216 bool IsMeander() const
217 {
218 return m_type == MT_SINGLE || m_type == MT_START || m_type == MT_FINISH || m_type == MT_TURN;
219 }
220
224 void SetBaseIndex( int aIndex )
225 {
226 m_baseIndex = aIndex;
227 }
228
232 int BaseIndex() const
233 {
234 return m_baseIndex;
235 }
236
240 int Amplitude() const
241 {
242 return m_amplitude;
243 }
244
252 void MakeCorner( const VECTOR2I& aP1, const VECTOR2I& aP2 = VECTOR2I( 0, 0 ) );
253
261 void MakeArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
262
269 void Resize( int aAmpl );
270
274 void Recalculate();
275
279 bool IsDual() const
280 {
281 return m_dual;
282 }
283
287 bool Side() const
288 {
289 return m_side;
290 }
291
295 VECTOR2I End() const
296 {
297 return m_clippedBaseSeg.B;
298 }
299
303 const SHAPE_LINE_CHAIN& CLine( int aShape ) const
304 {
305 return m_shapes[aShape];
306 }
307
311 void MakeEmpty();
312
323 bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
324
330 const SEG& BaseSegment() const
331 {
332 return m_clippedBaseSeg;
333 }
334
338 int BaselineLength() const;
339
343 long long int CurrentLength() const;
344
348 long long int MinTunableLength() const;
349
353 int MinAmplitude() const;
354
358 const MEANDER_SETTINGS& Settings() const;
359
363 int Width() const
364 {
365 return m_width;
366 }
367
374 void SetBaselineOffset( int aOffset )
375 {
376 m_baselineOffset = aOffset;
377 }
378
385 void SetTargetBaselineLength( int aLength ) { m_targetBaseLen = aLength; }
386
387private:
388 friend class MEANDERED_LINE;
389
391 void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
392
394 void forward( int aLength );
395
397 void turn( const EDA_ANGLE& aAngle );
398
400 void miter( int aRadius, bool aSide );
401
403 void uShape( int aSides, int aCorner, int aTop );
404
406 SHAPE_LINE_CHAIN makeMiterShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide );
407
409 SHAPE_LINE_CHAIN genMeanderShape( const VECTOR2D& aP, const VECTOR2D& aDir, bool aSide,
410 MEANDER_TYPE aType, int aBaselineOffset = 0 );
411
413 void updateBaseSegment();
414
416 int cornerRadius() const;
417
419 int spacing() const;
420
423
426
428 bool m_dual;
429
432
435
438
441
444
447
450
453
455 bool m_side;
456
459
462
465
468
471};
472
473
478{
479public:
481 {
482 // Do not leave uninitialized members, and keep static analyzer quiet:
483 m_placer = nullptr;
484 m_dual = false;
485 m_width = 0;
487 }
488
493 MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
494 m_placer( aPlacer ),
495 m_dual( aIsDual )
496 {
497 // Do not leave uninitialized members, and keep static analyzer quiet:
498 m_width = 0;
500 }
501
503 {
504 Clear();
505 }
506
514 void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
515
523 void AddArc( const SHAPE_ARC& aArc1, const SHAPE_ARC& aArc2 = SHAPE_ARC() );
524
532 void AddArcAndPt( const SHAPE_ARC& aArc1, const VECTOR2I& aPt2 );
533
541 void AddPtAndArc( const VECTOR2I& aPt1, const SHAPE_ARC& aArc2 );
542
548 void AddMeander( MEANDER_SHAPE* aShape );
549
553 void Clear();
554
558 void SetWidth( int aWidth )
559 {
560 m_width = aWidth;
561 }
562
570 void MeanderSegment( const SEG& aSeg, bool aSide, int aBaseIndex = 0 );
571
573 void SetBaselineOffset( int aOffset )
574 {
575 m_baselineOffset = aOffset;
576 }
577
581 std::vector<MEANDER_SHAPE*>& Meanders()
582 {
583 return m_meanders;
584 }
585
593 bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
594
598 const MEANDER_SETTINGS& Settings() const;
599
600 // Move assignment operator
602 {
603 if (this != &aOther)
604 {
605 m_last = aOther.m_last;
606
607 m_placer = aOther.m_placer;
608 m_meanders = std::move( aOther.m_meanders );
609
610 m_dual = aOther.m_dual;
611 m_width = aOther.m_width;
612 m_baselineOffset = aOther.m_baselineOffset;
613 }
614
615 return *this;
616 }
617
618private:
620
622 std::vector<MEANDER_SHAPE*> m_meanders;
623
624 bool m_dual;
627};
628
629}
630
631#endif // __PNS_MEANDER_H
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
Represent a set of meanders fitted over a single or two lines.
void AddMeander(MEANDER_SHAPE *aShape)
Add a new meander shape to the meandered line.
MEANDER_PLACER_BASE * m_placer
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
void SetWidth(int aWidth)
Set the line width.
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.
MEANDERED_LINE & operator=(MEANDERED_LINE &&aOther) noexcept
std::vector< MEANDER_SHAPE * > m_meanders
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)
std::vector< MEANDER_SHAPE * > & Meanders()
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:70
int m_minAmplitude
Minimum meandering amplitude.
void SetTargetLength(long long int aOpt)
bool m_isTimeDomain
Calculate tuning in the time domain.
static const long long int LENGTH_UNCONSTRAINED
Definition pns_meander.h:73
int m_cornerRadiusPercentage
Rounding percentage (0 - 100).
MEANDER_SIDE m_initialSide
Initial side when placing meanders at segment.
bool m_singleSided
Place meanders on one side.
void SetTargetLengthDelay(long long int aOpt)
static const int SKEW_UNCONSTRAINED
Definition pns_meander.h:78
static const long long int DEFAULT_DELAY_TOLERANCE
Definition pns_meander.h:75
MINOPTMAX< long long int > m_targetLength
Desired length of the tuned line/diff pair (this is in nm, so allow more than board width).
NETCLASS * m_netClass
The net class this meander pattern belongs to.
void SetTargetSignalLengthDelay(long long int aOpt)
void SetTargetSkew(int aOpt)
void SetTargetSignalLength(long long int aOpt)
static const long long int DEFAULT_LENGTH_TOLERANCE
Definition pns_meander.h:72
int m_lengthTolerance
Allowable tuning error.
int m_step
Amplitude/spacing adjustment step.
MINOPTMAX< int > m_targetSkew
Target skew value for diff pair de-skewing.
MEANDER_STYLE m_cornerStyle
Type of corners for the meandered line.
MINOPTMAX< long long int > m_targetSignalLengthDelay
Desired overall chain propagation delay.
bool m_keepEndpoints
Keep vertices between pre, tuned and post parts of the line.
MINOPTMAX< int > m_targetSkewDelay
Target skew value for diff pair de-skewing.
int m_maxAmplitude
Maximum meandering amplitude.
long long int m_signalExtraDelay
Additional pre-existing delay contributed by other nets in the same logical chain (used when chain-le...
MINOPTMAX< long long int > m_targetLengthDelay
Desired propagation delay of the tuned line.
void SetTargetSkewDelay(int aOpt)
static const long long int DELAY_UNCONSTRAINED
Definition pns_meander.h:76
int m_lenPadToDie
Length PadToDie.
long long int m_signalExtraLength
Additional pre-existing length contributed by other nets in the same logical chain (used when chain-l...
int m_spacing
Meandering period/spacing (see dialog picture for explanation).
MINOPTMAX< long long int > m_targetSignalLength
Desired chain length (copper-only, bridging subtracted).
The geometry of a single meander.
MEANDER_TYPE m_type
The type of meander.
int MinAmplitude() const
MEANDER_PLACER_BASE * m_placer
The placer that placed this meander.
SEG m_baseSeg
Base segment (unclipped).
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
SEG m_clippedBaseSeg
Base segment (clipped).
int Amplitude() const
void SetType(MEANDER_TYPE aType)
Set the type of the meander.
int m_targetBaseLen
Minimum length of the base segment to target when resizing.
VECTOR2I End() const
SHAPE_LINE_CHAIN genMeanderShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide, MEANDER_TYPE aType, int aBaselineOffset=0)
Produce a meander shape of given type.
void start(SHAPE_LINE_CHAIN *aTarget, const VECTOR2D &aWhere, const VECTOR2D &aDir)
Start turtle drawing.
void SetBaseIndex(int aIndex)
Set an auxiliary index of the segment being meandered in its original LINE.
int m_baselineOffset
Offset wrs the base segment (dual only).
VECTOR2D m_currentDir
The current turtle direction.
int m_width
Width of the line.
int BaseIndex() const
VECTOR2D m_currentPos
The current turtle position.
SHAPE_LINE_CHAIN m_shapes[2]
The actual shapes (0 used for single, both for dual).
long long int CurrentLength() const
bool m_side
Side (true = right).
bool Side() const
void updateBaseSegment()
Recalculate the clipped baseline after the parameters of the meander have been changed.
SHAPE_LINE_CHAIN makeMiterShape(const VECTOR2D &aP, const VECTOR2D &aDir, bool aSide)
Generate a 90-degree circular arc.
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.
int m_baseIndex
Index of the meandered segment in the base line.
SHAPE_LINE_CHAIN * m_currentTarget
The line the turtle is drawing on.
bool m_dual
Dual or single line.
void Recalculate()
Recalculate the line chain representing the meander's shape.
void miter(int aRadius, bool aSide)
Tell the turtle to draw a mitered corner of given radius and turn direction.
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
Average radius of meander corners (for correction of DP meanders).
int Width() const
int spacing() const
Return sanitized spacing value.
bool IsDual() const
friend class MEANDERED_LINE
int m_amplitude
Amplitude of the meander.
int cornerRadius() const
Return sanitized corner radius value.
void turn(const EDA_ANGLE &aAngle)
Turn the turtle by aAngle.
void SetBaselineOffset(int aOffset)
Set the parallel offset between the base segment and the meandered line.
void forward(int aLength)
Move turtle forward by aLength.
MEANDER_TYPE Type() const
VECTOR2I m_p0
First point of the meandered line.
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)
Tell the turtle to draw an U-like shape.
const SHAPE_LINE_CHAIN & CLine(int aShape) const
int BaselineLength() const
const SEG & BaseSegment() const
Return the base segment the meander was fitted to.
bool IsMeander() const
void MakeCorner(const VECTOR2I &aP1, const VECTOR2I &aP2=VECTOR2I(0, 0))
Create a dummy meander shape representing a line corner.
Definition seg.h:38
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:40
@ MT_ARC
Definition pns_meander.h:48
@ MT_TURN
Definition pns_meander.h:44
@ MT_CHECK_START
Definition pns_meander.h:45
@ MT_CHECK_FINISH
Definition pns_meander.h:46
@ MT_START
Definition pns_meander.h:42
@ MT_FINISH
Definition pns_meander.h:43
@ MT_EMPTY
Definition pns_meander.h:49
@ MT_CORNER
Definition pns_meander.h:47
@ MT_SINGLE
Definition pns_meander.h:41
MEANDER_SIDE
Initial side the meander is placed on.
Definition pns_meander.h:60
@ MEANDER_SIDE_RIGHT
Definition pns_meander.h:63
@ MEANDER_SIDE_DEFAULT
Definition pns_meander.h:62
@ MEANDER_SIDE_LEFT
Definition pns_meander.h:61
MEANDER_STYLE
Meander corner shape.
Definition pns_meander.h:53
@ MEANDER_STYLE_ROUND
Definition pns_meander.h:54
@ MEANDER_STYLE_CHAMFER
Definition pns_meander.h:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707