2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2023-09-23 17:33:32 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-18 00:29:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base_units.h> // God forgive me doing this...
|
|
|
|
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_itemset.h"
|
|
|
|
#include "pns_topology.h"
|
|
|
|
#include "pns_meander_skew_placer.h"
|
2021-04-05 00:27:22 +00:00
|
|
|
#include "pns_solid.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
#include "pns_router.h"
|
2016-08-15 15:16:48 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SKEW_PLACER::MEANDER_SKEW_PLACER ( ROUTER* aRouter ) :
|
|
|
|
MEANDER_PLACER ( aRouter )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-05-15 12:49:11 +00:00
|
|
|
// Init temporary variables (do not leave uninitialized members)
|
|
|
|
m_coupledLength = 0;
|
2019-10-31 13:00:01 +00:00
|
|
|
m_padToDieN = 0;
|
|
|
|
m_padToDieP = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_SKEW_PLACER::~MEANDER_SKEW_PLACER( )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDER_SKEW_PLACER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-01-04 13:54:29 +00:00
|
|
|
if( !aStartItem || !aStartItem->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
Router()->SetFailureReason( _( "Please select a differential pair trace you want to tune." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:54:29 +00:00
|
|
|
m_initialSegment = static_cast<LINKED_ITEM*>( aStartItem );
|
|
|
|
m_currentNode = nullptr;
|
|
|
|
m_currentStart = getSnappedStartPoint( m_initialSegment, aP );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_world = Router()->GetWorld( )->Branch();
|
2015-02-18 00:29:54 +00:00
|
|
|
m_originLine = m_world->AssembleLine( m_initialSegment );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
TOPOLOGY topo( m_world );
|
2023-09-23 17:33:32 +00:00
|
|
|
m_tunedPath = topo.AssembleTrivialPath( m_initialSegment, nullptr, true );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( !topo.AssembleDiffPair ( m_initialSegment, m_originPair ) )
|
|
|
|
{
|
|
|
|
Router()->SetFailureReason( _( "Unable to find complementary differential pair "
|
|
|
|
"net for skew tuning. Make sure the names of the nets belonging "
|
|
|
|
"to a differential pair end with either _N/_P or +/-." ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:10:02 +00:00
|
|
|
if( m_originPair.Gap() < 0 )
|
2015-07-02 14:11:15 +00:00
|
|
|
m_originPair.SetGap( Router()->Sizes().DiffPairGap() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( !m_originPair.PLine().SegmentCount() ||
|
|
|
|
!m_originPair.NLine().SegmentCount() )
|
|
|
|
return false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
m_tunedPathP = topo.AssembleTuningPath( m_originPair.PLine().GetLink( 0 ), &m_startPad_p, &m_endPad_p );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
m_padToDieP = 0;
|
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if( m_startPad_p )
|
|
|
|
m_padToDieP += m_startPad_p->GetPadToDie();
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if( m_endPad_p )
|
|
|
|
m_padToDieP += m_endPad_p->GetPadToDie();
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
m_tunedPathN = topo.AssembleTuningPath( m_originPair.NLine().GetLink( 0 ), &m_startPad_n, &m_endPad_n );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
m_padToDieN = 0;
|
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if( m_startPad_n )
|
|
|
|
m_padToDieN += m_startPad_n->GetPadToDie();
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if( m_endPad_n )
|
|
|
|
m_padToDieN += m_endPad_n->GetPadToDie();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
m_world->Remove( m_originLine );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_currentWidth = m_originLine.Width();
|
2015-02-18 00:29:54 +00:00
|
|
|
m_currentEnd = VECTOR2I( 0, 0 );
|
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if ( m_originPair.NetP() == m_originLine.Net() )
|
2019-10-31 13:00:01 +00:00
|
|
|
{
|
2022-08-02 03:23:07 +00:00
|
|
|
m_coupledLength = m_padToDieN + lineLength( m_tunedPathN, m_startPad_n, m_endPad_n );
|
2023-10-06 18:40:49 +00:00
|
|
|
m_lastLength = m_padToDieP + lineLength( m_tunedPathP, m_startPad_p, m_endPad_p );
|
2021-07-03 18:06:30 +00:00
|
|
|
m_tunedPath = m_tunedPathP;
|
2019-10-31 13:00:01 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
else
|
2019-10-31 13:00:01 +00:00
|
|
|
{
|
2022-08-02 03:23:07 +00:00
|
|
|
m_coupledLength = m_padToDieP + lineLength( m_tunedPathP, m_startPad_p, m_endPad_p );
|
2023-10-06 18:40:49 +00:00
|
|
|
m_lastLength = m_padToDieN + lineLength( m_tunedPathN, m_startPad_n, m_endPad_n );
|
2021-07-03 18:06:30 +00:00
|
|
|
m_tunedPath = m_tunedPathN;
|
2019-10-31 13:00:01 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
long long int MEANDER_SKEW_PLACER::origPathLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-02 03:23:07 +00:00
|
|
|
if ( m_originPair.NetP() == m_originLine.Net() )
|
2022-12-01 14:59:18 +00:00
|
|
|
return m_padToDieP + lineLength( m_tunedPath, m_startPad_p, m_endPad_p );
|
2022-08-02 03:23:07 +00:00
|
|
|
|
2022-12-01 14:59:18 +00:00
|
|
|
return m_padToDieN + lineLength( m_tunedPath, m_startPad_n, m_endPad_n );
|
2022-08-02 03:23:07 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-10-08 19:40:20 +00:00
|
|
|
long long int MEANDER_SKEW_PLACER::CurrentSkew() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_lastLength - m_coupledLength;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDER_SKEW_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-02-01 17:36:52 +00:00
|
|
|
bool isPositive = m_originPair.NetP() == m_originLine.Net();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : m_tunedPathP.CItems() )
|
2015-08-19 15:27:23 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( const LINE* l = dyn_cast<const LINE*>( item ) )
|
2023-02-01 17:36:52 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, l, BLUE, 10000, wxT( "tuned-path-skew-p" ) );
|
2023-02-01 17:36:52 +00:00
|
|
|
|
|
|
|
m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 1 : 0 );
|
|
|
|
}
|
2015-08-19 15:27:23 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : m_tunedPathN.CItems() )
|
2015-08-19 15:27:23 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( const LINE* l = dyn_cast<const LINE*>( item ) )
|
2023-02-01 17:36:52 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, l, YELLOW, 10000, wxT( "tuned-path-skew-n" ) );
|
2023-02-01 17:36:52 +00:00
|
|
|
|
|
|
|
m_router->GetInterface()->DisplayPathLine( l->CLine(), isPositive ? 0 : 1 );
|
|
|
|
}
|
2015-08-19 15:27:23 +00:00
|
|
|
}
|
|
|
|
|
2023-10-07 00:42:31 +00:00
|
|
|
return doMove( aP, aEndItem, m_coupledLength + m_settings.m_targetSkew );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
const wxString MEANDER_SKEW_PLACER::TuningInfo( EDA_UNITS aUnits ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
wxString status;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( m_lastStatus )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case TOO_LONG:
|
|
|
|
status = _( "Too long: skew " );
|
|
|
|
break;
|
|
|
|
case TOO_SHORT:
|
|
|
|
status = _( "Too short: skew " );
|
|
|
|
break;
|
|
|
|
case TUNED:
|
|
|
|
status = _( "Tuned: skew " );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return _( "?" );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 04:38:10 +00:00
|
|
|
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_lastLength - m_coupledLength );
|
2022-02-05 02:06:25 +00:00
|
|
|
status += wxT( "/" );
|
2023-10-07 00:42:31 +00:00
|
|
|
status += EDA_UNIT_UTILS::UI::MessageTextFromValue( pcbIUScale, aUnits, m_settings.m_targetSkew );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return status;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|