KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_meander_placer.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 The KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
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_debug_decorator.h"
23#include "pns_itemset.h"
24#include "pns_meander_placer.h"
25#include "pns_node.h"
26#include "pns_router.h"
27#include "pns_solid.h"
28#include "pns_topology.h"
29
31
33
34namespace PNS {
35
37 MEANDER_PLACER_BASE( aRouter )
38{
39 m_currentNode = nullptr;
40
41 // Init temporary variables (do not leave uninitialized members)
42 m_initialSegment = nullptr;
43 m_lastLength = 0;
44 m_lastDelay = 0;
48 m_netClass = nullptr;
49}
50
51
55
56
57NODE* MEANDER_PLACER::CurrentNode( bool aLoopsRemoved ) const
58{
59 if( !m_currentNode )
60 return m_world;
61
62 return m_currentNode;
63}
64
65
66bool MEANDER_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
67{
68 if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
69 {
70 Router()->SetFailureReason( _( "Please select a track whose length you want to tune." ) );
71 return false;
72 }
73
74 m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
75 m_currentNode = nullptr;
77
78 m_world = Router()->GetWorld()->Branch();
79 m_originLine = m_world->AssembleLine( m_initialSegment );
80
81 TOPOLOGY topo( m_world );
83
86
87 if( m_startPad_n )
88 {
89 m_padToDieLength += m_startPad_n->GetPadToDie();
90 m_padToDieDelay += m_startPad_n->GetPadToDieDelay();
91 }
92
93 if( m_endPad_n )
94 {
95 m_padToDieLength += m_endPad_n->GetPadToDie();
96 m_padToDieDelay += m_endPad_n->GetPadToDieDelay();
97 }
98
99 m_world->Remove( m_originLine );
100
102 m_currentEnd = VECTOR2I( 0, 0 );
103
104 const BOARD_CONNECTED_ITEM* conItem = static_cast<BOARD_CONNECTED_ITEM*>( aStartItem->GetSourceItem() );
105 m_netClass = conItem->GetEffectiveNetClass();
106
108
109 return true;
110}
111
112
117
118
123
124
126{
127 // If this is a time domain tuning, calculate the target length for the desired total delay
128 if( m_settings.m_isTimeDomain )
129 {
130 const int64_t curDelay = origPathDelay();
131
132 const int64_t desiredDelayMin = m_settings.m_targetLengthDelay.Min();
133 const int64_t desiredDelayOpt = m_settings.m_targetLengthDelay.Opt();
134 const int64_t desiredDelayMax = m_settings.m_targetLengthDelay.Max();
135
136 const int64_t delayDifferenceOpt = desiredDelayOpt - curDelay;
137
138 const int64_t curLength = origPathLength();
139 const int64_t lengthDiffMin = m_router->GetInterface()->CalculateLengthForDelay(
140 desiredDelayOpt - desiredDelayMin, m_currentWidth, false, m_router->Sizes().DiffPairGap(),
141 m_router->GetCurrentLayer(), m_netClass );
142 int64_t lengthDiffOpt = m_router->GetInterface()->CalculateLengthForDelay(
143 std::abs( delayDifferenceOpt ), m_currentWidth, false, m_router->Sizes().DiffPairGap(),
144 m_router->GetCurrentLayer(), m_netClass );
145 const int64_t lengthDiffMax = m_router->GetInterface()->CalculateLengthForDelay(
146 desiredDelayMax - desiredDelayOpt, m_currentWidth, false, m_router->Sizes().DiffPairGap(),
147 m_router->GetCurrentLayer(), m_netClass );
148
149 lengthDiffOpt = delayDifferenceOpt > 0 ? lengthDiffOpt : -lengthDiffOpt;
150
151 m_settings.m_targetLength.SetMin( curLength + lengthDiffOpt - lengthDiffMin );
152 m_settings.m_targetLength.SetOpt( curLength + lengthDiffOpt );
153 m_settings.m_targetLength.SetMax( curLength + lengthDiffOpt + lengthDiffMax );
154 }
155}
156
157
158bool MEANDER_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
159{
161
162 return doMove( aP, aEndItem, m_settings.m_targetLength.Opt(), m_settings.m_targetLength.Min(),
163 m_settings.m_targetLength.Max() );
164}
165
166
167bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int aTargetLength,
168 long long int aTargetMin, long long int aTargetMax )
169{
170 if( m_currentStart == aP )
171 return false;
172
173 if( m_currentNode )
174 delete m_currentNode;
175
176 m_currentNode = m_world->Branch();
177
178 SHAPE_LINE_CHAIN pre, tuned, post;
179
180 m_originLine.CLine().Split( m_currentStart, aP, pre, tuned, post );
181
182 m_result = MEANDERED_LINE( this, false );
183 m_result.SetWidth( m_originLine.Width() );
184 m_result.SetBaselineOffset( 0 );
185
186 for( int i = 0; i < tuned.SegmentCount(); i++ )
187 {
188 if( tuned.IsArcSegment( i ) )
189 {
190 ssize_t arcIndex = tuned.ArcIndex( i );
191 m_result.AddArc( tuned.Arc( arcIndex ) );
192 i = tuned.NextShape( i );
193
194 // NextShape will return -1 if last shape
195 if( i < 0 )
196 i = tuned.SegmentCount();
197
198 continue;
199 }
200
201 bool side = false;
202 const SEG s = tuned.CSegment( i );
203
204 if( m_settings.m_initialSide == 0 )
205 side = s.Side( aP ) < 0;
206 else
207 side = m_settings.m_initialSide < 0;
208
209 m_result.AddCorner( s.A );
210 m_result.MeanderSegment( s, side );
211 m_result.AddCorner( s.B );
212 }
213
214 long long int lineLen = origPathLength();
215 int64_t lineDelay = origPathDelay();
216
217 m_lastLength = lineLen;
220
221 if( lineLen > m_settings.m_targetLength.Max() )
222 {
224 }
225 else
226 {
227 m_lastLength = lineLen - tuned.Length();
228
229 if( m_settings.m_isTimeDomain )
230 {
232 - m_router->GetInterface()->CalculateDelayForShapeLineChain(
233 tuned, m_currentWidth, false, m_router->Sizes().DiffPairGap(),
234 m_router->GetCurrentLayer(), m_netClass );
235 }
236
237 tuneLineLength( m_result, aTargetLength - lineLen );
238 }
239
240 for( const ITEM* item : m_tunedPath.CItems() )
241 {
242 if( const LINE* l = dyn_cast<const LINE*>( item ) )
243 {
244 PNS_DBG( Dbg(), AddItem, l, BLUE, 30000, wxT( "tuned-line" ) );
245
246 m_router->GetInterface()->DisplayPathLine( l->CLine(), 1 );
247 }
248 }
249
250 if( m_lastStatus != TOO_LONG )
251 {
252 tuned.Clear();
253
254 for( MEANDER_SHAPE* m : m_result.Meanders() )
255 {
256 if( m->Type() != MT_EMPTY )
257 {
258 tuned.Append ( m->CLine( 0 ) );
259 }
260 }
261
262 m_lastLength += tuned.Length();
263
264 if( m_settings.m_isTimeDomain )
265 {
266 m_lastDelay += m_router->GetInterface()->CalculateDelayForShapeLineChain(
267 tuned, m_currentWidth, false, m_router->Sizes().DiffPairGap(), m_router->GetCurrentLayer(),
268 m_netClass );
269 }
270
271 if( m_lastLength > aTargetMax )
273 else if( m_lastLength < aTargetMin )
275 else
277 }
278
279 m_finalShape.Clear();
280
281 if( m_settings.m_keepEndpoints )
282 {
283 pre.Simplify();
284 tuned.Simplify();
285 post.Simplify();
286
287 m_finalShape.Append( pre );
288 m_finalShape.Append( tuned );
289 m_finalShape.Append( post );
290 }
291 else
292 {
293 m_finalShape.Append( pre );
294 m_finalShape.Append( tuned );
295 m_finalShape.Append( post );
296 m_finalShape.Simplify();
297 }
298
299 return true;
300}
301
302
303bool MEANDER_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish )
304{
305 if( !m_currentNode )
306 return false;
307
311
312 return true;
313}
314
315
317{
318 m_world->KillChildren();
319 return true;
320}
321
322
324{
325 return m_currentTrace.SegmentCount() > 0;
326}
327
328
330{
331 if( m_currentNode )
333
334 m_currentNode = nullptr;
335 return true;
336}
337
338
340{
341 LINE l( m_originLine, aShape->CLine( 0 ) );
342
343 if( m_currentNode->CheckColliding( &l ) )
344 return false;
345
346 int w = aShape->Width();
347 int clearance = w + m_settings.m_spacing;
348
349 return m_result.CheckSelfIntersections( aShape, clearance );
350}
351
352
358
360{
361 return m_tunedPath;
362}
363
365{
366 return m_currentStart;
367}
368
370{
371 return m_currentEnd;
372}
373
375{
376 return m_initialSegment->Layers().Start();
377}
378
379
381{
382 if( m_lastLength )
383 return m_lastLength;
384 else
385 return origPathLength();
386}
387
388
390{
391 if( m_lastDelay )
392 return m_lastDelay;
393 else
394 return origPathDelay();
395}
396
397
402
403}
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
ROUTER * Router() const
Return current router settings.
ROUTER * m_router
DEBUG_DECORATOR * Dbg() const
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * GetSourceItem() const
Definition pns_item.h:202
bool OfKind(int aKindMask) const
Definition pns_item.h:181
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition pns_line.h:62
Represent a set of meanders fitted over a single or two lines.
void tuneLineLength(MEANDERED_LINE &aTuned, long long int aElongation)
Take a set of meanders in aTuned and tunes their length to extend the original line length by aElonga...
TUNING_STATUS
< Result of the length tuning operation
int m_currentWidth
Meander settings.
MEANDER_SETTINGS m_settings
The current end point.
int64_t lineDelay(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad) const
Calculate the total delay of the line represented by an item set (tracks and vias)
NODE * m_world
Width of the meandered trace(s).
VECTOR2I getSnappedStartPoint(LINKED_ITEM *aStartItem, VECTOR2I aStartPoint)
long long int lineLength(const ITEM_SET &aLine, const SOLID *aStartPad, const SOLID *aEndPad) const
Calculate the total length of the line represented by an item set (tracks and vias)
virtual bool FixRoute(const VECTOR2I &aP, ITEM *aEndItem, bool aForceFinish=false) override
Function FixRoute()
bool doMove(const VECTOR2I &aP, ITEM *aEndItem, long long int aTargetLength, long long int aTargetMin, long long int aTargetMax)
virtual bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
virtual long long int origPathLength() const
int CurrentLayer() const override
Function CurrentLayer()
virtual void calculateTimeDomainTargets()
current routing start point (end of tail, beginning of head)
int m_padToDieDelay
The netclass for the placed segments.
const VECTOR2I & CurrentEnd() const override
Function CurrentEnd()
const VECTOR2I & CurrentStart() const override
Function CurrentStart()
long long int TuningLengthResult() const override
Return the resultant length or skew of the tuned traces.
bool AbortPlacement() override
int64_t TuningDelayResult() const override
Return the resultant delay or skew of the tuned traces.
bool HasPlacedAnything() const override
NODE * CurrentNode(bool aLoopsRemoved=false) const override
Function CurrentNode()
LINKED_ITEM * m_initialSegment
Total length added by pad to die size.
SHAPE_LINE_CHAIN m_finalShape
const ITEM_SET TunedPath() override
const ITEM_SET Traces() override
Function Traces()
MEANDER_PLACER(ROUTER *aRouter)
virtual int64_t origPathDelay() const
bool CheckFit(MEANDER_SHAPE *aShape) override
Checks if it's OK to place the shape aShape (i.e.
VECTOR2I m_currentStart
Current world state.
TUNING_STATUS TuningStatus() const override
Return the tuning status (too short, too long, etc.) of the trace(s) being tuned.
virtual bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
int m_padToDieLength
Total length added by pad to die size.
bool CommitPlacement() override
The geometry of a single meander.
int Width() const
const SHAPE_LINE_CHAIN & CLine(int aShape) const
Keep the router "world" - i.e.
Definition pns_node.h:240
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition pns_node.cpp:157
void SetFailureReason(const wxString &aReason)
Definition pns_router.h:231
void CommitRouting()
NODE * GetWorld() const
Definition pns_router.h:182
const ITEM_SET AssembleTuningPath(ROUTER_IFACE *aRouterIface, ITEM *aStart, SOLID **aStartPad=nullptr, SOLID **aEndPad=nullptr)
Like AssembleTrivialPath, but follows the track length algorithm, which discards segments that are fu...
Definition seg.h:42
VECTOR2I A
Definition seg.h:49
VECTOR2I B
Definition seg.h:50
int Side(const VECTOR2I &aP) const
Determine on which side of directed line passing via segment ends point aP lies.
Definition seg.h:143
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
void Clear()
Remove all points from the line chain.
void Simplify(int aTolerance=0)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
int NextShape(int aPointIndex) const
Return the vertex index of the next shape in the chain, or -1 if aPointIndex is the last shape.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
bool IsArcSegment(size_t aSegment) const
long long int Length() const
Return length of the line chain in Euclidean metric.
@ BLUE
Definition color4d.h:56
#define _(s)
Push and Shove diff pair dimensions (gap) settings dialog.
@ MT_EMPTY
Definition pns_meander.h:49
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
#define PNS_DBG(dbg, method,...)
int clearance
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:61
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695