From 16cb1e731d07691eda6f10388fd6db1daba409ff Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 9 Jun 2019 13:18:11 +0100 Subject: [PATCH] Finish moving TOOL_MANAGER down to the EDA_BASE_FRAME level. --- common/eda_base_frame.cpp | 15 +-------------- common/eda_draw_frame.cpp | 1 - common/tool/action_toolbar.cpp | 2 +- common/tool/tool_dispatcher.cpp | 6 +++--- common/tool/tool_manager.cpp | 32 ++++++++++++++------------------ include/eda_base_frame.h | 22 ++++++++++++++++++---- include/eda_draw_frame.h | 19 ++++--------------- include/tool/tool_manager.h | 14 +++++++------- 8 files changed, 48 insertions(+), 63 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index b707d14dce..1b872181f8 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -91,6 +91,7 @@ EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, m_autoSaveInterval = -1; m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER ); m_mruPath = wxStandardPaths::Get().GetDocumentsDir(); + m_toolManager = nullptr; // Gives a reasonable minimal size to the frame: const int minsize_x = 500; @@ -686,17 +687,3 @@ void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName ) } -bool EDA_BASE_FRAME::PostCommandMenuEvent( int evt_type ) -{ - if( evt_type != 0 ) - { - wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED ); - evt.SetEventObject( this ); - evt.SetId( evt_type ); - wxPostEvent( this, evt ); - return true; - } - - return false; -} - diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index af3e0cc60a..4e0a47817c 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -100,7 +100,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; m_galCanvas = NULL; m_actions = NULL; - m_toolManager = NULL; m_toolDispatcher = NULL; m_messagePanel = NULL; m_currentScreen = NULL; diff --git a/common/tool/action_toolbar.cpp b/common/tool/action_toolbar.cpp index 75eb61db9e..d6a0e5ccb1 100644 --- a/common/tool/action_toolbar.cpp +++ b/common/tool/action_toolbar.cpp @@ -41,7 +41,7 @@ ACTION_TOOLBAR::ACTION_TOOLBAR( EDA_DRAW_FRAME* parent, wxWindowID id, const wxP void ACTION_TOOLBAR::Add( const TOOL_ACTION& aAction, bool aIsToggleEntry ) { - EDA_DRAW_FRAME* editFrame = m_toolManager->GetEditFrame(); + EDA_BASE_FRAME* editFrame = m_toolManager->GetEditFrame(); int toolId = aAction.GetId() + ACTION_ID; AddTool( toolId, wxEmptyString, KiScaledBitmap( aAction.GetIcon(), editFrame ), diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index f495168e44..567dcdff61 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -320,8 +320,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // Sometimes there is no window that has the focus (it happens when another PCB_BASE_FRAME // is opened and is iconized on Windows). - // In this case, gives the focus to the parent frame (for an obscure reason, - // when happens, the GAL canvas itself does not accept the focus) + // In this case, give the focus to the parent frame (GAL canvas itself does not accept the + // focus when iconized for some obscure reason) if( wxWindow::FindFocus() == nullptr ) m_toolMgr->GetEditFrame()->SetFocus(); @@ -363,7 +363,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) // TODO That's a big ugly workaround, somehow DRAWPANEL_GAL loses focus // after second LMB click and currently I have no means to do better debugging if( type == wxEVT_LEFT_UP ) - m_toolMgr->GetEditFrame()->GetGalCanvas()->SetFocus(); + static_cast( m_toolMgr->GetEditFrame() )->GetGalCanvas()->SetFocus(); #endif /* __APPLE__ */ } else if( type == wxEVT_CHAR_HOOK || type == wxEVT_CHAR ) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index a31a27a6c2..542a0f7943 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -33,7 +33,7 @@ #include #include - +#include #include #include #include @@ -42,7 +42,6 @@ #include #include -#include /// Struct describing the current execution state of a TOOL struct TOOL_MANAGER::TOOL_STATE @@ -192,14 +191,14 @@ private: TOOL_MANAGER::TOOL_MANAGER() : - m_model( NULL ), - m_view( NULL ), - m_viewControls( NULL ), - m_editFrame( NULL ), - m_passEvent( false ), - m_menuActive( false ), - m_menuOwner( -1 ), - m_activeState( nullptr ) + m_model( NULL ), + m_view( NULL ), + m_viewControls( NULL ), + m_frame( NULL ), + m_passEvent( false ), + m_menuActive( false ), + m_menuOwner( -1 ), + m_activeState( nullptr ) { m_actionMgr = new ACTION_MANAGER( this ); } @@ -700,7 +699,7 @@ void TOOL_MANAGER::DispatchContextMenu( const TOOL_EVENT& aEvent ) m_menuOwner = toolId; m_menuActive = true; - auto frame = dynamic_cast( m_editFrame ); + auto frame = dynamic_cast( m_frame ); if( frame ) frame->PopupMenu( menu.get() ); @@ -782,10 +781,7 @@ bool TOOL_MANAGER::ProcessEvent( const TOOL_EVENT& aEvent ) if( m_view->IsDirty() ) { - auto f = dynamic_cast( GetEditFrame() ); - - if( f ) - f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER. + GetEditFrame()->RefreshCanvas(); #if defined( __WXMAC__ ) || defined( __WINDOWS__ ) wxTheApp->ProcessPendingEvents(); // required for updating brightening behind a popup menu @@ -861,12 +857,12 @@ TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName ) void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView, - KIGFX::VIEW_CONTROLS* aViewControls, EDA_DRAW_FRAME* aFrame ) + KIGFX::VIEW_CONTROLS* aViewControls, EDA_BASE_FRAME* aFrame ) { m_model = aModel; m_view = aView; m_viewControls = aViewControls; - m_editFrame = aFrame; + m_frame = aFrame; m_actionMgr->UpdateHotKeys(); } @@ -970,7 +966,7 @@ bool TOOL_MANAGER::IsToolActive( TOOL_ID aId ) const void TOOL_MANAGER::UpdateUI() { - EDA_DRAW_FRAME* frame = GetEditFrame(); + EDA_BASE_FRAME* frame = GetEditFrame(); if( frame ) { diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 078cd920e7..9135e497df 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -405,6 +405,21 @@ public: */ void CheckForAutoSaveFile( const wxFileName& aFileName ); + /** + * Update the status bar information. + * + * The status bar can draw itself. This is not a drawing function per se, but rather + * updates lines of text held by the components within the status bar which is owned + * by the wxFrame. + */ + virtual void UpdateStatusBar() { } + + /** + * Update the toolbars (mostly settings/check buttons/checkboxes) with the current + * controller state. + */ + virtual void SyncMenusAndToolbars() { }; + /** * Redraw the menus and what not in current language. */ @@ -415,12 +430,11 @@ public: * Update menus, toolbars, local variables, etc. */ virtual void CommonSettingsChanged(); - + /** - * Post a menu event to the frame, which can be used to trigger actions - * bound to menu items. + * Notification to refresh the drawing canvas (if any). */ - bool PostCommandMenuEvent( int evt_type ); + virtual void RefreshCanvas() { }; const wxString& GetAboutTitle() const { return m_AboutTitle; } }; diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index b66f20e6f6..1ce2b117f8 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -587,16 +587,11 @@ public: /** * Update the status bar information. * - * The base method updates the absolute and relative coordinates and the - * zoom information. If you override this virtual method, make sure to call - * this subclassed method. The status bar can draw itself. This is not - * a drawing function per se, but rather updates lines of text held by - * the components within the status bar which is owned by the wxFrame. - *

