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.

137 lines
3.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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. #ifndef _SYMBOL_LIBRARY_COMMON_H_
  20. #define _SYMBOL_LIBRARY_COMMON_H_
  21. #include <map>
  22. #include <wx/arrstr.h>
  23. class LIB_SYMBOL;
  24. class SCH_BASE_FRAME;
  25. class SYMBOL_LIB_TABLE;
  26. enum class SCH_LIB_TYPE
  27. {
  28. LT_EESCHEMA,
  29. LT_SYMBOL
  30. };
  31. /**
  32. * Symbol library map sorting helper.
  33. */
  34. struct LibSymbolMapSort
  35. {
  36. bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const
  37. {
  38. return aItem1 < aItem2;
  39. }
  40. };
  41. ///< Symbol library map sorted by the symbol name.
  42. typedef std::map< wxString, LIB_SYMBOL*, LibSymbolMapSort > LIB_SYMBOL_MAP;
  43. /**
  44. * Helper object to filter a list of libraries.
  45. */
  46. class SYMBOL_LIBRARY_FILTER
  47. {
  48. public:
  49. SYMBOL_LIBRARY_FILTER()
  50. {
  51. m_filterPowerSymbols = false;
  52. m_forceLoad = false;
  53. }
  54. /**
  55. * Add \a aLibName to the allowed libraries list.
  56. */
  57. void AddLib( const wxString& aLibName )
  58. {
  59. m_allowedLibs.Add( aLibName );
  60. m_forceLoad = false;
  61. }
  62. /**
  63. * Add \a aLibName to the allowed libraries list.
  64. */
  65. void LoadFrom( const wxString& aLibName )
  66. {
  67. m_allowedLibs.Clear();
  68. m_allowedLibs.Add( aLibName );
  69. m_forceLoad = true;
  70. }
  71. /**
  72. * Clear the allowed libraries list (allows all libraries).
  73. */
  74. void ClearLibList()
  75. {
  76. m_allowedLibs.Clear();
  77. m_forceLoad = false;
  78. }
  79. /**
  80. * Enable or disable the filtering of power symbols.
  81. */
  82. void FilterPowerSymbols( bool aFilterEnable )
  83. {
  84. m_filterPowerSymbols = aFilterEnable;
  85. }
  86. /**
  87. * @return true if the filtering of power symbols is on.
  88. */
  89. bool GetFilterPowerSymbols() const { return m_filterPowerSymbols; }
  90. /**
  91. * @return the list of the names of allowed libraries.
  92. */
  93. const wxArrayString& GetAllowedLibList() const { return m_allowedLibs; }
  94. /**
  95. * @return the name of the library to use to load a symbol or an a empty string if no
  96. * library source available.
  97. */
  98. const wxString& GetLibSource() const
  99. {
  100. static wxString dummy;
  101. if( m_forceLoad && m_allowedLibs.GetCount() > 0 )
  102. return m_allowedLibs[0];
  103. else
  104. return dummy;
  105. }
  106. private:
  107. wxArrayString m_allowedLibs; ///< List of filtered library names.
  108. bool m_filterPowerSymbols; ///< Enable or disable power symbol filtering.
  109. bool m_forceLoad; ///< Force loading symbol from library m_allowedLibs[0].
  110. };
  111. #endif // _SYMBOL_LIBRARY_COMMON_H_