From c047d7f48418bd2384fc3b456f8b3650f3855e5d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 10 Mar 2012 08:58:21 +0100 Subject: [PATCH] Pcbnew: regression fix when using the new netlist format: * when a footprint has many pads having the same pad name, only the first pad was connected to the net --- pcbnew/netlist_reader.h | 13 ++++++++----- pcbnew/netlist_reader_common.cpp | 32 ++++++++++++++++++++++++-------- pcbnew/netlist_reader_kicad.cpp | 12 ++++++++---- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/pcbnew/netlist_reader.h b/pcbnew/netlist_reader.h index e6ed974f38..bc958b8128 100644 --- a/pcbnew/netlist_reader.h +++ b/pcbnew/netlist_reader.h @@ -363,15 +363,18 @@ public: void RemoveExtraFootprints( ); /** - * Function SetPadNetName - * Update a pad netname + * Function SetPadsNetName + * Update pads netnames for a given module. + * Because a pad name can be found more than once in this module, + * all pads matching the pad name are updated * @param aModule = module reference * @param aPadname = pad name (pad num) * @param aNetname = new net name of the pad - * @return a pointer to the pad or NULL if the pad is not found + * @param aPadList = a std::vector& buffer where the updated pads can be stored + * @return the pad count */ - D_PAD* SetPadNetName( const wxString & aModule, const wxString & aPadname, - const wxString & aNetname ); + int SetPadsNetName( const wxString & aModule, const wxString & aPadname, + const wxString & aNetname, std::vector & aPadList ); private: diff --git a/pcbnew/netlist_reader_common.cpp b/pcbnew/netlist_reader_common.cpp index b20baad8c1..d06b4b5c07 100644 --- a/pcbnew/netlist_reader_common.cpp +++ b/pcbnew/netlist_reader_common.cpp @@ -278,27 +278,43 @@ void NETLIST_READER::TestFootprintsMatchingAndExchange() } /** - * Function SetPadNetName - * Update a pad netname + * Function SetPadsNetName + * Update pads netnames for a given module. + * Because a pad name can be found more than once in this module, + * all pads matching the pad name are updated * @param aModule = module reference * @param aPadname = pad name (pad num) * @param aNetname = new net name of the pad - * @return a pointer to the pad or NULL if the pad is not found + * @param aPadList = a std::vector& buffer where the updated pads can be stored + * @return the pad count */ -D_PAD* NETLIST_READER::SetPadNetName( const wxString & aModule, const wxString & aPadname, - const wxString & aNetname ) +int NETLIST_READER::SetPadsNetName( const wxString & aModule, const wxString & aPadname, + const wxString & aNetname, std::vector & aPadList ) { if( m_pcbframe == NULL ) - return NULL; + return 0; + int padcount = 0; MODULE* module = m_pcbframe->GetBoard()->FindModuleByReference( aModule ); if( module ) { D_PAD * pad = module->FindPadByName( aPadname ); if( pad ) { + padcount++; + aPadList.push_back( pad ); pad->SetNetname( aNetname ); - return pad; + // Search for other pads having the same pad name/num + for( D_PAD* curr_pad = pad->Next(); curr_pad; curr_pad = curr_pad->Next() ) + { + if( pad->PadNameEqual( curr_pad ) ) + { + padcount++; + aPadList.push_back( curr_pad ); + curr_pad->SetNetname( aNetname ); + } + } + return padcount; } if( m_messageWindow ) { @@ -309,7 +325,7 @@ D_PAD* NETLIST_READER::SetPadNetName( const wxString & aModule, const wxString & } } - return NULL; + return 0; } diff --git a/pcbnew/netlist_reader_kicad.cpp b/pcbnew/netlist_reader_kicad.cpp index f9462e6767..632b682dee 100644 --- a/pcbnew/netlist_reader_kicad.cpp +++ b/pcbnew/netlist_reader_kicad.cpp @@ -245,8 +245,9 @@ void NETLIST_READER_KICAD_PARSER::ParseNet( BOARD * aBrd ) wxString name; wxString cmpref; wxString pin; - D_PAD * pad = NULL; int nodecount = 0; + std::vector padList; + // The token net was read, so the next data is (code ) while( (token = NextTok()) != T_RIGHT ) { @@ -292,7 +293,7 @@ void NETLIST_READER_KICAD_PARSER::ParseNet( BOARD * aBrd ) break; } } - pad = netlist_reader->SetPadNetName( cmpref, pin, name ); + netlist_reader->SetPadsNetName( cmpref, pin, name, padList ); nodecount++; break; @@ -303,8 +304,11 @@ void NETLIST_READER_KICAD_PARSER::ParseNet( BOARD * aBrd ) } // When there is only one item in net, clear pad netname - if( nodecount < 2 && pad ) - pad->SetNetname( wxEmptyString ); + // Remember one can have more than one pad in list, because a footprint + // can have many pads with the same pad name + if( nodecount < 2 ) + for( unsigned ii = 0; ii < padList.size(); ii++ ) + padList[ii]->SetNetname( wxEmptyString ); }