- * On a MAC, be careful about calling this function when there is an - * existing wxDC in existence on a sibling window. + * The EDA_DRAW_FRAME level updates the absolute and relative coordinates and the + * zoom information. If you override this virtual method, make sure to call this + * subclassed method. */ - virtual void UpdateStatusBar(); + void UpdateStatusBar() override; /** * Display current unit pane on the status bar. @@ -688,12 +683,6 @@ public: */ KIGFX::GAL_DISPLAY_OPTIONS& GetGalDisplayOptions() { return m_galDisplayOptions; } - /** - * Update the toolbars and menus (mostly settings/check buttons/checkboxes) - * with the current controller state - */ - virtual void SyncMenusAndToolbars() { }; - virtual const BOX2I GetDocumentExtents() const; DECLARE_EVENT_TABLE() diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index bbd6e24ef2..f88b670ecb 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -37,7 +37,8 @@ class TOOL_BASE; class ACTION_MANAGER; class ACTION_MENU; -class wxWindow; +class EDA_BASE_FRAME; + /** * Class TOOL_MANAGER. @@ -242,11 +243,10 @@ public: /** * Sets the work environment (model, view, view controls and the parent window). - * These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME) - * when the board is set up. + * These are made available to the tool. Called by the parent frame when it is set up. */ void SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView, - KIGFX::VIEW_CONTROLS* aViewControls, EDA_DRAW_FRAME* aFrame ); + KIGFX::VIEW_CONTROLS* aViewControls, EDA_BASE_FRAME* aFrame ); /* Accessors for the environment objects (view, model, etc.) */ KIGFX::VIEW* GetView() const @@ -264,9 +264,9 @@ public: return m_model; } - inline EDA_DRAW_FRAME* GetEditFrame() const + inline EDA_BASE_FRAME* GetEditFrame() const { - return m_editFrame; + return m_frame; } /** @@ -535,7 +535,7 @@ private: EDA_ITEM* m_model; KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_viewControls; - EDA_DRAW_FRAME* m_editFrame; + EDA_BASE_FRAME* m_frame; /// Queue that stores events to be processed at the end of the event processing cycle. std::list m_eventQueue;