KiCad PCB EDA Suite
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 (C) 2022 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <drc/drc_engine.h>
25#include <drc/drc_item.h>
27#include <footprint.h>
28#include <pad.h>
29
30/*
31 Footprint tests:
32
33 - DRCE_FOOTPRINT_TYPE_MISMATCH,
34 - DRCE_OVERLAPPING_PADS,
35 - DRCE_PAD_TH_WITH_NO_HOLE,
36 - DRCE_PADSTACK,
37 - DRCE_FOOTPRINT (unknown or duplicate pads in net-tie pad groups),
38 - DRCE_SHORTING_ITEMS
39*/
40
42{
43public:
45 {
46 m_isRuleDriven = false;
47 }
48
50 {
51 }
52
53 virtual bool Run() override;
54
55 virtual const wxString GetName() const override
56 {
57 return wxT( "footprint checks" );
58 };
59
60 virtual const wxString GetDescription() const override
61 {
62 return wxT( "Check for common footprint pad and component type errors" );
63 }
64};
65
66
68{
69 if( !reportPhase( _( "Checking footprints..." ) ) )
70 return false; // DRC cancelled
71
72 auto errorHandler =
73 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB, const BOARD_ITEM* aItemC,
74 int aErrorCode, const wxString& aMsg, const VECTOR2I& aPt, PCB_LAYER_ID aLayer )
75 {
76 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( aErrorCode );
77
78 if( !aMsg.IsEmpty() )
79 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + aMsg );
80
81 drcItem->SetItems( aItemA, aItemB, aItemC );
82 reportViolation( drcItem, aPt, aLayer );
83 };
84
85 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
86 {
88 {
89 footprint->CheckFootprintAttributes(
90 [&]( const wxString& aMsg )
91 {
92 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_TYPE_MISMATCH,
93 aMsg, footprint->GetPosition(), footprint->GetLayer() );
94 } );
95 }
96
99 {
100 footprint->CheckPads(
101 [&]( const PAD* aPad, int aErrorCode, const wxString& aMsg )
102 {
103 if( !m_drcEngine->IsErrorLimitExceeded( aErrorCode ) )
104 {
105 errorHandler( aPad, nullptr, nullptr, aErrorCode, aMsg,
106 aPad->GetPosition(), aPad->GetPrincipalLayer() );
107 }
108 } );
109 }
110
112 {
113 footprint->CheckShortingPads(
114 [&]( const PAD* aPadA, const PAD* aPadB, const VECTOR2I& aPosition )
115 {
116 errorHandler( aPadA, aPadB, nullptr, DRCE_SHORTING_ITEMS, wxEmptyString,
117 aPosition, aPadA->GetPrincipalLayer() );
118 } );
119 }
120
121 if( footprint->IsNetTie() )
122 {
124 {
125 footprint->CheckNetTies(
126 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
127 const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
128 {
129 errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
130 wxEmptyString, aPosition, footprint->GetLayer() );
131 } );
132 }
133
134 footprint->CheckNetTiePadGroups(
135 [&]( const wxString& aMsg )
136 {
137 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
138 footprint->GetPosition(), footprint->GetLayer() );
139 } );
140 }
141 }
142
143 return !m_drcEngine->IsCancelled();
144}
145
146
147namespace detail
148{
150}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
FOOTPRINTS & Footprints()
Definition: board.h:307
BOARD * GetBoard() const
Definition: drc_engine.h:89
bool IsErrorLimitExceeded(int error_code)
bool IsCancelled() const
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:325
virtual const wxString GetName() const override
virtual const wxString GetDescription() const override
virtual bool Run() override
Run this provider against the given PCB with configured options (if any).
Represent a DRC "provider" which runs some DRC functions over a BOARD and spits out #DRC_ITEMs and po...
virtual bool reportPhase(const wxString &aStageName)
virtual void reportViolation(std::shared_ptr< DRC_ITEM > &item, const VECTOR2I &aMarkerPos, int aMarkerLayer)
DRC_ENGINE * m_drcEngine
Definition: pad.h:58
VECTOR2I GetPosition() const override
Definition: pad.h:196
PCB_LAYER_ID GetPrincipalLayer() const
Definition: pad.cpp:223
@ DRCE_PADSTACK
Definition: drc_item.h:59
@ DRCE_SHORTING_ITEMS
Definition: drc_item.h:40
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition: drc_item.h:75
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition: drc_item.h:78
@ DRCE_FOOTPRINT
Definition: drc_item.h:79
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy