2007-11-02 17:17:44 +00:00
|
|
|
/*****************************************************************/
|
2009-08-19 19:34:03 +00:00
|
|
|
/* Functions to handle component library files : read functions */
|
2007-11-02 17:17:44 +00:00
|
|
|
/*****************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
#include "dialog_load_error.h"
|
|
|
|
|
2007-12-05 20:54:11 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/**
|
|
|
|
* Function LoadLibraries
|
|
|
|
*
|
2009-09-18 14:56:05 +00:00
|
|
|
* Clear all already loaded libraries and load all of the project libraries.
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
void WinEDA_SchematicFrame::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
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
if( m_ComponentLibFiles.Index( i->GetName(), false ) == wxNOT_FOUND )
|
|
|
|
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. */
|
|
|
|
for( ii = 0; ii < m_ComponentLibFiles.GetCount(); ii++ )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
fn = 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 );
|
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;
|
|
|
|
|
|
|
|
prompt.Printf( _( "Component library <%s> failed to load.\n\n\
|
|
|
|
Error: %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() )
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
DIALOG_LOAD_ERROR dialog( this );
|
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
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#ifdef __WXDEBUG__
|
2009-10-05 19:17:32 +00:00
|
|
|
wxLogDebug( wxT( "Requested component library sort order." ) );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sortOrder.GetCount(); i++ )
|
|
|
|
wxLogDebug( wxT( " " ) + sortOrder[i] );
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
wxLogDebug( wxT( "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() );
|
2009-09-18 14:56:05 +00:00
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|