Eeschema: more schematic I/O plugin prep work.

Add code to schematic I/O plugin for updating library modification
hashes.

Remove unused RemoveLibrary() method from PART_LIBS object.

Purge wxT() macros from modified files.
This commit is contained in:
Wayne Stambaugh 2016-10-24 19:18:50 -04:00
parent 89f9b7df5c
commit 4ee0b3827e
5 changed files with 62 additions and 61 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@ -68,7 +68,7 @@ PART_LIB::PART_LIB( int aType, const wxString& aFileName ) :
fileName = aFileName;
if( !fileName.IsOk() )
fileName = wxT( "unnamed.lib" );
fileName = "unnamed.lib";
}
@ -77,7 +77,7 @@ 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, wxT( "Removing alias %s from library %s." ),
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;
@ -124,7 +124,7 @@ void PART_LIB::GetEntryTypePowerNames( wxArrayString& aNames )
bool PART_LIB::Conflicts( LIB_PART* aPart )
{
wxCHECK_MSG( aPart != NULL, false,
wxT( "Cannot test NULL component for conflicts in library " ) + GetName() );
"Cannot test NULL component for conflicts in library " + GetName() );
for( size_t i=0; i<aPart->m_aliases.size(); i++ )
{
@ -152,7 +152,7 @@ LIB_ALIAS* PART_LIB::FindAlias( const wxString& aName )
LIB_PART* PART_LIB::FindPart( const wxString& aName )
{
#if 0 && defined(DEBUG)
if( !aName.Cmp( wxT( "TI_STELLARIS_BOOSTERPACK" ) ) )
if( !aName.Cmp( "TI_STELLARIS_BOOSTERPACK" ) )
{
int breakhere = 1;
(void) breakhere;
@ -189,7 +189,7 @@ bool PART_LIB::AddAlias( LIB_ALIAS* aAlias )
wxASSERT( aAlias );
#if defined(DEBUG) && 0
if( !aAlias->GetName().Cmp( wxT( "TI_STELLARIS_BOOSTERPACK" ) ) )
if( !aAlias->GetName().Cmp( "TI_STELLARIS_BOOSTERPACK" ) )
{
int breakhere = 1;
(void) breakhere;
@ -227,8 +227,8 @@ bool PART_LIB::AddPart( LIB_PART* aPart )
// and user is not prompted )
if( Conflicts( aPart ) && !IsCache() )
{
wxFAIL_MSG( wxT( "Cannot add component <" ) + aPart->GetName() +
wxT( "> to library <" ) + GetName() + wxT( "> due to name conflict." ) );
wxFAIL_MSG( "Cannot add component <" + aPart->GetName() +
"> to library <" + GetName() + "> due to name conflict." );
return false;
}
@ -254,7 +254,7 @@ bool PART_LIB::AddPart( LIB_PART* aPart )
LIB_ALIAS* PART_LIB::RemoveAlias( LIB_ALIAS* aEntry )
{
wxCHECK_MSG( aEntry != NULL, NULL, wxT( "NULL pointer cannot be removed from library." ) );
wxCHECK_MSG( aEntry != NULL, NULL, "NULL pointer cannot be removed from library." );
LIB_ALIAS_MAP::iterator it = m_amap.find( aEntry->GetName() );
@ -264,8 +264,8 @@ LIB_ALIAS* PART_LIB::RemoveAlias( LIB_ALIAS* aEntry )
// 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,
wxT( "Pointer mismatch while attempting to remove entry <" ) +
aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) );
"Pointer mismatch while attempting to remove entry <" +
aEntry->GetName() + "> from library <" + GetName() + ">." );
LIB_ALIAS* alias = aEntry;
LIB_PART* part = alias->GetPart();
@ -337,7 +337,7 @@ bool PART_LIB::Load( wxString& aErrorMsg )
return false;
}
FILE* file = wxFopen( fileName.GetFullPath(), wxT( "rt" ) );
FILE* file = wxFopen( fileName.GetFullPath(), "rt" );
if( file == NULL )
{
@ -370,7 +370,7 @@ bool PART_LIB::Load( wxString& aErrorMsg )
* backwards compatibility is no longer required.
*/
if( !tkn.HasMoreTokens()
|| !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) )
|| !tkn.GetNextToken().Upper().StartsWith( "EESCHEMA-LIB" ) )
{
aErrorMsg = _( "The file is NOT an Eeschema library!" );
return false;
@ -382,14 +382,14 @@ bool PART_LIB::Load( wxString& aErrorMsg )
return false;
}
if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() )
if( tkn.GetNextToken() != "Version" || !tkn.HasMoreTokens() )
{
aErrorMsg = wxT( "The file header version information is invalid." );
aErrorMsg = "The file header version information is invalid.";
return false;
}
long major, minor;
wxStringTokenizer vers( tkn.GetNextToken(), wxT( "." ) );
wxStringTokenizer vers( tkn.GetNextToken(), "." );
if( !vers.HasMoreTokens() || !vers.GetNextToken().ToLong( &major )
|| major < 1L || !vers.HasMoreTokens()
@ -398,12 +398,12 @@ bool PART_LIB::Load( wxString& aErrorMsg )
{
#if 0 // Note for developers:
// Not sure this warning is very useful: old designs *must* be always loadable
wxLogWarning( wxT(
wxLogWarning(
"The component library '%s' header version "
"number is invalid.\n\nIn 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." ),
"the current schematic.",
GetChars( GetName() ) );
#endif
}
@ -468,7 +468,7 @@ bool PART_LIB::Load( wxString& aErrorMsg )
void PART_LIB::LoadAliases( LIB_PART* aPart )
{
wxCHECK_RET( aPart, wxT( "Cannot load aliases of NULL part. Bad programmer!" ) );
wxCHECK_RET( aPart, "Cannot load aliases of NULL part. Bad programmer!" );
for( size_t i = 0; i < aPart->m_aliases.size(); i++ )
{
@ -517,7 +517,7 @@ bool PART_LIB::LoadDocs( wxString& aErrorMsg )
fn.SetExt( DOC_EXT );
file = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
file = wxFopen( fn.GetFullPath(), "rt" );
if( file == NULL )
{
@ -546,7 +546,7 @@ bool PART_LIB::LoadDocs( wxString& aErrorMsg )
{
if( strncmp( line, "$CMP", 4 ) != 0 )
{
aErrorMsg.Printf( wxT( "$CMP command expected in line %d, aborted." ), lineNumber );
aErrorMsg.Printf( "$CMP command expected in line %d, aborted.", lineNumber );
fclose( file );
return false;
}
@ -707,14 +707,12 @@ PART_LIB* PART_LIBS::AddLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
{
PART_LIB* lib;
#if 1
wxFileName fn = aFileName;
// Don't reload the library if it is already loaded.
lib = FindLibrary( fn.GetName() );
if( lib )
return lib;
#endif
lib = PART_LIB::LoadLibrary( aFileName );
@ -727,14 +725,12 @@ PART_LIB* PART_LIBS::AddLibrary( const wxString& aFileName ) throw( IO_ERROR, bo
PART_LIB* PART_LIBS::AddLibrary( const wxString& aFileName, PART_LIBS::iterator& aIterator )
throw( IO_ERROR, boost::bad_pointer )
{
#if 1
// Don't reload the library if it is already loaded.
wxFileName fn( aFileName );
PART_LIB* lib = FindLibrary( fn.GetName() );
if( lib )
return lib;
#endif
lib = PART_LIB::LoadLibrary( aFileName );
@ -747,22 +743,6 @@ PART_LIB* PART_LIBS::AddLibrary( const wxString& aFileName, PART_LIBS::iterator&
}
void PART_LIBS::RemoveLibrary( const wxString& aName )
{
if( aName.IsEmpty() )
return;
for( PART_LIBS::iterator it = begin(); it < end(); ++it )
{
if( it->GetName().CmpNoCase( aName ) == 0 )
{
erase( it );
return;
}
}
}
PART_LIB* PART_LIBS::FindLibrary( const wxString& aName )
{
for( PART_LIBS::iterator it = begin(); it!=end(); ++it )
@ -890,7 +870,7 @@ void PART_LIBS::LibNamesAndPaths( PROJECT* aProject, bool doSave,
PARAM_CFG_ARRAY ca;
if( aPaths )
ca.push_back( new PARAM_CFG_FILENAME( wxT( "LibDir" ), aPaths ) );
ca.push_back( new PARAM_CFG_FILENAME( "LibDir", aPaths ) );
if( aNames )
ca.push_back( new PARAM_CFG_LIBNAME_LIST( wxT( "LibName" ), aNames, GROUP_SCH_LIBS ) );
@ -931,7 +911,7 @@ const wxString PART_LIBS::CacheName( const wxString& aFullProjectFilename )
*/
wxFileName new_name = aFullProjectFilename;
new_name.SetName( new_name.GetName() + wxT( "-cache" ) );
new_name.SetName( new_name.GetName() + "-cache" );
new_name.SetExt( SchematicLibraryFileExtension );
if( new_name.FileExists() )
@ -939,7 +919,7 @@ const wxString PART_LIBS::CacheName( const wxString& aFullProjectFilename )
else
{
wxFileName old_name = aFullProjectFilename;
old_name.SetExt( wxT( "cache.lib" ) );
old_name.SetExt( "cache.lib" );
if( old_name.FileExists() )
{
@ -968,7 +948,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject ) throw( IO_ERROR, boost::ba
// If the list is empty, force loading the standard power symbol library.
if( !lib_names.GetCount() )
lib_names.Add( wxT( "power" ) );
lib_names.Add( "power" );
wxASSERT( !size() ); // expect to load into "this" empty container.
@ -989,7 +969,7 @@ void PART_LIBS::LoadAllLibraries( PROJECT* aProject ) throw( IO_ERROR, boost::ba
if( !filename )
{
libs_not_found += fn.GetName();
libs_not_found += wxT( '\n' );
libs_not_found += '\n';
continue;
}
}

View File

@ -2,8 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2016 KiCad Developers, see change_log.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
@ -73,7 +73,7 @@ class SCH_LEGACY_PLUGIN;
/* Must be the first line of part library document (.dcm) files. */
#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0"
#define DOC_EXT wxT( "dcm" )
#define DOC_EXT "dcm"
// Helper class to filter a list of libraries, and/or a list of PART_LIB
// in dialogs
@ -225,14 +225,6 @@ public:
PART_LIB* AddLibrary( const wxString& aFileName, PART_LIBS::iterator& aIterator )
throw( IO_ERROR, boost::bad_pointer );
/**
* Function RemoveLibrary
* removes a part library from the library list.
*
* @param aName - Name of part library to remove.
*/
void RemoveLibrary( const wxString& aName );
/**
* Function LoadAllLibraries
* loads all of the project's libraries into this container, which should
@ -287,7 +279,8 @@ public:
* @param aLibraryName - Name of the library to search for part.
* @return LIB_PART* - The part object if found, otherwise NULL.
*/
LIB_PART* FindLibPart( const wxString& aPartName, const wxString& aLibraryName = wxEmptyString );
LIB_PART* FindLibPart( const wxString& aPartName,
const wxString& aLibraryName = wxEmptyString );
/**
* Function FindLibraryEntry
@ -300,7 +293,7 @@ public:
* @return The entry object if found, otherwise NULL.
*/
LIB_ALIAS* FindLibraryAlias( const wxString& aEntryName,
const wxString& aLibraryName = wxEmptyString );
const wxString& aLibraryName = wxEmptyString );
/**
* Function FindLibraryNearEntries
@ -316,7 +309,7 @@ public:
* @param aCandidates - a std::vector to store candidates
*/
void FindLibraryNearEntries( std::vector<LIB_ALIAS*>& aCandidates, const wxString& aEntryName,
const wxString& aLibraryName = wxEmptyString );
const wxString& aLibraryName = wxEmptyString );
int GetLibraryCount() { return size(); }
};

View File

@ -203,6 +203,19 @@ public:
*/
virtual const wxString GetFileExtension() const = 0;
/**
* Function GetModifyHash
*
* returns the modification hash from the library cache.
*
* @note This is temporary until the new s-expr file format is implement. The new file
* format will embed symbols instead of referencing them from the library. This
* function can be removed when the new file format is implemented.
*
* @return the modification hash of the library cache.
*/
virtual int GetModifyHash() const = 0;
/**
* Function Load
*

View File

@ -1950,6 +1950,8 @@ public:
SCH_LEGACY_PLUGIN_CACHE( const wxString& aLibraryPath );
~SCH_LEGACY_PLUGIN_CACHE();
int GetModifyHash() const { return m_modHash; }
// Most all functions in this class throw IO_ERROR exceptions. There are no
// error codes nor user interface calls from here, nor in any SCH_PLUGIN objects.
// Catch these exceptions higher up please.
@ -1978,7 +1980,8 @@ public:
SCH_LEGACY_PLUGIN_CACHE::SCH_LEGACY_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
m_libFileName( aFullPathAndFileName ),
m_isWritable( true ),
m_isModified( false )
m_isModified( false ),
m_modHash( 1 )
{
m_versionMajor = -1;
m_versionMinor = -1;
@ -3288,6 +3291,16 @@ void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName )
}
int SCH_LEGACY_PLUGIN::GetModifyHash() const
{
if( m_cache )
return m_cache->GetModifyHash();
// If the cache hasn't been loaded, it hasn't been modified.
return 0;
}
void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList,
const wxString& aLibraryPath,
const PROPERTIES* aProperties )

View File

@ -75,6 +75,8 @@ public:
return wxT( "sch" );
}
int GetModifyHash() const override;
SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ) override;