KiCad PCB EDA Suite
board_inspection_tool.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019-2021 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 
24 #ifndef BOARD_INSPECTION_TOOL_H
25 #define BOARD_INSPECTION_TOOL_H
26 
31 #include <drc/drc_rule.h>
32 #include <pcb_edit_frame.h>
33 #include <rc_item.h>
34 #include <tools/pcb_actions.h>
35 #include <tools/pcb_tool_base.h>
36 
37 class CONNECTIVITY_DATA;
38 
39 
41 {
42 public:
44  DIALOG_HTML_REPORTER( aFrame ),
45  m_frame( aFrame )
46  {
47  m_sdbSizerOK->SetDefault();
49  }
50 
51  void OnErrorLinkClicked( wxHtmlLinkEvent& event ) override;
52 
53  void OnOK( wxCommandEvent& event ) override
54  {
55  Close();
56  }
57 
58 protected:
60 };
61 
62 
66 class BOARD_INSPECTION_TOOL : public wxEvtHandler, public PCB_TOOL_BASE
67 {
68 public:
70 
72  bool Init() override;
73 
75  void Reset( RESET_REASON aReason ) override;
76 
80  int ShowStatisticsDialog( const TOOL_EVENT& aEvent );
81 
83  int CrossProbePcbToSch( const TOOL_EVENT& aEvent );
84 
86  int HighlightNet( const TOOL_EVENT& aEvent );
87 
89  int ClearHighlight( const TOOL_EVENT& aEvent );
90 
92  int HighlightNetTool( const TOOL_EVENT& aEvent );
93 
95  int HighlightItem( const TOOL_EVENT& aEvent );
96 
98  int UpdateSelectionRatsnest( const TOOL_EVENT& aEvent );
99 
101  int HideDynamicRatsnest( const TOOL_EVENT& aEvent );
102 
104  int LocalRatsnestTool( const TOOL_EVENT& aEvent );
105 
106  int FlipPcbView( const TOOL_EVENT& aEvent );
107 
108  int ListNets( const TOOL_EVENT& aEvent );
109 
111  int HideNet( const TOOL_EVENT& aEvent );
112 
114  int ShowNet( const TOOL_EVENT& aEvent );
115 
116  void InspectDRCError( const std::shared_ptr<RC_ITEM>& aDRCItem );
117 
119  int InspectClearance( const TOOL_EVENT& aEvent );
120 
121  int InspectConstraints( const TOOL_EVENT& aEvent );
122 
126  bool IsNetHighlightSet() const
127  {
128  return !m_currentlyHighlighted.empty();
129  }
130 
131 private:
133  void ratsnestTimer( wxTimerEvent& aEvent );
134 
136  void calculateSelectionRatsnest( const VECTOR2I& aDelta );
137 
145  bool highlightNet( const VECTOR2D& aPosition, bool aUseSelection );
146 
147  void doHideNet( int aNetCode, bool aHide );
148 
150  void setTransitions() override;
151 
152  void onListNetsDialogClosed( wxCommandEvent& aEvent );
153  void onInspectClearanceDialogClosed( wxCommandEvent& aEvent );
154  void onInspectConstraintsDialogClosed( wxCommandEvent& aEvent );
155 
156  void reportZoneConnection( ZONE* aZone, PAD* aPad, REPORTER* r );
157 
158  void reportClearance( DRC_CONSTRAINT_T aClearanceType, PCB_LAYER_ID aLayer, BOARD_ITEM* aA,
159  BOARD_ITEM* aB, REPORTER* r );
160 
161  wxString getItemDescription( BOARD_ITEM* aItem );
162 
163 private:
164  PCB_EDIT_FRAME* m_frame; // Pointer to the currently used edit frame.
165 
166  bool m_probingSchToPcb; // Recursion guard when cross-probing to Eeschema
167  std::set<int> m_currentlyHighlighted; // Active net being highlighted, or -1 when off
168  std::set<int> m_lastHighlighted; // Used for toggling between last two highlighted nets
169 
170  CONNECTIVITY_DATA* m_dynamicData; // Cached connectivity data from the selection
171 
172  std::unique_ptr<DIALOG_NET_INSPECTOR> m_listNetsDialog;
174 
175  std::unique_ptr<DIALOG_INSPECTION_REPORTER> m_inspectClearanceDialog;
176  std::unique_ptr<DIALOG_CONSTRAINTS_REPORTER> m_inspectConstraintsDialog;
177 };
178 
179 #endif //BOARD_INSPECTION_TOOL_H
void reportClearance(DRC_CONSTRAINT_T aClearanceType, PCB_LAYER_ID aLayer, BOARD_ITEM *aA, BOARD_ITEM *aB, REPORTER *r)
int HideDynamicRatsnest(const TOOL_EVENT &aEvent)
Show local ratsnest of a component.
wxString getItemDescription(BOARD_ITEM *aItem)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
int LocalRatsnestTool(const TOOL_EVENT &aEvent)
int InspectClearance(const TOOL_EVENT &aEvent)
int ClearHighlight(const TOOL_EVENT &aEvent)
Launch a tool to pick the item whose net is going to be highlighted.
int CrossProbePcbToSch(const TOOL_EVENT &aEvent)
Highlight net belonging to the item under the cursor.
void InspectDRCError(const std::shared_ptr< RC_ITEM > &aDRCItem)
Show the clearance resolution for two selected items.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
std::set< int > m_currentlyHighlighted
DRC_CONSTRAINT_T
Definition: drc_rule.h:41
int InspectConstraints(const TOOL_EVENT &aEvent)
std::set< int > m_lastHighlighted
PCB_LAYER_ID
A quick note on layer IDs:
int HighlightNet(const TOOL_EVENT &aEvent)
Clear all board highlights.
std::unique_ptr< DIALOG_CONSTRAINTS_REPORTER > m_inspectConstraintsDialog
void onInspectClearanceDialogClosed(wxCommandEvent &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Generic, UI-independent tool event.
Definition: tool_event.h:152
Class DIALOG_HTML_REPORTER.
int HighlightItem(const TOOL_EVENT &aEvent)
Update ratsnest for selected items.
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
int ShowNet(const TOOL_EVENT &aEvent)
void ratsnestTimer(wxTimerEvent &aEvent)
< Event handler to recalculate dynamic ratsnest.
bool highlightNet(const VECTOR2D &aPosition, bool aUseSelection)
Look for a BOARD_CONNECTED_ITEM in a given spot and if one is found - it enables highlight for its ne...
std::unique_ptr< DIALOG_NET_INSPECTOR > m_listNetsDialog
void reportZoneConnection(ZONE *aZone, PAD *aPad, REPORTER *r)
int ListNets(const TOOL_EVENT &aEvent)
Hide the ratsnest for a given net.
int HighlightNetTool(const TOOL_EVENT &aEvent)
Perform the appropriate action in response to an Eeschema cross-probe.
DIALOG_NET_INSPECTOR::SETTINGS m_listNetsDialogSettings
bool Init() override
Init() is called once upon a registration of the tool.
void onListNetsDialogClosed(wxCommandEvent &aEvent)
void doHideNet(int aNetCode, bool aHide)
Bind handlers to corresponding TOOL_ACTIONs.
The main frame for Pcbnew.
DIALOG_INSPECTION_REPORTER(PCB_EDIT_FRAME *aFrame)
int FlipPcbView(const TOOL_EVENT &aEvent)
CONNECTIVITY_DATA * m_dynamicData
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
int HideNet(const TOOL_EVENT &aEvent)
Show the ratsnest for a given net.
int UpdateSelectionRatsnest(const TOOL_EVENT &aEvent)
Hide ratsnest for selected items. Called when there are no items selected.
void OnOK(wxCommandEvent &event) override
Definition: pad.h:57
std::unique_ptr< DIALOG_INSPECTION_REPORTER > m_inspectClearanceDialog
void calculateSelectionRatsnest(const VECTOR2I &aDelta)
void onInspectConstraintsDialogClosed(wxCommandEvent &aEvent)
int ShowStatisticsDialog(const TOOL_EVENT &aEvent)
Show dialog with board statistics.
void OnErrorLinkClicked(wxHtmlLinkEvent &event) override
Tool for pcb inspection.