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.

83 lines
3.1 KiB

2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 3
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * https://www.gnu.org/licenses/gpl-3.0.html
  22. * or you may search the http://www.gnu.org website for the version 3 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H
  27. #define SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H
  28. #include <lib_tree_model_adapter.h>
  29. #include <map>
  30. class SYMBOL_EDIT_FRAME;
  31. class SYMBOL_LIBRARY_MANAGER;
  32. class SYMBOL_TREE_SYNCHRONIZING_ADAPTER : public LIB_TREE_MODEL_ADAPTER
  33. {
  34. public:
  35. static wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> Create( SYMBOL_EDIT_FRAME* aParent,
  36. SYMBOL_LIBRARY_MANAGER* aLibs );
  37. bool IsContainer( const wxDataViewItem& aItem ) const override;
  38. void Sync( const wxString& aForceRefresh,
  39. std::function<void( int, int, const wxString&)> aProgressCallback );
  40. int GetLibrariesCount() const override;
  41. TOOL_INTERACTIVE* GetContextMenuTool() override;
  42. wxDataViewItem GetCurrentDataViewItem() override;
  43. bool HasPreview( const wxDataViewItem& aItem ) override;
  44. void ShowPreview( wxWindow* aParent, const wxDataViewItem& aItem ) override;
  45. void ShutdownPreview( wxWindow* aParent ) override;
  46. protected:
  47. void updateLibrary( LIB_TREE_NODE_LIBRARY& aLibNode );
  48. LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary( LIB_TREE_NODE::PTR_VECTOR::iterator& aLibNodeIt );
  49. void GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
  50. unsigned int aCol ) const override;
  51. bool GetAttr( wxDataViewItem const& aItem, unsigned int aCol,
  52. wxDataViewItemAttr& aAttr ) const override;
  53. SYMBOL_TREE_SYNCHRONIZING_ADAPTER( SYMBOL_EDIT_FRAME* aParent,
  54. SYMBOL_LIBRARY_MANAGER* aLibMgr );
  55. PROJECT::LIB_TYPE_T getLibType() override { return PROJECT::LIB_TYPE_T::SYMBOL_LIB; }
  56. protected:
  57. SYMBOL_EDIT_FRAME* m_frame;
  58. SYMBOL_LIBRARY_MANAGER* m_libMgr;
  59. /// Hashes to decide whether a library needs an update.
  60. std::map<wxString, int> m_libHashes;
  61. /// #SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
  62. int m_lastSyncHash;
  63. };
  64. #endif /* SYMBOL_TREE_SYNCHRONIZING_ADAPTER_H */