From 820e6e5e165be45d6dd60bb09bc177d89e389b72 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 15 Apr 2013 17:57:03 +0200 Subject: [PATCH] Introduced Cairo-based rendering backend using GAL. Moved switching canvas routines to pcbnew, as they are used only there right now (otherwise libgal would have to be linked to every Kicad application). --- common/drawframe.cpp | 33 +++++++++++++++++++++++++++------ common/drawpanel_gal.cpp | 10 ++++++++++ common/zoom.cpp | 35 ----------------------------------- include/class_drawpanel_gal.h | 1 - include/id.h | 1 - include/wxPcbStruct.h | 7 +++++++ pcbnew/hotkeys.cpp | 6 ++++-- pcbnew/hotkeys.h | 4 +++- pcbnew/menubar_pcbframe.cpp | 21 ++++++++++++++++++--- pcbnew/pcbframe.cpp | 35 +++++++++++++++++++++++++++++++++++ pcbnew/pcbnew_id.h | 3 +++ 11 files changed, 107 insertions(+), 49 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 9bf7fde793..c723a30cd0 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -46,7 +46,10 @@ #include #include - +#ifdef KICAD_GAL +#include +#include +#endif /* KICAD_GAL */ /** * Definition for enabling and disabling scroll bar setting trace output. See the @@ -67,7 +70,6 @@ BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, EDA_BASE_FRAME ) EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen ) EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate ) EVT_MENU_RANGE( ID_ZOOM_IN, ID_ZOOM_REDRAW, EDA_DRAW_FRAME::OnZoom ) - EVT_MENU( ID_SWITCH_CANVAS, EDA_DRAW_FRAME::OnZoom ) EVT_MENU_RANGE( ID_OFFCENTER_ZOOM_IN, ID_OFFCENTER_ZOOM_OUT, EDA_DRAW_FRAME::OnZoom ) EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE, EDA_DRAW_FRAME::OnZoom ) @@ -943,22 +945,41 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU ) void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) { + if( aEnable && m_galCanvasActive ) + { + // When we switch between GAL based canvases, all we need is a refresh + m_galCanvas->Refresh(); + } + if( !( aEnable ^ m_galCanvasActive ) ) return; + KiGfx::VIEW* view = m_galCanvas->GetView(); + KiGfx::GAL* gal = m_galCanvas->GetGAL(); + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + + // Display the same view after canvas switching if( aEnable ) { - m_canvas->Hide(); + double zoom = 1 / ( zoomFactor * m_canvas->GetZoom() ); + view->SetScale( zoom ); + + view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); + m_galCanvas->Show(); - m_galCanvas->Raise(); m_galCanvas->Refresh(); } else { m_galCanvas->Hide(); + + double zoom = 1 / ( zoomFactor * view->GetScale() ); + m_canvas->SetZoom( zoom ); + + VECTOR2D center = view->GetCenter(); + RedrawScreen( wxPoint( center.x, center.y ), false ); + m_canvas->Show(); - m_canvas->Raise(); - m_canvas->Refresh(); } m_galCanvasActive = aEnable; diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index bc8c5224b4..483bac5fc4 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -84,7 +84,11 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_gal->SetZoomFactor( 1.0 ); m_gal->ComputeWorldScreenMatrix(); + m_painter = new KiGfx::PCB_PAINTER( m_gal ); + m_painter->SetGAL( m_gal ); + m_view = new KiGfx::VIEW( true ); + m_view->SetPainter( m_painter ); m_view->SetGAL( m_gal ); // View uses layers to display EDA_ITEMs (item may be displayed on several layers, for example @@ -150,4 +154,10 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType, bool aUseShaders ) if( m_view ) m_view->SetGAL( m_gal ); + + if( m_painter ) + m_painter->SetGAL( m_gal ); + + wxSize size = GetClientSize(); + m_gal->ResizeScreen( size.GetX(), size.GetY() ); } diff --git a/common/zoom.cpp b/common/zoom.cpp index 6d3dac3ee9..e8e07b5f90 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -39,11 +39,6 @@ #include #include #include -#ifdef KICAD_GAL -#include -#include -#include -#endif void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer ) @@ -167,36 +162,6 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) m_canvas->Refresh(); break; -#ifdef KICAD_GAL - // Switch canvas between standard and GAL-based - case ID_SWITCH_CANVAS: - { - UseGalCanvas( !m_galCanvasActive ); - - KiGfx::VIEW* view = m_galCanvas->GetView(); - KiGfx::GAL* gal = m_galCanvas->GetGAL(); - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); - - // Display the same view after canvas switching - if( m_galCanvasActive ) - { - double zoom = 1 / ( zoomFactor * m_canvas->GetZoom() ); - view->SetScale( zoom ); - - view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); - } - else - { - double zoom = 1 / ( zoomFactor * view->GetScale() ); - m_canvas->SetZoom( zoom ); - - VECTOR2D center = view->GetCenter(); - RedrawScreen( wxPoint( center.x, center.y ), false ); - } - } - break; -#endif - case ID_POPUP_ZOOM_CENTER: center = screen->GetCrossHairPosition(); RedrawScreen( center, true ); diff --git a/include/class_drawpanel_gal.h b/include/class_drawpanel_gal.h index 206d88a5ff..63ed0cc6a1 100644 --- a/include/class_drawpanel_gal.h +++ b/include/class_drawpanel_gal.h @@ -52,7 +52,6 @@ public: enum GalType { GAL_TYPE_OPENGL, ///< OpenGL implementation GAL_TYPE_CAIRO, ///< Cairo implementation - GAL_TYPE_WXDC ///< WXDC implementation }; EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, diff --git a/include/id.h b/include/id.h index eb9eec91b0..4d517474af 100644 --- a/include/id.h +++ b/include/id.h @@ -213,7 +213,6 @@ enum main_id ID_ZOOM_OUT, ID_ZOOM_PAGE, ID_ZOOM_REDRAW, - ID_SWITCH_CANVAS, /* Panning command event IDs. */ ID_PAN_UP, diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 5ba16dc3e6..dabdb2ece0 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -581,6 +581,13 @@ public: * displays the 3D view of current printed circuit board. */ void Show3D_Frame( wxCommandEvent& event ); + + /** + * Function ChangeCanvas + * switches currently used canvas (default / Cairo / OpenGL). + */ + void SwitchCanvas( wxCommandEvent& aEvent ); + void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 ); /** diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index c0fbfb006a..95715d7af9 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -83,7 +83,9 @@ static EDA_HOTKEY HkResetLocalCoord( wxT( "Reset Local Coordinates" ), static EDA_HOTKEY HkSwitchHighContrastMode( wxT("Switch Highcontrast mode"), HK_SWITCH_HIGHCONTRAST_MODE,'H'); #ifdef KICAD_GAL -static EDA_HOTKEY HkSwitchCanvas( wxT( "Switch canvas" ), HK_SWITCH_CANVAS, WXK_F12 ); +static EDA_HOTKEY HkCanvasDefault( wxT( "Switch to default canvas" ), HK_CANVAS_DEFAULT, WXK_F10 ); +static EDA_HOTKEY HkCanvasCairo( wxT( "Switch to OpenGL canvas" ), HK_CANVAS_OPENGL, WXK_F11 ); +static EDA_HOTKEY HkCanvasOpenGL( wxT( "Switch to Cairo canvas" ), HK_CANVAS_CAIRO, WXK_F12 ); #endif /* Fit on Screen */ #if !defined( __WXMAC__ ) @@ -232,7 +234,7 @@ EDA_HOTKEY* board_edit_Hotkey_List[] = &HkRecordMacros8, &HkCallMacros8, &HkRecordMacros9, &HkCallMacros9, &HkSwitchHighContrastMode, #ifdef KICAD_GAL - &HkSwitchCanvas, + &HkCanvasDefault, &HkCanvasCairo, &HkCanvasOpenGL, #endif NULL }; diff --git a/pcbnew/hotkeys.h b/pcbnew/hotkeys.h index 5c24b43ea0..d504e99887 100644 --- a/pcbnew/hotkeys.h +++ b/pcbnew/hotkeys.h @@ -83,7 +83,9 @@ enum hotkey_id_commnand { HK_MACRO_ID_END, HK_SWITCH_HIGHCONTRAST_MODE, #ifdef KICAD_GAL - HK_SWITCH_CANVAS, + HK_CANVAS_DEFAULT, + HK_CANVAS_OPENGL, + HK_CANVAS_CAIRO, #endif }; diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index c3e1cd2301..35babf398f 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -352,10 +352,25 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() // Switching GAL-based canvas on/off viewMenu->AppendSeparator(); - text = AddHotkeyName( _( "&Switch canvas" ), g_Pcbnew_Editor_Hokeys_Descr, HK_SWITCH_CANVAS, IS_ACCELERATOR ); + text = AddHotkeyName( _( "&Switch canvas to default" ), g_Pcbnew_Editor_Hokeys_Descr, + HK_CANVAS_DEFAULT, IS_ACCELERATOR ); - AddMenuItem( viewMenu, ID_SWITCH_CANVAS, - text, _( "Switch the canvas implementation between old (XOR-based) and new (GAL-based)" ), + AddMenuItem( viewMenu, ID_MENU_CANVAS_DEFAULT, + text, _( "Switch the canvas implementation to default" ), + KiBitmap( tools_xpm ) ); + + text = AddHotkeyName( _( "&Switch canvas to OpenGL" ), g_Pcbnew_Editor_Hokeys_Descr, + HK_CANVAS_OPENGL, IS_ACCELERATOR ); + + AddMenuItem( viewMenu, ID_MENU_CANVAS_OPENGL, + text, _( "Switch the canvas implementation to OpenGL" ), + KiBitmap( tools_xpm ) ); + + text = AddHotkeyName( _( "&Switch canvas to Cairo" ), g_Pcbnew_Editor_Hokeys_Descr, + HK_CANVAS_CAIRO, IS_ACCELERATOR ); + + AddMenuItem( viewMenu, ID_MENU_CANVAS_CAIRO, + text, _( "Switch the canvas implementation to Cairo" ), KiBitmap( tools_xpm ) ); #endif diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index db8e6f4127..439105b92b 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -59,6 +59,10 @@ #include #endif +#if defined(KICAD_GAL) +#include +#endif + // Keys used in read/write config #define OPTKEY_DEFAULT_LINEWIDTH_VALUE wxT( "PlotLineWidth_mm" ) #define PCB_SHOW_FULL_RATSNET_OPT wxT( "PcbFullRatsnest" ) @@ -152,6 +156,11 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) // Menu 3D 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 ) + // Menu Get Design Rules Editor EVT_MENU( ID_MENU_PCB_SHOW_DESIGN_RULES_DIALOG, PCB_EDIT_FRAME::ShowDesignRulesEditor ) @@ -557,6 +566,32 @@ void PCB_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event ) } +void PCB_EDIT_FRAME::SwitchCanvas( wxCommandEvent& aEvent ) +{ +#ifdef KICAD_GAL + int id = aEvent.GetId(); + + switch( id ) + { + case ID_MENU_CANVAS_DEFAULT: + UseGalCanvas( false ); + break; + + case ID_MENU_CANVAS_CAIRO: + m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO, false ); + UseGalCanvas( true ); + break; + + case ID_MENU_CANVAS_OPENGL: + m_galCanvas->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL, false ); + UseGalCanvas( true ); + break; + } +#endif +} + + + void PCB_EDIT_FRAME::ShowDesignRulesEditor( wxCommandEvent& event ) { DIALOG_DESIGN_RULES dR_editor( this ); diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index a579b9ecbe..d6580786fb 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -266,6 +266,9 @@ enum pcbnew_ids ID_PCB_GEN_CMP_FILE, ID_MENU_PCB_SHOW_3D_FRAME, + ID_MENU_CANVAS_DEFAULT, + ID_MENU_CANVAS_OPENGL, + ID_MENU_CANVAS_CAIRO, ID_PCB_USER_GRID_SETUP, ID_PCB_GEN_BOM_FILE_FROM_BOARD, ID_PCB_LIB_TABLE_EDIT,