mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-20 21:11:43 +00:00
Fix use of wrong variable.
The passed in footprint is a filter, not the current footprint from the iterator. Also cleaned up confusion and bad reporting over temp file usage, and need to const cast for updating embedded fonts.
This commit is contained in:
parent
cbccf6f027
commit
4e3175b244
pcbnew
@ -88,7 +88,7 @@ FP_CACHE::FP_CACHE( PCB_IO_KICAD_SEXPR* aOwner, const wxString& aLibraryPath )
|
||||
}
|
||||
|
||||
|
||||
void FP_CACHE::Save( FOOTPRINT* aFootprint )
|
||||
void FP_CACHE::Save( FOOTPRINT* aFootprintFilter )
|
||||
{
|
||||
m_cache_timestamp = 0;
|
||||
|
||||
@ -104,37 +104,41 @@ void FP_CACHE::Save( FOOTPRINT* aFootprint )
|
||||
m_lib_raw_path ) );
|
||||
}
|
||||
|
||||
for( FP_CACHE_FOOTPRINT_MAP::iterator it = m_footprints.begin(); it != m_footprints.end(); ++it )
|
||||
for( auto it = m_footprints.begin(); it != m_footprints.end(); ++it )
|
||||
{
|
||||
if( aFootprint && aFootprint != it->second->GetFootprint() )
|
||||
FP_CACHE_ITEM* fpCacheEntry = it->second;
|
||||
std::unique_ptr<FOOTPRINT>& footprint = fpCacheEntry->GetFootprint();
|
||||
|
||||
if( aFootprintFilter && footprint.get() != aFootprintFilter )
|
||||
continue;
|
||||
|
||||
// If we've requested to embed the fonts in the footprint, do so.
|
||||
// Otherwise, clear the embedded fonts from the footprint. Embedded
|
||||
// fonts will be used if available
|
||||
if( aFootprint->GetAreFontsEmbedded() )
|
||||
aFootprint->EmbedFonts();
|
||||
// If we've requested to embed the fonts in the footprint, do so. Otherwise, clear the
|
||||
// embedded fonts from the footprint. Embedded fonts will be used if available.
|
||||
if( footprint->GetAreFontsEmbedded() )
|
||||
footprint->EmbedFonts();
|
||||
else
|
||||
aFootprint->GetEmbeddedFiles()->ClearEmbeddedFonts();
|
||||
footprint->GetEmbeddedFiles()->ClearEmbeddedFonts();
|
||||
|
||||
WX_FILENAME fn = it->second->GetFileName();
|
||||
WX_FILENAME fn = fpCacheEntry->GetFileName();
|
||||
wxString fileName = fn.GetFullPath();
|
||||
|
||||
wxString tempFileName =
|
||||
#ifdef USE_TMP_FILE
|
||||
wxFileName::CreateTempFileName( fn.GetPath() );
|
||||
#else
|
||||
fn.GetFullPath();
|
||||
#endif
|
||||
// Allow file output stream to go out of scope to close the file stream before
|
||||
// renaming the file.
|
||||
{
|
||||
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file '%s'." ),
|
||||
tempFileName );
|
||||
#ifdef USE_TMP_FILE
|
||||
fileName = wxFileName::CreateTempFileName( fn.GetPath() );
|
||||
|
||||
PRETTIFIED_FILE_OUTPUTFORMATTER formatter( tempFileName );
|
||||
wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file '%s'." ),
|
||||
fileName );
|
||||
#else
|
||||
wxLogTrace( traceKicadPcbPlugin, wxT( "Writing library file '%s'." ),
|
||||
fileName );
|
||||
#endif
|
||||
|
||||
PRETTIFIED_FILE_OUTPUTFORMATTER formatter( fileName );
|
||||
|
||||
m_owner->SetOutputFormatter( &formatter );
|
||||
m_owner->Format( (BOARD_ITEM*) it->second->GetFootprint() );
|
||||
m_owner->Format( footprint.get() );
|
||||
}
|
||||
|
||||
#ifdef USE_TMP_FILE
|
||||
@ -145,12 +149,12 @@ void FP_CACHE::Save( FOOTPRINT* aFootprint )
|
||||
wxMilliSleep( 250L );
|
||||
|
||||
// Preserve the permissions of the current file
|
||||
KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), tempFileName );
|
||||
KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), fileName );
|
||||
|
||||
if( !wxRenameFile( tempFileName, fn.GetFullPath() ) )
|
||||
if( !wxRenameFile( fileName, fn.GetFullPath() ) )
|
||||
{
|
||||
wxString msg = wxString::Format( _( "Cannot rename temporary file '%s' to '%s'" ),
|
||||
tempFileName,
|
||||
fileName,
|
||||
fn.GetFullPath() );
|
||||
THROW_IO_ERROR( msg );
|
||||
}
|
||||
@ -161,7 +165,7 @@ void FP_CACHE::Save( FOOTPRINT* aFootprint )
|
||||
m_cache_timestamp += m_lib_path.GetModificationTime().GetValue().GetValue();
|
||||
|
||||
// If we've saved the full cache, we clear the dirty flag.
|
||||
if( !aFootprint )
|
||||
if( !aFootprintFilter )
|
||||
m_cache_dirty = false;
|
||||
}
|
||||
|
||||
@ -2817,13 +2821,13 @@ const FOOTPRINT* PCB_IO_KICAD_SEXPR::getFootprint( const wxString& aLibraryPath,
|
||||
// do nothing with the error
|
||||
}
|
||||
|
||||
FP_CACHE_FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
|
||||
FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( aFootprintName );
|
||||
FP_CACHE_FOOTPRINT_MAP& footprints = m_cache->GetFootprints();
|
||||
auto it = footprints.find( aFootprintName );
|
||||
|
||||
if( it == footprints.end() )
|
||||
return nullptr;
|
||||
|
||||
return it->second->GetFootprint();
|
||||
return it->second->GetFootprint().get();
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,8 +212,8 @@ public:
|
||||
FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName );
|
||||
|
||||
const WX_FILENAME& GetFileName() const { return m_filename; }
|
||||
void SetFilePath( const wxString& aFilePath ) { m_filename.SetPath( aFilePath ); }
|
||||
const FOOTPRINT* GetFootprint() const { return m_footprint.get(); }
|
||||
void SetFilePath( const wxString& aFilePath ) { m_filename.SetPath( aFilePath ); }
|
||||
std::unique_ptr<FOOTPRINT>& GetFootprint() { return m_footprint; }
|
||||
};
|
||||
|
||||
typedef boost::ptr_map<wxString, FP_CACHE_ITEM> FP_CACHE_FOOTPRINT_MAP;
|
||||
@ -248,9 +248,9 @@ public:
|
||||
/**
|
||||
* Save the footprint cache or a single footprint from it to disk
|
||||
*
|
||||
* @param aFootprint if set, save only this footprint, otherwise, save the full library
|
||||
* @param aFootprintFilter if set, save only this footprint, otherwise, save the full library
|
||||
*/
|
||||
void Save( FOOTPRINT* aFootprint = nullptr );
|
||||
void Save( FOOTPRINT* aFootprintFilter = nullptr );
|
||||
|
||||
void Load();
|
||||
|
||||
|
@ -1663,10 +1663,11 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
|
||||
FP_CACHE_FOOTPRINT_MAP& footprintMap = fpLib.GetFootprints();
|
||||
|
||||
bool singleFpPlotted = false;
|
||||
for( FP_CACHE_FOOTPRINT_MAP::iterator it = footprintMap.begin(); it != footprintMap.end();
|
||||
++it )
|
||||
|
||||
for( auto it = footprintMap.begin(); it != footprintMap.end(); ++it )
|
||||
{
|
||||
const FOOTPRINT* fp = it->second->GetFootprint();
|
||||
const std::unique_ptr<FOOTPRINT>& fp = it->second->GetFootprint();
|
||||
|
||||
if( !svgJob->m_footprint.IsEmpty() )
|
||||
{
|
||||
if( fp->GetFPID().GetLibItemName().wx_str() != svgJob->m_footprint )
|
||||
@ -1680,7 +1681,7 @@ int PCBNEW_JOBS_HANDLER::JobExportFpSvg( JOB* aJob )
|
||||
}
|
||||
}
|
||||
|
||||
exitCode = doFpExportSvg( svgJob, fp );
|
||||
exitCode = doFpExportSvg( svgJob, fp.get() );
|
||||
if( exitCode != CLI::EXIT_CODES::OK )
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user