2019-04-23 09:46:26 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2023-08-22 12:06:33 +00:00
|
|
|
* Copyright (C) 2016-2023 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();
|
2023-11-28 17:55:37 +00:00
|
|
|
assert( range.Start() != -1 && range.End() != -1 );
|
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 )
|
2021-01-01 00:29:05 +00:00
|
|
|
m_subIndices[i].Add( aItem );
|
2020-07-29 03:13:18 +00:00
|
|
|
|
2019-04-23 09:46:26 +00:00
|
|
|
m_allItems.insert( aItem );
|
2023-08-22 12:06:33 +00:00
|
|
|
NET_HANDLE net = aItem->Net();
|
2019-04-23 09:46:26 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
if( net )
|
2019-04-23 09:46:26 +00:00
|
|
|
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();
|
2023-11-28 17:55:37 +00:00
|
|
|
assert( range.Start() != -1 && range.End() != -1 );
|
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 );
|
2023-08-22 12:06:33 +00:00
|
|
|
NET_HANDLE net = aItem->Net();
|
2019-04-23 09:46:26 +00:00
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
if( net && m_netMap.find( net ) != m_netMap.end() )
|
2019-04-23 09:46:26 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-22 12:06:33 +00:00
|
|
|
INDEX::NET_ITEMS_LIST* INDEX::GetItemsForNet( NET_HANDLE aNet )
|
2019-04-23 09:46:26 +00:00
|
|
|
{
|
|
|
|
if( m_netMap.find( aNet ) == m_netMap.end() )
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2019-04-23 09:46:26 +00:00
|
|
|
|
|
|
|
return &m_netMap[aNet];
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|