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#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 wxString formatDelay( int64_t aValue ) const;
112
114 void generateShowHideColumnMenu( wxMenu* target );
115
117 std::vector<CN_ITEM*> relevantConnectivityItems() const;
118
120 bool netFilterMatches( NETINFO_ITEM* aNet, PANEL_NET_INSPECTOR_SETTINGS* cfg = nullptr ) const;
121
123 void buildNetsList( bool rebuildColumns = false );
124
126 void buildColumns();
127
130
137
145 bool restoreSortColumn( int sortingColumnId, bool sortOrderAsc ) const;
146
153 wxDataViewColumn* getDisplayedColumnForModelField( int columnId ) const;
154
156 void generateReport();
157
160
162 void onUnitsChanged( wxCommandEvent& event );
163
165 void onContextMenuSelection( wxCommandEvent& event );
166
168 void onItemContextMenu( wxCommandEvent& event );
169
171 void onAddNet();
172
174 void onRenameSelectedNet();
175
177 void onDeleteSelectedNet();
178
180 void onAddGroup();
181
184
186 void onClearHighlighting();
187
189 class LIST_ITEM;
190
198 std::vector<std::unique_ptr<LIST_ITEM>> calculateNets( const std::vector<NETINFO_ITEM*>& aNetCodes,
199 bool aIncludeZeroPadNets ) const;
200
203
206
207 using LIST_ITEM_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::iterator;
208 using LIST_ITEM_CONST_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::const_iterator;
209
211 void updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow ) const;
212
214 BOARD* m_board = nullptr;
215
218
220 class DATA_MODEL;
221
223 wxObjectDataPtr<DATA_MODEL> m_dataModel;
225
226 /*
227 * Status flags set during reporting and net rebuild operations
228 */
229 bool m_inReporting = false;
230 bool m_inBuildNetsList = false;
231
232 /*
233 * Status flags to indicate whether a board has been loaded in this control's
234 * lifetime. Required as on PCB_EDIT_FRAME construction, there are multiple events
235 * triggered which would usually result in saving settings and re-loading the board.
236 * However, before the board loads the frame is in an inconsistent state: The project
237 * settings are available, but the board is not yet loaded. This results in overwriting
238 * settings calculated from an empty board. We do not save settings until the first
239 * board load operation has occured.
240 */
241 bool m_boardLoaded = false;
242 bool m_boardLoading = false;
243
244 /*
245 * Flags to indicate whether certain events should be disabled during programmatic updates
246 */
247 bool m_rowExpanding = false;
248 bool m_highlightingNets = false;
249
250 /*
251 * Configuration flags - these are all persisted to the project storage
252 */
253 bool m_filterByNetName = true;
255 bool m_showZeroPadNets = false;
257 bool m_groupByNetclass = false;
260
262 std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>> m_custom_group_rules;
263
265 enum class CSV_COLUMN_DESC : int
266 {
268 CSV_QUOTE = 1 << 0
269 };
270
273 {
274 COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp,
275 const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) :
276 num( aNum ),
277 layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ),
278 has_units( aHasUnits )
279 {
280 }
281
282 unsigned int num;
284 wxString display_name;
285 wxString csv_name;
288
289 operator unsigned int() const { return num; }
290 };
291
295 std::vector<COLUMN_DESC> m_columns;
296
298 enum
299 {
309 };
310
333};
334
335#endif
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:317
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 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.
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 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.
@ 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)