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.

142 lines
4.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2021 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 FOOTPRINT_SELECT_WIDGET_H
  20. #define FOOTPRINT_SELECT_WIDGET_H
  21. #include <footprint_filter.h>
  22. #include <footprint_info.h>
  23. #include <vector>
  24. #include <wx/panel.h>
  25. class KIWAY;
  26. class PROJECT;
  27. class FOOTPRINT_CHOICE;
  28. class wxWindow;
  29. /**
  30. * This event is fired when a footprint is selected. The string data of the
  31. * event will contain the footprint name.
  32. */
  33. wxDECLARE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
  34. class FOOTPRINT_SELECT_WIDGET : public wxPanel
  35. {
  36. public:
  37. /**
  38. * Construct a footprint selector widget.
  39. *
  40. * This requires references to an external footprint loader, and an external
  41. * unique_ptr-to-FOOTPRINT_LIST. The latter will be populated with a
  42. * FOOTPRINT_LIST instance the first time Load() is called.
  43. *
  44. * The reason for this is that footprint loading tends to be very expensive,
  45. * especially when using online libraries. The caller is expected to keep
  46. * these objects around (e.g. they may be statics on the dialog this
  47. * FOOTPRINT_SELECT_WIDGET is created in) so footprints do not have to be
  48. * loaded more than once.
  49. *
  50. * @param aParent - parent window
  51. * @param aFpList - FOOTPRINT_LIST container
  52. * @param aUpdate - whether to call UpdateList() automatically when finished loading
  53. * @param aMaxItems - maximum number of filter items to display, in addition to
  54. * Default and Other
  55. */
  56. FOOTPRINT_SELECT_WIDGET( EDA_DRAW_FRAME* aFrame, wxWindow* aParent, FOOTPRINT_LIST* aFpList,
  57. bool aUpdate = true, int aMaxItems = 400 );
  58. virtual ~FOOTPRINT_SELECT_WIDGET()
  59. {
  60. }
  61. /**
  62. * Start loading. This function returns immediately; footprints will
  63. * continue to load in the background.
  64. *
  65. * @param aKiway - active kiway instance. This is cached for use when "Other"
  66. * is selected.
  67. * @param aProject - current project
  68. */
  69. void Load( KIWAY& aKiway, PROJECT& aProject );
  70. /**
  71. * Clear all filters. Does not update the list.
  72. */
  73. void ClearFilters();
  74. /**
  75. * Filter by pin count. Does not update the list.
  76. */
  77. void FilterByPinCount( int aPinCount );
  78. /**
  79. * Filter by footprint filter list. Does not update the list.
  80. *
  81. * @param aFilters is a wxArrayString of strings used to filter the list of available
  82. * footprints (can be empty).
  83. * The final fp list is the list of footprint names matching at least one filtering string.
  84. * A filtering string is something like sm0402 or DIP*
  85. * @param aZeroFilters - if true, zero filters = zero footprints. If false, zero filters =
  86. * not filtering.
  87. */
  88. void FilterByFootprintFilters( const wxArrayString& aFilters, bool aZeroFilters );
  89. /**
  90. * Set the default footprint for a part. This will be listed at the
  91. * top. May be an empty string.
  92. */
  93. void SetDefaultFootprint( const wxString& aFp );
  94. /**
  95. * Update the contents of the list to match the filters. Has no effect if
  96. * the footprint list has not been loaded yet. The "default" footprint will be
  97. * selected.
  98. *
  99. * @return true if the footprint list has been loaded (and the list was updated)
  100. */
  101. bool UpdateList();
  102. /**
  103. * Set current selection to the default footprint
  104. */
  105. void SelectDefault();
  106. /**
  107. * Enable or disable the control for input
  108. */
  109. virtual bool Enable( bool aEnable = true ) override;
  110. private:
  111. FOOTPRINT_CHOICE* m_fp_sel_ctrl;
  112. wxSizer* m_sizer;
  113. bool m_update;
  114. int m_max_items;
  115. wxString m_default_footprint;
  116. FOOTPRINT_LIST* m_fp_list;
  117. FOOTPRINT_FILTER m_fp_filter;
  118. bool m_zero_filter;
  119. EDA_DRAW_FRAME* m_frame;
  120. void OnComboBox( wxCommandEvent& aEvent );
  121. };
  122. #endif // FOOTPRINT_SELECT_WIDGET