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 <pad.h>
25
26/*
27 Footprint tests:
28
29 - DRCE_FOOTPRINT_TYPE_MISMATCH,
30 - DRCE_OVERLAPPING_PADS,
31 - DRCE_PAD_TH_WITH_NO_HOLE,
32 - DRCE_PADSTACK,
33 - DRCE_PADSTACK_INVALID,
34 - DRCE_FOOTPRINT (unknown or duplicate pads in net-tie pad groups),
35 - DRCE_SHORTING_ITEMS,
36 - DRCE_FOOTPRINT_SCALED_WITH_PADS
37*/
38
40{
41public:
46
48
49 virtual bool Run() override;
50
51 virtual const wxString GetName() const override { return wxT( "footprint checks" ); };
52};
53
54
56{
57 if( !reportPhase( _( "Checking footprints..." ) ) )
58 return false; // DRC cancelled
59
60 auto errorHandler =
61 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB, const BOARD_ITEM* aItemC,
62 int aErrorCode, const wxString& aMsg, const VECTOR2I& aPt, PCB_LAYER_ID aLayer )
63 {
64 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( aErrorCode );
65
66 if( !aMsg.IsEmpty() )
67 drcItem->SetErrorDetail( aMsg );
68
69 drcItem->SetItems( aItemA, aItemB, aItemC );
70 reportViolation( drcItem, aPt, aLayer );
71 };
72
73 for( FOOTPRINT* footprint : m_drcEngine->GetBoard()->Footprints() )
74 {
75 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_FOOTPRINT_TYPE_MISMATCH ) )
76 {
77 footprint->CheckFootprintAttributes(
78 [&]( const wxString& aMsg )
79 {
80 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_TYPE_MISMATCH,
81 aMsg, footprint->GetPosition(), footprint->GetLayer() );
82 } );
83 }
84
85 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_FOOTPRINT_SCALED_WITH_PADS ) )
86 {
87 const TRANSFORM_TRS& xform = footprint->GetTransform();
88
89 if( !xform.IsUniformScale() || xform.GetScaleX() != 1.0 )
90 {
91 if( !footprint->Pads().empty() )
92 {
93 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT_SCALED_WITH_PADS, wxEmptyString,
94 footprint->GetPosition(), footprint->GetLayer() );
95 }
96 }
97 }
98
99 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_PAD_TH_WITH_NO_HOLE )
100 || !m_drcEngine->IsErrorLimitExceeded( DRCE_PADSTACK ) )
101 {
102 footprint->CheckPads( m_drcEngine,
103 [&]( const PAD* aPad, int aErrorCode, const wxString& aMsg )
104 {
105 if( !m_drcEngine->IsErrorLimitExceeded( aErrorCode ) )
106 {
107 errorHandler( aPad, nullptr, nullptr, aErrorCode, aMsg,
108 aPad->GetPosition(), aPad->GetPrincipalLayer() );
109 }
110 } );
111 }
112
113 // Don't call footprint->CheckShortingPads(). At the board level we know about nets,
114 // and the pads may have the same net even though they're distinct pads.
115
116 if( footprint->IsNetTie() )
117 {
118 if( !m_drcEngine->IsErrorLimitExceeded( DRCE_SHORTING_ITEMS ) )
119 {
120 footprint->CheckNetTies(
121 [&]( const BOARD_ITEM* aItemA, const BOARD_ITEM* aItemB,
122 const BOARD_ITEM* aItemC, const VECTOR2I& aPosition )
123 {
124 errorHandler( aItemA, aItemB, aItemC, DRCE_SHORTING_ITEMS,
125 wxEmptyString, aPosition, footprint->GetLayer() );
126 } );
127 }
128
129 footprint->CheckNetTiePadGroups(
130 [&]( const wxString& aMsg )
131 {
132 errorHandler( footprint, nullptr, nullptr, DRCE_FOOTPRINT, aMsg,
133 footprint->GetPosition(), footprint->GetLayer() );
134 } );
135 }
136 }
137
138 return !m_drcEngine->IsCancelled();
139}
140
141
142namespace detail
143{
145}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition drc_item.cpp:417
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:245
PCB_LAYER_ID GetPrincipalLayer() const
Definition pad.cpp:628
bool IsUniformScale() const
double GetScaleX() const
@ DRCE_FOOTPRINT_SCALED_WITH_PADS
Definition drc_item.h:83
@ DRCE_PADSTACK
Definition drc_item.h:59
@ DRCE_SHORTING_ITEMS
Definition drc_item.h:37
@ DRCE_FOOTPRINT_TYPE_MISMATCH
Definition drc_item.h:78
@ DRCE_PAD_TH_WITH_NO_HOLE
Definition drc_item.h:81
@ DRCE_FOOTPRINT
Definition drc_item.h:82
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
static DRC_REGISTER_TEST_PROVIDER< DRC_TEST_PROVIDER_ANNULAR_WIDTH > dummy
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683