KiCad PCB EDA Suite
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 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 <base_units.h> // God forgive me doing this...
23
24#include "pns_node.h"
25#include "pns_itemset.h"
26#include "pns_topology.h"
28#include "pns_solid.h"
29
30#include "pns_router.h"
31#include "pns_debug_decorator.h"
32
33namespace PNS {
34
36 MEANDER_PLACER ( aRouter )
37{
38 // Init temporary variables (do not leave uninitialized members)
40 m_padToDieN = 0;
41 m_padToDieP = 0;
42}
43
44
46{
47}
48
49
50bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
51{
52 if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T) )
53 {
54 Router()->SetFailureReason( _( "Please select a differential pair trace you want to tune." ) );
55 return false;
56 }
57
58 m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
59 m_currentNode = nullptr;
61
62 m_world = Router()->GetWorld( )->Branch();
64
65 TOPOLOGY topo( m_world );
67
69 {
70 Router()->SetFailureReason( _( "Unable to find complementary differential pair "
71 "net for skew tuning. Make sure the names of the nets belonging "
72 "to a differential pair end with either _N/_P or +/-." ) );
73 return false;
74 }
75
76 if( m_originPair.Gap() < 0 )
77 m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
78
81 return false;
82
84
85 m_padToDieP = 0;
86
87 if( m_startPad_p )
89
90 if( m_endPad_p )
92
94
95 m_padToDieN = 0;
96
97 if( m_startPad_n )
99
100 if( m_endPad_n )
102
104
106 m_currentEnd = VECTOR2I( 0, 0 );
107
108 if ( m_originPair.NetP() == m_originLine.Net() )
109 {
113 }
114 else
115 {
119 }
120
121 return true;
122}
123
124
126{
127 if ( m_originPair.NetP() == m_originLine.Net() )
129
131
132}
133
134
136{
138}
139
140
141bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
142{
143 for( const ITEM* item : m_tunedPathP.CItems() )
144 {
145 if( const LINE* l = dyn_cast<const LINE*>( item ) )
146 PNS_DBG( Dbg(), AddItem, l, BLUE, 10000, wxT( "tuned-path-skew-p" ) );
147 }
148
149 for( const ITEM* item : m_tunedPathN.CItems() )
150 {
151 if( const LINE* l = dyn_cast<const LINE*>( item ) )
152 PNS_DBG( Dbg(), AddItem, l, YELLOW, 10000, wxT( "tuned-path-skew-n" ) );
153 }
154
155 return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew );
156}
157
158
159const wxString MEANDER_SKEW_PLACER::TuningInfo( EDA_UNITS aUnits ) const
160{
161 wxString status;
162
163 switch( m_lastStatus )
164 {
165 case TOO_LONG:
166 status = _( "Too long: skew " );
167 break;
168 case TOO_SHORT:
169 status = _( "Too short: skew " );
170 break;
171 case TUNED:
172 status = _( "Tuned: skew " );
173 break;
174 default:
175 return _( "?" );
176 }
177
179 status += wxT( "/" );
181
182 return status;
183}
184
185}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
int Gap() const
int NetP() const
void SetGap(int aGap)
const ENTRIES & CItems() const
Definition: pns_itemset.h:136
Base class for PNS router board items.
Definition: pns_item.h:56
@ SEGMENT_T
Definition: pns_item.h:66
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:140
int Net() const
Definition: pns_item.h:154
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:61
int SegmentCount() const
Definition: pns_line.h:139
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:156
int m_currentWidth
Meander settings.
int m_padToDieLength
Width of the meandered trace(s).
MEANDER_SETTINGS m_settings
The current end point.
NODE * m_world
Total length added by pad to die size.
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.
TUNING_STATUS m_lastStatus
LINKED_ITEM * m_initialSegment
bool doMove(const VECTOR2I &aP, ITEM *aEndItem, long long int aTargetLength)
VECTOR2I m_currentStart
Current world state.
long long int m_lastLength
long long int origPathLength() const override
current routing start point (end of tail, beginning of head)
const wxString TuningInfo(EDA_UNITS aUnits) const override
Return a string describing the status and length of the tuned traces.
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:139
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:873
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:983
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:205
NODE * GetWorld() const
Definition: pns_router.h:156
int GetPadToDie() const
Definition: pns_solid.h:103
const DIFF_PAIR AssembleDiffPair(SEGMENT *aStart)
const ITEM_SET AssembleTrivialPath(ITEM *aStart, std::pair< JOINT *, 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)
EDA_UNITS
Definition: eda_units.h:43
wxString MessageTextFromValue(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, double aValue, bool aAddUnitsText=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
A helper to convert the double length aValue to a string in inches, millimeters, or unscaled units.
Definition: eda_units.cpp:323
Push and Shove diff pair dimensions (gap) settings dialog.
#define PNS_DBG(dbg, method,...)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618