KiCad PCB EDA Suite
Loading...
Searching...
No Matches
board_statistics.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, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <board.h>
21#include <footprint.h>
22#include <pad.h>
23#include <pcb_track.h>
24#include <board_statistics.h>
25
26
27void CollectDrillLineItems( BOARD* board, std::vector<DRILL_LINE_ITEM>& out )
28{
29 out.clear();
30
31 auto addOrIncrement = [&]( const DRILL_LINE_ITEM& d )
32 {
33 for( DRILL_LINE_ITEM& e : out )
34 {
35 if( e == d )
36 {
37 e.m_Qty++;
38 return;
39 }
40 }
41
42 DRILL_LINE_ITEM n = d;
43 n.m_Qty = 1;
44 out.push_back( n );
45 };
46
47 if( !board )
48 return;
49
50 // Pads
51 for( FOOTPRINT* fp : board->Footprints() )
52 {
53 for( PAD* pad : fp->Pads() )
54 {
55 if( !pad->HasHole() )
56 continue;
57
58 int xs = pad->GetDrillSize().x;
59 int ys = pad->GetDrillSize().y;
60
61 if( xs <= 0 || ys <= 0 )
62 continue;
63
64 PCB_LAYER_ID top, bottom;
65
66 if( pad->GetLayerSet().CuStack().empty() )
67 {
68 top = UNDEFINED_LAYER;
69 bottom = UNDEFINED_LAYER;
70 }
71 else
72 {
73 top = pad->GetLayerSet().CuStack().front();
74 bottom = pad->GetLayerSet().CuStack().back();
75 }
76
77 DRILL_LINE_ITEM d( xs, ys, pad->GetDrillShape(), pad->GetAttribute() != PAD_ATTRIB::NPTH, true, top,
78 bottom );
79
80 addOrIncrement( d );
81 }
82 }
83
84 // Vias
85 for( PCB_TRACK* t : board->Tracks() )
86 {
87 if( t->Type() != PCB_VIA_T )
88 continue;
89
90 PCB_VIA* via = static_cast<PCB_VIA*>( t );
91 int dmm = via->GetDrillValue();
92
93 if( dmm <= 0 )
94 continue;
95
96 DRILL_LINE_ITEM d( dmm, dmm, PAD_DRILL_SHAPE::CIRCLE, true, false, via->TopLayer(), via->BottomLayer() );
97 addOrIncrement( d );
98 }
99}
100
void CollectDrillLineItems(BOARD *board, std::vector< DRILL_LINE_ITEM > &out)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
const FOOTPRINTS & Footprints() const
Definition board.h:358
const TRACKS & Tracks() const
Definition board.h:356
Definition pad.h:54
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ UNDEFINED_LAYER
Definition layer_ids.h:61
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:87
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97