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.

126 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <symbol_library.h>
  20. #include <confirm.h>
  21. #include <dialogs/html_message_box.h>
  22. #include <kiface_base.h>
  23. #include <pgm_base.h>
  24. #include <wx/app.h>
  25. // non-member so it can be moved easily, and kept REALLY private.
  26. // Do NOT Clear() in here.
  27. static void add_search_paths( SEARCH_STACK* aDst, const SEARCH_STACK& aSrc, int aIndex )
  28. {
  29. for( unsigned i=0; i<aSrc.GetCount(); ++i )
  30. aDst->AddPaths( aSrc[i], aIndex );
  31. }
  32. SEARCH_STACK* PROJECT::SchSearchS()
  33. {
  34. SEARCH_STACK* ss = (SEARCH_STACK*) GetElem( PROJECT::ELEM_SCH_SEARCH_STACK );
  35. wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) );
  36. if( !ss )
  37. {
  38. ss = new SEARCH_STACK();
  39. // Make PROJECT the new SEARCH_STACK owner.
  40. SetElem( PROJECT::ELEM_SCH_SEARCH_STACK, ss );
  41. // to the empty SEARCH_STACK for SchSearchS(), add project dir as first
  42. ss->AddPaths( m_project_name.GetPath() );
  43. // next add the paths found in *.pro, variable "LibDir"
  44. wxString libDir;
  45. try
  46. {
  47. SYMBOL_LIBS::LibNamesAndPaths( this, false, &libDir );
  48. }
  49. catch( const IO_ERROR& )
  50. {
  51. }
  52. if( !!libDir )
  53. {
  54. wxArrayString paths;
  55. SEARCH_STACK::Split( &paths, libDir );
  56. for( unsigned i =0; i<paths.GetCount(); ++i )
  57. {
  58. wxString path = AbsolutePath( paths[i] );
  59. ss->AddPaths( path ); // at the end
  60. }
  61. }
  62. // append all paths from aSList
  63. add_search_paths( ss, Kiface().KifaceSearch(), -1 );
  64. }
  65. return ss;
  66. }
  67. SYMBOL_LIBS* PROJECT::SchLibs()
  68. {
  69. SYMBOL_LIBS* libs = (SYMBOL_LIBS*) GetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS );
  70. wxASSERT( !libs || libs->Type() == SYMBOL_LIBS_T );
  71. if( !libs )
  72. {
  73. libs = new SYMBOL_LIBS();
  74. // Make PROJECT the new SYMBOL_LIBS owner.
  75. SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, libs );
  76. try
  77. {
  78. libs->LoadAllLibraries( this );
  79. }
  80. catch( const PARSE_ERROR& pe )
  81. {
  82. wxString lib_list = UTF8( pe.inputLine );
  83. wxWindow* parent = Pgm().App().GetTopWindow();
  84. // parent of this dialog cannot be NULL since that breaks the Kiway() chain.
  85. HTML_MESSAGE_BOX dlg( parent, _( "Not Found" ) );
  86. dlg.MessageSet( _( "The following libraries were not found:" ) );
  87. dlg.ListSet( lib_list );
  88. dlg.Layout();
  89. dlg.ShowModal();
  90. }
  91. catch( const IO_ERROR& ioe )
  92. {
  93. wxWindow* parent = Pgm().App().GetTopWindow();
  94. DisplayError( parent, ioe.What() );
  95. }
  96. }
  97. return libs;
  98. }