diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index cc05ce1919..57be222adc 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -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() }; diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 3c35c39fa3..8253bf91e8 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -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 ); /** diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index f5d9e13ef3..3b9f4b19c6 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -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 ); + } +} diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index 402dc98f8c..08cb17fe3d 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -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 ); diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 79d68f945e..3fbbb7ac6f 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -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( 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 ); - } } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 5b80077612..7ade7dfd98 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -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(); diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index aac6c17442..902fc77082 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -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 diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 22a3ad4041..6ab272ffdb 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -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 ); +} diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 3bb6cdec4e..bcc869fdcb 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -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; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 9f84003f89..64d3ca26f7 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -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.