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 The 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 int startIdx = static_cast<int>( m_subIndices.size() );
36
37 for( int i = startIdx; i <= range.End(); ++i )
38 m_subIndices.emplace_back( std::make_unique<ITEM_SHAPE_INDEX>( i ) );
39 }
40
41 if( !m_deferred )
42 {
43 for( int i = range.Start(); i <= range.End(); ++i )
44 m_subIndices[i]->Add( aItem );
45 }
46
47 m_allItems.insert( aItem );
48 NET_HANDLE net = aItem->Net();
49
50 if( net )
51 m_netMap[net].push_back( aItem );
52}
53
54
55void INDEX::SetDeferred( bool aDeferred )
56{
57 m_deferred = aDeferred;
58}
59
60
62{
63 // Group items by sub-index layer
64 std::map<int, std::vector<std::pair<ITEM*, BOX2I>>> layerItems;
65
66 for( ITEM* item : m_allItems )
67 {
68 const PNS_LAYER_RANGE& range = item->Layers();
69
70 for( int i = range.Start(); i <= range.End(); ++i )
71 {
72 BOX2I box = boundingBox( item, i );
73 layerItems[i].emplace_back( item, box );
74 }
75 }
76
77 // Bulk load each sub-index
78 for( auto& [layerId, items] : layerItems )
79 {
80 if( static_cast<size_t>( layerId ) < m_subIndices.size() )
81 m_subIndices[layerId]->BulkLoad( items );
82 }
83}
84
85
86void INDEX::Remove( ITEM* aItem )
87{
88 const PNS_LAYER_RANGE& range = aItem->Layers();
89 assert( range.Start() != -1 && range.End() != -1 );
90
91 if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
92 return;
93
94 for( int i = range.Start(); i <= range.End(); ++i )
95 m_subIndices[i]->Remove( aItem );
96
97 m_allItems.erase( aItem );
98 NET_HANDLE net = aItem->Net();
99
100 if( net && m_netMap.find( net ) != m_netMap.end() )
101 m_netMap[net].remove( aItem );
102}
103
104
105void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
106{
107 Remove( aOldItem );
108 Add( aNewItem );
109}
110
111
113{
114 if( m_netMap.find( aNet ) == m_netMap.end() )
115 return nullptr;
116
117 return &m_netMap[aNet];
118}
119
120};
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
std::deque< std::unique_ptr< ITEM_SHAPE_INDEX > > m_subIndices
Definition pns_index.h:154
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
ITEM_SET m_allItems
Definition pns_index.h:156
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition pns_index.cpp:86
std::list< ITEM * > NET_ITEMS_LIST
Definition pns_index.h:49
void SetDeferred(bool aDeferred)
When deferred, Add() registers items in metadata but skips spatial index insertion.
Definition pns_index.cpp:55
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.
std::map< NET_HANDLE, NET_ITEMS_LIST > m_netMap
Definition pns_index.h:155
bool m_deferred
Definition pns_index.h:157
void BuildSpatialIndex()
Bulk load the spatial sub-indices from all registered items.
Definition pns_index.cpp:61
Base class for PNS router board items.
Definition pns_item.h:98
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
virtual NET_HANDLE Net() const
Definition pns_item.h:210
Represent a contiguous set of PCB layers.
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition pns_item.h:55
BOX2I boundingBox(T aObject, int aLayer)
Used by SHAPE_INDEX to get the bounding box of a generic T object.
Definition shape_index.h:62