diff --git a/eeschema/widgets/sch_search_pane.cpp b/eeschema/widgets/sch_search_pane.cpp index a5aeec4612..6c42270ba1 100644 --- a/eeschema/widgets/sch_search_pane.cpp +++ b/eeschema/widgets/sch_search_pane.cpp @@ -47,6 +47,7 @@ SCH_SEARCH_PANE::SCH_SEARCH_PANE( SCH_EDIT_FRAME* aFrame ) : m_notebook->SetFont( infoFont ); AddSearcher( new SYMBOL_SEARCH_HANDLER( aFrame ) ); + AddSearcher( new POWER_SEARCH_HANDLER( aFrame ) ); AddSearcher( new TEXT_SEARCH_HANDLER( aFrame ) ); AddSearcher( new LABEL_SEARCH_HANDLER( aFrame ) ); } diff --git a/eeschema/widgets/search_handlers.cpp b/eeschema/widgets/search_handlers.cpp index eb3bfc196a..f162fa23f1 100644 --- a/eeschema/widgets/search_handlers.cpp +++ b/eeschema/widgets/search_handlers.cpp @@ -226,6 +226,70 @@ wxString SYMBOL_SEARCH_HANDLER::getResultCell( const SCH_SEARCH_HIT& aHit, int a } +POWER_SEARCH_HANDLER::POWER_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame ) : + SCH_SEARCH_HANDLER( _HKI( "Power" ), aFrame ) +{ + m_columns.emplace_back( _HKI( "Reference" ), 2, wxLIST_FORMAT_LEFT ); + m_columns.emplace_back( _HKI( "Value" ), 6, wxLIST_FORMAT_LEFT ); + m_columns.emplace_back( _HKI( "Page" ), 1, wxLIST_FORMAT_CENTER ); + m_columns.emplace_back( wxT( "X" ), 3, wxLIST_FORMAT_CENTER ); + m_columns.emplace_back( wxT( "Y" ), 3, wxLIST_FORMAT_CENTER ); +} + + +int POWER_SEARCH_HANDLER::Search( const wxString& aQuery ) +{ + m_hitlist.clear(); + + SCH_SEARCH_DATA frp; + frp.findString = aQuery; + + // Try to handle whatever the user throws at us (substring, wildcards, regex, etc.) + frp.matchMode = EDA_SEARCH_MATCH_MODE::PERMISSIVE; + frp.searchCurrentSheetOnly = false; + + auto search = + [frp]( SCH_ITEM* item, SCH_SHEET_PATH* sheet ) + { + if( item && item->Type() == SCH_SYMBOL_T ) + { + SCH_SYMBOL* sym = static_cast( item ); + + // IsPower depends on non-missing lib symbol association + return !sym->IsMissingLibSymbol() && sym->IsPower(); + } + + return false; + }; + + FindAll( search ); + + return (int) m_hitlist.size(); +} + + +wxString POWER_SEARCH_HANDLER::getResultCell( const SCH_SEARCH_HIT& aHit, int aCol ) +{ + SCH_SYMBOL* sym = dynamic_cast( aHit.item ); + + if( !sym ) + return wxEmptyString; + + if( aCol == 0 ) + return sym->GetRef( aHit.sheetPath, true ); + else if( aCol == 1 ) + return sym->GetField( VALUE_FIELD )->GetShownText( aHit.sheetPath, false ); + else if( aCol == 2 ) + return aHit.sheetPath->GetPageNumber(); + else if( aCol == 3 ) + return m_frame->MessageTextFromValue( sym->GetPosition().x ); + else if( aCol == 4 ) + return m_frame->MessageTextFromValue( sym->GetPosition().y ); + + return wxEmptyString; +} + + TEXT_SEARCH_HANDLER::TEXT_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame ) : SCH_SEARCH_HANDLER( _HKI( "Text" ), aFrame ) { diff --git a/eeschema/widgets/search_handlers.h b/eeschema/widgets/search_handlers.h index 85325d8446..f07c39ce28 100644 --- a/eeschema/widgets/search_handlers.h +++ b/eeschema/widgets/search_handlers.h @@ -82,6 +82,17 @@ protected: wxString getResultCell( const SCH_SEARCH_HIT& aHit, int aCol ) override; }; +class POWER_SEARCH_HANDLER : public SCH_SEARCH_HANDLER +{ +public: + POWER_SEARCH_HANDLER( SCH_EDIT_FRAME* aFrame ); + + int Search( const wxString& aQuery ) override; + +protected: + wxString getResultCell( const SCH_SEARCH_HIT& aHit, int aCol ) override; +}; + class TEXT_SEARCH_HANDLER : public SCH_SEARCH_HANDLER { public: