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(); 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() DECLARE_EVENT_TABLE()
}; };

View File

@ -607,19 +607,9 @@ public:
*/ */
void Show3D_Frame( wxCommandEvent& event ); void Show3D_Frame( wxCommandEvent& event );
/** ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
* Virtual function UseGalCanvas
* Enables/disables GAL canvas.
* @param aEnable determines if GAL should be active or not.
*/
void UseGalCanvas( bool aEnable ); 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 ); bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/** /**

View File

@ -916,3 +916,58 @@ void PCB_BASE_FRAME::SetPrevGrid()
else else
GetCanvas()->Refresh(); 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 ); 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 ); bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
void OnVerticalToolbar( wxCommandEvent& aEvent ); 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 ) EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, FOOTPRINT_EDIT_FRAME::Show3D_Frame )
// Switching canvases // Switching canvases
EVT_MENU( ID_MENU_CANVAS_DEFAULT, FOOTPRINT_EDIT_FRAME::SwitchCanvas ) EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, FOOTPRINT_EDIT_FRAME::SwitchCanvas ) EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, FOOTPRINT_EDIT_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_DELETE_PART, FOOTPRINT_EDIT_FRAME::OnUpdateLibSelected )
EVT_UPDATE_UI( ID_MODEDIT_SELECT_CURRENT_LIB, FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib ) 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() void FOOTPRINT_EDIT_FRAME::setupTools()
{ {
PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() ); 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 ) void FOOTPRINT_EDIT_FRAME::UseGalCanvas( bool aEnable )
{ {
EDA_DRAW_FRAME::UseGalCanvas( aEnable ); PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
if( aEnable ) if( aEnable )
{
SetBoard( m_Pcb );
m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH );
updateView(); 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() void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
{ {
m_footprintList->Clear(); m_footprintList->Clear();

View File

@ -69,9 +69,6 @@ public:
*/ */
void ReCreateLibraryList(); void ReCreateLibraryList();
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
virtual void UseGalCanvas( bool aEnable );
private: private:
wxListBox* m_libList; // The list of libs names 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; 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; m_undoRedoBlocked = aBlock;
} }
///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
void UseGalCanvas( bool aEnable );
protected: protected:
/// User defined rotation angle (in tenths of a degree). /// User defined rotation angle (in tenths of a degree).
int m_rotationAngle; 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 ) EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, PCB_EDIT_FRAME::Show3D_Frame )
// Switching canvases // Switching canvases
EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_EDIT_FRAME::SwitchCanvas ) EVT_MENU( ID_MENU_CANVAS_DEFAULT, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_EDIT_FRAME::SwitchCanvas ) EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_BASE_FRAME::SwitchCanvas )
EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_EDIT_FRAME::SwitchCanvas ) EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_BASE_FRAME::SwitchCanvas )
// Menu Get Design Rules Editor // Menu Get Design Rules Editor
EVT_MENU( ID_MENU_PCB_SHOW_DESIGN_RULES_DIALOG, PCB_EDIT_FRAME::ShowDesignRulesEditor ) 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 ) void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
{ {
EDA_DRAW_FRAME::UseGalCanvas( aEnable ); PCB_BASE_EDIT_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 );
}
enableGALSpecificMenus(); 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() void PCB_EDIT_FRAME::enableGALSpecificMenus()
{ {
// some menus are active only in GAL mode and do nothing in legacy mode. // some menus are active only in GAL mode and do nothing in legacy mode.