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_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
111 // Don't call footprint->CheckShortingPads(). At the board level we know about nets,
112 // and the pads may have the same net even though they're distinct pads.
113
114 if( footprint->IsNetTie() )
115 {
117 {
118 footprint->CheckNetTies(
119 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
120 const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
121 {
122 errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
123 wxEmptyString, aPosition, footprint->GetLayer() );
124 } );
125 }
126
127 footprint->CheckNetTiePadGroups(
128 [&]( const wxString& aMsg )
129 {
130 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
131 footprint->GetPosition(), footprint->GetLayer() );
132 } );
133 }
134 }
135
136 return !m_drcEngine->IsCancelled();
137}
138
139
140namespace detail
141{
143}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
const FOOTPRINTS & Footprints() const
Definition: board.h:322
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:331
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:59
VECTOR2I GetPosition() const override
Definition: pad.h:201
PCB_LAYER_ID GetPrincipalLayer() const
Definition: pad.cpp:398
@ DRCE_PADSTACK
Definition: drc_item.h:59
@ DRCE_SHORTING_ITEMS
Definition: drc_item.h:40
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition: drc_item.h:76
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition: drc_item.h:79
@ DRCE_FOOTPRINT
Definition: drc_item.h:80
#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