2019-04-23 09:46:26 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2020-08-16 19:36:58 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-23 09:46:26 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pns_index.h"
|
2020-08-16 19:36:58 +00:00
|
|
|
#include "pns_router.h"
|
2019-04-23 09:46:26 +00:00
|
|
|
|
|
|
|
namespace PNS {
|
|
|
|
|
|
|
|
|
2020-07-29 03:13:18 +00:00
|
|
|
void INDEX::Add( ITEM* aItem )
|
|
|
|
{
|
2020-07-28 17:17:56 +00:00
|
|
|
const LAYER_RANGE& range = aItem->Layers();
|
2020-07-29 03:13:18 +00:00
|
|
|
|
2020-07-28 17:17:56 +00:00
|
|
|
if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
|
|
|
|
m_subIndices.resize( 2 * range.End() + 1 ); // +1 handles the 0 case
|
|
|
|
|
|
|
|
for( int i = range.Start(); i <= range.End(); ++i )
|
2020-08-16 19:36:58 +00:00
|
|
|
{
|
2020-08-25 16:39:56 +00:00
|
|
|
if( !ROUTER::GetInstance()->GetInterface()->IsOnLayer( aItem, i ) )
|
2020-08-19 13:56:08 +00:00
|
|
|
{
|
|
|
|
if( aItem->AlternateShape() )
|
|
|
|
m_subIndices[i].Add( aItem, aItem->AlternateShape()->BBox() );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxLogError( "Missing expected Alternate shape for %s at %d %d",
|
|
|
|
aItem->Parent()->GetClass(), aItem->Anchor( 0 ).x, aItem->Anchor( 0 ).y );
|
|
|
|
m_subIndices[i].Add( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
else
|
2020-08-19 13:56:08 +00:00
|
|
|
{
|
2020-08-16 19:36:58 +00:00
|
|
|
m_subIndices[i].Add( aItem );
|
2020-08-19 13:56:08 +00:00
|
|
|
}
|
2020-08-16 19:36:58 +00:00
|
|
|
}
|
2020-07-29 03:13:18 +00:00
|
|
|
|
2019-04-23 09:46:26 +00:00
|
|
|
m_allItems.insert( aItem );
|
|
|
|
int net = aItem->Net();
|
|
|
|
|
|
|
|
if( net >= 0 )
|
|
|
|
m_netMap[net].push_back( aItem );
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:17:56 +00:00
|
|
|
|
2019-04-23 09:46:26 +00:00
|
|
|
void INDEX::Remove( ITEM* aItem )
|
|
|
|
{
|
2020-07-28 17:17:56 +00:00
|
|
|
const LAYER_RANGE& range = aItem->Layers();
|
2019-04-23 09:46:26 +00:00
|
|
|
|
2020-07-28 17:17:56 +00:00
|
|
|
if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
|
2019-04-23 09:46:26 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-06 02:35:32 +00:00
|
|
|
for( int i = range.Start(); i <= range.End(); ++i )
|
2020-07-28 17:17:56 +00:00
|
|
|
m_subIndices[i].Remove( aItem );
|
|
|
|
|
2019-04-23 09:46:26 +00:00
|
|
|
m_allItems.erase( aItem );
|
|
|
|
int net = aItem->Net();
|
|
|
|
|
|
|
|
if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
|
|
|
|
m_netMap[net].remove( aItem );
|
|
|
|
}
|
|
|
|
|
2020-07-28 17:17:56 +00:00
|
|
|
|
2019-04-23 09:46:26 +00:00
|
|
|
void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
|
|
|
|
{
|
|
|
|
Remove( aOldItem );
|
|
|
|
Add( aNewItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( int aNet )
|
|
|
|
{
|
|
|
|
if( m_netMap.find( aNet ) == m_netMap.end() )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &m_netMap[aNet];
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|