Save ModEdit's footprint ID rather than source.

This primarily keeps us from overriding "truth" with data that
might not have even been saved when closing ModEdit.

Fixes: lp:1752543
* https://bugs.launchpad.net/kicad/+bug/1752543
This commit is contained in:
Jeff Young 2018-03-09 01:31:30 +00:00
parent f1b48eb4f4
commit 308f28d2d4
2 changed files with 12 additions and 35 deletions

View File

@ -170,6 +170,8 @@ public:
PCB_LIB_NICKNAME, PCB_LIB_NICKNAME,
PCB_FOOTPRINT, PCB_FOOTPRINT,
PCB_FOOTPRINT_EDITOR_FPNAME,
PCB_FOOTPRINT_EDITOR_NICKNAME,
PCB_FOOTPRINT_VIEWER_FPNAME, PCB_FOOTPRINT_VIEWER_FPNAME,
PCB_FOOTPRINT_VIEWER_NICKNAME, PCB_FOOTPRINT_VIEWER_NICKNAME,

View File

@ -409,57 +409,32 @@ const wxString FOOTPRINT_EDIT_FRAME::GetCurrentLib() const
void FOOTPRINT_EDIT_FRAME::retainLastFootprint() void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
{ {
PCB_IO pcb_io;
MODULE* module = GetBoard()->m_Modules; MODULE* module = GetBoard()->m_Modules;
if( module ) if( module )
{ {
pcb_io.Format( module ); LIB_ID id = module->GetFPID();
Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME, id.GetLibNickname() );
wxString pretty = FROM_UTF8( pcb_io.GetStringOutput( true ).c_str() ); Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME, id.GetLibItemName() );
// save the footprint in the RSTRING facility.
Prj().SetRString( PROJECT::PCB_FOOTPRINT, pretty );
} }
} }
void FOOTPRINT_EDIT_FRAME::restoreLastFootprint() void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
{ {
wxString pretty = Prj().GetRString( PROJECT::PCB_FOOTPRINT ); const wxString& curFootprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME );
const wxString& curNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME );
if( !!pretty ) if( curNickname.Length() && curFootprintName.Length() )
{ {
PCB_IO pcb_io; LIB_ID id;
MODULE* module = NULL; id.SetLibNickname( curNickname );
id.SetLibItemName( curFootprintName );
try MODULE* module = loadFootprint( id );
{
module = (MODULE*) pcb_io.Parse( pretty );
}
catch( const PARSE_ERROR& )
{
// unlikely to be a problem, since we produced the pretty string.
wxLogError( "PARSE_ERROR" );
}
catch( const IO_ERROR& )
{
// unlikely to be a problem, since we produced the pretty string.
wxLogError( "IO_ERROR" );
}
if( module ) if( module )
{
// assumes BOARD is empty.
wxASSERT( GetBoard()->m_Modules == NULL );
// no idea, its monkey see monkey do. I would encapsulate this into
// a member function if its actually necessary.
module->SetParent( GetBoard() );
module->SetLink( 0 );
GetBoard()->Add( module ); GetBoard()->Add( module );
}
} }
} }