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
This commit is contained in:
John Beard 2019-02-08 14:34:53 +00:00
parent 076499f3ad
commit d06f0de1eb
3 changed files with 32 additions and 8 deletions

View File

@ -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;

View File

@ -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 );

View File

@ -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