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.

134 lines
4.7 KiB

2 years ago
2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2023 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef PANEL_FOOTPRINT_CHOOSER_H
  25. #define PANEL_FOOTPRINT_CHOOSER_H
  26. #include <widgets/lib_tree.h>
  27. #include <fp_tree_model_adapter.h>
  28. #include <footprint_info.h>
  29. #include <widgets/footprint_preview_widget.h>
  30. class wxTimer;
  31. class wxSplitterWindow;
  32. class wxBoxSizer;
  33. class PCB_BASE_FRAME;
  34. // When a new footprint is selected, a custom event is sent, for instance to update
  35. // 3D viewer. So declare a FP_SELECTION_EVENT event
  36. wxDECLARE_EVENT(FP_SELECTION_EVENT, wxCommandEvent);
  37. class PANEL_FOOTPRINT_CHOOSER : public wxPanel
  38. {
  39. public:
  40. /**
  41. * Create dialog to choose component.
  42. *
  43. * @param aFrame the parent frame (usually a PCB_EDIT_FRAME or FOOTPRINT_CHOOSER_FRAME)
  44. * @param aParent the parent window (usually a DIALOG_SHIM or FOOTPRINT_CHOOSER_FRAME)
  45. * @param aAcceptHandler a handler to be called on double-click of a footprint
  46. * @param aEscapeHandler a handler to be called on <ESC>
  47. */
  48. PANEL_FOOTPRINT_CHOOSER( PCB_BASE_FRAME* aFrame, wxTopLevelWindow* aParent,
  49. const wxArrayString& aFootprintHistoryList,
  50. std::function<bool( LIB_TREE_NODE& )> aFilter,
  51. std::function<void()> aAcceptHandler,
  52. std::function<void()> aEscapeHandler );
  53. ~PANEL_FOOTPRINT_CHOOSER();
  54. void FinishSetup();
  55. void SetPreselect( const LIB_ID& aPreselect );
  56. /**
  57. * To be called after this dialog returns from ShowModal().
  58. *
  59. * @return the #LIB_ID of the symbol that has been selected.
  60. */
  61. LIB_ID GetSelectedLibId() const;
  62. int GetItemCount() const { return m_adapter->GetItemCount(); }
  63. wxWindow* GetFocusTarget() const { return m_tree->GetFocusTarget(); }
  64. wxSizer* GetFiltersSizer() const { return m_tree->GetFiltersSizer(); }
  65. void Regenerate() { m_tree->Regenerate( true ); }
  66. FOOTPRINT_PREVIEW_WIDGET* GetViewerPanel() const { return m_preview_ctrl; }
  67. wxSplitterWindow* GetVerticalSpliter() const { return m_vsplitter; }
  68. wxPanel* GetDetailsPanel() const { return m_detailsPanel; }
  69. protected:
  70. static constexpr int DblClickDelay = 100; // milliseconds
  71. void OnDetailsCharHook( wxKeyEvent& aEvt );
  72. void onCloseTimer( wxTimerEvent& aEvent );
  73. void onOpenLibsTimer( wxTimerEvent& aEvent );
  74. /**
  75. * Handle parent frame menu events to block tree preview
  76. */
  77. void onMenuOpen( wxMenuEvent& aEvent );
  78. void onMenuClose( wxMenuEvent& aEvent );
  79. void onFootprintSelected( wxCommandEvent& aEvent );
  80. /**
  81. * Handle the selection of an item. This is called when either the search
  82. * box or the tree receive an Enter, or the tree receives a double click.
  83. * If the item selected is a category, it is expanded or collapsed; if it
  84. * is a component, the component is picked.
  85. */
  86. void onFootprintChosen( wxCommandEvent& aEvent );
  87. public:
  88. wxPanel* m_RightPanel;
  89. wxBoxSizer* m_RightPanelSizer;
  90. const FOOTPRINT* m_CurrFootprint;
  91. protected:
  92. wxPanel* m_detailsPanel;
  93. wxTimer* m_dbl_click_timer;
  94. wxTimer* m_open_libs_timer;
  95. wxSplitterWindow* m_hsplitter;
  96. wxSplitterWindow* m_vsplitter;
  97. wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
  98. FOOTPRINT_PREVIEW_WIDGET* m_preview_ctrl;
  99. LIB_TREE* m_tree;
  100. HTML_WINDOW* m_details;
  101. PCB_BASE_FRAME* m_frame;
  102. std::function<bool( LIB_TREE_NODE& )> m_filter;
  103. std::function<void()> m_acceptHandler;
  104. std::function<void()> m_escapeHandler;
  105. };
  106. #endif /* PANEL_FOOTPRINT_CHOOSER_H */