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.

153 lines
5.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019-2023 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 BOARD_INSPECTION_TOOL_H
  24. #define BOARD_INSPECTION_TOOL_H
  25. #include <dialogs/dialog_net_inspector.h>
  26. #include <dialogs/dialog_book_reporter.h>
  27. #include <drc/drc_rule.h>
  28. #include <drc/drc_engine.h>
  29. #include <pcb_edit_frame.h>
  30. #include <rc_item.h>
  31. #include <tools/pcb_actions.h>
  32. #include <tools/pcb_tool_base.h>
  33. class CONNECTIVITY_DATA;
  34. class FOOTPRINT_DIFF_WIDGET;
  35. /**
  36. * Tool for pcb inspection.
  37. */
  38. class BOARD_INSPECTION_TOOL : public wxEvtHandler, public PCB_TOOL_BASE
  39. {
  40. public:
  41. BOARD_INSPECTION_TOOL();
  42. /// @copydoc TOOL_INTERACTIVE::Init()
  43. bool Init() override;
  44. /// @copydoc TOOL_INTERACTIVE::Reset()
  45. void Reset( RESET_REASON aReason ) override;
  46. /**
  47. * Show dialog with board statistics.
  48. */
  49. int ShowBoardStatistics( const TOOL_EVENT& aEvent );
  50. ///< Highlight net belonging to the item under the cursor.
  51. int HighlightNet( const TOOL_EVENT& aEvent );
  52. ///< Clear all board highlights
  53. int ClearHighlight( const TOOL_EVENT& aEvent );
  54. ///< Perform the appropriate action in response to an Eeschema cross-probe.
  55. int HighlightItem( const TOOL_EVENT& aEvent );
  56. ///< Update ratsnest for selected items.
  57. int UpdateLocalRatsnest( const TOOL_EVENT& aEvent );
  58. ///< Hide ratsnest for selected items. Called when there are no items selected.
  59. int HideLocalRatsnest( const TOOL_EVENT& aEvent );
  60. ///< Show local ratsnest of a component.
  61. int LocalRatsnestTool( const TOOL_EVENT& aEvent );
  62. int ListNets( const TOOL_EVENT& aEvent );
  63. ///< Hide the ratsnest for a given net.
  64. int HideNetInRatsnest( const TOOL_EVENT& aEvent );
  65. ///< Show the ratsnest for a given net.
  66. int ShowNetInRatsnest( const TOOL_EVENT& aEvent );
  67. void InspectDRCError( const std::shared_ptr<RC_ITEM>& aDRCItem );
  68. ///< Show the clearance resolution for two selected items.
  69. int InspectClearance( const TOOL_EVENT& aEvent );
  70. int InspectConstraints( const TOOL_EVENT& aEvent );
  71. int DiffFootprint( const TOOL_EVENT& aEvent );
  72. /**
  73. * @return true if a net or nets to highlight have been set
  74. */
  75. bool IsNetHighlightSet() const
  76. {
  77. return !m_currentlyHighlighted.empty();
  78. }
  79. private:
  80. ///< Recalculate dynamic ratsnest for the current selection.
  81. void calculateSelectionRatsnest( const VECTOR2I& aDelta );
  82. /**
  83. * Look for a #BOARD_CONNECTED_ITEM in a given spot and if one is found - it enables
  84. * highlight for its net.
  85. *
  86. * @param aPosition is the point where an item is expected (world coordinates).
  87. * @param aUseSelection is true if we should use the current selection to pick the netcode
  88. */
  89. bool highlightNet( const VECTOR2D& aPosition, bool aUseSelection );
  90. void doHideRatsnestNet( int aNetCode, bool aHide );
  91. ///< Bind handlers to corresponding TOOL_ACTIONs.
  92. void setTransitions() override;
  93. void onListNetsDialogClosed( wxCommandEvent& aEvent );
  94. void onInspectClearanceDialogClosed( wxCommandEvent& aEvent );
  95. void onInspectConstraintsDialogClosed( wxCommandEvent& aEvent );
  96. void onDiffFootprintDialogClosed( wxCommandEvent& event );
  97. DRC_ENGINE makeDRCEngine( bool* aCompileError, bool* aCourtyardError = nullptr );
  98. wxString getItemDescription( BOARD_ITEM* aItem );
  99. void reportCompileError( REPORTER* r );
  100. void reportHeader( const wxString& aTitle, BOARD_ITEM* a, REPORTER* r );
  101. void reportHeader( const wxString& aTitle, BOARD_ITEM* a, BOARD_ITEM* b, REPORTER* r );
  102. void reportHeader( const wxString& aTitle, BOARD_ITEM* a, BOARD_ITEM* b, PCB_LAYER_ID aLayer,
  103. REPORTER* r );
  104. FOOTPRINT_DIFF_WIDGET* constructDiffPanel( wxPanel* aParentPanel );
  105. private:
  106. PCB_EDIT_FRAME* m_frame; // Pointer to the currently used edit frame.
  107. std::set<int> m_currentlyHighlighted; // Active net being highlighted, or -1 when off
  108. std::set<int> m_lastHighlighted; // For toggling between last two highlighted nets
  109. CONNECTIVITY_DATA* m_dynamicData; // Cached connectivity data from the selection
  110. std::unique_ptr<DIALOG_NET_INSPECTOR> m_listNetsDialog;
  111. DIALOG_NET_INSPECTOR::SETTINGS m_listNetsDialogSettings;
  112. std::unique_ptr<DIALOG_BOOK_REPORTER> m_inspectClearanceDialog;
  113. std::unique_ptr<DIALOG_BOOK_REPORTER> m_inspectConstraintsDialog;
  114. std::unique_ptr<DIALOG_BOOK_REPORTER> m_diffFootprintDialog;
  115. };
  116. #endif //BOARD_INSPECTION_TOOL_H