From 72120e0a96f5b34b6547e12772a2b1e967eb18f6 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Thu, 18 Jul 2019 23:47:01 +0200 Subject: [PATCH] Actionize cvpcb --- cvpcb/CMakeLists.txt | 1 + cvpcb/auto_associate.cpp | 2 +- cvpcb/cvpcb_id.h | 15 +- cvpcb/cvpcb_mainframe.cpp | 280 ++++++++--------------- cvpcb/cvpcb_mainframe.h | 98 ++++---- cvpcb/dialogs/dialog_config_equfiles.cpp | 8 - cvpcb/footprints_listbox.cpp | 11 +- cvpcb/library_listbox.cpp | 7 +- cvpcb/menubar.cpp | 34 ++- cvpcb/readwrite_dlgs.cpp | 13 +- cvpcb/toolbars_cvpcb.cpp | 84 +++---- cvpcb/tools/cvpcb_actions.cpp | 95 +++++++- cvpcb/tools/cvpcb_actions.h | 28 ++- cvpcb/tools/cvpcb_control.cpp | 165 +++++++++++++ cvpcb/tools/cvpcb_control.h | 112 +++++++++ 15 files changed, 607 insertions(+), 346 deletions(-) create mode 100644 cvpcb/tools/cvpcb_control.cpp create mode 100644 cvpcb/tools/cvpcb_control.h diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index b0bfb8cbb5..537ead1f8a 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -47,6 +47,7 @@ set( CVPCB_SRCS readwrite_dlgs.cpp toolbars_cvpcb.cpp tools/cvpcb_actions.cpp + tools/cvpcb_control.cpp tools/cvpcb_fpviewer_control.cpp tools/cvpcb_fpviewer_selection_tool.cpp ) diff --git a/cvpcb/auto_associate.cpp b/cvpcb/auto_associate.cpp index c3757a2343..954613ea7b 100644 --- a/cvpcb/auto_associate.cpp +++ b/cvpcb/auto_associate.cpp @@ -167,7 +167,7 @@ int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wx } -void CVPCB_MAINFRAME::AutomaticFootprintMatching( wxCommandEvent& event ) +void CVPCB_MAINFRAME::AutomaticFootprintMatching() { FOOTPRINT_EQUIVALENCE_LIST equiv_List; wxString msg, error_msg; diff --git a/cvpcb/cvpcb_id.h b/cvpcb/cvpcb_id.h index 07197b08c4..8df4dbb6f9 100644 --- a/cvpcb/cvpcb_id.h +++ b/cvpcb/cvpcb_id.h @@ -39,21 +39,8 @@ // specific IDs enum id_cvpcb_frm { - ID_CVPCB_CREATE_SCREENCMP = ID_END_LIST, - ID_CVPCB_GOTO_FIRSTNA, - ID_CVPCB_GOTO_PREVIOUSNA, - ID_CVPCB_DEL_ASSOCIATIONS, - ID_CVPCB_AUTO_ASSOCIE, - ID_CVPCB_COMPONENT_LIST, + ID_CVPCB_COMPONENT_LIST = ID_END_LIST, ID_CVPCB_FOOTPRINT_LIST, - ID_CVPCB_FOOTPRINT_DISPLAY_FULL_LIST, - ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, - ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, - ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, - ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, ID_CVPCB_LIBRARY_LIST, - ID_CVPCB_EQUFILES_LIST_EDIT, - ID_CVPCB_LIB_TABLE_EDIT, ID_CVPCB_FILTER_TEXT_EDIT, - ID_TB_MEASUREMENT_TOOL }; diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 3b3576d193..9649c730a8 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -23,29 +23,33 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include #include -#include -#include -#include -#include #include #include -#include +#include #include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include wxSize const FRAME_MIN_SIZE_DU( 350, 250 ); wxSize const FRAME_DEFAULT_SIZE_DU( 450, 300 ); @@ -58,44 +62,18 @@ static const wxString FilterFootprintEntry = "FilterFootprint"; BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, KIWAY_PLAYER ) - // Menu events - EVT_MENU( ID_SAVE_PROJECT, CVPCB_MAINFRAME::OnSaveAndContinue ) + // Control events EVT_MENU( wxID_EXIT, CVPCB_MAINFRAME::OnQuit ) - EVT_MENU( ID_CVPCB_EQUFILES_LIST_EDIT, CVPCB_MAINFRAME::OnEditEquFilesList ) - - // Toolbar events - EVT_TOOL( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable ) - EVT_TOOL( ID_CVPCB_CREATE_SCREENCMP, CVPCB_MAINFRAME::DisplayModule ) - EVT_TOOL( ID_CVPCB_GOTO_FIRSTNA, CVPCB_MAINFRAME::ToFirstNA ) - EVT_TOOL( ID_CVPCB_GOTO_PREVIOUSNA, CVPCB_MAINFRAME::ToPreviousNA ) - EVT_TOOL( ID_CVPCB_DEL_ASSOCIATIONS, CVPCB_MAINFRAME::DelAssociations ) - EVT_TOOL( ID_CVPCB_AUTO_ASSOCIE, CVPCB_MAINFRAME::AutomaticFootprintMatching ) - EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, - CVPCB_MAINFRAME::OnSelectFilteringFootprint ) - EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, - CVPCB_MAINFRAME::OnSelectFilteringFootprint ) - EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, - CVPCB_MAINFRAME::OnSelectFilteringFootprint ) - EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, - CVPCB_MAINFRAME::OnSelectFilteringFootprint ) - EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText ) - - // Button events EVT_BUTTON( wxID_OK, CVPCB_MAINFRAME::OnOK ) EVT_BUTTON( wxID_CANCEL, CVPCB_MAINFRAME::OnCancel ) + // Toolbar events + EVT_TEXT( ID_CVPCB_FILTER_TEXT_EDIT, CVPCB_MAINFRAME::OnEnterFilteringText ) + // Frame events EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow ) EVT_SIZE( CVPCB_MAINFRAME::OnSize ) - // UI event handlers - EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, CVPCB_MAINFRAME::OnFilterFPbyKeywords ) - EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, - CVPCB_MAINFRAME::OnFilterFPbyPinCount ) - EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, - CVPCB_MAINFRAME::OnFilterFPbyLibrary ) - EVT_UPDATE_UI( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, CVPCB_MAINFRAME::OnFilterFPbyKeyName ) - END_EVENT_TABLE() @@ -112,7 +90,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : m_mainToolBar = NULL; m_modified = false; m_skipComponentSelect = false; - m_filteringOptions = 0; + m_filteringOptions = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST; m_tcFilterString = NULL; m_FootprintsList = FOOTPRINT_LIST::GetInstance( Kiway() ); m_initialized = false; @@ -133,14 +111,7 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : // Frame size and position SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - // Create the manager - m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, this ); - - // Register tools - m_toolManager->RegisterTool( new COMMON_CONTROL ); - m_toolManager->InitTools(); - + setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); @@ -216,24 +187,28 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( KIWAY* aKiway, wxWindow* aParent ) : m_initialized = true; // Connect Events - m_saveAndContinue->Connect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), - NULL, this ); m_footprintListBox->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnFootprintRightClick ), NULL, this ); m_compListBox->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnComponentRightClick ), NULL, this ); + + // Use Bind for this one to allow the lambda expression + m_saveAndContinue->Bind( wxEVT_COMMAND_BUTTON_CLICKED, + [this]( wxCommandEvent& ) + { + this->GetToolManager()->RunAction( CVPCB_ACTIONS::saveAssociations ); + } ); + + // Ensure the toolbars are sync'd properly so the filtering options display correct + SyncToolbars(); } CVPCB_MAINFRAME::~CVPCB_MAINFRAME() { // Disconnect Events - m_saveAndContinue->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, - wxCommandEventHandler( CVPCB_MAINFRAME::OnSaveAndContinue ), - NULL, this ); m_footprintListBox->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( CVPCB_MAINFRAME::OnFootprintRightClick ), NULL, this ); @@ -242,6 +217,30 @@ CVPCB_MAINFRAME::~CVPCB_MAINFRAME() } +void CVPCB_MAINFRAME::setupTools() +{ + // Create the manager + m_toolManager = new TOOL_MANAGER; + m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, this ); + + // Register tools + m_toolManager->RegisterTool( new COMMON_CONTROL ); + m_toolManager->RegisterTool( new CVPCB_CONTROL ); + m_toolManager->InitTools(); + + CVPCB_CONTROL* tool = m_toolManager->GetTool(); + + // Create the context menu for the component list box + m_componentContextMenu = new ACTION_MENU( true ); + m_componentContextMenu->SetTool( tool ); + m_componentContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer ); + + // Create the context menu for the footprint list box + m_footprintContextMenu = new ACTION_MENU( true ); + m_footprintContextMenu->SetTool( tool ); + m_footprintContextMenu->Add( CVPCB_ACTIONS::showFootprintViewer ); +} + void CVPCB_MAINFRAME::LoadSettings( wxConfigBase* aCfg ) { EDA_BASE_FRAME::LoadSettings( aCfg ); @@ -321,7 +320,7 @@ void CVPCB_MAINFRAME::ChangeFocus( bool aMoveRight ) } -void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event ) +void CVPCB_MAINFRAME::ToNextNA() { if( m_netlist.IsEmpty() ) return; @@ -351,7 +350,7 @@ void CVPCB_MAINFRAME::ToFirstNA( wxCommandEvent& event ) } -void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event ) +void CVPCB_MAINFRAME::ToPreviousNA() { if( m_netlist.IsEmpty() ) return; @@ -384,19 +383,11 @@ void CVPCB_MAINFRAME::ToPreviousNA( wxCommandEvent& event ) void CVPCB_MAINFRAME::OnOK( wxCommandEvent& aEvent ) { SaveFootprintAssociation( false ); - m_modified = false; Close( true ); } -void CVPCB_MAINFRAME::OnSaveAndContinue( wxCommandEvent& aEvent ) -{ - SaveFootprintAssociation( true ); - m_modified = false; -} - - void CVPCB_MAINFRAME::OnCancel( wxCommandEvent& event ) { // Throw away modifications on a Cancel @@ -412,9 +403,9 @@ void CVPCB_MAINFRAME::OnQuit( wxCommandEvent& event ) } -void CVPCB_MAINFRAME::DelAssociations( wxCommandEvent& event ) +void CVPCB_MAINFRAME::DeleteAll() { - if( IsOK( this, _( "Delete selections" ) ) ) + if( IsOK( this, _( "Delete all associations?" ) ) ) { m_skipComponentSelect = true; @@ -446,42 +437,15 @@ bool CVPCB_MAINFRAME::OpenProjectFiles( const std::vector& aFileSet, i } -void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent ) -{ - KIFACE* kiface = Kiway().KiFACE( KIWAY::FACE_PCB ); - kiface->CreateWindow( this, DIALOG_PCB_LIBRARY_TABLE, &Kiway() ); - - wxBusyCursor dummy; - BuildLIBRARY_LISTBOX(); - m_FootprintsList->ReadFootprintFiles( Prj().PcbFootprintLibs( Kiway() ) ); -} - - -void CVPCB_MAINFRAME::DisplayModule( wxCommandEvent& event ) -{ - CreateScreenCmp(); -} - - void CVPCB_MAINFRAME::OnComponentRightClick( wxMouseEvent& event ) { - wxMenu menu; - - menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), - _( "Show the assigned footprint in the footprint viewer" ) ); - - PopupMenu( &menu ); + PopupMenu( m_componentContextMenu ); } void CVPCB_MAINFRAME::OnFootprintRightClick( wxMouseEvent& event ) { - wxMenu menu; - - menu.Append( ID_CVPCB_CREATE_SCREENCMP, _( "View Footprint" ), - _( "Show the current footprint in the footprint viewer" ) ); - - PopupMenu( &menu ); + PopupMenu( m_footprintContextMenu ); } @@ -546,7 +510,7 @@ void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component ) } if( GetFootprintViewerFrame() ) - CreateScreenCmp(); + m_toolManager->RunAction( CVPCB_ACTIONS::showFootprintViewer, true ); } SendMessageToEESCHEMA(); @@ -554,64 +518,46 @@ void CVPCB_MAINFRAME::refreshAfterComponentSearch( COMPONENT* component ) } -void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event ) +void CVPCB_MAINFRAME::SetFootprintFilter( + FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction ) { - int option = 0; + int option = FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST; - switch( event.GetId() ) + // Extract the needed information about the filter + switch( aFilter ) { - case ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST: - option = FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_KEYWORD; - break; - - case ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST: - option = FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT; - break; - - case ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST: - option = FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY; - break; - - case ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME: + case FOOTPRINTS_LISTBOX::FILTERING_BY_NAME: + // Extract the current search patten when needed m_currentSearchPattern = m_tcFilterString->GetValue(); - option = FOOTPRINTS_LISTBOX::FILTERING_BY_NAME; + + case FOOTPRINTS_LISTBOX::UNFILTERED_FP_LIST: + case FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT: + case FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY: + case FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_KEYWORD: + option = aFilter; + } + + // Apply the filter accordingly + switch( aAction ) + { + case CVPCB_MAINFRAME::FILTER_DISABLE: + m_filteringOptions &= ~option; + break; + + case CVPCB_MAINFRAME::FILTER_ENABLE: + m_filteringOptions |= option; + break; + + case CVPCB_MAINFRAME::FILTER_TOGGLE: + m_filteringOptions ^= option; break; } - if( event.IsChecked() ) - m_filteringOptions |= option; - else - m_filteringOptions &= ~option; - wxListEvent l_event; OnSelectComponent( l_event ); } -void CVPCB_MAINFRAME::OnFilterFPbyKeywords( wxUpdateUIEvent& event ) -{ - event.Check( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_KEYWORD ); -} - - -void CVPCB_MAINFRAME::OnFilterFPbyPinCount( wxUpdateUIEvent& event ) -{ - event.Check( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT ); -} - - -void CVPCB_MAINFRAME::OnFilterFPbyLibrary( wxUpdateUIEvent& event ) -{ - event.Check( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY ); -} - - -void CVPCB_MAINFRAME::OnFilterFPbyKeyName( wxUpdateUIEvent& event ) -{ - event.Check( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ); -} - - void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent ) { // Called when changing the filter string in main toolbar. @@ -623,7 +569,8 @@ void CVPCB_MAINFRAME::OnEnterFilteringText( wxCommandEvent& aEvent ) if( ( m_filteringOptions & FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ) == 0 ) return; - OnSelectFilteringFootprint( aEvent ); + wxListEvent l_event; + OnSelectComponent( l_event ); } @@ -806,39 +753,6 @@ int CVPCB_MAINFRAME::ReadSchematicNetlist( const std::string& aNetlist ) } -void CVPCB_MAINFRAME::CreateScreenCmp() -{ - DISPLAY_FOOTPRINTS_FRAME* fpframe = GetFootprintViewerFrame(); - - if( !fpframe ) - { - fpframe = (DISPLAY_FOOTPRINTS_FRAME*) Kiway().Player( FRAME_CVPCB_DISPLAY, true, this ); - fpframe->Show( true ); - } - else - { - if( fpframe->IsIconized() ) - fpframe->Iconize( false ); - - // The display footprint window might be buried under some other - // windows, so CreateScreenCmp() on an existing window would not - // show any difference, leaving the user confused. - // So we want to put it to front, second after our CVPCB_MAINFRAME. - // We do this by a little dance of bringing it to front then the main - // frame back. - wxWindow* focus = FindFocus(); - - fpframe->Raise(); // Make sure that is visible. - Raise(); // .. but still we want the focus. - - if( focus ) - focus->SetFocus(); - } - - fpframe->InitDisplay(); -} - - void CVPCB_MAINFRAME::BuildFOOTPRINTS_LISTBOX() { wxFont guiFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); diff --git a/cvpcb/cvpcb_mainframe.h b/cvpcb/cvpcb_mainframe.h index 4925e5104f..a75e436fe7 100644 --- a/cvpcb/cvpcb_mainframe.h +++ b/cvpcb/cvpcb_mainframe.h @@ -25,22 +25,20 @@ #ifndef _CVPCB_MAINFRAME_H_ #define _CVPCB_MAINFRAME_H_ -#include -#include -#include -#include - -#include #include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include /* Forward declarations of all top-level window classes. */ class wxAuiToolBar; -class FOOTPRINTS_LISTBOX; -class COMPONENTS_LISTBOX; -class LIBRARY_LISTBOX; class DISPLAY_FOOTPRINTS_FRAME; class COMPONENT; class FP_LIB_TABLE; @@ -57,7 +55,7 @@ class CVPCB_MAINFRAME : public KIWAY_PLAYER wxString m_currentSearchPattern; NETLIST m_netlist; int m_filteringOptions; - wxAuiToolBar* m_mainToolBar; + ACTION_TOOLBAR* m_mainToolBar; FOOTPRINTS_LISTBOX* m_footprintListBox; LIBRARY_LISTBOX* m_libListBox; COMPONENTS_LISTBOX* m_compListBox; @@ -89,6 +87,16 @@ public: void KiwayMailIn( KIWAY_EXPRESS& aEvent ) override; + /** + * The action to apply to a footprint filter when it is modified. + */ + enum CVPCB_FILTER_ACTION + { + FILTER_DISABLE, ///< Turn off the filter + FILTER_ENABLE, ///< Turn on the filter + FILTER_TOGGLE ///< Toggle the filter state + }; + /** * @return a pointer on the Footprint Viewer frame, if exists, or NULL */ @@ -103,16 +111,8 @@ public: */ void OnSelectComponent( wxListEvent& event ); - /** - * Function OnEditFootprintLibraryTable - * displays the footprint library table editing dialog and updates the global and local - * footprint tables accordingly. - */ - void OnEditFootprintLibraryTable( wxCommandEvent& event ); - void OnCancel( wxCommandEvent& aEvent ); void OnOK( wxCommandEvent& aEvent ); - void OnSaveAndContinue( wxCommandEvent& aEvent ); void OnQuit( wxCommandEvent& event ); void OnCloseWindow( wxCloseEvent& Event ); void OnSize( wxSizeEvent& SizeEvent ); @@ -123,22 +123,21 @@ public: void ChangeFocus( bool aMoveRight ); - void ToFirstNA( wxCommandEvent& event ); - void ToPreviousNA( wxCommandEvent& event ); + /** + * Move to the next not associated component. + */ + void ToNextNA(); /** - * Function DelAssociations + * Move to the previous not associated component. + */ + void ToPreviousNA(); + + /** + * Function DeleteAll * removes all component footprint associations already made */ - void DelAssociations( wxCommandEvent& event ); - - /** - * Function OnEditEquFilesList - * envokes the equ files list edit dialog. - */ - void OnEditEquFilesList( wxCommandEvent& aEvent ); - - void DisplayModule( wxCommandEvent& event ); + void DeleteAll(); void OnComponentRightClick( wxMouseEvent& event ); @@ -152,13 +151,17 @@ public: * format of a line: * 'cmp_ref' 'footprint_name' */ - void AutomaticFootprintMatching( wxCommandEvent& event ); + void AutomaticFootprintMatching(); /** - * Function OnSelectFilteringFootprint - * is the command event handler for enabling and disabling footprint filtering. + * Function SetFootprintFilter + * Set a filter criteria to either on/off or toggle the criteria. + * + * @param aFilter The filter to modify + * @param aAction What action (on, off or toggle) to take */ - void OnSelectFilteringFootprint( wxCommandEvent& event ); + void SetFootprintFilter( + FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction ); /** * Function OnEnterFilteringText @@ -187,12 +190,6 @@ public: void BuildFOOTPRINTS_LISTBOX(); void BuildLIBRARY_LISTBOX(); - /** - * Create or Update the frame showing the current highlighted footprint - * and (if showed) the 3D display frame - */ - void CreateScreenCmp(); - /** * Function SaveFootprintAssociation * saves the edits that the user has done by sending them back to eeschema @@ -297,13 +294,16 @@ public: void SetStatusText( const wxString& aText, int aNumber = 0 ) override; + /** + * Syncronize the toolbar state with the current tool state. + */ + void SyncToolbars() override; + private: - // UI event handlers. - // Keep consistent the display state of toggle menus or tools in toolbar - void OnFilterFPbyKeywords( wxUpdateUIEvent& event ); - void OnFilterFPbyPinCount( wxUpdateUIEvent& event ); - void OnFilterFPbyLibrary( wxUpdateUIEvent& event ); - void OnFilterFPbyKeyName( wxUpdateUIEvent& event ); + /** + * Setup the tool system for the CVPCB main frame. + */ + void setupTools(); /** * read the .equ files and populate the list of equvalents @@ -316,6 +316,10 @@ private: void refreshAfterComponentSearch (COMPONENT* component); + // Context menus for the list boxes + ACTION_MENU* m_footprintContextMenu; + ACTION_MENU* m_componentContextMenu; + DECLARE_EVENT_TABLE() }; diff --git a/cvpcb/dialogs/dialog_config_equfiles.cpp b/cvpcb/dialogs/dialog_config_equfiles.cpp index d9aa80ae57..4f28304b57 100644 --- a/cvpcb/dialogs/dialog_config_equfiles.cpp +++ b/cvpcb/dialogs/dialog_config_equfiles.cpp @@ -59,14 +59,6 @@ DIALOG_CONFIG_EQUFILES::DIALOG_CONFIG_EQUFILES( CVPCB_MAINFRAME* aParent ) : } -void CVPCB_MAINFRAME::OnEditEquFilesList( wxCommandEvent& aEvent ) -{ - DIALOG_CONFIG_EQUFILES dlg( this ); - - dlg.ShowModal(); -} - - void DIALOG_CONFIG_EQUFILES::Init() { m_sdbSizerOK->SetDefault(); diff --git a/cvpcb/footprints_listbox.cpp b/cvpcb/footprints_listbox.cpp index a30df9aaed..b03e78be02 100644 --- a/cvpcb/footprints_listbox.cpp +++ b/cvpcb/footprints_listbox.cpp @@ -27,16 +27,17 @@ * class to display the list of available footprints */ +#include #include +#include +#include #include #include +#include #include #include -#include -#include -#include - +#include FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id, const wxPoint& loc, @@ -215,7 +216,7 @@ void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event ) // If the footprint view window is displayed, update the footprint. if( GetParent()->GetFootprintViewerFrame() ) - GetParent()->CreateScreenCmp(); + GetParent()->GetToolManager()->RunAction( CVPCB_ACTIONS::showFootprintViewer, true ); GetParent()->DisplayStatus(); diff --git a/cvpcb/library_listbox.cpp b/cvpcb/library_listbox.cpp index 0113e606b8..e771f978ac 100644 --- a/cvpcb/library_listbox.cpp +++ b/cvpcb/library_listbox.cpp @@ -211,10 +211,9 @@ void LIBRARY_LISTBOX::OnChar( wxKeyEvent& event ) void LIBRARY_LISTBOX::OnSelectLibrary( wxListEvent& event ) { - wxCommandEvent setLibraryFilterEvent; - setLibraryFilterEvent.SetId( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ); - setLibraryFilterEvent.SetInt( 1 ); - GetParent()->OnSelectFilteringFootprint( setLibraryFilterEvent ); + // Apply the filter + GetParent()->SetFootprintFilter( + FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY, CVPCB_MAINFRAME::FILTER_ENABLE ); SetFocus(); GetParent()->OnSelectComponent( event ); diff --git a/cvpcb/menubar.cpp b/cvpcb/menubar.cpp index ef8db00a3e..3a146720ee 100644 --- a/cvpcb/menubar.cpp +++ b/cvpcb/menubar.cpp @@ -22,15 +22,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include -#include -#include -#include -#include -#include "cvpcb_id.h" -#include "cvpcb_mainframe.h" #include +#include +#include +#include +#include +#include + +#include +#include +#include void CVPCB_MAINFRAME::ReCreateMenuBar() @@ -45,10 +47,7 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() // CONDITIONAL_MENU* fileMenu = new CONDITIONAL_MENU( false, tool ); - fileMenu->AddItem( ID_SAVE_PROJECT, - _( "&Save Schematic\tCtrl+S" ), - _( "Save footprint associations in schematic symbol footprint fields" ), - save_xpm, SELECTION_CONDITIONS::ShowAlways ); + fileMenu->AddItem( CVPCB_ACTIONS::saveAssociations, SELECTION_CONDITIONS::ShowAlways ); fileMenu->Resolve(); @@ -56,19 +55,14 @@ void CVPCB_MAINFRAME::ReCreateMenuBar() // CONDITIONAL_MENU* prefsMenu = new CONDITIONAL_MENU( false, tool ); - prefsMenu->AddItem( ACTIONS::configurePaths, SELECTION_CONDITIONS::ShowAlways ); - prefsMenu->AddItem( ACTIONS::showFootprintLibTable, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->AddItem( ACTIONS::configurePaths, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->AddItem( ACTIONS::showFootprintLibTable, SELECTION_CONDITIONS::ShowAlways ); prefsMenu->AddItem( wxID_PREFERENCES, _( "Preferences...\tCTRL+," ), _( "Show preferences for all open tools" ), - preference_xpm, SELECTION_CONDITIONS::ShowAlways ); - + preference_xpm, SELECTION_CONDITIONS::ShowAlways ); prefsMenu->AddSeparator(); - prefsMenu->AddItem( ID_CVPCB_EQUFILES_LIST_EDIT, - _( "Footprint &Association Files..." ), - _( "Configure footprint association file (.equ) list. These files are " - "used to automatically assign footprint names from symbol values." ), - library_table_xpm, SELECTION_CONDITIONS::ShowAlways ); + prefsMenu->AddItem( CVPCB_ACTIONS::showEquFileTable, SELECTION_CONDITIONS::ShowAlways ); prefsMenu->AddSeparator(); AddMenuLanguageList( prefsMenu, tool ); diff --git a/cvpcb/readwrite_dlgs.cpp b/cvpcb/readwrite_dlgs.cpp index f0d3ff5256..1f7d8feed3 100644 --- a/cvpcb/readwrite_dlgs.cpp +++ b/cvpcb/readwrite_dlgs.cpp @@ -26,15 +26,15 @@ * or you may write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include +#include #include #include -#include -#include -#include +#include #include #include +#include +#include +#include #include #include @@ -390,5 +390,8 @@ bool CVPCB_MAINFRAME::SaveFootprintAssociation( bool doSaveSchematic ) SetStatusText( _( "Schematic saved" ), 1 ); } + // Changes are saved, so reset the flag + m_modified = false; + return true; } diff --git a/cvpcb/toolbars_cvpcb.cpp b/cvpcb/toolbars_cvpcb.cpp index 6334c53ad4..bed9662398 100644 --- a/cvpcb/toolbars_cvpcb.cpp +++ b/cvpcb/toolbars_cvpcb.cpp @@ -23,13 +23,16 @@ * @file tool_cvpcb.cpp */ +#include +#include #include #include -#include +#include +#include -#include -#include #include +#include +#include void CVPCB_MAINFRAME::ReCreateHToolbar() @@ -37,35 +40,22 @@ void CVPCB_MAINFRAME::ReCreateHToolbar() if( m_mainToolBar ) m_mainToolBar->Clear(); else - m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize, - KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT ); + m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize, + KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT ); - m_mainToolBar->AddTool( ID_CVPCB_LIB_TABLE_EDIT, wxEmptyString, - KiScaledBitmap( config_xpm, this ), - _( "Edit footprint library table" ) ); + m_mainToolBar->Add( ACTIONS::showFootprintLibTable ); KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->AddTool( ID_CVPCB_CREATE_SCREENCMP, wxEmptyString, - KiScaledBitmap( show_footprint_xpm, this ), - _( "View selected footprint" ) ); + m_mainToolBar->Add( CVPCB_ACTIONS::showFootprintViewer ); + KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->AddTool( ID_CVPCB_GOTO_PREVIOUSNA, wxEmptyString, - KiScaledBitmap( left_xpm, this ), - _( "Select previous unlinked symbol" ) ); - - m_mainToolBar->AddTool( ID_CVPCB_GOTO_FIRSTNA, wxEmptyString, - KiScaledBitmap( right_xpm, this ), - _( "Select next unlinked symbol" ) ); + m_mainToolBar->Add( CVPCB_ACTIONS::gotoPreviousNA ); + m_mainToolBar->Add( CVPCB_ACTIONS::gotoNextNA ); KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->AddTool( ID_CVPCB_AUTO_ASSOCIE, wxEmptyString, - KiScaledBitmap( auto_associe_xpm, this ), - _( "Perform automatic footprint association" ) ); - - m_mainToolBar->AddTool( ID_CVPCB_DEL_ASSOCIATIONS, wxEmptyString, - KiScaledBitmap( delete_association_xpm, this ), - _( "Delete all footprint associations" ) ); + m_mainToolBar->Add( CVPCB_ACTIONS::autoAssociate ); + m_mainToolBar->Add( CVPCB_ACTIONS::deleteAll ); // Add tools for footprint names filtering: KiScaledSeparator( m_mainToolBar, this ); @@ -75,32 +65,12 @@ void CVPCB_MAINFRAME::ReCreateHToolbar() text->SetFont( m_mainToolBar->GetFont().Bold() ); m_mainToolBar->AddControl( text ); - m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, - KiScaledBitmap( module_filtered_list_xpm, this ), - wxNullBitmap, - true, NULL, - _( "Filter footprint list by schematic symbol keywords" ), - wxEmptyString ); - - m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, - KiScaledBitmap( module_pin_filtered_list_xpm, this ), - wxNullBitmap, - true, NULL, - _( "Filter footprint list by pin count" ), - wxEmptyString ); - - m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, - KiScaledBitmap( module_library_list_xpm, this ), - wxNullBitmap, true, NULL, - _( "Filter footprint list by library" ), - wxEmptyString ); + m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyKeywords, true ); + m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyPin, true ); + m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyLibrary, true ); KiScaledSeparator( m_mainToolBar, this ); - m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, - KiScaledBitmap( module_name_filtered_list_xpm, this ), - wxNullBitmap, true, NULL, - _( "Filter footprint list using a partial name or a pattern" ), - wxEmptyString ); + m_mainToolBar->Add( CVPCB_ACTIONS::filterFPbyDisplayName, true ); m_tcFilterString = new wxTextCtrl( m_mainToolBar, ID_CVPCB_FILTER_TEXT_EDIT ); @@ -110,3 +80,19 @@ void CVPCB_MAINFRAME::ReCreateHToolbar() // after adding the buttons to the toolbar, must call Realize() to reflect the changes m_mainToolBar->Realize(); } + + +void CVPCB_MAINFRAME::SyncToolbars() +{ +#define filterActive( filt ) ( m_filteringOptions & filt ) + + m_mainToolBar->Toggle( CVPCB_ACTIONS::filterFPbyKeywords, + filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_KEYWORD ) ); + m_mainToolBar->Toggle( CVPCB_ACTIONS::filterFPbyLibrary, + filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY ) ); + m_mainToolBar->Toggle( CVPCB_ACTIONS::filterFPbyPin, + filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT ) ); + m_mainToolBar->Toggle( CVPCB_ACTIONS::filterFPbyDisplayName, + filterActive( FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ) ); + m_mainToolBar->Refresh(); +} diff --git a/cvpcb/tools/cvpcb_actions.cpp b/cvpcb/tools/cvpcb_actions.cpp index 4dc8505144..78f1bc897c 100644 --- a/cvpcb/tools/cvpcb_actions.cpp +++ b/cvpcb/tools/cvpcb_actions.cpp @@ -18,10 +18,12 @@ * with this program. If not, see . */ -#include #include -#include "cvpcb_actions.h" +#include +#include +#include +#include // Actions, being statically-defined, require specialized I18N handling. We continue to // use the _() macro so that string harvesting by the I18N framework doesn't have to be @@ -31,10 +33,89 @@ #define _(s) s -// CVPCB_SELECTION_TOOL -// -TOOL_ACTION CVPCB_ACTIONS::selectionActivate( "cvpcb.InteractiveSelection", - AS_GLOBAL, 0, "", - "", "", NULL, AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere +// Selection tool action for the footprint viewer window +TOOL_ACTION CVPCB_ACTIONS::selectionActivate( "cvpcb.InteractiveSelection", AS_GLOBAL, + 0, "", + "", + "", + NULL, AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere +// Action to show the footprint viewer window +TOOL_ACTION CVPCB_ACTIONS::showFootprintViewer( "cvpcb.Control.ShowFootprintViewer", AS_GLOBAL, + 0, "", + _( "View selected footprint" ), + _( "View the selected footprint in the footprint viewer" ), + show_footprint_xpm ); + + +// Actions to handle management tasks +TOOL_ACTION CVPCB_ACTIONS::showEquFileTable( "cvpcb.Control.ShowEquFileTable", AS_GLOBAL, + 0, "", + _( "Manage Footprint Association Files" ), + _( "Configure footprint association file (.equ) list. These files are " + "used to automatically assign footprint names from symbol values." ), + library_table_xpm ); + +TOOL_ACTION CVPCB_ACTIONS::saveAssociations( "cvpcb.Control.SaveAssocations", AS_GLOBAL, + MD_CTRL + 'S', LEGACY_HK_NAME( "Save" ), + _( "Save to Schematic" ), + _( "Save footprint associations in schematic symbol footprint fields" ), + save_xpm ); + +// Actions to navigate the component list +TOOL_ACTION CVPCB_ACTIONS::gotoNextNA( "cvpcb.Control.GotoNextNA", AS_GLOBAL, + 0, "", + _( "Select next unassociated symbol" ), + _( "Select next unassociated symbol" ), + right_xpm ); + +TOOL_ACTION CVPCB_ACTIONS::gotoPreviousNA( "cvpcb.Control.GotoPreviousNA", AS_GLOBAL, + 0, "", + _( "Select previous unassociated symbol" ), + _( "Select previous unassociated symbol" ), + left_xpm ); + + +// Actions to modify component associations +TOOL_ACTION CVPCB_ACTIONS::autoAssociate( "cvpcb.Control.AutoAssociate", AS_GLOBAL, + 0, "", + _( "Automatically associate footprints" ), + _( "Perform automatic footprint association" ), + auto_associe_xpm ); + +TOOL_ACTION CVPCB_ACTIONS::deleteAll( "cvpcb.Control.DeleteAll", AS_GLOBAL, + 0, "", + _( "Delete all footprint associations" ), + _( "Delete all footprint associations" ), + delete_association_xpm ); + + +// Actions to filter the footprint list +TOOL_ACTION CVPCB_ACTIONS::filterFPbyKeywords( "cvpcb.Control.FilterFPByKeyword", AS_GLOBAL, + 0, "", + _( "Filter by keyword" ), + _( "Filter footprint list by schematic symbol keywords" ), + module_filtered_list_xpm, AF_NONE, + (void*) FOOTPRINTS_LISTBOX::FILTERING_BY_COMPONENT_KEYWORD ); + +TOOL_ACTION CVPCB_ACTIONS::filterFPbyPin( "cvpcb.Control.FilterFPByPin", AS_GLOBAL, + 0, "", + _( "Filter by pin count" ), + _( "Filter footprint list by pin count" ), + module_pin_filtered_list_xpm, AF_NONE, + (void*) FOOTPRINTS_LISTBOX::FILTERING_BY_PIN_COUNT ); + +TOOL_ACTION CVPCB_ACTIONS::filterFPbyLibrary( "cvpcb.Control.FilterFPByLibrary", AS_GLOBAL, + 0, "", + _( "Filter by library" ), + _( "Filter footprint list by library" ), + module_library_list_xpm, AF_NONE, + (void*) FOOTPRINTS_LISTBOX::FILTERING_BY_LIBRARY ); + +TOOL_ACTION CVPCB_ACTIONS::filterFPbyDisplayName( "cvpcb.Control.FilterFPByDisplayName", AS_GLOBAL, + 0, "", + _( "Filter by display name" ), + _( "Filter footprint list using a partial name or a pattern" ), + module_name_filtered_list_xpm, AF_NONE, + (void*) FOOTPRINTS_LISTBOX::FILTERING_BY_NAME ); diff --git a/cvpcb/tools/cvpcb_actions.h b/cvpcb/tools/cvpcb_actions.h index 9fb87597ec..4921b31308 100644 --- a/cvpcb/tools/cvpcb_actions.h +++ b/cvpcb/tools/cvpcb_actions.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2013-2016 CERN - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -26,9 +26,9 @@ #ifndef CVPCB_ACTIONS_H #define CVPCB_ACTIONS_H -#include -#include #include +#include +#include class TOOL_EVENT; class TOOL_MANAGER; @@ -46,6 +46,28 @@ public: /// Activation of the selection tool static TOOL_ACTION selectionActivate; + /// Open the footprint viewer + static TOOL_ACTION showFootprintViewer; + + /// Navigate the component tree + static TOOL_ACTION gotoPreviousNA; + static TOOL_ACTION gotoNextNA; + + /// Management actions + static TOOL_ACTION saveAssociations; + static TOOL_ACTION showEquFileTable; + + /// Footprint Association actions + static TOOL_ACTION autoAssociate; + static TOOL_ACTION associate; + static TOOL_ACTION deleteAll; + + /// Footprint Filtering actions + static TOOL_ACTION filterFPbyKeywords; + static TOOL_ACTION filterFPbyPin; + static TOOL_ACTION filterFPbyLibrary; + static TOOL_ACTION filterFPbyDisplayName; + ///> @copydoc COMMON_ACTIONS::TranslateLegacyId() virtual OPT TranslateLegacyId( int aId ) override { return OPT(); } }; diff --git a/cvpcb/tools/cvpcb_control.cpp b/cvpcb/tools/cvpcb_control.cpp new file mode 100644 index 0000000000..66c90831bd --- /dev/null +++ b/cvpcb/tools/cvpcb_control.cpp @@ -0,0 +1,165 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 Ian McInerney + * Copyright (C) 2019 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 +#include +#include + +using namespace std::placeholders; + + +CVPCB_CONTROL::CVPCB_CONTROL() : + TOOL_INTERACTIVE( "cvpcb.Control" ), + m_frame( nullptr ) +{ +} + + +void CVPCB_CONTROL::Reset( RESET_REASON aReason ) +{ + m_frame = getEditFrame(); +} + + +int CVPCB_CONTROL::ShowFootprintViewer( const TOOL_EVENT& aEvent ) +{ + + DISPLAY_FOOTPRINTS_FRAME* fpframe = m_frame->GetFootprintViewerFrame(); + + if( !fpframe ) + { + fpframe = (DISPLAY_FOOTPRINTS_FRAME*) m_frame->Kiway().Player( + FRAME_CVPCB_DISPLAY, true, m_frame ); + fpframe->Show( true ); + } + else + { + if( fpframe->IsIconized() ) + fpframe->Iconize( false ); + + // The display footprint window might be buried under some other + // windows, so CreateScreenCmp() on an existing window would not + // show any difference, leaving the user confused. + // So we want to put it to front, second after our CVPCB_MAINFRAME. + // We do this by a little dance of bringing it to front then the main + // frame back. + wxWindow* focus = m_frame->FindFocus(); + + fpframe->Raise(); // Make sure that is visible. + m_frame->Raise(); // .. but still we want the focus. + + if( focus ) + focus->SetFocus(); + } + + fpframe->InitDisplay(); + + return 0; +} + + +int CVPCB_CONTROL::ToggleFootprintFilter( const TOOL_EVENT& aEvent ) +{ + m_frame->SetFootprintFilter( + static_cast( aEvent.Parameter() ), + CVPCB_MAINFRAME::FILTER_TOGGLE ); + + return 0; +} + + +int CVPCB_CONTROL::AutoAssociate( const TOOL_EVENT& aEvent ) +{ + m_frame->AutomaticFootprintMatching(); + + return 0; +} + + +int CVPCB_CONTROL::DeleteAll( const TOOL_EVENT& aEvent ) +{ + m_frame->DeleteAll(); + + return 0; +} + + +int CVPCB_CONTROL::ShowEquFileTable( const TOOL_EVENT& aEvent ) +{ + DIALOG_CONFIG_EQUFILES dlg( m_frame ); + dlg.ShowModal(); + + return 0; +} + + +int CVPCB_CONTROL::SaveAssociations( const TOOL_EVENT& aEvent ) +{ + m_frame->SaveFootprintAssociation( true ); + return 0; +} + + +int CVPCB_CONTROL::ToNextNA( const TOOL_EVENT& aEvent ) +{ + m_frame->ToNextNA(); + return 0; +} + + +int CVPCB_CONTROL::ToPreviousNA( const TOOL_EVENT& aEvent ) +{ + m_frame->ToPreviousNA(); + return 0; +} + + +void CVPCB_CONTROL::setTransitions() +{ + // Run the footprint viewer + Go( &CVPCB_CONTROL::ShowFootprintViewer, CVPCB_ACTIONS::showFootprintViewer.MakeEvent() ); + + // Management actions + Go( &CVPCB_CONTROL::ShowEquFileTable, CVPCB_ACTIONS::showEquFileTable.MakeEvent() ); + Go( &CVPCB_CONTROL::SaveAssociations, CVPCB_ACTIONS::saveAssociations.MakeEvent() ); + Go( &CVPCB_CONTROL::DeleteAll, CVPCB_ACTIONS::deleteAll.MakeEvent() ); + + // Navigation actions + Go( &CVPCB_CONTROL::ToNextNA, CVPCB_ACTIONS::gotoNextNA.MakeEvent() ); + Go( &CVPCB_CONTROL::ToPreviousNA, CVPCB_ACTIONS::gotoPreviousNA.MakeEvent() ); + + // Footprint association actions + Go( &CVPCB_CONTROL::AutoAssociate, CVPCB_ACTIONS::autoAssociate.MakeEvent() ); + + // Filter the footprints + Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyKeywords.MakeEvent() ); + Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyLibrary.MakeEvent() ); + Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyPin.MakeEvent() ); + Go( &CVPCB_CONTROL::ToggleFootprintFilter, CVPCB_ACTIONS::filterFPbyDisplayName.MakeEvent() ); +} diff --git a/cvpcb/tools/cvpcb_control.h b/cvpcb/tools/cvpcb_control.h new file mode 100644 index 0000000000..e2752e68ad --- /dev/null +++ b/cvpcb/tools/cvpcb_control.h @@ -0,0 +1,112 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 Ian McInerney + * Copyright (C) 2019 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 CVPCB_CONTROL_H_ +#define CVPCB_CONTROL_H_ + +#include + +#include + + +/** + * Class CVPCB_CONTROL + * + * Handles actions in main cvpcb window. + */ + +class CVPCB_CONTROL : public TOOL_INTERACTIVE +{ +public: + CVPCB_CONTROL(); + ~CVPCB_CONTROL() {} + + /// @copydoc TOOL_INTERACTIVE::Reset() + void Reset( RESET_REASON aReason ) override; + + /** + * Perform automatic footprint association. + * + * @param aEvent is the event generated by the tool framework + */ + int AutoAssociate( const TOOL_EVENT& aEvent ); + + /** + * Delete all associations. + * + * @param aEvent is the event generated by the tool framework + */ + int DeleteAll( const TOOL_EVENT& aEvent ); + + /** + * Move the selected component to the next not associated one. + * + * @param aEvent is the event generated by the tool framework + */ + int ToNextNA( const TOOL_EVENT& aEvent ); + + /** + * Move the selected component to the previous not associated one. + * + * @param aEvent is the event generated by the tool framework + */ + int ToPreviousNA( const TOOL_EVENT& aEvent ); + + /** + * Show the dialog to modify the included footprint association files (.equ) + * + * @param aEvent is the event generated by the tool framework + */ + int ShowEquFileTable( const TOOL_EVENT& aEvent ); + + /** + * Save the associations to the schematic. + * + * @param aEvent is the event generated by the tool framework + */ + int SaveAssociations( const TOOL_EVENT& aEvent ); + + /** + * Create or Update the frame showing the current highlighted footprint + * and (if showed) the 3D display frame. + * + * @param aEvent is the event generated by the tool framework + */ + int ShowFootprintViewer( const TOOL_EVENT& aEvent ); + + /** + * Filter the footprint list by toggling the given filter type. + * The event parameter corresponds to the filter type (using the FP_FILTER_T from the + * FOOTPRINTS_LISTBOX class) + * + * @param aEvent is the event generated by the tool framework + */ + int ToggleFootprintFilter( const TOOL_EVENT& aEvent ); + + /* + * Sets up handlers for various events. + */ + void setTransitions() override; + +private: + CVPCB_MAINFRAME* m_frame; +}; + +#endif