KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_net_inspector_panel.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 The 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
20#ifndef PCB_NET_INSPECTOR_H
21#define PCB_NET_INSPECTOR_H
22
23#include <board.h>
24#include <id.h>
27
28#include <optional>
29#include <vector>
30
31class PCB_EDIT_FRAME;
32class NETINFO_ITEM;
33class BOARD;
34class BOARD_ITEM;
35class CN_ITEM;
36class PCB_TRACK;
38
46{
47public:
48 PCB_NET_INSPECTOR_PANEL( wxWindow* parent, PCB_EDIT_FRAME* aFrame );
50
56 void OnParentSetupChanged() override;
57
58 /*
59 * BOARD_LISTENER implementation
60 */
61 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
62 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
63 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
64 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
65 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
66 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
67 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
68 void OnBoardHighlightNetChanged( BOARD& aBoard ) override;
69 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
70 std::vector<BOARD_ITEM*>& aRemovedItems,
71 std::vector<BOARD_ITEM*>& aChangedItems ) override;
72
74 void OnBoardChanged() override;
75
77 void OnShowPanel() override;
78
80 void SaveSettings() override;
81
82protected:
84 void OnLanguageChangedImpl() override;
85
86 /*
87 * UI events
88 */
89 void OnSearchTextChanged( wxCommandEvent& event ) override;
90 void OnConfigButton( wxCommandEvent& event ) override;
91 void OnExpandCollapseRow( wxCommandEvent& event );
92 void OnHeaderContextMenu( wxCommandEvent& event );
93 void OnNetsListContextMenu( wxDataViewEvent& event );
94 void OnNetsListItemActivated( wxDataViewEvent& event );
95 void OnColumnSorted( wxDataViewEvent& event );
96
97private:
99 void updateNets( const std::vector<NETINFO_ITEM*>& aNets ) const;
100
102 void updateBoardItems( const std::vector<BOARD_ITEM*>& aBoardItems );
103
104 /*
105 * Helper methods for returning formatted data
106 */
107 static wxString formatNetCode( const NETINFO_ITEM* aNet );
108 static wxString formatNetName( const NETINFO_ITEM* aNet );
109 static wxString formatCount( unsigned int aValue );
110 wxString formatLength( int64_t aValue ) const;
111
113 void generateShowHideColumnMenu( wxMenu* target );
114
116 std::vector<CN_ITEM*> relevantConnectivityItems() const;
117
119 bool netFilterMatches( NETINFO_ITEM* aNet, PANEL_NET_INSPECTOR_SETTINGS* cfg = nullptr ) const;
120
122 void buildNetsList( bool rebuildColumns = false );
123
125 void buildColumns();
126
129
136
144 bool restoreSortColumn( int sortingColumnId, bool sortOrderAsc ) const;
145
152 wxDataViewColumn* getDisplayedColumnForModelField( int columnId ) const;
153
155 void generateReport();
156
159
161 void onUnitsChanged( wxCommandEvent& event );
162
164 void onContextMenuSelection( wxCommandEvent& event );
165
167 void onItemContextMenu( wxCommandEvent& event );
168
170 void onAddNet();
171
173 void onRenameSelectedNet();
174
176 void onDeleteSelectedNet();
177
179 void onAddGroup();
180
183
185 void onClearHighlighting();
186
188 class LIST_ITEM;
189
197 std::vector<std::unique_ptr<LIST_ITEM>> calculateNets( const std::vector<NETINFO_ITEM*>& aNetCodes,
198 bool aIncludeZeroPadNets ) const;
199
202
205
206 using LIST_ITEM_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::iterator;
207 using LIST_ITEM_CONST_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::const_iterator;
208
210 void updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow ) const;
211
213 BOARD* m_board = nullptr;
214
217
219 class DATA_MODEL;
220
222 wxObjectDataPtr<DATA_MODEL> m_dataModel;
224
225 /*
226 * Status flags set during reporting and net rebuild operations
227 */
228 bool m_inReporting = false;
229 bool m_inBuildNetsList = false;
230
231 /*
232 * Status flags to indicate whether a board has been loaded in this control's
233 * lifetime. Required as on PCB_EDIT_FRAME construction, there are multiple events
234 * triggered which would usually result in saving settings and re-loading the board.
235 * However, before the board loads the frame is in an inconsistent state: The project
236 * settings are available, but the board is not yet loaded. This results in overwriting
237 * settings calculated from an empty board. We do not save settings until the first
238 * board load operation has occured.
239 */
240 bool m_boardLoaded = false;
241 bool m_boardLoading = false;
242
243 /*
244 * Flags to indicate whether certain events should be disabled during programmatic updates
245 */
246 bool m_rowExpanding = false;
247 bool m_highlightingNets = false;
248
249 /*
250 * Configuration flags - these are all persisted to the project storage
251 */
252 bool m_filterByNetName = true;
254 bool m_showZeroPadNets = false;
256 bool m_groupByNetclass = false;
258
260 std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>> m_custom_group_rules;
261
263 enum class CSV_COLUMN_DESC : int
264 {
265 CSV_NONE = 0,
266 CSV_QUOTE = 1 << 0
267 };
268
271 {
272 COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp,
273 const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) :
274 num( aNum ),
275 layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ),
276 has_units( aHasUnits )
277 {
278 }
279
280 unsigned int num;
282 wxString display_name;
283 wxString csv_name;
286
287 operator unsigned int() const { return num; }
288 };
289
293 std::vector<COLUMN_DESC> m_columns;
294
296 enum
297 {
307 };
308
311 {
329 };
330};
331
332#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:78
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
CN_ITEM represents a BOARD_CONNETED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
Handle the data for a net.
Definition: netinfo.h:56
A base class used to implement docking net inspector panels.
The main frame for Pcbnew.
Data model for display in the Net Inspector panel.
Primary data item for entries in the Net Inspector list.
PCB net inspection panel.
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
std::vector< std::unique_ptr< LIST_ITEM > >::const_iterator LIST_ITEM_CONST_ITER
std::vector< std::unique_ptr< LIST_ITEM > >::iterator LIST_ITEM_ITER
void OnBoardHighlightNetChanged(BOARD &aBoard) override
void generateReport()
Generates a CSV report from currently disaplyed data.
void onDeleteSelectedNet()
Deletes a selected net.
bool restoreSortColumn(int sortingColumnId, bool sortOrderAsc) const
Sets the sort column in the grid to that showing the given model ID column.
void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
void adjustListColumnSizes(PANEL_NET_INSPECTOR_SETTINGS *cfg) const
Adjust the sizing of list columns.
void OnSearchTextChanged(wxCommandEvent &event) override
void updateDisplayedRowValues(const std::optional< LIST_ITEM_ITER > &aRow) const
Refreshes displayed data for the given rows.
void onAddNet()
Adds a new user-specified net to the board.
PCB_EDIT_FRAME * m_frame
Owning edit frame.
void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
void onClearHighlighting()
Clears highlighting from nets.
void onContextMenuSelection(wxCommandEvent &event)
Handle a net row(s) context menu selection.
static wxString formatNetCode(const NETINFO_ITEM *aNet)
void OnBoardChanged() override
Update panel when board is changed.
void generateShowHideColumnMenu(wxMenu *target)
Generates a sub-menu for the show / hide columns submenu.
std::vector< std::unique_ptr< LIST_ITEM > > calculateNets(const std::vector< NETINFO_ITEM * > &aNetCodes, bool aIncludeZeroPadNets) const
Calculates the length statistics for each given netcode.
CSV_COLUMN_DESC
CSV output control.
static wxString formatCount(unsigned int aValue)
std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > m_custom_group_rules
Custom net grouping rules.
std::vector< CN_ITEM * > relevantConnectivityItems() const
Fetches an ordered (by NetCode) list of all board connectivity items.
void highlightSelectedNets()
Highlight the currently selected net.
void updateNets(const std::vector< NETINFO_ITEM * > &aNets) const
Updates displayed statistics for the given nets.
void OnBoardItemsAdded(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
void OnLanguageChangedImpl() override
Reloads strings on an application language change.
void onAddGroup()
Adds a custom display grouping of nets.
void OnNetsListContextMenu(wxDataViewEvent &event)
void OnBoardNetSettingsChanged(BOARD &aBoard) override
void OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems) override
void OnNetsListItemActivated(wxDataViewEvent &event)
void OnColumnSorted(wxDataViewEvent &event)
void onRemoveSelectedGroup()
Removes a custom display grouping.
POPUP_MENU_OPTIONS
Popup menu item IDs.
void buildColumns()
Build the required columns in the net inspector grid.
void setColumnWidths()
Set sensible default column widths.
void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
void OnParentSetupChanged() override
Updates the netlist based on global board changes (e.g.
void OnHeaderContextMenu(wxCommandEvent &event)
bool netFilterMatches(NETINFO_ITEM *aNet, PANEL_NET_INSPECTOR_SETTINGS *cfg=nullptr) const
Filter to determine whether a board net should be included in the net inspector.
void OnConfigButton(wxCommandEvent &event) override
void buildNetsList(bool rebuildColumns=false)
Rebuilds the net inspector list, removing all previous entries.
wxString formatLength(int64_t aValue) const
void SaveSettings() override
Persist the net inspector configuration to project / global settings.
void onRenameSelectedNet()
Renames a selected net.
void onUnitsChanged(wxCommandEvent &event)
Handle an application-level change of units.
void OnExpandCollapseRow(wxCommandEvent &event)
void updateBoardItems(const std::vector< BOARD_ITEM * > &aBoardItems)
Unified handling of added / deleted / modified board items.
wxObjectDataPtr< DATA_MODEL > m_dataModel
The bound data model to display.
wxDataViewColumn * getDisplayedColumnForModelField(int columnId) const
Fetches the displayed grid view column for the given model column ID.
static wxString formatNetName(const NETINFO_ITEM *aNet)
void onItemContextMenu(wxCommandEvent &event)
Display a new row(s) context menu.
void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
std::vector< COLUMN_DESC > m_columns
All displayed (or hidden) columns.
void OnShowPanel() override
Prepare the panel when shown in the editor.
Common command IDs shared by more than one of the KiCad applications.
@ ID_POPUP_MENU_START
Definition: id.h:181
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
Persisted state for the net inspector panel.
COLUMN_DESC(unsigned aNum, PCB_LAYER_ID aLayer, const wxString &aDisp, const wxString &aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits)