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 <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 <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 
29 #include "pns_router.h"
30 #include "pns_debug_decorator.h"
31 
32 namespace PNS {
33 
35  MEANDER_PLACER ( aRouter )
36 {
37  // Init temporary variables (do not leave uninitialized members)
38  m_coupledLength = 0;
39  m_padToDieN = 0;
40  m_padToDieP = 0;
41 }
42 
43 
45 {
46 }
47 
48 
49 bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
50 {
51  if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T) )
52  {
53  Router()->SetFailureReason( _( "Please select a differential pair trace you want to tune." ) );
54  return false;
55  }
56 
57  m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
58  m_currentNode = nullptr;
60 
61  m_world = Router()->GetWorld( )->Branch();
63 
64  TOPOLOGY topo( m_world );
66 
68  {
69  Router()->SetFailureReason( _( "Unable to find complementary differential pair "
70  "net for skew tuning. Make sure the names of the nets belonging "
71  "to a differential pair end with either _N/_P or +/-." ) );
72  return false;
73  }
74 
75  if( m_originPair.Gap() < 0 )
76  m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
77 
78  if( !m_originPair.PLine().SegmentCount() ||
80  return false;
81 
84 
86 
88  m_currentEnd = VECTOR2I( 0, 0 );
91 
92  if ( m_originPair.PLine().Net() == m_originLine.Net() )
93  {
96  }
97  else
98  {
101  }
102 
103  return true;
104 }
105 
106 
108 {
109  return itemsetLength ( m_tunedPath );
110 }
111 
112 
113 long long int MEANDER_SKEW_PLACER::itemsetLength( const ITEM_SET& aSet ) const
114 {
115  long long int total = m_padToDieLenth;
116  for( const ITEM* item : aSet.CItems() )
117  {
118  if( const LINE* l = dyn_cast<const LINE*>( item ) )
119  {
120  total += l->CLine().Length();
121  }
122  }
123 
124  return total;
125 }
126 
127 
128 long long int MEANDER_SKEW_PLACER::currentSkew() const
129 {
130  return m_lastLength - m_coupledLength;
131 }
132 
133 
134 bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
135 {
136  for( const ITEM* item : m_tunedPathP.CItems() )
137  {
138  if( const LINE* l = dyn_cast<const LINE*>( item ) )
139  Dbg()->AddLine( l->CLine(), 5, 10000 );
140  }
141 
142  for( const ITEM* item : m_tunedPathN.CItems() )
143  {
144  if( const LINE* l = dyn_cast<const LINE*>( item ) )
145  Dbg()->AddLine( l->CLine(), 4, 10000 );
146  }
147 
148  return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew );
149 }
150 
151 
152 const wxString MEANDER_SKEW_PLACER::TuningInfo( EDA_UNITS aUnits ) const
153 {
154  wxString status;
155 
156  switch( m_lastStatus )
157  {
158  case TOO_LONG:
159  status = _( "Too long: skew " );
160  break;
161  case TOO_SHORT:
162  status = _( "Too short: skew " );
163  break;
164  case TUNED:
165  status = _( "Tuned: skew " );
166  break;
167  default:
168  return _( "?" );
169  }
170 
171  status += ::MessageTextFromValue( aUnits, m_lastLength - m_coupledLength );
172  status += "/";
173  status += ::MessageTextFromValue( aUnits, m_settings.m_targetSkew );
174 
175  return status;
176 }
177 
178 }
int GetTotalPadToDieLength(const LINE &aLine) const
Base class for PNS router board items.
Definition: pns_item.h:55
ROUTER * Router() const
Return current router settings.
Definition: pns_algo_base.h:54
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:125
virtual void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType=0, int aWidth=0, const std::string aName="")
Implementation of conversion functions that require both schematic and board internal units.
int Gap() const
int SegmentCount() const
Definition: pns_line.h:139
long long int itemsetLength(const ITEM_SET &aSet) const
const DIFF_PAIR AssembleDiffPair(SEGMENT *aStart)
TUNING_STATUS m_lastStatus
long long int m_lastLength
LINKED_ITEM * m_initialSegment
Represents a track on a PCB, connecting two non-trivial joints (that is, vias, pads,...
Definition: pns_line.h:60
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
NODE * Branch()
Create a lightweight copy (called branch) of self that tracks the changes (added/removed items) wrs t...
Definition: pns_node.cpp:124
int m_currentWidth
Meander settings.
void Remove(ARC *aArc)
Remove an item from this branch.
Definition: pns_node.cpp:804
void SetGap(int aGap)
const ITEM_SET AssembleTrivialPath(ITEM *aStart)
const LINE AssembleLine(LINKED_ITEM *aSeg, int *aOriginSegmentIndex=NULL, bool aStopAtLockedJoints=false)
Follow the joint map to assemble a line connecting two non-trivial joints starting from segment aSeg.
Definition: pns_node.cpp:912
int Net() const
Definition: pns_item.h:148
NODE * m_world
Total length added by pad to die size.
bool doMove(const VECTOR2I &aP, ITEM *aEndItem, long long int aTargetLength)
DEBUG_DECORATOR * Dbg() const
Definition: pns_algo_base.h:78
void SetFailureReason(const wxString &aReason)
Definition: pns_router.h:210
Single track length matching/meandering tool.
const wxString TuningInfo(EDA_UNITS aUnits) const override
Return a string describing the status and length of the tuned traces.
VECTOR2I getSnappedStartPoint(LINKED_ITEM *aStartItem, VECTOR2I aStartPoint)
Pointer to world to search colliding items.
int m_padToDieLenth
Width of the meandered trace(s).
EDA_UNITS
Definition: eda_units.h:38
VECTOR2I m_currentStart
Current world state.
MEANDER_SETTINGS m_settings
The current end point.
bool Start(const VECTOR2I &aP, ITEM *aStartItem) override
Function Start()
#define _(s)
Definition: 3d_actions.cpp:33
bool OfKind(int aKindMask) const
Return true if the item's type matches the mask aKindMask.
Definition: pns_item.h:134
const ENTRIES & CItems() const
Definition: pns_itemset.h:139
int Width() const
Return true if the line is geometrically identical as line aOther.
Definition: pns_line.h:156
long long int origPathLength() const override
current routing start point (end of tail, beginning of head)
Push and Shove diff pair dimensions (gap) settings dialog.
NODE * GetWorld() const
Definition: pns_router.h:158
bool Move(const VECTOR2I &aP, ITEM *aEndItem) override
Function Move()