2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2021-07-19 23:56:05 +00:00
|
|
|
* Copyright (C) 2016-2021 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-10-31 13:00:01 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_itemset.h"
|
|
|
|
#include "pns_meander_placer.h"
|
2019-10-31 13:00:01 +00:00
|
|
|
#include "pns_node.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_router.h"
|
2019-10-31 13:00:01 +00:00
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_topology.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_PLACER::MEANDER_PLACER( ROUTER* aRouter ) :
|
|
|
|
MEANDER_PLACER_BASE( aRouter )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_currentNode = nullptr;
|
2015-05-15 12:49:11 +00:00
|
|
|
|
|
|
|
// Init temporary variables (do not leave uninitialized members)
|
2021-07-19 23:56:05 +00:00
|
|
|
m_initialSegment = nullptr;
|
2015-05-15 12:49:11 +00:00
|
|
|
m_lastLength = 0;
|
|
|
|
m_lastStatus = TOO_SHORT;
|
2022-12-01 14:59:18 +00:00
|
|
|
m_padToDieLength = 0;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
MEANDER_PLACER::~MEANDER_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
|
|
|
NODE* MEANDER_PLACER::CurrentNode( bool aLoopsRemoved ) const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( !m_currentNode )
|
|
|
|
return m_world;
|
|
|
|
|
|
|
|
return m_currentNode;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDER_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 track whose length 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 );
|
2022-08-02 03:23:07 +00:00
|
|
|
m_tunedPath = topo.AssembleTuningPath( m_initialSegment, &m_startPad_n, &m_endPad_n );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
m_padToDieLength = 0;
|
|
|
|
|
2022-08-02 03:23:07 +00:00
|
|
|
if( m_startPad_n )
|
|
|
|
m_padToDieLength += 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_padToDieLength += 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 );
|
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_PLACER::origPathLength() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-02 03:23:07 +00:00
|
|
|
return m_padToDieLength + lineLength( m_tunedPath, m_startPad_n, m_endPad_n );
|
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_PLACER::Move( const VECTOR2I& aP, ITEM* aEndItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-10-16 23:27:08 +00:00
|
|
|
return doMove( aP, aEndItem, m_settings.m_targetLength.Opt(), m_settings.m_targetLength.Min(),
|
|
|
|
m_settings.m_targetLength.Max() );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
bool MEANDER_PLACER::doMove( const VECTOR2I& aP, ITEM* aEndItem, long long int aTargetLength,
|
|
|
|
long long int aTargetMin, long long int aTargetMax )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-10-07 03:00:25 +00:00
|
|
|
if( m_currentStart == aP )
|
|
|
|
return false;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_currentNode )
|
2015-02-18 00:29:54 +00:00
|
|
|
delete m_currentNode;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_currentNode = m_world->Branch();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-10-07 03:00:25 +00:00
|
|
|
SHAPE_LINE_CHAIN pre, tuned, post;
|
|
|
|
|
2023-10-07 02:11:26 +00:00
|
|
|
m_originLine.CLine().Split( m_currentStart, aP, pre, tuned, post );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
m_result = MEANDERED_LINE( this, false );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_result.SetWidth( m_originLine.Width() );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_result.SetBaselineOffset( 0 );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
for( int i = 0; i < tuned.SegmentCount(); i++ )
|
|
|
|
{
|
2021-05-06 22:10:39 +00:00
|
|
|
if( tuned.IsArcSegment( i ) )
|
2021-08-09 20:00:35 +00:00
|
|
|
{
|
|
|
|
ssize_t arcIndex = tuned.ArcIndex( i );
|
|
|
|
m_result.AddArc( tuned.Arc( arcIndex ) );
|
|
|
|
i = tuned.NextShape( i );
|
|
|
|
|
|
|
|
// NextShape will return -1 if last shape
|
|
|
|
if( i < 0 )
|
|
|
|
i = tuned.SegmentCount();
|
|
|
|
|
2021-01-04 13:54:29 +00:00
|
|
|
continue;
|
2021-08-09 20:00:35 +00:00
|
|
|
}
|
2021-01-04 13:54:29 +00:00
|
|
|
|
2023-10-07 03:25:27 +00:00
|
|
|
bool side = false;
|
2015-02-18 00:29:54 +00:00
|
|
|
const SEG s = tuned.CSegment( i );
|
2023-10-07 03:25:27 +00:00
|
|
|
|
2023-10-16 12:12:17 +00:00
|
|
|
if( m_settings.m_initialSide == 0 )
|
2023-10-07 03:25:27 +00:00
|
|
|
side = s.Side( aP ) < 0;
|
|
|
|
else
|
2023-10-16 12:12:17 +00:00
|
|
|
side = m_settings.m_initialSide < 0;
|
2023-10-07 03:25:27 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_result.AddCorner( s.A );
|
2023-10-07 03:25:27 +00:00
|
|
|
m_result.MeanderSegment( s, side );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_result.AddCorner( s.B );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-09-03 23:38:58 +00:00
|
|
|
long long int lineLen = origPathLength();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_lastLength = lineLen;
|
|
|
|
m_lastStatus = TUNED;
|
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( lineLen > m_settings.m_targetLength.Max() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_lastStatus = TOO_LONG;
|
2023-10-16 12:12:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_lastLength = lineLen - tuned.Length();
|
|
|
|
tuneLineLength( m_result, aTargetLength - lineLen );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : m_tunedPath.CItems() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( const LINE* l = dyn_cast<const LINE*>( item ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-02-26 01:42:16 +00:00
|
|
|
PNS_DBG( Dbg(), AddItem, l, BLUE, 30000, wxT( "tuned-line" ) );
|
2023-02-01 17:36:52 +00:00
|
|
|
|
|
|
|
m_router->GetInterface()->DisplayPathLine( l->CLine(), 1 );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( m_lastStatus != TOO_LONG )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
tuned.Clear();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( MEANDER_SHAPE* m : m_result.Meanders() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( m->Type() != MT_EMPTY )
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
tuned.Append ( m->CLine( 0 ) );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_lastLength += tuned.Length();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-10-16 23:27:08 +00:00
|
|
|
if( m_lastLength > aTargetMax )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_lastStatus = TOO_LONG;
|
2023-10-16 23:27:08 +00:00
|
|
|
else if( m_lastLength < aTargetMin )
|
2015-02-18 00:29:54 +00:00
|
|
|
m_lastStatus = TOO_SHORT;
|
|
|
|
else
|
|
|
|
m_lastStatus = TUNED;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_finalShape.Clear();
|
2023-11-12 09:17:03 +00:00
|
|
|
|
|
|
|
if( m_settings.m_keepEndpoints )
|
|
|
|
{
|
|
|
|
pre.Simplify();
|
|
|
|
tuned.Simplify();
|
|
|
|
post.Simplify();
|
|
|
|
|
|
|
|
m_finalShape.Append( pre );
|
|
|
|
m_finalShape.Append( tuned );
|
|
|
|
m_finalShape.Append( post );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_finalShape.Append( pre );
|
|
|
|
m_finalShape.Append( tuned );
|
|
|
|
m_finalShape.Append( post );
|
|
|
|
m_finalShape.Simplify();
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-19 17:29:36 +00:00
|
|
|
bool MEANDER_PLACER::FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-03-03 20:58:36 +00:00
|
|
|
if( !m_currentNode )
|
|
|
|
return false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
m_currentTrace = LINE( m_originLine, m_finalShape );
|
2016-08-30 15:28:35 +00:00
|
|
|
m_currentNode->Add( m_currentTrace );
|
2020-03-06 17:55:20 +00:00
|
|
|
CommitPlacement();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
|
2020-03-06 17:55:20 +00:00
|
|
|
bool MEANDER_PLACER::AbortPlacement()
|
|
|
|
{
|
|
|
|
m_world->KillChildren();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MEANDER_PLACER::HasPlacedAnything() const
|
|
|
|
{
|
|
|
|
return m_currentTrace.SegmentCount() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MEANDER_PLACER::CommitPlacement()
|
|
|
|
{
|
|
|
|
if( m_currentNode )
|
|
|
|
Router()->CommitRouting( m_currentNode );
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_currentNode = nullptr;
|
2020-03-06 17:55:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool MEANDER_PLACER::CheckFit( MEANDER_SHAPE* aShape )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE l( m_originLine, aShape->CLine( 0 ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( m_currentNode->CheckColliding( &l ) )
|
|
|
|
return false;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
int w = aShape->Width();
|
2015-02-18 00:29:54 +00:00
|
|
|
int clearance = w + m_settings.m_spacing;
|
|
|
|
|
|
|
|
return m_result.CheckSelfIntersections( aShape, clearance );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET MEANDER_PLACER::Traces()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
m_currentTrace = LINE( m_originLine, m_finalShape );
|
|
|
|
return ITEM_SET( &m_currentTrace );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2023-12-02 10:32:45 +00:00
|
|
|
const ITEM_SET MEANDER_PLACER::TunedPath()
|
|
|
|
{
|
|
|
|
return m_tunedPath;
|
|
|
|
}
|
|
|
|
|
2022-09-12 19:43:36 +00:00
|
|
|
const VECTOR2I& MEANDER_PLACER::CurrentStart() const
|
|
|
|
{
|
|
|
|
return m_currentStart;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const VECTOR2I& MEANDER_PLACER::CurrentEnd() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_currentEnd;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int MEANDER_PLACER::CurrentLayer() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
return m_initialSegment->Layers().Start();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-17 12:03:38 +00:00
|
|
|
long long int MEANDER_PLACER::TuningResult() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-11-23 18:41:59 +00:00
|
|
|
if( m_lastLength )
|
|
|
|
return m_lastLength;
|
|
|
|
else
|
|
|
|
return origPathLength();
|
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_PLACER::TUNING_STATUS MEANDER_PLACER::TuningStatus() const
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
return m_lastStatus;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|