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.

147 lines
4.9 KiB

  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 FOOTPRINT_CHOOSER_FRAME_H
  25. #define FOOTPRINT_CHOOSER_FRAME_H
  26. #include <wx/gdicmn.h>
  27. #include <pcb_base_frame.h>
  28. #include <pcbnew_settings.h>
  29. #include <netlist_reader/pcb_netlist.h>
  30. #include <lib_tree_model.h>
  31. #include <3d_canvas/board_adapter.h>
  32. #include <3d_rendering/track_ball.h>
  33. class PANEL_FOOTPRINT_CHOOSER;
  34. class wxCheckBox;
  35. class BITMAP_BUTTON;
  36. class BOARD;
  37. class CAMERA;
  38. namespace PCB { struct IFACE; }
  39. class FOOTPRINT_CHOOSER_FRAME : public PCB_BASE_FRAME
  40. {
  41. public:
  42. ~FOOTPRINT_CHOOSER_FRAME();
  43. ///< @copydoc PCB_BASE_FRAME::GetModel()
  44. BOARD_ITEM_CONTAINER* GetModel() const override;
  45. /**
  46. * @param aFootprint an optional FPID string to initialize the viewer with and to
  47. * return a selected footprint through.
  48. */
  49. bool ShowModal( wxString* aFootprint, wxWindow* aParent ) override;
  50. void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
  51. /**
  52. * Force the position of the dialog to a new position. This mimics the DIALOG_SHIM
  53. * implementation.
  54. * @param aNewPosition is the new forced position
  55. */
  56. void SetPosition( const wxPoint& aNewPosition );
  57. bool Show( bool show ) override;
  58. // We don't have a status bar
  59. void SetStatusText( const wxString& aText, int aNumber = 0 ) override {}
  60. void UpdateStatusBar() override {}
  61. protected:
  62. FOOTPRINT_CHOOSER_FRAME( KIWAY* aKiway, wxWindow* aParent );
  63. private:
  64. bool filterByPinCount();
  65. bool filterByFPFilters();
  66. bool filterFootprint( LIB_TREE_NODE& aNode );
  67. void Show3DViewerFrame();
  68. void setupUIConditions() override;
  69. /// @copydoc PCB_BASE_FRAME::Update3DView
  70. void Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle = nullptr ) override;
  71. void OnPaint( wxPaintEvent& aEvent );
  72. void OnOK( wxCommandEvent& aEvent );
  73. void doCloseWindow() override;
  74. void closeFootprintChooser( wxCommandEvent& aEvent );
  75. WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override;
  76. COLOR_SETTINGS* GetColorSettings( bool aForceRefresh ) const override;
  77. void on3DviewReq( wxCommandEvent& event );
  78. void onFpViewReq( wxCommandEvent& event );
  79. void onExternalViewer3DEnable( wxCommandEvent& aEvent );
  80. /**
  81. * Show hide footprint view panel and/or 3d view panel according to the options
  82. * (display 3D shapes and use external 3D viewer)
  83. */
  84. void updatePanelsVisibility();
  85. /**
  86. * Must be called after loading a new footprint: update footprint and/or 3D views
  87. */
  88. void updateViews();
  89. // A command event sent by a PANEL_FOOTPRINT_CHOOSER will fire this event:
  90. void onFpChanged( wxCommandEvent& event );
  91. void build3DCanvas();
  92. DECLARE_EVENT_TABLE()
  93. friend struct PCB::IFACE; // constructor called from here only
  94. private:
  95. PANEL_FOOTPRINT_CHOOSER* m_chooserPanel;
  96. bool m_showFpMode; // True to show the footprint
  97. bool m_show3DMode; // True to show the 3D model
  98. wxCheckBox* m_filterByPinCount;
  99. wxCheckBox* m_filterByFPFilters;
  100. wxCheckBox* m_show3DViewer;
  101. BOARD_ADAPTER m_boardAdapter;
  102. EDA_3D_CANVAS* m_preview3DCanvas;
  103. CAMERA& m_currentCamera;
  104. TRACK_BALL m_trackBallCamera;
  105. BOARD* m_dummyBoard;
  106. BITMAP_BUTTON* m_grButtonFpView;
  107. BITMAP_BUTTON* m_grButton3DView;
  108. int m_pinCount;
  109. std::vector<std::unique_ptr<EDA_PATTERN_MATCH>> m_fpFilters;
  110. // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
  111. // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
  112. // the initial-focus SetFocus() call to the first paint event.
  113. bool m_firstPaintEvent;
  114. };
  115. #endif // FOOTPRINT_CHOOSER_FRAME_H