router: copy m_maxClearance when cloning/branching PNS::NODEs

Fixes: lp:1813328
* https://bugs.launchpad.net/kicad/+bug/1813328

(cherry picked from commit 9e00f48efc)
This commit is contained in:
Tomasz Włostowski 2019-04-23 11:46:26 +02:00 committed by John Beard
parent 89d39cf8ff
commit d94b8b9c0e
4 changed files with 149 additions and 116 deletions

View File

@ -17,6 +17,7 @@ set( PCBNEW_PNS_SRCS
pns_diff_pair_placer.cpp
pns_dp_meander_placer.cpp
pns_dragger.cpp
pns_index.cpp
pns_item.cpp
pns_itemset.cpp
pns_line.cpp

146
pcbnew/router/pns_index.cpp Normal file
View File

@ -0,0 +1,146 @@
/*
* KiRouter - a push-and-(sometimes-)shove PCB router
*
* Copyright (C) 2013-2014 CERN
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pns_index.h"
namespace PNS {
INDEX::INDEX()
{
memset( m_subIndices, 0, sizeof( m_subIndices ) );
}
INDEX::~INDEX()
{
Clear();
}
INDEX::ITEM_SHAPE_INDEX* INDEX::getSubindex( const ITEM* aItem )
{
int idx_n = -1;
const LAYER_RANGE l = aItem->Layers();
switch( aItem->Kind() )
{
case ITEM::VIA_T:
idx_n = SI_Multilayer;
break;
case ITEM::SOLID_T:
{
if( l.IsMultilayer() )
idx_n = SI_Multilayer;
else if( l.Start() == B_Cu ) // fixme: use kicad layer codes
idx_n = SI_PadsTop;
else if( l.Start() == F_Cu )
idx_n = SI_PadsBottom;
else
idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
}
break;
case ITEM::SEGMENT_T:
case ITEM::LINE_T:
idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
break;
default:
break;
}
if( idx_n < 0 || idx_n >= MaxSubIndices )
{
wxASSERT( idx_n >= 0 );
wxASSERT( idx_n < MaxSubIndices );
return nullptr;
}
if( !m_subIndices[idx_n] )
m_subIndices[idx_n] = new ITEM_SHAPE_INDEX;
return m_subIndices[idx_n];
}
void INDEX::Add( ITEM* aItem )
{
ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Add( aItem );
m_allItems.insert( aItem );
int net = aItem->Net();
if( net >= 0 )
{
m_netMap[net].push_back( aItem );
}
}
void INDEX::Remove( ITEM* aItem )
{
ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Remove( aItem );
m_allItems.erase( aItem );
int net = aItem->Net();
if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
m_netMap[net].remove( aItem );
}
void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
{
Remove( aOldItem );
Add( aNewItem );
}
void INDEX::Clear()
{
for( int i = 0; i < MaxSubIndices; ++i )
{
ITEM_SHAPE_INDEX* idx = m_subIndices[i];
if( idx )
delete idx;
m_subIndices[i] = NULL;
}
}
INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet )
{
if( m_netMap.find( aNet ) == m_netMap.end() )
return NULL;
return &m_netMap[aNet];
}
};

View File

@ -159,95 +159,6 @@ private:
ITEM_SET m_allItems;
};
INDEX::INDEX()
{
memset( m_subIndices, 0, sizeof( m_subIndices ) );
}
INDEX::ITEM_SHAPE_INDEX* INDEX::getSubindex( const ITEM* aItem )
{
int idx_n = -1;
const LAYER_RANGE l = aItem->Layers();
switch( aItem->Kind() )
{
case ITEM::VIA_T:
idx_n = SI_Multilayer;
break;
case ITEM::SOLID_T:
{
if( l.IsMultilayer() )
idx_n = SI_Multilayer;
else if( l.Start() == B_Cu ) // fixme: use kicad layer codes
idx_n = SI_PadsTop;
else if( l.Start() == F_Cu )
idx_n = SI_PadsBottom;
else
idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
}
break;
case ITEM::SEGMENT_T:
case ITEM::LINE_T:
idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
break;
default:
break;
}
if( idx_n < 0 || idx_n >= MaxSubIndices )
{
wxASSERT( idx_n >= 0 );
wxASSERT( idx_n < MaxSubIndices );
return nullptr;
}
if( !m_subIndices[idx_n] )
m_subIndices[idx_n] = new ITEM_SHAPE_INDEX;
return m_subIndices[idx_n];
}
void INDEX::Add( ITEM* aItem )
{
ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Add( aItem );
m_allItems.insert( aItem );
int net = aItem->Net();
if( net >= 0 )
{
m_netMap[net].push_back( aItem );
}
}
void INDEX::Remove( ITEM* aItem )
{
ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
if( !idx )
return;
idx->Remove( aItem );
m_allItems.erase( aItem );
int net = aItem->Net();
if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
m_netMap[net].remove( aItem );
}
void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
{
Remove( aOldItem );
Add( aNewItem );
}
template<class Visitor>
int INDEX::querySingle( int index, const SHAPE* aShape, int aMinDistance, Visitor& aVisitor )
@ -302,32 +213,6 @@ int INDEX::Query( const SHAPE* aShape, int aMinDistance, Visitor& aVisitor )
return total;
}
void INDEX::Clear()
{
for( int i = 0; i < MaxSubIndices; ++i )
{
ITEM_SHAPE_INDEX* idx = m_subIndices[i];
if( idx )
delete idx;
m_subIndices[i] = NULL;
}
}
INDEX::~INDEX()
{
Clear();
}
INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet )
{
if( m_netMap.find( aNet ) == m_netMap.end() )
return NULL;
return &m_netMap[aNet];
}
}
};
#endif

View File

@ -116,6 +116,7 @@ NODE* NODE::Branch()
child->m_parent = this;
child->m_ruleResolver = m_ruleResolver;
child->m_root = isRoot() ? this : m_root;
child->m_maxClearance = m_maxClearance;
// immmediate offspring of the root branch needs not copy anything.
// For the rest, deep-copy joints, overridden item map and pointers