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;
37
60{
61public:
62 PCB_NET_INSPECTOR_PANEL( wxWindow* parent, PCB_EDIT_FRAME* aFrame );
64
70 virtual void OnParentSetupChanged() override;
71
72 /*
73 * BOARD_LISTENER implementation
74 */
75 virtual void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
76 virtual void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems ) override;
77 virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
78 virtual void OnBoardItemsRemoved( BOARD& aBoard,
79 std::vector<BOARD_ITEM*>& aBoardItems ) override;
80 virtual void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
81 virtual void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
82 virtual void OnBoardItemsChanged( BOARD& aBoard,
83 std::vector<BOARD_ITEM*>& aBoardItems ) override;
84 virtual void OnBoardHighlightNetChanged( BOARD& aBoard ) override;
85 virtual void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
86 std::vector<BOARD_ITEM*>& aRemovedItems,
87 std::vector<BOARD_ITEM*>& aDeletedItems ) override;
91 virtual void OnBoardChanged() override;
92
96 virtual void OnShowPanel() override;
97
101 virtual void SaveSettings() override;
102
103protected:
107 virtual void OnLanguageChangedImpl() override;
108
109 /*
110 * UI events
111 */
112 virtual void OnSearchTextChanged( wxCommandEvent& event ) override;
113 virtual void OnConfigButton( wxCommandEvent& event ) override;
114 void OnExpandCollapseRow( wxCommandEvent& event );
115 void OnHeaderContextMenu( wxCommandEvent& event );
116 void OnNetsListContextMenu( wxDataViewEvent& event );
117 void OnNetsListItemActivated( wxDataViewEvent& event );
118 void OnColumnSorted( wxDataViewEvent& event );
119
120private:
121 /*
122 * Helper methods for returning fornatted data
123 */
124 wxString formatNetCode( const NETINFO_ITEM* aNet ) const;
125 wxString formatNetName( const NETINFO_ITEM* aNet ) const;
126 wxString formatCount( unsigned int aValue ) const;
127 wxString formatLength( int64_t aValue ) const;
128
132 void generateShowHideColumnMenu( wxMenu* target );
133
138 std::vector<CN_ITEM*> relevantConnectivityItems() const;
139
143 bool netFilterMatches( NETINFO_ITEM* aNet, PANEL_NET_INSPECTOR_SETTINGS* cfg = nullptr ) const;
144
148 void updateNet( NETINFO_ITEM* aNet );
149
153 unsigned int calculateViaLength( const PCB_TRACK* ) const;
154
155 void buildNetsList( bool rebuildColumns = false );
156 void buildColumns();
158
165
173 bool restoreSortColumn( int sortingColumnId, bool sortOrderAsc );
174
181 wxDataViewColumn* getDisplayedColumnForModelField( int columnId );
182
186 void generateReport();
187
192
193 void onUnitsChanged( wxCommandEvent& event );
194 void onSettingsMenu( wxCommandEvent& event );
195 void onItemContextMenu( wxCommandEvent& event );
196 void onAddNet();
197 void onRenameSelectedNet();
198 void onDeleteSelectedNet();
200 void onAddGroup();
201 void onClearHighlighting();
202
206 class LIST_ITEM;
207
212
217
218 using LIST_ITEM_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::iterator;
219 using LIST_ITEM_CONST_ITER = std::vector<std::unique_ptr<LIST_ITEM>>::const_iterator;
220
224 std::unique_ptr<LIST_ITEM> buildNewItem( NETINFO_ITEM* aNet, unsigned int aPadCount,
225 const std::vector<CN_ITEM*>& aCNItems );
226
227 void updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow );
228
229 // special zero-netcode item. Unconnected pads etc might use different
230 // (dummy) NETINFO_ITEM. Redirect all of them to this item, which we get
231 // from the board object in buildNetsList.
233
234 /*
235 * Current board and parent edit frame
236 */
237 BOARD* m_brd = nullptr;
239
243 class DATA_MODEL;
244
245 /*
246 * The bound data model to display
247 */
248 wxObjectDataPtr<DATA_MODEL> m_data_model;
250
251 /*
252 * Status flags set during reporting and net rebuild operations
253 */
254 bool m_in_reporting = false;
256
257 /*
258 * Status flags to indicate whether a board has been loaded in this control's
259 * lifetime. Required as on PCB_EDIT_FRAME construction, there are multiple events
260 * triggered which would usually result in saving settings and re-loading the board.
261 * However, before the board loads the frame is in an inconsistent state: The project
262 * settings are available, but the board is not yet loaded. This results in overwriting
263 * settings calculated from an empty board. We do not save settings until the first
264 * board load operation has occured.
265 */
266 bool m_board_loaded = false;
267 bool m_board_loading = false;
268
269 /*
270 * Flags to indicate whether certain events should be disabled during programmatic updates
271 */
272 bool m_row_expanding = false;
274
275 /*
276 * Configuration flags - these are all persisted to the project storage
277 */
284
286
287 std::vector<wxString> m_custom_group_rules;
288
292 enum class CSV_COLUMN_DESC : int
293 {
294 CSV_NONE = 0,
295 CSV_QUOTE = 1 << 0
296 };
297
302 {
303 COLUMN_DESC( unsigned aNum, PCB_LAYER_ID aLayer, const wxString& aDisp,
304 const wxString& aCsv, CSV_COLUMN_DESC aFlags, bool aHasUnits ) :
305 num( aNum ),
306 layer( aLayer ), display_name( aDisp ), csv_name( aCsv ), csv_flags( aFlags ),
307 has_units( aHasUnits )
308 {
309 }
310
311 unsigned int num;
313 wxString display_name;
314 wxString csv_name;
317
318 operator unsigned int() const { return num; }
319 };
320
324 std::vector<COLUMN_DESC> m_columns;
325
326 /*
327 * Column static IDs. Used to refer to columns as use re-ordering can occur.
328 */
329 enum
330 {
340 };
341
342 /*
343 * Popup menu item IDs
344 */
346 {
364 };
365};
366
367#endif
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
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.
std::vector< wxString > m_custom_group_rules
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.
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)