Simplified code for switching canvases.

Moved SwitchCanvas() to PCB_BASE_FRAME and made it common for all subclasses.
More code from UseGalCanvas() is shared between classes.
This commit is contained in:
Maciej Suminski 2015-08-07 19:15:36 +02:00
parent ddcdda1a59
commit 1d6fc920e6
10 changed files with 86 additions and 123 deletions

View File

@ -672,6 +672,15 @@ public:
void ClearSelection();
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas
virtual void UseGalCanvas( bool aEnable );
/**
* Function SwitchCanvas
* switches currently used canvas (default / Cairo / OpenGL).
*/
void SwitchCanvas( wxCommandEvent& aEvent );
DECLARE_EVENT_TABLE()
};

View File

@ -607,19 +607,9 @@ public:
*/
void Show3D_Frame( wxCommandEvent& event );
/**
* Virtual function UseGalCanvas
* Enables/disables GAL canvas.
* @param aEnable determines if GAL should be active or not.
*/
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
void UseGalCanvas( bool aEnable );
/**
* Function SwitchCanvas
* switches currently used canvas (default / Cairo / OpenGL).
*/
void SwitchCanvas( wxCommandEvent& aEvent );
bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/**

View File

@ -916,3 +916,58 @@ void PCB_BASE_FRAME::SetPrevGrid()
else
GetCanvas()->Refresh();
}
void PCB_BASE_FRAME::SwitchCanvas( wxCommandEvent& aEvent )
{
int id = aEvent.GetId();
bool use_gal = false;
switch( id )
{
case ID_MENU_CANVAS_DEFAULT:
break;
case ID_MENU_CANVAS_CAIRO:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO );
break;
case ID_MENU_CANVAS_OPENGL:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
break;
}
UseGalCanvas( use_gal );
}
void PCB_BASE_FRAME::UseGalCanvas( bool aEnable )
{
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
EDA_DRAW_PANEL_GAL* galCanvas = GetGalCanvas();
if( m_toolManager )
m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(),
GetGalCanvas()->GetViewControls(), this );
if( aEnable )
{
SetBoard( m_Pcb );
if( m_toolManager )
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
galCanvas->GetView()->RecacheAllItems( true );
galCanvas->SetEventDispatcher( m_toolDispatcher );
galCanvas->StartDrawing();
}
else
{
if( m_toolManager )
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
// Redirect all events to the legacy canvas
galCanvas->SetEventDispatcher( NULL );
}
}

View File

@ -167,12 +167,6 @@ public:
*/
void Show3D_Frame( wxCommandEvent& event );
/**
* Function SwitchCanvas
* switches currently used canvas (default / Cairo / OpenGL).
*/
void SwitchCanvas( wxCommandEvent& aEvent );
bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
void OnVerticalToolbar( wxCommandEvent& aEvent );

View File

@ -167,9 +167,9 @@ BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, FOOTPRINT_EDIT_FRAME::Show3D_Frame )
// Switching canvases
EVT_MENU( ID_MENU_CANVAS_DEFAULT, FOOTPRINT_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, FOOTPRINT_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, FOOTPRINT_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_BASE_FRAME::SwitchCanvas )
EVT_UPDATE_UI( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::OnUpdateLibSelected )
EVT_UPDATE_UI( ID_MODEDIT_SELECT_CURRENT_LIB, FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib )
@ -904,29 +904,6 @@ void FOOTPRINT_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
}
void FOOTPRINT_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent )
{
int id = aEvent.GetId();
bool use_gal = false;
switch( id )
{
case ID_MENU_CANVAS_DEFAULT:
break;
case ID_MENU_CANVAS_CAIRO:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO );
break;
case ID_MENU_CANVAS_OPENGL:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
break;
}
UseGalCanvas( use_gal );
}
void FOOTPRINT_EDIT_FRAME::setupTools()
{
PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
@ -960,21 +937,8 @@ void FOOTPRINT_EDIT_FRAME::setupTools()
void FOOTPRINT_EDIT_FRAME::UseGalCanvas( bool aEnable )
{
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
if( aEnable )
{
SetBoard( m_Pcb );
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
updateView();
GetGalCanvas()->SetEventDispatcher( m_toolDispatcher );
GetGalCanvas()->StartDrawing();
}
else
{
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
// Redirect all events to the legacy canvas
GetGalCanvas()->SetEventDispatcher( NULL );
}
}

View File

@ -362,15 +362,6 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
}
void FOOTPRINT_VIEWER_FRAME::UseGalCanvas( bool aEnable )
{
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
if( aEnable )
GetGalCanvas()->StartDrawing();
}
void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
{
m_footprintList->Clear();

View File

@ -69,9 +69,6 @@ public:
*/
void ReCreateLibraryList();
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
virtual void UseGalCanvas( bool aEnable );
private:
wxListBox* m_libList; // The list of libs names

View File

@ -46,3 +46,13 @@ bool PCB_BASE_EDIT_FRAME::PostCommandMenuEvent( int evt_type )
return false;
}
void PCB_BASE_EDIT_FRAME::UseGalCanvas( bool aEnable )
{
PCB_BASE_FRAME::UseGalCanvas( aEnable );
// No matter what, reenable undo/redo on switching to the legacy canvas
if( !aEnable )
UndoRedoBlock( false );
}

View File

@ -89,6 +89,9 @@ public:
m_undoRedoBlocked = aBlock;
}
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
void UseGalCanvas( bool aEnable );
protected:
/// User defined rotation angle (in tenths of a degree).
int m_rotationAngle;

View File

@ -178,9 +178,9 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME )
EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, PCB_EDIT_FRAME::Show3D_Frame )
// Switching canvases
EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_EDIT_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_BASE_FRAME::SwitchCanvas )
// Menu Get Design Rules Editor
EVT_MENU( ID_MENU_PCB_SHOW_DESIGN_RULES_DIALOG, PCB_EDIT_FRAME::ShowDesignRulesEditor )
@ -661,62 +661,12 @@ void PCB_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event )
void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
{
EDA_DRAW_FRAME::UseGalCanvas( aEnable );
m_toolManager->SetEnvironment( m_Pcb, GetGalCanvas()->GetView(),
GetGalCanvas()->GetViewControls(), this );
if( aEnable )
{
SetBoard( m_Pcb );
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
GetGalCanvas()->GetView()->RecacheAllItems( true );
GetGalCanvas()->SetEventDispatcher( m_toolDispatcher );
GetGalCanvas()->StartDrawing();
}
else
{
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
// Redirect all events to the legacy canvas
GetGalCanvas()->SetEventDispatcher( NULL );
// No matter what, reenable undo/redo
UndoRedoBlock( false );
}
PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
enableGALSpecificMenus();
}
void PCB_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent )
{
int id = aEvent.GetId();
bool use_gal = false;
switch( id )
{
case ID_MENU_CANVAS_DEFAULT:
break;
case ID_MENU_CANVAS_CAIRO:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO );
break;
case ID_MENU_CANVAS_OPENGL:
use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL );
break;
}
if( !use_gal )
Compile_Ratsnest( NULL, true );
else
GetBoard()->GetRatsnest()->ProcessBoard();
UseGalCanvas( use_gal );
}
void PCB_EDIT_FRAME::enableGALSpecificMenus()
{
// some menus are active only in GAL mode and do nothing in legacy mode.