From d06f0de1eb0f6aa911256c765b2aec9cdf18a0bf Mon Sep 17 00:00:00 2001 From: John Beard Date: Fri, 8 Feb 2019 14:34:53 +0000 Subject: [PATCH] Libedit: transfer current screen settings on part load When loading a part in libedit, also transfer certain screen settings to the incoming SCH_SCREEN, from the current SCH_SCREEN. Currently, the grid settings are transferred, but this could also do other settings if needed. Also remove some duplicate commentary and mention why the grid is set in a SCH_SCREEN even though the BASE_SCREEN ctor sets the same default. Fixes: lp:1815108 * https://bugs.launchpad.net/kicad/+bug/1815108 --- common/base_screen.cpp | 6 +----- eeschema/libedit/libedit.cpp | 30 ++++++++++++++++++++++++++++-- eeschema/sch_screen.cpp | 4 +++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/common/base_screen.cpp b/common/base_screen.cpp index 3a77b43a4d..9d38cf5f98 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -174,11 +174,7 @@ bool BASE_SCREEN::SetPreviousZoom() return false; } -/* Build the list of human readable grid list. - * The list shows the grid size both in mils or mm. - * aMmFirst = true to have mm first and mils after - * false to have mils first and mm after - */ + int BASE_SCREEN::BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const { wxString msg; diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index d2951b1d4b..fc701b2388 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -151,6 +151,22 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, in return true; } +/** + * Synchronise screen settings from a current screen into another screen. + * + * This can be used, for example, when loading a new screen into a frame, + * but you want the new screen to inherit some settings (e.g. grids) from the + * frame's current screen. + * + * @param aCurrentScreen the existing frame screen + * @param aIncomingScreen a screen that is intended to replace the current screen + */ +static void synchronizeLibEditScreenSettings( + const SCH_SCREEN& aCurrentScreen, SCH_SCREEN& aIncomingScreen ) +{ + aIncomingScreen.SetGrid( aCurrentScreen.GetGridSize() ); +} + bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& aLibrary, int aUnit, int aConvert ) @@ -172,8 +188,18 @@ bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, const wxString& a m_unit = aUnit > 0 ? aUnit : 1; m_convert = aConvert > 0 ? aConvert : 1; - auto s = m_libMgr->GetScreen( lib_part->GetName(), aLibrary ); - SetScreen( s ); + // The buffered screen for the part + SCH_SCREEN* part_screen = m_libMgr->GetScreen( lib_part->GetName(), aLibrary ); + + const SCH_SCREEN* curr_screen = GetScreen(); + + // Before we set the frame screen, transfer any settings from the current + // screen that we want to keep to the incoming (buffered) part's screen + // which could be out of date relative to the current screen. + if( curr_screen ) + synchronizeLibEditScreenSettings( *curr_screen, *part_screen ); + + SetScreen( part_screen ); SetCurPart( new LIB_PART( *lib_part ) ); SetCurLib( aLibrary ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index d0846e7ac7..a79d398fad 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -105,7 +105,9 @@ SCH_SCREEN::SCH_SCREEN( KIWAY* aKiway ) : for( unsigned i = 0; i < arrayDim( SchematicGridList ); i++ ) AddGrid( SchematicGridList[i] ); - SetGrid( wxRealPoint( 50, 50 ) ); // Default grid size. + // Set the default grid size, now that the grid list is populated + SetGrid( wxRealPoint( 50, 50 ) ); + m_refCount = 0; // Suitable for schematic only. For libedit and viewlib, must be set to true