Add textboxes to Text tab of search

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12477
This commit is contained in:
Marek Roszko 2022-09-20 18:22:17 -04:00
parent 728ef8a61c
commit 35201eac52
2 changed files with 34 additions and 7 deletions

View File

@ -23,6 +23,7 @@
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <pcb_marker.h> #include <pcb_marker.h>
#include <pcb_textbox.h>
#include <pcb_text.h> #include <pcb_text.h>
#include <zone.h> #include <zone.h>
#include "search_handlers.h" #include "search_handlers.h"
@ -150,6 +151,7 @@ void ZONE_SEARCH_HANDLER::SelectItem( int row )
TEXT_SEARCH_HANDLER::TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) : TEXT_SEARCH_HANDLER::TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) :
SEARCH_HANDLER( wxT( "Text" ) ), m_frame( aFrame ) SEARCH_HANDLER( wxT( "Text" ) ), m_frame( aFrame )
{ {
m_columnNames.emplace_back( wxT( "Type" ) );
m_columnNames.emplace_back( wxT( "Text" ) ); m_columnNames.emplace_back( wxT( "Text" ) );
m_columnNames.emplace_back( wxT( "Layer" ) ); m_columnNames.emplace_back( wxT( "Layer" ) );
m_columnNames.emplace_back( wxT( "X" ) ); m_columnNames.emplace_back( wxT( "X" ) );
@ -169,11 +171,16 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& query )
for( BOARD_ITEM* item : board->Drawings() ) for( BOARD_ITEM* item : board->Drawings() )
{ {
PCB_TEXT* textItem = dynamic_cast<PCB_TEXT*>( item ); PCB_TEXT* textItem = dynamic_cast<PCB_TEXT*>( item );
PCB_TEXTBOX* textBoxItem = dynamic_cast<PCB_TEXTBOX*>( item );
if( textItem && textItem->Matches( frp, nullptr ) ) if( textItem && textItem->Matches( frp, nullptr ) )
{ {
m_hitlist.push_back( textItem ); m_hitlist.push_back( textItem );
} }
else if( textBoxItem && textBoxItem->Matches( frp, nullptr ) )
{
m_hitlist.push_back( textBoxItem );
}
} }
return m_hitlist.size(); return m_hitlist.size();
@ -182,15 +189,35 @@ int TEXT_SEARCH_HANDLER::Search( const wxString& query )
wxString TEXT_SEARCH_HANDLER::GetResultCell( int row, int col ) wxString TEXT_SEARCH_HANDLER::GetResultCell( int row, int col )
{ {
PCB_TEXT* text = m_hitlist[row]; BOARD_ITEM* text = m_hitlist[row];
if( col == 0 ) if( col == 0 )
return text->GetText(); {
if( col == 1 ) if( PCB_TEXT::ClassOf( text ) )
{
return _( "Text" );
}
else if( PCB_TEXTBOX::ClassOf( text ) )
{
return _( "Textbox" );
}
}
else if( col == 1 )
{
if( PCB_TEXT::ClassOf( text ) )
{
return dynamic_cast<PCB_TEXT*>( text )->GetText();
}
else if( PCB_TEXTBOX::ClassOf( text ) )
{
return dynamic_cast<PCB_TEXTBOX*>( text )->GetShownText();
}
}
if( col == 2 )
return text->GetLayerName(); return text->GetLayerName();
else if( col == 2 )
return m_frame->MessageTextFromValue( text->GetX() );
else if( col == 3 ) else if( col == 3 )
return m_frame->MessageTextFromValue( text->GetX() );
else if( col == 4 )
return m_frame->MessageTextFromValue( text->GetY() ); return m_frame->MessageTextFromValue( text->GetY() );
return wxEmptyString; return wxEmptyString;
@ -199,7 +226,7 @@ wxString TEXT_SEARCH_HANDLER::GetResultCell( int row, int col )
void TEXT_SEARCH_HANDLER::SelectItem( int row ) void TEXT_SEARCH_HANDLER::SelectItem( int row )
{ {
PCB_TEXT* text = m_hitlist[row]; BOARD_ITEM* text = m_hitlist[row];
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, text ); m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, text );

View File

@ -70,7 +70,7 @@ public:
private: private:
PCB_EDIT_FRAME* m_frame; PCB_EDIT_FRAME* m_frame;
std::vector<PCB_TEXT*> m_hitlist; std::vector<BOARD_ITEM*> m_hitlist;
}; };