KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_index.cpp
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "pns_index.h"
23#include "pns_router.h"
24
25namespace PNS {
26
27
28void INDEX::Add( ITEM* aItem )
29{
30 const LAYER_RANGE& range = aItem->Layers();
31 assert( range.Start() != -1 && range.End() != -1 );
32
33 if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
34 m_subIndices.resize( 2 * range.End() + 1 ); // +1 handles the 0 case
35
36 for( int i = range.Start(); i <= range.End(); ++i )
37 m_subIndices[i].Add( aItem );
38
39 m_allItems.insert( aItem );
40 NET_HANDLE net = aItem->Net();
41
42 if( net )
43 m_netMap[net].push_back( aItem );
44}
45
46
47void INDEX::Remove( ITEM* aItem )
48{
49 const LAYER_RANGE& range = aItem->Layers();
50 assert( range.Start() != -1 && range.End() != -1 );
51
52 if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
53 return;
54
55 for( int i = range.Start(); i <= range.End(); ++i )
56 m_subIndices[i].Remove( aItem );
57
58 m_allItems.erase( aItem );
59 NET_HANDLE net = aItem->Net();
60
61 if( net && m_netMap.find( net ) != m_netMap.end() )
62 m_netMap[net].remove( aItem );
63}
64
65
66void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
67{
68 Remove( aOldItem );
69 Add( aNewItem );
70}
71
72
74{
75 if( m_netMap.find( aNet ) == m_netMap.end() )
76 return nullptr;
77
78 return &m_netMap[aNet];
79}
80
81};
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:82
int End() const
Definition: pns_layerset.h:87
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
Definition: pns_index.cpp:66
ITEM_SET m_allItems
Definition: pns_index.h:127
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition: pns_index.cpp:47
std::list< ITEM * > NET_ITEMS_LIST
Definition: pns_index.h:48
void Add(ITEM *aItem)
Adds item to the spatial index.
Definition: pns_index.cpp:28
NET_ITEMS_LIST * GetItemsForNet(NET_HANDLE aNet)
Returns list of all items in a given net.
Definition: pns_index.cpp:73
std::map< NET_HANDLE, NET_ITEMS_LIST > m_netMap
Definition: pns_index.h:126
std::deque< ITEM_SHAPE_INDEX > m_subIndices
Definition: pns_index.h:125
Base class for PNS router board items.
Definition: pns_item.h:97
virtual NET_HANDLE Net() const
Definition: pns_item.h:193
const LAYER_RANGE & Layers() const
Definition: pns_item.h:195
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54