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 =
32 [&]( const DRILL_LINE_ITEM& d )
33 {
34 for( DRILL_LINE_ITEM& e : out )
35 {
36 if( e == d )
37 {
38 e.m_Qty++;
39 return;
40 }
41 }
42
43 DRILL_LINE_ITEM n = d;
44 n.m_Qty = 1;
45 out.push_back( n );
46 };
47
48 if( !board )
49 return;
50
51 // Pads
52 for( FOOTPRINT* fp : board->Footprints() )
53 {
54 for( PAD* pad : fp->Pads() )
55 {
56 if( !pad->HasHole() )
57 continue;
58
59 int xs = pad->GetDrillSize().x;
60 int ys = pad->GetDrillSize().y;
61
62 if( xs <= 0 || ys <= 0 )
63 continue;
64
65 PCB_LAYER_ID top, bottom;
66
67 if( pad->GetLayerSet().CuStack().empty() )
68 {
70 bottom = UNDEFINED_LAYER;
71 }
72 else
73 {
74 top = pad->GetLayerSet().CuStack().front();
75 bottom = pad->GetLayerSet().CuStack().back();
76 }
77
78 DRILL_LINE_ITEM d( xs, ys, pad->GetDrillShape(), pad->GetAttribute() != PAD_ATTRIB::NPTH, true, top,
79 bottom );
80
81 addOrIncrement( d );
82 }
83 }
84
85 // Vias
86 for( PCB_TRACK* t : board->Tracks() )
87 {
88 if( t->Type() != PCB_VIA_T )
89 continue;
90
91 PCB_VIA* via = static_cast<PCB_VIA*>( t );
92 int dmm = via->GetDrillValue();
93
94 if( dmm <= 0 )
95 continue;
96
97 DRILL_LINE_ITEM d( dmm, dmm, PAD_DRILL_SHAPE::CIRCLE, true, false, via->TopLayer(), via->BottomLayer() );
98 addOrIncrement( d );
99 }
100}
101
void CollectDrillLineItems(BOARD *board, std::vector< DRILL_LINE_ITEM > &out)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
const FOOTPRINTS & Footprints() const
Definition board.h:363
const TRACKS & Tracks() const
Definition board.h:361
Definition pad.h:55
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:103
KIBIS top(path, &reporter)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:97