Fix broken symbol library alias root symbol links.
Check to see if the root symbol alias already exists before adding it to the symbol library alias list in the legacy schematic I/O plugin. There currently about six different ways that the root alias can be changed in the root symbol which causes issues. This really needs to be cleaned up. Use buffering when updating a symbol in a library to prevent the library file from being written before it is backed up. Update the alias and unit selection menubar drop down lists. Delete the output formatter so the file is closed so that reading the file time stamp can be performed to prevent unnecessary cache reloads. Fixes lp:1664834 https://bugs.launchpad.net/kicad/+bug/1664834
This commit is contained in:
parent
58ed5466b4
commit
9375e18fb6
|
@ -697,7 +697,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress )
|
|||
THROW_PARSE_ERROR( wxEmptyString, UTF8( __func__ ), UTF8( libs_not_found ), 0, 0 );
|
||||
}
|
||||
|
||||
#if defined(DEBUG) && 0
|
||||
#if defined(DEBUG) && 1
|
||||
printf( "%s: lib_names:\n", __func__ );
|
||||
|
||||
for( PART_LIBS::const_iterator it = begin(); it < end(); ++it )
|
||||
|
|
|
@ -321,7 +321,24 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
|
|||
if( GetScreen()->IsModify() )
|
||||
{
|
||||
if( IsOK( this, _( "Include last component changes?" ) ) )
|
||||
SaveOnePart( lib, false );
|
||||
{
|
||||
lib->EnableBuffering();
|
||||
|
||||
try
|
||||
{
|
||||
SaveOnePart( lib, false );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
lib->EnableBuffering( false );
|
||||
msg.Printf( _( "Unexpected error occured saving part to '%s' symbol library." ),
|
||||
lib->GetName() );
|
||||
DisplayError( this, msg );
|
||||
return false;
|
||||
}
|
||||
|
||||
lib->EnableBuffering( false );
|
||||
}
|
||||
}
|
||||
|
||||
if( newFile )
|
||||
|
@ -425,6 +442,8 @@ bool LIB_EDIT_FRAME::SaveActiveLibrary( bool newFile )
|
|||
wxString msg1;
|
||||
msg1.Printf( _( "Documentation file '%s' saved" ), GetChars( fn.GetFullPath() ) );
|
||||
AppendMsgPanel( msg, msg1, BLUE );
|
||||
UpdateAliasSelectList();
|
||||
UpdatePartSelectList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2141,6 +2141,9 @@ void SCH_LEGACY_PLUGIN_CACHE::Load()
|
|||
wxString::Format( "Cannot use relative file paths in legacy plugin to "
|
||||
"open library '%s'.", m_libFileName.GetFullPath() ) );
|
||||
|
||||
wxLogTrace( traceSchLegacyPlugin, "Loading legacy symbol file '%s'",
|
||||
m_libFileName.GetFullPath() );
|
||||
|
||||
FILE_LINE_READER reader( m_libFileName.GetFullPath() );
|
||||
|
||||
if( !reader.ReadLine() )
|
||||
|
@ -2385,6 +2388,14 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader )
|
|||
value.SetVisible( false );
|
||||
}
|
||||
|
||||
// There are some code paths in SetText() that do not set the root alias to the
|
||||
// alias list so add it here if it didn't get added by SetText().
|
||||
if( !part->HasAlias( part->GetName() ) )
|
||||
part->AddAlias( part->GetName() );
|
||||
|
||||
// Add the root alias to the cache alias list.
|
||||
m_aliases[ part->GetName() ] = part->GetAlias( part->GetName() );
|
||||
|
||||
LIB_FIELD& reference = part->GetReferenceField();
|
||||
|
||||
if( prefix == "~" )
|
||||
|
@ -2450,10 +2461,6 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader )
|
|||
loadFootprintFilters( part, aReader );
|
||||
else if( strCompare( "ENDDEF", line, &line ) ) // End of part description
|
||||
{
|
||||
// Add the root alias to the alias list.
|
||||
part->m_aliases.push_back( new LIB_ALIAS( name, part.get() ) );
|
||||
m_aliases[ part->GetName() ] = part->GetAlias( name );
|
||||
|
||||
return part.release();
|
||||
}
|
||||
|
||||
|
@ -3251,19 +3258,21 @@ void SCH_LEGACY_PLUGIN_CACHE::Save( bool aSaveDocFile )
|
|||
if( !m_isModified )
|
||||
return;
|
||||
|
||||
FILE_OUTPUTFORMATTER formatter( m_libFileName.GetFullPath() );
|
||||
formatter.Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
|
||||
formatter.Print( 0, "#encoding utf-8\n");
|
||||
std::unique_ptr< FILE_OUTPUTFORMATTER > formatter( new FILE_OUTPUTFORMATTER( m_libFileName.GetFullPath() ) );
|
||||
formatter->Print( 0, "%s %d.%d\n", LIBFILE_IDENT, LIB_VERSION_MAJOR, LIB_VERSION_MINOR );
|
||||
formatter->Print( 0, "#encoding utf-8\n");
|
||||
|
||||
for( LIB_ALIAS_MAP::iterator it = m_aliases.begin(); it != m_aliases.end(); it++ )
|
||||
{
|
||||
if( !it->second->IsRoot() )
|
||||
continue;
|
||||
|
||||
it->second->GetPart()->Save( formatter );
|
||||
it->second->GetPart()->Save( *formatter.get() );
|
||||
}
|
||||
|
||||
formatter.Print( 0, "#\n#End Library\n" );
|
||||
formatter->Print( 0, "#\n#End Library\n" );
|
||||
formatter.reset();
|
||||
|
||||
m_fileModTime = m_libFileName.GetModificationTime();
|
||||
m_isModified = false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue