diff --git a/common/footprint_info.cpp b/common/footprint_info.cpp index 363c543d1f..da14839cdb 100644 --- a/common/footprint_info.cpp +++ b/common/footprint_info.cpp @@ -102,10 +102,14 @@ void FOOTPRINT_INFO::load() std::auto_ptr m( fptable->FootprintLoad( m_nickname, m_fpname ) ); if( m.get() == NULL ) // Should happen only with malformed/broken libraries + { m_pad_count = 0; + m_unique_pad_count = 0; + } else { m_pad_count = m->GetPadCount( DO_NOT_INCLUDE_NPTH ); + m_unique_pad_count = m->GetUniquePadCount( DO_NOT_INCLUDE_NPTH ); m_keywords = m->GetKeywords(); m_doc = m->GetDescription(); diff --git a/cvpcb/class_footprints_listbox.cpp b/cvpcb/class_footprints_listbox.cpp index 7db8318bd2..ae611e43a7 100644 --- a/cvpcb/class_footprints_listbox.cpp +++ b/cvpcb/class_footprints_listbox.cpp @@ -156,7 +156,7 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a continue; if( (aFilterType & BY_PIN_COUNT) && aComponent - && aComponent->GetNetCount() != aList.GetItem( ii ).GetPadCount() ) + && aComponent->GetNetCount() != aList.GetItem( ii ).GetUniquePadCount() ) continue; msg.Printf( wxT( "%3d %s:%s" ), int( newList.GetCount() + 1 ), diff --git a/include/footprint_info.h b/include/footprint_info.h index 54a7c1af7c..7af63e4017 100644 --- a/include/footprint_info.h +++ b/include/footprint_info.h @@ -68,7 +68,8 @@ public: m_nickname( aNickname ), m_fpname( aFootprintName ), m_num( 0 ), - m_pad_count( 0 ) + m_pad_count( 0 ), + m_unique_pad_count( 0 ) { #if !USE_FPI_LAZY load(); @@ -93,6 +94,12 @@ public: return m_pad_count; } + unsigned GetUniquePadCount() + { + ensure_loaded(); + return m_unique_pad_count; + } + int GetOrderNum() { ensure_loaded(); @@ -121,16 +128,17 @@ private: /// lazily load stuff not filled in by constructor. This may throw IO_ERRORS. void load(); - FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE + FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE bool m_loaded; - wxString m_nickname; ///< library as known in FP_LIB_TABLE - wxString m_fpname; ///< Module name. - int m_num; ///< Order number in the display list. - int m_pad_count; ///< Number of pads - wxString m_doc; ///< Footprint description. - wxString m_keywords; ///< Footprint keywords. + wxString m_nickname; ///< library as known in FP_LIB_TABLE + wxString m_fpname; ///< Module name. + int m_num; ///< Order number in the display list. + int m_pad_count; ///< Number of pads + int m_unique_pad_count; ///< Number of unique pads + wxString m_doc; ///< Footprint description. + wxString m_keywords; ///< Footprint keywords. }; diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index bd194eccc1..a4700b3774 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -717,6 +717,30 @@ unsigned MODULE::GetPadCount( INCLUDE_NPTH_T aIncludeNPTH ) const } +unsigned MODULE::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const +{ + std::set usedNumbers; + + // Create a set of used pad numbers + for( D_PAD* pad = Pads(); pad; pad = pad->Next() ) + { + if( !aIncludeNPTH ) + { + //remove NPTH + if( pad->GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) + { + continue; + } + } + + int padNumber = getTrailingInt( pad->GetPadName() ); + usedNumbers.insert( padNumber ); + } + + return usedNumbers.size(); +} + + void MODULE::Add3DModel( S3D_MASTER* a3DModel ) { a3DModel->SetParent( this ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index f01dda9627..f409e8bb8f 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -487,7 +487,7 @@ public: D_PAD* GetPad( const wxPoint& aPosition, LSET aLayerMask = LSET::AllLayersMask() ); /** - * GetPadCount + * GetUniPadCount * returns the number of pads. * * @param aIncludeNPTH includes non-plated through holes when true. Does not include @@ -496,6 +496,16 @@ public: */ unsigned GetPadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T( INCLUDE_NPTH ) ) const; + /** + * GetUniquePadCount + * returns the number of unique pads. + * + * @param aIncludeNPTH includes non-plated through holes when true. Does not include + * non-plated through holes when false. + * @return the number of unique pads according to \a aIncludeNPTH. + */ + unsigned GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T( INCLUDE_NPTH ) ) const; + /** * Function GetNextPadName * returns the next available pad name in the module