From ff966eaf62bc52f591a2cca93e540ba42b222758 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 26 Apr 2024 09:36:58 +0100 Subject: [PATCH] Gracefully handle DNP & Excl-from-brd components in nets list. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17146 (cherry picked from commit 9be60cb45da919e2e74ab42a4e3f70ed080a9bbc) --- .../netlist_reader/kicad_netlist_reader.cpp | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/pcbnew/netlist_reader/kicad_netlist_reader.cpp b/pcbnew/netlist_reader/kicad_netlist_reader.cpp index 8f7f04f5c7..070bb708c1 100644 --- a/pcbnew/netlist_reader/kicad_netlist_reader.cpp +++ b/pcbnew/netlist_reader/kicad_netlist_reader.cpp @@ -183,7 +183,6 @@ void KICAD_NETLIST_PARSER::parseNet() * (node (ref "U9") (pin "M6") (pin_function "reset"))) */ - COMPONENT* component = NULL; wxString code; wxString name; wxString reference; @@ -257,25 +256,18 @@ void KICAD_NETLIST_PARSER::parseNet() } } - if( strtol( code.c_str(), NULL, 10 ) >= 1 ) + // Don't assume component will be found; it might be "DNP" or "Exclude from board". + if( COMPONENT* component = m_netlist->GetComponentByReference( reference ) ) { - if( name.IsEmpty() ) // Give a dummy net name like N-000009 - name = wxT("N-00000") + code; - - component = m_netlist->GetComponentByReference( reference ); - - // Cannot happen if the netlist is valid. - if( component == NULL ) + if( strtol( code.c_str(), nullptr, 10 ) >= 1 ) { - wxString msg; - msg.Printf( _( "Cannot find component with ref '%s' in netlist." ), - reference ); - THROW_PARSE_ERROR( msg, m_lineReader->GetSource(), m_lineReader->Line(), - m_lineReader->LineNumber(), m_lineReader->Length() ); - } + if( name.IsEmpty() ) // Give a dummy net name like N-000009 + name = wxT("N-00000") + code; - component->AddNet( pin_number, name, pin_function, pin_type ); + component->AddNet( pin_number, name, pin_function, pin_type ); + } } + break; default: