KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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#pragma once
21
22#include <board.h>
23#include <id.h>
26
27#include <optional>
28#include <vector>
29
30class PCB_EDIT_FRAME;
31class NETINFO_ITEM;
32class BOARD;
33class BOARD_ITEM;
34class CN_ITEM;
35class PCB_TRACK;
37
45{
46public:
47 PCB_NET_INSPECTOR_PANEL( wxWindow* parent, PCB_EDIT_FRAME* aFrame );
49
55 void OnParentSetupChanged() override;
56
57 /*
58 * BOARD_LISTENER implementation
59 */
60 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
61 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
62 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
63 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
64 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
65 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
66 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
67 void OnBoardHighlightNetChanged( BOARD& aBoard ) override;
68 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
69 std::vector<BOARD_ITEM*>& aRemovedItems,
70 std::vector<BOARD_ITEM*>& aChangedItems ) override;
71
73 void OnBoardChanged() override;
74
76 void OnShowPanel() override;
77
79 void SaveSettings() override;
80
81protected:
83 void OnLanguageChangedImpl() override;
84
85 /*
86 * UI events
87 */
88 void OnSearchTextChanged( wxCommandEvent& event ) override;
89 void OnConfigButton( wxCommandEvent& event ) override;
90 void OnExpandCollapseRow( wxCommandEvent& event );
91 void OnHeaderContextMenu( wxCommandEvent& event );
92 void OnNetsListContextMenu( wxDataViewEvent& event );
93 void OnNetsListItemActivated( wxDataViewEvent& event );
94 void OnColumnSorted( wxDataViewEvent& event );
95
96private:
98 void updateNets( const std::vector<NETINFO_ITEM*>& aNets ) const;
99
101 void updateBoardItems( const std::vector<BOARD_ITEM*>& aBoardItems );
102
103 /*
104 * Helper methods for returning formatted data
105 */
106 static wxString formatNetCode( const NETINFO_ITEM* aNet );
107 static wxString formatNetName( const NETINFO_ITEM* aNet );
108 static wxString formatCount( unsigned int aValue );
109 wxString formatLength( int64_t aValue ) const;
110 wxString formatDelay( 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
133
141 bool restoreSortColumn( int sortingColumnId, bool sortOrderAsc ) const;
142
149 wxDataViewColumn* getDisplayedColumnForModelField( int columnId ) const;
150
152 void generateReport();
153
156
158 void onUnitsChanged( wxCommandEvent& event );
159
161 void onContextMenuSelection( wxCommandEvent& event );
162
164 void onAddNet();
165
167 void onRenameSelectedNet();
168
170 void onDeleteSelectedNet();
171
173 void onAddGroup();
174
177
179 void onClearHighlighting();
180
182 class LIST_ITEM;
183
192 std::vector<std::unique_ptr<LIST_ITEM>> calculateNets( const std::vector<NETINFO_ITEM*>& aNetCodes,
193 bool aIncludeZeroPadNets ) const;
194
197
200
201 using LIST_ITEM_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::iterator;
202 using LIST_ITEM_CONST_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::const_iterator;
203
205 void updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow ) const;
206
208 BOARD* m_board = nullptr;
209
212
214 class DATA_MODEL;
215
217 wxObjectDataPtr<DATA_MODEL> m_dataModel;
219
220 /*
221 * Status flags set during reporting and net rebuild operations
222 */
223 bool m_inReporting = false;
224 bool m_inBuildNetsList = false;
225
226 /*
227 * Status flags to indicate whether a board has been loaded in this control's
228 * lifetime. Required as on PCB_EDIT_FRAME construction, there are multiple events
229 * triggered which would usually result in saving settings and re-loading the board.
230 * However, before the board loads the frame is in an inconsistent state: The project
231 * settings are available, but the board is not yet loaded. This results in overwriting
232 * settings calculated from an empty board. We do not save settings until the first
233 * board load operation has occured.
234 */
235 bool m_boardLoaded = false;
236 bool m_boardLoading = false;
237
238 /*
239 * Flags to indicate whether certain events should be disabled during programmatic updates
240 */
241 bool m_rowExpanding = false;
242 bool m_highlightingNets = false;
243
244 /*
245 * Configuration flags - these are all persisted to the project storage
246 */
247 bool m_filterByNetName = true;
249 bool m_showZeroPadNets = false;
251 bool m_groupByNetclass = false;
254
256 std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>> m_custom_group_rules;
257
259 enum class CSV_COLUMN_DESC : int
260 {
262 CSV_QUOTE = 1 << 0
263 };
264
267 {
268 COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp,
269 const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) :
270 num( aNum ),
271 layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ),
272 has_units( aHasUnits )
273 {
274 }
275
276 unsigned int num;
278 wxString display_name;
279 wxString csv_name;
282
283 operator unsigned int() const { return num; }
284 };
285
289 std::vector<COLUMN_DESC> m_columns;
290
292 enum
293 {
303 };
304
327};
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
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:54
NET_INSPECTOR_PANEL(wxWindow *parent, EDA_BASE_FRAME *aFrame, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1, -1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
The main frame for Pcbnew.
Data model for display in the Net Inspector panel.
Primary data item for entries in the Net Inspector list.
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
void OnBoardHighlightNetChanged(BOARD &aBoard) override
void generateReport()
Generates a CSV report from currently disaplyed data.
PCB_NET_INSPECTOR_PANEL(wxWindow *parent, PCB_EDIT_FRAME *aFrame)
std::vector< std::unique_ptr< LIST_ITEM > >::const_iterator LIST_ITEM_CONST_ITER
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.
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 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.
std::vector< std::unique_ptr< LIST_ITEM > >::iterator LIST_ITEM_ITER
void OnExpandCollapseRow(wxCommandEvent &event)
void updateBoardItems(const std::vector< BOARD_ITEM * > &aBoardItems)
Unified handling of added / deleted / modified board items.
wxString formatDelay(int64_t aValue) const
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 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.
@ ID_POPUP_MENU_START
Definition id.h:158
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)