2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 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 "pns_meander_placer_base.h"
|
2019-10-31 13:00:01 +00:00
|
|
|
#include "pns_meander.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_solid.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_PLACER_BASE::MEANDER_PLACER_BASE( ROUTER* aRouter ) :
|
|
|
|
PLACEMENT_ALGO( aRouter )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2019-10-31 13:00:01 +00:00
|
|
|
m_world = NULL;
|
2015-06-19 08:55:37 +00:00
|
|
|
m_currentWidth = 0;
|
2019-10-31 13:00:01 +00:00
|
|
|
m_padToDieLenth = 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_PLACER_BASE::~MEANDER_PLACER_BASE()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_PLACER_BASE::AmplitudeStep( int aSign )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int a = m_settings.m_maxAmplitude + aSign * m_settings.m_step;
|
|
|
|
a = std::max( a, m_settings.m_minAmplitude );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_settings.m_maxAmplitude = a;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_PLACER_BASE::SpacingStep( int aSign )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
int s = m_settings.m_spacing + aSign * m_settings.m_step;
|
|
|
|
s = std::max( s, 2 * m_currentWidth );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_settings.m_spacing = s;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void MEANDER_PLACER_BASE::UpdateSettings( const MEANDER_SETTINGS& aSettings )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_settings = aSettings;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
void MEANDER_PLACER_BASE::cutTunedLine( const SHAPE_LINE_CHAIN& aOrigin, const VECTOR2I& aTuneStart,
|
|
|
|
const VECTOR2I& aCursorPos, SHAPE_LINE_CHAIN& aPre,
|
|
|
|
SHAPE_LINE_CHAIN& aTuned, SHAPE_LINE_CHAIN& aPost )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-03-05 09:02:29 +00:00
|
|
|
VECTOR2I cp ( aCursorPos );
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( cp == aTuneStart ) // we don't like tuning segments with 0 length
|
2015-03-05 09:02:29 +00:00
|
|
|
{
|
|
|
|
int idx = aOrigin.FindSegment( cp );
|
2020-11-24 22:16:41 +00:00
|
|
|
|
2015-06-19 08:55:37 +00:00
|
|
|
if( idx >= 0 )
|
2015-03-05 09:02:29 +00:00
|
|
|
{
|
|
|
|
const SEG& s = aOrigin.CSegment( idx );
|
|
|
|
cp += (s.B - s.A).Resize(2);
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-05 09:02:29 +00:00
|
|
|
cp += VECTOR2I (2, 5); // some arbitrary value that is not 45 degrees oriented
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
2015-03-05 09:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I n = aOrigin.NearestPoint( cp );
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I m = aOrigin.NearestPoint( aTuneStart );
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN l( aOrigin );
|
|
|
|
l.Split( n );
|
|
|
|
l.Split( m );
|
|
|
|
|
|
|
|
int i_start = l.Find( m );
|
|
|
|
int i_end = l.Find( n );
|
|
|
|
|
|
|
|
if( i_start > i_end )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
l = l.Reverse();
|
2015-02-18 00:29:54 +00:00
|
|
|
i_start = l.Find( m );
|
|
|
|
i_end = l.Find( n );
|
|
|
|
}
|
|
|
|
|
|
|
|
aPre = l.Slice( 0, i_start );
|
2015-02-18 16:53:46 +00:00
|
|
|
aPost = l.Slice( i_end, -1 );
|
2015-02-18 00:29:54 +00:00
|
|
|
aTuned = l.Slice( i_start, i_end );
|
2015-03-05 09:02:29 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aTuned.Simplify();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
void MEANDER_PLACER_BASE::tuneLineLength( MEANDERED_LINE& aTuned, long long int aElongation )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2019-09-03 23:38:58 +00:00
|
|
|
long long int remaining = aElongation;
|
2015-02-18 00:29:54 +00:00
|
|
|
bool finished = false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( MEANDER_SHAPE* m : aTuned.Meanders() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m->Type() != MT_CORNER )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( remaining >= 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
remaining -= m->MaxTunableLength() - m->BaselineLength();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( remaining < 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !finished )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_TYPE newType;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( m->Type() == MT_START || m->Type() == MT_SINGLE )
|
|
|
|
newType = MT_SINGLE;
|
|
|
|
else
|
|
|
|
newType = MT_FINISH;
|
|
|
|
|
|
|
|
m->SetType( newType );
|
|
|
|
m->Recalculate();
|
|
|
|
|
|
|
|
finished = true;
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m->MakeEmpty();
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remaining = aElongation;
|
|
|
|
int meanderCount = 0;
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
for( MEANDER_SHAPE* m : aTuned.Meanders() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m->Type() != MT_CORNER && m->Type() != MT_EMPTY )
|
|
|
|
{
|
|
|
|
if(remaining >= 0)
|
|
|
|
{
|
|
|
|
remaining -= m->MaxTunableLength() - m->BaselineLength();
|
|
|
|
meanderCount ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
long long int balance = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( meanderCount )
|
|
|
|
balance = -remaining / meanderCount;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( balance >= 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( MEANDER_SHAPE* m : aTuned.Meanders() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m->Type() != MT_CORNER && m->Type() != MT_EMPTY )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2019-09-03 23:38:58 +00:00
|
|
|
m->Resize( std::max( m->Amplitude() - balance / 2,
|
2020-11-24 22:16:41 +00:00
|
|
|
(long long int) m_settings.m_minAmplitude ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-10-31 13:00:01 +00:00
|
|
|
int MEANDER_PLACER_BASE::GetTotalPadToDieLength( const LINE& aLine ) const
|
|
|
|
{
|
|
|
|
int length = 0;
|
|
|
|
JOINT start;
|
|
|
|
JOINT end;
|
|
|
|
|
|
|
|
m_world->FindLineEnds( aLine, start, end );
|
|
|
|
|
|
|
|
// Extract the length of the pad to die for start and end pads
|
|
|
|
for( auto& link : start.LinkList() )
|
|
|
|
{
|
|
|
|
if( const SOLID* solid = dynamic_cast<const SOLID*>( link.item ) )
|
|
|
|
{
|
|
|
|
// If there are overlapping pads, choose the first with a non-zero length
|
|
|
|
if( solid->GetPadToDie() > 0 )
|
|
|
|
{
|
|
|
|
length += solid->GetPadToDie();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& link : end.LinkList() )
|
|
|
|
{
|
|
|
|
if( const SOLID* solid = dynamic_cast<const SOLID*>( link.item ) )
|
|
|
|
{
|
|
|
|
if( solid->GetPadToDie() > 0 )
|
|
|
|
{
|
|
|
|
length += solid->GetPadToDie();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const MEANDER_SETTINGS& MEANDER_PLACER_BASE::MeanderSettings() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_settings;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
int MEANDER_PLACER_BASE::compareWithTolerance(
|
|
|
|
long long int aValue, long long int aExpected, long long int aTolerance ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aValue < aExpected - aTolerance )
|
2015-02-18 00:29:54 +00:00
|
|
|
return -1;
|
2015-02-18 16:53:46 +00:00
|
|
|
else if( aValue > aExpected + aTolerance )
|
2015-02-18 00:29:54 +00:00
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|