From 007580c4b8b425b1517f7ee5a77efeb4e086df5f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Sep 2020 10:32:20 +0100 Subject: [PATCH] ADDED pad:pin checks for DRC "Test footprints against schematic". --- pcbnew/board_design_settings.cpp | 1 + pcbnew/class_board.cpp | 28 ++------ pcbnew/drc/drc.h | 1 + pcbnew/drc/drc_item.cpp | 5 ++ pcbnew/drc/drc_item.h | 1 + pcbnew/drc/footprint_tester.cpp | 72 +++++++++++++++++-- .../netlist_reader/board_netlist_updater.cpp | 3 +- 7 files changed, 81 insertions(+), 30 deletions(-) diff --git a/pcbnew/board_design_settings.cpp b/pcbnew/board_design_settings.cpp index 5e3698e95f..334a6851f5 100644 --- a/pcbnew/board_design_settings.cpp +++ b/pcbnew/board_design_settings.cpp @@ -154,6 +154,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std: m_DRCSeverities[ DRCE_MISSING_FOOTPRINT ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_DUPLICATE_FOOTPRINT ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_EXTRA_FOOTPRINT ] = RPT_SEVERITY_WARNING; + m_DRCSeverities[ DRCE_NET_CONFLICT ] = RPT_SEVERITY_WARNING; m_MaxError = ARC_HIGH_DEF; m_ZoneUseNoOutlineInFill = true; // Use new algo by default to fill zones diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 5df234452c..7d0a78b343 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1100,29 +1100,13 @@ NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const { - MODULE* found = nullptr; + for( MODULE* module : m_modules ) + { + if( aReference == module->GetReference() ) + return module; + } - // search only for MODULES - static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT }; - - INSPECTOR_FUNC inspector = [&]( EDA_ITEM* item, void* testData ) - { - MODULE* module = (MODULE*) item; - - if( aReference == module->GetReference() ) - { - found = module; - return SEARCH_RESULT::QUIT; - } - - return SEARCH_RESULT::CONTINUE; - }; - - // visit this BOARD with the above inspector - BOARD* nonconstMe = (BOARD*) this; - nonconstMe->Visit( inspector, NULL, scanTypes ); - - return found; + return nullptr; } diff --git a/pcbnew/drc/drc.h b/pcbnew/drc/drc.h index e82afc1232..a7f4bf8ee3 100644 --- a/pcbnew/drc/drc.h +++ b/pcbnew/drc/drc.h @@ -70,6 +70,7 @@ enum PCB_DRC_CODE { DRCE_MISSING_FOOTPRINT, ///< footprint not found for netlist item DRCE_DUPLICATE_FOOTPRINT, ///< more than one footprints found for netlist item DRCE_EXTRA_FOOTPRINT, ///< netlist item not found for footprint + DRCE_NET_CONFLICT, ///< pad net doesn't match netlist DRCE_UNRESOLVED_VARIABLE, diff --git a/pcbnew/drc/drc_item.cpp b/pcbnew/drc/drc_item.cpp index b2aae8422d..ab5209ccec 100644 --- a/pcbnew/drc/drc_item.cpp +++ b/pcbnew/drc/drc_item.cpp @@ -159,6 +159,10 @@ DRC_ITEM DRC_ITEM::extraFootprint( DRCE_EXTRA_FOOTPRINT, _( "Extra footprint" ), wxT( "extra_footprint" ) ); +DRC_ITEM DRC_ITEM::netConflict( DRCE_NET_CONFLICT, + _( "Pad net doesn't match schematic" ), + wxT( "net_conflict" ) ); + DRC_ITEM DRC_ITEM::unresolvedVariable( DRCE_UNRESOLVED_VARIABLE, _( "Unresolved text variable" ), wxT( "unresolved_variable" ) ); @@ -232,6 +236,7 @@ std::shared_ptr DRC_ITEM::Create( int aErrorCode ) case DRCE_INVALID_OUTLINE: return std::make_shared( invalidOutline ); case DRCE_MISSING_FOOTPRINT: return std::make_shared( missingFootprint ); case DRCE_DUPLICATE_FOOTPRINT: return std::make_shared( duplicateFootprints ); + case DRCE_NET_CONFLICT: return std::make_shared( netConflict ); case DRCE_EXTRA_FOOTPRINT: return std::make_shared( extraFootprint ); case DRCE_UNRESOLVED_VARIABLE: return std::make_shared( unresolvedVariable ); diff --git a/pcbnew/drc/drc_item.h b/pcbnew/drc/drc_item.h index 1ace251a3e..69997eff8c 100644 --- a/pcbnew/drc/drc_item.h +++ b/pcbnew/drc/drc_item.h @@ -98,6 +98,7 @@ private: static DRC_ITEM duplicateFootprints; static DRC_ITEM missingFootprint; static DRC_ITEM extraFootprint; + static DRC_ITEM netConflict; static DRC_ITEM unresolvedVariable; }; diff --git a/pcbnew/drc/footprint_tester.cpp b/pcbnew/drc/footprint_tester.cpp index 1e6f954d65..499e7f6b3d 100644 --- a/pcbnew/drc/footprint_tester.cpp +++ b/pcbnew/drc/footprint_tester.cpp @@ -52,15 +52,15 @@ void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vectorGetDesignSettings().Ignore( DRCE_MISSING_FOOTPRINT ) ) + // Search for component footprints in the netlist but not on the board. + for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ ) { - // Search for component footprints in the netlist but not on the board. - for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ ) - { - COMPONENT* component = aNetlist.GetComponent( ii ); - MODULE* module = aBoard->FindModuleByReference( component->GetReference() ); + COMPONENT* component = aNetlist.GetComponent( ii ); + MODULE* module = aBoard->FindModuleByReference( component->GetReference() ); - if( module == NULL ) + if( module == nullptr ) + { + if( !aBoard->GetDesignSettings().Ignore( DRCE_MISSING_FOOTPRINT ) && module == NULL ) { msg.Printf( _( "Missing footprint %s (%s)" ), component->GetReference(), @@ -71,6 +71,64 @@ void TestFootprints( NETLIST& aNetlist, BOARD* aBoard, std::vectorGetDesignSettings().Ignore( DRCE_NET_CONFLICT ) ) + { + for( D_PAD* pad : module->Pads() ) + { + const COMPONENT_NET& sch_net = component->GetNet( pad->GetName() ); + const wxString& pcb_netname = pad->GetNetname(); + + if( !pcb_netname.IsEmpty() && sch_net.GetPinName().IsEmpty() ) + { + msg.Printf( _( "No corresponding pin found in schematic." ) ); + + std::shared_ptr item = DRC_ITEM::Create( DRCE_NET_CONFLICT ); + item->SetErrorMessage( msg ); + item->SetItems( pad ); + aDRCList.push_back( item ); + } + else if( pcb_netname.IsEmpty() && !sch_net.GetNetName().IsEmpty() ) + { + msg.Printf( _( "Pad missing net given by schematic (%s)." ), + sch_net.GetNetName() ); + + std::shared_ptr item = DRC_ITEM::Create( DRCE_NET_CONFLICT ); + item->SetErrorMessage( msg ); + item->SetItems( pad ); + aDRCList.push_back( item ); + } + else if( pcb_netname != sch_net.GetNetName() ) + { + msg.Printf( _( "Pad net (%s) doesn't match net given by schematic (%s)." ), + pcb_netname, + sch_net.GetNetName() ); + + std::shared_ptr item = DRC_ITEM::Create( DRCE_NET_CONFLICT ); + item->SetErrorMessage( msg ); + item->SetItems( pad ); + aDRCList.push_back( item ); + } + } + + for( unsigned jj = 0; jj < component->GetNetCount(); ++jj ) + { + const COMPONENT_NET& sch_net = component->GetNet( jj ); + + if( !module->FindPadByName( sch_net.GetPinName() ) ) + { + msg.Printf( _( "No pad found for pin %s in schematic." ), + sch_net.GetPinName() ); + + std::shared_ptr item = DRC_ITEM::Create( DRCE_NET_CONFLICT ); + item->SetErrorMessage( msg ); + item->SetItems( module ); + aDRCList.push_back( item ); + } + } + } + } } if( !aBoard->GetDesignSettings().Ignore( DRCE_EXTRA_FOOTPRINT ) ) diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 15fbc5f801..3eee17a84e 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -169,7 +169,8 @@ MODULE* BOARD_NETLIST_UPDATER::addNewComponent( COMPONENT* aComponent ) // Set the pads ratsnest settings to the global settings bool set_ratsnest = m_frame->GetDisplayOptions().m_ShowGlobalRatsnest; - for ( auto pad : footprint->Pads() ) + + for ( D_PAD* pad : footprint->Pads() ) pad->SetLocalRatsnestVisible( set_ratsnest ); m_newFootprintsCount++;