diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 7759ce8ebb..8f6da7c719 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -398,8 +398,6 @@ public: void OnFpChangeDebounceTimer( wxTimerEvent& aEvent ); protected: - void configureToolbars() override; - bool canCloseWindow( wxCloseEvent& aCloseEvent ) override; void handleActivateEvent( wxActivateEvent& aEvent ) override; @@ -435,10 +433,6 @@ protected: PCB_DISPLAY_OPTIONS m_displayOptions; PCB_ORIGIN_TRANSFORMS m_originTransforms; - PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer - - const std::string m_tbPcbLayerSelectorName = "control.PCBLayerSelector"; - private: std::unique_ptr<NL_PCBNEW_PLUGIN> m_spaceMouse; diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 04704fe7b3..3e7234c2d4 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -35,6 +35,7 @@ #include <board_design_settings.h> #include <gal/graphics_abstraction_layer.h> #include <pcb_dimension.h> +#include <pcb_layer_box_selector.h> #include <footprint.h> #include <footprint_info_impl.h> #include <layer_pairs.h> @@ -58,6 +59,7 @@ PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, m_appearancePanel( nullptr ), m_tabbedPanel( nullptr ) { + m_SelLayerBox = nullptr; m_darkMode = KIPLATFORM::UI::IsDarkTheme(); Bind( wxEVT_IDLE, @@ -353,3 +355,57 @@ void PCB_BASE_EDIT_FRAME::GetContextualTextVars( BOARD_ITEM* aSourceItem, const } +void PCB_BASE_EDIT_FRAME::configureToolbars() +{ + // Load the toolbar configuration and base controls + PCB_BASE_FRAME::configureToolbars(); + + // Layer selector + auto layerSelectorFactory = + [this]( ACTION_TOOLBAR* aToolbar ) + { + if( !m_SelLayerBox ) + { + m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( aToolbar, wxID_ANY ); + m_SelLayerBox->SetBoardFrame( this ); + } + + // In the footprint editor, some layers cannot be select (they are shown in the layer + // manager only to set the color and visibility, but not for selection) + // Disable them in layer box + if( IsType( FRAME_FOOTPRINT_EDITOR ) ) + m_SelLayerBox->SetNotAllowedLayerSet( LSET::ForbiddenFootprintLayers() ); + + m_SelLayerBox->SetToolTip( _( "+/- to switch" ) ); + m_SelLayerBox->Resync(); + + aToolbar->Add( m_SelLayerBox ); + + // UI update handler for the control + aToolbar->Bind( wxEVT_UPDATE_UI, + [this]( wxUpdateUIEvent& aEvent ) + { + if( m_SelLayerBox->GetCount() + && ( m_SelLayerBox->GetLayerSelection() != GetActiveLayer() ) ) + { + m_SelLayerBox->SetLayerSelection( GetActiveLayer() ); + } + }, + m_SelLayerBox->GetId() ); + + // Event handler to respond to the user interacting with the control + aToolbar->Bind( wxEVT_COMBOBOX, + [this]( wxCommandEvent& aEvent ) + { + SetActiveLayer( ToLAYER_ID( m_SelLayerBox->GetLayerSelection() ) ); + + if( GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) + GetCanvas()->Refresh(); + }, + m_SelLayerBox->GetId() ); + }; + + RegisterCustomToolbarControlFactory( m_tbPcbLayerSelectorName, _( "Layer selector" ), + _( "Control to select the layer" ), + layerSelectorFactory ); +} \ No newline at end of file diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index bedfbb1e8d..557dd2f835 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -232,6 +232,8 @@ public: wxArrayString* aTokens ); protected: + void configureToolbars() override; + /** * Prompts a user to select global or project library tables * @@ -262,6 +264,9 @@ protected: APPEARANCE_CONTROLS* m_appearancePanel; std::unique_ptr<LAYER_PAIR_SETTINGS> m_layerPairSettings; + PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer + const std::string m_tbPcbLayerSelectorName = "control.PCBLayerSelector"; + wxAuiNotebook* m_tabbedPanel; /// Panel with Layers and Object Inspector tabs bool m_darkMode; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index bd9264d7f6..f182f8acb9 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -54,7 +54,6 @@ #include <project_pcb.h> #include <wildcards_and_files_ext.h> #include <zoom_defines.h> -#include <pcb_layer_box_selector.h> #include <math/vector2d.h> #include <math/vector2wx.h> @@ -84,7 +83,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_pcb( nullptr ), m_originTransforms( *this ) { - m_SelLayerBox = nullptr; m_watcherDebounceTimer.Bind( wxEVT_TIMER, &PCB_BASE_FRAME::OnFpChangeDebounceTimer, this ); } @@ -1270,59 +1268,3 @@ void PCB_BASE_FRAME::OnFpChangeDebounceTimer( wxTimerEvent& aEvent ) } } } - - -void PCB_BASE_FRAME::configureToolbars() -{ - // Load the toolbar configuration and base controls - EDA_DRAW_FRAME::configureToolbars(); - - // Layer selector - auto layerSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelLayerBox ) - { - m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( aToolbar, wxID_ANY ); - m_SelLayerBox->SetBoardFrame( this ); - } - - // In the footprint editor, some layers cannot be select (they are shown in the layer - // manager only to set the color and visibility, but not for selection) - // Disable them in layer box - if( IsType( FRAME_FOOTPRINT_EDITOR ) ) - m_SelLayerBox->SetNotAllowedLayerSet( LSET::ForbiddenFootprintLayers() ); - - m_SelLayerBox->SetToolTip( _( "+/- to switch" ) ); - m_SelLayerBox->Resync(); - - aToolbar->Add( m_SelLayerBox ); - - // UI update handler for the control - aToolbar->Bind( wxEVT_UPDATE_UI, - [this]( wxUpdateUIEvent& aEvent ) - { - if( m_SelLayerBox->GetCount() - && ( m_SelLayerBox->GetLayerSelection() != GetActiveLayer() ) ) - { - m_SelLayerBox->SetLayerSelection( GetActiveLayer() ); - } - }, - m_SelLayerBox->GetId() ); - - // Event handler to respond to the user interacting with the control - aToolbar->Bind( wxEVT_COMBOBOX, - [this]( wxCommandEvent& aEvent ) - { - SetActiveLayer( ToLAYER_ID( m_SelLayerBox->GetLayerSelection() ) ); - - if( GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) - GetCanvas()->Refresh(); - }, - m_SelLayerBox->GetId() ); - }; - - RegisterCustomToolbarControlFactory( m_tbPcbLayerSelectorName, _( "Layer selector" ), - _( "Control to select the layer" ), - layerSelectorFactory ); -} diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index c60ace7006..78fc78ca3f 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -372,7 +372,7 @@ std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_FRAME::DefaultTopAuxToolbarConfig( void PCB_EDIT_FRAME::configureToolbars() { - PCB_BASE_FRAME::configureToolbars(); + PCB_BASE_EDIT_FRAME::configureToolbars(); // Box to display and choose track widths auto trackWidthSelectorFactory =