@ -2,8 +2,8 @@
* This program source code file is part of KiCad , a free EDA CAD application .
*
* Copyright ( C ) 2004 - 2016 Jean - Pierre Charras , jp . charras at wanadoo . fr
* Copyright ( C ) 2008 - 2016 Wayne Stambaugh < stambaughw @ verizon . net >
* Copyright ( C ) 2004 - 2016 KiCad Developers , see AUTHORS . txt for contributors .
* Copyright ( C ) 2008 - 2017 Wayne Stambaugh < stambaughw @ verizon . net >
* Copyright ( C ) 2004 - 2017 KiCad Developers , see AUTHORS . txt for contributors .
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
@ -39,6 +39,7 @@
# include <config_params.h>
# include <wildcards_and_files_ext.h>
# include <project_rescue.h>
# include <properties.h>
# include <general.h>
# include <class_library.h>
@ -53,10 +54,11 @@
" This may cause some unexpected behavior when loading components into a schematic. " )
PART_LIB : : PART_LIB ( int aType , const wxString & aFileName ) :
PART_LIB : : PART_LIB ( int aType , const wxString & aFileName , SCH_IO_MGR : : SCH_FILE_T aPluginType ) :
// start @ != 0 so each additional library added
// is immediately detectable, zero would not be.
m_mod_hash ( PART_LIBS : : s_modify_generation )
m_mod_hash ( PART_LIBS : : s_modify_generation ) ,
m_pluginType ( aPluginType )
{
type = aType ;
isModified = false ;
@ -65,411 +67,137 @@ PART_LIB::PART_LIB( int aType, const wxString& aFileName ) :
timeStamp = wxDateTime : : Now ( ) ;
versionMajor = 0 ; // Will be updated after reading the lib file
versionMinor = 0 ; // Will be updated after reading the lib file
m_buffering = false ;
fileName = aFileName ;
if ( ! fileName . IsOk ( ) )
fileName = " unnamed.lib " ;
m_plugin . reset ( SCH_IO_MGR : : FindPlugin ( m_pluginType ) ) ;
}
PART_LIB : : ~ PART_LIB ( )
{
// When the library is destroyed, all of the alias objects on the heap should be deleted.
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; + + it )
{
wxLogTrace ( traceSchLibMem , " Removing alias %s from library %s. " ,
GetChars ( it - > second - > GetName ( ) ) , GetChars ( GetLogicalName ( ) ) ) ;
LIB_PART * part = it - > second - > GetPart ( ) ;
LIB_ALIAS * alias = it - > second ;
delete alias ;
// When the last alias of a part is destroyed, the part is no longer required and it
// too is destroyed.
if ( part & & part - > GetAliasCount ( ) = = 0 )
delete part ;
}
m_amap . clear ( ) ;
}
void PART_LIB : : GetAliasNames ( wxArrayString & aNames )
void PART_LIB : : Save ( bool aSaveDocFile )
{
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; it + + )
{
aNames . Add ( ( * it ) . first ) ;
}
aNames . Sort ( ) ;
}
wxCHECK_RET ( m_plugin ! = NULL , wxString : : Format ( " no plugin defined for library `%s`. " ,
fileName . GetFullPath ( ) ) ) ;
std : : unique_ptr < PROPERTIES > props ;
void PART_LIB : : GetEntryTypePowerNames ( wxArrayString & aNames )
{
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; it + + )
if ( ! aSaveDocFile )
{
LIB_ALIAS * alias = it - > second ;
LIB_PART * root = alias - > GetPart ( ) ;
if ( ! root | | ! root - > IsPower ( ) )
continue ;
aNames . Add ( ( * it ) . first ) ;
props . reset ( new PROPERTIES ) ;
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropNoDocFile ] = " " ;
}
aNames . Sort ( ) ;
m_plugin - > SaveLibrary ( fileName . GetFullPath ( ) , props . get ( ) ) ;
}
LIB_ALIAS * PART_LIB : : FindAlias ( const wxString & aName )
void PART_LIB : : Create ( const wxString & aFile Name )
{
LIB_ALIAS_MAP : : iterator it = m_amap . find ( aName ) ;
if ( it ! = m_amap . end ( ) )
return it - > second ;
return NULL ;
}
std : : unique_ptr < PROPERTIES > props ;
LIB_PART * PART_LIB : : FindPart ( const wxString & aName )
{
#if 0 && defined(DEBUG)
if ( ! aName . Cmp ( " TI_STELLARIS_BOOSTERPACK " ) )
if ( isCache )
{
int breakhere = 1 ;
( void ) breakhere ;
props . reset ( new PROPERTIES ) ;
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropNoDocFile ] = " " ;
}
# endif
if ( LIB_ALIAS * alias = FindAlias ( aName ) )
{
return alias - > GetPart ( ) ;
}
return NULL ;
}
bool PART_LIB : : HasPowerParts ( )
{
// return true if at least one power part is found in lib
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; it + + )
{
LIB_ALIAS * alias = it - > second ;
LIB_PART * root = alias - > GetPart ( ) ;
wxString tmpFileName = fileName . GetFullPath ( ) ;
if ( root & & root - > IsPower ( ) )
return true ;
}
if ( ! aFileName . IsEmpty ( ) )
tmpFileName = aFileName ;
return false ;
m_plugin - > CreateSymbolLib ( tmpFileName , props . get ( ) ) ;
}
bool PART_LIB : : AddAlias ( LIB_ALIAS * aAlias )
void PART_LIB : : SetPluginType ( SCH_IO_MGR : : SCH_FILE_T aPluginType )
{
wxASSERT ( aAlias ) ;
# if defined(DEBUG) && 0
if ( ! aAlias - > GetName ( ) . Cmp ( " TI_STELLARIS_BOOSTERPACK " ) )
{
int breakhere = 1 ;
( void ) breakhere ;
}
# endif
LIB_ALIAS_MAP : : iterator it = m_amap . find ( aAlias - > GetName ( ) ) ;
if ( it ! = m_amap . end ( ) )
if ( m_pluginType ! = aPluginType )
{
wxString msg ;
msg . Printf ( _ ( " Cannot add duplicate alias '%s' to library '%s'. " ) ,
GetChars ( aAlias - > GetName ( ) ) ,
GetChars ( fileName . GetName ( ) ) ) ;
return false ;
m_pluginType = aPluginType ;
m_plugin . reset ( SCH_IO_MGR : : FindPlugin ( m_pluginType ) ) ;
}
wxString name = aAlias - > GetName ( ) ;
m_amap [ name ] = aAlias ;
isModified = true ;
+ + m_mod_hash ;
return true ;
}
void PART_LIB : : AddPart ( LIB_PART * aPart )
void PART_LIB : : GetAliasNames ( wxArrayString & aNames )
{
// add a clone, not the caller's copy
LIB_PART * my_part = new LIB_PART ( * aPart ) ;
m_plugin - > EnumerateSymbolLib ( aNames , fileName . GetFullPath ( ) ) ;
for ( size_t i = 0 ; i < my_part - > m_aliases . size ( ) ; i + + )
{
wxString aliasname = my_part - > m_aliases [ i ] - > GetName ( ) ;
if ( LIB_ALIAS * alias = FindAlias ( aliasname ) )
RemoveAlias ( alias ) ;
m_amap [ aliasname ] = my_part - > m_aliases [ i ] ;
}
isModified = true ;
+ + m_mod_hash ;
aNames . Sort ( ) ;
}
LIB_ALIAS * PART_LIB : : RemoveAlias ( LIB_ALIAS * aEntry )
void PART_LIB : : GetEntryTypePowerNames ( wxArrayString & aNames )
{
wxCHECK_MSG ( aEntry ! = NULL , NULL , " NULL pointer cannot be removed from library. " ) ;
LIB_ALIAS_MAP : : iterator it = m_amap . find ( aEntry - > GetName ( ) ) ;
if ( it = = m_amap . end ( ) )
return NULL ;
wxArrayString aliases ;
// If the entry pointer doesn't match the name it is mapped to in the library, we
// have done something terribly wrong.
wxCHECK_MSG ( * it - > second = = aEntry , NULL ,
" Pointer mismatch while attempting to remove entry < " +
aEntry - > GetName ( ) + " > from library < " + GetName ( ) + " >. " ) ;
m_plugin - > EnumerateSymbolLib ( aliases , fileName . GetFullPath ( ) ) ;
LIB_ALIAS * alias = aEntry ;
LIB_PART * part = alias - > GetPart ( ) ;
alias = part - > RemoveAlias ( alias ) ;
if ( ! alias )
for ( size_t i = 0 ; i < aliases . GetCount ( ) ; i + + )
{
delete part ;
LIB_ALIAS * alias = m_plugin - > LoadSymbol ( fileName . GetFullPath ( ) , aliases [ i ] ) ;
if ( m_amap . size ( ) > 1 )
{
LIB_ALIAS_MAP : : iterator next = it ;
next + + ;
wxCHECK2_MSG ( alias ! = NULL , continue ,
wxString : : Format ( " alias '%s' not found in symbol library '%s' " ,
aliases [ i ] , fileName . GetFullPath ( ) ) ) ;
if ( next = = m_amap . end ( ) )
next = m_amap . begin ( ) ;
alias = next - > second ;
}
}
m_amap . erase ( it ) ;
isModified = true ;
+ + m_mod_hash ;
return alias ;
}
LIB_PART * PART_LIB : : ReplacePart ( LIB_PART * aOldPart , LIB_PART * aNewPart )
{
wxASSERT ( aOldPart ! = NULL ) ;
wxASSERT ( aNewPart ! = NULL ) ;
/* Remove the old root component. The component will automatically be deleted
* when all it ' s aliases are deleted . Do not place any code that accesses
* aOldPart inside this loop that gets evaluated after the last alias is
* removed in RemoveAlias ( ) . Failure to heed this warning will result in a
* segfault .
*/
size_t i = aOldPart - > m_aliases . size ( ) ;
while ( i > 0 )
{
i - = 1 ;
RemoveAlias ( aOldPart - > m_aliases [ i ] ) ;
}
LIB_PART * root = alias - > GetPart ( ) ;
LIB_PART * my_part = new LIB_PART ( * aNewPart , this ) ;
if ( ! root | | ! root - > IsPower ( ) )
continue ;
// Add new aliases to library alias map.
for ( i = 0 ; i < my_part - > m_aliases . size ( ) ; i + + )
{
wxString aname = my_part - > m_aliases [ i ] - > GetName ( ) ;
m_amap [ aname ] = my_part - > m_aliases [ i ] ;
aNames . Add ( aliases [ i ] ) ;
}
isModified = true ;
+ + m_mod_hash ;
return my_part ;
aNames . Sort ( ) ;
}
bool PART_LIB : : Load ( wxString & aErrorMsg )
LIB_ALIAS * PART_LIB : : FindAlias ( const wxString & aName )
{
if ( fileName . GetFullPath ( ) . IsEmpty ( ) )
{
aErrorMsg = _ ( " The component library file name is not set. " ) ;
return false ;
}
FILE * file = wxFopen ( fileName . GetFullPath ( ) , " rt " ) ;
if ( file = = NULL )
{
aErrorMsg = _ ( " The file could not be opened. " ) ;
return false ;
}
FILE_LINE_READER reader ( file , fileName . GetFullPath ( ) ) ;
if ( ! reader . ReadLine ( ) )
{
aErrorMsg = _ ( " The file is empty! " ) ;
return false ;
}
// There is no header if this is a symbol library.
if ( type = = LIBRARY_TYPE_EESCHEMA )
{
char * line = reader . Line ( ) ;
header = FROM_UTF8 ( line ) ;
wxStringTokenizer tkn ( header ) ;
/*
* The file header ( first line ) in library versions 2.0 and lower
* apparently started with EESchema - LIB . Sometime after 2.0 , it
* was changed to EESchema - LIBRARY . Therefore , the test for
* EESchema - LIB will work in both cases . Don ' t change this unless
* backwards compatibility is no longer required .
*/
if ( ! tkn . HasMoreTokens ( )
| | ! tkn . GetNextToken ( ) . Upper ( ) . StartsWith ( " EESCHEMA-LIB " ) )
{
aErrorMsg = _ ( " The file is NOT an Eeschema library! " ) ;
return false ;
}
if ( ! tkn . HasMoreTokens ( ) )
{
aErrorMsg = _ ( " The file header is missing version and time stamp information. " ) ;
return false ;
}
if ( tkn . GetNextToken ( ) ! = " Version " | | ! tkn . HasMoreTokens ( ) )
{
aErrorMsg = " The file header version information is invalid. " ;
return false ;
}
long major , minor ;
wxStringTokenizer vers ( tkn . GetNextToken ( ) , " . " ) ;
if ( ! vers . HasMoreTokens ( ) | | ! vers . GetNextToken ( ) . ToLong ( & major )
| | major < 1L | | ! vers . HasMoreTokens ( )
| | ! vers . GetNextToken ( ) . ToLong ( & minor ) | | minor < 0L
| | minor > 99 )
{
#if 0 // Note for developers:
// Not sure this warning is very useful: old designs *must* be always loadable
wxLogWarning (
" The component library '%s' header version "
" number is invalid. \n \n In future versions of Eeschema this library may not "
" load correctly. To resolve this problem open the library in the library "
" editor and save it. If this library is the project cache library, save "
" the current schematic. " ,
GetChars ( GetName ( ) ) ) ;
# endif
}
else
{
versionMajor = ( int ) major ;
versionMinor = ( int ) minor ;
}
}
while ( reader . ReadLine ( ) )
{
char * line = reader . Line ( ) ;
if ( type = = LIBRARY_TYPE_EESCHEMA & & strncasecmp ( line , " $HEADER " , 7 ) = = 0 )
{
if ( ! LoadHeader ( reader ) )
{
aErrorMsg = _ ( " An error occurred attempting to read the header. " ) ;
return false ;
}
continue ;
}
wxString msg ;
if ( strncasecmp ( line , " DEF " , 3 ) = = 0 )
{
// Read one DEF/ENDDEF part entry from library:
LIB_PART * part = new LIB_PART ( wxEmptyString , this ) ;
if ( part - > Load ( reader , msg ) )
{
// Check for duplicate entry names and warn the user about
// the potential conflict.
if ( FindAlias ( part - > GetName ( ) ) ! = NULL )
{
wxLogWarning ( DUPLICATE_NAME_MSG ,
GetChars ( fileName . GetName ( ) ) ,
GetChars ( part - > GetName ( ) ) ) ;
}
LoadAliases ( part ) ;
}
else
{
wxLogWarning ( _ ( " Library '%s' component load error %s. " ) ,
GetChars ( fileName . GetName ( ) ) ,
GetChars ( msg ) ) ;
msg . Clear ( ) ;
delete part ;
}
}
}
+ + m_mod_hash ;
return true ;
return m_plugin - > LoadSymbol ( fileName . GetFullPath ( ) , aName ) ;
}
void PART_LIB : : LoadAliases ( LIB_PART * aPart )
LIB_PART * PART_LIB : : FindPart ( const wxString & aName )
{
wxCHECK_RET ( aPart , " Cannot load aliases of NULL part. Bad programmer! " ) ;
LIB_ALIAS * alias = FindAlias ( aName ) ;
for ( size_t i = 0 ; i < aPart - > m_aliases . size ( ) ; i + + )
{
if ( FindAlias ( aPart - > m_aliases [ i ] - > GetName ( ) ) ! = NULL )
{
wxLogError ( DUPLICATE_NAME_MSG ,
GetChars ( fileName . GetName ( ) ) ,
GetChars ( aPart - > m_aliases [ i ] - > GetName ( ) ) ) ;
}
if ( alias ! = NULL )
return alias - > GetPart ( ) ;
wxString aname = aPart - > m_aliases [ i ] - > GetName ( ) ;
m_amap [ aname ] = aPart - > m_aliases [ i ] ;
}
return NULL ;
}
bool PART_LIB : : LoadHeader ( LINE_READER & aLineReader )
bool PART_LIB : : HasPowerParts ( )
{
char * line , * text , * data ;
// return true if at least one power part is found in lib
wxArrayString aliases ;
m_plugin - > EnumerateSymbolLib ( aliases , fileName . GetFullPath ( ) ) ;
while ( aLineReader . ReadLine ( ) )
for ( size_t i = 0 ; i < aliases . GetCount ( ) ; i + + )
{
line = ( char * ) aLineReader ;
LIB_ALIAS * alias = m_plugin - > LoadSymbol ( fileName . GetFullPath ( ) , aliases [ i ] ) ;
text = strtok ( line , " \t \r \n " ) ;
data = strtok ( NULL , " \t \r \n " ) ;
wxCHECK2_MSG ( alias ! = NULL , continue ,
wxString : : Format ( " alias '%s' not found in symbol library '%s' " ,
aliases [ i ] , fileName . GetFullPath ( ) ) ) ;
if ( strcasecmp ( text , " TimeStamp " ) = = 0 )
timeStamp = atol ( data ) ;
LIB_PART * root = alias - > GetPart ( ) ;
if ( strcasecmp ( text , " $ENDHEADER " ) = = 0 )
if ( ! root | | root - > IsPower ( ) )
return true ;
}
@ -477,162 +205,93 @@ bool PART_LIB::LoadHeader( LINE_READER& aLineReader )
}
bool PART_LIB : : LoadDocs ( wxString & aErrorMsg )
void PART_LIB : : AddPart ( LIB_PART * aPart )
{
int lineNumber = 0 ;
char line [ 8000 ] , * name , * text ;
LIB_ALIAS * entry ;
FILE * file ;
wxFileName fn = fileName ;
fn . SetExt ( DOC_EXT ) ;
std : : unique_ptr < PROPERTIES > props ;
file = wxFopen ( fn . GetFullPath ( ) , " rt " ) ;
if ( file = = NULL )
if ( isCache | | m_buffering )
{
aErrorMsg . Printf ( _ ( " Could not open component document library file '%s'. " ) ,
GetChars ( fn . GetFullPath ( ) ) ) ;
return false ;
}
props . reset ( new PROPERTIES ) ;
if ( GetLine ( file , line , & lineNumber , sizeof ( line ) ) = = NULL )
{
aErrorMsg . Printf ( _ ( " Part document library file '%s' is empty. " ) ,
GetChars ( fn . GetFullPath ( ) ) ) ;
fclose ( file ) ;
return false ;
}
if ( isCache )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropNoDocFile ] = " " ;
if ( strncasecmp ( line , DOCFILE_IDENT , 10 ) ! = 0 )
{
aErrorMsg . Printf ( _ ( " File '%s' is not a valid component library document file. " ) ,
GetChars ( fn . GetFullPath ( ) ) ) ;
fclose ( file ) ;
return false ;
if ( m_buffering )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropBuffering ] = " " ;
}
while ( GetLine ( file , line , & lineNumber , sizeof ( line ) ) )
{
if ( strncmp ( line , " $CMP " , 4 ) ! = 0 )
{
aErrorMsg . Printf ( " $CMP command expected in line %d, aborted. " , lineNumber ) ;
fclose ( file ) ;
return false ;
}
// Read one $CMP/$ENDCMP part entry from library:
name = strtok ( line + 5 , " \n \r " ) ;
wxString cmpname = FROM_UTF8 ( name ) ;
entry = FindAlias ( cmpname ) ;
while ( GetLine ( file , line , & lineNumber , sizeof ( line ) ) )
{
if ( strncmp ( line , " $ENDCMP " , 7 ) = = 0 )
break ;
// add a clone, not the caller's copy, the plugin take ownership of the new symbol.
m_plugin - > SaveSymbol ( fileName . GetFullPath ( ) , new LIB_PART ( * aPart , this ) , props . get ( ) ) ;
text = strtok ( line + 2 , " \n \r " ) ;
// If we are not buffering, the library file is updated immediately when the plugin
// SaveSymbol() function is called.
if ( m_buffering )
isModified = true ;
if ( entry )
{
switch ( line [ 0 ] )
{
case ' D ' :
entry - > SetDescription ( FROM_UTF8 ( text ) ) ;
break ;
case ' K ' :
entry - > SetKeyWords ( FROM_UTF8 ( text ) ) ;
break ;
case ' F ' :
entry - > SetDocFileName ( FROM_UTF8 ( text ) ) ;
break ;
}
}
}
}
fclose ( file ) ;
return true ;
+ + m_mod_hash ;
}
bool PART_LIB : : Save ( OUTPUTFORMATTER & aFormatter )
LIB_ALIAS * PART_LIB : : RemoveAlias ( LIB_ALIAS * aEntry )
{
if ( isModified )
{
timeStamp = GetNewTimeStamp ( ) ;
isModified = false ;
}
wxCHECK_MSG ( aEntry ! = NULL , NULL , " NULL pointer cannot be removed from library. " ) ;
bool success = true ;
std : : unique_ptr < PROPERTIES > props ;
try
if ( isCache | | m_buffering )
{
SaveHeader ( aFormatter ) ;
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; it + + )
{
if ( ! it - > second - > IsRoot ( ) )
continue ;
props . reset ( new PROPERTIES ) ;
it - > second - > GetPart ( ) - > Save ( aFormatter ) ;
}
if ( isCache )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropNoDocFile ] = " " ;
aFormatter . Print ( 0 , " # \n #End Library \n " ) ;
}
catch ( const IO_ERROR & )
{
success = false ;
if ( m_buffering )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropBuffering ] = " " ;
}
return success ;
m_plugin - > DeleteAlias ( fileName . GetFullPath ( ) , aEntry - > GetName ( ) , props . get ( ) ) ;
// If we are not buffering, the library file is updated immediately when the plugin
// SaveSymbol() function is called.
if ( m_buffering )
isModified = true ;
+ + m_mod_hash ;
return NULL ;
}
bool PART_LIB : : SaveDocs ( OUTPUTFORMATTER & aFormatter )
LIB_PART * PART_LIB : : ReplacePart ( LIB_PART * aOldPart , LIB_PART * aNewPart )
{
bool success = true ;
wxASSERT ( aOldPart ! = NULL ) ;
wxASSERT ( aNewPart ! = NULL ) ;
std : : unique_ptr < PROPERTIES > props ;
try
if ( isCache | | m_buffering )
{
aFormatter . Print ( 0 , " %s \n " , DOCFILE_IDENT ) ;
props . reset ( new PROPERTIES ) ;
for ( LIB_ALIAS_MAP : : iterator it = m_amap . begin ( ) ; it ! = m_amap . end ( ) ; it + + )
{
if ( ! it - > second - > SaveDoc ( aFormatter ) )
success = false ;
}
if ( isCache )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropNoDocFile ] = " " ;
aFormatter . Print ( 0 , " # \n #End Doc Library \n " ) ;
}
catch ( const IO_ERROR & )
{
success = false ;
if ( m_buffering )
( * props . get ( ) ) [ SCH_LEGACY_PLUGIN : : PropBuffering ] = " " ;
}
return success ;
}
m_plugin - > DeleteSymbol ( fileName . GetFullPath ( ) , aOldPart - > GetName ( ) , props . get ( ) ) ;
bool PART_LIB : : SaveHeader ( OUTPUTFORMATTER & aFormatter )
{
aFormatter . Print ( 0 , " %s %d.%d \n " , LIBFILE_IDENT ,
LIB_VERSION_MAJOR , LIB_VERSION_MINOR ) ;
LIB_PART * my_part = new LIB_PART ( * aNewPart , this ) ;
aFormatter . Print ( 0 , " #encoding utf-8 \n " ) ;
m_plugin - > SaveSymbol ( fileName . GetFullPath ( ) , my_part , props . get ( ) ) ;
#if 0
aFormatter . Print ( 0 , " $HEADER \n " ) ;
aFormatter . Print ( 0 , " TimeStamp %8.8lX \n " , m_TimeStamp ) ;
aFormatter . Print ( 0 , " Parts %d \n " , m_amap . size ( ) ) ;
aFormatter . Print ( 0 , " $ENDHEADER \n " ) ! = 1 ) ;
# endif
// If we are not buffering, the library file is updated immediately when the plugin
// SaveSymbol() function is called.
if ( m_buffering )
isModified = true ;
return true ;
+ + m_mod_hash ;
return my_part ;
}
@ -640,32 +299,10 @@ PART_LIB* PART_LIB::LoadLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
{
std : : unique_ptr < PART_LIB > lib ( new PART_LIB ( LIBRARY_TYPE_EESCHEMA , aFileName ) ) ;
wxBusyCursor ShowWait ; // Do we want UI elements in PART_LIB?
wxString errorMsg ;
# ifdef KICAD_USE_SCH_IO_MANAGER
SCH_PLUGIN : : SCH_PLUGIN_RELEASER pi ( SCH_IO_MGR : : FindPlugin ( SCH_IO_MGR : : SCH_LEGACY ) ) ;
wxArrayString tmp ;
pi - > EnumerateSymbolLib ( tmp , aFileName ) ;
pi - > TransferCache ( * lib . get ( ) ) ;
# else
if ( ! lib - > Load ( errorMsg ) )
THROW_IO_ERROR ( errorMsg ) ;
if ( USE_OLD_DOC_FILE_FORMAT ( lib - > versionMajor , lib - > versionMinor ) )
{
# if 1
// not fatal if error here.
lib - > LoadDocs ( errorMsg ) ;
# else
if ( ! lib - > LoadDocs ( errorMsg ) )
THROW_IO_ERROR ( errorMsg ) ;
# endif
}
# endif
// This loads the library although we could probably do lazy loading.
lib - > GetCount ( ) ;
PART_LIB * ret = lib . release ( ) ;
@ -774,7 +411,7 @@ LIB_ALIAS* PART_LIBS::FindLibraryAlias( const wxString& aEntryName, const wxStri
for ( PART_LIB & lib : * this )
{
if ( ! ! aLibraryName & & lib . GetName ( ) ! = aLibraryName )
if ( ! aLibraryName . IsEmpty ( ) & & lib . GetName ( ) ! = aLibraryName )
continue ;
entry = lib . FindAlias ( aEntryName ) ;
@ -796,7 +433,7 @@ void PART_LIBS::FindLibraryNearEntries( std::vector<LIB_ALIAS*>& aCandidates,
{
for ( PART_LIB & lib : * this )
{
if ( ! ! aLibraryName & & lib . GetName ( ) ! = aLibraryName )
if ( ! aLibraryName . IsEmpty ( ) & & lib . GetName ( ) ! = aLibraryName )
continue ;
wxArrayString aliasNames ;
@ -824,7 +461,7 @@ int PART_LIBS::GetModifyHash()
for ( PART_LIBS : : const_iterator it = begin ( ) ; it ! = end ( ) ; + + it )
{
hash + = it - > m_mod_hash ;
hash + = it - > GetModHash ( ) ;
}
return hash ;
@ -907,7 +544,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) throw(
wxString libs_not_found ;
SEARCH_STACK * lib_search = aProject - > SchSearchS ( ) ;
# if defined(DEBUG) && 1
# if defined(DEBUG) && 0
lib_search - > Show ( __func__ ) ;
# endif
@ -977,9 +614,9 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) throw(
}
catch ( const IO_ERROR & ioe )
{
wxString msg = wxString : : Format ( _ (
" Part library '%s' failed to load. Error: \n %s " ) ,
GetChars ( filename ) , GetChars ( ioe . What ( ) ) ) ;
wxString msg ;
msg . Printf ( _ ( " Part library '%s' failed to load. Error: \n %s " ) ,
GetChars ( filename ) , GetChars ( ioe . What ( ) ) ) ;
wxLogError ( msg ) ;
}
@ -994,7 +631,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) throw(
wxString cache_name = CacheName ( aProject - > GetProjectFullName ( ) ) ;
PART_LIB * cache_lib ;
if ( ! ! cache_name )
if ( ! cache_name . IsEmpty ( ) )
{
try
{
@ -1016,15 +653,14 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) throw(
}
// Print the libraries not found
if ( ! ! libs_not_found )
if ( ! libs_not_found . IsEmpty ( ) )
{
// Use a different exception type so catch()er can route to proper use
// of the HTML_MESSAGE_BOX.
THROW_PARSE_ERROR ( wxEmptyString , UTF8 ( __func__ ) ,
UTF8 ( libs_not_found ) , 0 , 0 ) ;
THROW_PARSE_ERROR ( wxEmptyString , UTF8 ( __func__ ) , UTF8 ( libs_not_found ) , 0 , 0 ) ;
}
# if defined(DEBUG) && 1
# if defined(DEBUG) && 0
printf ( " %s: lib_names: \n " , __func__ ) ;
for ( PART_LIBS : : const_iterator it = begin ( ) ; it < end ( ) ; + + it )