Fix incorrect (broken) canvas type saving in config.

The config was saving a canvas type EDA_DRAW_FRAME member not always accurately initialized.
And the last canvas opened frame setup was saved, not necessary a frame having a canvas type that can be set by user.
This is a broken feature especially because the footprint viewer has a fixed canvas setting.
This commit is contained in:
jean-pierre charras 2019-01-11 13:19:46 +01:00
parent bd4222cc84
commit 644855c5ba
9 changed files with 90 additions and 42 deletions

View File

@ -46,7 +46,6 @@
#include <math/box2.h>
#include <lockfile.h>
#include <trace_helpers.h>
//#include "../eeschema/sch_draw_panel.h"
#include <wx/fontdlg.h>
#include <wx/snglinst.h>
#include <view/view.h>
@ -78,9 +77,6 @@ static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
///@{
/// \ingroup config
const wxChar EDA_DRAW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" );
static const wxString FirstRunShownKeyword( wxT( "FirstRunShown" ) );
///@}
@ -221,6 +217,7 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
{
delete m_socketServer;
for( auto socket : m_sockets )
{
socket->Shutdown();
@ -1072,7 +1069,7 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::LoadCanvasTypeSetting()
wxConfigBase* cfg = Kiface().KifaceSettings();
if( cfg )
canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY,
canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( GetCanvasTypeKey(),
EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
@ -1096,6 +1093,28 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::LoadCanvasTypeSetting()
bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
{
// Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
// have a fixed type, or do not have a option to set the canvas type (they inherit from
// a parent frame)
FRAME_T allowed_frames[] =
{
FRAME_SCH, FRAME_PCB, FRAME_PCB_MODULE_EDITOR
};
bool allow_save = false;
for( int ii = 0; ii < 3; ii++ )
{
if( m_Ident == allowed_frames[ii] )
{
allow_save = true;
break;
}
}
if( !allow_save )
return false;
if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
|| aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
{
@ -1106,7 +1125,7 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas
wxConfigBase* cfg = Kiface().KifaceSettings();
if( cfg )
return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType );
return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
return false;
}

View File

@ -81,9 +81,6 @@ static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
///@{
/// \ingroup config
const wxChar EDA_DRAW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" );
static const wxString FirstRunShownKeyword( wxT( "FirstRunShown" ) );
///@}
@ -1325,7 +1322,7 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::LoadCanvasTypeSetting()
wxConfigBase* cfg = Kiface().KifaceSettings();
if( cfg )
canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY,
canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( GetCanvasTypeKey(),
EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
@ -1349,17 +1346,39 @@ EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::LoadCanvasTypeSetting()
bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
{
// Not all classes derived from EDA_DRAW_FRAME can save the canvas type, because some
// have a fixed type, or do not have a option to set the canvas type (they inherit from
// a parent frame)
FRAME_T allowed_frames[] =
{
FRAME_SCH, FRAME_PCB, FRAME_PCB_MODULE_EDITOR
};
bool allow_save = false;
for( int ii = 0; ii < 3; ii++ )
{
if( m_Ident == allowed_frames[ii] )
{
allow_save = true;
break;
}
}
if( !allow_save )
return false;
if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
|| aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
{
assert( false );
wxASSERT( false );
return false;
}
wxConfigBase* cfg = Kiface().KifaceSettings();
if( cfg )
return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType );
return cfg->Write( GetCanvasTypeKey(), (long) aCanvasType );
return false;
}

View File

@ -58,10 +58,11 @@ class EDA_DRAW_PANEL_GAL : public wxScrolledCanvas
{
public:
enum GAL_TYPE {
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
GAL_TYPE_UNKNOWN = -1, ///< not specified: a GAL engine must be set by the client
GAL_TYPE_NONE = 0, ///< GAL not used (the legacy wxDC engine is 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,

View File

@ -60,14 +60,17 @@ namespace KIGFX
/// \ingroup config
/// User units
static const wxString UserUnitsEntryKeyword( wxT( "Units" ) );
#define UserUnitsEntryKeyword "Units"
/// Nonzero to show grid (suffix)
static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
#define ShowGridEntryKeyword "ShowGrid"
/// Grid color ID (suffix)
static const wxString GridColorEntryKeyword( wxT( "GridColor" ) );
#define GridColorEntryKeyword "GridColor"
/// Most recently used grid size (suffix)
static const wxString LastGridSizeIdKeyword( wxT( "_LastGridSize" ) );
#define LastGridSizeIdKeyword "_LastGridSize"
/// The key to store the canvas type in config. This is the base key.
/// can be a suffix if the canvas_type in config is specific to a frame
#define CanvasTypeKeyBase "canvas_type"
///@}
@ -230,8 +233,14 @@ protected:
bool saveCanvasImageToFile( const wxString& aFileName,
wxBitmapType aBitmapType = wxBITMAP_TYPE_PNG );
///> Key in KifaceSettings to store the canvas type.
static const wxChar CANVAS_TYPE_KEY[];
/** @return the key in KifaceSettings to store the canvas type.
* the base version returns only CanvasTypeKeyBase.
* Can be overriden to return a key specific of a frame name
*/
virtual wxString GetCanvasTypeKey()
{
return CanvasTypeKeyBase;
}
public:
EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
@ -893,7 +902,7 @@ public:
/**
* Returns the canvas type stored in the application settings.
*/
static EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting();
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting();
/**
* Use to switch between standard and GAL-based canvas.
@ -915,7 +924,7 @@ public:
*
* @return True for GAL-based canvas, false for standard canvas.
*/
bool IsGalCanvasActive() const { return m_galCanvasActive; }
bool IsGalCanvasActive() const { return m_galCanvasActive; }
/**
* Return a pointer to GAL-based canvas of given EDA draw frame.

View File

@ -622,8 +622,6 @@ public:
}
///> Key in KifaceSettings to store the canvas type.
static const wxChar CANVAS_TYPE_KEY[];
static const wxChar AUTO_ZOOM_KEY[];
static const wxChar ZOOM_KEY[];

View File

@ -228,8 +228,13 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
SetIcon( icon );
// Create GAL canvas
if( aBackend == EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN )
m_canvasType = LoadCanvasTypeSetting();
else
m_canvasType = aBackend;
PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
GetGalDisplayOptions(), aBackend );
GetGalDisplayOptions(), m_canvasType );
SetGalCanvas( drawPanel );
SetBoard( new BOARD() );
@ -317,7 +322,7 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
// Create the manager and dispatcher & route draw panel events to the dispatcher
setupTools();
GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
UseGalCanvas( aBackend != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
UseGalCanvas( m_canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
m_auimgr.Update();
updateTitle();

View File

@ -61,7 +61,6 @@
#include <tool/tool_dispatcher.h>
#include <tools/pcb_actions.h>
const wxChar PCB_BASE_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" );
const wxChar PCB_BASE_FRAME::AUTO_ZOOM_KEY[] = wxT( "AutoZoom" );
const wxChar PCB_BASE_FRAME::ZOOM_KEY[] = wxT( "Zoom" );
@ -126,6 +125,12 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
PCB_BASE_FRAME::~PCB_BASE_FRAME()
{
// Ensure m_canvasType is up to date, to save it in config
if( !GetGalCanvas() )
m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
else
m_canvasType = GetGalCanvas()->GetBackend();
delete m_Collector;
delete m_Pcb;
}

View File

@ -390,12 +390,12 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
Zoom_Automatique( false );
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = LoadCanvasTypeSetting();
m_canvasType = LoadCanvasTypeSetting();
// Nudge user to switch to OpenGL if they are on legacy or Cairo
if( m_firstRunDialogSetting < 1 )
{
if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
if( m_canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
{
wxString msg = _( "KiCad can use your graphics card to give you a smoother "
"and faster experience. This option is turned off by "
@ -439,9 +439,9 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
}
else
{
if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
if( m_canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE )
{
if( GetGalCanvas()->SwitchBackend( canvasType ) )
if( GetGalCanvas()->SwitchBackend( m_canvasType ) )
UseGalCanvas( true );
}
}

View File

@ -131,18 +131,10 @@ static struct IFACE : public KIFACE_I
case FRAME_PCB_MODULE_VIEWER:
case FRAME_PCB_MODULE_VIEWER_MODAL:
{
EDA_DRAW_PANEL_GAL::GAL_TYPE backend;
auto pcbFrame = static_cast<PCB_EDIT_FRAME*>( wxWindow::FindWindowByName( wxT( "Pcbnew" ) ) );
if( pcbFrame )
backend = pcbFrame->GetGalCanvas()->GetBackend();
else
backend = EDA_DRAW_FRAME::LoadCanvasTypeSetting();
switch( aClassId )
{
case FRAME_PCB_MODULE_EDITOR:
return new FOOTPRINT_EDIT_FRAME( aKiway, aParent, backend );
return new FOOTPRINT_EDIT_FRAME( aKiway, aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN );
case FRAME_PCB_MODULE_VIEWER:
case FRAME_PCB_MODULE_VIEWER_MODAL:
return new FOOTPRINT_VIEWER_FRAME( aKiway, aParent, FRAME_T( aClassId ) );