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.

122 lines
3.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
  5. * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
  6. * Copyright (C) 2014-2019 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <wx/tokenzr.h>
  22. #include <wx/window.h>
  23. #include <widgets/app_progress_dialog.h>
  24. #include <eda_pattern_match.h>
  25. #include <symbol_lib_table.h>
  26. #include <class_libentry.h>
  27. #include <generate_alias_info.h>
  28. #include <symbol_tree_model_adapter.h>
  29. bool SYMBOL_TREE_MODEL_ADAPTER::m_show_progress = true;
  30. #define PROGRESS_INTERVAL_MILLIS 66
  31. SYMBOL_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent,
  32. LIB_TABLE* aLibs )
  33. {
  34. return PTR( new SYMBOL_TREE_MODEL_ADAPTER( aParent, aLibs ) );
  35. }
  36. SYMBOL_TREE_MODEL_ADAPTER::SYMBOL_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs ) :
  37. LIB_TREE_MODEL_ADAPTER( aParent, "pinned_symbol_libs" ),
  38. m_libs( (SYMBOL_LIB_TABLE*) aLibs )
  39. {}
  40. SYMBOL_TREE_MODEL_ADAPTER::~SYMBOL_TREE_MODEL_ADAPTER()
  41. {}
  42. void SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNicknames,
  43. wxWindow* aParent )
  44. {
  45. APP_PROGRESS_DIALOG* prg = nullptr;
  46. wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
  47. if( m_show_progress )
  48. {
  49. prg = new APP_PROGRESS_DIALOG( _( "Loading Symbol Libraries" ), wxEmptyString,
  50. aNicknames.size(), aParent );
  51. }
  52. unsigned int ii = 0;
  53. for( const auto& nickname : aNicknames )
  54. {
  55. if( prg && wxGetUTCTimeMillis() > nextUpdate )
  56. {
  57. prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) );
  58. nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
  59. }
  60. AddLibrary( nickname );
  61. ii++;
  62. }
  63. m_tree.AssignIntrinsicRanks();
  64. if( prg )
  65. {
  66. prg->Destroy();
  67. m_show_progress = false;
  68. }
  69. }
  70. void SYMBOL_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname )
  71. {
  72. bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
  73. std::vector<LIB_PART*> symbols;
  74. std::vector<LIB_TREE_ITEM*> comp_list;
  75. try
  76. {
  77. m_libs->LoadSymbolLib( symbols, aLibNickname, onlyPowerSymbols );
  78. }
  79. catch( const IO_ERROR& ioe )
  80. {
  81. wxLogError( wxString::Format( _( "Error loading symbol library %s.\n\n%s" ),
  82. aLibNickname,
  83. ioe.What() ) );
  84. return;
  85. }
  86. if( symbols.size() > 0 )
  87. {
  88. comp_list.assign( symbols.begin(), symbols.end() );
  89. DoAddLibrary( aLibNickname, m_libs->GetDescription( aLibNickname ), comp_list, false );
  90. }
  91. }
  92. wxString SYMBOL_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
  93. {
  94. return GenerateAliasInfo( m_libs, aLibId, aUnit );
  95. }