KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_test_provider_footprint_checks.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
20#include <drc/drc_engine.h>
21#include <drc/drc_item.h>
23#include <footprint.h>
24#include <footprint_utils.h>
25#include <pad.h>
26#include <pad_utils.h>
27
28/*
29 Footprint tests:
30
31 - DRCE_FOOTPRINT_TYPE_MISMATCH,
32 - DRCE_OVERLAPPING_PADS,
33 - DRCE_PAD_TH_WITH_NO_HOLE,
34 - DRCE_PADSTACK,
35 - DRCE_PADSTACK_INVALID,
36 - DRCE_FOOTPRINT (unknown or duplicate pads in net-tie pad groups),
37 - DRCE_SHORTING_ITEMS,
38 - DRCE_FOOTPRINT_SCALED_WITH_PADS
39*/
40
42{
43public:
48
50
51 virtual bool Run() override;
52
53 virtual const wxString GetName() const override { return wxT( "footprint checks" ); };
54};
55
56
58{
59 if( !reportPhase( _( "Checking footprints..." ) ) )
60 return false; // DRC cancelled
61
62 const auto errorHandler =
63 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB, const BOARD_ITEM* aItemC,
64 int aErrorCode, const wxString& aMsg, const VECTOR2I& aPt, PCB_LAYER_ID aLayer )
65 {
66 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( aErrorCode );
67
68 if( !aMsg.IsEmpty() )
69 drcItem->SetErrorDetail( aMsg );
70
71 drcItem->SetItems( aItemA, aItemB, aItemC );
72 reportViolation( drcItem, aPt, aLayer );
73 };
74
75 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
76 {
77 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_FOOTPRINT_TYPE_MISMATCH ) )
78 {
80 [&]( const wxString& aMsg )
81 {
82 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_TYPE_MISMATCH,
83 aMsg, footprint->GetPosition(), footprint->GetLayer() );
84 } );
85 }
86
87 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_FOOTPRINT_SCALED_WITH_PADS ) )
88 {
89 const TRANSFORM_TRS& xform = footprint->GetTransform();
90
91 if( !xform.HasUnitScale() )
92 {
93 if( !footprint->Pads().empty() )
94 {
95 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_SCALED_WITH_PADS, wxEmptyString,
96 footprint->GetPosition(), footprint->GetLayer() );
97 }
98 }
99 }
100
101 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_PAD_TH_WITH_NO_HOLE )
102 || !m_drcEngine->IsErrorLimitExceeded( DRCE_PADSTACK ) )
103 {
105 [&]( const PAD& aPad, const PAD_UTILS::PAD_CHECK_RESULT& aResult )
106 {
107 const int drcPadErrorCode = ConvertPadCheckToDrcCode( aResult.code );
108
109 if( !m_drcEngine->IsErrorLimitExceeded( drcPadErrorCode ) )
110 {
111 wxString detail;
112 if( !aResult.message.IsEmpty() )
113 detail = wxString::Format( wxT( "(%s)" ), aResult.message );
114
115 errorHandler( &aPad, nullptr, nullptr, drcPadErrorCode, detail,
116 aPad.GetPosition(), aPad.GetPrincipalLayer() );
117 }
118 } );
119 }
120
121 // Don't call FOOTPRINT_UTILS::CheckShortingPads(). At the board level we know about nets,
122 // and the pads may have the same net even though they're distinct pads.
123
124 if( footprint->IsNetTie() )
125 {
126 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS ) )
127 {
129 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
130 const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
131 {
132 errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
133 wxEmptyString, aPosition, footprint->GetLayer() );
134 } );
135 }
136
138 [&]( const wxString& aMsg )
139 {
140 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
141 footprint->GetPosition(), footprint->GetLayer() );
142 } );
143 }
144 }
145
146 return !m_drcEngine->IsCancelled();
147}
148
149
150namespace detail
151{
153}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:492
virtual const wxString GetName() const override
virtual ~DRC_TEST_PROVIDER_FOOTPRINT_CHECKS()=default
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
virtual bool reportPhase(const wxString &aStageName)
void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer, const std::function< void(PCB_MARKER *)> &aPathGenerator=[](PCB_MARKER *){})
Definition pad.h:61
VECTOR2I GetPosition() const override
Definition pad.cpp:255
PCB_LAYER_ID GetPrincipalLayer() const
Definition pad.cpp:664
bool HasUnitScale() const
True when both scales are 1, ignoring rounding.
int ConvertPadCheckToDrcCode(PAD_UTILS::PAD_CHECK_CODE aCode)
Map a granular PAD_UTILS::PAD_CHECK_CODE to the DRC error code used to report it at the DRC level (in...
Definition drc_item.cpp:32
@ DRCE_FOOTPRINT_SCALED_WITH_PADS
Definition drc_item.h:100
@ DRCE_PADSTACK
Definition drc_item.h:71
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:49
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:95
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:98
@ DRCE_FOOTPRINT
Definition drc_item.h:99
#define _(s)
Collection of reusable/testable functions for footprint manipulation and validation.
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
void CheckFootprintAttributes(const FOOTPRINT &aFootprint, const std::function< void(const wxString &)> &aErrorHandler)
Check that the footprint's SMD/through-hole attribute matches its pads.
void CheckNetTies(const FOOTPRINT &aFootprint, const std::function< void(const BOARD_ITEM *, const BOARD_ITEM *, const BOARD_ITEM *, const VECTOR2I &)> &aErrorHandler)
Check for un-allowed shorting of pads in net-tie footprints.
void CheckPads(const FOOTPRINT &aFootprint, const UNITS_PROVIDER &aUnitsProvider, const PAD_CHECK_HANDLER &aErrorHandler)
Run non-board-specific DRC checks on footprint's pads.
void CheckNetTiePadGroups(const FOOTPRINT &aFootprint, const std::function< void(const wxString &)> &aErrorHandler)
Sanity check net-tie pad groups.
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
A single finding from CheckPad().
Definition pad_utils.h:107
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708