From 6018bb662518ae5856b8853782b507f37ec593dc Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 7 Aug 2015 19:15:47 +0200 Subject: [PATCH] Pcbnew saves the type of used canvas. --- common/draw_panel_gal.cpp | 4 +++ include/class_draw_panel_gal.h | 1 + include/wxBasePcbFrame.h | 16 +++++++++++ pcbnew/basepcbframe.cpp | 52 ++++++++++++++++++++++++++++++++-- pcbnew/pcbframe.cpp | 10 ++++++- 5 files changed, 80 insertions(+), 3 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index d386184980..7b19d5499f 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -291,6 +291,10 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) case GAL_TYPE_NONE: return false; + + default: + assert( false ); + return false; } delete m_gal; diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index fc7ad8e35c..11c6cb153d 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -56,6 +56,7 @@ public: GAL_TYPE_NONE, ///< Not used GAL_TYPE_OPENGL, ///< OpenGL implementation GAL_TYPE_CAIRO, ///< Cairo implementation + GAL_TYPE_LAST ///< Sentinel, do not use as a parameter }; EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, const wxPoint& aPosition, diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 57be222adc..951c13a573 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -41,6 +41,7 @@ #include #include #include +#include /* Forward declarations of classes. */ @@ -681,6 +682,21 @@ public: */ void SwitchCanvas( wxCommandEvent& aEvent ); + /** + * Function LoadCanvasTypeSetting() + * Returns the canvas type stored in the application settings. + */ + EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting() const; + + /** + * Function SaveCanvasTypeSetting() + * Stores the canvas type in the application settings. + */ + bool SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ); + + ///> Key in KifaceSettings to store the canvas type. + static const wxString CANVAS_TYPE_KEY; + DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 3b9f4b19c6..95c4fc86c4 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -920,23 +920,30 @@ void PCB_BASE_FRAME::SetPrevGrid() void PCB_BASE_FRAME::SwitchCanvas( wxCommandEvent& aEvent ) { - int id = aEvent.GetId(); bool use_gal = false; + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; - switch( id ) + switch( aEvent.GetId() ) { case ID_MENU_CANVAS_DEFAULT: break; case ID_MENU_CANVAS_CAIRO: use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ); + + if( use_gal ) + canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; break; case ID_MENU_CANVAS_OPENGL: use_gal = GetGalCanvas()->SwitchBackend( EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL ); + + if( use_gal ) + canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL; break; } + SaveCanvasTypeSetting( canvasType ); UseGalCanvas( use_gal ); } @@ -971,3 +978,44 @@ void PCB_BASE_FRAME::UseGalCanvas( bool aEnable ) galCanvas->SetEventDispatcher( NULL ); } } + + +EDA_DRAW_PANEL_GAL::GAL_TYPE PCB_BASE_FRAME::LoadCanvasTypeSetting() const +{ + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; + + wxConfigBase* cfg = Kiface().KifaceSettings(); + + if( cfg ) + cfg->Read( CANVAS_TYPE_KEY, (long*) &canvasType ); + + if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE + || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) + { + assert( false ); + canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; + } + + return canvasType; +} + + +bool PCB_BASE_FRAME::SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) +{ + if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE + || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) + { + assert( false ); + return false; + } + + wxConfigBase* cfg = Kiface().KifaceSettings(); + + if( cfg ) + return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType ); + + return false; +} + + +const wxString PCB_BASE_FRAME::CANVAS_TYPE_KEY = wxT( "canvas_type" ); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 64d3ca26f7..e61efc9fda 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -321,6 +321,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_hasAutoSave = true; m_RecordingMacros = -1; m_microWaveToolBar = NULL; + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = LoadCanvasTypeSetting(); m_rotationAngle = 900; @@ -329,7 +330,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // Create GAL canvas SetGalCanvas( new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, - PCB_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ); + canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ? EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO : canvasType ) ); SetBoard( new BOARD() ); @@ -453,6 +454,13 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : enableGALSpecificMenus(); Zoom_Automatique( false ); + + if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ) + { + GetGalCanvas()->SwitchBackend( canvasType ); + UseGalCanvas( true ); + } + }