diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index 70c8a75c67..71ada6e562 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -226,7 +226,7 @@ void EDA_DRAW_FRAME::configureToolbars() [this]( ACTION_TOOLBAR* aToolbar ) { if( !m_overrideLocksCb ) - m_overrideLocksCb = new wxCheckBox( aToolbar, wxID_ANY, _( "Override locks" ) ); + m_overrideLocksCb = new wxCheckBox( aToolbar, ID_ON_OVERRIDE_LOCKS, _( "Override locks" ) ); aToolbar->Add( m_overrideLocksCb ); }; @@ -239,8 +239,9 @@ void EDA_DRAW_FRAME::ClearToolbarControl( int aId ) { switch( aId ) { - case ID_ON_GRID_SELECT: m_gridSelectBox = nullptr; break; - case ID_ON_ZOOM_SELECT: m_zoomSelectBox = nullptr; break; + case ID_ON_GRID_SELECT: m_gridSelectBox = nullptr; break; + case ID_ON_ZOOM_SELECT: m_zoomSelectBox = nullptr; break; + case ID_ON_OVERRIDE_LOCKS: m_overrideLocksCb = nullptr; break; } } diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index 2931f0adf4..88b0fc8b35 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -249,6 +249,20 @@ ACTION_TOOLBAR::~ACTION_TOOLBAR() } +std::list ACTION_TOOLBAR::GetCustomControlList( FRAME_T aContext ) +{ + std::list controls; + + for( ACTION_TOOLBAR_CONTROL* control : GetAllCustomControls() ) + { + if( control->SupportedFor( aContext ) ) + controls.push_back( control ); + } + + return controls; +} + + void ACTION_TOOLBAR::ApplyConfiguration( const TOOLBAR_CONFIGURATION& aConfig ) { wxASSERT( GetParent() ); @@ -1055,24 +1069,58 @@ void ACTION_TOOLBAR::RefreshBitmaps() /* * Common controls for the toolbar */ -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::gridSelect( "control.GridSelector", _( "Grid Selector" ), - _( "Grid Selection box" ) ); +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::gridSelect( "control.GridSelector", + _( "Grid selector" ), + _( "Grid Selection box" ), + { FRAME_SCH, + FRAME_SCH_SYMBOL_EDITOR, + FRAME_SCH_VIEWER, + FRAME_PCB_EDITOR, + FRAME_FOOTPRINT_EDITOR, + FRAME_FOOTPRINT_VIEWER, + FRAME_GERBER, + FRAME_PL_EDITOR } ); -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::zoomSelect( "control.ZoomSelector", _( "Zoom Selector" ), - _( "Zoom Selection box" ) ); -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::ipcScripting( "control.IPCPlugin", _( "IPC/Scripting plugins" ), - _( "Region to hold the IPC/Scripting action buttons" ) ); +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::zoomSelect( "control.ZoomSelector", + _( "Zoom selector" ), + _( "Zoom Selection box" ), + { FRAME_SCH, + FRAME_SCH_SYMBOL_EDITOR, + FRAME_SCH_VIEWER, + FRAME_PCB_EDITOR, + FRAME_FOOTPRINT_EDITOR, + FRAME_FOOTPRINT_VIEWER, + FRAME_GERBER, + FRAME_PL_EDITOR } ); -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::layerSelector( "control.LayerSelector", _( "Layer selector" ), - _( "Control to select the layer" ) ); +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::ipcScripting( "control.IPCPlugin", + _( "IPC/Scripting plugins" ), + _( "Region to hold the IPC/Scripting action buttons" ), + { FRAME_SCH, + FRAME_PCB_EDITOR } ); -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::unitSelector( "control.UnitSelector", _( "Symbol unit selector" ), - _( "Displays the current unit" ) ); +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::layerSelector( "control.LayerSelector", + _( "Layer selector" ), + _( "Control to select the layer" ), + { FRAME_PCB_EDITOR, + FRAME_FOOTPRINT_EDITOR, + FRAME_FOOTPRINT_VIEWER, + FRAME_GERBER } ); + +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::unitSelector( "control.UnitSelector", + _( "Symbol unit selector" ), + _( "Displays the current unit" ), + { FRAME_SCH_SYMBOL_EDITOR, + FRAME_SCH_VIEWER } ); ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::bodyStyleSelector( "control.BodyStyleSelector", _( "Symbol body style selector" ), - _( "Displays the current body style" ) ); + _( "Displays the current body style" ), + { FRAME_SCH_SYMBOL_EDITOR, + FRAME_SCH_VIEWER } ); -ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::overrideLocks( "control.OverrideLocks", _( "Override locks" ), - _( "Allow moving of locked items with the mouse" ) ); \ No newline at end of file +ACTION_TOOLBAR_CONTROL ACTION_TOOLBAR_CONTROLS::overrideLocks( "control.OverrideLocks", + _( "Override locks" ), + _( "Allow moving of locked items with the mouse" ), + { FRAME_PCB_EDITOR } ); \ No newline at end of file diff --git a/cvpcb/toolbars_cvpcb.cpp b/cvpcb/toolbars_cvpcb.cpp index bc1e920539..da6f15e601 100644 --- a/cvpcb/toolbars_cvpcb.cpp +++ b/cvpcb/toolbars_cvpcb.cpp @@ -119,5 +119,7 @@ void CVPCB_MAINFRAME::configureToolbars() } -ACTION_TOOLBAR_CONTROL CVPCB_ACTION_TOOLBAR_CONTROLS::footprintFilter( "control.FootprintFilters", _( "Footprint filters" ), - _( "Footprint filtering controls" ) ); +ACTION_TOOLBAR_CONTROL CVPCB_ACTION_TOOLBAR_CONTROLS::footprintFilter( "control.FootprintFilters", + _( "Footprint filters" ), + _( "Footprint filtering controls" ), + { FRAME_CVPCB } ); diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index dcff9618e2..3e915c969d 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -283,7 +283,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_SCH_SYMBOL_EDITOR ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); @@ -339,7 +339,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_SCH ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 2115c82feb..eca7edcc30 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -887,6 +887,8 @@ public: return PLUGIN_ACTION_SCOPE::SCHEMATIC; } + void ClearToolbarControl( int aId ) override; + DECLARE_EVENT_TABLE() protected: diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index b3e810b279..51c5f6f10d 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -405,6 +405,8 @@ public: ///< Restore the empty editor screen, without any symbol or library selected. void emptyScreen(); + void ClearToolbarControl( int aId ) override; + protected: void configureToolbars() override; void setupUIConditions() override; diff --git a/eeschema/symbol_editor/toolbars_symbol_editor.cpp b/eeschema/symbol_editor/toolbars_symbol_editor.cpp index 66d3e2d3a4..63123dd919 100644 --- a/eeschema/symbol_editor/toolbars_symbol_editor.cpp +++ b/eeschema/symbol_editor/toolbars_symbol_editor.cpp @@ -169,34 +169,47 @@ void SYMBOL_EDIT_FRAME::configureToolbars() SCH_BASE_FRAME::configureToolbars(); auto unitDisplayFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_unitSelectBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_unitSelectBox = new wxComboBox( aToolbar, ID_LIBEDIT_SELECT_UNIT_NUMBER, - wxEmptyString, wxDefaultPosition, - wxSize( LISTBOX_WIDTH, -1 ), 0, - nullptr, wxCB_READONLY ); - } + if( !m_unitSelectBox ) + { + m_unitSelectBox = new wxComboBox( aToolbar, ID_LIBEDIT_SELECT_UNIT_NUMBER, + wxEmptyString, wxDefaultPosition, + wxSize( LISTBOX_WIDTH, -1 ), 0, + nullptr, wxCB_READONLY ); + } - aToolbar->Add( m_unitSelectBox ); - }; + aToolbar->Add( m_unitSelectBox ); + }; auto bodyDisplayFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_bodyStyleSelectBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_bodyStyleSelectBox = new wxComboBox( aToolbar, ID_LIBEDIT_SELECT_BODY_STYLE, - wxEmptyString, wxDefaultPosition, - wxSize( LISTBOX_WIDTH, -1 ), 0, - nullptr, wxCB_READONLY ); - } + if( !m_bodyStyleSelectBox ) + { + m_bodyStyleSelectBox = new wxComboBox( aToolbar, ID_LIBEDIT_SELECT_BODY_STYLE, + wxEmptyString, wxDefaultPosition, + wxSize( LISTBOX_WIDTH, -1 ), 0, + nullptr, wxCB_READONLY ); + } - aToolbar->Add( m_bodyStyleSelectBox ); - }; + aToolbar->Add( m_bodyStyleSelectBox ); + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::unitSelector, unitDisplayFactory ); RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::bodyStyleSelector, bodyDisplayFactory ); } + +void SYMBOL_EDIT_FRAME::ClearToolbarControl( int aId ) +{ + SCH_BASE_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_LIBEDIT_SELECT_UNIT_NUMBER: m_unitSelectBox = nullptr; break; + case ID_LIBEDIT_SELECT_BODY_STYLE: m_bodyStyleSelectBox = nullptr; break; + } +} + + diff --git a/eeschema/symbol_viewer_frame.h b/eeschema/symbol_viewer_frame.h index 49688b784d..4d2d5dcf06 100644 --- a/eeschema/symbol_viewer_frame.h +++ b/eeschema/symbol_viewer_frame.h @@ -116,6 +116,8 @@ public: void KiwayMailIn( KIWAY_EXPRESS& mail ) override; + void ClearToolbarControl( int aId ) override; + protected: void configureToolbars() override; diff --git a/eeschema/toolbars_sch_editor.cpp b/eeschema/toolbars_sch_editor.cpp index 600f4379bc..d79643cb07 100644 --- a/eeschema/toolbars_sch_editor.cpp +++ b/eeschema/toolbars_sch_editor.cpp @@ -46,10 +46,10 @@ #include -ACTION_TOOLBAR_CONTROL SCH_ACTION_TOOLBAR_CONTROLS::currentVariant( - "control.currentVariant", - _( "Current Variant" ), - _( "Control to select the current schematic variant" ) ); +ACTION_TOOLBAR_CONTROL SCH_ACTION_TOOLBAR_CONTROLS::currentVariant( "control.currentVariant", + _( "Current variant" ), + _( "Selects the current schematic variant" ), + { FRAME_SCH } ); std::optional SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar ) @@ -227,19 +227,19 @@ void SCH_EDIT_FRAME::configureToolbars() { // Variant selection drop down control on main tool bar. auto variantSelectionCtrlFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - std::optional currentVariantName = Schematic().GetCurrentVariant(); - wxString tmp = currentVariantName ? *currentVariantName : GetDefaultVariantName(); + [this]( ACTION_TOOLBAR* aToolbar ) + { + std::optional currentVariantName = Schematic().GetCurrentVariant(); + wxString tmp = currentVariantName ? *currentVariantName : GetDefaultVariantName(); - m_currentVariantCtrl = new wxChoice( aToolbar, ID_TOOLBAR_SCH_SELECT_VARAIANT, wxDefaultPosition, - wxDefaultSize, Schematic().GetVariantNamesForUI(), 0, - wxDefaultValidator, tmp ); + m_currentVariantCtrl = new wxChoice( aToolbar, ID_TOOLBAR_SCH_SELECT_VARAIANT, wxDefaultPosition, + wxDefaultSize, Schematic().GetVariantNamesForUI(), 0, + wxDefaultValidator, tmp ); - m_currentVariantCtrl->SetToolTip( _( "Select the current variant to display and edit." ) ); - aToolbar->Add( m_currentVariantCtrl ); - UpdateVariantSelectionCtrl( Schematic().GetVariantNamesForUI() ); - }; + m_currentVariantCtrl->SetToolTip( _( "Select the current variant to display and edit." ) ); + aToolbar->Add( m_currentVariantCtrl ); + UpdateVariantSelectionCtrl( Schematic().GetVariantNamesForUI() ); + }; RegisterCustomToolbarControlFactory( SCH_ACTION_TOOLBAR_CONTROLS::currentVariant, variantSelectionCtrlFactory ); } @@ -248,31 +248,42 @@ void SCH_EDIT_FRAME::configureToolbars() // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire // control auto pluginControlFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - // Add scripting console and API plugins - bool scriptingAvailable = SCRIPTING::IsWxAvailable(); - - #ifdef KICAD_IPC_API - bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server && - !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty(); - #else - bool haveApiPlugins = false; - #endif - - if( scriptingAvailable || haveApiPlugins ) + [this]( ACTION_TOOLBAR* aToolbar ) { - aToolbar->AddScaledSeparator( aToolbar->GetParent() ); + // Add scripting console and API plugins + bool scriptingAvailable = SCRIPTING::IsWxAvailable(); - if( haveApiPlugins ) - AddApiPluginTools( aToolbar ); - } - }; +#ifdef KICAD_IPC_API + bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server + && !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty(); +#else + bool haveApiPlugins = false; +#endif + + if( scriptingAvailable || haveApiPlugins ) + { + aToolbar->AddScaledSeparator( aToolbar->GetParent() ); + + if( haveApiPlugins ) + AddApiPluginTools( aToolbar ); + } + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory ); } +void SCH_EDIT_FRAME::ClearToolbarControl( int aId ) +{ + SCH_BASE_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_TOOLBAR_SCH_SELECT_VARAIANT: m_currentVariantCtrl = nullptr; break; + } +} + + void SCH_EDIT_FRAME::UpdateVariantSelectionCtrl( const wxArrayString& aVariantNames ) { if( !m_currentVariantCtrl ) diff --git a/eeschema/toolbars_symbol_viewer.cpp b/eeschema/toolbars_symbol_viewer.cpp index 30b238ca8b..51ee2f1668 100644 --- a/eeschema/toolbars_symbol_viewer.cpp +++ b/eeschema/toolbars_symbol_viewer.cpp @@ -91,34 +91,46 @@ void SYMBOL_VIEWER_FRAME::configureToolbars() // Toolbar widget for selecting the unit to show in the symbol viewer auto unitChoiceFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_unitChoice ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_unitChoice = new wxChoice( m_tbTopMain, ID_LIBVIEW_SELECT_UNIT_NUMBER, - wxDefaultPosition, wxSize( 150, -1 ) ); - } + if( !m_unitChoice ) + { + m_unitChoice = new wxChoice( m_tbTopMain, ID_LIBVIEW_SELECT_UNIT_NUMBER, + wxDefaultPosition, wxSize( 150, -1 ) ); + } - aToolbar->Add( m_unitChoice ); - }; + aToolbar->Add( m_unitChoice ); + }; auto bodyChoiceFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_bodyStyleChoice ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_bodyStyleChoice = new wxChoice( m_tbTopMain, ID_LIBVIEW_SELECT_BODY_STYLE, - wxDefaultPosition, wxSize( 150, -1 ) ); - } + if( !m_bodyStyleChoice ) + { + m_bodyStyleChoice = new wxChoice( m_tbTopMain, ID_LIBVIEW_SELECT_BODY_STYLE, + wxDefaultPosition, wxSize( 150, -1 ) ); + } - aToolbar->Add( m_bodyStyleChoice ); - }; + aToolbar->Add( m_bodyStyleChoice ); + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::unitSelector, unitChoiceFactory ); RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::bodyStyleSelector, bodyChoiceFactory ); } +void SYMBOL_VIEWER_FRAME::ClearToolbarControl( int aId ) +{ + SCH_BASE_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_LIBVIEW_SELECT_UNIT_NUMBER: m_unitChoice = nullptr; break; + case ID_LIBVIEW_SELECT_BODY_STYLE: m_bodyStyleChoice = nullptr; break; + } +} + + void SYMBOL_VIEWER_FRAME::doReCreateMenuBar() { SYMBOL_EDITOR_CONTROL* libControl = m_toolManager->GetTool(); diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index d11fbb6ce5..ddd73e4410 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -104,7 +104,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_GERBER ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 1288662293..f3ef802de5 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -446,6 +446,8 @@ public: return m_gerberLayout->ViewBBox(); } + void ClearToolbarControl( int aId ) override; + DECLARE_EVENT_TABLE() protected: diff --git a/gerbview/toolbars_gerber.cpp b/gerbview/toolbars_gerber.cpp index 98a77b9795..b7e1225049 100644 --- a/gerbview/toolbars_gerber.cpp +++ b/gerbview/toolbars_gerber.cpp @@ -130,45 +130,44 @@ void GERBVIEW_FRAME::configureToolbars() // Register factories for the various toolbar controls auto layerBoxFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelLayerBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( aToolbar, - ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, - wxDefaultPosition, wxDefaultSize, 0, nullptr ); - } + if( !m_SelLayerBox ) + { + m_SelLayerBox = new GBR_LAYER_BOX_SELECTOR( aToolbar, ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, + wxDefaultPosition, wxDefaultSize, 0, nullptr ); + } - m_SelLayerBox->Resync(); - aToolbar->Add( m_SelLayerBox ); + 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() ) + // UI update handler for the control + aToolbar->Bind( wxEVT_UPDATE_UI, + [this]( wxUpdateUIEvent& aEvent ) { - if( m_SelLayerBox->GetSelection() != GetActiveLayer() ) - m_SelLayerBox->SetSelection( GetActiveLayer() ); - } - }, - m_SelLayerBox->GetId() ); - }; + if( m_SelLayerBox->GetCount() ) + { + if( m_SelLayerBox->GetSelection() != GetActiveLayer() ) + m_SelLayerBox->SetSelection( GetActiveLayer() ); + } + }, + m_SelLayerBox->GetId() ); + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::layerSelector, layerBoxFactory ); auto textInfoFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_TextInfo ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString, - wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); - } + if( !m_TextInfo ) + { + m_TextInfo = new wxTextCtrl( aToolbar, ID_TOOLBARH_GERBER_DATA_TEXT_BOX, wxEmptyString, + wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + } - aToolbar->Add( m_TextInfo ); - }; + aToolbar->Add( m_TextInfo ); + }; RegisterCustomToolbarControlFactory( GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo, textInfoFactory ); @@ -177,112 +176,134 @@ void GERBVIEW_FRAME::configureToolbars() // (note, when the m_tbTopAux is recreated, tools are deleted, but controls // are not deleted: they are just no longer managed by the toolbar auto componentBoxFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelComponentBox ) - m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE ); + [this]( ACTION_TOOLBAR* aToolbar ) + { + if( !m_SelComponentBox ) + m_SelComponentBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE ); - if( !m_cmpText ) - m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) ); + if( !m_cmpText ) + m_cmpText = new wxStaticText( aToolbar, wxID_ANY, _( "Cmp:" ) + wxS( " " ) ); - m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") ); - m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language + m_SelComponentBox->SetToolTip( _("Highlight items belonging to this component") ); + m_cmpText->SetLabel( _( "Cmp:" ) + wxS( " " ) ); // can change when changing the language - updateComponentListSelectBox(); + updateComponentListSelectBox(); - aToolbar->Add( m_cmpText ); - aToolbar->Add( m_SelComponentBox ); - }; + aToolbar->Add( m_cmpText ); + aToolbar->Add( m_SelComponentBox ); + }; RegisterCustomToolbarControlFactory( GERBVIEW_ACTION_TOOLBAR_CONTROLS::componentHighlight, componentBoxFactory ); // Creates choice box to display net names and highlight selected: auto netBoxFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelNetnameBox ) - m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE ); + [this]( ACTION_TOOLBAR* aToolbar ) + { + if( !m_SelNetnameBox ) + m_SelNetnameBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE ); - if( !m_netText ) - m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) ); + if( !m_netText ) + m_netText = new wxStaticText( aToolbar, wxID_ANY, _( "Net:" ) ); - m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") ); - m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language + m_SelNetnameBox->SetToolTip( _("Highlight items belonging to this net") ); + m_netText->SetLabel( _( "Net:" ) ); // can change when changing the language - updateNetnameListSelectBox(); + updateNetnameListSelectBox(); - aToolbar->Add( m_netText ); - aToolbar->Add( m_SelNetnameBox ); - }; + aToolbar->Add( m_netText ); + aToolbar->Add( m_SelNetnameBox ); + }; RegisterCustomToolbarControlFactory( GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight, netBoxFactory ); // Creates choice box to display aperture attributes and highlight selected: auto appertureBoxFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelAperAttributesBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_SelAperAttributesBox = new wxChoice( aToolbar, - ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE ); - } + if( !m_SelAperAttributesBox ) + m_SelAperAttributesBox = new wxChoice( aToolbar, ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE ); - if( !m_apertText ) - m_apertText = new wxStaticText( aToolbar, wxID_ANY, _( "Attr:" ) ); + if( !m_apertText ) + m_apertText = new wxStaticText( aToolbar, wxID_ANY, _( "Attr:" ) ); - m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) ); - m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language + m_SelAperAttributesBox->SetToolTip( _( "Highlight items with this aperture attribute" ) ); + m_apertText->SetLabel( _( "Attr:" ) ); // can change when changing the language - updateAperAttributesSelectBox(); + updateAperAttributesSelectBox(); - aToolbar->Add( m_apertText ); - aToolbar->Add( m_SelAperAttributesBox ); - }; + aToolbar->Add( m_apertText ); + aToolbar->Add( m_SelAperAttributesBox ); + }; RegisterCustomToolbarControlFactory( GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight, appertureBoxFactory ); // D-code selection auto dcodeSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_DCodeSelector ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_DCodeSelector = new DCODE_SELECTION_BOX( aToolbar, - ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, - wxDefaultPosition, wxSize( 150, -1 ) ); - } + if( !m_DCodeSelector ) + { + m_DCodeSelector = new DCODE_SELECTION_BOX( aToolbar, ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, + wxDefaultPosition, wxSize( 150, -1 ) ); + } - if( !m_dcodeText ) - m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) ); + if( !m_dcodeText ) + m_dcodeText = new wxStaticText( aToolbar, wxID_ANY, _( "DCode:" ) ); - m_dcodeText->SetLabel( _( "DCode:" ) ); + m_dcodeText->SetLabel( _( "DCode:" ) ); - updateDCodeSelectBox(); + updateDCodeSelectBox(); - aToolbar->Add( m_dcodeText ); - aToolbar->Add( m_DCodeSelector ); - }; + aToolbar->Add( m_dcodeText ); + aToolbar->Add( m_DCodeSelector ); + }; RegisterCustomToolbarControlFactory( GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector, dcodeSelectorFactory ); } -ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo( "control.TextInfo", _( "Text info entry" ), - _( "Text info entry" ) ); + +void GERBVIEW_FRAME::ClearToolbarControl( int aId ) +{ + EDA_DRAW_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER: m_SelLayerBox = nullptr; break; + case ID_TOOLBARH_GERBER_DATA_TEXT_BOX: m_TextInfo = nullptr; break; + case ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE: m_SelComponentBox = nullptr; break; + case ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE: m_SelNetnameBox = nullptr; break; + case ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE: m_SelAperAttributesBox = nullptr; break; + case ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE: m_DCodeSelector = nullptr; break; + } +} + + +ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::textInfo( "control.TextInfo", + _( "Text info entry" ), + _( "Text info entry" ), + { FRAME_GERBER } ); ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::componentHighlight( "control.ComponentHighlight", _( "Component highlight" ), - _( "Highlight items belonging to this component" ) ); -ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight( "control.NetHighlight", _( "Net highlight" ), - _( "Highlight items belonging to this net" ) ); -ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight( "control.AppertureHighlight", _( "Aperture highlight" ), - _( "Highlight items with this aperture attribute" )); -ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector( "control.GerberDcodeSelector", _( "DCode Selector" ), - _( "Select all items with the selected DCode" ) ); + _( "Highlight items belonging to this component" ), + { FRAME_GERBER } ); +ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::netHighlight( "control.NetHighlight", + _( "Net highlight" ), + _( "Highlight items belonging to this net" ), + { FRAME_GERBER } ); +ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::appertureHighlight( "control.AppertureHighlight", + _( "Aperture highlight" ), + _( "Highlight items with this aperture attribute" ), + { FRAME_GERBER } ); +ACTION_TOOLBAR_CONTROL GERBVIEW_ACTION_TOOLBAR_CONTROLS::dcodeSelector( "control.GerberDcodeSelector", + _( "DCode selector" ), + _( "Select all items with the selected DCode" ), + { FRAME_GERBER } ); -#define NO_SELECTION_STRING _("") +#define NO_SELECTION_STRING _( "" ) void GERBVIEW_FRAME::updateDCodeSelectBox() diff --git a/include/id.h b/include/id.h index 49f19d7771..aa53adb610 100644 --- a/include/id.h +++ b/include/id.h @@ -110,8 +110,9 @@ enum main_id ID_LANGUAGE_CHOICE_END, ID_ON_ZOOM_SELECT, - ID_ON_GRID_SELECT, + ID_ON_OVERRIDE_LOCKS, + ID_ON_LAYER_SELECT, // Popup Menu (mouse Right button) (id consecutifs) diff --git a/include/tool/action_toolbar.h b/include/tool/action_toolbar.h index 1dd118b1a7..b0ddc06182 100644 --- a/include/tool/action_toolbar.h +++ b/include/tool/action_toolbar.h @@ -21,8 +21,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef ACTION_TOOLBAR_H -#define ACTION_TOOLBAR_H +#pragma once #include #include @@ -33,6 +32,7 @@ #include #include #include +#include class ACTION_MENU; class BITMAP_BUTTON; @@ -351,12 +351,17 @@ public: /** * Get the list of custom controls that could be used on toolbars. */ - static std::list& GetCustomControlList() + static std::list& GetAllCustomControls() { static std::list m_controls; return m_controls; } + /** + * Get the list of custom controls that could be used on a particular frame type. + */ + static std::list GetCustomControlList( FRAME_T aContext ); + static constexpr bool TOGGLE = true; static constexpr bool CANCEL = true; @@ -435,21 +440,33 @@ class ACTION_TOOLBAR_CONTROL { public: ACTION_TOOLBAR_CONTROL( const std::string& aName, const wxString& aUiName, - const wxString& aDescription ) : + const wxString& aDescription, std::vector aSupportedContexts ) : m_name( aName ), m_uiname( aUiName ), - m_description( aDescription ) + m_description( aDescription ), + m_supportedContexts( aSupportedContexts ) { wxASSERT_MSG( aName.starts_with( "control" ), wxString::Format( "Control name \"%s\" must start with \"control\"", aName ) ); - ACTION_TOOLBAR::GetCustomControlList().push_back( this ); + ACTION_TOOLBAR::GetAllCustomControls().push_back( this ); } const std::string& GetName() const { return m_name; } const wxString& GetUiName() const { return m_uiname; } const wxString& GetDescription() const { return m_description; } + bool SupportedFor( FRAME_T aFrame ) const + { + for( FRAME_T candidate : m_supportedContexts ) + { + if( aFrame == candidate ) + return true; + } + + return false; + } + protected: /** * Name of the control - must start with "control." @@ -465,6 +482,11 @@ protected: * User-visible tooltip for the control */ wxString m_description; + + /** + * List of frame types that support the control. + */ + std::vector m_supportedContexts; }; class ACTION_TOOLBAR_CONTROLS @@ -478,5 +500,3 @@ public: static ACTION_TOOLBAR_CONTROL layerSelector; static ACTION_TOOLBAR_CONTROL overrideLocks; }; - -#endif diff --git a/pagelayout_editor/pl_editor.cpp b/pagelayout_editor/pl_editor.cpp index 62f58384c6..f50615bb6a 100644 --- a/pagelayout_editor/pl_editor.cpp +++ b/pagelayout_editor/pl_editor.cpp @@ -93,7 +93,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_PL_EDITOR ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index c56654a180..26ad82d0c6 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -240,6 +240,8 @@ public: void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override; + void ClearToolbarControl( int aId ) override; + protected: bool saveCurrentPageLayout(); diff --git a/pagelayout_editor/toolbars_pl_editor.cpp b/pagelayout_editor/toolbars_pl_editor.cpp index 8cc37c7aac..5242b2f4bd 100644 --- a/pagelayout_editor/toolbars_pl_editor.cpp +++ b/pagelayout_editor/toolbars_pl_editor.cpp @@ -115,53 +115,69 @@ void PL_EDITOR_FRAME::configureToolbars() EDA_DRAW_FRAME::configureToolbars(); auto originSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_originSelectBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN, - wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList ); - } + if( !m_originSelectBox ) + { + m_originSelectBox = new wxChoice( aToolbar, ID_SELECT_COORDINATE_ORIGIN, + wxDefaultPosition, wxDefaultSize, 5, m_originChoiceList ); + } - m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") ); - m_originSelectBox->SetSelection( m_originSelectChoice ); + m_originSelectBox->SetToolTip( _("Origin of coordinates displayed to the status bar") ); + m_originSelectBox->SetSelection( m_originSelectChoice ); - aToolbar->Add( m_originSelectBox ); - }; + aToolbar->Add( m_originSelectBox ); + }; RegisterCustomToolbarControlFactory( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector, originSelectorFactory ); auto pageSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - wxString pageList[5] = + [this]( ACTION_TOOLBAR* aToolbar ) { - _("Page 1"), - _("Other pages") + wxString pageList[5] = + { + _("Page 1"), + _("Other pages") + }; + + if( !m_pageSelectBox ) + { + m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER, + wxDefaultPosition, wxDefaultSize, 2, pageList ); + } + + m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\ + "which are not on all page are displayed") ); + m_pageSelectBox->SetSelection( 0 ); + + aToolbar->Add( m_pageSelectBox ); }; - if( !m_pageSelectBox ) - { - m_pageSelectBox = new wxChoice( aToolbar, ID_SELECT_PAGE_NUMBER, - wxDefaultPosition, wxDefaultSize, 2, pageList ); - } - - m_pageSelectBox->SetToolTip( _("Simulate page 1 or other pages to show how items\n"\ - "which are not on all page are displayed") ); - m_pageSelectBox->SetSelection( 0 ); - - aToolbar->Add( m_pageSelectBox ); - }; - RegisterCustomToolbarControlFactory( PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect, pageSelectorFactory ); } -ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector( "control.OriginSelector", _( "Origin Selector" ), - _( "Select the origin of the status bar coordinates" ) ); -ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect( "control.PageSelect", _( "Page Selector" ), - _( "Select the page to simulate item displays" )); +void PL_EDITOR_FRAME::ClearToolbarControl( int aId ) +{ + EDA_DRAW_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_SELECT_COORDINATE_ORIGIN: m_originSelectBox = nullptr; break; + case ID_SELECT_PAGE_NUMBER: m_pageSelectBox = nullptr; break; + } +} + + +ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::originSelector( "control.OriginSelector", + _( "Origin selector" ), + _( "Select the origin of the status bar coordinates" ), + { FRAME_PL_EDITOR } ); +ACTION_TOOLBAR_CONTROL PL_EDITOR_ACTION_TOOLBAR_CONTROLS::pageSelect( "control.PageSelect", + _( "Page selector" ), + _( "Select the page to simulate item displays" ), + { FRAME_PL_EDITOR } ); diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 083cdd71da..22a8244836 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -52,6 +52,7 @@ #include #include +#include PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, @@ -380,47 +381,58 @@ void PCB_BASE_EDIT_FRAME::configureToolbars() // Layer selector auto layerSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelLayerBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( aToolbar, wxID_ANY ); - m_SelLayerBox->SetBoardFrame( this ); - } + if( !m_SelLayerBox ) + { + m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( aToolbar, ID_ON_LAYER_SELECT ); + m_SelLayerBox->SetBoardFrame( this ); + } - m_SelLayerBox->SetToolTip( _( "+/- to switch" ) ); - m_SelLayerBox->Resync(); + m_SelLayerBox->SetToolTip( _( "+/- to switch" ) ); + m_SelLayerBox->Resync(); - aToolbar->Add( m_SelLayerBox ); + 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() ) ) + // UI update handler for the control + aToolbar->Bind( wxEVT_UPDATE_UI, + [this]( wxUpdateUIEvent& aEvent ) { - m_SelLayerBox->SetLayerSelection( GetActiveLayer() ); - } - }, - m_SelLayerBox->GetId() ); + 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() ) ); + // 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() ); - }; + if( GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL ) + GetCanvas()->Refresh(); + }, + m_SelLayerBox->GetId() ); + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::layerSelector, layerSelectorFactory ); } +void PCB_BASE_EDIT_FRAME::ClearToolbarControl( int aId ) +{ + PCB_BASE_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_ON_LAYER_SELECT: m_SelLayerBox = nullptr; break; + } +} + + void PCB_BASE_EDIT_FRAME::HighlightSelectionFilter( const PCB_SELECTION_FILTER_OPTIONS& aOptions ) { PCB_SELECTION_FILTER_EVENT evt( aOptions ); diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index d14371a409..9278aaeeda 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -255,6 +255,8 @@ public: void HighlightSelectionFilter( const PCB_SELECTION_FILTER_OPTIONS& aOptions ); + void ClearToolbarControl( int aId ) override; + protected: void configureToolbars() override; diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 871a45f9bb..386396fb34 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -690,6 +690,8 @@ public: */ bool DoAutoSave(); + void ClearToolbarControl( int aId ) override; + DECLARE_EVENT_TABLE() protected: diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index e62513e2ba..b38c593b61 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -236,7 +236,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_FOOTPRINT_EDITOR ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); @@ -307,7 +307,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_PCB_EDITOR ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); @@ -336,7 +336,7 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER for( TOOL_ACTION* action : ACTION_MANAGER::GetActionList() ) actions.push_back( action ); - for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList() ) + for( ACTION_TOOLBAR_CONTROL* control : ACTION_TOOLBAR::GetCustomControlList( FRAME_PCB_DISPLAY3D ) ) controls.push_back( control ); return new PANEL_TOOLBAR_CUSTOMIZATION( aParent, cfg, tb, actions, controls ); diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp index e9dbd7fe8a..6b8678b811 100644 --- a/pcbnew/toolbars_pcb_editor.cpp +++ b/pcbnew/toolbars_pcb_editor.cpp @@ -120,10 +120,14 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild ) } -ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::trackWidth( "control.PCBTrackWidth", _( "Track width selector" ), - _( "Control to select the track width" ) ); -ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter( "control.PCBViaDia", _( "Via diameter selector" ), - _( "Control to select the via diameter" ) ); +ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::trackWidth( "control.PCBTrackWidth", + _( "Track width selector" ), + _( "Control to select the track width" ), + { FRAME_PCB_EDITOR } ); +ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter( "control.PCBViaDia", + _( "Via diameter selector" ), + _( "Control to select the via diameter" ), + { FRAME_PCB_EDITOR } ); std::optional PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar ) @@ -380,40 +384,40 @@ void PCB_EDIT_FRAME::configureToolbars() // Box to display and choose track widths auto trackWidthSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelTrackWidthBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_SelTrackWidthBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, - wxDefaultPosition, wxDefaultSize, 0, nullptr ); - } + if( !m_SelTrackWidthBox ) + { + m_SelTrackWidthBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH, + wxDefaultPosition, wxDefaultSize, 0, nullptr ); + } - m_SelTrackWidthBox->SetToolTip( _( "Select the default width for new tracks. Note that this " - "width can be overridden by the board minimum width, or by " - "the width of an existing track if the 'Use Existing Track " - "Width' feature is enabled." ) ); + m_SelTrackWidthBox->SetToolTip( _( "Select the default width for new tracks. Note that this " + "width can be overridden by the board minimum width, or by " + "the width of an existing track if the 'Use Existing Track " + "Width' feature is enabled." ) ); - UpdateTrackWidthSelectBox( m_SelTrackWidthBox, true, true ); + UpdateTrackWidthSelectBox( m_SelTrackWidthBox, true, true ); - aToolbar->Add( m_SelTrackWidthBox ); - }; + aToolbar->Add( m_SelTrackWidthBox ); + }; RegisterCustomToolbarControlFactory( PCB_ACTION_TOOLBAR_CONTROLS::trackWidth, trackWidthSelectorFactory ); // Box to display and choose vias diameters auto viaDiaSelectorFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - if( !m_SelViaSizeBox ) + [this]( ACTION_TOOLBAR* aToolbar ) { - m_SelViaSizeBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_VIA_SIZE, - wxDefaultPosition, wxDefaultSize, 0, nullptr ); - } + if( !m_SelViaSizeBox ) + { + m_SelViaSizeBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_VIA_SIZE, + wxDefaultPosition, wxDefaultSize, 0, nullptr ); + } - UpdateViaSizeSelectBox( m_SelViaSizeBox, true, true ); - aToolbar->Add( m_SelViaSizeBox ); - }; + UpdateViaSizeSelectBox( m_SelViaSizeBox, true, true ); + aToolbar->Add( m_SelViaSizeBox ); + }; RegisterCustomToolbarControlFactory( PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter, viaDiaSelectorFactory ); @@ -421,37 +425,49 @@ void PCB_EDIT_FRAME::configureToolbars() // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire // control auto pluginControlFactory = - [this]( ACTION_TOOLBAR* aToolbar ) - { - // Add scripting console and API plugins - bool scriptingAvailable = SCRIPTING::IsWxAvailable(); - - #ifdef KICAD_IPC_API - bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server && - !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty(); - #else - bool haveApiPlugins = false; - #endif - - if( scriptingAvailable || haveApiPlugins ) + [this]( ACTION_TOOLBAR* aToolbar ) { - aToolbar->AddScaledSeparator( aToolbar->GetParent() ); + // Add scripting console and API plugins + bool scriptingAvailable = SCRIPTING::IsWxAvailable(); - if( scriptingAvailable ) +#ifdef KICAD_IPC_API + bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server + && !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty(); +#else + bool haveApiPlugins = false; +#endif + + if( scriptingAvailable || haveApiPlugins ) { - aToolbar->Add( PCB_ACTIONS::showPythonConsole ); - addActionPluginTools( aToolbar ); - } + aToolbar->AddScaledSeparator( aToolbar->GetParent() ); - if( haveApiPlugins ) - AddApiPluginTools( aToolbar ); - } - }; + if( scriptingAvailable ) + { + aToolbar->Add( PCB_ACTIONS::showPythonConsole ); + addActionPluginTools( aToolbar ); + } + + if( haveApiPlugins ) + AddApiPluginTools( aToolbar ); + } + }; RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory ); } +void PCB_EDIT_FRAME::ClearToolbarControl( int aId ) +{ + PCB_BASE_EDIT_FRAME::ClearToolbarControl( aId ); + + switch( aId ) + { + case ID_AUX_TOOLBAR_PCB_TRACK_WIDTH: m_SelTrackWidthBox = nullptr; break; + case ID_AUX_TOOLBAR_PCB_VIA_SIZE: m_SelViaSizeBox = nullptr; break; + } +} + + static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLabel = true ) { wxString text;