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.

118 lines
3.4 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-2017 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/progdlg.h>
  23. #include <eda_pattern_match.h>
  24. #include <symbol_lib_table.h>
  25. #include <class_libentry.h>
  26. #include <generate_alias_info.h>
  27. #include <symbol_tree_model_adapter.h>
  28. bool SYMBOL_TREE_MODEL_ADAPTER::m_show_progress = true;
  29. #define PROGRESS_INTERVAL_MILLIS 66
  30. SYMBOL_TREE_MODEL_ADAPTER::PTR SYMBOL_TREE_MODEL_ADAPTER::Create( LIB_TABLE* aLibs )
  31. {
  32. return PTR( new SYMBOL_TREE_MODEL_ADAPTER( aLibs ) );
  33. }
  34. SYMBOL_TREE_MODEL_ADAPTER::SYMBOL_TREE_MODEL_ADAPTER( LIB_TABLE* aLibs )
  35. : m_libs( (SYMBOL_LIB_TABLE*) aLibs )
  36. {}
  37. SYMBOL_TREE_MODEL_ADAPTER::~SYMBOL_TREE_MODEL_ADAPTER()
  38. {}
  39. void SYMBOL_TREE_MODEL_ADAPTER::AddLibraries( const std::vector<wxString>& aNicknames,
  40. wxWindow* aParent )
  41. {
  42. wxProgressDialog* prg = nullptr;
  43. wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
  44. if( m_show_progress )
  45. {
  46. prg = new wxProgressDialog( _( "Loading Symbol Libraries" ), wxEmptyString,
  47. aNicknames.size(), aParent );
  48. }
  49. unsigned int ii = 0;
  50. for( const auto& nickname : aNicknames )
  51. {
  52. if( prg && wxGetUTCTimeMillis() > nextUpdate )
  53. {
  54. prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) );
  55. nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
  56. }
  57. AddLibrary( nickname );
  58. ii++;
  59. }
  60. m_tree.AssignIntrinsicRanks();
  61. if( prg )
  62. {
  63. prg->Destroy();
  64. m_show_progress = false;
  65. }
  66. }
  67. void SYMBOL_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname )
  68. {
  69. bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
  70. std::vector<LIB_ALIAS*> alias_list;
  71. std::vector<LIB_TREE_ITEM*> comp_list;
  72. try
  73. {
  74. m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols );
  75. }
  76. catch( const IO_ERROR& ioe )
  77. {
  78. wxLogError( wxString::Format( _( "Error loading symbol library %s.\n\n%s" ),
  79. aLibNickname,
  80. ioe.What() ) );
  81. return;
  82. }
  83. if( alias_list.size() > 0 )
  84. {
  85. comp_list.assign( alias_list.begin(), alias_list.end() );
  86. DoAddLibrary( aLibNickname, m_libs->GetDescription( aLibNickname ), comp_list, false );
  87. }
  88. }
  89. wxString SYMBOL_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
  90. {
  91. return GenerateAliasInfo( m_libs, aLibId, aUnit );
  92. }