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.

107 lines
3.1 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
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef LAYER_PAIRS_H
  24. #define LAYER_PAIRS_H
  25. #include <memory>
  26. #include <span>
  27. #include <string>
  28. #include <vector>
  29. #include <optional>
  30. #include <wx/event.h>
  31. #include <project/board_project_settings.h>
  32. class wxBitmap;
  33. wxDECLARE_EVENT( PCB_LAYER_PAIR_PRESETS_CHANGED, wxCommandEvent );
  34. wxDECLARE_EVENT( PCB_CURRENT_LAYER_PAIR_CHANGED, wxCommandEvent );
  35. /**
  36. * Management class for layer pairs in a PCB
  37. */
  38. class LAYER_PAIR_SETTINGS: public wxEvtHandler
  39. {
  40. public:
  41. /**
  42. * Construct a new layer pair manager.
  43. */
  44. LAYER_PAIR_SETTINGS() :
  45. m_currentPair( F_Cu, B_Cu )
  46. {
  47. }
  48. LAYER_PAIR_SETTINGS( const LAYER_PAIR_SETTINGS& aOther );
  49. bool AddLayerPair( LAYER_PAIR_INFO aPair );
  50. /**
  51. * Remove the matching layer pair from the store, if present.
  52. */
  53. bool RemoveLayerPair( const LAYER_PAIR& aPair );
  54. /**
  55. * Returns a span of all stored layer pairs.
  56. */
  57. std::span<const LAYER_PAIR_INFO> GetLayerPairs() const;
  58. std::span<LAYER_PAIR_INFO> GetLayerPairs();
  59. /**
  60. * Get a vector of all enabled layer pairs, in order.
  61. *
  62. * This includes a "manual" pair, if one is set
  63. * and isn't in the list of presets.
  64. */
  65. std::vector<LAYER_PAIR_INFO> GetEnabledLayerPairs( int& aCurrentIndex ) const;
  66. /**
  67. * Replace the stored layer pairs with the given list.
  68. *
  69. * The same conditions are maintained as for AddLayerPair
  70. */
  71. void SetLayerPairs( std::span<const LAYER_PAIR_INFO> aPairs );
  72. const LAYER_PAIR& GetCurrentLayerPair() const { return m_currentPair; }
  73. /**
  74. * Set the "active" layer pair. This doesn't have to be a preset pair.
  75. */
  76. void SetCurrentLayerPair( const LAYER_PAIR& aPair );
  77. private:
  78. bool addLayerPairInternal( LAYER_PAIR_INFO aPair );
  79. bool removeLayerPairInternal( const LAYER_PAIR& aPair );
  80. // Ordered store of all preset layer pairs
  81. std::vector<LAYER_PAIR_INFO> m_pairs;
  82. // Keep track of the last manual pair (set, but not a preset)
  83. // for quick switching back
  84. std::optional<LAYER_PAIR> m_lastManualPair;
  85. LAYER_PAIR m_currentPair;
  86. };
  87. #endif // LAYER_PAIRS_H