2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2019-05-17 00:13:21 +00:00
|
|
|
* Copyright (C) 2013-2019 CERN
|
2023-03-02 14:04:37 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-27 22:15:38 +00:00
|
|
|
*
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2019-05-17 00:13:21 +00:00
|
|
|
#include <utility>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_arc.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_item.h"
|
2021-12-05 18:35:28 +00:00
|
|
|
#include "pns_itemset.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_joint.h"
|
|
|
|
#include "pns_index.h"
|
2021-01-01 00:29:05 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
|
|
|
#include "pns_router.h"
|
2021-05-27 22:11:39 +00:00
|
|
|
#include "pns_utils.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2022-08-29 20:21:46 +00:00
|
|
|
static std::unordered_set<const NODE*> allocNodes;
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::NODE()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_depth = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_root = this;
|
2021-07-08 12:33:08 +00:00
|
|
|
m_parent = nullptr;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_maxClearance = 800000; // fixme: depends on how thick traces are.
|
2021-07-08 12:33:08 +00:00
|
|
|
m_ruleResolver = nullptr;
|
2016-08-29 17:31:13 +00:00
|
|
|
m_index = new INDEX;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2013-09-26 21:53:54 +00:00
|
|
|
allocNodes.insert( this );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::~NODE()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !m_children.empty() )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "attempting to free a node that has kids." ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
assert( false );
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2013-09-26 21:53:54 +00:00
|
|
|
if( allocNodes.find( this ) == allocNodes.end() )
|
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "attempting to free an already-free'd node." ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
assert( false );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
allocNodes.erase( this );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
|
|
|
|
2015-08-12 19:12:13 +00:00
|
|
|
m_joints.clear();
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
std::vector<ITEM*> toDelete;
|
|
|
|
|
|
|
|
toDelete.reserve( m_index->Size() );
|
|
|
|
|
2019-07-21 22:35:22 +00:00
|
|
|
for( ITEM* item : *m_index )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
if( item->BelongsTo( this ) && item->OfKind( ITEM::HOLE_T ) )
|
|
|
|
toDelete.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ITEM* item : toDelete )
|
|
|
|
{
|
2023-04-20 22:19:04 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "del item %p type %s" ), item, item->KindStr().c_str() );
|
2022-08-30 12:52:34 +00:00
|
|
|
delete item;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
releaseGarbage();
|
2013-09-26 21:53:54 +00:00
|
|
|
unlinkParent();
|
2015-08-03 19:11:51 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
delete m_index;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
|
2022-06-03 21:20:47 +00:00
|
|
|
int NODE::GetClearance( const ITEM* aA, const ITEM* aB, bool aUseClearanceEpsilon ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-15 15:16:47 +00:00
|
|
|
if( !m_ruleResolver )
|
2015-08-03 19:11:51 +00:00
|
|
|
return 100000;
|
|
|
|
|
2021-07-13 23:09:40 +00:00
|
|
|
if( aA->IsVirtual() || aB->IsVirtual() )
|
|
|
|
return 0;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
int cl = m_ruleResolver->Clearance( aA, aB, aUseClearanceEpsilon );
|
|
|
|
|
|
|
|
return cl;
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* NODE::Branch()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* child = new NODE;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-09-14 16:40:29 +00:00
|
|
|
m_children.insert( child );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
child->m_depth = m_depth + 1;
|
2013-09-26 21:53:54 +00:00
|
|
|
child->m_parent = this;
|
2016-08-15 15:16:47 +00:00
|
|
|
child->m_ruleResolver = m_ruleResolver;
|
2013-09-26 21:53:54 +00:00
|
|
|
child->m_root = isRoot() ? this : m_root;
|
2019-04-23 09:46:26 +00:00
|
|
|
child->m_maxClearance = m_maxClearance;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
// Immediate offspring of the root branch needs not copy anything. For the rest, deep-copy
|
2019-07-21 22:35:22 +00:00
|
|
|
// joints, overridden item maps and pointers to stored items.
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !isRoot() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP::iterator j;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2019-07-21 22:35:22 +00:00
|
|
|
for( ITEM* item : *m_index )
|
|
|
|
child->m_index->Add( item );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
child->m_joints = m_joints;
|
|
|
|
child->m_override = m_override;
|
|
|
|
}
|
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
#if 0
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "%d items, %d joints, %d overrides" ),
|
2021-01-01 01:02:06 +00:00
|
|
|
child->m_index->Size(),
|
|
|
|
(int) child->m_joints.size(),
|
|
|
|
(int) child->m_override.size() );
|
2021-01-04 02:37:24 +00:00
|
|
|
#endif
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::unlinkParent()
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
if( isRoot() )
|
|
|
|
return;
|
|
|
|
|
2015-09-14 16:40:29 +00:00
|
|
|
m_parent->m_children.erase( this );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE_VISITOR::OBSTACLE_VISITOR( const ITEM* aItem ) :
|
2016-08-15 15:16:53 +00:00
|
|
|
m_item( aItem ),
|
2021-07-08 12:33:08 +00:00
|
|
|
m_node( nullptr ),
|
|
|
|
m_override( nullptr )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void OBSTACLE_VISITOR::SetWorld( const NODE* aNode, const NODE* aOverride )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
m_node = aNode;
|
|
|
|
m_override = aOverride;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool OBSTACLE_VISITOR::visit( ITEM* aCandidate )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
2021-01-27 22:15:38 +00:00
|
|
|
// check if there is a more recent branch with a newer (possibly modified) version of this
|
2021-01-01 01:02:06 +00:00
|
|
|
// item.
|
2016-08-15 15:16:49 +00:00
|
|
|
if( m_override && m_override->Overrides( aCandidate ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
// function object that visits potential obstacles and performs the actual collision refining
|
2016-08-29 17:31:13 +00:00
|
|
|
struct NODE::DEFAULT_OBSTACLE_VISITOR : public OBSTACLE_VISITOR
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
COLLISION_SEARCH_CONTEXT* m_ctx;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
DEFAULT_OBSTACLE_VISITOR( COLLISION_SEARCH_CONTEXT* aCtx, const ITEM* aItem ) :
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE_VISITOR( aItem ),
|
2022-08-30 12:52:34 +00:00
|
|
|
m_ctx( aCtx )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~DEFAULT_OBSTACLE_VISITOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool operator()( ITEM* aCandidate ) override
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
if( !aCandidate->OfKind( m_ctx->options.m_kindMask ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( visit( aCandidate ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( !aCandidate->Collide( m_item, m_node, m_ctx ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( m_ctx->options.m_limitCount > 0 && m_ctx->obstacles.size() >= m_ctx->options.m_limitCount )
|
2013-09-26 21:53:54 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2022-08-15 13:31:43 +00:00
|
|
|
int NODE::QueryColliding( const ITEM* aItem, NODE::OBSTACLES& aObstacles,
|
2022-08-30 12:52:34 +00:00
|
|
|
const COLLISION_SEARCH_OPTIONS& aOpts ) const
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
COLLISION_SEARCH_CONTEXT ctx( aObstacles, aOpts );
|
|
|
|
|
2021-07-13 23:09:40 +00:00
|
|
|
/// By default, virtual items cannot collide
|
|
|
|
if( aItem->IsVirtual() )
|
|
|
|
return 0;
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
DEFAULT_OBSTACLE_VISITOR visitor( &ctx, aItem );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2013-09-26 21:53:54 +00:00
|
|
|
assert( allocNodes.find( this ) != allocNodes.end() );
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
visitor.SetWorld( this, nullptr );
|
2021-01-01 00:29:05 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// first, look for colliding items in the local index
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Query( aItem, m_maxClearance, visitor );
|
|
|
|
|
|
|
|
// if we haven't found enough items, look in the root branch as well.
|
2022-08-30 12:52:34 +00:00
|
|
|
if( !isRoot() && ( ctx.obstacles.size() < aOpts.m_limitCount || aOpts.m_limitCount < 0 ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
visitor.SetWorld( m_root, this );
|
|
|
|
m_root->m_index->Query( aItem, m_maxClearance, visitor );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aObstacles.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aLine,
|
2022-08-15 13:31:43 +00:00
|
|
|
const COLLISION_SEARCH_OPTIONS& aOpts )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
const int clearanceEpsilon = GetRuleResolver()->ClearanceEpsilon();
|
|
|
|
OBSTACLES obstacleList;
|
|
|
|
std::vector<SEGMENT> tmpSegs;
|
|
|
|
|
|
|
|
tmpSegs.reserve( aLine->CLine().SegmentCount() );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
for( int i = 0; i < aLine->CLine().SegmentCount(); i++ )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
// Note: Clearances between tmpSegs.back() and other items are cached,
|
2022-11-16 21:05:12 +00:00
|
|
|
// which means they'll be the same for all segments in the line.
|
|
|
|
// Disabling the cache will lead to slowness.
|
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
tmpSegs.emplace_back( *aLine, aLine->CLine().CSegment( i ) );
|
|
|
|
QueryColliding( &tmpSegs.back(), obstacleList, aOpts );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2020-12-30 20:27:20 +00:00
|
|
|
if( aLine->EndsWithVia() )
|
2022-08-15 13:31:43 +00:00
|
|
|
QueryColliding( &aLine->Via(), obstacleList, aOpts );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( obstacleList.empty() )
|
2014-05-16 11:37:31 +00:00
|
|
|
return OPT_OBSTACLE();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE nearest;
|
2023-03-04 18:02:05 +00:00
|
|
|
nearest.m_head = nullptr;
|
2021-07-08 12:33:08 +00:00
|
|
|
nearest.m_item = nullptr;
|
2014-05-16 11:37:31 +00:00
|
|
|
nearest.m_distFirst = INT_MAX;
|
2023-03-02 14:04:37 +00:00
|
|
|
nearest.m_maxFanoutWidth = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
auto updateNearest =
|
2022-08-30 12:52:34 +00:00
|
|
|
[&]( const SHAPE_LINE_CHAIN::INTERSECTION& pt, const OBSTACLE& obstacle )
|
2021-01-01 00:29:05 +00:00
|
|
|
{
|
2021-05-27 22:11:39 +00:00
|
|
|
int dist = aLine->CLine().PathLength( pt.p, pt.index_their );
|
2021-01-02 19:10:56 +00:00
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( dist < nearest.m_distFirst )
|
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
nearest = obstacle;
|
2021-01-01 00:29:05 +00:00
|
|
|
nearest.m_distFirst = dist;
|
2021-05-27 22:11:39 +00:00
|
|
|
nearest.m_ipFirst = pt.p;
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
|
|
|
};
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-02 19:10:56 +00:00
|
|
|
SHAPE_LINE_CHAIN obstacleHull;
|
|
|
|
DEBUG_DECORATOR* debugDecorator = ROUTER::GetInstance()->GetInterface()->GetDebugDecorator();
|
|
|
|
std::vector<SHAPE_LINE_CHAIN::INTERSECTION> intersectingPts;
|
|
|
|
int layer = aLine->Layer();
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
for( const OBSTACLE& obstacle : obstacleList )
|
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aOpts.m_restrictedSet && aOpts.m_restrictedSet->count( obstacle.m_item ) == 0 )
|
2015-08-19 16:07:16 +00:00
|
|
|
continue;
|
|
|
|
|
2022-06-03 21:20:47 +00:00
|
|
|
int clearance =
|
2022-08-15 13:31:43 +00:00
|
|
|
GetClearance( obstacle.m_item, aLine, aOpts.m_useClearanceEpsilon ) + aLine->Width() / 2;
|
2022-06-03 21:20:47 +00:00
|
|
|
|
|
|
|
obstacleHull = obstacle.m_item->Hull( clearance, 0, layer );
|
2021-05-27 22:11:39 +00:00
|
|
|
//debugDecorator->AddLine( obstacleHull, 2, 40000, "obstacle-hull-test" );
|
|
|
|
//debugDecorator->AddLine( aLine->CLine(), 5, 40000, "obstacle-test-line" );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-02 19:10:56 +00:00
|
|
|
intersectingPts.clear();
|
2021-05-27 22:11:39 +00:00
|
|
|
HullIntersection( obstacleHull, aLine->CLine(), intersectingPts );
|
2021-01-02 19:10:56 +00:00
|
|
|
|
2021-05-27 22:11:39 +00:00
|
|
|
for( const auto& ip : intersectingPts )
|
|
|
|
{
|
|
|
|
//debugDecorator->AddPoint( ip.p, ip.valid?3:6, 100000, (const char *) wxString::Format("obstacle-isect-point-%d" ).c_str() );
|
2022-06-07 23:48:38 +00:00
|
|
|
if( ip.valid )
|
2022-08-30 12:52:34 +00:00
|
|
|
updateNearest( ip, obstacle );
|
2021-05-27 22:11:39 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-12-30 20:27:20 +00:00
|
|
|
if( aLine->EndsWithVia() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-01-01 00:29:05 +00:00
|
|
|
const VIA& via = aLine->Via();
|
2022-08-15 13:31:43 +00:00
|
|
|
int viaClearance = GetClearance( obstacle.m_item, &via, aOpts.m_useClearanceEpsilon )
|
2022-06-07 23:48:38 +00:00
|
|
|
+ via.Diameter() / 2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-06-03 21:20:47 +00:00
|
|
|
obstacleHull = obstacle.m_item->Hull( viaClearance, 0, layer );
|
2021-05-27 22:11:39 +00:00
|
|
|
//debugDecorator->AddLine( obstacleHull, 3 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-02 19:10:56 +00:00
|
|
|
intersectingPts.clear();
|
2021-05-27 22:11:39 +00:00
|
|
|
HullIntersection( obstacleHull, aLine->CLine(), intersectingPts );
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
for( const SHAPE_LINE_CHAIN::INTERSECTION& ip : intersectingPts )
|
2022-08-30 12:52:34 +00:00
|
|
|
updateNearest( ip, obstacle );
|
2021-01-01 00:29:05 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 00:29:05 +00:00
|
|
|
if( nearest.m_distFirst == INT_MAX )
|
2022-08-30 12:52:34 +00:00
|
|
|
nearest = (*obstacleList.begin());
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
return nearest;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE NODE::CheckColliding( const ITEM_SET& aSet, int aKindMask )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( const ITEM* item : aSet.CItems() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
OPT_OBSTACLE obs = CheckColliding( item, aKindMask );
|
|
|
|
|
|
|
|
if( obs )
|
2023-04-09 19:25:22 +00:00
|
|
|
return obs;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
return OPT_OBSTACLE();
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE NODE::CheckColliding( const ITEM* aItemA, int aKindMask )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
OBSTACLES obs;
|
2022-08-15 13:31:43 +00:00
|
|
|
COLLISION_SEARCH_OPTIONS opts;
|
|
|
|
|
|
|
|
opts.m_kindMask = aKindMask;
|
|
|
|
opts.m_limitCount = 1;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( aItemA->Kind() == ITEM::LINE_T )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE* line = static_cast<const LINE*>( aItemA );
|
2014-05-14 13:53:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& l = line->CLine();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
2022-11-16 21:05:12 +00:00
|
|
|
// Note: Clearances between &s and other items are cached,
|
|
|
|
// which means they'll be the same for all segments in the line.
|
|
|
|
// Disabling the cache will lead to slowness.
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const SEGMENT s( *line, l.CSegment( i ) );
|
2022-08-15 13:31:43 +00:00
|
|
|
n += QueryColliding( &s, obs, opts );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( n )
|
2022-08-30 12:52:34 +00:00
|
|
|
return OPT_OBSTACLE( *obs.begin() );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( line->EndsWithVia() )
|
|
|
|
{
|
2022-08-15 13:31:43 +00:00
|
|
|
n += QueryColliding( &line->Via(), obs, opts );
|
2022-11-16 21:05:12 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( n )
|
2022-08-30 12:52:34 +00:00
|
|
|
return OPT_OBSTACLE( *obs.begin() );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-15 13:31:43 +00:00
|
|
|
else if( QueryColliding( aItemA, obs, opts ) > 0 )
|
2021-01-01 01:02:06 +00:00
|
|
|
{
|
2022-08-30 12:52:34 +00:00
|
|
|
return OPT_OBSTACLE( *obs.begin() );
|
2021-01-01 01:02:06 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
return OPT_OBSTACLE();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
struct HIT_VISITOR : public OBSTACLE_VISITOR
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET& m_items;
|
2013-09-26 21:53:54 +00:00
|
|
|
const VECTOR2I& m_point;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
HIT_VISITOR( ITEM_SET& aTab, const VECTOR2I& aPoint ) :
|
2021-07-08 12:33:08 +00:00
|
|
|
OBSTACLE_VISITOR( nullptr ),
|
2021-01-01 01:02:06 +00:00
|
|
|
m_items( aTab ),
|
|
|
|
m_point( aPoint )
|
2014-05-16 11:37:31 +00:00
|
|
|
{}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~HIT_VISITOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool operator()( ITEM* aItem ) override
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
SHAPE_CIRCLE cp( m_point, 0 );
|
|
|
|
|
|
|
|
int cl = 0;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( aItem->Shape()->Collide( &cp, cl ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
m_items.Add( aItem );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET NODE::HitTest( const VECTOR2I& aPoint ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET items;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// fixme: we treat a point as an infinitely small circle - this is inefficient.
|
|
|
|
SHAPE_CIRCLE s( aPoint, 0 );
|
2016-08-15 15:16:49 +00:00
|
|
|
HIT_VISITOR visitor( items, aPoint );
|
2021-07-08 12:33:08 +00:00
|
|
|
visitor.SetWorld( this, nullptr );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
m_index->Query( &s, m_maxClearance, visitor );
|
|
|
|
|
|
|
|
if( !isRoot() ) // fixme: could be made cleaner
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM_SET items_root;
|
2021-07-08 12:33:08 +00:00
|
|
|
visitor.SetWorld( m_root, nullptr );
|
2016-08-15 15:16:49 +00:00
|
|
|
HIT_VISITOR visitor_root( items_root, aPoint );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_root->m_index->Query( &s, m_maxClearance, visitor_root );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : items_root.Items() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
if( !Overrides( item ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
items.Add( item );
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return items;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::addSolid( SOLID* aSolid )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-09-11 21:17:45 +00:00
|
|
|
if( aSolid->HasHole() && aSolid->Hole()->BelongsTo( aSolid ) )
|
2022-08-30 12:52:34 +00:00
|
|
|
addHole( aSolid->Hole() );
|
|
|
|
|
2020-03-03 20:41:30 +00:00
|
|
|
if( aSolid->IsRoutable() )
|
|
|
|
linkJoint( aSolid->Pos(), aSolid->Layers(), aSolid->Net(), aSolid );
|
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
aSolid->SetOwner( this );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Add( aSolid );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
void NODE::Add( std::unique_ptr< SOLID >&& aSolid )
|
2016-08-30 15:28:35 +00:00
|
|
|
{
|
|
|
|
aSolid->SetOwner( this );
|
|
|
|
addSolid( aSolid.release() );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::addVia( VIA* aVia )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-09-11 21:17:45 +00:00
|
|
|
if( aVia->HasHole() && aVia->Hole()->BelongsTo( aVia ) )
|
2022-08-30 12:52:34 +00:00
|
|
|
addHole( aVia->Hole() );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
linkJoint( aVia->Pos(), aVia->Layers(), aVia->Net(), aVia );
|
2022-09-11 21:17:45 +00:00
|
|
|
aVia->SetOwner( this );
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Add( aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
void NODE::addHole( HOLE* aHole )
|
|
|
|
{
|
|
|
|
// do we need holes in the connection graph?
|
|
|
|
//linkJoint( aHole->Pos(), aHole->Layers(), aHole->Net(), aHole );
|
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
aHole->SetOwner( this );
|
2022-08-30 12:52:34 +00:00
|
|
|
m_index->Add( aHole );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
void NODE::Add( std::unique_ptr< VIA >&& aVia )
|
2016-08-30 15:28:35 +00:00
|
|
|
{
|
|
|
|
addVia( aVia.release() );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2023-04-09 19:25:22 +00:00
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
void NODE::add( ITEM* aItem, bool aAllowRedundant )
|
2022-08-30 12:52:34 +00:00
|
|
|
{
|
|
|
|
switch( aItem->Kind() )
|
|
|
|
{
|
|
|
|
case ITEM::ARC_T:
|
|
|
|
addArc( static_cast<ARC*>( aItem ) );
|
|
|
|
break;
|
|
|
|
case ITEM::SEGMENT_T:
|
|
|
|
addSegment( static_cast<SEGMENT*>( aItem ) );
|
|
|
|
break;
|
|
|
|
case ITEM::VIA_T:
|
|
|
|
addVia( static_cast<VIA*>( aItem ) );
|
|
|
|
break;
|
|
|
|
case ITEM::SOLID_T:
|
|
|
|
addSolid( static_cast<SOLID*>( aItem ) );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
void NODE::Add( LINE& aLine, bool aAllowRedundant )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
assert( !aLine.IsLinked() );
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
SHAPE_LINE_CHAIN& l = aLine.Line();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
for( size_t i = 0; i < l.ArcCount(); i++ )
|
|
|
|
{
|
|
|
|
auto s = l.Arc( i );
|
|
|
|
ARC* rarc;
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
if( !aAllowRedundant && ( rarc = findRedundantArc( s.GetP0(), s.GetP1(), aLine.Layers(),
|
|
|
|
aLine.Net() ) ) )
|
2020-11-24 22:16:41 +00:00
|
|
|
{
|
2020-04-15 20:16:24 +00:00
|
|
|
aLine.Link( rarc );
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
2019-05-17 00:13:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto newarc = std::make_unique< ARC >( aLine, s );
|
2020-04-15 20:16:24 +00:00
|
|
|
aLine.Link( newarc.get() );
|
2019-05-17 00:13:21 +00:00
|
|
|
Add( std::move( newarc ), true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
2021-05-06 22:10:39 +00:00
|
|
|
if( l.IsArcSegment( i ) )
|
2019-05-17 00:13:21 +00:00
|
|
|
continue;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
SEG s = l.CSegment( i );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( s.A != s.B )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
SEGMENT* rseg;
|
2020-11-24 22:16:41 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
if( !aAllowRedundant && ( rseg = findRedundantSegment( s.A, s.B, aLine.Layers(),
|
|
|
|
aLine.Net() ) ) )
|
2015-03-10 14:38:27 +00:00
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
// another line could be referencing this segment too :(
|
2020-04-15 20:16:24 +00:00
|
|
|
aLine.Link( rseg );
|
2015-03-10 14:38:27 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<SEGMENT> newseg = std::make_unique<SEGMENT>( aLine, s );
|
2020-04-15 20:16:24 +00:00
|
|
|
aLine.Link( newseg.get() );
|
2016-08-30 18:55:00 +00:00
|
|
|
Add( std::move( newseg ), true );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2016-08-30 15:28:35 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::addSegment( SEGMENT* aSeg )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-09-11 21:17:45 +00:00
|
|
|
aSeg->SetOwner( this );
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
linkJoint( aSeg->Seg().A, aSeg->Layers(), aSeg->Net(), aSeg );
|
|
|
|
linkJoint( aSeg->Seg().B, aSeg->Layers(), aSeg->Net(), aSeg );
|
|
|
|
|
|
|
|
m_index->Add( aSeg );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
bool NODE::Add( std::unique_ptr< SEGMENT >&& aSegment, bool aAllowRedundant )
|
2016-08-30 15:28:35 +00:00
|
|
|
{
|
|
|
|
if( aSegment->Seg().A == aSegment->Seg().B )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ),
|
|
|
|
wxT( "attempting to add a segment with same end coordinates, ignoring." ) );
|
2018-02-08 10:32:13 +00:00
|
|
|
return false;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
if( !aAllowRedundant && findRedundantSegment( aSegment.get() ) )
|
2018-02-08 10:32:13 +00:00
|
|
|
return false;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
addSegment( aSegment.release() );
|
2018-02-08 10:32:13 +00:00
|
|
|
|
|
|
|
return true;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void NODE::addArc( ARC* aArc )
|
|
|
|
{
|
2022-09-11 21:17:45 +00:00
|
|
|
aArc->SetOwner( this );
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
linkJoint( aArc->Anchor( 0 ), aArc->Layers(), aArc->Net(), aArc );
|
|
|
|
linkJoint( aArc->Anchor( 1 ), aArc->Layers(), aArc->Net(), aArc );
|
|
|
|
|
|
|
|
m_index->Add( aArc );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
bool NODE::Add( std::unique_ptr< ARC >&& aArc, bool aAllowRedundant )
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
2021-07-14 01:13:40 +00:00
|
|
|
const SHAPE_ARC& arc = aArc->CArc();
|
|
|
|
|
|
|
|
if( !aAllowRedundant && findRedundantArc( arc.GetP0(), arc.GetP1(), aArc->Layers(),
|
|
|
|
aArc->Net() ) )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
addArc( aArc.release() );
|
2021-07-14 01:13:40 +00:00
|
|
|
return true;
|
2019-05-17 00:13:21 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2022-06-27 21:07:25 +00:00
|
|
|
void NODE::AddEdgeExclusion( std::unique_ptr<SHAPE> aShape )
|
|
|
|
{
|
|
|
|
m_edgeExclusions.push_back( std::move( aShape ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool NODE::QueryEdgeExclusions( const VECTOR2I& aPos ) const
|
|
|
|
{
|
|
|
|
for( const std::unique_ptr<SHAPE>& edgeExclusion : m_edgeExclusions )
|
|
|
|
{
|
|
|
|
if( edgeExclusion->Collide( aPos ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::doRemove( ITEM* aItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
// case 1: removing an item that is stored in the root node from any branch:
|
2013-09-26 21:53:54 +00:00
|
|
|
// mark it as overridden, but do not remove
|
|
|
|
if( aItem->BelongsTo( m_root ) && !isRoot() )
|
2022-08-30 12:52:34 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_override.insert( aItem );
|
2022-09-11 21:17:45 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aItem->HasHole() )
|
|
|
|
m_override.insert( aItem->Hole() );
|
|
|
|
}
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// case 2: the item belongs to this branch or a parent, non-root branch,
|
2013-09-26 21:53:54 +00:00
|
|
|
// or the root itself and we are the root: remove from the index
|
|
|
|
else if( !aItem->BelongsTo( m_root ) || isRoot() )
|
2022-08-30 12:52:34 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Remove( aItem );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-08-30 12:52:34 +00:00
|
|
|
if( aItem->HasHole() )
|
|
|
|
m_index->Remove( aItem->Hole() );
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
// the item belongs to this particular branch: un-reference it
|
|
|
|
if( aItem->BelongsTo( this ) )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2021-07-08 12:33:08 +00:00
|
|
|
aItem->SetOwner( nullptr );
|
2022-08-30 12:52:34 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_root->m_garbageItems.insert( aItem );
|
2022-08-30 12:52:34 +00:00
|
|
|
|
|
|
|
HOLE *hole = aItem->Hole();
|
|
|
|
|
|
|
|
if( hole )
|
|
|
|
{
|
|
|
|
m_index->Remove( hole ); // hole is not directly owned by NODE but by the parent SOLID/VIA.
|
2022-09-11 21:17:45 +00:00
|
|
|
hole->SetOwner( hole->ParentPadVia() );
|
2022-08-30 12:52:34 +00:00
|
|
|
}
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::removeSegmentIndex( SEGMENT* aSeg )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
unlinkJoint( aSeg->Seg().A, aSeg->Layers(), aSeg->Net(), aSeg );
|
|
|
|
unlinkJoint( aSeg->Seg().B, aSeg->Layers(), aSeg->Net(), aSeg );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
void NODE::removeArcIndex( ARC* aArc )
|
|
|
|
{
|
|
|
|
unlinkJoint( aArc->Anchor( 0 ), aArc->Layers(), aArc->Net(), aArc );
|
|
|
|
unlinkJoint( aArc->Anchor( 1 ), aArc->Layers(), aArc->Net(), aArc );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
void NODE::rebuildJoint( const JOINT* aJoint, const ITEM* aItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2021-01-01 01:02:06 +00:00
|
|
|
// We have to split a single joint (associated with a via or a pad, binding together multiple
|
|
|
|
// layers) into multiple independent joints. As I'm a lazy bastard, I simply delete the
|
|
|
|
// via/solid and all its links and re-insert them.
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
std::vector<ITEM*> links( aJoint->LinkList() );
|
|
|
|
JOINT::HASH_TAG tag;
|
|
|
|
int net = aItem->Net();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
tag.net = net;
|
2020-02-28 22:03:04 +00:00
|
|
|
tag.pos = aJoint->Pos();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool split;
|
2021-01-27 22:15:38 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
do
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
split = false;
|
2020-02-28 22:03:04 +00:00
|
|
|
auto range = m_joints.equal_range( tag );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( range.first == m_joints.end() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// find and remove all joints containing the via to be removed
|
|
|
|
|
2020-02-28 22:03:04 +00:00
|
|
|
for( auto f = range.first; f != range.second; ++f )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-02-28 22:03:04 +00:00
|
|
|
if( aItem->LayersOverlap( &f->second ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_joints.erase( f );
|
|
|
|
split = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
} while( split );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
// and re-link them, using the former via's link list
|
2021-01-27 22:15:38 +00:00
|
|
|
for( ITEM* link : links )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-02-28 22:03:04 +00:00
|
|
|
if( link != aItem )
|
|
|
|
linkJoint( tag.pos, link->Layers(), net, link );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2016-08-30 17:01:30 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-02-28 22:03:04 +00:00
|
|
|
|
|
|
|
void NODE::removeViaIndex( VIA* aVia )
|
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jt = FindJoint( aVia->Pos(), aVia->Layers().Start(), aVia->Net() );
|
2020-02-28 22:03:04 +00:00
|
|
|
assert( jt );
|
|
|
|
rebuildJoint( jt, aVia );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::removeSolidIndex( SOLID* aSolid )
|
|
|
|
{
|
2020-08-26 21:57:32 +00:00
|
|
|
if( !aSolid->IsRoutable() )
|
|
|
|
return;
|
|
|
|
|
2020-02-28 22:03:04 +00:00
|
|
|
// fixme: redundant code
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jt = FindJoint( aSolid->Pos(), aSolid->Layers().Start(), aSolid->Net() );
|
2020-02-28 22:03:04 +00:00
|
|
|
assert( jt );
|
|
|
|
rebuildJoint( jt, aSolid );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2022-09-11 21:17:45 +00:00
|
|
|
void NODE::Replace( ITEM* aOldItem, std::unique_ptr< ITEM >&& aNewItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
Remove( aOldItem );
|
2022-09-11 21:17:45 +00:00
|
|
|
add( aNewItem.release() );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::Replace( LINE& aOldLine, LINE& aNewLine )
|
|
|
|
{
|
|
|
|
Remove( aOldLine );
|
|
|
|
Add( aNewLine );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::Remove( SOLID* aSolid )
|
|
|
|
{
|
|
|
|
removeSolidIndex( aSolid );
|
|
|
|
doRemove( aSolid );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::Remove( VIA* aVia )
|
|
|
|
{
|
|
|
|
removeViaIndex( aVia );
|
|
|
|
doRemove( aVia );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::Remove( SEGMENT* aSegment )
|
|
|
|
{
|
|
|
|
removeSegmentIndex( aSegment );
|
|
|
|
doRemove( aSegment );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
void NODE::Remove( ARC* aArc )
|
|
|
|
{
|
|
|
|
removeArcIndex( aArc );
|
|
|
|
doRemove( aArc );
|
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::Remove( ITEM* aItem )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( aItem->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
case ITEM::ARC_T:
|
|
|
|
Remove( static_cast<ARC*>( aItem ) );
|
|
|
|
break;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SOLID_T:
|
2016-08-30 17:01:30 +00:00
|
|
|
Remove( static_cast<SOLID*>( aItem ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2016-08-30 17:01:30 +00:00
|
|
|
Remove( static_cast<SEGMENT*>( aItem ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::LINE_T:
|
2016-12-30 19:14:44 +00:00
|
|
|
{
|
2021-01-01 01:02:06 +00:00
|
|
|
LINE* l = static_cast<LINE*>( aItem );
|
2016-12-30 19:14:44 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
for ( LINKED_ITEM* s : l->Links() )
|
2016-12-30 19:14:44 +00:00
|
|
|
Remove( s );
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
2016-12-30 19:14:44 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2016-08-30 17:01:30 +00:00
|
|
|
Remove( static_cast<VIA*>( aItem ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::Remove( LINE& aLine )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-01-27 22:15:38 +00:00
|
|
|
// LINE does not have a separate remover, as LINEs are never truly a member of the tree
|
2020-04-15 20:16:24 +00:00
|
|
|
std::vector<LINKED_ITEM*>& segRefs = aLine.Links();
|
2016-08-30 17:01:30 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
for( LINKED_ITEM* li : segRefs )
|
2016-08-30 17:01:30 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( li->OfKind( ITEM::SEGMENT_T ) )
|
|
|
|
Remove( static_cast<SEGMENT*>( li ) );
|
|
|
|
else if( li->OfKind( ITEM::ARC_T ) )
|
|
|
|
Remove( static_cast<ARC*>( li ) );
|
2016-08-30 17:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aLine.SetOwner( nullptr );
|
2020-04-15 20:16:24 +00:00
|
|
|
aLine.ClearLinks();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-02-20 16:57:28 +00:00
|
|
|
void NODE::followLine( LINKED_ITEM* aCurrent, bool aScanDirection, int& aPos, int aLimit,
|
2021-01-05 22:55:55 +00:00
|
|
|
VECTOR2I* aCorners, LINKED_ITEM** aSegments, bool* aArcReversed,
|
2021-12-05 18:35:28 +00:00
|
|
|
bool& aGuardHit, bool aStopAtLockedJoints, bool aFollowLockedSegments )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
bool prevReversed = false;
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
const VECTOR2I guard = aCurrent->Anchor( aScanDirection );
|
2014-05-23 09:57:43 +00:00
|
|
|
|
|
|
|
for( int count = 0 ; ; ++count )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-12-05 18:35:28 +00:00
|
|
|
const VECTOR2I p = aCurrent->Anchor( aScanDirection ^ prevReversed );
|
|
|
|
const JOINT* jt = FindJoint( p, aCurrent );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
assert( jt );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-12-05 18:35:28 +00:00
|
|
|
aCorners[aPos] = jt->Pos();
|
|
|
|
aSegments[aPos] = aCurrent;
|
2021-01-05 22:55:55 +00:00
|
|
|
aArcReversed[aPos] = false;
|
|
|
|
|
|
|
|
if( aCurrent->Kind() == ITEM::ARC_T )
|
|
|
|
{
|
2021-12-05 18:35:28 +00:00
|
|
|
if( ( aScanDirection && jt->Pos() == aCurrent->Anchor( 0 ) )
|
|
|
|
|| ( !aScanDirection && jt->Pos() == aCurrent->Anchor( 1 ) ) )
|
2021-01-05 22:55:55 +00:00
|
|
|
aArcReversed[aPos] = true;
|
|
|
|
}
|
|
|
|
|
2015-07-22 11:51:12 +00:00
|
|
|
aPos += ( aScanDirection ? 1 : -1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-05 22:55:55 +00:00
|
|
|
if( count && guard == p )
|
2014-05-23 09:57:43 +00:00
|
|
|
{
|
2021-04-08 03:16:56 +00:00
|
|
|
if( aPos >= 0 && aPos < aLimit )
|
2021-07-08 12:33:08 +00:00
|
|
|
aSegments[aPos] = nullptr;
|
2021-04-08 03:16:56 +00:00
|
|
|
|
2014-05-23 09:57:43 +00:00
|
|
|
aGuardHit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-09 12:31:06 +00:00
|
|
|
bool locked = aStopAtLockedJoints ? jt->IsLocked() : false;
|
|
|
|
|
2021-12-05 18:35:28 +00:00
|
|
|
if( locked || !jt->IsLineCorner( aFollowLockedSegments ) || aPos < 0 || aPos == aLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2021-12-05 18:35:28 +00:00
|
|
|
aCurrent = jt->NextSegment( aCurrent, aFollowLockedSegments );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2021-04-08 03:34:45 +00:00
|
|
|
prevReversed = ( aCurrent && jt->Pos() == aCurrent->Anchor( aScanDirection ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
const LINE NODE::AssembleLine( LINKED_ITEM* aSeg, int* aOriginSegmentIndex,
|
2021-12-05 18:35:28 +00:00
|
|
|
bool aStopAtLockedJoints, bool aFollowLockedSegments )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
const int MaxVerts = 1024 * 16;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-02-23 21:48:30 +00:00
|
|
|
std::array<VECTOR2I, MaxVerts + 1> corners;
|
|
|
|
std::array<LINKED_ITEM*, MaxVerts + 1> segs;
|
|
|
|
std::array<bool, MaxVerts + 1> arcReversed;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE pl;
|
2014-05-23 09:57:43 +00:00
|
|
|
bool guardHit = false;
|
|
|
|
|
2021-04-08 03:34:45 +00:00
|
|
|
int i_start = MaxVerts / 2;
|
|
|
|
int i_end = i_start + 1;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
pl.SetWidth( aSeg->Width() );
|
|
|
|
pl.SetLayers( aSeg->Layers() );
|
|
|
|
pl.SetNet( aSeg->Net() );
|
|
|
|
pl.SetOwner( this );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-02-23 21:48:30 +00:00
|
|
|
followLine( aSeg, false, i_start, MaxVerts, corners.data(), segs.data(), arcReversed.data(),
|
2021-12-05 18:35:28 +00:00
|
|
|
guardHit, aStopAtLockedJoints, aFollowLockedSegments );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-23 09:57:43 +00:00
|
|
|
if( !guardHit )
|
2021-01-05 22:55:55 +00:00
|
|
|
{
|
2021-04-08 03:34:45 +00:00
|
|
|
followLine( aSeg, true, i_end, MaxVerts, corners.data(), segs.data(), arcReversed.data(),
|
2021-12-05 18:35:28 +00:00
|
|
|
guardHit, aStopAtLockedJoints, aFollowLockedSegments );
|
2021-01-05 22:55:55 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
int n = 0;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
LINKED_ITEM* prev_seg = nullptr;
|
2015-07-22 11:51:12 +00:00
|
|
|
bool originSet = false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-04-11 19:15:13 +00:00
|
|
|
SHAPE_LINE_CHAIN& line = pl.Line();
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
for( int i = i_start + 1; i < i_end; i++ )
|
|
|
|
{
|
2021-01-04 02:37:24 +00:00
|
|
|
const VECTOR2I& p = corners[i];
|
|
|
|
LINKED_ITEM* li = segs[i];
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
if( !li || li->Kind() != ITEM::ARC_T )
|
2021-04-11 19:15:13 +00:00
|
|
|
line.Append( p );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
if( li && prev_seg != li )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2021-01-04 02:37:24 +00:00
|
|
|
if( li->Kind() == ITEM::ARC_T )
|
|
|
|
{
|
|
|
|
const ARC* arc = static_cast<const ARC*>( li );
|
|
|
|
const SHAPE_ARC* sa = static_cast<const SHAPE_ARC*>( arc->Shape() );
|
2021-04-08 00:28:30 +00:00
|
|
|
|
2021-04-11 19:15:13 +00:00
|
|
|
int nSegs = line.PointCount();
|
2021-04-12 02:32:11 +00:00
|
|
|
VECTOR2I last = nSegs ? line.CPoint( -1 ) : VECTOR2I();
|
2021-05-06 22:10:39 +00:00
|
|
|
ssize_t lastShape = nSegs ? line.ArcIndex( static_cast<ssize_t>( nSegs ) - 1 ) : -1;
|
2021-04-11 19:15:13 +00:00
|
|
|
|
|
|
|
line.Append( arcReversed[i] ? sa->Reversed() : *sa );
|
2021-01-04 02:37:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pl.Link( li );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-22 11:51:12 +00:00
|
|
|
// latter condition to avoid loops
|
2021-01-04 02:37:24 +00:00
|
|
|
if( li == aSeg && aOriginSegmentIndex && !originSet )
|
2015-07-22 11:51:12 +00:00
|
|
|
{
|
2021-04-12 02:12:53 +00:00
|
|
|
wxASSERT( n < line.SegmentCount() ||
|
|
|
|
( n == line.SegmentCount() && li->Kind() == ITEM::SEGMENT_T ) );
|
2021-08-13 16:13:54 +00:00
|
|
|
*aOriginSegmentIndex = line.PointCount() - 1;
|
2015-07-22 11:51:12 +00:00
|
|
|
originSet = true;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-04 02:37:24 +00:00
|
|
|
prev_seg = li;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 03:36:42 +00:00
|
|
|
// Remove duplicate verts, but do NOT remove colinear segments here!
|
|
|
|
pl.Line().Simplify( false );
|
2021-01-04 02:37:24 +00:00
|
|
|
|
2023-03-02 14:04:37 +00:00
|
|
|
// TODO: maintain actual segment index under simplification system
|
2022-08-01 15:56:11 +00:00
|
|
|
if( aOriginSegmentIndex && *aOriginSegmentIndex >= pl.SegmentCount() )
|
|
|
|
*aOriginSegmentIndex = pl.SegmentCount() - 1;
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
assert( pl.SegmentCount() != 0 );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
return pl;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::FindLineEnds( const LINE& aLine, JOINT& aA, JOINT& aB )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
aA = *FindJoint( aLine.CPoint( 0 ), &aLine );
|
|
|
|
aB = *FindJoint( aLine.CPoint( -1 ), &aLine );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2020-11-18 19:50:36 +00:00
|
|
|
int NODE::FindLinesBetweenJoints( const JOINT& aA, const JOINT& aB, std::vector<LINE>& aLines )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : aA.LinkList() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-12-31 18:04:10 +00:00
|
|
|
if( item->Kind() == ITEM::SEGMENT_T || item->Kind() == ITEM::ARC_T )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2020-12-31 18:04:10 +00:00
|
|
|
LINKED_ITEM* li = static_cast<LINKED_ITEM*>( item );
|
|
|
|
LINE line = AssembleLine( li );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
if( !line.Layers().Overlaps( aB.Layers() ) )
|
2016-01-11 18:37:00 +00:00
|
|
|
continue;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT j_start, j_end;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
FindLineEnds( line, j_start, j_end );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
int id_start = line.CLine().Find( aA.Pos() );
|
|
|
|
int id_end = line.CLine().Find( aB.Pos() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( id_end < id_start )
|
|
|
|
std::swap( id_end, id_start );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( id_start >= 0 && id_end >= 0 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
line.ClipVertexRange( id_start, id_end );
|
2013-09-26 21:53:54 +00:00
|
|
|
aLines.push_back( line );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-06-03 20:36:06 +00:00
|
|
|
void NODE::FixupVirtualVias()
|
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const SEGMENT* locked_seg = nullptr;
|
2021-06-03 20:36:06 +00:00
|
|
|
std::vector<VVIA*> vvias;
|
|
|
|
|
2021-09-22 02:38:53 +00:00
|
|
|
for( auto& jointPair : m_joints )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
2021-09-22 02:38:53 +00:00
|
|
|
JOINT joint = jointPair.second;
|
|
|
|
|
|
|
|
if( joint.Layers().IsMultilayer() )
|
2021-06-03 20:36:06 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int n_seg = 0, n_solid = 0, n_vias = 0;
|
2021-09-22 02:38:53 +00:00
|
|
|
int prev_w = -1;
|
|
|
|
int max_w = -1;
|
2021-06-03 20:36:06 +00:00
|
|
|
bool is_width_change = false;
|
2021-09-22 02:38:53 +00:00
|
|
|
bool is_locked = false;
|
2021-06-03 20:36:06 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
for( const ITEM* item : joint.LinkList() )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
if( item->OfKind( ITEM::VIA_T ) )
|
2021-07-08 12:33:08 +00:00
|
|
|
{
|
2021-06-03 20:36:06 +00:00
|
|
|
n_vias++;
|
2021-07-08 12:33:08 +00:00
|
|
|
}
|
2022-08-29 20:21:46 +00:00
|
|
|
else if( item->OfKind( ITEM::SOLID_T ) )
|
2021-07-08 12:33:08 +00:00
|
|
|
{
|
2021-06-03 20:36:06 +00:00
|
|
|
n_solid++;
|
2021-07-08 12:33:08 +00:00
|
|
|
}
|
2022-08-29 20:21:46 +00:00
|
|
|
else if( const auto t = dyn_cast<const PNS::SEGMENT*>( item ) )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
|
|
|
int w = t->Width();
|
|
|
|
|
|
|
|
if( prev_w >= 0 && w != prev_w )
|
|
|
|
{
|
|
|
|
is_width_change = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_w = std::max( w, max_w );
|
|
|
|
prev_w = w;
|
2021-09-22 02:38:53 +00:00
|
|
|
|
|
|
|
is_locked = t->IsLocked();
|
|
|
|
locked_seg = t;
|
2021-06-03 20:36:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 02:38:53 +00:00
|
|
|
if( ( is_width_change || n_seg >= 3 || is_locked ) && n_solid == 0 && n_vias == 0 )
|
2021-06-03 20:36:06 +00:00
|
|
|
{
|
|
|
|
// fixme: the hull margin here is an ugly temporary workaround. The real fix
|
|
|
|
// is to use octagons for via force propagation.
|
2021-09-22 02:38:53 +00:00
|
|
|
vvias.push_back( new VVIA( joint.Pos(), joint.Layers().Start(),
|
|
|
|
max_w + 2 * PNS_HULL_MARGIN, joint.Net() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( is_locked )
|
|
|
|
{
|
|
|
|
const VECTOR2I& secondPos = ( locked_seg->Seg().A == joint.Pos() ) ?
|
|
|
|
locked_seg->Seg().B :
|
|
|
|
locked_seg->Seg().A;
|
|
|
|
|
|
|
|
vvias.push_back( new VVIA( secondPos, joint.Layers().Start(),
|
|
|
|
max_w + 2 * PNS_HULL_MARGIN, joint.Net() ) );
|
2021-06-03 20:36:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto vvia : vvias )
|
|
|
|
{
|
|
|
|
Add( ItemCast<VIA>( std::move( std::unique_ptr<VVIA>( vvia ) ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* NODE::FindJoint( const VECTOR2I& aPos, int aLayer, int aNet ) const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT::HASH_TAG tag;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
tag.net = aNet;
|
|
|
|
tag.pos = aPos;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2022-08-29 20:21:46 +00:00
|
|
|
JOINT_MAP::const_iterator f = m_joints.find( tag ), end = m_joints.end();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( f == end && !isRoot() )
|
|
|
|
{
|
|
|
|
end = m_root->m_joints.end();
|
|
|
|
f = m_root->m_joints.find( tag ); // m_root->FindJoint(aPos, aLayer, aNet);
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( f == end )
|
2021-07-08 12:33:08 +00:00
|
|
|
return nullptr;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
while( f != end )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
if( f->second.Layers().Overlaps( aLayer ) )
|
|
|
|
return &f->second;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
++f;
|
|
|
|
}
|
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
return nullptr;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::LockJoint( const VECTOR2I& aPos, const ITEM* aItem, bool aLock )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT& jt = touchJoint( aPos, aItem->Layers(), aItem->Net() );
|
2015-08-03 19:11:51 +00:00
|
|
|
jt.Lock( aLock );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT& NODE::touchJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT::HASH_TAG tag;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
tag.pos = aPos;
|
|
|
|
tag.net = aNet;
|
|
|
|
|
|
|
|
// try to find the joint in this node.
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP::iterator f = m_joints.find( tag );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
std::pair<JOINT_MAP::iterator, JOINT_MAP::iterator> range;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
// not found and we are not root? find in the root and copy results here.
|
|
|
|
if( f == m_joints.end() && !isRoot() )
|
|
|
|
{
|
|
|
|
range = m_root->m_joints.equal_range( tag );
|
|
|
|
|
|
|
|
for( f = range.first; f != range.second; ++f )
|
|
|
|
m_joints.insert( *f );
|
|
|
|
}
|
|
|
|
|
|
|
|
// now insert and combine overlapping joints
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT jt( aPos, aLayers, aNet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
bool merged;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
merged = false;
|
|
|
|
range = m_joints.equal_range( tag );
|
|
|
|
|
|
|
|
if( range.first == m_joints.end() )
|
|
|
|
break;
|
|
|
|
|
|
|
|
for( f = range.first; f != range.second; ++f )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
if( aLayers.Overlaps( f->second.Layers() ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
jt.Merge( f->second );
|
|
|
|
m_joints.erase( f );
|
|
|
|
merged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-03-02 14:04:37 +00:00
|
|
|
} while( merged );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
return m_joints.insert( TagJointPair( tag, jt ) )->second;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void JOINT::Dump() const
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "joint layers %d-%d, net %d, pos %s, links: %d" ),
|
2021-01-01 01:02:06 +00:00
|
|
|
m_layers.Start(),
|
|
|
|
m_layers.End(),
|
|
|
|
m_tag.net,
|
|
|
|
m_tag.pos.Format().c_str(),
|
|
|
|
LinkCount() );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
void NODE::linkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT& jt = touchJoint( aPos, aLayers, aNet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
jt.Link( aWhere );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
void NODE::unlinkJoint( const VECTOR2I& aPos, const LAYER_RANGE& aLayers, int aNet, ITEM* aWhere )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
// fixme: remove dangling joints
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT& jt = touchJoint( aPos, aLayers, aNet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
jt.Unlink( aWhere );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::Dump( bool aLong )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2017-11-01 11:14:16 +00:00
|
|
|
std::unordered_set<SEGMENT*> all_segs;
|
2016-08-29 17:31:13 +00:00
|
|
|
SHAPE_INDEX_LIST<ITEM*>::iterator i;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
for( i = m_items.begin(); i != m_items.end(); i++ )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( (*i)->GetKind() == ITEM::SEGMENT_T )
|
|
|
|
all_segs.insert( static_cast<SEGMENT*>( *i ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !isRoot() )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
for( i = m_root->m_items.begin(); i != m_root->m_items.end(); i++ )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( (*i)->GetKind() == ITEM::SEGMENT_T && !overrides( *i ) )
|
|
|
|
all_segs.insert( static_cast<SEGMENT*>(*i) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP::iterator j;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( aLong )
|
2021-01-27 22:15:38 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
for( j = m_joints.begin(); j != m_joints.end(); ++j )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "joint : %s, links : %d\n" ),
|
2021-01-27 22:15:38 +00:00
|
|
|
j->second.GetPos().Format().c_str(), j->second.LinkCount() );
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT::LINKED_ITEMS::const_iterator k;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
for( k = j->second.GetLinkList().begin(); k != j->second.GetLinkList().end(); ++k )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM* m_item = *k;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( m_item->GetKind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const SEGMENT* seg = static_cast<const SEGMENT*>( m_item );
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( " -> seg %s %s\n" ),
|
|
|
|
seg->GetSeg().A.Format().c_str(),
|
|
|
|
seg->GetSeg().B.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 22:15:38 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
int lines_count = 0;
|
|
|
|
|
|
|
|
while( !all_segs.empty() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* s = *all_segs.begin();
|
|
|
|
LINE* l = AssembleLine( s );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE::LinkedSegments* seg_refs = l->GetLinkedSegments();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( aLong )
|
2022-02-05 02:06:25 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "Line: %s, net %d " ),
|
|
|
|
l->GetLine().Format().c_str(), l->GetNet() );
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( std::vector<SEGMENT*>::iterator j = seg_refs->begin(); j != seg_refs->end(); ++j )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "%s " ), (*j)->GetSeg().A.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( j + 1 == seg_refs->end() )
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "%s\n" ), (*j)->GetSeg().B.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
all_segs.erase( *j );
|
|
|
|
}
|
|
|
|
|
|
|
|
lines_count++;
|
|
|
|
}
|
|
|
|
|
2022-02-05 02:06:25 +00:00
|
|
|
wxLogTrace( wxT( "PNS" ), wxT( "Local joints: %d, lines : %d \n" ),
|
|
|
|
m_joints.size(), lines_count );
|
2013-09-18 17:55:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::GetUpdatedItems( ITEM_VECTOR& aRemoved, ITEM_VECTOR& aAdded )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( isRoot() )
|
|
|
|
return;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2020-02-28 22:03:04 +00:00
|
|
|
if( m_override.size() )
|
|
|
|
aRemoved.reserve( m_override.size() );
|
2020-08-16 19:36:58 +00:00
|
|
|
|
2020-02-28 22:03:04 +00:00
|
|
|
if( m_index->Size() )
|
|
|
|
aAdded.reserve( m_index->Size() );
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : m_override )
|
2015-07-07 16:36:38 +00:00
|
|
|
aRemoved.push_back( item );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2023-04-09 19:25:22 +00:00
|
|
|
for( ITEM* item : *m_index )
|
|
|
|
aAdded.push_back( item );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 01:02:06 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::releaseChildren()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
// copy the kids as the NODE destructor erases the item from the parent node.
|
|
|
|
std::set<NODE*> kids = m_children;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( NODE* node : kids )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
node->releaseChildren();
|
|
|
|
delete node;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::releaseGarbage()
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2015-08-12 19:12:12 +00:00
|
|
|
if( !isRoot() )
|
2015-08-03 19:11:51 +00:00
|
|
|
return;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : m_garbageItems )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
|
|
|
if( !item->BelongsTo( this ) )
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_garbageItems.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::Commit( NODE* aNode )
|
2021-01-07 12:13:03 +00:00
|
|
|
{
|
|
|
|
if( aNode->isRoot() )
|
|
|
|
return;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
for( ITEM* item : aNode->m_override )
|
|
|
|
Remove( item );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
for( ITEM* item : *aNode->m_index )
|
|
|
|
{
|
|
|
|
item->SetRank( -1 );
|
|
|
|
item->Unmark();
|
2022-09-11 21:17:45 +00:00
|
|
|
add( item );
|
2018-10-04 12:29:21 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
releaseChildren();
|
|
|
|
releaseGarbage();
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::KillChildren()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
releaseChildren();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
void NODE::AllItemsInNet( int aNet, std::set<ITEM*>& aItems, int aKindMask )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aNet );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( l_cur )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-07 12:13:03 +00:00
|
|
|
for( ITEM* item : *l_cur )
|
|
|
|
{
|
2021-01-07 12:24:13 +00:00
|
|
|
if( item->OfKind( aKindMask ) && item->IsRoutable() )
|
2020-09-04 23:10:26 +00:00
|
|
|
aItems.insert( item );
|
2021-01-07 12:13:03 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !isRoot() )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
INDEX::NET_ITEMS_LIST* l_root = m_root->m_index->GetItemsForNet( aNet );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( l_root )
|
2020-11-24 22:16:41 +00:00
|
|
|
{
|
2021-01-07 12:13:03 +00:00
|
|
|
for( ITEM* item : *l_root )
|
2020-11-24 22:16:41 +00:00
|
|
|
{
|
2021-01-07 12:24:13 +00:00
|
|
|
if( !Overrides( item ) && item->OfKind( aKindMask ) && item->IsRoutable() )
|
2021-01-07 12:13:03 +00:00
|
|
|
aItems.insert( item );
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::ClearRanks( int aMarkerMask )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-01-07 12:13:03 +00:00
|
|
|
for( ITEM* item : *m_index )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2021-01-07 12:13:03 +00:00
|
|
|
item->SetRank( -1 );
|
|
|
|
item->Mark( item->Marker() & ~aMarkerMask );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
void NODE::RemoveByMarker( int aMarker )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2021-04-08 03:34:45 +00:00
|
|
|
std::vector<ITEM*> garbage;
|
2014-06-23 06:50:53 +00:00
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
for( ITEM* item : *m_index )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2019-07-24 15:19:03 +00:00
|
|
|
if( item->Marker() & aMarker )
|
2021-04-08 03:34:45 +00:00
|
|
|
garbage.emplace_back( item );
|
2014-06-23 06:50:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 15:19:03 +00:00
|
|
|
for( ITEM* item : garbage )
|
|
|
|
Remove( item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
SEGMENT* NODE::findRedundantSegment( const VECTOR2I& A, const VECTOR2I& B, const LAYER_RANGE& lr,
|
|
|
|
int aNet )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jtStart = FindJoint( A, lr.Start(), aNet );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !jtStart )
|
2016-08-30 18:55:00 +00:00
|
|
|
return nullptr;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jtStart->LinkList() )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
SEGMENT* seg2 = (SEGMENT*)item;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
const VECTOR2I a2( seg2->Seg().A );
|
|
|
|
const VECTOR2I b2( seg2->Seg().B );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( seg2->Layers().Start() == lr.Start()
|
|
|
|
&& ( ( A == a2 && B == b2 ) || ( A == b2 && B == a2 ) ) )
|
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
return seg2;
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
SEGMENT* NODE::findRedundantSegment( SEGMENT* aSeg )
|
|
|
|
{
|
|
|
|
return findRedundantSegment( aSeg->Seg().A, aSeg->Seg().B, aSeg->Layers(), aSeg->Net() );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
ARC* NODE::findRedundantArc( const VECTOR2I& A, const VECTOR2I& B, const LAYER_RANGE& lr,
|
2020-11-24 22:16:41 +00:00
|
|
|
int aNet )
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
2022-08-29 20:21:46 +00:00
|
|
|
const JOINT* jtStart = FindJoint( A, lr.Start(), aNet );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
if( !jtStart )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
for( ITEM* item : jtStart->LinkList() )
|
|
|
|
{
|
|
|
|
if( item->OfKind( ITEM::ARC_T ) )
|
|
|
|
{
|
|
|
|
ARC* seg2 = static_cast<ARC*>( item );
|
|
|
|
|
|
|
|
const VECTOR2I a2( seg2->Anchor( 0 ) );
|
|
|
|
const VECTOR2I b2( seg2->Anchor( 1 ) );
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( seg2->Layers().Start() == lr.Start()
|
|
|
|
&& ( ( A == a2 && B == b2 ) || ( A == b2 && B == a2 ) ) )
|
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
return seg2;
|
2020-11-24 22:16:41 +00:00
|
|
|
}
|
2019-05-17 00:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-01-07 12:13:03 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
ARC* NODE::findRedundantArc( ARC* aArc )
|
|
|
|
{
|
|
|
|
return findRedundantArc( aArc->Anchor( 0 ), aArc->Anchor( 1 ), aArc->Layers(), aArc->Net() );
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2020-12-23 03:43:44 +00:00
|
|
|
int NODE::QueryJoints( const BOX2I& aBox, std::vector<JOINT*>& aJoints, LAYER_RANGE aLayerMask,
|
2020-11-24 22:16:41 +00:00
|
|
|
int aKindMask )
|
2020-02-19 17:41:13 +00:00
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
aJoints.clear();
|
|
|
|
|
2020-12-23 03:28:13 +00:00
|
|
|
for( JOINT_MAP::value_type& j : m_joints )
|
2020-02-19 17:41:13 +00:00
|
|
|
{
|
2020-12-23 03:43:44 +00:00
|
|
|
if( !j.second.Layers().Overlaps( aLayerMask ) )
|
2020-12-23 03:28:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( aBox.Contains( j.second.Pos() ) && j.second.LinkCount( aKindMask ) )
|
2020-02-19 17:41:13 +00:00
|
|
|
{
|
2020-12-23 03:28:13 +00:00
|
|
|
aJoints.push_back( &j.second );
|
2020-02-19 17:41:13 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( isRoot() )
|
2020-02-19 17:41:13 +00:00
|
|
|
return n;
|
|
|
|
|
2020-12-23 03:28:13 +00:00
|
|
|
for( JOINT_MAP::value_type& j : m_root->m_joints )
|
2020-02-19 17:41:13 +00:00
|
|
|
{
|
2020-12-23 03:43:44 +00:00
|
|
|
if( !Overrides( &j.second ) && j.second.Layers().Overlaps( aLayerMask ) )
|
2020-11-24 22:16:41 +00:00
|
|
|
{
|
2020-12-23 03:28:13 +00:00
|
|
|
if( aBox.Contains( j.second.Pos() ) && j.second.LinkCount( aKindMask ) )
|
2020-02-19 17:41:13 +00:00
|
|
|
{
|
2020-12-23 03:28:13 +00:00
|
|
|
aJoints.push_back( &j.second );
|
2020-02-19 17:41:13 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-17 12:52:18 +00:00
|
|
|
ITEM *NODE::FindItemByParent( const BOARD_ITEM* aParent )
|
2015-07-02 14:09:56 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
if( aParent->IsConnected() )
|
2020-03-06 17:30:56 +00:00
|
|
|
{
|
2020-10-17 12:52:18 +00:00
|
|
|
const BOARD_CONNECTED_ITEM* cItem = static_cast<const BOARD_CONNECTED_ITEM*>( aParent );
|
2023-04-06 14:05:48 +00:00
|
|
|
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( cItem->GetNetCode() );
|
2020-10-17 12:52:18 +00:00
|
|
|
|
|
|
|
if( l_cur )
|
|
|
|
{
|
|
|
|
for( ITEM* item : *l_cur )
|
|
|
|
{
|
|
|
|
if( item->Parent() == aParent )
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
2020-03-06 17:30:56 +00:00
|
|
|
}
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2021-07-08 12:33:08 +00:00
|
|
|
return nullptr;
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|