From f304e2d4f63c1047d39440aa2f7608a282698ae3 Mon Sep 17 00:00:00 2001 From: Mark Roszko Date: Wed, 14 Sep 2022 02:59:57 +0000 Subject: [PATCH] ADDED: Search/inspect pane --- common/CMakeLists.txt | 3 + common/eda_draw_frame.cpp | 12 ++ common/tool/actions.cpp | 6 + common/widgets/search_pane.cpp | 82 +++++++++ common/widgets/search_pane_base.cpp | 51 ++++++ common/widgets/search_pane_base.fbp | 192 ++++++++++++++++++++ common/widgets/search_pane_base.h | 52 ++++++ common/widgets/search_pane_tab.cpp | 95 ++++++++++ include/eda_draw_frame.h | 7 + include/tool/actions.h | 1 + include/widgets/search_pane.h | 70 ++++++++ include/widgets/search_pane_tab.h | 66 +++++++ pcbnew/CMakeLists.txt | 2 + pcbnew/menubar_pcb_editor.cpp | 3 +- pcbnew/pcb_edit_frame.cpp | 18 ++ pcbnew/pcb_edit_frame.h | 9 +- pcbnew/toolbars_pcb_editor.cpp | 15 ++ pcbnew/tools/board_editor_control.cpp | 18 +- pcbnew/tools/board_editor_control.h | 2 + pcbnew/tools/pcb_actions.cpp | 5 + pcbnew/tools/pcb_actions.h | 1 + pcbnew/widgets/pcb_search_pane.cpp | 119 ++++++++++++ pcbnew/widgets/pcb_search_pane.h | 53 ++++++ pcbnew/widgets/search_handlers.cpp | 248 ++++++++++++++++++++++++++ pcbnew/widgets/search_handlers.h | 90 ++++++++++ 25 files changed, 1217 insertions(+), 3 deletions(-) create mode 100644 common/widgets/search_pane.cpp create mode 100644 common/widgets/search_pane_base.cpp create mode 100644 common/widgets/search_pane_base.fbp create mode 100644 common/widgets/search_pane_base.h create mode 100644 common/widgets/search_pane_tab.cpp create mode 100644 include/widgets/search_pane.h create mode 100644 include/widgets/search_pane_tab.h create mode 100644 pcbnew/widgets/pcb_search_pane.cpp create mode 100644 pcbnew/widgets/pcb_search_pane.h create mode 100644 pcbnew/widgets/search_handlers.cpp create mode 100644 pcbnew/widgets/search_handlers.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 3b2582d612..09ad90728f 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -190,6 +190,9 @@ set( COMMON_WIDGET_SRCS widgets/paged_dialog.cpp widgets/progress_reporter_base.cpp widgets/properties_panel.cpp + widgets/search_pane.cpp + widgets/search_pane_base.cpp + widgets/search_pane_tab.cpp widgets/split_button.cpp widgets/stepped_slider.cpp widgets/text_ctrl_eval.cpp diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index e44fdb8da4..05f6f33230 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -1092,6 +1093,17 @@ void EDA_DRAW_FRAME::RecreateToolbars() } +void EDA_DRAW_FRAME::ShowChangedLanguage() +{ + EDA_BASE_FRAME::ShowChangedLanguage(); + + if( m_searchPane ) + { + m_searchPane->OnLanguageChange(); + } +} + + COLOR_SETTINGS* EDA_DRAW_FRAME::GetColorSettings( bool aForceRefresh ) const { if( !m_colorSettings || aForceRefresh ) diff --git a/common/tool/actions.cpp b/common/tool/actions.cpp index d5d63d81d1..3c5dac87d4 100644 --- a/common/tool/actions.cpp +++ b/common/tool/actions.cpp @@ -203,6 +203,12 @@ TOOL_ACTION ACTIONS::activatePointEditor( "common.Control.activatePointEditor", TOOL_ACTION ACTIONS::changeEditMethod( "common.Interactive.changeEditMethod", AS_GLOBAL, MD_CTRL + ' ', "", _( "Change Edit Method" ), _( "Change edit method constraints" ) ); +TOOL_ACTION ACTIONS::search( "common.Interactive.search", + AS_GLOBAL, + MD_CTRL + 'G', LEGACY_HK_NAME( "Search" ), + _( "Find" ), _( "Search for items" ), + BITMAPS::find ); + TOOL_ACTION ACTIONS::find( "common.Interactive.find", AS_GLOBAL, MD_CTRL + 'F', LEGACY_HK_NAME( "Find" ), diff --git a/common/widgets/search_pane.cpp b/common/widgets/search_pane.cpp new file mode 100644 index 0000000000..003d4b4b29 --- /dev/null +++ b/common/widgets/search_pane.cpp @@ -0,0 +1,82 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include +#include + + +SEARCH_PANE::SEARCH_PANE( EDA_DRAW_FRAME* aFrame ) : + SEARCH_PANE_BASE( aFrame ), + m_frame( aFrame ) +{ +} + + +SEARCH_PANE::~SEARCH_PANE() +{ +} + + +void SEARCH_PANE::OnLanguageChange() +{ + for( size_t i = 0; i < m_notebook->GetPageCount(); ++i ) + { + wxWindow* page = m_notebook->GetPage( i ); + SEARCH_PANE_TAB* tab = dynamic_cast( page ); + + tab->RefreshColumnNames(); + m_notebook->SetPageText( i, _( tab->GetSearchHandler()->GetName() ) ); + } +} + + +void SEARCH_PANE::AddSearcher( SEARCH_HANDLER* aHandler ) +{ + SEARCH_PANE_TAB* tab = new SEARCH_PANE_TAB( aHandler, m_notebook ); + + m_notebook->AddPage( tab, _( aHandler->GetName() ) ); + m_handlers.push_back( aHandler ); + m_tabs.push_back( tab ); +} + + +void SEARCH_PANE::RefreshSearch() +{ + for( SEARCH_PANE_TAB* tab : m_tabs ) + { + tab->Search( m_lastQuery ); + } +} + + +void SEARCH_PANE::OnSearchTextEntry( wxCommandEvent& aEvent ) +{ + wxString query = m_searchCtrl1->GetValue(); + m_lastQuery = query; + + RefreshSearch(); +} + + +void SEARCH_PANE::FocusSearch() +{ + m_searchCtrl1->SetFocus(); +} \ No newline at end of file diff --git a/common/widgets/search_pane_base.cpp b/common/widgets/search_pane_base.cpp new file mode 100644 index 0000000000..ed6b20a3ad --- /dev/null +++ b/common/widgets/search_pane_base.cpp @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "search_pane_base.h" + +/////////////////////////////////////////////////////////////////////////// + +SEARCH_PANE_BASE::SEARCH_PANE_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name ) +{ + this->SetFont( wxFont( 10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); + this->SetMinSize( wxSize( 360,100 ) ); + + m_sizerOuter = new wxBoxSizer( wxVERTICAL ); + + m_searchCtrl1 = new wxSearchCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + #ifndef __WXMAC__ + m_searchCtrl1->ShowSearchButton( true ); + #endif + m_searchCtrl1->ShowCancelButton( false ); + m_sizerOuter->Add( m_searchCtrl1, 0, wxALL|wxEXPAND, 5 ); + + m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + + m_sizerOuter->Add( m_notebook, 1, wxEXPAND, 5 ); + + + this->SetSizer( m_sizerOuter ); + this->Layout(); + + // Connect Events + this->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( SEARCH_PANE_BASE::OnSetFocus ) ); + this->Connect( wxEVT_SIZE, wxSizeEventHandler( SEARCH_PANE_BASE::OnSize ) ); + m_searchCtrl1->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( SEARCH_PANE_BASE::OnSearchTextEntry ), NULL, this ); + m_notebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SEARCH_PANE_BASE::OnNotebookPageChanged ), NULL, this ); + m_notebook->Connect( wxEVT_SET_FOCUS, wxFocusEventHandler( SEARCH_PANE_BASE::OnSetFocus ), NULL, this ); +} + +SEARCH_PANE_BASE::~SEARCH_PANE_BASE() +{ + // Disconnect Events + this->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( SEARCH_PANE_BASE::OnSetFocus ) ); + this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( SEARCH_PANE_BASE::OnSize ) ); + m_searchCtrl1->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( SEARCH_PANE_BASE::OnSearchTextEntry ), NULL, this ); + m_notebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SEARCH_PANE_BASE::OnNotebookPageChanged ), NULL, this ); + m_notebook->Disconnect( wxEVT_SET_FOCUS, wxFocusEventHandler( SEARCH_PANE_BASE::OnSetFocus ), NULL, this ); + +} diff --git a/common/widgets/search_pane_base.fbp b/common/widgets/search_pane_base.fbp new file mode 100644 index 0000000000..3546d7c4f3 --- /dev/null +++ b/common/widgets/search_pane_base.fbp @@ -0,0 +1,192 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + search_pane_base + 1000 + none + + + 1 + SEARCH PANE + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + + + 1 + 1 + impl_virtual + + ,90,90,10,70,0 + 0 + wxID_ANY + + 360,100 + SEARCH_PANE_BASE + + 360,250 + ; ; forward_declare + + 0 + + + wxTAB_TRAVERSAL + OnSetFocus + OnSize + + + m_sizerOuter + wxVERTICAL + protected + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + 0 + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_searchCtrl1 + 1 + + + protected + 1 + + Resizable + 1 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + OnSearchTextEntry + + + + 5 + wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_notebook + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + OnNotebookPageChanged + OnSetFocus + + + + + + diff --git a/common/widgets/search_pane_base.h b/common/widgets/search_pane_base.h new file mode 100644 index 0000000000..69ee152074 --- /dev/null +++ b/common/widgets/search_pane_base.h @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class SEARCH_PANE_BASE +/////////////////////////////////////////////////////////////////////////////// +class SEARCH_PANE_BASE : public wxPanel +{ + private: + + protected: + wxBoxSizer* m_sizerOuter; + wxSearchCtrl* m_searchCtrl1; + wxNotebook* m_notebook; + + // Virtual event handlers, override them in your derived class + virtual void OnSetFocus( wxFocusEvent& event ) { event.Skip(); } + virtual void OnSize( wxSizeEvent& event ) { event.Skip(); } + virtual void OnSearchTextEntry( wxCommandEvent& event ) { event.Skip(); } + virtual void OnNotebookPageChanged( wxNotebookEvent& event ) { event.Skip(); } + + + public: + + SEARCH_PANE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 360,250 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + + ~SEARCH_PANE_BASE(); + +}; + diff --git a/common/widgets/search_pane_tab.cpp b/common/widgets/search_pane_tab.cpp new file mode 100644 index 0000000000..f4dcc2e501 --- /dev/null +++ b/common/widgets/search_pane_tab.cpp @@ -0,0 +1,95 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include + +SEARCH_PANE_LISTVIEW::SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, wxWindow* parent, + wxWindowID winid, const wxPoint& pos, + const wxSize& size ) : + wxListView( parent, winid, pos, size, wxLC_REPORT | wxLC_VIRTUAL ), + m_handler( handler ) +{ + SetItemCount( 0 ); + + RefreshColumnNames(); + + Bind( wxEVT_LIST_ITEM_SELECTED, &SEARCH_PANE_LISTVIEW::onItemSelected, this ); +} + + +void SEARCH_PANE_LISTVIEW::onItemSelected( wxListEvent& aEvent ) +{ + long idx = aEvent.GetIndex(); + + m_handler->SelectItem( idx ); +} + + +void SEARCH_PANE_LISTVIEW::RefreshColumnNames() +{ + Freeze(); + DeleteAllColumns(); + + std::vector columns = m_handler->GetColumnNames(); + for( wxString& columnName : columns ) + { + AppendColumn( _( columnName ) ); + } + + Thaw(); +} + + +wxString SEARCH_PANE_LISTVIEW::OnGetItemText( long item, long column ) const +{ + return m_handler->GetResultCell( item, column ); +} + + +SEARCH_PANE_TAB::SEARCH_PANE_TAB( SEARCH_HANDLER* handler, wxWindow* parent, wxWindowID aId, + const wxPoint& aLocation, const wxSize& aSize ) : + wxPanel( parent, aId, aLocation, aSize ), + m_handler( handler ) +{ + wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL ); + + m_listView = new SEARCH_PANE_LISTVIEW( handler, this ); + sizer->Add( m_listView, 5, wxRIGHT | wxBOTTOM | wxEXPAND, 1 ); + + SetSizer( sizer ); + + Layout(); + sizer->Fit( this ); +} + + +void SEARCH_PANE_TAB::Search( wxString& query ) +{ + int results = m_handler->Search( query ); + m_listView->SetItemCount( results ); + m_listView->Refresh(); +} + + +void SEARCH_PANE_TAB::RefreshColumnNames() +{ + m_listView->RefreshColumnNames(); +} \ No newline at end of file diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index a6310073e1..fe8ce6eb0f 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -41,6 +41,7 @@ class COLOR_SETTINGS; class TOOL_MENU; class APP_SETTINGS_BASE; class wxFindReplaceData; +class SEARCH_PANE; namespace KIGFX { @@ -444,6 +445,11 @@ public: */ void RecreateToolbars(); + /** + * Redraw the menus and what not in current language. + */ + void ShowChangedLanguage() override; + DECLARE_EVENT_TABLE() protected: @@ -509,6 +515,7 @@ protected: int m_msgFrameHeight; COLOR_SETTINGS* m_colorSettings; + SEARCH_PANE* m_searchPane; ///< The current canvas type. EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType; diff --git a/include/tool/actions.h b/include/tool/actions.h index 92be008c59..4487ef6ab9 100644 --- a/include/tool/actions.h +++ b/include/tool/actions.h @@ -73,6 +73,7 @@ public: static TOOL_ACTION deleteTool; // Find and Replace + static TOOL_ACTION search; static TOOL_ACTION find; static TOOL_ACTION findAndReplace; static TOOL_ACTION findNext; diff --git a/include/widgets/search_pane.h b/include/widgets/search_pane.h new file mode 100644 index 0000000000..45750e1c21 --- /dev/null +++ b/include/widgets/search_pane.h @@ -0,0 +1,70 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SEARCH_PANE_H +#define SEARCH_PANE_H + +#include +#include + +class EDA_DRAW_FRAME; +class SEARCH_PANE_TAB; + +class SEARCH_HANDLER +{ +public: + SEARCH_HANDLER( wxString aName ) : + m_name( aName ) {} + + wxString GetName() const { return m_name; } + + std::vector GetColumnNames() const { return m_columnNames; } + + virtual int Search( const wxString& string ) = 0; + virtual wxString GetResultCell( int row, int col ) = 0; + + virtual void SelectItem(int row) {} + +protected: + wxString m_name; + std::vector m_columnNames; +}; + +class SEARCH_PANE : public SEARCH_PANE_BASE +{ +public: + SEARCH_PANE( EDA_DRAW_FRAME* aFrame ); + virtual ~SEARCH_PANE(); + + void AddSearcher( SEARCH_HANDLER* aHandler ); + void OnSearchTextEntry( wxCommandEvent& aEvent ) override; + + void RefreshSearch(); + void OnLanguageChange(); + void FocusSearch(); + +private: + + EDA_DRAW_FRAME* m_frame; + std::vector m_handlers; + std::vector m_tabs; + wxString m_lastQuery; +}; + +#endif \ No newline at end of file diff --git a/include/widgets/search_pane_tab.h b/include/widgets/search_pane_tab.h new file mode 100644 index 0000000000..c9e71291bf --- /dev/null +++ b/include/widgets/search_pane_tab.h @@ -0,0 +1,66 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SEARCH_PANE_TAB_H +#define SEARCH_PANE_TAB_H + +#include +#include +#include + +class SEARCH_HANDLER; + + +class SEARCH_PANE_LISTVIEW : public wxListView +{ +public: + SEARCH_PANE_LISTVIEW( SEARCH_HANDLER* handler, + wxWindow* parent, wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize ); + + void RefreshColumnNames(); + +protected: + wxString OnGetItemText( long item, long column ) const override; + void onItemSelected( wxListEvent& aEvent ); + +private: + SEARCH_HANDLER* m_handler; +}; + + +class SEARCH_PANE_TAB : public wxPanel +{ +public: + SEARCH_PANE_TAB( SEARCH_HANDLER* handler, wxWindow* parent, wxWindowID aId = wxID_ANY, + const wxPoint& aLocation = wxDefaultPosition, + const wxSize& aSize = wxDefaultSize ); + + void Search( wxString& query ); + void RefreshColumnNames(); + + SEARCH_HANDLER* GetSearchHandler() const { return m_handler; } + +private: + SEARCH_PANE_LISTVIEW* m_listView; + SEARCH_HANDLER* m_handler; +}; + +#endif \ No newline at end of file diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index a01eb5e9e1..c30d5ad159 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -370,6 +370,8 @@ set( PCBNEW_CLASS_SRCS widgets/appearance_controls_base.cpp widgets/panel_selection_filter.cpp widgets/panel_selection_filter_base.cpp + widgets/pcb_search_pane.cpp + widgets/search_handlers.cpp ) diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index 8a8eaeb72d..3e5cb1dcaf 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -228,7 +228,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool ); viewMenu->Add( PCB_ACTIONS::showLayersManager, ACTION_MENU::CHECK ); - viewMenu->Add( PCB_ACTIONS::showProperties , ACTION_MENU::CHECK ); + viewMenu->Add( PCB_ACTIONS::showProperties, ACTION_MENU::CHECK ); + viewMenu->Add( PCB_ACTIONS::showSearch, ACTION_MENU::CHECK ); viewMenu->Add( ACTIONS::showFootprintBrowser ); viewMenu->Add( ACTIONS::show3DViewer ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index f37c39f813..99d5d992d9 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -97,6 +97,8 @@ #include // for DIALOG_DRC_WINDOW_NAME definition #include #include +#include +#include #include #include #include @@ -191,6 +193,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_supportsAutoSave = true; m_probingSchToPcb = false; m_show_properties = true; + m_show_search = false; // We don't know what state board was in when it was last saved, so we have to // assume dirty @@ -248,6 +251,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this ); m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas() ); + m_searchPane = new PCB_SEARCH_PANE( this ); m_auimgr.SetManagedWindow( this ); @@ -297,12 +301,26 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ) .Center() ); + + m_auimgr.AddPane( m_searchPane, EDA_PANE() + .Name( SearchPaneName() ) + .Bottom() + .Caption( _( "Search" ) ) + .PaneBorder( false ) + .MinSize( 180, -1 ) + .BestSize( 180, -1 ) + .CloseButton( true ) + .DestroyOnClose( false ) ); + + m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools ); m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools ); bool showProperties = ADVANCED_CFG::GetCfg().m_ShowPropertiesPanel && m_show_properties; m_auimgr.GetPane( "PropertiesManager" ).Show( showProperties ); + m_auimgr.GetPane( SearchPaneName() ).Show( m_show_search ); + // The selection filter doesn't need to grow in the vertical direction when docked m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0; diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 83ba995d99..32500ab462 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -124,6 +124,11 @@ public: */ std::vector FindItemsFromSyncSelection( std::string syncStr ); + /** + * @return the name of the wxAuiPaneInfo managing the Search panel + */ + static const wxString SearchPaneName() { return wxT( "Search" ); } + /** * Show the Find dialog. */ @@ -296,6 +301,7 @@ public: void ToggleLayersManager(); void ToggleProperties(); + void ToggleSearch(); /** * Create an ASCII footprint position file. @@ -645,7 +651,7 @@ public: * @param aItems are the items to try to select on schematic. * @param aFocusItem set to item to select and focus on even if selection can't be * represented in Schematic editor fully. - * @param aForce select elements in Schematic editor whether or not the user has + * @param aForce select elements in Schematic editor whether or not the user has * the select option chosen. */ void SendSelectItemsToSch( const std::deque& aItems, EDA_ITEM* aFocusItem, @@ -808,6 +814,7 @@ public: bool m_show_layer_manager_tools; bool m_show_properties; + bool m_show_search; bool m_ZoneFillsDirty; // Board has been modified since last zone fill. diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index 408c543aa6..b461509df9 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -793,6 +794,20 @@ void PCB_EDIT_FRAME::ToggleProperties() } +void PCB_EDIT_FRAME::ToggleSearch() +{ + m_show_search = !m_show_search; + + m_auimgr.GetPane( SearchPaneName() ).Show( m_show_search ); + m_auimgr.Update(); + + if( m_show_search ) + { + m_searchPane->FocusSearch(); + } +} + + void PCB_EDIT_FRAME::OnUpdateSelectTrackWidth( wxUpdateUIEvent& aEvent ) { if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_TRACK_WIDTH ) diff --git a/pcbnew/tools/board_editor_control.cpp b/pcbnew/tools/board_editor_control.cpp index 5785662d5e..de784242b5 100644 --- a/pcbnew/tools/board_editor_control.cpp +++ b/pcbnew/tools/board_editor_control.cpp @@ -337,6 +337,13 @@ int BOARD_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent ) } +int BOARD_EDITOR_CONTROL::Search( const TOOL_EVENT& aEvent ) +{ + m_frame->ToggleSearch(); + return 0; +} + + int BOARD_EDITOR_CONTROL::Find( const TOOL_EVENT& aEvent ) { m_frame->ShowFindDialog(); @@ -678,6 +685,13 @@ int BOARD_EDITOR_CONTROL::ToggleProperties( const TOOL_EVENT& aEvent ) } +int BOARD_EDITOR_CONTROL::ToggleSearch( const TOOL_EVENT& aEvent ) +{ + getEditFrame()->ToggleSearch(); + return 0; +} + + int BOARD_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent ) { m_frame->ScriptingConsoleEnableDisable(); @@ -1587,6 +1601,7 @@ void BOARD_EDITOR_CONTROL::setTransitions() Go( &BOARD_EDITOR_CONTROL::PageSettings, ACTIONS::pageSettings.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() ); + Go( &BOARD_EDITOR_CONTROL::Search, ACTIONS::search.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::Find, ACTIONS::find.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::FindNext, ACTIONS::findNext.MakeEvent() ); @@ -1646,7 +1661,8 @@ void BOARD_EDITOR_CONTROL::setTransitions() ACTIONS::updateSchematicFromPcb.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::ShowEeschema, PCB_ACTIONS::showEeschema.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::ToggleLayersManager, PCB_ACTIONS::showLayersManager.MakeEvent() ); - Go( &BOARD_EDITOR_CONTROL::ToggleProperties, PCB_ACTIONS::showProperties.MakeEvent() ); + Go( &BOARD_EDITOR_CONTROL::ToggleProperties, PCB_ACTIONS::showProperties.MakeEvent() ); + Go( &BOARD_EDITOR_CONTROL::ToggleSearch, PCB_ACTIONS::showSearch.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::TogglePythonConsole, PCB_ACTIONS::showPythonConsole.MakeEvent() ); Go( &BOARD_EDITOR_CONTROL::RepairBoard, PCB_ACTIONS::repairBoard.MakeEvent() ); } diff --git a/pcbnew/tools/board_editor_control.h b/pcbnew/tools/board_editor_control.h index df4b9f5c78..21aeaaa36e 100644 --- a/pcbnew/tools/board_editor_control.h +++ b/pcbnew/tools/board_editor_control.h @@ -60,6 +60,7 @@ public: int PageSettings( const TOOL_EVENT& aEvent ); int Plot( const TOOL_EVENT& aEvent ); + int Search( const TOOL_EVENT& aEvent ); int Find( const TOOL_EVENT& aEvent ); int FindNext( const TOOL_EVENT& aEvent ); @@ -78,6 +79,7 @@ public: int ShowEeschema( const TOOL_EVENT& aEvent ); int ToggleLayersManager( const TOOL_EVENT& aEvent ); int ToggleProperties( const TOOL_EVENT& aEvent ); + int ToggleSearch( const TOOL_EVENT& aEvent ); int TogglePythonConsole( const TOOL_EVENT& aEvent ); // Track & via size control diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index f8f56ba1b6..0032bc1fdc 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -837,6 +837,11 @@ TOOL_ACTION PCB_ACTIONS::showProperties( "pcbnew.Control.showProperties", _( "Show Properties Panel" ), _( "Show/hide the properties panel" ), BITMAPS::tools ); +TOOL_ACTION PCB_ACTIONS::showSearch( "pcbnew.Control.showSearch", + AS_GLOBAL, 0, "", + _( "Show Search Panel" ), _( "Show/hide the search panel" ), + BITMAPS::tools ); + TOOL_ACTION PCB_ACTIONS::flipBoard( "pcbnew.Control.flipBoard", AS_GLOBAL, 0, "", _( "Flip Board View" ), _( "View board from the opposite side" ), diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 7cde0a32af..180aa271f5 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -364,6 +364,7 @@ public: static TOOL_ACTION showLayersManager; static TOOL_ACTION showProperties; + static TOOL_ACTION showSearch; static TOOL_ACTION showPythonConsole; // Module editor tools diff --git a/pcbnew/widgets/pcb_search_pane.cpp b/pcbnew/widgets/pcb_search_pane.cpp new file mode 100644 index 0000000000..9ccc2ad5d2 --- /dev/null +++ b/pcbnew/widgets/pcb_search_pane.cpp @@ -0,0 +1,119 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include "pcb_search_pane.h" +#include "search_handlers.h" + + +PCB_SEARCH_PANE::PCB_SEARCH_PANE( PCB_EDIT_FRAME* aFrame ) : + m_pcbFrame( aFrame ), SEARCH_PANE( aFrame ) +{ + m_brd = m_pcbFrame->GetBoard(); + + if( m_brd != nullptr ) + { + m_brd->AddListener( this ); + } + + m_pcbFrame->Connect( UNITS_CHANGED, wxCommandEventHandler( PCB_SEARCH_PANE::onUnitsChanged ), + nullptr, this ); + + m_pcbFrame->Connect( BOARD_CHANGED, wxCommandEventHandler( PCB_SEARCH_PANE::onBoardChanged ), + nullptr, this ); + + AddSearcher( new FOOTPRINT_SEARCH_HANDLER( aFrame ) ); + AddSearcher( new ZONE_SEARCH_HANDLER( aFrame ) ); + AddSearcher( new NETS_SEARCH_HANDLER( aFrame ) ); + AddSearcher( new TEXT_SEARCH_HANDLER( aFrame ) ); +} + + +PCB_SEARCH_PANE::~PCB_SEARCH_PANE() +{ + m_pcbFrame->Disconnect( UNITS_CHANGED, wxCommandEventHandler( PCB_SEARCH_PANE::onUnitsChanged ), + nullptr, this ); + m_pcbFrame->Disconnect( BOARD_CHANGED, wxCommandEventHandler( PCB_SEARCH_PANE::onBoardChanged ), + nullptr, this ); +} + + +void PCB_SEARCH_PANE::onUnitsChanged( wxCommandEvent& event ) +{ + event.Skip(); +} + + +void PCB_SEARCH_PANE::onBoardChanged( wxCommandEvent& event ) +{ + m_brd = m_pcbFrame->GetBoard(); + + if( m_brd != nullptr ) + m_brd->AddListener( this ); + + RefreshSearch(); + + event.Skip(); +} + + +void PCB_SEARCH_PANE::OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardItemsAdded( BOARD& aBoard, std::vector& aBoardItems ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardItemsRemoved( BOARD& aBoard, std::vector& aBoardItems ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardNetSettingsChanged( BOARD& aBoard ) +{ +} + + +void PCB_SEARCH_PANE::OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardItemsChanged( BOARD& aBoard, std::vector& aBoardItems ) +{ + RefreshSearch(); +} + + +void PCB_SEARCH_PANE::OnBoardHighlightNetChanged( BOARD& aBoard ) +{ +} \ No newline at end of file diff --git a/pcbnew/widgets/pcb_search_pane.h b/pcbnew/widgets/pcb_search_pane.h new file mode 100644 index 0000000000..cb092a6e73 --- /dev/null +++ b/pcbnew/widgets/pcb_search_pane.h @@ -0,0 +1,53 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef PCB_SEARCH_PANE_H +#define PCB_SEARCH_PANE_H + +#include +#include + +class PCB_EDIT_FRAME; + +class PCB_SEARCH_PANE : public SEARCH_PANE, public BOARD_LISTENER +{ +public: + PCB_SEARCH_PANE( PCB_EDIT_FRAME* aFrame ); + virtual ~PCB_SEARCH_PANE(); + + virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override; + virtual void OnBoardItemsAdded( BOARD& aBoard, std::vector& aBoardItems ) override; + virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override; + virtual void OnBoardItemsRemoved( BOARD& aBoard, + std::vector& aBoardItems ) override; + virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) override; + virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override; + virtual void OnBoardItemsChanged( BOARD& aBoard, + std::vector& aBoardItems ) override; + virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) override; + +private: + void onUnitsChanged( wxCommandEvent& event ); + void onBoardChanged( wxCommandEvent& event ); + + PCB_EDIT_FRAME* m_pcbFrame; + BOARD* m_brd; +}; + +#endif \ No newline at end of file diff --git a/pcbnew/widgets/search_handlers.cpp b/pcbnew/widgets/search_handlers.cpp new file mode 100644 index 0000000000..c60292514b --- /dev/null +++ b/pcbnew/widgets/search_handlers.cpp @@ -0,0 +1,248 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "search_handlers.h" + + +FOOTPRINT_SEARCH_HANDLER::FOOTPRINT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) : + SEARCH_HANDLER( wxT( "Footprint" ) ), m_frame( aFrame ) +{ + m_columnNames.emplace_back( wxT( "Reference" ) ); + m_columnNames.emplace_back( wxT( "Value" ) ); + m_columnNames.emplace_back( wxT( "Layer" ) ); + m_columnNames.emplace_back( wxT( "X" ) ); + m_columnNames.emplace_back( wxT( "Y" ) ); +} + + +int FOOTPRINT_SEARCH_HANDLER::Search( const wxString& query ) +{ + m_hitlist.clear(); + BOARD* board = m_frame->GetBoard(); + + EDA_SEARCH_DATA frp; + frp.findString = query; + frp.matchMode = EDA_SEARCH_MATCH_MODE::WILDCARD; + + for( FOOTPRINT* fp : board->Footprints() ) + { + if( fp->Reference().Matches( frp, nullptr ) || fp->Value().Matches( frp, nullptr ) ) + { + m_hitlist.push_back( fp ); + } + } + + return m_hitlist.size(); +} + + +wxString FOOTPRINT_SEARCH_HANDLER::GetResultCell( int row, int col ) +{ + FOOTPRINT* fp = m_hitlist[row]; + + if( col == 0 ) + return fp->GetReference(); + else if( col == 1 ) + return fp->GetValue(); + else if( col == 2 ) + return fp->GetLayerName(); + else if( col == 3 ) + return MessageTextFromValue( m_frame->GetUserUnits(), fp->GetX() ); + else if( col == 4 ) + return MessageTextFromValue( m_frame->GetUserUnits(), fp->GetY() ); + + return wxEmptyString; +} + + +void FOOTPRINT_SEARCH_HANDLER::SelectItem( int row ) +{ + FOOTPRINT* fp = m_hitlist[row]; + + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, fp ); +} + + +ZONE_SEARCH_HANDLER::ZONE_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) : + SEARCH_HANDLER( wxT( "Zones" ) ), m_frame( aFrame ) +{ + m_columnNames.emplace_back( wxT( "Name" ) ); + m_columnNames.emplace_back( wxT( "Layer" ) ); + m_columnNames.emplace_back( wxT( "X" ) ); + m_columnNames.emplace_back( wxT( "Y" ) ); +} + + +int ZONE_SEARCH_HANDLER::Search( const wxString& query ) +{ + m_hitlist.clear(); + BOARD* board = m_frame->GetBoard(); + + EDA_SEARCH_DATA frp; + frp.findString = query; + frp.matchMode = EDA_SEARCH_MATCH_MODE::WILDCARD; + + for( BOARD_ITEM* item : board->Zones() ) + { + ZONE* zoneItem = dynamic_cast( item ); + + if( zoneItem && zoneItem->Matches( frp, nullptr ) ) + { + m_hitlist.push_back( zoneItem ); + } + } + + return m_hitlist.size(); +} + + +wxString ZONE_SEARCH_HANDLER::GetResultCell( int row, int col ) +{ + ZONE* zone = m_hitlist[row]; + + if( col == 0 ) + return zone->GetNetname(); + else if( col == 1 ) + return zone->GetLayerName(); + else if( col == 2 ) + return MessageTextFromValue( m_frame->GetUserUnits(), zone->GetX() ); + else if( col == 3 ) + return MessageTextFromValue( m_frame->GetUserUnits(), zone->GetY() ); + + return wxEmptyString; +} + + +void ZONE_SEARCH_HANDLER::SelectItem( int row ) +{ + ZONE* zone = m_hitlist[row]; + + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, zone ); +} + + +TEXT_SEARCH_HANDLER::TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) : + SEARCH_HANDLER( wxT( "Text" ) ), m_frame( aFrame ) +{ + m_columnNames.emplace_back( wxT( "Text" ) ); + m_columnNames.emplace_back( wxT( "Layer" ) ); + m_columnNames.emplace_back( wxT( "X" ) ); + m_columnNames.emplace_back( wxT( "Y" ) ); +} + + +int TEXT_SEARCH_HANDLER::Search( const wxString& query ) +{ + m_hitlist.clear(); + BOARD* board = m_frame->GetBoard(); + + EDA_SEARCH_DATA frp; + frp.findString = query; + frp.matchMode = EDA_SEARCH_MATCH_MODE::WILDCARD; + + for( BOARD_ITEM* item : board->Drawings() ) + { + PCB_TEXT* textItem = dynamic_cast( item ); + + if( textItem && textItem->Matches( frp, nullptr ) ) + { + m_hitlist.push_back( textItem ); + } + } + + return m_hitlist.size(); +} + + +wxString TEXT_SEARCH_HANDLER::GetResultCell( int row, int col ) +{ + PCB_TEXT* text = m_hitlist[row]; + + if( col == 0 ) + return text->GetText(); + if( col == 1 ) + return text->GetLayerName(); + else if( col == 2 ) + return MessageTextFromValue( m_frame->GetUserUnits(), text->GetX() ); + else if( col == 3 ) + return MessageTextFromValue( m_frame->GetUserUnits(), text->GetY() ); + + return wxEmptyString; +} + + +void TEXT_SEARCH_HANDLER::SelectItem( int row ) +{ + PCB_TEXT* text = m_hitlist[row]; + + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true ); + m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, text ); +} + + +NETS_SEARCH_HANDLER::NETS_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ) : + SEARCH_HANDLER( wxT( "Nets" ) ), m_frame( aFrame ) +{ + m_columnNames.emplace_back( wxT( "Name" ) ); + m_columnNames.emplace_back( wxT( "Class" ) ); +} + + +int NETS_SEARCH_HANDLER::Search( const wxString& query ) +{ + m_hitlist.clear(); + + EDA_SEARCH_DATA frp; + frp.findString = query; + frp.matchMode = EDA_SEARCH_MATCH_MODE::WILDCARD; + + BOARD* board = m_frame->GetBoard(); + for( NETINFO_ITEM* net : board->GetNetInfo() ) + { + if( net && net->Matches( frp, nullptr ) ) + { + m_hitlist.push_back( net ); + } + } + + return m_hitlist.size(); +} + + +wxString NETS_SEARCH_HANDLER::GetResultCell( int row, int col ) +{ + NETINFO_ITEM* net = m_hitlist[row]; + + if( col == 0 ) + return net->GetNetname(); + else if( col == 1 ) + return net->GetNetClass()->GetName(); + + return wxEmptyString; +} \ No newline at end of file diff --git a/pcbnew/widgets/search_handlers.h b/pcbnew/widgets/search_handlers.h new file mode 100644 index 0000000000..e77b11b72e --- /dev/null +++ b/pcbnew/widgets/search_handlers.h @@ -0,0 +1,90 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef SEARCH_HANDLERS_H +#define SEARCH_HANDLERS_H + +#include + +class ZONE; +class FOOTPRINT; +class PCB_TEXT; + +class FOOTPRINT_SEARCH_HANDLER : public SEARCH_HANDLER +{ +public: + FOOTPRINT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ); + + int Search( const wxString& query ) override; + wxString GetResultCell( int row, int col ) override; + void SelectItem( int row ) override; + +private: + PCB_EDIT_FRAME* m_frame; + std::vector m_hitlist; +}; + +class ZONE_SEARCH_HANDLER : public SEARCH_HANDLER +{ +public: + ZONE_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ); + + int Search( const wxString& query ) override; + wxString GetResultCell( int row, int col ) override; + void SelectItem( int row ) override; + +private: + PCB_EDIT_FRAME* m_frame; + std::vector m_hitlist; +}; + + +class TEXT_SEARCH_HANDLER : public SEARCH_HANDLER +{ +public: + TEXT_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ); + + int Search( const wxString& query ) override; + wxString GetResultCell( int row, int col ) override; + void SelectItem( int row ) override; + +private: + PCB_EDIT_FRAME* m_frame; + std::vector m_hitlist; +}; + + +class NETS_SEARCH_HANDLER : public SEARCH_HANDLER +{ +public: + NETS_SEARCH_HANDLER( PCB_EDIT_FRAME* aFrame ); + + int Search( const wxString& query ) override; + wxString GetResultCell( int row, int col ) override; + +private: + PCB_EDIT_FRAME* m_frame; + std::vector m_hitlist; +}; + +#endif \ No newline at end of file