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 (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_PADSTACK_INVALID,
38 - DRCE_FOOTPRINT (unknown or duplicate pads in net-tie pad groups),
39 - DRCE_SHORTING_ITEMS
40*/
41
43{
44public:
46 {
47 m_isRuleDriven = false;
48 }
49
51 {
52 }
53
54 virtual bool Run() override;
55
56 virtual const wxString GetName() const override
57 {
58 return wxT( "footprint checks" );
59 };
60
61 virtual const wxString GetDescription() const override
62 {
63 return wxT( "Check for common footprint pad and component type errors" );
64 }
65};
66
67
69{
70 if( !reportPhase( _( "Checking footprints..." ) ) )
71 return false; // DRC cancelled
72
73 auto errorHandler =
74 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB, const BOARD_ITEM* aItemC,
75 int aErrorCode, const wxString& aMsg, const VECTOR2I& aPt, PCB_LAYER_ID aLayer )
76 {
77 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( aErrorCode );
78
79 if( !aMsg.IsEmpty() )
80 drcItem->SetErrorMessage( drcItem->GetErrorText() + wxS( " " ) + aMsg );
81
82 drcItem->SetItems( aItemA, aItemB, aItemC );
83 reportViolation( drcItem, aPt, aLayer );
84 };
85
86 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
87 {
89 {
90 footprint->CheckFootprintAttributes(
91 [&]( const wxString& aMsg )
92 {
93 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_TYPE_MISMATCH,
94 aMsg, footprint->GetPosition(), footprint->GetLayer() );
95 } );
96 }
97
100 {
101 footprint->CheckPads( m_drcEngine,
102 [&]( const PAD* aPad, int aErrorCode, const wxString& aMsg )
103 {
104 if( !m_drcEngine->IsErrorLimitExceeded( aErrorCode ) )
105 {
106 errorHandler( aPad, nullptr, nullptr, aErrorCode, aMsg,
107 aPad->GetPosition(), aPad->GetPrincipalLayer() );
108 }
109 } );
110 }
111
112 // Don't call footprint->CheckShortingPads(). At the board level we know about nets,
113 // and the pads may have the same net even though they're distinct pads.
114
115 if( footprint->IsNetTie() )
116 {
118 {
119 footprint->CheckNetTies(
120 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
121 const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
122 {
123 errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
124 wxEmptyString, aPosition, footprint->GetLayer() );
125 } );
126 }
127
128 footprint->CheckNetTiePadGroups(
129 [&]( const wxString& aMsg )
130 {
131 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
132 footprint->GetPosition(), footprint->GetLayer() );
133 } );
134 }
135 }
136
137 return !m_drcEngine->IsCancelled();
138}
139
140
141namespace detail
142{
144}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
const FOOTPRINTS & Footprints() const
Definition: board.h:331
BOARD * GetBoard() const
Definition: drc_engine.h:99
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:372
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_ITEM and posi...
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:54
VECTOR2I GetPosition() const override
Definition: pad.h:210
PCB_LAYER_ID GetPrincipalLayer() const
Definition: pad.cpp:316
@ DRCE_PADSTACK
Definition: drc_item.h:62
@ DRCE_SHORTING_ITEMS
Definition: drc_item.h:40
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition: drc_item.h:81
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition: drc_item.h:84
@ DRCE_FOOTPRINT
Definition: drc_item.h:85
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy