KiCad PCB EDA Suite
pns_meander_placer_base.cpp
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 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 #include "pns_router.h"
23 #include "pns_meander.h"
25 
26 namespace PNS {
27 
29  PLACEMENT_ALGO( aRouter )
30 {
31  m_currentWidth = 0;
32 }
33 
34 
36 {
37 }
38 
39 
41 {
42  int a = m_settings.m_maxAmplitude + aSign * m_settings.m_step;
44 
46 }
47 
48 
50 {
51  int s = m_settings.m_spacing + aSign * m_settings.m_step;
52  s = std::max( s, 2 * m_currentWidth );
53 
55 }
56 
57 
59 {
60  m_settings = aSettings;
61 }
62 
63 
65  const VECTOR2I& aTuneStart,
66  const VECTOR2I& aCursorPos,
67  SHAPE_LINE_CHAIN& aPre,
68  SHAPE_LINE_CHAIN& aTuned,
69  SHAPE_LINE_CHAIN& aPost )
70 {
71  VECTOR2I cp ( aCursorPos );
72 
73  if ( cp == aTuneStart ) // we don't like tuning segments with 0 length
74  {
75  int idx = aOrigin.FindSegment( cp );
76  if( idx >= 0 )
77  {
78  const SEG& s = aOrigin.CSegment( idx );
79  cp += (s.B - s.A).Resize(2);
80  } else
81  cp += VECTOR2I (2, 5); // some arbitrary value that is not 45 degrees oriented
82  }
83 
84  VECTOR2I n = aOrigin.NearestPoint( cp );
85  VECTOR2I m = aOrigin.NearestPoint( aTuneStart );
86 
87  SHAPE_LINE_CHAIN l( aOrigin );
88  l.Split( n );
89  l.Split( m );
90 
91  int i_start = l.Find( m );
92  int i_end = l.Find( n );
93 
94  if( i_start > i_end )
95  {
96  l = l.Reverse();
97  i_start = l.Find( m );
98  i_end = l.Find( n );
99  }
100 
101  aPre = l.Slice( 0, i_start );
102  aPost = l.Slice( i_end, -1 );
103  aTuned = l.Slice( i_start, i_end );
104 
105  aTuned.Simplify();
106 }
107 
108 
109 void MEANDER_PLACER_BASE::tuneLineLength( MEANDERED_LINE& aTuned, int aElongation )
110 {
111  int remaining = aElongation;
112  bool finished = false;
113 
114  for( MEANDER_SHAPE* m : aTuned.Meanders() )
115  {
116  if( m->Type() != MT_CORNER )
117  {
118  if( remaining >= 0 )
119  remaining -= m->MaxTunableLength() - m->BaselineLength();
120 
121  if( remaining < 0 )
122  {
123  if( !finished )
124  {
125  MEANDER_TYPE newType;
126 
127  if( m->Type() == MT_START || m->Type() == MT_SINGLE )
128  newType = MT_SINGLE;
129  else
130  newType = MT_FINISH;
131 
132  m->SetType( newType );
133  m->Recalculate();
134 
135  finished = true;
136  } else {
137  m->MakeEmpty();
138  }
139  }
140  }
141  }
142 
143  remaining = aElongation;
144  int meanderCount = 0;
145 
146  for(MEANDER_SHAPE* m : aTuned.Meanders())
147  {
148  if( m->Type() != MT_CORNER && m->Type() != MT_EMPTY )
149  {
150  if(remaining >= 0)
151  {
152  remaining -= m->MaxTunableLength() - m->BaselineLength();
153  meanderCount ++;
154  }
155  }
156  }
157 
158  int balance = 0;
159 
160  if( meanderCount )
161  balance = -remaining / meanderCount;
162 
163  if( balance >= 0 )
164  {
165  for( MEANDER_SHAPE* m : aTuned.Meanders() )
166  {
167  if( m->Type() != MT_CORNER && m->Type() != MT_EMPTY )
168  {
169  m->Resize( std::max( m->Amplitude() - balance / 2, m_settings.m_minAmplitude ) );
170  }
171  }
172  }
173 }
174 
175 
177 {
178  return m_settings;
179 }
180 
181 
182 int MEANDER_PLACER_BASE::compareWithTolerance( int aValue, int aExpected, int aTolerance ) const
183 {
184  if( aValue < aExpected - aTolerance )
185  return -1;
186  else if( aValue > aExpected + aTolerance )
187  return 1;
188  else
189  return 0;
190 }
191 
192 }
int Split(const VECTOR2I &aP)
Function Split()
int m_minAmplitude
minimum meandering amplitude
Definition: pns_meander.h:76
const SHAPE_LINE_CHAIN Reverse() const
Function Reverse()
Class MEANDER_SETTINGS.
Definition: pns_meander.h:104
MEANDER_TYPE
Shapes of available meanders.
Definition: pns_meander.h:35
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Class MEANDER_SETTINGS.
Definition: pns_meander.h:57
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Function Slice()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:589
virtual void UpdateSettings(const MEANDER_SETTINGS &aSettings)
int m_currentWidth
width of the meandered trace(s)
Class PLACEMENT_ALGO.
SHAPE_LINE_CHAIN & Simplify()
Function Simplify()
const SEG CSegment(int aIndex) const
Function CSegment()
int Find(const VECTOR2I &aP) const
Function Find()
int m_step
amplitude/spacing adjustment step
Definition: pns_meander.h:82
std::vector< MEANDER_SHAPE * > & Meanders()
Function Meanders()
Definition: pns_meander.h:483
void tuneLineLength(MEANDERED_LINE &aTuned, int aElongation)
Function tuneLineLength()
virtual void SpacingStep(int aSign)
Function SpacingStep()
int FindSegment(const VECTOR2I &aP) const
Function FindSegment()
Class MEANDERED_LINE.
Definition: pns_meander.h:395
Definition: seg.h:36
int compareWithTolerance(int aValue, int aExpected, int aTolerance=0) const
Function compareWithTolerance()
MEANDER_SETTINGS m_settings
meandering settings
#define max(a, b)
Definition: auxiliary.h:86
Class SHAPE_LINE_CHAIN.
VECTOR2I A
Definition: seg.h:46
virtual const MEANDER_SETTINGS & MeanderSettings() const
Function MeanderSettings()
virtual void AmplitudeStep(int aSign)
Function AmplitudeStep()
int m_spacing
meandering period/spacing (see dialog picture for explanation)
Definition: pns_meander.h:80
Push and Shove diff pair dimensions (gap) settings dialog.
void cutTunedLine(const SHAPE_LINE_CHAIN &aOrigin, const VECTOR2I &aTuneStart, const VECTOR2I &aCursorPos, SHAPE_LINE_CHAIN &aPre, SHAPE_LINE_CHAIN &aTuned, SHAPE_LINE_CHAIN &aPost)
Function cutTunedLine()
int m_maxAmplitude
maximum meandering amplitude
Definition: pns_meander.h:78
VECTOR2I B
Definition: seg.h:47