KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_courtyard_index.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <footprint.h>
24
26{
28
29 builder.Reserve( aBoard->Footprints().size() );
30
31 for( FOOTPRINT* footprint : aBoard->Footprints() )
32 {
33 BOX2I bbox;
34 bool hasCourtyard = false;
35
36 // Index by the union of the front and back courtyard bounds so a single query serves
37 // intersectsCourtyard/Front/Back; the downstream per-side test discards any extra hits.
38 for( PCB_LAYER_ID side : { F_Cu, B_Cu } )
39 {
40 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( side );
41
42 if( courtyard.OutlineCount() == 0 )
43 continue;
44
45 if( hasCourtyard )
46 bbox.Merge( courtyard.BBox() );
47 else
48 bbox = courtyard.BBox();
49
50 hasCourtyard = true;
51 }
52
53 if( !hasCourtyard )
54 continue;
55
56 const int min[2] = { bbox.GetLeft(), bbox.GetTop() };
57 const int max[2] = { bbox.GetRight(), bbox.GetBottom() };
58
59 builder.Add( min, max, footprint );
60 }
61
62 m_tree = builder.Build();
63}
64
65
67 const std::function<bool( FOOTPRINT* )>& aVisitor ) const
68{
69 const int min[2] = { aBox.GetLeft(), aBox.GetTop() };
70 const int max[2] = { aBox.GetRight(), aBox.GetBottom() };
71
72 m_tree.Search( min, max, aVisitor );
73}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
const FOOTPRINTS & Footprints() const
Definition board.h:420
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:654
constexpr coord_type GetLeft() const
Definition box2.h:224
constexpr coord_type GetRight() const
Definition box2.h:213
constexpr coord_type GetTop() const
Definition box2.h:225
constexpr coord_type GetBottom() const
Definition box2.h:218
KIRTREE::PACKED_RTREE< FOOTPRINT *, int, 2 > m_tree
void QueryOverlapping(const BOX2I &aBox, const std::function< bool(FOOTPRINT *)> &aVisitor) const
Visit every footprint whose courtyard bounding box overlaps aBox.
FOOTPRINT_COURTYARD_INDEX(const BOARD *aBoard)
Build the index from the board's footprint courtyards (which DRC has already cached).
Builder for constructing a PACKED_RTREE from a set of items.
void Add(const ELEMTYPE aMin[NUMDIMS], const ELEMTYPE aMax[NUMDIMS], const DATATYPE &aData)
void Reserve(size_t aCount)
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60