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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef __PNS_MEANDER_H
23 #define __PNS_MEANDER_H
24 
25 #include <math/vector2d.h>
26 
27 #include <geometry/shape.h>
28 #include <geometry/shape_line_chain.h>
29 
30 namespace PNS {
31 
32 class MEANDER_PLACER_BASE;
33 
35 enum MEANDER_TYPE {
36  MT_SINGLE, // _|^|_, single-sided
37  MT_START, // _|^|
38  MT_FINISH, // |^|_
39  MT_TURN, // |^| or |_|
40  MT_CHECK_START, // try fitting a start type, but don't produce a line
41  MT_CHECK_FINISH, // try fitting a finish type, but don't produce a line
42  MT_CORNER, // line corner
43  MT_EMPTY // no meander (straight line)
44 };
45 
47 enum MEANDER_STYLE {
48  MEANDER_STYLE_ROUND = 1, // rounded (90 degree arc)
49  MEANDER_STYLE_CHAMFER // chamfered (45 degree segment)
50 };
51 
58 {
59 public:
60 
62  {
63  m_minAmplitude = 100000;
64  m_maxAmplitude = 1000000;
65  m_step = 50000;
66  m_spacing = 600000;
67  m_targetLength = 100000000;
68  m_targetSkew = 0;
69  m_cornerStyle = MEANDER_STYLE_ROUND;
71  m_lengthTolerance = 100000;
73  }
74 
80  int m_spacing;
82  int m_step;
86  MEANDER_STYLE m_cornerStyle;
95 };
96 
97 class MEANDERED_LINE;
98 
105 {
106 public:
115  MEANDER_SHAPE( MEANDER_PLACER_BASE* aPlacer, int aWidth, bool aIsDual = false ) :
116  m_placer( aPlacer ),
117  m_dual( aIsDual ),
118  m_width( aWidth ),
119  m_baselineOffset( 0 )
120  {
121  // Do not leave unitialized members, and keep static analyser quiet:
122  m_type = MT_SINGLE;
123  m_amplitude = 0;
124  m_side = false;
125  m_baseIndex = 0;
126  m_currentTarget = NULL;
127  m_meanCornerRadius = 0;
128  }
129 
135  void SetType( MEANDER_TYPE aType )
136  {
137  m_type = aType;
138  }
139 
145  MEANDER_TYPE Type() const
146  {
147  return m_type;
148  }
149 
155  void SetBaseIndex( int aIndex )
156  {
157  m_baseIndex = aIndex;
158  }
159 
165  int BaseIndex() const
166  {
167  return m_baseIndex;
168  }
169 
175  int Amplitude() const
176  {
177  return m_amplitude;
178  }
179 
188  void MakeCorner( VECTOR2I aP1, VECTOR2I aP2 = VECTOR2I( 0, 0 ) );
189 
197  void Resize( int aAmpl );
198 
204  void Recalculate();
205 
211  bool IsDual() const
212  {
213  return m_dual;
214  }
215 
221  bool Side() const
222  {
223  return m_side;
224  }
225 
231  VECTOR2I End() const
232  {
233  return m_clippedBaseSeg.B;
234  }
235 
241  const SHAPE_LINE_CHAIN& CLine( int aShape ) const
242  {
243  return m_shapes[aShape];
244  }
245 
252  void MakeEmpty();
253 
265  bool Fit( MEANDER_TYPE aType, const SEG& aSeg, const VECTOR2I& aP, bool aSide );
266 
273  const SEG& BaseSegment() const
274  {
275  return m_clippedBaseSeg;
276  }
277 
284  int BaselineLength() const;
285 
291  int MaxTunableLength() const;
292 
298  const MEANDER_SETTINGS& Settings() const;
299 
305  int Width() const
306  {
307  return m_width;
308  }
309 
317  void SetBaselineOffset( int aOffset )
318  {
319  m_baselineOffset = aOffset;
320  }
321 
322 private:
323  friend class MEANDERED_LINE;
324 
326  void start( SHAPE_LINE_CHAIN* aTarget, const VECTOR2D& aWhere, const VECTOR2D& aDir );
328  void forward( int aLength );
330  void turn( int aAngle );
332  void miter( int aRadius, bool aSide );
334  void uShape( int aSides, int aCorner, int aTop );
335 
337  SHAPE_LINE_CHAIN makeMiterShape( VECTOR2D aP, VECTOR2D aDir, bool aSide );
338 
340  VECTOR2I reflect( VECTOR2I aP, const SEG& aLine );
341 
343  SHAPE_LINE_CHAIN genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, MEANDER_TYPE aType, int aAmpl, int aBaselineOffset = 0 );
344 
347  void updateBaseSegment();
348 
350  int cornerRadius() const;
351 
353  int spacing() const;
354 
356  MEANDER_TYPE m_type;
358  MEANDER_PLACER_BASE* m_placer;
360  bool m_dual;
362  int m_width;
364  int m_amplitude;
366  int m_baselineOffset;
368  int m_meanCornerRadius;
370  VECTOR2I m_p0;
372  SEG m_baseSeg;
374  SEG m_clippedBaseSeg;
376  bool m_side;
378  SHAPE_LINE_CHAIN m_shapes[2];
380  int m_baseIndex;
382  VECTOR2D m_currentDir;
384  VECTOR2D m_currentPos;
386  SHAPE_LINE_CHAIN* m_currentTarget;
387 };
388 
389 
396 {
397 public:
399  {
400  // Do not leave unitialized members, and keep static analyser quiet:
401  m_placer = NULL;
402  m_dual = false;
403  m_width = 0;
404  m_baselineOffset = 0;
405  }
406 
413  MEANDERED_LINE( MEANDER_PLACER_BASE* aPlacer, bool aIsDual = false ) :
414  m_placer( aPlacer ),
415  m_dual( aIsDual )
416  {
417  // Do not leave unitialized members, and keep static analyser quiet:
418  m_width = 0;
419  m_baselineOffset = 0;
420  }
421 
422  ~MEANDERED_LINE()
423  {
424  Clear();
425  }
426 
435  void AddCorner( const VECTOR2I& aA, const VECTOR2I& aB = VECTOR2I( 0, 0 ) );
436 
443  void AddMeander( MEANDER_SHAPE* aShape );
444 
450  void Clear();
451 
457  void SetWidth( int aWidth )
458  {
459  m_width = aWidth;
460  }
461 
470  void MeanderSegment( const SEG& aSeg, int aBaseIndex = 0 );
471 
473  void SetBaselineOffset( int aOffset )
474  {
475  m_baselineOffset = aOffset;
476  }
477 
483  std::vector<MEANDER_SHAPE*>& Meanders()
484  {
485  return m_meanders;
486  }
487 
497  bool CheckSelfIntersections( MEANDER_SHAPE* aShape, int aClearance );
498 
504  const MEANDER_SETTINGS& Settings() const;
505 
506 private:
507  VECTOR2I m_last;
508 
509  MEANDER_PLACER_BASE* m_placer;
510  std::vector<MEANDER_SHAPE*> m_meanders;
511 
512  bool m_dual;
513  int m_width;
514  int m_baselineOffset;
515 };
516 
517 }
518 
519 #endif // __PNS_MEANDER_H
PNS::MEANDER_SHAPE
Class MEANDER_SETTINGS.
Definition: pns_meander.h:105
PNS::MEANDER_SETTINGS::m_cornerRadiusPercentage
int m_cornerRadiusPercentage
rounding percentage (0 - 100)
Definition: pns_meander.h:88
PNS::MEANDER_SETTINGS::m_step
int m_step
amplitude/spacing adjustment step
Definition: pns_meander.h:82
PNS::MEANDERED_LINE
Class MEANDERED_LINE.
Definition: pns_meander.h:396
PNS::MEANDER_SHAPE::MaxTunableLength
int MaxTunableLength() const
Function MaxTunableLength()
Definition: pns_meander.cpp:623
PNS::MEANDER_SHAPE::Side
bool Side() const
Function Side()
Definition: pns_meander.h:221
PNS::MEANDER_SHAPE::Fit
bool Fit(MEANDER_TYPE aType, const SEG &aSeg, const VECTOR2I &aP, bool aSide)
Function Fit()
Definition: pns_meander.cpp:449
PNS::MEANDERED_LINE::SetBaselineOffset
void SetBaselineOffset(int aOffset)
Function SetBaselineOffset()
Definition: pns_meander.h:473
PNS::MEANDER_SHAPE::CLine
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Function CLine()
Definition: pns_meander.h:241
PNS::MEANDER_SETTINGS::m_lengthTolerance
int m_lengthTolerance
allowable tuning error
Definition: pns_meander.h:90
PNS::MEANDERED_LINE::Clear
void Clear()
Function Clear()
Definition: pns_meander.cpp:606
PNS::MEANDER_SHAPE::MEANDER_SHAPE
MEANDER_SHAPE(MEANDER_PLACER_BASE *aPlacer, int aWidth, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:115
PNS::MEANDER_SETTINGS::m_spacing
int m_spacing
meandering period/spacing (see dialog picture for explanation)
Definition: pns_meander.h:80
PNS::MEANDERED_LINE::CheckSelfIntersections
bool CheckSelfIntersections(MEANDER_SHAPE *aShape, int aClearance)
Function CheckSelfIntersections()
Definition: pns_meander.cpp:423
PNS::MEANDER_SHAPE::Resize
void Resize(int aAmpl)
Function Resize()
Definition: pns_meander.cpp:550
PNS::MEANDER_SHAPE::SetType
void SetType(MEANDER_TYPE aType)
Function SetType()
Definition: pns_meander.h:135
PNS::MEANDERED_LINE::SetWidth
void SetWidth(int aWidth)
Function SetWidth()
Definition: pns_meander.h:457
PNS::MEANDERED_LINE::MeanderSegment
void MeanderSegment(const SEG &aSeg, int aBaseIndex=0)
Function MeanderSegment()
Definition: pns_meander.cpp:46
VECTOR2
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:76
PNS::MEANDERED_LINE::Meanders
std::vector< MEANDER_SHAPE * > & Meanders()
Function Meanders()
Definition: pns_meander.h:483
PNS::MEANDER_SHAPE::Settings
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:34
PNS::MEANDER_SHAPE::Recalculate
void Recalculate()
Function Recalculate()
Definition: pns_meander.cpp:539
PNS::MEANDER_SHAPE::Width
int Width() const
Function Width()
Definition: pns_meander.h:305
PNS::MEANDER_PLACER_BASE
Class MEANDER_PLACER_BASE.
Definition: pns_meander_placer_base.h:49
PNS::MEANDER_SHAPE::BaselineLength
int BaselineLength() const
Function BaselineLength()
Definition: pns_meander.cpp:617
PNS::MEANDER_SHAPE::SetBaseIndex
void SetBaseIndex(int aIndex)
Function SetBaseIndex()
Definition: pns_meander.h:155
PNS::MEANDERED_LINE::AddCorner
void AddCorner(const VECTOR2I &aA, const VECTOR2I &aB=VECTOR2I(0, 0))
Function AddCorner()
Definition: pns_meander.cpp:576
PNS::MEANDER_SETTINGS::m_maxAmplitude
int m_maxAmplitude
maximum meandering amplitude
Definition: pns_meander.h:78
PNS::MEANDER_SETTINGS::m_minAmplitude
int m_minAmplitude
minimum meandering amplitude
Definition: pns_meander.h:76
PNS::MEANDERED_LINE::AddMeander
void AddMeander(MEANDER_SHAPE *aShape)
Function AddMeander()
Definition: pns_meander.cpp:599
PNS::MEANDER_SHAPE::Type
MEANDER_TYPE Type() const
Function Type()
Definition: pns_meander.h:145
PNS::MEANDERED_LINE::Settings
const MEANDER_SETTINGS & Settings() const
Function Settings()
Definition: pns_meander.cpp:40
PNS::MEANDER_SHAPE::End
VECTOR2I End() const
Function End()
Definition: pns_meander.h:231
PNS::MEANDER_SETTINGS
Class MEANDER_SETTINGS.
Definition: pns_meander.h:58
PNS::MEANDER_SETTINGS::m_cornerArcSegments
int m_cornerArcSegments
number of line segments for arc approximation
Definition: pns_meander.h:92
PNS::MEANDER_SHAPE::Amplitude
int Amplitude() const
Function Amplitude()
Definition: pns_meander.h:175
PNS::MEANDER_SETTINGS::m_cornerStyle
MEANDER_STYLE m_cornerStyle
type of corners for the meandered line
Definition: pns_meander.h:86
SEG
Definition: seg.h:37
PNS::MEANDERED_LINE::MEANDERED_LINE
MEANDERED_LINE(MEANDER_PLACER_BASE *aPlacer, bool aIsDual=false)
Constructor.
Definition: pns_meander.h:413
PNS::MEANDER_SHAPE::MakeEmpty
void MakeEmpty()
Function MakeEmpty()
Definition: pns_meander.cpp:561
PNS::MEANDER_SETTINGS::m_targetSkew
int m_targetSkew
target skew value for diff pair de-skewing
Definition: pns_meander.h:94
PNS::MEANDER_SETTINGS::m_targetLength
int m_targetLength
desired length of the tuned line/diff pair
Definition: pns_meander.h:84
SHAPE_LINE_CHAIN
Class SHAPE_LINE_CHAIN.
Definition: shape_line_chain.h:50
PNS::MEANDER_SHAPE::BaseSegment
const SEG & BaseSegment() const
Function BaseSegment()
Definition: pns_meander.h:273
PNS::MEANDER_SHAPE::IsDual
bool IsDual() const
Function IsDual()
Definition: pns_meander.h:211
PNS::MEANDER_SHAPE::MakeCorner
void MakeCorner(VECTOR2I aP1, VECTOR2I aP2=VECTOR2I(0, 0))
Function MakeCorner()
Definition: pns_meander.cpp:587
PNS::MEANDER_SHAPE::BaseIndex
int BaseIndex() const
Function BaseIndex()
Definition: pns_meander.h:165
PNS::MEANDER_SHAPE::SetBaselineOffset
void SetBaselineOffset(int aOffset)
Function SetBaselineOffset()
Definition: pns_meander.h:317