2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
2014-05-14 13:53:54 +00:00
|
|
|
* Copyright (C) 2013-2014 CERN
|
2016-08-29 14:38:11 +00:00
|
|
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-09-18 17:55:16 +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>
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
|
|
|
|
|
|
|
#include <geometry/seg.h>
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_index.h>
|
|
|
|
|
|
|
|
#include "pns_item.h"
|
|
|
|
#include "pns_line.h"
|
|
|
|
#include "pns_node.h"
|
|
|
|
#include "pns_via.h"
|
|
|
|
#include "pns_solid.h"
|
|
|
|
#include "pns_joint.h"
|
|
|
|
#include "pns_index.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_router.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
|
2017-11-01 11:14:16 +00:00
|
|
|
static std::unordered_set<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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
wxLogTrace( "PNS", "NODE::create %p", this );
|
2014-05-14 13:53:54 +00:00
|
|
|
m_depth = 0;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_root = this;
|
|
|
|
m_parent = NULL;
|
|
|
|
m_maxClearance = 800000; // fixme: depends on how thick traces are.
|
2016-08-15 15:16:47 +00:00
|
|
|
m_ruleResolver = NULL;
|
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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
wxLogTrace( "PNS", "NODE::delete %p", this );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( !m_children.empty() )
|
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "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() )
|
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "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();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
if( (*i)->BelongsTo( this ) )
|
|
|
|
delete *i;
|
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
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::GetClearance( const ITEM* aA, const ITEM* aB ) 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;
|
|
|
|
|
2016-08-15 15:16:47 +00:00
|
|
|
return m_ruleResolver->Clearance( aA, aB );
|
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::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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
wxLogTrace( "PNS", "NODE::branch %p (parent %p)", child, this );
|
2015-02-18 16:53:46 +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
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
// immmediate offspring of the root branch needs not copy anything.
|
|
|
|
// For the rest, deep-copy joints, overridden item map and pointers
|
2013-09-26 21:53:54 +00:00
|
|
|
// to stored items.
|
|
|
|
if( !isRoot() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP::iterator j;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2013-09-26 21:53:54 +00:00
|
|
|
child->m_index->Add( *i );
|
|
|
|
|
|
|
|
child->m_joints = m_joints;
|
|
|
|
child->m_override = m_override;
|
|
|
|
}
|
|
|
|
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "%d items, %d joints, %d overrides",
|
|
|
|
child->m_index->Size(), (int) child->m_joints.size(), (int) child->m_override.size() );
|
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 ),
|
|
|
|
m_node( NULL ),
|
2016-08-15 15:16:49 +00:00
|
|
|
m_override( NULL ),
|
2016-08-15 15:16:53 +00:00
|
|
|
m_extraClearance( 0 )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-09-07 21:15:37 +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
|
|
|
{
|
|
|
|
// check if there is a more recent branch with a newer
|
|
|
|
// (possibily modified) version of this item.
|
|
|
|
if( m_override && m_override->Overrides( aCandidate ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-15 15:16:49 +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
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
///> list of encountered obstacles
|
2014-05-16 11:37:31 +00:00
|
|
|
OBSTACLES& m_tab;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
///> acccepted kinds of colliding items (solids, vias, segments, etc...)
|
|
|
|
int m_kindMask;
|
|
|
|
|
|
|
|
///> max number of hits
|
|
|
|
int m_limitCount;
|
|
|
|
|
|
|
|
///> number of items found so far
|
|
|
|
int m_matchCount;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
///> additional clearance
|
|
|
|
int m_extraClearance;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
bool m_differentNetsOnly;
|
|
|
|
|
|
|
|
int m_forceClearance;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DEFAULT_OBSTACLE_VISITOR( NODE::OBSTACLES& aTab, const ITEM* aItem, int aKindMask, bool aDifferentNetsOnly ) :
|
|
|
|
OBSTACLE_VISITOR( aItem ),
|
2013-09-26 21:53:54 +00:00
|
|
|
m_tab( aTab ),
|
|
|
|
m_kindMask( aKindMask ),
|
|
|
|
m_limitCount( -1 ),
|
2014-05-14 13:53:54 +00:00
|
|
|
m_matchCount( 0 ),
|
2016-08-17 13:09:48 +00:00
|
|
|
m_extraClearance( 0 ),
|
2015-08-19 16:07:16 +00:00
|
|
|
m_differentNetsOnly( aDifferentNetsOnly ),
|
|
|
|
m_forceClearance( -1 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-09-07 21:15:37 +00:00
|
|
|
if( aItem && aItem->Kind() == ITEM::LINE_T )
|
|
|
|
{
|
|
|
|
m_extraClearance += static_cast<const LINE*>( aItem )->Width() / 2;
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
void SetCountLimit( int aLimit )
|
|
|
|
{
|
|
|
|
m_limitCount = aLimit;
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:06:49 +00:00
|
|
|
bool operator()( ITEM* aCandidate ) override
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
if( !aCandidate->OfKind( 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;
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
int clearance = m_extraClearance + m_node->GetClearance( aCandidate, m_item );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( aCandidate->Kind() == ITEM::LINE_T ) // this should never happen.
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
assert( false );
|
2016-08-29 17:31:13 +00:00
|
|
|
clearance += static_cast<LINE*>( aCandidate )->Width() / 2;
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( m_forceClearance >= 0 )
|
|
|
|
clearance = m_forceClearance;
|
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
if( !aCandidate->Collide( m_item, clearance, m_differentNetsOnly ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
return true;
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE obs;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-15 15:16:49 +00:00
|
|
|
obs.m_item = aCandidate;
|
2015-02-18 00:29:54 +00:00
|
|
|
obs.m_head = m_item;
|
2013-09-26 21:53:54 +00:00
|
|
|
m_tab.push_back( obs );
|
|
|
|
|
|
|
|
m_matchCount++;
|
|
|
|
|
|
|
|
if( m_limitCount > 0 && m_matchCount >= m_limitCount )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-08-15 15:16:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::QueryColliding( const ITEM* aItem, OBSTACLE_VISITOR& aVisitor )
|
2016-08-15 15:16:49 +00:00
|
|
|
{
|
|
|
|
aVisitor.SetWorld( this, NULL );
|
|
|
|
m_index->Query( aItem, m_maxClearance, aVisitor );
|
|
|
|
|
|
|
|
// if we haven't found enough items, look in the root branch as well.
|
|
|
|
if( !isRoot() )
|
|
|
|
{
|
|
|
|
aVisitor.SetWorld( m_root, this );
|
|
|
|
m_root->m_index->Query( aItem, m_maxClearance, aVisitor );
|
|
|
|
}
|
2016-08-15 15:16:50 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-08-15 15:16:49 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::QueryColliding( const ITEM* aItem,
|
|
|
|
NODE::OBSTACLES& aObstacles, int aKindMask, int aLimitCount, bool aDifferentNetsOnly, int aForceClearance )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:49 +00:00
|
|
|
DEFAULT_OBSTACLE_VISITOR visitor( aObstacles, aItem, aKindMask, aDifferentNetsOnly );
|
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
|
|
|
|
|
|
|
visitor.SetCountLimit( aLimitCount );
|
|
|
|
visitor.SetWorld( this, NULL );
|
2015-08-19 16:07:16 +00:00
|
|
|
visitor.m_forceClearance = aForceClearance;
|
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.
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !isRoot() && ( visitor.m_matchCount < aLimitCount || aLimitCount < 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE::OPT_OBSTACLE NODE::NearestObstacle( const LINE* aItem, int aKindMask,
|
|
|
|
const std::set<ITEM*>* aRestrictedSet )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
OBSTACLES obs_list;
|
2013-09-26 21:53:54 +00:00
|
|
|
bool found_isects = false;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
const SHAPE_LINE_CHAIN& line = aItem->CLine();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
obs_list.reserve( 100 );
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
for( int i = 0; i < line.SegmentCount(); i++ )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const SEGMENT s( *aItem, line.CSegment( i ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
n += QueryColliding( &s, obs_list, aKindMask );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aItem->EndsWithVia() )
|
2014-05-14 13:53:54 +00:00
|
|
|
n += QueryColliding( &aItem->Via(), obs_list, aKindMask );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( !n )
|
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
|
|
|
LINE& aLine = (LINE&) *aItem;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
OBSTACLE nearest;
|
2014-05-16 11:37:31 +00:00
|
|
|
nearest.m_item = NULL;
|
|
|
|
nearest.m_distFirst = INT_MAX;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( OBSTACLE obs : obs_list )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
VECTOR2I ip_first, ip_last;
|
|
|
|
int dist_max = INT_MIN;
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
if( aRestrictedSet && aRestrictedSet->find( obs.m_item ) == aRestrictedSet->end() )
|
|
|
|
continue;
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
std::vector<SHAPE_LINE_CHAIN::INTERSECTION> isect_list;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
int clearance = GetClearance( obs.m_item, &aLine );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
SHAPE_LINE_CHAIN hull = obs.m_item->Hull( clearance, aItem->Width() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( aLine.EndsWithVia() )
|
|
|
|
{
|
2016-11-25 14:07:23 +00:00
|
|
|
clearance = GetClearance( obs.m_item, &aLine.Via() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
SHAPE_LINE_CHAIN viaHull = aLine.Via().Hull( clearance, aItem->Width() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
viaHull.Intersect( hull, isect_list );
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SHAPE_LINE_CHAIN::INTERSECTION isect : isect_list )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int dist = aLine.CLine().Length() +
|
|
|
|
( isect.p - aLine.Via().Pos() ).EuclideanNorm();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dist < nearest.m_distFirst )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
found_isects = true;
|
2014-05-16 11:37:31 +00:00
|
|
|
nearest.m_distFirst = dist;
|
|
|
|
nearest.m_ipFirst = isect.p;
|
|
|
|
nearest.m_item = obs.m_item;
|
|
|
|
nearest.m_hull = hull;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( dist > dist_max )
|
|
|
|
{
|
|
|
|
dist_max = dist;
|
|
|
|
ip_last = isect.p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isect_list.clear();
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
hull.Intersect( aLine.CLine(), isect_list );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( SHAPE_LINE_CHAIN::INTERSECTION isect : isect_list )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
int dist = aLine.CLine().PathLength( isect.p );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( dist < nearest.m_distFirst )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
found_isects = true;
|
2014-05-16 11:37:31 +00:00
|
|
|
nearest.m_distFirst = dist;
|
|
|
|
nearest.m_ipFirst = isect.p;
|
|
|
|
nearest.m_item = obs.m_item;
|
|
|
|
nearest.m_hull = hull;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
if( dist > dist_max )
|
|
|
|
{
|
|
|
|
dist_max = dist;
|
|
|
|
ip_last = isect.p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
nearest.m_ipLast = ip_last;
|
|
|
|
nearest.m_distLast = dist_max;
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !found_isects )
|
|
|
|
nearest.m_item = obs_list[0].m_item;
|
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 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return obs;
|
|
|
|
}
|
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;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
obs.reserve( 100 );
|
|
|
|
|
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++ )
|
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
const SEGMENT s( *line, l.CSegment( i ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
n += QueryColliding( &s, obs, aKindMask, 1 );
|
|
|
|
|
|
|
|
if( n )
|
2014-05-16 11:37:31 +00:00
|
|
|
return OPT_OBSTACLE( obs[0] );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( line->EndsWithVia() )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
n += QueryColliding( &line->Via(), obs, aKindMask, 1 );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( n )
|
2014-05-16 11:37:31 +00:00
|
|
|
return OPT_OBSTACLE( obs[0] );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( QueryColliding( aItemA, obs, aKindMask, 1 ) > 0 )
|
2014-05-16 11:37:31 +00:00
|
|
|
return OPT_OBSTACLE( obs[0] );
|
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
|
|
|
bool NODE::CheckColliding( const ITEM* aItemA, const ITEM* aItemB, int aKindMask, int aForceClearance )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
assert( aItemB );
|
2015-02-18 00:29:54 +00:00
|
|
|
int clearance;
|
|
|
|
if( aForceClearance >= 0 )
|
|
|
|
clearance = aForceClearance;
|
|
|
|
else
|
|
|
|
clearance = GetClearance( aItemA, aItemB );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
// fixme: refactor
|
2016-08-29 17:31:13 +00:00
|
|
|
if( aItemA->Kind() == ITEM::LINE_T )
|
|
|
|
clearance += static_cast<const LINE*>( aItemA )->Width() / 2;
|
|
|
|
if( aItemB->Kind() == ITEM::LINE_T )
|
|
|
|
clearance += static_cast<const LINE*>( aItemB )->Width() / 2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return aItemA->Collide( aItemB, clearance );
|
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 ) :
|
|
|
|
OBSTACLE_VISITOR( NULL ),
|
2016-08-15 15:16:49 +00:00
|
|
|
m_items( aTab ), m_point( aPoint )
|
2014-05-16 11:37:31 +00:00
|
|
|
{}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
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 );
|
2016-08-15 15:16:53 +00:00
|
|
|
visitor.SetWorld( this, NULL );
|
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;
|
2016-08-15 15:16:53 +00:00
|
|
|
visitor.SetWorld( m_root, NULL );
|
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
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
linkJoint( aSolid->Pos(), aSolid->Layers(), aSolid->Net(), aSolid );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Add( aSolid );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::Add( std::unique_ptr< SOLID > aSolid )
|
|
|
|
{
|
|
|
|
aSolid->SetOwner( this );
|
|
|
|
addSolid( aSolid.release() );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::addVia( VIA* aVia )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
linkJoint( aVia->Pos(), aVia->Layers(), aVia->Net(), aVia );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_index->Add( aVia );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::Add( std::unique_ptr< VIA > aVia )
|
|
|
|
{
|
|
|
|
aVia->SetOwner( this );
|
|
|
|
addVia( aVia.release() );
|
|
|
|
}
|
2013-09-26 21:53:54 +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
|
|
|
|
|
|
|
for( int i = 0; i < l.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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 :(
|
|
|
|
aLine.LinkSegment( rseg );
|
2015-03-10 14:38:27 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
std::unique_ptr< SEGMENT > newseg( new SEGMENT( aLine, s ) );
|
|
|
|
aLine.LinkSegment( newseg.get() );
|
|
|
|
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
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::addSegment( SEGMENT* aSeg )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
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 );
|
|
|
|
}
|
|
|
|
|
2018-02-08 10:32:13 +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
|
|
|
{
|
2016-08-17 14:00:21 +00:00
|
|
|
wxLogTrace( "PNS", "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
|
|
|
aSegment->SetOwner( this );
|
|
|
|
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
|
|
|
|
2016-08-30 15:28:35 +00:00
|
|
|
void NODE::Add( std::unique_ptr< ITEM > aItem, bool aAllowRedundant )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
switch( aItem->Kind() )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SOLID_T:
|
2016-08-30 15:28:35 +00:00
|
|
|
Add( ItemCast<SOLID>( std::move( aItem ) ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2016-08-30 15:28:35 +00:00
|
|
|
Add( ItemCast<SEGMENT>( std::move( aItem ) ), aAllowRedundant );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::LINE_T:
|
2016-08-30 15:28:35 +00:00
|
|
|
assert( false );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2016-08-30 15:28:35 +00:00
|
|
|
Add( ItemCast<VIA>( std::move( aItem ) ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
default:
|
|
|
|
assert( 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() )
|
|
|
|
m_override.insert( aItem );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
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() )
|
|
|
|
m_index->Remove( aItem );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
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
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
aItem->SetOwner( NULL );
|
2015-08-03 19:11:51 +00:00
|
|
|
m_root->m_garbageItems.insert( aItem );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::removeViaIndex( VIA* aVia )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
// We have to split a single joint (associated with a via, binding together multiple layers)
|
|
|
|
// into multiple independent joints. As I'm a lazy bastard, I simply delete the via and all its links and re-insert them.
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT::HASH_TAG tag;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
VECTOR2I p( aVia->Pos() );
|
2016-08-29 17:31:13 +00:00
|
|
|
LAYER_RANGE vLayers( aVia->Layers() );
|
2014-05-14 13:53:54 +00:00
|
|
|
int net = aVia->Net();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* jt = FindJoint( p, vLayers.Start(), net );
|
|
|
|
JOINT::LINKED_ITEMS links( jt->LinkList() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
tag.net = net;
|
|
|
|
tag.pos = p;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
bool split;
|
2014-05-14 13:53:54 +00:00
|
|
|
do
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
split = false;
|
|
|
|
std::pair<JOINT_MAP::iterator, JOINT_MAP::iterator> 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
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
for( JOINT_MAP::iterator f = range.first; f != range.second; ++f )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
if( aVia->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
|
2016-08-29 17:31:13 +00:00
|
|
|
for(ITEM* item : links)
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
if( item != aVia )
|
2016-08-15 15:16:53 +00:00
|
|
|
linkJoint( p, item->Layers(), net, item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2016-08-30 17:01:30 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::removeSolidIndex( SOLID* aSolid )
|
|
|
|
{
|
|
|
|
// fixme: this fucks up the joints, but it's only used for marking colliding obstacles for the moment, so we don't care.
|
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-30 15:28:35 +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 );
|
2016-08-30 15:28:35 +00:00
|
|
|
Add( std::move( aNewItem ) );
|
2013-09-18 17:55:16 +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
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
void NODE::Remove( SOLID* aSolid )
|
|
|
|
{
|
|
|
|
removeSolidIndex( aSolid );
|
|
|
|
doRemove( aSolid );
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE::Remove( VIA* aVia )
|
|
|
|
{
|
|
|
|
removeViaIndex( aVia );
|
|
|
|
doRemove( aVia );
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE::Remove( SEGMENT* aSegment )
|
|
|
|
{
|
|
|
|
removeSegmentIndex( aSegment );
|
|
|
|
doRemove( aSegment );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
{
|
|
|
|
auto l = static_cast<LINE *> ( aItem );
|
|
|
|
|
|
|
|
for ( auto s : l->LinkedSegments() )
|
|
|
|
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
|
|
|
{
|
2016-08-30 17:01:30 +00:00
|
|
|
// LINE does not have a seperate remover, as LINEs are never truly a member of the tree
|
|
|
|
std::vector<SEGMENT*>& segRefs = aLine.LinkedSegments();
|
|
|
|
|
|
|
|
for( SEGMENT* seg : segRefs )
|
|
|
|
{
|
|
|
|
Remove( seg );
|
|
|
|
}
|
|
|
|
|
|
|
|
aLine.SetOwner( nullptr );
|
|
|
|
aLine.ClearSegmentLinks();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::followLine( SEGMENT* aCurrent, bool aScanDirection, int& aPos,
|
|
|
|
int aLimit, VECTOR2I* aCorners, SEGMENT** aSegments, bool& aGuardHit,
|
2016-08-29 14:38:11 +00:00
|
|
|
bool aStopAtLockedJoints )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2013-09-26 21:53:54 +00:00
|
|
|
bool prevReversed = false;
|
|
|
|
|
2014-05-23 09:57:43 +00:00
|
|
|
const VECTOR2I guard = aScanDirection ? aCurrent->Seg().B : aCurrent->Seg().A;
|
|
|
|
|
|
|
|
for( int count = 0 ; ; ++count )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
|
|
|
const VECTOR2I p =
|
2014-05-16 11:37:31 +00:00
|
|
|
( aScanDirection ^ prevReversed ) ? aCurrent->Seg().B : aCurrent->Seg().A;
|
2016-08-29 17:31:13 +00:00
|
|
|
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
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
aCorners[aPos] = jt->Pos();
|
2015-07-22 11:51:12 +00:00
|
|
|
aSegments[aPos] = aCurrent;
|
|
|
|
aPos += ( aScanDirection ? 1 : -1 );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-07-22 11:51:12 +00:00
|
|
|
if( count && guard == p)
|
2014-05-23 09:57:43 +00:00
|
|
|
{
|
|
|
|
aSegments[aPos] = NULL;
|
|
|
|
aGuardHit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-09 12:31:06 +00:00
|
|
|
bool locked = aStopAtLockedJoints ? jt->IsLocked() : false;
|
|
|
|
|
|
|
|
if( locked || !jt->IsLineCorner() || aPos < 0 || aPos == aLimit )
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
aCurrent = jt->NextSegment( aCurrent );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
prevReversed =
|
2015-02-18 16:53:46 +00:00
|
|
|
( jt->Pos() == ( aScanDirection ? aCurrent->Seg().B : aCurrent->Seg().A ) );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const LINE NODE::AssembleLine( SEGMENT* aSeg, int* aOriginSegmentIndex, bool aStopAtLockedJoints )
|
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
|
|
|
|
|
|
|
VECTOR2I corners[MaxVerts + 1];
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* segs[MaxVerts + 1];
|
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;
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
int i_start = MaxVerts / 2, 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
|
|
|
|
2015-10-09 12:31:06 +00:00
|
|
|
followLine( aSeg, false, i_start, MaxVerts, corners, segs, guardHit, aStopAtLockedJoints );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-23 09:57:43 +00:00
|
|
|
if( !guardHit )
|
2015-10-09 12:31:06 +00:00
|
|
|
followLine( aSeg, true, i_end, MaxVerts, corners, segs, guardHit, aStopAtLockedJoints );
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* prev_seg = NULL;
|
2015-07-22 11:51:12 +00:00
|
|
|
bool originSet = false;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
for( int i = i_start + 1; i < i_end; i++ )
|
|
|
|
{
|
|
|
|
const VECTOR2I& p = corners[i];
|
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
pl.Line().Append( p );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-05-23 09:57:43 +00:00
|
|
|
if( segs[i] && prev_seg != segs[i] )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2015-08-03 19:11:51 +00:00
|
|
|
pl.LinkSegment( segs[i] );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-07-22 11:51:12 +00:00
|
|
|
// latter condition to avoid loops
|
|
|
|
if( segs[i] == aSeg && aOriginSegmentIndex && !originSet )
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
*aOriginSegmentIndex = n;
|
2015-07-22 11:51:12 +00:00
|
|
|
originSet = true;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
n++;
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
prev_seg = segs[i];
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
#if 0
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::MapConnectivity( JOINT* aStart, std::vector<JOINT*>& aFoundJoints )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
std::deque<JOINT*> searchQueue;
|
|
|
|
std::set<JOINT*> processed;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
searchQueue.push_back( aStart );
|
|
|
|
processed.insert( aStart );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
while( !searchQueue.empty() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* current = searchQueue.front();
|
2014-05-14 13:53:54 +00:00
|
|
|
searchQueue.pop_front();
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : current->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-29 17:31:13 +00:00
|
|
|
SEGMENT* seg = static_cast<SEGMENT *>( item );
|
|
|
|
JOINT* a = FindJoint( seg->Seg().A, seg );
|
|
|
|
JOINT* b = FindJoint( seg->Seg().B, seg );
|
|
|
|
JOINT* next = ( *a == *current ) ? b : a;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
if( processed.find( next ) == processed.end() )
|
|
|
|
{
|
2014-05-16 11:37:31 +00:00
|
|
|
processed.insert( next );
|
2014-05-14 13:53:54 +00:00
|
|
|
searchQueue.push_back( next );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for(JOINT* jt : processed)
|
2014-05-14 13:53:54 +00:00
|
|
|
aFoundJoints.push_back( jt );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
#endif
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::FindLinesBetweenJoints( JOINT& aA, 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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( item->Kind() == ITEM::SEGMENT_T )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
SEGMENT* seg = static_cast<SEGMENT*>( item );
|
|
|
|
LINE line = AssembleLine( seg );
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
JOINT* NODE::FindJoint( const VECTOR2I& aPos, int aLayer, 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.net = aNet;
|
|
|
|
tag.pos = aPos;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
JOINT_MAP::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 )
|
2014-05-14 13:53:54 +00:00
|
|
|
return NULL;
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return NULL;
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-05-16 11:37:31 +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
|
|
|
{
|
2016-08-25 07:24:43 +00:00
|
|
|
wxLogTrace( "PNS", "joint layers %d-%d, net %d, pos %s, links: %d", m_layers.Start(),
|
2013-09-26 21:53:54 +00:00
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +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
|
|
|
|
2016-08-29 17:31:13 +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 )
|
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
|
|
|
{
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", "joint : %s, links : %d\n",
|
2013-09-26 21:53:54 +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 );
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", " -> seg %s %s\n", seg->GetSeg().A.Format().c_str(),
|
2013-10-14 18:40:36 +00:00
|
|
|
seg->GetSeg().B.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 )
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", "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
|
|
|
{
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", "%s ", (*j)->GetSeg().A.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( j + 1 == seg_refs->end() )
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", "%s\n", (*j)->GetSeg().B.Format().c_str() );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
all_segs.erase( *j );
|
|
|
|
}
|
|
|
|
|
|
|
|
lines_count++;
|
|
|
|
}
|
|
|
|
|
2016-08-15 15:16:54 +00:00
|
|
|
wxLogTrace( "PNS", "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
|
|
|
aRemoved.reserve( m_override.size() );
|
|
|
|
aAdded.reserve( m_index->Size() );
|
|
|
|
|
|
|
|
if( isRoot() )
|
|
|
|
return;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
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
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2013-09-26 21:53:54 +00:00
|
|
|
aAdded.push_back( *i );
|
2013-09-18 17:55:16 +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 )
|
2018-10-04 12:29:21 +00:00
|
|
|
{
|
|
|
|
if( aNode->isRoot() )
|
|
|
|
return;
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2018-10-04 12:29:21 +00:00
|
|
|
for( ITEM* item : aNode->m_override )
|
|
|
|
Remove( item );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2018-10-04 12:29:21 +00:00
|
|
|
for( auto i : *aNode->m_index )
|
|
|
|
{
|
|
|
|
i->SetRank( -1 );
|
|
|
|
i->Unmark();
|
|
|
|
Add( std::unique_ptr<ITEM>( i ) );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2018-10-04 12:29:21 +00:00
|
|
|
releaseChildren();
|
|
|
|
releaseGarbage();
|
|
|
|
}
|
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::KillChildren()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-08-12 19:12:12 +00:00
|
|
|
assert( isRoot() );
|
2013-09-26 21:53:54 +00:00
|
|
|
releaseChildren();
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
void NODE::AllItemsInNet( int aNet, std::set<ITEM*>& aItems )
|
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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM*item : *l_cur )
|
2014-05-16 11:37:31 +00:00
|
|
|
aItems.insert( item );
|
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 )
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::NET_ITEMS_LIST::iterator i = l_root->begin(); i!= l_root->end(); ++i )
|
2016-08-15 15:16:49 +00:00
|
|
|
if( !Overrides( *i ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
aItems.insert( *i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
(*i)->SetRank( -1 );
|
|
|
|
(*i)->Mark( (*i)->Marker() & (~aMarkerMask) );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::FindByMarker( int aMarker, ITEM_SET& aItems )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
|
|
|
if( (*i)->Marker() & aMarker )
|
|
|
|
aItems.Add( *i );
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
int NODE::RemoveByMarker( int aMarker )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
std::list<ITEM*> garbage;
|
2014-06-23 06:50:53 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( INDEX::ITEM_SET::iterator i = m_index->begin(); i != m_index->end(); ++i )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2016-08-15 15:16:53 +00:00
|
|
|
if( (*i)->Marker() & aMarker )
|
2014-05-16 11:37:31 +00:00
|
|
|
{
|
2014-06-23 06:50:53 +00:00
|
|
|
garbage.push_back( *i );
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( std::list<ITEM*>::const_iterator i = garbage.begin(), end = garbage.end(); i != end; ++i )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2014-06-23 06:50:53 +00:00
|
|
|
Remove( *i );
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2016-08-30 18:55:00 +00:00
|
|
|
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
|
|
|
|
2016-08-30 18:55:00 +00:00
|
|
|
if( seg2->Layers().Start() == lr.Start() &&
|
|
|
|
((A == a2 && B == b2) || (A == b2 && B == a2)) )
|
|
|
|
return seg2;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
ITEM *NODE::FindItemByParent( const BOARD_CONNECTED_ITEM* aParent )
|
2015-07-02 14:09:56 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aParent->GetNetCode() );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM*item : *l_cur )
|
2015-07-02 14:11:15 +00:00
|
|
|
if( item->Parent() == aParent )
|
2015-07-02 14:09:56 +00:00
|
|
|
return item;
|
|
|
|
|
|
|
|
return NULL;
|
2015-07-02 14:11:15 +00:00
|
|
|
}
|
2016-08-29 14:38:11 +00:00
|
|
|
|
|
|
|
}
|