You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.1 KiB

18 years ago
  1. /**
  2. * @file eelibs_read_libraryfiles.cpp
  3. * @brief Functions to handle reading component library files.
  4. */
  5. #include "fctsys.h"
  6. #include "confirm.h"
  7. #include "macros.h"
  8. #include "appl_wxstruct.h"
  9. #include "wxEeschemaStruct.h"
  10. #include "general.h"
  11. #include "class_library.h"
  12. #include "html_messagebox.h"
  13. void SCH_EDIT_FRAME::LoadLibraries( void )
  14. {
  15. size_t ii;
  16. wxFileName fn;
  17. wxString msg, tmp, errMsg;
  18. wxString libraries_not_found;
  19. wxArrayString sortOrder;
  20. CMP_LIBRARY_LIST::iterator i = CMP_LIBRARY::GetLibraryList().begin();
  21. /* Free the unwanted libraries but keep the cache library. */
  22. while ( i < CMP_LIBRARY::GetLibraryList().end() )
  23. {
  24. if( i->IsCache() )
  25. {
  26. i++;
  27. continue;
  28. }
  29. if( m_ComponentLibFiles.Index( i->GetName(), false ) == wxNOT_FOUND )
  30. i = CMP_LIBRARY::GetLibraryList().erase( i );
  31. else
  32. i++;
  33. }
  34. /* Load missing libraries. */
  35. for( ii = 0; ii < m_ComponentLibFiles.GetCount(); ii++ )
  36. {
  37. fn.Clear();
  38. fn.SetName( m_ComponentLibFiles[ii] );
  39. fn.SetExt( CompLibFileExtension );
  40. /* Skip if the file name is not valid.. */
  41. if( !fn.IsOk() )
  42. continue;
  43. if( !fn.FileExists() )
  44. {
  45. tmp = wxGetApp().FindLibraryPath( fn );
  46. if( !tmp )
  47. {
  48. libraries_not_found += fn.GetName() + _( "\n" );
  49. continue;
  50. }
  51. }
  52. else
  53. {
  54. tmp = fn.GetFullPath();
  55. }
  56. // Loaded library statusbar message
  57. msg = _( "Library " ) + tmp;
  58. fn = tmp;
  59. if( CMP_LIBRARY::AddLibrary( fn, errMsg ) )
  60. {
  61. msg += _( " loaded" );
  62. sortOrder.Add( fn.GetName() );
  63. }
  64. else
  65. {
  66. wxString prompt;
  67. prompt.Printf( _( "Component library <%s> failed to load.\nError: %s" ),
  68. GetChars( fn.GetFullPath() ),
  69. GetChars( errMsg ) );
  70. DisplayError( this, prompt );
  71. msg += _( " error!" );
  72. }
  73. PrintMsg( msg );
  74. }
  75. /* Print the libraries not found */
  76. if( !libraries_not_found.IsEmpty() )
  77. {
  78. HTML_MESSAGE_BOX dialog( this, _("Files not found") );
  79. dialog.MessageSet( _( "The following libraries could not be found:" ) );
  80. dialog.ListSet( libraries_not_found );
  81. libraries_not_found.empty();
  82. dialog.ShowModal();
  83. }
  84. /* Put the libraries in the correct order. */
  85. CMP_LIBRARY::SetSortOrder( sortOrder );
  86. CMP_LIBRARY::GetLibraryList().sort();
  87. #if 0 // #ifdef __WXDEBUG__
  88. wxLogDebug( wxT( "LoadLibraries() requested component library sort order:" ) );
  89. for( size_t i = 0; i < sortOrder.GetCount(); i++ )
  90. wxLogDebug( wxT( " " ) + sortOrder[i] );
  91. wxLogDebug( wxT( "Real component library sort order:" ) );
  92. for ( i = CMP_LIBRARY::GetLibraryList().begin();
  93. i < CMP_LIBRARY::GetLibraryList().end(); i++ )
  94. wxLogDebug( wxT( " " ) + i->GetName() );
  95. wxLogDebug( wxT( "end LoadLibraries ()" ) );
  96. #endif
  97. }