From f8a3ec4974db318109c546c269551a22c1d39d34 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 3 Apr 2018 13:00:20 +0200 Subject: [PATCH] Add a method to facilitate Tools handling in main frame toolbars. Fix also a bug in gerbview_frame.cpp, about a broken toolbar accessor (fortunately not used in current code) --- common/draw_frame.cpp | 32 ++++++++++++++++++++++++++++++++ gerbview/gerbview_frame.cpp | 1 - gerbview/gerbview_frame.h | 6 ------ include/draw_frame.h | 27 +++++++++++++++++---------- include/pcb_base_frame.h | 4 ---- pcbnew/pcb_base_frame.cpp | 2 -- 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 6211c5ab6a..86e2a3bd69 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -134,6 +134,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, { m_drawToolBar = NULL; m_optionsToolBar = NULL; + m_auxiliaryToolBar = NULL; m_gridSelectBox = NULL; m_zoomSelectBox = NULL; m_hotkeysDescrList = NULL; @@ -306,6 +307,37 @@ void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent ) m_canvas->Refresh(); } +bool EDA_DRAW_FRAME::GetToolToggled( int aToolId ) +{ + // Checks all the toolbars and returns true if the given tool id is toggled. + return ( ( m_mainToolBar && m_mainToolBar->GetToolToggled( aToolId ) ) || + ( m_optionsToolBar && m_optionsToolBar->GetToolToggled( aToolId ) ) || + ( m_drawToolBar && m_drawToolBar->GetToolToggled( aToolId ) ) || + ( m_auxiliaryToolBar && m_auxiliaryToolBar->GetToolToggled( aToolId ) ) + ); +} + + +wxAuiToolBarItem* EDA_DRAW_FRAME::GetToolbarTool( int aToolId ) +{ + // Checks all the toolbars and returns a reference to the given tool id + // (or the first tool found, but only one or 0 tool is expected, because on + // Windows, when different tools have the same ID, it creates issues) + if( m_mainToolBar && m_mainToolBar->FindTool( aToolId ) ) + return m_mainToolBar->FindTool( aToolId ); + + if( m_optionsToolBar && m_optionsToolBar->FindTool( aToolId ) ) + return m_optionsToolBar->FindTool( aToolId ); + + if( m_drawToolBar && m_drawToolBar->FindTool( aToolId ) ) + return m_drawToolBar->FindTool( aToolId ); + + if( m_auxiliaryToolBar && m_auxiliaryToolBar->FindTool( aToolId ) ) + return m_auxiliaryToolBar->FindTool( aToolId ); + + return nullptr; +} + void EDA_DRAW_FRAME::OnSelectUnits( wxCommandEvent& aEvent ) { diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 0cc864b1ab..4a5f50fa31 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -68,7 +68,6 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ): EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition, wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, GERBVIEW_FRAME_NAME ) { - m_auxiliaryToolBar = NULL; m_colorsSettings = &g_ColorsSettings; m_gerberLayout = NULL; m_zoomLevelCoeff = ZOOM_FACTOR( 110 ); // Adjusted to roughly displays zoom level = 1 diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 06927d13ba..b86a73066f 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -182,10 +182,6 @@ public: COLORS_DESIGN_SETTINGS* m_colorsSettings; private: - /// Auxiliary tool bar typically shown below the main tool bar at the top of the - /// main window. - wxAuiToolBar* m_auxiliaryToolBar; - // list of PARAM_CFG_xxx to read/write parameters saved in config PARAM_CFG_ARRAY m_configSettings; @@ -258,8 +254,6 @@ public: double BestZoom() override; void UpdateStatusBar() override; - wxAuiToolBar* GetMainToolBar() { return m_optionsToolBar; } - /** * Function GetZoomLevelIndicator * returns a human readable value which can be displayed as zoom diff --git a/include/draw_frame.h b/include/draw_frame.h index d7fb95a4f9..68e3aa8a97 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -121,6 +121,10 @@ protected: /// Choice box to choose the zoom value. wxChoice* m_zoomSelectBox; + /// Auxiliary tool bar typically shown below the main tool bar at the top of the + /// main window. + wxAuiToolBar* m_auxiliaryToolBar; + /// The tool bar that contains the buttons for quick access to the application draw /// tools. It typically is located on the right side of the main window. wxAuiToolBar* m_drawToolBar; @@ -434,20 +438,23 @@ public: // Toolbar accessors wxAuiToolBar* GetMainToolBar() const { return m_mainToolBar; } + wxAuiToolBar* GetOptionsToolBar() const { return m_optionsToolBar; } + wxAuiToolBar* GetDrawToolBar() const { return m_drawToolBar; } + wxAuiToolBar* GetAuxiliaryToolBar() const { return m_auxiliaryToolBar; } /** * Checks all the toolbars and returns true if the given tool id is toggled. * - * This is needed because GerbView and Pcbnew put some of the same tools in - * different toolbars (for example, zoom selection is in the main bar in - * Pcbnew and in the options bar in GerbView). + * This is needed because GerbView and Pcbnew can put some of the same tools in + * different toolbars. */ - bool GetToolToggled( int aToolId ) - { - return ( ( m_mainToolBar && m_mainToolBar->GetToolToggled( aToolId ) ) || - ( m_optionsToolBar && m_optionsToolBar->GetToolToggled( aToolId ) ) || - ( m_drawToolBar && m_drawToolBar->GetToolToggled( aToolId ) ) ); - } + bool GetToolToggled( int aToolId ); + + /** + * Checks all the toolbars and returns a reference to the given tool id + * or nullptr if not found + */ + wxAuiToolBarItem* GetToolbarTool( int aToolId ); /** * Function SetToolID @@ -905,7 +912,7 @@ public: /** * Function SyncMenusAndToolbars * Updates the toolbars and menus (mostly settings/check buttons/checkboxes) - * with the current controller state + * with the current controller state */ virtual void SyncMenusAndToolbars( wxEvent& aEvent ) {}; diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 2184f71056..9dcb5321aa 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -78,10 +78,6 @@ protected: GENERAL_COLLECTOR* m_Collector; PCB_GENERAL_SETTINGS m_configSettings; - /// Auxiliary tool bar typically shown below the main tool bar at the top of the - /// main window. - wxAuiToolBar* m_auxiliaryToolBar; - void updateGridSelectBox(); void updateZoomSelectBox(); virtual void unitsChangeRefresh() override; diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 5e6aada4e9..0684aaec1e 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -115,8 +115,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_FastGrid1 = 0; m_FastGrid2 = 0; - m_auxiliaryToolBar = NULL; - m_zoomLevelCoeff = 11.0 * IU_PER_MILS; // Adjusted to roughly displays zoom level = 1 // when the screen shows a 1:1 image // obviously depends on the monitor,