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 PNS_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 {
35 for( int i = 0; i <= range.End(); ++i )
36 m_subIndices.emplace_back( std::make_unique<ITEM_SHAPE_INDEX>( i ) );
37 }
38
39 for( int i = range.Start(); i <= range.End(); ++i )
40 m_subIndices[i]->Add( aItem );
41
42 m_allItems.insert( aItem );
43 NET_HANDLE net = aItem->Net();
44
45 if( net )
46 m_netMap[net].push_back( aItem );
47}
48
49
50void INDEX::Remove( ITEM* aItem )
51{
52 const PNS_LAYER_RANGE& range = aItem->Layers();
53 assert( range.Start() != -1 && range.End() != -1 );
54
55 if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
56 return;
57
58 for( int i = range.Start(); i <= range.End(); ++i )
59 m_subIndices[i]->Remove( aItem );
60
61 m_allItems.erase( aItem );
62 NET_HANDLE net = aItem->Net();
63
64 if( net && m_netMap.find( net ) != m_netMap.end() )
65 m_netMap[net].remove( aItem );
66}
67
68
69void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
70{
71 Remove( aOldItem );
72 Add( aNewItem );
73}
74
75
77{
78 if( m_netMap.find( aNet ) == m_netMap.end() )
79 return nullptr;
80
81 return &m_netMap[aNet];
82}
83
84};
std::deque< std::unique_ptr< ITEM_SHAPE_INDEX > > m_subIndices
Definition: pns_index.h:126
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
Definition: pns_index.cpp:69
ITEM_SET m_allItems
Definition: pns_index.h:128
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition: pns_index.cpp:50
std::list< ITEM * > NET_ITEMS_LIST
Definition: pns_index.h:49
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:76
std::map< NET_HANDLE, NET_ITEMS_LIST > m_netMap
Definition: pns_index.h:127
Base class for PNS router board items.
Definition: pns_item.h:97
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
virtual NET_HANDLE Net() const
Definition: pns_item.h:197
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:86
int End() const
Definition: pns_layerset.h:91
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54