KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_fab_pin.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
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
22#include <boost/test/unit_test.hpp>
23#include <json_common.h>
24
25#include <array>
26#include <memory>
27#include <set>
28#include <string>
29
30#include <board.h>
31#include <footprint.h>
32#include <pad.h>
34
35
37{
38 const std::array<const char*, 3> boardNames = { "connect/connect.kicad_pcb",
39 "issue19325/issue19325.kicad_pcb",
40 "issue14130.kicad_pcb" };
41 size_t fiducials = 0;
42 size_t castellated = 0;
43 size_t tooling = 0;
44 size_t issue14130NpthTht = 0;
45 size_t issue14130NpthHole = 0;
46 size_t plated = 0;
47 size_t padCount = 0;
48 std::set<wxString> issue14130NpthNames;
49
50 for( const char* boardName : boardNames )
51 {
52 std::unique_ptr<BOARD> board = KI_TEST::RequireBoardFromPcbnewQAData( boardName );
53
54 for( const FOOTPRINT* footprint : board->Footprints() )
55 {
56 for( size_t index = 0; index < footprint->Pads().size(); ++index )
57 {
58 const PAD* pad = footprint->Pads()[index];
59 FAB_PIN fabPin = MakeFabPin( *pad, index );
60 std::string location = std::string( boardName ) + "/" + footprint->GetReference().ToStdString() + "/"
61 + std::to_string( index );
62 ++padCount;
63
64 if( pad->GetProperty() == PAD_PROP::FIDUCIAL_GLBL )
65 {
66 ++fiducials;
68 }
69
70 if( pad->GetProperty() == PAD_PROP::CASTELLATED )
71 {
72 ++castellated;
73 BOOST_CHECK( GetFabPadRole( *pad ) == FAB_PAD_ROLE::CASTELLATED );
74 }
75
76 if( pad->GetAttribute() == PAD_ATTRIB::NPTH && pad->GetNumber().IsEmpty()
77 && pad->GetProperty() == PAD_PROP::NONE )
78 {
79 ++tooling;
80 BOOST_CHECK( GetFabPadRole( *pad ) == FAB_PAD_ROLE::TOOLING_HOLE );
81 BOOST_CHECK( pad->HasHole() );
82 BOOST_CHECK( fabPin.m_mount == FAB_MOUNT::THT || fabPin.m_mount == FAB_MOUNT::HOLE );
83 BOOST_CHECK( fabPin.m_electrical == FAB_ELECTRICAL::MECHANICAL );
84 }
85
86 if( std::string( boardName ) == "issue14130.kicad_pcb"
87 && footprint->GetReference() == wxS( "P2" ) && pad->GetAttribute() == PAD_ATTRIB::NPTH )
88 {
89 BOOST_CHECK_MESSAGE( issue14130NpthNames.insert( fabPin.m_name ).second,
90 location << " repeats an NPTH pin name" );
91
92 if( fabPin.m_mount == FAB_MOUNT::THT )
93 {
94 ++issue14130NpthTht;
95 }
96 else if( fabPin.m_mount == FAB_MOUNT::HOLE )
97 {
98 ++issue14130NpthHole;
99 }
100 }
101
102 if( std::string( boardName ) == "connect/connect.kicad_pcb"
103 && pad->GetAttribute() != PAD_ATTRIB::NPTH && !pad->GetNumber().IsEmpty()
104 && pad->IsOnCopperLayer() )
105 {
106 ++plated;
107 BOOST_CHECK( fabPin.m_electrical == FAB_ELECTRICAL::ELECTRICAL );
108 }
109 }
110 }
111 }
112
113 BOOST_CHECK_GT( fiducials, 0 );
114 BOOST_CHECK_GT( castellated, 0 );
115 BOOST_CHECK_GT( tooling, 0 );
116 BOOST_CHECK_GT( plated, 0 );
117 BOOST_CHECK_EQUAL( issue14130NpthNames.size(), 7 );
118 BOOST_CHECK_EQUAL( issue14130NpthTht, 1 );
119 BOOST_CHECK_EQUAL( issue14130NpthHole, 6 );
120 BOOST_CHECK_GT( padCount, 0 );
121}
int index
General utilities for PCB file IO for QA programs.
Definition pad.h:61
FAB_PAD_ROLE GetFabPadRole(const PAD &aPad)
Explicit fabrication properties take precedence over the unnumbered NPTH fallback.
Definition fab_pin.cpp:26
FAB_PIN MakeFabPin(const PAD &aPad, size_t aIndexInFootprint)
aIndexInFootprint is the pad's position in its footprint, used to name NPTH and unnumbered pads
Definition fab_pin.cpp:50
@ FIDUCIAL_GLOBAL
Definition fab_pin.h:31
std::unique_ptr< BOARD > RequireBoardFromPcbnewQAData(const std::filesystem::path &aFilename)
Require a board from the path relative to the pcbnew QA data directory.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:102
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
Definition padstack.h:116
@ NONE
no special fabrication property
Definition padstack.h:114
@ CASTELLATED
a pad with a castellated through hole
Definition padstack.h:120
wxString m_name
Definition fab_pin.h:58
FAB_ELECTRICAL m_electrical
Definition fab_pin.h:61
FAB_MOUNT m_mount
Definition fab_pin.h:60
BOOST_AUTO_TEST_CASE(FabPinRoles)
VECTOR2I location
BOOST_CHECK_EQUAL(result, "25.4")