KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_meander_skew_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 (C) 2016-2023 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_node.h"
23#include "pns_itemset.h"
24#include "pns_topology.h"
26#include "pns_solid.h"
27
28#include "pns_router.h"
29#include "pns_debug_decorator.h"
30
31namespace PNS {
32
34 MEANDER_PLACER ( aRouter )
35{
36 // Init temporary variables (do not leave uninitialized members)
38 m_padToDieN = 0;
39 m_padToDieP = 0;
40}
41
42
44{
45}
46
47
48bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
49{
50 if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T) )
51 {
52 Router()->SetFailureReason( _( "Please select a differential pair track you want to tune." ) );
53 return false;
54 }
55
56 m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
57 m_currentNode = nullptr;
59
60 m_world = Router()->GetWorld( )->Branch();
62
63 TOPOLOGY topo( m_world );
64 m_tunedPath = topo.AssembleTrivialPath( m_initialSegment, nullptr, true );
65
67 {
68 Router()->SetFailureReason( _( "Unable to find complementary differential pair "
69 "net for skew tuning. Make sure the names of the nets belonging "
70 "to a differential pair end with either _N/_P or +/-." ) );
71 return false;
72 }
73
74 if( m_originPair.Gap() < 0 )
75 m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
76
79 return false;
80
82
83 m_padToDieP = 0;
84
85 if( m_startPad_p )
87
88 if( m_endPad_p )
90
92
93 m_padToDieN = 0;
94
95 if( m_startPad_n )
97
98 if( m_endPad_n )
100
102
104 m_currentEnd = VECTOR2I( 0, 0 );
105
106 if ( m_originPair.NetP() == m_originLine.Net() )
107 {
111 }
112 else
113 {
117 }
118
119 return true;
120}
121
122
124{
125 if ( m_originPair.NetP() == m_originLine.Net() )
127
129
130}
131
132
134{
136}
137
138
139bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
140{
141 bool isPositive = m_originPair.NetP() == m_originLine.Net();
142
143 for( const ITEM* item : m_tunedPathP.CItems() )
144 {
145 if( const LINE* l = dyn_cast<const LINE*>( item ) )
146 {
147 PNS_DBG( Dbg(), AddItem, l, BLUE, 10000, wxT( "tuned-path-skew-p" ) );
148
149 m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 1 : 0 );
150 }
151 }
152
153 for( const ITEM* item : m_tunedPathN.CItems() )
154 {
155 if( const LINE* l = dyn_cast<const LINE*>( item ) )
156 {
157 PNS_DBG( Dbg(), AddItem, l, YELLOW, 10000, wxT( "tuned-path-skew-n" ) );
158
159 m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 0 : 1 );
160 }
161 }
162
163 return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew.Opt(),
166}
167
168
170{
172}
173
174}
T Min() const
Definition: minoptmax.h:33
T Max() const
Definition: minoptmax.h:34
T Opt() const
Definition: minoptmax.h:35
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
ROUTER * m_router
Definition: pns_algo_base.h:87
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
int Gap() const
NET_HANDLE NetP() const
void SetGap(int aGap)
const std::vector< ITEM * > & CItems() const
Definition: pns_itemset.h:88
Base class for PNS router board items.
Definition: pns_item.h:97
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
@ SEGMENT_T
Definition: pns_item.h:106
bool OfKind(int aKindMask) const
Definition: pns_item.h:178
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:62
int SegmentCount() const
Definition: pns_line.h:140
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:157
int m_currentWidth
Meander settings.
MEANDER_SETTINGS m_settings
The current end point.
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)
Single track length matching/meandering tool.
bool doMove(const VECTOR2I &aP, ITEM *aEndItem, long long int aTargetLength, long long int aTargetMin, long long int aTargetMax)
LINKED_ITEM * m_initialSegment
Total length added by pad to die size.
VECTOR2I m_currentStart
Current world state.
long long int m_lastLength
MINOPTMAX< int > m_targetSkew
Definition: pns_meander.h:101
long long int origPathLength() const override
current routing start point (end of tail, beginning of head)
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
long long int TuningResult() const override
Return the resultant length or skew of the tuned traces.
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:143
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:906
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=nullptr, bool aStopAtLockedJoints=false, bool aFollowLockedSegments=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition: pns_node.cpp:1044
virtual void DisplayPathLine(const SHAPE_LINE_CHAIN &aLine, int aImportance)=0
ROUTER_IFACE * GetInterface() const
Definition: pns_router.h:223
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:218
NODE * GetWorld() const
Definition: pns_router.h:169
int GetPadToDie() const
Definition: pns_solid.h:107
const DIFF_PAIR AssembleDiffPair(SEGMENT *aStart)
const ITEM_SET AssembleTrivialPath(ITEM *aStart, std::pair< const JOINT *, const JOINT * > *aTerminalJoints=nullptr, bool aFollowLockedSegments=false)
Assemble a trivial path between two joints given a starting item.
const ITEM_SET AssembleTuningPath(ITEM *aStart, SOLID **aStartPad=nullptr, SOLID **aEndPad=nullptr)
Like AssembleTrivialPath, but follows the track length algorithm, which discards segments that are fu...
@ BLUE
Definition: color4d.h:56
@ YELLOW
Definition: color4d.h:67
#define _(s)
Push and Shove diff pair dimensions (gap) settings dialog.
#define PNS_DBG(dbg, method,...)
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691