Finish moving TOOL_MANAGER down to the EDA_BASE_FRAME level.

This commit is contained in:
Jeff Young 2019-06-09 13:18:11 +01:00
parent c3cc85eb1c
commit 16cb1e731d
8 changed files with 48 additions and 63 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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 ),

View File

@ -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<EDA_DRAW_FRAME*>( m_toolMgr->GetEditFrame() )->GetGalCanvas()->SetFocus();
#endif /* __APPLE__ */
}
else if( type == wxEVT_CHAR_HOOK || type == wxEVT_CHAR )

View File

@ -33,7 +33,7 @@
#include <wx/clipbrd.h>
#include <view/view.h>
#include <eda_base_frame.h>
#include <tool/tool_base.h>
#include <tool/tool_interactive.h>
#include <tool/tool_manager.h>
@ -42,7 +42,6 @@
#include <tool/action_manager.h>
#include <class_draw_panel_gal.h>
#include <eda_draw_frame.h>
/// Struct describing the current execution state of a TOOL
struct TOOL_MANAGER::TOOL_STATE
@ -195,7 +194,7 @@ TOOL_MANAGER::TOOL_MANAGER() :
m_model( NULL ),
m_view( NULL ),
m_viewControls( NULL ),
m_editFrame( NULL ),
m_frame( NULL ),
m_passEvent( false ),
m_menuActive( false ),
m_menuOwner( -1 ),
@ -700,7 +699,7 @@ void TOOL_MANAGER::DispatchContextMenu( const TOOL_EVENT& aEvent )
m_menuOwner = toolId;
m_menuActive = true;
auto frame = dynamic_cast<wxFrame*>( m_editFrame );
auto frame = dynamic_cast<wxFrame*>( 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<EDA_DRAW_FRAME*>( 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 )
{

View File

@ -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.
*/
@ -417,10 +432,9 @@ public:
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; }
};

View File

@ -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.
* <p>
* 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()

View File

@ -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<TOOL_EVENT> m_eventQueue;