2011-10-02 20:24:41 +00:00
|
|
|
/**
|
|
|
|
* @file eelibs_read_libraryfiles.cpp
|
|
|
|
* @brief Functions to handle reading component library files.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <class_library.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <html_messagebox.h>
|
2009-07-13 06:20:18 +00:00
|
|
|
|
2007-12-05 20:54:11 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::LoadLibraries( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
size_t ii;
|
2009-08-19 19:34:03 +00:00
|
|
|
wxFileName fn;
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg, tmp, errMsg;
|
2009-08-19 19:34:03 +00:00
|
|
|
wxString libraries_not_found;
|
2009-10-05 19:17:32 +00:00
|
|
|
wxArrayString sortOrder;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY_LIST::iterator i = CMP_LIBRARY::GetLibraryList().begin();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/* Free the unwanted libraries but keep the cache library. */
|
|
|
|
while ( i < CMP_LIBRARY::GetLibraryList().end() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
if( i->IsCache() )
|
|
|
|
{
|
|
|
|
i++;
|
2007-08-24 15:10:46 +00:00
|
|
|
continue;
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2011-12-09 16:37:11 +00:00
|
|
|
if( m_componentLibFiles.Index( i->GetName(), false ) == wxNOT_FOUND )
|
2009-09-18 14:56:05 +00:00
|
|
|
i = CMP_LIBRARY::GetLibraryList().erase( i );
|
|
|
|
else
|
|
|
|
i++;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/* Load missing libraries. */
|
2011-12-09 16:37:11 +00:00
|
|
|
for( ii = 0; ii < m_componentLibFiles.GetCount(); ii++ )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2011-10-02 20:24:41 +00:00
|
|
|
fn.Clear();
|
2011-12-09 16:37:11 +00:00
|
|
|
fn.SetName( m_componentLibFiles[ii] );
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( CompLibFileExtension );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/* Skip if the file name is not valid.. */
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !fn.IsOk() )
|
2007-08-24 15:10:46 +00:00
|
|
|
continue;
|
2007-11-02 17:17:44 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !fn.FileExists() )
|
|
|
|
{
|
2009-04-08 18:06:22 +00:00
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2011-10-02 20:24:41 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( !tmp )
|
|
|
|
{
|
2009-08-19 19:34:03 +00:00
|
|
|
libraries_not_found += fn.GetName() + _( "\n" );
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp = fn.GetFullPath();
|
|
|
|
}
|
2007-11-02 17:17:44 +00:00
|
|
|
|
2008-10-05 10:56:43 +00:00
|
|
|
// Loaded library statusbar message
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Library " ) + tmp;
|
2009-09-18 14:56:05 +00:00
|
|
|
fn = tmp;
|
2007-11-02 17:17:44 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
if( CMP_LIBRARY::AddLibrary( fn, errMsg ) )
|
|
|
|
{
|
2008-10-05 10:56:43 +00:00
|
|
|
msg += _( " loaded" );
|
2009-10-05 19:17:32 +00:00
|
|
|
sortOrder.Add( fn.GetName() );
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
else
|
2009-09-18 14:56:05 +00:00
|
|
|
{
|
|
|
|
wxString prompt;
|
|
|
|
|
2010-11-01 18:33:44 +00:00
|
|
|
prompt.Printf( _( "Component library <%s> failed to load.\nError: %s" ),
|
2009-10-16 17:18:23 +00:00
|
|
|
GetChars( fn.GetFullPath() ),
|
|
|
|
GetChars( errMsg ) );
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayError( this, prompt );
|
2008-10-05 10:56:43 +00:00
|
|
|
msg += _( " error!" );
|
2009-09-18 14:56:05 +00:00
|
|
|
}
|
2007-11-02 17:17:44 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
PrintMsg( msg );
|
2009-04-10 14:57:10 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-08-19 19:34:03 +00:00
|
|
|
/* Print the libraries not found */
|
|
|
|
if( !libraries_not_found.IsEmpty() )
|
|
|
|
{
|
2011-09-04 18:35:14 +00:00
|
|
|
HTML_MESSAGE_BOX dialog( this, _("Files not found") );
|
2009-08-19 19:34:03 +00:00
|
|
|
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
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
/* Put the libraries in the correct order. */
|
2009-10-05 19:17:32 +00:00
|
|
|
CMP_LIBRARY::SetSortOrder( sortOrder );
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY::GetLibraryList().sort();
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-11-07 20:06:07 +00:00
|
|
|
#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++ )
|
2011-10-02 20:24:41 +00:00
|
|
|
wxLogDebug( wxT( " " ) + sortOrder[i] );
|
2009-10-05 19:17:32 +00:00
|
|
|
|
2010-02-15 14:24:52 +00:00
|
|
|
wxLogDebug( wxT( "Real component library sort order:" ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
for ( i = CMP_LIBRARY::GetLibraryList().begin();
|
|
|
|
i < CMP_LIBRARY::GetLibraryList().end(); i++ )
|
2009-10-05 19:17:32 +00:00
|
|
|
wxLogDebug( wxT( " " ) + i->GetName() );
|
2011-10-02 20:24:41 +00:00
|
|
|
|
2010-02-15 14:24:52 +00:00
|
|
|
wxLogDebug( wxT( "end LoadLibraries ()" ) );
|
2009-09-18 14:56:05 +00:00
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|