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 (C) 2024 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
61{
62public:
63 PCB_NET_INSPECTOR_PANEL( wxWindow* parent, PCB_EDIT_FRAME* aFrame );
65
71 virtual void OnParentSetupChanged() override;
72
73 /*
74 * BOARD_LISTENER implementation
75 */
76 virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
77 virtual void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
78 virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
79 virtual void OnBoardItemsRemoved( BOARD& aBoard,
80 std::vector<BOARD_ITEM*>& aBoardItems ) override;
81 virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
82 virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
83 virtual void OnBoardItemsChanged( BOARD& aBoard,
84 std::vector<BOARD_ITEM*>& aBoardItems ) override;
85 virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) override;
86 virtual void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
87 std::vector<BOARD_ITEM*>& aRemovedItems,
88 std::vector<BOARD_ITEM*>& aDeletedItems ) override;
92 virtual void OnBoardChanged() override;
93
97 virtual void OnShowPanel() override;
98
102 virtual void SaveSettings() override;
103
104protected:
108 virtual void OnLanguageChangedImpl() override;
109
110 /*
111 * UI events
112 */
113 virtual void OnSearchTextChanged( wxCommandEvent& event ) override;
114 virtual void OnConfigButton( wxCommandEvent& event ) override;
115 void OnExpandCollapseRow( wxCommandEvent& event );
116 void OnHeaderContextMenu( wxCommandEvent& event );
117 void OnNetsListContextMenu( wxDataViewEvent& event );
118 void OnNetsListItemActivated( wxDataViewEvent& event );
119 void OnColumnSorted( wxDataViewEvent& event );
120
121private:
122 /*
123 * Helper methods for returning fornatted data
124 */
125 wxString formatNetCode( const NETINFO_ITEM* aNet ) const;
126 wxString formatNetName( const NETINFO_ITEM* aNet ) const;
127 wxString formatCount( unsigned int aValue ) const;
128 wxString formatLength( int64_t aValue ) const;
129
133 void generateShowHideColumnMenu( wxMenu* target );
134
139 std::vector<CN_ITEM*> relevantConnectivityItems() const;
140
144 bool netFilterMatches( NETINFO_ITEM* aNet, PANEL_NET_INSPECTOR_SETTINGS* cfg = nullptr ) const;
145
149 void updateNet( NETINFO_ITEM* aNet );
150
154 unsigned int calculateViaLength( const PCB_TRACK* ) const;
155
156 void buildNetsList( bool rebuildColumns = false );
157 void buildColumns();
159
166
174 bool restoreSortColumn( int sortingColumnId, bool sortOrderAsc );
175
182 wxDataViewColumn* getDisplayedColumnForModelField( int columnId );
183
187 void generateReport();
188
193
194 void onUnitsChanged( wxCommandEvent& event );
195 void onSettingsMenu( wxCommandEvent& event );
196 void onItemContextMenu( wxCommandEvent& event );
197 void onAddNet();
198 void onRenameSelectedNet();
199 void onDeleteSelectedNet();
201 void onAddGroup();
202 void onClearHighlighting();
203
207 class LIST_ITEM;
208
213
218
219 using LIST_ITEM_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::iterator;
220 using LIST_ITEM_CONST_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::const_iterator;
221
225 std::unique_ptr<LIST_ITEM> buildNewItem( NETINFO_ITEM* aNet, unsigned int aPadCount,
226 const std::vector<CN_ITEM*>& aCNItems );
227
228 void updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow );
229
230 // special zero-netcode item. Unconnected pads etc might use different
231 // (dummy) NETINFO_ITEM. Redirect all of them to this item, which we get
232 // from the board object in buildNetsList.
234
235 /*
236 * Current board and parent edit frame
237 */
238 BOARD* m_brd = nullptr;
240
244 class DATA_MODEL;
245
246 /*
247 * The bound data model to display
248 */
249 wxObjectDataPtr<DATA_MODEL> m_data_model;
251
252 /*
253 * Status flags set during reporting and net rebuild operations
254 */
255 bool m_in_reporting = false;
257
258 /*
259 * Status flags to indicate whether a board has been loaded in this control's
260 * lifetime. Required as on PCB_EDIT_FRAME construction, there are multiple events
261 * triggered which would usually result in saving settings and re-loading the board.
262 * However, before the board loads the frame is in an inconsistent state: The project
263 * settings are available, but the board is not yet loaded. This results in overwriting
264 * settings calculated from an empty board. We do not save settings until the first
265 * board load operation has occured.
266 */
267 bool m_board_loaded = false;
268 bool m_board_loading = false;
269
270 /*
271 * Flags to indicate whether certain events should be disabled during programmatic updates
272 */
273 bool m_row_expanding = false;
275
276 /*
277 * Configuration flags - these are all persisted to the project storage
278 */
285
287
288 std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>> m_custom_group_rules;
289
293 enum class CSV_COLUMN_DESC : int
294 {
295 CSV_NONE = 0,
296 CSV_QUOTE = 1 << 0
297 };
298
303 {
304 COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp,
305 const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) :
306 num( aNum ),
307 layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ),
308 has_units( aHasUnits )
309 {
310 }
311
312 unsigned int num;
314 wxString display_name;
315 wxString csv_name;
318
319 operator unsigned int() const { return num; }
320 };
321
325 std::vector<COLUMN_DESC> m_columns;
326
327 /*
328 * Column static IDs. Used to refer to columns as use re-ordering can occur.
329 */
330 enum
331 {
341 };
342
343 /*
344 * Popup menu item IDs
345 */
347 {
365 };
366};
367
368#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:290
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.
Net inspection panel for pcbnew.
virtual 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
virtual void OnBoardHighlightNetChanged(BOARD &aBoard) override
void generateReport()
Generates a CSV report from currently disaplyed data.
wxString formatCount(unsigned int aValue) const
virtual void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
virtual void OnSearchTextChanged(wxCommandEvent &event) override
virtual void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
virtual void OnBoardChanged() override
Update panel when board is changed.
void generateShowHideColumnMenu(wxMenu *target)
Generates a sub-menu for the show / hide columns submenu.
wxString formatNetCode(const NETINFO_ITEM *aNet) const
CSV_COLUMN_DESC
CSV output control.
std::unique_ptr< LIST_ITEM > buildNewItem(NETINFO_ITEM *aNet, unsigned int aPadCount, const std::vector< CN_ITEM * > &aCNItems)
Constructs a LIST_ITEM for storage in the data model from a board net item.
std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > m_custom_group_rules
wxString formatNetName(const NETINFO_ITEM *aNet) const
void onSettingsMenu(wxCommandEvent &event)
std::vector< CN_ITEM * > relevantConnectivityItems() const
Filters connectivity items from a board update to remove those not related to net / track metrics.
unsigned int calculateViaLength(const PCB_TRACK *) const
Calculates the length of a via from the board stackup.
void highlightSelectedNets()
Highlight the currently selected net.
virtual void OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aDeletedItems) override
virtual void OnBoardItemsAdded(BOARD &aBoard, std::vector< BOARD_ITEM * > &aBoardItems) override
wxObjectDataPtr< DATA_MODEL > m_data_model
void updateNet(NETINFO_ITEM *aNet)
Updates the stored LIST_ITEMs for a given updated board net item.
virtual void OnLanguageChangedImpl() override
Reloads strings on an application language change.
void OnNetsListContextMenu(wxDataViewEvent &event)
virtual void OnBoardNetSettingsChanged(BOARD &aBoard) override
void OnNetsListItemActivated(wxDataViewEvent &event)
void OnColumnSorted(wxDataViewEvent &event)
void updateDisplayedRowValues(const std::optional< LIST_ITEM_ITER > &aRow)
virtual void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
virtual 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.
virtual void OnConfigButton(wxCommandEvent &event) override
void buildNetsList(bool rebuildColumns=false)
bool restoreSortColumn(int sortingColumnId, bool sortOrderAsc)
Sets the sort column in the grid to that showing the given model ID column.
wxString formatLength(int64_t aValue) const
virtual void SaveSettings() override
Persist the net inspector configuration to project / global settings.
void onUnitsChanged(wxCommandEvent &event)
void OnExpandCollapseRow(wxCommandEvent &event)
wxDataViewColumn * getDisplayedColumnForModelField(int columnId)
Fetches the displayed grid view column for the given model column ID.
void adjustListColumnSizes(PANEL_NET_INSPECTOR_SETTINGS *cfg)
Adjust the sizing of list columns.
void onItemContextMenu(wxCommandEvent &event)
virtual void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
std::vector< COLUMN_DESC > m_columns
All displayed (or hidden) columns.
virtual void OnShowPanel() override
Prepare the panel when shown in the editor.
@ ID_POPUP_MENU_START
Definition: id.h:189
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)