2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
2023-08-22 12:06:33 +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 "pns_line.h"
|
|
|
|
#include "pns_segment.h"
|
2023-12-27 13:51:41 +00:00
|
|
|
#include "pns_arc.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_joint.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_router.h"
|
2015-07-02 14:10:49 +00:00
|
|
|
#include "pns_utils.h"
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
#include "pns_diff_pair.h"
|
|
|
|
#include "pns_topology.h"
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.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
|
|
|
bool TOPOLOGY::SimplifyLine( LINE* aLine )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 18:36:05 +00:00
|
|
|
if( !aLine->IsLinked() || !aLine->SegmentCount() )
|
2015-02-18 16:53:46 +00:00
|
|
|
return false;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
LINKED_ITEM* root = aLine->GetLink( 0 );
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE l = m_world->AssembleLine( root );
|
2015-08-03 19:11:51 +00:00
|
|
|
SHAPE_LINE_CHAIN simplified( l.CLine() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
simplified.Simplify();
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
if( simplified.PointCount() != l.PointCount() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-30 17:01:30 +00:00
|
|
|
m_world->Remove( l );
|
2017-01-18 14:52:35 +00:00
|
|
|
LINE lnew( l );
|
2015-08-03 19:11:51 +00:00
|
|
|
lnew.SetShape( simplified );
|
2016-08-30 15:28:35 +00:00
|
|
|
m_world->Add( lnew );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const TOPOLOGY::JOINT_SET TOPOLOGY::ConnectedJoints( const JOINT* aStart )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
std::deque<const JOINT*> searchQueue;
|
|
|
|
JOINT_SET processed;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
searchQueue.push_back( aStart );
|
|
|
|
processed.insert( aStart );
|
|
|
|
|
|
|
|
while( !searchQueue.empty() )
|
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* current = searchQueue.front();
|
2015-02-18 00:29:54 +00:00
|
|
|
searchQueue.pop_front();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : current->LinkList() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* a = m_world->FindJoint( item->Anchor( 0 ), item );;
|
|
|
|
const JOINT* b = m_world->FindJoint( item->Anchor( 1 ), item );;
|
|
|
|
const JOINT* next = ( *a == *current ) ? b : a;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( processed.find( next ) == processed.end() )
|
|
|
|
{
|
|
|
|
processed.insert( next );
|
|
|
|
searchQueue.push_back( next );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return processed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-14 16:38:39 +00:00
|
|
|
bool TOPOLOGY::NearestUnconnectedAnchorPoint( const LINE* aTrack, VECTOR2I& aPoint,
|
2023-03-06 19:48:42 +00:00
|
|
|
LAYER_RANGE& aLayers, ITEM*& aItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE track( *aTrack );
|
2015-02-18 00:29:54 +00:00
|
|
|
VECTOR2I end;
|
|
|
|
|
|
|
|
if( !track.PointCount() )
|
|
|
|
return false;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
std::unique_ptr<NODE> tmpNode( m_world->Branch() );
|
2016-08-30 15:28:35 +00:00
|
|
|
tmpNode->Add( track );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jt = tmpNode->FindJoint( track.CPoint( -1 ), &track );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
if( !jt || m_world->GetRuleResolver()->NetCode( jt->Net() ) <= 0 )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2020-12-02 18:42:37 +00:00
|
|
|
if( ( !track.EndsWithVia() && jt->LinkCount() >= 2 )
|
|
|
|
|| ( track.EndsWithVia() && jt->LinkCount() >= 3 ) ) // we got something connected
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
end = jt->Pos();
|
2022-07-14 16:38:39 +00:00
|
|
|
aLayers = jt->Layers();
|
2023-03-06 19:48:42 +00:00
|
|
|
aItem = jt->LinkList()[0];
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-04 16:57:19 +00:00
|
|
|
int anchor;
|
2020-12-02 20:04:21 +00:00
|
|
|
|
2020-12-04 16:57:19 +00:00
|
|
|
TOPOLOGY topo( tmpNode.get() );
|
|
|
|
ITEM* it = topo.NearestUnconnectedItem( jt, &anchor );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
if( !it )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
end = it->Anchor( anchor );
|
2022-07-14 16:38:39 +00:00
|
|
|
aLayers = it->Layers();
|
2023-03-06 19:48:42 +00:00
|
|
|
aItem = it;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:38:39 +00:00
|
|
|
aPoint = end;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TOPOLOGY::LeadingRatLine( const LINE* aTrack, SHAPE_LINE_CHAIN& aRatLine )
|
|
|
|
{
|
|
|
|
VECTOR2I end;
|
|
|
|
// Ratline doesn't care about the layer
|
|
|
|
LAYER_RANGE layers;
|
2023-03-06 19:48:42 +00:00
|
|
|
ITEM* unusedItem;
|
2022-07-14 16:38:39 +00:00
|
|
|
|
2023-03-06 19:48:42 +00:00
|
|
|
if( !NearestUnconnectedAnchorPoint( aTrack, end, layers, unusedItem ) )
|
2022-07-14 16:38:39 +00:00
|
|
|
return false;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
aRatLine.Clear();
|
2022-07-14 16:38:39 +00:00
|
|
|
aRatLine.Append( aTrack->CPoint( -1 ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
aRatLine.Append( end );
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
ITEM* TOPOLOGY::NearestUnconnectedItem( const JOINT* aStart, int* aAnchor, int aKindMask )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
std::set<ITEM*> disconnected;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_world->AllItemsInNet( aStart->Net(), disconnected );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const JOINT* jt : ConnectedJoints( aStart ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* link : jt->LinkList() )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( disconnected.find( link ) != disconnected.end() )
|
|
|
|
disconnected.erase( link );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int best_dist = INT_MAX;
|
2021-07-19 23:56:05 +00:00
|
|
|
ITEM* best = nullptr;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : disconnected )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
if( item->OfKind( aKindMask ) )
|
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
for( int i = 0; i < item->AnchorCount(); i++ )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I p = item->Anchor( i );
|
|
|
|
int d = ( p - aStart->Pos() ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( d < best_dist )
|
|
|
|
{
|
|
|
|
best_dist = d;
|
|
|
|
best = item;
|
|
|
|
|
|
|
|
if( aAnchor )
|
|
|
|
*aAnchor = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
bool TOPOLOGY::followTrivialPath( LINE* aLine2, bool aLeft, ITEM_SET& aSet,
|
|
|
|
const JOINT** aTerminalJoint, bool aFollowLockedSegments )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-11-28 14:56:00 +00:00
|
|
|
assert( aLine2->IsLinked() );
|
|
|
|
LINE* curr_line = aLine2;
|
|
|
|
std::set<ITEM*> visited;
|
2016-08-29 18:36:05 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
while( true )
|
|
|
|
{
|
|
|
|
VECTOR2I anchor = aLeft ? curr_line->CPoint( 0 ) : curr_line->CPoint( -1 );
|
|
|
|
LINKED_ITEM* last = aLeft ? curr_line->Links().front() : curr_line->Links().back();
|
|
|
|
const JOINT* jt = m_world->FindJoint( anchor, curr_line );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
assert( jt != nullptr );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
if( !visited.insert( last ).second
|
|
|
|
|| ( !jt->IsNonFanoutVia() && !jt->IsTraceWidthChange() ) )
|
|
|
|
{
|
|
|
|
if( aTerminalJoint )
|
|
|
|
*aTerminalJoint = jt;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITEM* via = nullptr;
|
2021-07-19 23:56:05 +00:00
|
|
|
SEGMENT* next_seg = nullptr;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
ITEM_SET links( jt->CLinks() );
|
|
|
|
|
|
|
|
for( ITEM* link : links )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( link->OfKind( ITEM::VIA_T ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
via = link;
|
2023-11-28 14:56:00 +00:00
|
|
|
else if( visited.insert( link ).second )
|
2016-08-29 17:31:13 +00:00
|
|
|
next_seg = static_cast<SEGMENT*>( link );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( !next_seg )
|
2021-04-05 00:27:22 +00:00
|
|
|
{
|
|
|
|
if( aTerminalJoint )
|
|
|
|
*aTerminalJoint = jt;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
2021-04-05 00:27:22 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
LINE l = m_world->AssembleLine( next_seg, nullptr, false, aFollowLockedSegments );
|
2015-08-03 19:11:51 +00:00
|
|
|
VECTOR2I nextAnchor = ( aLeft ? l.CLine().CPoint( -1 ) : l.CLine().CPoint( 0 ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( nextAnchor != anchor )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
l.Reverse();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aLeft )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-11-05 09:20:08 +00:00
|
|
|
if( via )
|
|
|
|
aSet.Prepend( via );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aSet.Prepend( l );
|
2023-11-28 14:56:00 +00:00
|
|
|
curr_line = static_cast<PNS::LINE*>( aSet[0] );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-05 09:20:08 +00:00
|
|
|
if( via )
|
|
|
|
aSet.Add( via );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
aSet.Add( l );
|
2023-11-28 14:56:00 +00:00
|
|
|
curr_line = static_cast<PNS::LINE*>( aSet[aSet.Size() - 1] );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
continue;
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-04-05 00:27:22 +00:00
|
|
|
const ITEM_SET TOPOLOGY::AssembleTrivialPath( ITEM* aStart,
|
2022-08-29 20:21:46 +00:00
|
|
|
std::pair<const JOINT*, const JOINT*>* aTerminalJoints,
|
2021-12-05 18:35:28 +00:00
|
|
|
bool aFollowLockedSegments )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-04-06 13:07:00 +00:00
|
|
|
ITEM_SET path;
|
|
|
|
LINKED_ITEM* seg = nullptr;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( aStart->Kind() == ITEM::VIA_T )
|
2016-08-15 15:16:47 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
VIA* via = static_cast<VIA*>( aStart );
|
|
|
|
const JOINT* jt = m_world->FindJoint( via->Pos(), via );
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( !jt->IsNonFanoutVia() )
|
2016-08-29 17:31:13 +00:00
|
|
|
return ITEM_SET();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
ITEM_SET links( jt->CLinks() );
|
|
|
|
|
|
|
|
for( ITEM* item : links )
|
2021-04-06 13:07:00 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
2021-04-06 13:07:00 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
seg = static_cast<LINKED_ITEM*>( item );
|
2016-08-15 15:16:47 +00:00
|
|
|
break;
|
2021-04-06 13:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( aStart->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
|
|
|
{
|
|
|
|
seg = static_cast<LINKED_ITEM*>( aStart );
|
2016-08-15 15:16:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !seg )
|
2016-08-29 17:31:13 +00:00
|
|
|
return ITEM_SET();
|
2016-08-15 15:16:47 +00:00
|
|
|
|
2021-12-05 18:35:28 +00:00
|
|
|
// Assemble a line following through locked segments
|
|
|
|
// TODO: consider if we want to allow tuning lines with different widths in the future
|
2023-09-23 17:33:32 +00:00
|
|
|
LINE l = m_world->AssembleLine( seg, nullptr, false, aFollowLockedSegments );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
path.Add( l );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jointA = nullptr;
|
|
|
|
const JOINT* jointB = nullptr;
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2023-11-28 14:56:00 +00:00
|
|
|
followTrivialPath( &l, false, path, &jointB, aFollowLockedSegments );
|
|
|
|
followTrivialPath( &l, true, path, &jointA, aFollowLockedSegments );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
if( aTerminalJoints )
|
|
|
|
{
|
|
|
|
wxASSERT( jointA && jointB );
|
|
|
|
*aTerminalJoints = std::make_pair( jointA, jointB );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-04-05 00:27:22 +00:00
|
|
|
const ITEM_SET TOPOLOGY::AssembleTuningPath( ITEM* aStart, SOLID** aStartPad, SOLID** aEndPad )
|
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
std::pair<const JOINT*, const JOINT*> joints;
|
2021-12-05 18:35:28 +00:00
|
|
|
ITEM_SET initialPath = AssembleTrivialPath( aStart, &joints, true );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
PAD* padA = nullptr;
|
|
|
|
PAD* padB = nullptr;
|
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
auto getPadFromJoint =
|
2022-08-29 20:21:46 +00:00
|
|
|
[]( const JOINT* aJoint, PAD** aTargetPad, SOLID** aTargetSolid )
|
2021-04-05 00:27:22 +00:00
|
|
|
{
|
2021-04-06 13:07:00 +00:00
|
|
|
for( ITEM* item : aJoint->LinkList() )
|
|
|
|
{
|
|
|
|
if( item->OfKind( ITEM::SOLID_T ) )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* bi = static_cast<SOLID*>( item )->Parent();
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( bi->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
*aTargetPad = static_cast<PAD*>( bi );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( aTargetSolid )
|
|
|
|
*aTargetSolid = static_cast<SOLID*>( item );
|
|
|
|
}
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( joints.first )
|
|
|
|
getPadFromJoint( joints.first, &padA, aStartPad );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( joints.second )
|
|
|
|
getPadFromJoint( joints.second, &padB, aEndPad );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
2021-04-06 13:07:00 +00:00
|
|
|
if( !padA && !padB )
|
|
|
|
return initialPath;
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
auto clipLineToPad =
|
|
|
|
[]( SHAPE_LINE_CHAIN& aLine, PAD* aPad, bool aForward = true )
|
|
|
|
{
|
2023-10-13 11:25:52 +00:00
|
|
|
const auto& shape = aPad->GetEffectivePolygon( ERROR_INSIDE );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
int start = aForward ? 0 : aLine.PointCount() - 1;
|
|
|
|
int delta = aForward ? 1 : -1;
|
|
|
|
|
|
|
|
// Skip the "first" (or last) vertex, we already know it's contained in the pad
|
|
|
|
int clip = start;
|
|
|
|
|
|
|
|
for( int vertex = start + delta;
|
|
|
|
aForward ? vertex < aLine.PointCount() : vertex >= 0;
|
|
|
|
vertex += delta )
|
|
|
|
{
|
|
|
|
SEG seg( aLine.GetPoint( vertex ), aLine.GetPoint( vertex - delta ) );
|
|
|
|
|
|
|
|
bool containsA = shape->Contains( seg.A );
|
|
|
|
bool containsB = shape->Contains( seg.B );
|
|
|
|
|
|
|
|
if( containsA && containsB )
|
|
|
|
{
|
|
|
|
// Whole segment is inside: clip out this segment
|
|
|
|
clip = vertex;
|
|
|
|
}
|
2022-12-30 11:27:59 +00:00
|
|
|
else if( containsB )
|
2021-04-05 00:27:22 +00:00
|
|
|
{
|
|
|
|
// Only one point inside: Find the intersection
|
|
|
|
VECTOR2I loc;
|
|
|
|
|
|
|
|
if( shape->Collide( seg, 0, nullptr, &loc ) )
|
|
|
|
{
|
|
|
|
aLine.Replace( vertex - delta, vertex - delta, loc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aForward && clip < start )
|
|
|
|
aLine.Remove( clip + 1, start );
|
|
|
|
else if( clip > start )
|
|
|
|
aLine.Remove( start, clip - 1 );
|
|
|
|
|
|
|
|
// Now connect the dots
|
2021-09-23 00:25:10 +00:00
|
|
|
aLine.Insert( aForward ? 0 : aLine.PointCount(), aPad->GetPosition() );
|
2021-04-05 00:27:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto processPad =
|
2022-08-29 20:21:46 +00:00
|
|
|
[&]( const JOINT* aJoint, PAD* aPad )
|
2021-04-05 00:27:22 +00:00
|
|
|
{
|
2023-10-13 11:25:52 +00:00
|
|
|
const auto& shape = aPad->GetEffectivePolygon( ERROR_INSIDE );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
for( int idx = 0; idx < initialPath.Size(); idx++ )
|
|
|
|
{
|
|
|
|
if( initialPath[idx]->Kind() != ITEM::LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LINE* line = static_cast<LINE*>( initialPath[idx] );
|
|
|
|
|
2021-05-29 19:52:44 +00:00
|
|
|
if( !aPad->FlashLayer( line->Layer() ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const std::vector<VECTOR2I>& points = line->CLine().CPoints();
|
|
|
|
|
|
|
|
if( points.front() != aJoint->Pos() && points.back() != aJoint->Pos() )
|
|
|
|
continue;
|
|
|
|
|
2021-04-05 00:27:22 +00:00
|
|
|
SHAPE_LINE_CHAIN& slc = line->Line();
|
|
|
|
|
|
|
|
if( shape->Contains( slc.CPoint( 0 ) ) )
|
|
|
|
clipLineToPad( slc, aPad, true );
|
|
|
|
else if( shape->Contains( slc.CPoint( -1 ) ) )
|
|
|
|
clipLineToPad( slc, aPad, false );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if( padA )
|
2021-05-29 19:52:44 +00:00
|
|
|
processPad( joints.first, padA );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
if( padB )
|
2021-05-29 19:52:44 +00:00
|
|
|
processPad( joints.second, padB );
|
2021-04-05 00:27:22 +00:00
|
|
|
|
|
|
|
return initialPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const ITEM_SET TOPOLOGY::ConnectedItems( const JOINT* aStart, int aKindMask )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
return ITEM_SET();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET TOPOLOGY::ConnectedItems( ITEM* aStart, int aKindMask )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
return ITEM_SET();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2018-10-08 14:30:17 +00:00
|
|
|
bool commonParallelProjection( SEG p, SEG n, SEG &pClip, SEG& nClip );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool TOPOLOGY::AssembleDiffPair( ITEM* aStart, DIFF_PAIR& aPair )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-12-23 23:42:33 +00:00
|
|
|
NET_HANDLE refNet = aStart->Net();
|
|
|
|
NET_HANDLE coupledNet = m_world->GetRuleResolver()->DpCoupledNet( refNet );
|
|
|
|
LINKED_ITEM* startItem = dynamic_cast<LINKED_ITEM*>( aStart );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2023-12-23 23:42:33 +00:00
|
|
|
if( !coupledNet || !startItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2023-12-23 23:42:33 +00:00
|
|
|
LINE lp = m_world->AssembleLine( startItem );
|
|
|
|
|
2023-12-30 20:27:03 +00:00
|
|
|
std::vector<ITEM*> pItems;
|
|
|
|
std::vector<ITEM*> nItems;
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-12-30 20:27:03 +00:00
|
|
|
for( ITEM* item : lp.Links() )
|
|
|
|
{
|
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) && item->Layers() == startItem->Layers() )
|
|
|
|
pItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<ITEM*> coupledItems;
|
2015-02-18 00:29:54 +00:00
|
|
|
m_world->AllItemsInNet( coupledNet, coupledItems );
|
|
|
|
|
2023-12-30 20:27:03 +00:00
|
|
|
for( ITEM* item : coupledItems )
|
|
|
|
{
|
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) && item->Layers() == startItem->Layers() )
|
|
|
|
nItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
LINKED_ITEM* refItem = nullptr;
|
|
|
|
LINKED_ITEM* coupledItem = nullptr;
|
|
|
|
SEG::ecoord minDist_sq = std::numeric_limits<SEG::ecoord>::max();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-12-30 20:27:03 +00:00
|
|
|
for( ITEM* p_item : pItems )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-12-30 20:27:03 +00:00
|
|
|
for( ITEM* n_item : nItems )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2023-12-27 13:51:41 +00:00
|
|
|
SEG::ecoord dist_sq = std::numeric_limits<SEG::ecoord>::max();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-12-30 20:27:03 +00:00
|
|
|
if( n_item->Kind() != p_item->Kind() )
|
2023-12-23 23:42:33 +00:00
|
|
|
continue;
|
2015-07-02 14:10:49 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( p_item->Kind() == ITEM::SEGMENT_T )
|
|
|
|
{
|
|
|
|
SEGMENT* p_seg = static_cast<SEGMENT*>( p_item );
|
|
|
|
SEGMENT* n_seg = static_cast<SEGMENT*>( n_item );
|
2023-12-23 23:42:33 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( n_seg->Width() != p_seg->Width() )
|
|
|
|
continue;
|
2023-12-23 23:42:33 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( !p_seg->Seg().ApproxParallel( n_seg->Seg(), DP_PARALLELITY_THRESHOLD ) )
|
|
|
|
continue;
|
2023-12-23 23:42:33 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
SEG p_clip, n_clip;
|
2023-12-23 23:42:33 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( !commonParallelProjection( p_seg->Seg(), n_seg->Seg(), p_clip, n_clip ) )
|
|
|
|
continue;
|
2023-12-23 23:42:33 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
dist_sq = n_seg->Seg().SquaredDistance( p_seg->Seg() );
|
|
|
|
}
|
|
|
|
else if( p_item->Kind() == ITEM::ARC_T )
|
2023-12-23 23:42:33 +00:00
|
|
|
{
|
2023-12-27 13:51:41 +00:00
|
|
|
ARC* p_arc = static_cast<ARC*>( p_item );
|
|
|
|
ARC* n_arc = static_cast<ARC*>( n_item );
|
|
|
|
|
|
|
|
if( n_arc->Width() != p_arc->Width() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
VECTOR2I centerDiff = n_arc->CArc().GetCenter() - p_arc->CArc().GetCenter();
|
|
|
|
SEG::ecoord centerDist_sq = centerDiff.SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
if( centerDist_sq > SEG::Square( DP_PARALLELITY_THRESHOLD ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dist_sq = SEG::Square( p_arc->CArc().GetRadius() - n_arc->CArc().GetRadius() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( dist_sq < minDist_sq )
|
|
|
|
{
|
|
|
|
minDist_sq = dist_sq;
|
|
|
|
refItem = static_cast<LINKED_ITEM*>( p_item );
|
|
|
|
coupledItem = static_cast<LINKED_ITEM*>( n_item );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( !coupledItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
LINE ln = m_world->AssembleLine( coupledItem );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
if( m_world->GetRuleResolver()->DpNetPolarity( refNet ) < 0 )
|
2015-02-18 16:53:46 +00:00
|
|
|
std::swap( lp, ln );
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int gap = -1;
|
|
|
|
|
2023-12-27 13:51:41 +00:00
|
|
|
if( refItem && refItem->Kind() == ITEM::SEGMENT_T )
|
2015-07-02 14:11:15 +00:00
|
|
|
{
|
|
|
|
// Segments are parallel -> compute pair gap
|
2023-12-27 13:51:41 +00:00
|
|
|
const VECTOR2I refDir = refItem->Anchor( 1 ) - refItem->Anchor( 0 );
|
|
|
|
const VECTOR2I displacement = refItem->Anchor( 1 ) - coupledItem->Anchor( 1 );
|
2015-08-03 19:11:51 +00:00
|
|
|
gap = (int) std::abs( refDir.Cross( displacement ) / refDir.EuclideanNorm() ) - lp.Width();
|
2015-07-02 14:10:02 +00:00
|
|
|
}
|
2023-12-27 13:51:41 +00:00
|
|
|
else if( refItem && refItem->Kind() == ITEM::ARC_T )
|
|
|
|
{
|
|
|
|
const ARC* refArc = static_cast<ARC*>( refItem );
|
|
|
|
const ARC* coupledArc = static_cast<ARC*>( coupledItem );
|
|
|
|
gap = (int) std::abs( refArc->CArc().GetRadius() - coupledArc->CArc().GetRadius() ) - lp.Width();
|
|
|
|
}
|
2015-07-02 14:10:02 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
aPair = DIFF_PAIR( lp, ln );
|
2015-08-03 19:11:51 +00:00
|
|
|
aPair.SetWidth( lp.Width() );
|
|
|
|
aPair.SetLayers( lp.Layers() );
|
2015-07-02 14:10:02 +00:00
|
|
|
aPair.SetGap( gap );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const std::set<ITEM*> TOPOLOGY::AssembleCluster( ITEM* aStart, int aLayer )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
std::set<ITEM*> visited;
|
|
|
|
std::deque<ITEM*> pending;
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2022-08-15 13:31:43 +00:00
|
|
|
COLLISION_SEARCH_OPTIONS opts;
|
|
|
|
|
|
|
|
opts.m_differentNetsOnly = false;
|
|
|
|
opts.m_overrideClearance = 0;
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
pending.push_back( aStart );
|
|
|
|
|
|
|
|
while( !pending.empty() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OBSTACLES obstacles;
|
|
|
|
ITEM* top = pending.front();
|
2015-08-19 16:07:16 +00:00
|
|
|
|
|
|
|
pending.pop_front();
|
|
|
|
|
|
|
|
visited.insert( top );
|
|
|
|
|
2022-08-15 13:31:43 +00:00
|
|
|
m_world->QueryColliding( top, obstacles, opts ); // only query touching objects
|
2015-08-19 16:07:16 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
for( const OBSTACLE& obs : obstacles )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
2022-06-03 21:03:24 +00:00
|
|
|
bool trackOnTrack = ( obs.m_item->Net() != top->Net() ) && obs.m_item->OfKind( ITEM::SEGMENT_T ) && top->OfKind( ITEM::SEGMENT_T );
|
|
|
|
|
|
|
|
if( trackOnTrack )
|
|
|
|
continue;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( visited.find( obs.m_item ) == visited.end() &&
|
|
|
|
obs.m_item->Layers().Overlaps( aLayer ) && !( obs.m_item->Marker() & MK_HEAD ) )
|
2015-08-19 16:07:16 +00:00
|
|
|
{
|
|
|
|
visited.insert( obs.m_item );
|
|
|
|
pending.push_back( obs.m_item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return visited;
|
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|