kicad/eeschema/eelibs_read_libraryfiles.cpp

122 lines
3.3 KiB
C++
Raw Normal View History

/*****************************************************************/
/* Functions to handle component library files : read functions */
/*****************************************************************/
#include "fctsys.h"
#include "confirm.h"
#include "macros.h"
#include "appl_wxstruct.h"
#include "wxEeschemaStruct.h"
#include "general.h"
#include "class_library.h"
#include "dialog_load_error.h"
2007-12-05 20:54:11 +00:00
/**
* Function LoadLibraries
*
* Clear all already loaded libraries and load all of the project libraries.
*/
void WinEDA_SchematicFrame::LoadLibraries( void )
{
size_t ii;
wxFileName fn;
wxString msg, tmp, errMsg;
wxString libraries_not_found;
2009-10-05 19:17:32 +00:00
wxArrayString sortOrder;
CMP_LIBRARY_LIST::iterator i = CMP_LIBRARY::GetLibraryList().begin();
/* Free the unwanted libraries but keep the cache library. */
while ( i < CMP_LIBRARY::GetLibraryList().end() )
{
if( i->IsCache() )
{
i++;
continue;
}
if( m_ComponentLibFiles.Index( i->GetName(), false ) == wxNOT_FOUND )
i = CMP_LIBRARY::GetLibraryList().erase( i );
else
i++;
}
/* Load missing libraries. */
for( ii = 0; ii < m_ComponentLibFiles.GetCount(); ii++ )
{
fn = m_ComponentLibFiles[ii];
fn.SetExt( CompLibFileExtension );
/* Skip if the file name is not valid.. */
if( !fn.IsOk() )
continue;
if( !fn.FileExists() )
{
tmp = wxGetApp().FindLibraryPath( fn );
if( !tmp )
{
libraries_not_found += fn.GetName() + _( "\n" );
continue;
}
}
else
{
tmp = fn.GetFullPath();
}
// Loaded library statusbar message
msg = _( "Library " ) + tmp;
fn = tmp;
if( CMP_LIBRARY::AddLibrary( fn, errMsg ) )
{
msg += _( " loaded" );
2009-10-05 19:17:32 +00:00
sortOrder.Add( fn.GetName() );
}
else
{
wxString prompt;
prompt.Printf( _( "Component library <%s> failed to load.\nError: %s" ),
GetChars( fn.GetFullPath() ),
GetChars( errMsg ) );
DisplayError( this, prompt );
msg += _( " error!" );
}
PrintMsg( msg );
}
/* Print the libraries not found */
if( !libraries_not_found.IsEmpty() )
{
DIALOG_LOAD_ERROR dialog( this );
dialog.MessageSet( _( "The following libraries could not be found:" ) );
dialog.ListSet( libraries_not_found );
libraries_not_found.empty();
dialog.ShowModal();
}
2009-07-05 16:59:12 +00:00
/* Put the libraries in the correct order. */
2009-10-05 19:17:32 +00:00
CMP_LIBRARY::SetSortOrder( sortOrder );
CMP_LIBRARY::GetLibraryList().sort();
#if 0 // #ifdef __WXDEBUG__
wxLogDebug( wxT( "LoadLibraries() requested component library sort order:" ) );
2009-10-05 19:17:32 +00:00
for( size_t i = 0; i < sortOrder.GetCount(); i++ )
wxLogDebug( wxT( " " ) + sortOrder[i] );
wxLogDebug( wxT( "Real component library sort order:" ) );
for ( i = CMP_LIBRARY::GetLibraryList().begin();
i < CMP_LIBRARY::GetLibraryList().end(); i++ )
2009-10-05 19:17:32 +00:00
wxLogDebug( wxT( " " ) + i->GetName() );
wxLogDebug( wxT( "end LoadLibraries ()" ) );
#endif
}