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.

98 lines
2.9 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 <cmp_tree_model_adapter.h>
  22. #include <eda_pattern_match.h>
  23. #include <wx/tokenzr.h>
  24. #include <symbol_lib_table.h>
  25. #include <wx/progdlg.h>
  26. CMP_TREE_MODEL_ADAPTER_BASE::PTR CMP_TREE_MODEL_ADAPTER::Create( SYMBOL_LIB_TABLE* aLibs )
  27. {
  28. auto adapter = new CMP_TREE_MODEL_ADAPTER( aLibs );
  29. auto container = CMP_TREE_MODEL_ADAPTER::PTR( adapter );
  30. return container;
  31. }
  32. CMP_TREE_MODEL_ADAPTER::CMP_TREE_MODEL_ADAPTER( SYMBOL_LIB_TABLE* aLibs )
  33. : m_libs( aLibs )
  34. {}
  35. CMP_TREE_MODEL_ADAPTER::~CMP_TREE_MODEL_ADAPTER()
  36. {}
  37. void CMP_TREE_MODEL_ADAPTER::AddLibrary( wxString const& aLibNickname )
  38. {
  39. bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
  40. std::vector<LIB_ALIAS*> alias_list;
  41. try
  42. {
  43. m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols );
  44. }
  45. catch( const IO_ERROR& ioe )
  46. {
  47. wxLogError( wxString::Format( _( "Error occurred loading symbol library %s."
  48. "\n\n%s" ), aLibNickname, ioe.What() ) );
  49. return;
  50. }
  51. if( alias_list.size() > 0 )
  52. {
  53. AddAliasList( aLibNickname, m_libs->GetDescription( aLibNickname ), alias_list );
  54. m_tree.AssignIntrinsicRanks();
  55. }
  56. }
  57. void CMP_TREE_MODEL_ADAPTER::AddAliasList(
  58. wxString const& aNodeName,
  59. wxArrayString const& aAliasNameList )
  60. {
  61. std::vector<LIB_ALIAS*> alias_list;
  62. for( const wxString& name: aAliasNameList )
  63. {
  64. LIB_ALIAS* a = nullptr;
  65. try
  66. {
  67. a = m_libs->LoadSymbol( aNodeName, name );
  68. }
  69. catch( const IO_ERROR& ioe )
  70. {
  71. wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
  72. "\n\n%s" ), name, aNodeName, ioe.What() ) );
  73. continue;
  74. }
  75. if( a )
  76. alias_list.push_back( a );
  77. }
  78. if( alias_list.size() > 0 )
  79. AddAliasList( aNodeName, m_libs->GetDescription( aNodeName ), alias_list );
  80. }