KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_net_inspector_panel.cpp
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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <properties/property.h>
23
24#include <advanced_config.h>
26#include <confirm.h>
31#include <footprint.h>
34#include <net_chain_bridging.h>
35#include <pad.h>
36#include <pcb_edit_frame.h>
37#include <pcb_painter.h>
38#include <pgm_base.h>
40#include <string_utils.h>
41#include <validators.h>
43#include <eda_pattern_match.h>
44#include <map>
45#include <cmath>
46
47#include <wx/wupdlock.h>
48#include <wx/filedlg.h>
49#include <kiplatform/ui.h>
50
51#include <algorithm>
52#include <thread_pool.h>
54
56 NET_INSPECTOR_PANEL( parent, aFrame ),
57 m_frame( aFrame ),
58 m_dataModel( new DATA_MODEL( *this ) )
59{
60 m_board = m_frame->GetBoard();
61
62 m_netsList->AssociateModel( &*m_dataModel );
63
64 // Rebuild nets list
65 buildNetsList( true );
66
67 // Register the panel to receive board change notifications
68 if( m_board != nullptr )
69 {
71 m_board->AddListener( this );
72 }
73
74 // Connect to board events
75 m_frame->Bind( EDA_EVT_UNITS_CHANGED, &PCB_NET_INSPECTOR_PANEL::onUnitsChanged, this );
76
77 // Connect to wxDataViewCtrl events
78 m_netsList->Bind( wxEVT_DATAVIEW_ITEM_EXPANDED, &PCB_NET_INSPECTOR_PANEL::OnExpandCollapseRow, this );
79 m_netsList->Bind( wxEVT_DATAVIEW_ITEM_COLLAPSED, &PCB_NET_INSPECTOR_PANEL::OnExpandCollapseRow, this );
80 m_netsList->Bind( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &PCB_NET_INSPECTOR_PANEL::OnHeaderContextMenu, this );
81 m_netsList->Bind( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &PCB_NET_INSPECTOR_PANEL::OnNetsListContextMenu, this );
82 m_netsList->Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &PCB_NET_INSPECTOR_PANEL::OnNetsListItemActivated, this );
83 m_netsList->Bind( wxEVT_DATAVIEW_COLUMN_SORTED, &PCB_NET_INSPECTOR_PANEL::OnColumnSorted, this );
84}
85
87{
89
90 m_netsList->AssociateModel( nullptr );
91
92 // Disconnect from board events
93 m_frame->Unbind( EDA_EVT_UNITS_CHANGED, &PCB_NET_INSPECTOR_PANEL::onUnitsChanged, this );
94
95 // Connect to wxDataViewCtrl events
96 m_netsList->Unbind( wxEVT_DATAVIEW_ITEM_EXPANDED, &PCB_NET_INSPECTOR_PANEL::OnExpandCollapseRow, this );
97 m_netsList->Unbind( wxEVT_DATAVIEW_ITEM_COLLAPSED, &PCB_NET_INSPECTOR_PANEL::OnExpandCollapseRow, this );
98 m_netsList->Unbind( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, &PCB_NET_INSPECTOR_PANEL::OnHeaderContextMenu, this );
99 m_netsList->Unbind( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &PCB_NET_INSPECTOR_PANEL::OnNetsListContextMenu, this );
100 m_netsList->Unbind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &PCB_NET_INSPECTOR_PANEL::OnNetsListItemActivated, this );
101 m_netsList->Unbind( wxEVT_DATAVIEW_COLUMN_SORTED, &PCB_NET_INSPECTOR_PANEL::OnColumnSorted, this );
102}
103
104
105/*****************************************************************************************
106 *
107 * Grid / model columns configuration
108 *
109 * ***************************************************************************************/
110
111
113{
114 m_columns.clear();
115
116 // Set up the column display vector
117 m_columns.emplace_back( 0u, UNDEFINED_LAYER, _( "Name" ), _( "Net Name" ), CSV_COLUMN_DESC::CSV_QUOTE, false );
118 m_columns.emplace_back( 1u, UNDEFINED_LAYER, _( "Net Chain" ), _( "Net Chain" ), CSV_COLUMN_DESC::CSV_QUOTE, false );
119 m_columns.emplace_back( 2u, UNDEFINED_LAYER, _( "Netclass" ), _( "Netclass" ), CSV_COLUMN_DESC::CSV_QUOTE, false );
120
122 {
123 m_columns.emplace_back( 3u, UNDEFINED_LAYER, _( "Total Delay" ), _( "Net Delay" ), CSV_COLUMN_DESC::CSV_NONE,
124 true );
125 }
126 else
127 {
128 m_columns.emplace_back( 3u, UNDEFINED_LAYER, _( "Total Length" ), _( "Net Length" ), CSV_COLUMN_DESC::CSV_NONE,
129 true );
130 }
131
133 {
134 m_columns.emplace_back( 4u, UNDEFINED_LAYER, _( "Net Chain Delay" ), _( "Net Chain Delay" ),
136 }
137 else
138 {
139 m_columns.emplace_back( 4u, UNDEFINED_LAYER, _( "Net Chain Length" ), _( "Net Chain Length" ),
141 }
142
143 m_columns.emplace_back( 5u, UNDEFINED_LAYER, _( "Via Count" ), _( "Via Count" ), CSV_COLUMN_DESC::CSV_NONE, false );
144
146 {
147 m_columns.emplace_back( 6u, UNDEFINED_LAYER, _( "Via Delay" ), _( "Via Delay" ), CSV_COLUMN_DESC::CSV_NONE,
148 true );
149 m_columns.emplace_back( 7u, UNDEFINED_LAYER, _( "Track Delay" ), _( "Track Delay" ), CSV_COLUMN_DESC::CSV_NONE,
150 true );
151 m_columns.emplace_back( 8u, UNDEFINED_LAYER, _( "Die Delay" ), _( "Die Delay" ), CSV_COLUMN_DESC::CSV_NONE,
152 true );
153 }
154 else
155 {
156 m_columns.emplace_back( 6u, UNDEFINED_LAYER, _( "Via Length" ), _( "Via Length" ), CSV_COLUMN_DESC::CSV_NONE,
157 true );
158 m_columns.emplace_back( 7u, UNDEFINED_LAYER, _( "Track Length" ), _( "Track Length" ),
160 m_columns.emplace_back( 8u, UNDEFINED_LAYER, _( "Die Length" ), _( "Die Length" ), CSV_COLUMN_DESC::CSV_NONE,
161 true );
162 }
163
164 m_columns.emplace_back( 9u, UNDEFINED_LAYER, _( "Unrouted Length" ), _( "Unrouted Length" ),
166
167 m_columns.emplace_back( 10u, UNDEFINED_LAYER, _( "Pad Count" ), _( "Pad Count" ), CSV_COLUMN_DESC::CSV_NONE,
168 false );
169
170 const std::vector<std::function<void( void )>> add_col{
171 [&]()
172 {
173 m_netsList->AppendTextColumn( m_columns[COLUMN_NAME].display_name, m_columns[COLUMN_NAME],
174 wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
175 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_SORTABLE );
176 },
177 [&]()
178 {
179 m_netsList->AppendTextColumn( m_columns[COLUMN_NET_CHAIN].display_name, m_columns[COLUMN_NET_CHAIN],
180 wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
181 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
182 },
183 [&]()
184 {
185 m_netsList->AppendTextColumn( m_columns[COLUMN_NETCLASS].display_name, m_columns[COLUMN_NETCLASS],
186 wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
187 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
188 },
189 [&]()
190 {
191 m_netsList->AppendTextColumn( m_columns[COLUMN_TOTAL_LENGTH].display_name, m_columns[COLUMN_TOTAL_LENGTH],
192 wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
193 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
194 },
195 [&]()
196 {
197 m_netsList->AppendTextColumn( m_columns[COLUMN_NET_CHAIN_LENGTH].display_name,
198 m_columns[COLUMN_NET_CHAIN_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
199 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
200 },
201 [&]()
202 {
203 m_netsList->AppendTextColumn( m_columns[COLUMN_VIA_COUNT].display_name, m_columns[COLUMN_VIA_COUNT],
204 wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
205 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
206 },
207 [&]()
208 {
209 m_netsList->AppendTextColumn( m_columns[COLUMN_VIA_LENGTH].display_name, m_columns[COLUMN_VIA_LENGTH],
210 wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
211 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
212 },
213 [&]()
214 {
215 m_netsList->AppendTextColumn( m_columns[COLUMN_BOARD_LENGTH].display_name, m_columns[COLUMN_BOARD_LENGTH],
216 wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
217 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
218 },
219 [&]()
220 {
221 m_netsList->AppendTextColumn( m_columns[COLUMN_PAD_DIE_LENGTH].display_name,
222 m_columns[COLUMN_PAD_DIE_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
223 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
224 },
225 [&]()
226 {
227 m_netsList->AppendTextColumn( m_columns[COLUMN_UNROUTED_LENGTH].display_name,
228 m_columns[COLUMN_UNROUTED_LENGTH], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
229 wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_REORDERABLE
230 | wxDATAVIEW_COL_SORTABLE );
231 },
232 [&]()
233 {
234 m_netsList->AppendTextColumn( m_columns[COLUMN_PAD_COUNT].display_name, m_columns[COLUMN_PAD_COUNT],
235 wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
236 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
237 }
238 };
239
240 // If we have not yet loaded the first board, use a dummy local settings object to ensure we
241 // don't over-write existing board settings (note that PCB_EDIT_FRAME loads the local settings
242 // object prior to loading the board; the two are not synced and we need to account for that)
243 PANEL_NET_INSPECTOR_SETTINGS* cfg = nullptr;
244
245 if( m_boardLoaded )
246 {
248 cfg = &localSettings.m_NetInspectorPanel;
249 }
250 else
251 {
253 }
254
255 // Reset the column display settings if column count doesn't match
256 const int totalNumColumns = (int) add_col.size() + m_board->GetCopperLayerCount();
257
258 if( (int) cfg->col_order.size() != totalNumColumns
259 || (int) cfg->col_hidden.size() != totalNumColumns )
260 {
261 cfg->col_order.resize( totalNumColumns );
262 cfg->col_hidden.resize( totalNumColumns );
263
264 for( int i = 0; i < totalNumColumns; ++i )
265 {
266 cfg->col_order[i] = i;
267 cfg->col_hidden[i] = false;
268 }
269 }
270
271 // Check that all columns are unique and in range to protect against corrupted settings data
272 std::set<int> col_order_set( cfg->col_order.begin(), cfg->col_order.end() );
273 bool invalidColumn = std::any_of( cfg->col_order.begin(), cfg->col_order.end(),
274 [totalNumColumns]( int aColumn )
275 {
276 return aColumn < 0 || aColumn >= totalNumColumns;
277 } );
278
279 if( col_order_set.size() != cfg->col_order.size() || invalidColumn )
280 {
281 for( std::size_t i = 0; i < cfg->col_order.size(); ++i )
282 cfg->col_order[i] = static_cast<int>( i );
283 }
284
285 // Add column records for copper layers
286 for( PCB_LAYER_ID layer : m_board->GetEnabledLayers().Seq() )
287 {
288 if( !IsCopperLayer( layer ) )
289 continue;
290
291 m_columns.emplace_back( m_columns.size(), layer, m_board->GetLayerName( layer ), m_board->GetLayerName( layer ),
293 }
294
295 // Add display columns in settings order
296 for( const int i : cfg->col_order )
297 {
298 const int addModelColumn = i;
299
300 if( addModelColumn >= (int) add_col.size() )
301 {
302 m_netsList->AppendTextColumn( m_board->GetLayerName( m_columns[addModelColumn].layer ),
303 m_columns[addModelColumn], wxDATAVIEW_CELL_INERT, -1, wxALIGN_CENTER,
304 wxDATAVIEW_COL_RESIZABLE|wxDATAVIEW_COL_REORDERABLE|wxDATAVIEW_COL_SORTABLE );
305 }
306 else
307 {
308 add_col.at( i )();
309 }
310 }
311
312 // Set the name column as the expander row
313 if( wxDataViewColumn* col = getDisplayedColumnForModelField( COLUMN_NAME ) )
314 {
315 m_netsList->SetExpanderColumn( col );
316 }
317
319
320 // Delete the temporary config if used
321 if( !m_boardLoaded )
322 delete cfg;
323}
324
325
327{
328 constexpr int margins = 15;
329 constexpr int extra_width = 30;
330
331 int headerWidth = GetTextExtent( m_columns[aModelColumn].display_name ).x;
332 headerWidth += ( aModelColumn == COLUMN_NAME ) ? extra_width : margins;
333
334 return headerWidth;
335}
336
337
338void PCB_NET_INSPECTOR_PANEL::autosizeColumn( wxDataViewColumn* aCol )
339{
340 if( !aCol || aCol->IsHidden() )
341 return;
342
343 const unsigned int modelCol = aCol->GetModelColumn();
344
345 if( modelCol >= m_columns.size() )
346 return;
347
348 constexpr int margins = 15;
349 constexpr int extra_width = 30;
350 const bool isNameCol = ( modelCol == COLUMN_NAME );
351 const int padding = isNameCol ? extra_width : margins;
352 const int indent = m_netsList->GetIndent();
353
354 int maxWidth = getMinColumnWidth( modelCol );
355
356 for( unsigned int row = 0; row < m_dataModel->itemCount(); ++row )
357 {
358 wxVariant value = m_dataModel->valueAt( modelCol, row );
359 int textWidth = GetTextExtent( value.GetString() ).x + padding;
360 maxWidth = std::max( maxWidth, textWidth );
361
362 const LIST_ITEM& item = m_dataModel->itemAt( row );
363
364 if( item.GetIsGroup() )
365 {
366 for( auto it = item.ChildrenBegin(); it != item.ChildrenEnd(); ++it )
367 {
368 wxVariant childValue = m_dataModel->valueForItem( *it, modelCol );
369 int childWidth = GetTextExtent( childValue.GetString() ).x + padding;
370
371 if( isNameCol )
372 childWidth += indent;
373
374 maxWidth = std::max( maxWidth, childWidth );
375 }
376 }
377 }
378
379 aCol->SetWidth( maxWidth );
380}
381
382
384{
385 wxWindowUpdateLocker locker( m_netsList );
386
387 if( cfg->col_widths.size() != m_columns.size() )
388 {
389 int minValueWidth = GetTextExtent( wxT( "00000,000 mm" ) ).x;
390 int minNumberWidth = GetTextExtent( wxT( "000" ) ).x;
391 int minNameWidth = GetTextExtent( wxT( "MMMMMMMMMMMM" ) ).x;
392
393 // Considering left and right margins.
394 // For wxRenderGeneric it is 5px.
395 // Also account for the sorting arrow in the column header.
396 // Column 0 also needs space for any potential expander icons.
397 constexpr int margins = 15;
398 constexpr int extra_width = 30;
399
400 auto getTargetWidth =
401 [&]( int columnID )
402 {
403 switch( columnID )
404 {
405 case COLUMN_NAME: return minNameWidth + extra_width;
406 case COLUMN_NETCLASS: return minNameWidth + margins;
407 case COLUMN_VIA_COUNT: return minNumberWidth + margins;
408 case COLUMN_PAD_COUNT: return minNumberWidth + margins;
409 default: return minValueWidth + margins;
410 }
411 };
412
413 wxASSERT( m_columns.size() == cfg->col_order.size() );
414
415 for( size_t i = 0; i < m_columns.size(); ++i )
416 {
417 const int modelColumn = cfg->col_order[i];
418 int titleSize = GetTextExtent( m_columns[modelColumn].display_name ).x;
419 titleSize = modelColumn == COLUMN_NAME ? titleSize + extra_width : titleSize + margins;
420 const int valSize = getTargetWidth( modelColumn );
421 m_netsList->GetColumn( i )->SetWidth( std::max( titleSize, valSize ) );
422 }
423 }
424 else
425 {
426 wxASSERT( m_columns.size() == cfg->col_hidden.size() );
427 wxASSERT( m_columns.size() == cfg->col_widths.size() );
428
429 for( size_t ii = 0; ii < m_columns.size(); ++ii )
430 {
431 const int modelCol = static_cast<int>( m_netsList->GetColumn( ii )->GetModelColumn() );
432 const int minWidth = getMinColumnWidth( modelCol );
433 const int newWidth = cfg->col_widths[ii];
434
435 m_netsList->GetColumn( ii )->SetWidth( std::max( newWidth, minWidth ) );
436 m_netsList->GetColumn( ii )->SetHidden( cfg->col_hidden[ii] );
437 }
438 }
439
440 m_netsList->Refresh();
441}
442
443
444bool PCB_NET_INSPECTOR_PANEL::restoreSortColumn( const int sortingColumnId, const bool sortOrderAsc ) const
445{
446 if( sortingColumnId != -1 )
447 {
448 if( wxDataViewColumn* col = getDisplayedColumnForModelField( sortingColumnId ) )
449 {
450 col->SetSortOrder( sortOrderAsc );
451 m_dataModel->Resort();
452 return true;
453 }
454 }
455
456 return false;
457}
458
459
460wxDataViewColumn* PCB_NET_INSPECTOR_PANEL::getDisplayedColumnForModelField( const int columnId ) const
461{
462 for( unsigned int i = 0; i < m_netsList->GetColumnCount(); ++i )
463 {
464 wxDataViewColumn* col = m_netsList->GetColumn( i );
465
466 if( static_cast<int>( col->GetModelColumn() ) == columnId )
467 return col;
468 }
469
470 return nullptr;
471}
472
473
474/*****************************************************************************************
475 *
476 * Nets list generation
477 *
478 * ***************************************************************************************/
479
480
481void PCB_NET_INSPECTOR_PANEL::buildNetsList( const bool rebuildColumns )
482{
483 // Only build the list of nets if there is a board present
484 if( !m_board )
485 return;
486
487 m_inBuildNetsList = true;
488
489 m_netsList->Freeze();
490
493
494 // Refresh all filtering / grouping settings
502
503 // Must follow the settings load so the model reflects this board's mode, not the previous one
504 m_dataModel->SetIsTimeDomain( m_showTimeDomainDetails );
505
506 // Attempt to keep any expanded groups open
508 {
509 cfg->expanded_rows.clear();
510 DATA_MODEL* model = static_cast<DATA_MODEL*>( m_netsList->GetModel() );
511
512 for( const auto& [groupName, groupItem] : model->getGroupDataViewItems() )
513 {
514 if( m_netsList->IsExpanded( groupItem ) )
515 cfg->expanded_rows.push_back( groupName );
516 }
517 }
518
519 // When rebuilding the netlist, try to keep the row selection
520 wxDataViewItemArray sel;
521 m_netsList->GetSelections( sel );
522
523 std::vector<int> prev_selected_netcodes;
524 prev_selected_netcodes.reserve( sel.GetCount() );
525
526 for( unsigned int i = 0; i < sel.GetCount(); ++i )
527 {
528 const LIST_ITEM* item = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
529 prev_selected_netcodes.push_back( item->GetNetCode() );
530 }
531
532 int sorting_column_id = cfg->sorting_column;
533 bool sort_order_asc = cfg->sort_order_asc;
534
535 if( wxDataViewColumn* sorting_column = m_netsList->GetSortingColumn() )
536 {
537 if( !m_boardLoading )
538 {
539 sorting_column_id = static_cast<int>( sorting_column->GetModelColumn() );
540 sort_order_asc = sorting_column->IsSortOrderAscending();
541 }
542
543 // On GTK, wxDVC will crash if we rebuild with a sorting column set.
544 sorting_column->UnsetAsSortKey();
545 }
546
547 if( rebuildColumns )
548 {
549 m_netsList->ClearColumns();
550 buildColumns();
551 }
552
553 m_dataModel->deleteAllItems();
554 m_custom_group_rules.clear();
555
556 for( const wxString& rule : cfg->custom_group_rules )
557 m_custom_group_rules.push_back( std::make_unique<EDA_COMBINED_MATCHER>( rule, CTX_NET ) );
558
559 m_dataModel->addCustomGroups();
560
561 std::vector<NETINFO_ITEM*> netCodes;
562
563 for( NETINFO_ITEM* ni : m_board->GetNetInfo() )
564 {
565 if( netFilterMatches( ni, cfg ) )
566 netCodes.emplace_back( ni );
567 }
568
569 std::ranges::sort( netCodes,
570 []( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
571 {
572 return a->GetNetCode() < b->GetNetCode();
573 } );
574
575 std::vector<std::unique_ptr<LIST_ITEM>> lengths = calculateNets( netCodes, m_showZeroPadNets );
576
577 m_dataModel->addItems( lengths );
578
579 // Try to re-enable the sorting column
580 if( !restoreSortColumn( sorting_column_id, sort_order_asc ))
581 {
582 // By default, sort by Name column
584 }
585
586 // Try to restore the expanded groups
587 if( m_boardLoaded )
588 {
589 m_rowExpanding = true;
590
591 std::vector<std::pair<wxString, wxDataViewItem>> groupItems = m_dataModel->getGroupDataViewItems();
592
593 for( wxString& groupName : cfg->expanded_rows )
594 {
595 auto pred =
596 [&groupName]( const std::pair<wxString, wxDataViewItem>& item )
597 {
598 return groupName == item.first;
599 };
600
601 auto tableItem = std::ranges::find_if( groupItems, pred );
602
603 if( tableItem != groupItems.end() )
604 m_netsList->Expand( tableItem->second );
605 }
606
607 m_rowExpanding = false;
608 }
609
610 // Try to restore the selected rows
611 sel.Clear();
612
613 for( const int& nc : prev_selected_netcodes )
614 {
615 if( std::optional<LIST_ITEM_ITER> r = m_dataModel->findItem( nc ) )
616 {
617 const std::unique_ptr<LIST_ITEM>& list_item = *r.value();
618 sel.Add( wxDataViewItem( list_item.get() ) );
619 }
620 }
621
622 m_netsList->Thaw(); // Must thaw before reselecting to avoid windows selection bug
623
624 if( !sel.IsEmpty() )
625 {
626 m_netsList->SetSelections( sel );
627 m_netsList->EnsureVisible( sel.Item( 0 ) );
628 }
629 else
630 {
631 m_netsList->UnselectAll();
632 }
633
634 m_inBuildNetsList = false;
635}
636
637
640{
641 if( cfg == nullptr )
642 {
644 cfg = &localSettings.m_NetInspectorPanel;
645 }
646
647 // Never show an unconnected net
648 if( aNet->GetNetCode() <= 0 )
649 return false;
650
651 const wxString filterString = UnescapeString( m_searchCtrl->GetValue() ).Upper();
652 const wxString netName = UnescapeString( aNet->GetNetname() ).Upper();
653 const NETCLASS* netClass = aNet->GetNetClass();
654 const wxString netClassName = UnescapeString( netClass->GetName() ).Upper();
655
656 bool matched = false;
657
658 // No filter - match all
659 if( filterString.Length() == 0 )
660 matched = true;
661
662 // Search on net class
663 if( !matched && cfg->filter_by_netclass && netClassName.Find( filterString ) != wxNOT_FOUND )
664 matched = true;
665
666 // Search on net name
667 if( !matched && cfg->filter_by_net_name && netName.Find( filterString ) != wxNOT_FOUND )
668 matched = true;
669
670 // Remove unconnected nets if required
671 if( matched )
672 {
674 matched = !netName.StartsWith( wxT( "UNCONNECTED-(" ) );
675 }
676
677 return matched;
678}
679
680
682{
683 bool operator()( const CN_ITEM* a, const CN_ITEM* b ) const { return a->Net() < b->Net(); }
684
685 bool operator()( const CN_ITEM* a, int b ) const { return a->Net() < b; }
686
687 bool operator()( int a, const CN_ITEM* b ) const { return a < b->Net(); }
688};
689
690
692{
693 // Pre-filter the connectivity items and sort them by netcode. This avoids quadratic runtime when building the whole
694 // net list.
695 const auto type_bits = std::bitset<MAX_STRUCT_TYPE_ID>().set( PCB_TRACE_T )
696 .set( PCB_ARC_T )
697 .set( PCB_VIA_T )
698 .set( PCB_PAD_T );
699
700 std::vector<CN_ITEM*> cn_items;
701 cn_items.reserve( 1024 );
702
703 for( CN_ITEM* cn_item : m_board->GetConnectivity()->GetConnectivityAlgo()->ItemList() )
704 {
705 if( cn_item->Valid() && type_bits[cn_item->Parent()->Type()] )
706 cn_items.push_back( cn_item );
707 }
708
709 std::ranges::sort( cn_items, NETCODE_CMP_LESS() );
710
711 return cn_items;
712}
713
714
715std::vector<std::unique_ptr<PCB_NET_INSPECTOR_PANEL::LIST_ITEM>>
716PCB_NET_INSPECTOR_PANEL::calculateNets( const std::vector<NETINFO_ITEM*>& aNetCodes, bool aIncludeZeroPadNets ) const
717{
718 std::vector<std::unique_ptr<LIST_ITEM>> results;
719
720 // A chain total needs every member net, so pull in the siblings.
721 std::vector<NETINFO_ITEM*> netCodes( aNetCodes );
722 std::set<wxString> chains;
723
724 for( NETINFO_ITEM* net : netCodes )
725 {
726 if( !net->GetNetChain().IsEmpty() )
727 chains.insert( net->GetNetChain() );
728 }
729
730 if( !chains.empty() )
731 {
732 for( NETINFO_ITEM* net : m_board->GetNetInfo() )
733 {
734 if( chains.count( net->GetNetChain() ) )
735 netCodes.push_back( net );
736 }
737
738 std::sort( netCodes.begin(), netCodes.end(),
739 []( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
740 {
741 return a->GetNetCode() < b->GetNetCode();
742 } );
743 netCodes.erase( std::unique( netCodes.begin(), netCodes.end() ), netCodes.end() );
744 }
745
746 LENGTH_DELAY_CALCULATION* calc = m_board->GetLengthCalculation();
747 const std::vector<CN_ITEM*> conItems = relevantConnectivityItems();
748
749 // First assemble the LENGTH_CALCULATION_ITEMs for board items which match the nets we need to recompute
750 // Precondition: conItems and aNetCodes are sorted in increasing netcode value
751 // Functionality: This extracts any items from conItems which have a netcode which is present in aNetCodes
752 std::unordered_map<int, std::vector<LENGTH_DELAY_CALCULATION_ITEM>> netItemsMap;
753 std::vector<NETINFO_ITEM*> foundNets;
754
755 auto itemItr = conItems.begin();
756 auto netCodeItr = netCodes.begin();
757
758 while( itemItr != conItems.end() && netCodeItr != netCodes.end() )
759 {
760 const int curNetCode = ( *netCodeItr )->GetNetCode();
761 const int curItemNetCode = ( *itemItr )->Net();
762
763 if( curItemNetCode == curNetCode )
764 {
765 if( foundNets.empty() || foundNets.back() != *netCodeItr )
766 foundNets.emplace_back( *netCodeItr );
767
768 // Take the item
769 LENGTH_DELAY_CALCULATION_ITEM lengthItem = calc->GetLengthCalculationItem( ( *itemItr )->Parent() );
770 netItemsMap[curItemNetCode].emplace_back( std::move( lengthItem ) );
771 ++itemItr;
772 }
773 else if( curItemNetCode < curNetCode )
774 {
775 // Fast-forward through items
776 while( itemItr != conItems.end() && ( *itemItr )->Net() < curNetCode )
777 ++itemItr;
778 }
779 else if( curItemNetCode > curNetCode )
780 {
781 // Fast-forward through required net codes
782 while( netCodeItr != netCodes.end() && curItemNetCode > ( *netCodeItr )->GetNetCode() )
783 ++netCodeItr;
784 }
785 }
786
787 // Now calculate the length statistics for each net. This includes potentially expensive path optimisations, so
788 // parallelize this work.
789 std::mutex resultsMutex;
791
792 auto resultsFuture = tp.submit_loop(
793 0, foundNets.size(),
794 [&, this, calc]( const int i )
795 {
796 int netCode = foundNets[i]->GetNetCode();
797
798 constexpr PATH_OPTIMISATIONS opts = { .OptimiseVias = true,
799 .MergeTracks = true,
800 .OptimiseTracesInPads = true,
801 .InferViaInPad = false };
802
803 LENGTH_DELAY_STATS lengthDetails = calc->CalculateLengthDetails(
804 netItemsMap[netCode],
805 opts,
806 nullptr,
807 nullptr,
811
812 if( aIncludeZeroPadNets || lengthDetails.NumPads > 0 )
813 {
814 std::unique_ptr<LIST_ITEM> new_item = std::make_unique<LIST_ITEM>( foundNets[i] );
815
816 new_item->SetPadCount( lengthDetails.NumPads );
817 new_item->SetLayerCount( m_board->GetCopperLayerCount() );
818 new_item->SetPadDieLength( lengthDetails.PadToDieLength );
819 new_item->SetPadDieDelay( lengthDetails.PadToDieDelay );
820 new_item->SetViaCount( lengthDetails.NumVias );
821 new_item->SetViaLength( lengthDetails.ViaLength );
822 new_item->SetViaDelay( lengthDetails.ViaDelay );
823 new_item->SetLayerWireLengths( *lengthDetails.LayerLengths );
824
825 // Estimated unrouted length: sum of the optimized ratsnest airline edges
826 // for this net, as maintained by the connectivity engine. Uses the
827 // unsorted accessor to avoid the stable sort in RN_NET::GetEdges().
828 int64_t unroutedLength = 0;
829
830 if( RN_NET* rnNet = m_board->GetConnectivity()->GetRatsnestForNet( netCode ) )
831 unroutedLength = rnNet->GetTotalAirlineLength();
832
833 new_item->SetUnroutedLength( unroutedLength );
834
835 if( m_showTimeDomainDetails )
836 new_item->SetLayerWireDelays( *lengthDetails.LayerDelays );
837
838 new_item->SetNetChainName( foundNets[i]->GetNetChain() );
839
840 std::scoped_lock lock( resultsMutex );
841 results.emplace_back( std::move( new_item ) );
842 }
843 } );
844
845 resultsFuture.get();
846
847 std::map<wxString, int64_t> netChainLengths;
848 std::map<wxString, int64_t> netChainDelays;
849
850 for( const std::unique_ptr<LIST_ITEM>& item : results )
851 {
852 if( !item->GetNetChainName().IsEmpty() )
853 {
854 netChainLengths[item->GetNetChainName()] += item->GetTotalLength();
855
856 if( m_showTimeDomainDetails )
857 netChainDelays[item->GetNetChainName()] += item->GetTotalDelay();
858 }
859 }
860
861 // Cache per-chain delay-per-mm so we only sample the chain tracks once.
862 std::map<wxString, double> chainDelayPerIU;
863
864 auto delayPerIUFor = [&]( const wxString& aChain ) -> double
865 {
866 auto it = chainDelayPerIU.find( aChain );
867
868 if( it != chainDelayPerIU.end() )
869 return it->second;
870
871 double perIU = ChainBridgingDelayPerMm( m_board, aChain ) / pcbIUScale.IU_PER_MM;
872 chainDelayPerIU.emplace( aChain, perIU );
873 return perIU;
874 };
875
876 for( FOOTPRINT* fp : m_board->Footprints() )
877 {
878 std::vector<PAD*> chainPads;
879
880 for( PAD* pad : fp->Pads() )
881 {
882 if( pad->GetNet() && !pad->GetNet()->GetNetChain().IsEmpty() )
883 chainPads.push_back( pad );
884 }
885
886 for( size_t i = 0; i < chainPads.size(); ++i )
887 {
888 for( size_t j = i + 1; j < chainPads.size(); ++j )
889 {
890 NETINFO_ITEM* netA = chainPads[i]->GetNet();
891 NETINFO_ITEM* netB = chainPads[j]->GetNet();
892
893 if( netA->GetNetChain() == netB->GetNetChain()
894 && netA->GetNetCode() != netB->GetNetCode() )
895 {
896 VECTOR2I p1 = chainPads[i]->GetPosition();
897 VECTOR2I p2 = chainPads[j]->GetPosition();
898 int64_t dx = p1.x - p2.x;
899 int64_t dy = p1.y - p2.y;
900 int64_t dist = KiROUND( std::hypot( (double) dx, (double) dy ) );
901 const wxString& chain = netA->GetNetChain();
902
903 netChainLengths[chain] += dist;
904
905 if( m_showTimeDomainDetails )
906 netChainDelays[chain] += KiROUND( delayPerIUFor( chain ) * (double) dist );
907 }
908 }
909 }
910 }
911
912 for( std::unique_ptr<LIST_ITEM>& item : results )
913 {
914 if( !item->GetNetChainName().IsEmpty() )
915 {
916 item->SetNetChainLength( netChainLengths[item->GetNetChainName()] );
917
918 if( m_showTimeDomainDetails )
919 item->SetNetChainDelay( netChainDelays[item->GetNetChainName()] );
920 }
921 }
922
923 return results;
924}
925
926
927/*****************************************************************************************
928 *
929 * Formatting helpers
930 *
931 * ***************************************************************************************/
932
933
935{
936 return wxString::Format( wxT( "%.3d" ), aNet->GetNetCode() );
937}
938
939
941{
942 return UnescapeString( aNet->GetNetname() );
943}
944
945
946wxString PCB_NET_INSPECTOR_PANEL::formatCount( const unsigned int aValue )
947{
948 return wxString::Format( wxT( "%u" ), aValue );
949}
950
951
952wxString PCB_NET_INSPECTOR_PANEL::formatLength( const int64_t aValue ) const
953{
954 return m_frame->MessageTextFromValue( aValue,
955 // don't include unit label in the string when reporting
956 !m_inReporting );
957}
958
959wxString PCB_NET_INSPECTOR_PANEL::formatDelay( const int64_t aValue ) const
960{
961 return m_frame->MessageTextFromValue( aValue,
962 // don't include unit label in the string when reporting
964}
965
966
967void PCB_NET_INSPECTOR_PANEL::updateDisplayedRowValues( const std::optional<LIST_ITEM_ITER>& aRow ) const
968{
969 if( !aRow )
970 return;
971
972 wxDataViewItemArray sel;
973 m_netsList->GetSelections( sel );
974
975 m_dataModel->updateItem( aRow );
976
977 if( !sel.IsEmpty() )
978 {
979 m_netsList->SetSelections( sel );
980 m_netsList->EnsureVisible( sel.Item( 0 ) );
981 }
982}
983
984
985/*****************************************************************************************
986 *
987 * BOARD_LISTENER event handling
988 *
989 * ***************************************************************************************/
990
991
993{
994 m_board = m_frame->GetBoard();
995
996 if( m_board )
997 m_board->AddListener( this );
998
999 m_boardLoaded = true;
1000 m_boardLoading = true;
1001
1002 const PROJECT_LOCAL_SETTINGS& localSettings = Pgm().GetSettingsManager().Prj().GetLocalSettings();
1003 auto& cfg = localSettings.m_NetInspectorPanel;
1004 // ChangeValue avoids the wxEVT_TEXT that SetValue fires, which doubled buildNetsList() below
1005 m_searchCtrl->ChangeValue( cfg.filter_text );
1006
1007 // Skip the full net solve while hidden; OnShowPanel() rebuilds from scratch when revealed
1008 if( IsShown() )
1009 {
1010 buildNetsList( true );
1011 m_boardLoading = false;
1012 }
1013}
1014
1015
1017{
1018 const std::vector<BOARD_ITEM*> item{ aBoardItem };
1019 updateBoardItems( item );
1020}
1021
1022
1023void PCB_NET_INSPECTOR_PANEL::OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems )
1024{
1025 updateBoardItems( aBoardItems );
1026}
1027
1028
1029void PCB_NET_INSPECTOR_PANEL::updateBoardItems( const std::vector<BOARD_ITEM*>& aBoardItems )
1030{
1031 if( !IsShownOnScreen() )
1032 return;
1033
1034 // Rebuild full list for large changes
1035 if( aBoardItems.size()
1036 > static_cast<size_t>( ADVANCED_CFG::GetCfg().m_NetInspectorBulkUpdateOptimisationThreshold ) )
1037 {
1038 buildNetsList();
1039 }
1040 else
1041 {
1042 std::vector<NETINFO_ITEM*> changedNets;
1043
1044 for( BOARD_ITEM* boardItem : aBoardItems )
1045 {
1046 if( NETINFO_ITEM* net = dynamic_cast<NETINFO_ITEM*>( boardItem ) )
1047 {
1048 // A new net has been added to the board. Add it to our list if it passes the netname filter test.
1049 if( netFilterMatches( net ) )
1050 changedNets.emplace_back( net );
1051 }
1052 else if( BOARD_CONNECTED_ITEM* i = dynamic_cast<BOARD_CONNECTED_ITEM*>( boardItem ) )
1053 {
1054 changedNets.emplace_back( i->GetNet() );
1055 }
1056 else if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( boardItem ) )
1057 {
1058 for( const PAD* pad : footprint->Pads() )
1059 {
1060 if( netFilterMatches( pad->GetNet() ) )
1061 changedNets.emplace_back( pad->GetNet() );
1062 }
1063 }
1064 }
1065
1066 std::ranges::sort( changedNets,
1067 []( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1068 {
1069 return a->GetNetCode() < b->GetNetCode();
1070 } );
1071
1072 updateNets( changedNets );
1073 }
1074
1075 m_netsList->Refresh();
1076}
1077
1078
1079void PCB_NET_INSPECTOR_PANEL::updateNets( const std::vector<NETINFO_ITEM*>& aNets ) const
1080{
1081 std::vector<NETINFO_ITEM*> netsToUpdate;
1082 std::unordered_set<NETINFO_ITEM*> netsToDelete;
1083
1084 for( NETINFO_ITEM* net : aNets )
1085 {
1086 // Add all nets to the deletion list - we will prune this later to only contain unhandled nets
1087 netsToDelete.insert( net );
1088
1089 // Only calculate nets that match the current filter
1090 if( netFilterMatches( net ) )
1091 netsToUpdate.emplace_back( net );
1092 }
1093
1094 wxWindowUpdateLocker updateLocker( m_netsList );
1095
1096 std::vector<std::unique_ptr<LIST_ITEM>> newListItems = calculateNets( aNets, true );
1097
1098 for( std::unique_ptr<LIST_ITEM>& newListItem : newListItems )
1099 {
1100 // Remove the handled net from the deletion list
1101 netsToDelete.erase( newListItem->GetNet() );
1102
1103 std::optional<LIST_ITEM_ITER> curNetRow = m_dataModel->findItem( newListItem->GetNetCode() );
1104
1105 if( !m_showZeroPadNets && newListItem->GetPadCount() == 0 )
1106 {
1107 m_dataModel->deleteItem( curNetRow );
1108 continue;
1109 }
1110
1111 if( !curNetRow )
1112 {
1113 m_dataModel->addItem( std::move( newListItem ) );
1114 continue;
1115 }
1116
1117 const std::unique_ptr<LIST_ITEM>& curListItem = *curNetRow.value();
1118
1119 if( curListItem->GetNetName() != newListItem->GetNetName() )
1120 {
1121 // If the name has changed, it might require re-grouping. It's easier to remove and re-insert it.
1122 m_dataModel->deleteItem( curNetRow );
1123 m_dataModel->addItem( std::move( newListItem ) );
1124 }
1125 else
1126 {
1127 curListItem->SetPadCount( newListItem->GetPadCount() );
1128 curListItem->SetPadDieLength( newListItem->GetPadDieLength() );
1129 curListItem->SetPadDieDelay( newListItem->GetPadDieDelay() );
1130 curListItem->SetViaCount( newListItem->GetViaCount() );
1131 curListItem->SetViaLength( newListItem->GetViaLength() );
1132 curListItem->SetViaDelay( newListItem->GetViaDelay() );
1133 curListItem->SetUnroutedLength( newListItem->GetUnroutedLength() );
1134 curListItem->SetLayerWireLengths( newListItem->GetLayerWireLengths() );
1135 curListItem->SetNetChainName( newListItem->GetNetChainName() );
1136 curListItem->SetNetChainLength( newListItem->GetNetChainLength() );
1137 curListItem->SetNetChainDelay( newListItem->GetNetChainDelay() );
1138
1140 curListItem->SetLayerWireDelays( newListItem->GetLayerWireDelays() );
1141
1142 updateDisplayedRowValues( curNetRow );
1143 }
1144 }
1145
1146 // Delete any nets we have not yet handled
1147 for( const NETINFO_ITEM* netToDelete : netsToDelete )
1148 m_dataModel->deleteItem( m_dataModel->findItem( netToDelete->GetNetCode() ) );
1149}
1150
1151
1153{
1154 const std::vector<BOARD_ITEM*> item{ aBoardItem };
1155 updateBoardItems( item );
1156}
1157
1158
1159void PCB_NET_INSPECTOR_PANEL::OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems )
1160{
1161 updateBoardItems( aBoardItems );
1162}
1163
1164
1166{
1167 if( !IsShownOnScreen() )
1168 return;
1169
1170 buildNetsList();
1171}
1172
1173
1175{
1176 const std::vector<BOARD_ITEM*> item{ aBoardItem };
1177 updateBoardItems( item );
1178}
1179
1180
1181void PCB_NET_INSPECTOR_PANEL::OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aBoardItems )
1182{
1183 updateBoardItems( aBoardItems );
1184}
1185
1186
1188 std::vector<BOARD_ITEM*>& aAddedItems,
1189 std::vector<BOARD_ITEM*>& aRemovedItems,
1190 std::vector<BOARD_ITEM*>& aChangedItems )
1191{
1192 if( !IsShownOnScreen() )
1193 return;
1194
1195 std::vector<BOARD_ITEM*> allItems{ aAddedItems.begin(), aAddedItems.end() };
1196 allItems.insert( allItems.end(), aRemovedItems.begin(), aRemovedItems.end() );
1197 allItems.insert( allItems.end(), aChangedItems.begin(), aChangedItems.end() );
1198 updateBoardItems( allItems );
1199}
1200
1201
1203{
1204 if( m_highlightingNets || !IsShownOnScreen() )
1205 return;
1206
1207 if( !m_board->IsHighLightNetON() )
1208 {
1209 m_netsList->UnselectAll();
1210 }
1211 else
1212 {
1213 const std::set<int>& selected_codes = m_board->GetHighLightNetCodes();
1214
1215 wxDataViewItemArray new_selection;
1216 new_selection.Alloc( selected_codes.size() );
1217
1218 for( const int code : selected_codes )
1219 {
1220 if( std::optional<LIST_ITEM_ITER> r = m_dataModel->findItem( code ) )
1221 new_selection.Add( wxDataViewItem( &***r ) );
1222 }
1223
1224 m_netsList->SetSelections( new_selection );
1225
1226 if( !new_selection.IsEmpty() )
1227 m_netsList->EnsureVisible( new_selection.Item( 0 ) );
1228 }
1229}
1230
1231
1232/*****************************************************************************************
1233 *
1234 * UI-generated event handling
1235 *
1236 * ***************************************************************************************/
1237
1239{
1240 // A board loaded while hidden still owes its first full build, columns included
1241 if( m_boardLoading )
1242 {
1243 buildNetsList( true );
1244 m_boardLoading = false;
1245 }
1246 else
1247 {
1248 buildNetsList();
1249 }
1250
1252}
1253
1254
1256{
1257 bool multipleSelections = false;
1258 const LIST_ITEM* selItem = nullptr;
1259
1260 if( m_netsList->GetSelectedItemsCount() == 1 )
1261 {
1262 selItem = static_cast<const LIST_ITEM*>( m_netsList->GetSelection().GetID() );
1263 }
1264 else
1265 {
1266 if( m_netsList->GetSelectedItemsCount() > 1 )
1267 multipleSelections = true;
1268 }
1269
1270 wxMenu menu;
1271
1272 // Net edit menu items
1273 wxMenuItem* highlightNet = new wxMenuItem( &menu, ID_HIGHLIGHT_SELECTED_NETS, _( "Highlight Selected Net" ),
1274 wxEmptyString, wxITEM_NORMAL );
1275 menu.Append( highlightNet );
1276
1277 wxMenuItem* clearHighlighting = new wxMenuItem( &menu, ID_CLEAR_HIGHLIGHTING, _( "Clear Net Highlighting" ),
1278 wxEmptyString, wxITEM_NORMAL );
1279 menu.Append( clearHighlighting );
1280
1281 RENDER_SETTINGS* renderSettings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
1282 const std::set<int>& selected_codes = renderSettings->GetHighlightNetCodes();
1283
1284 if( selected_codes.size() == 0 )
1285 clearHighlighting->Enable( false );
1286
1287 menu.AppendSeparator();
1288
1289 wxMenuItem* renameNet = new wxMenuItem( &menu, ID_RENAME_NET, _( "Rename Selected Net..." ), wxEmptyString,
1290 wxITEM_NORMAL );
1291 menu.Append( renameNet );
1292
1293 wxMenuItem* deleteNet = new wxMenuItem( &menu, ID_DELETE_NET, _( "Delete Selected Net" ), wxEmptyString,
1294 wxITEM_NORMAL );
1295 menu.Append( deleteNet );
1296
1297 menu.AppendSeparator();
1298
1299 wxMenuItem* addNet = new wxMenuItem( &menu, ID_ADD_NET, _( "Add Net..." ), wxEmptyString, wxITEM_NORMAL );
1300 menu.Append( addNet );
1301
1302 if( !selItem && !multipleSelections )
1303 {
1304 highlightNet->Enable( false );
1305 deleteNet->Enable( false );
1306 renameNet->Enable( false );
1307 }
1308 else
1309 {
1310 if( multipleSelections || selItem->GetIsGroup() )
1311 {
1312 highlightNet->SetItemLabel( _( "Highlight Selected Nets" ) );
1313 renameNet->Enable( false );
1314 deleteNet->SetItemLabel( _( "Delete Selected Nets" ) );
1315 }
1316 }
1317
1318 menu.AppendSeparator();
1319
1320 wxMenuItem* removeSelectedGroup = new wxMenuItem( &menu, ID_REMOVE_SELECTED_GROUP,
1321 _( "Remove Selected Custom Group" ),
1322 wxEmptyString, wxITEM_NORMAL );
1323 menu.Append( removeSelectedGroup );
1324
1325 if( !selItem || !selItem->GetIsGroup() )
1326 removeSelectedGroup->Enable( false );
1327
1328 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PCB_NET_INSPECTOR_PANEL::onContextMenuSelection, this );
1329
1330 PopupMenu( &menu );
1331}
1332
1333
1335{
1336 SaveSettings();
1337 buildNetsList();
1338}
1339
1340
1342{
1343 wxString newGroupName;
1344 NETNAME_VALIDATOR validator( &newGroupName );
1345
1346 WX_TEXT_ENTRY_DIALOG dlg( this, _( "Group name / pattern:" ), _( "New Group" ), newGroupName );
1347 wxStaticText* help = new wxStaticText( &dlg, wxID_ANY, _( "(Use /.../ to indicate a regular expression.)" ) );
1348 help->SetFont( KIUI::GetInfoFont( this ).Italic() );
1349 dlg.m_ContentSizer->Add( help, 0, wxALL|wxEXPAND, 5 );
1351 dlg.GetSizer()->SetSizeHints( &dlg );
1352
1353 if( dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty() )
1354 return; //Aborted by user
1355
1356 newGroupName = UnescapeString( dlg.GetValue() );
1357
1358 if( newGroupName == "" )
1359 return;
1360
1361 if( std::ranges::find_if( m_custom_group_rules,
1362 [&]( std::unique_ptr<EDA_COMBINED_MATCHER>& rule )
1363 {
1364 return rule->GetPattern() == newGroupName;
1365 } )
1366 == m_custom_group_rules.end() )
1367 {
1368 m_custom_group_rules.push_back( std::make_unique<EDA_COMBINED_MATCHER>( newGroupName, CTX_NET ) );
1369 SaveSettings();
1370 }
1371
1372 buildNetsList();
1373}
1374
1375
1377{
1378 m_highlightingNets = true;
1379
1380 m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings()->SetHighlight( false );
1381 m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
1382 m_frame->GetCanvas()->Refresh();
1383
1384 m_highlightingNets = false;
1385}
1386
1387
1389{
1390 if( !m_rowExpanding )
1391 SaveSettings();
1392}
1393
1394
1396{
1397 m_contextMenuColumn = event.GetDataViewColumn();
1398
1399 wxMenu menu;
1400
1401 menu.Append( ID_AUTOFIT_COLUMN, _( "Auto-fit Column" ) );
1402 menu.Append( ID_AUTOFIT_ALL_COLUMNS, _( "Auto-fit All Columns" ) );
1403 menu.AppendSeparator();
1404
1406 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PCB_NET_INSPECTOR_PANEL::onContextMenuSelection, this );
1407 PopupMenu( &menu );
1408}
1409
1410
1411void PCB_NET_INSPECTOR_PANEL::OnConfigButton( wxCommandEvent& event )
1412{
1414 auto& cfg = localSettings.m_NetInspectorPanel;
1415
1416 const LIST_ITEM* selItem = nullptr;
1417
1418 if( m_netsList->GetSelectedItemsCount() == 1 )
1419 {
1420 selItem = static_cast<const LIST_ITEM*>( m_netsList->GetSelection().GetID() );
1421 }
1422
1423 wxMenu menu;
1424
1425 // Filtering menu items
1426 wxMenuItem* filterByNetName = new wxMenuItem( &menu, ID_FILTER_BY_NET_NAME, _( "Filter by Net Name" ),
1427 wxEmptyString, wxITEM_CHECK );
1428 menu.Append( filterByNetName );
1429 filterByNetName->Check( cfg.filter_by_net_name );
1430
1431 wxMenuItem* filterByNetclass = new wxMenuItem( &menu, ID_FILTER_BY_NETCLASS, _( "Filter by Netclass" ),
1432 wxEmptyString, wxITEM_CHECK );
1433 menu.Append( filterByNetclass );
1434 filterByNetclass->Check( cfg.filter_by_netclass );
1435
1436 menu.AppendSeparator();
1437
1438 // Grouping menu items
1439 //wxMenuItem* groupConstraint =
1440 // new wxMenuItem( &menu, ID_GROUP_BY_CONSTRAINT, _( "Group by DRC Constraint" ),
1441 // wxEmptyString, wxITEM_CHECK );
1442 //groupConstraint->Check( m_group_by_constraint );
1443 //menu.Append( groupConstraint );
1444
1445 wxMenuItem* groupNetclass = new wxMenuItem( &menu, ID_GROUP_BY_NETCLASS, _( "Group by Netclass" ),
1446 wxEmptyString, wxITEM_CHECK );
1447 menu.Append( groupNetclass );
1448 groupNetclass->Check( m_groupByNetclass );
1449
1450 wxMenuItem* groupSignal = new wxMenuItem( &menu, ID_GROUP_BY_NET_CHAIN,
1451 _( "Group by Net Chain" ),
1452 wxEmptyString, wxITEM_CHECK );
1453 menu.Append( groupSignal );
1454 groupSignal->Check( m_groupByNetChain );
1455
1456 menu.AppendSeparator();
1457
1458 wxMenuItem* addGroup = new wxMenuItem( &menu, ID_ADD_GROUP, _( "Add Custom Group..." ),
1459 wxEmptyString, wxITEM_NORMAL );
1460 menu.Append( addGroup );
1461
1462 wxMenuItem* removeSelectedGroup = new wxMenuItem( &menu, ID_REMOVE_SELECTED_GROUP,
1463 _( "Remove Selected Custom Group" ),
1464 wxEmptyString, wxITEM_NORMAL );
1465 menu.Append( removeSelectedGroup );
1466
1467 if( !selItem || !selItem->GetIsGroup() )
1468 removeSelectedGroup->Enable( false );
1469
1470 wxMenuItem* removeCustomGroups = new wxMenuItem( &menu, ID_REMOVE_GROUPS, _( "Remove All Custom Groups" ),
1471 wxEmptyString, wxITEM_NORMAL );
1472 menu.Append( removeCustomGroups );
1473 removeCustomGroups->Enable( m_custom_group_rules.size() != 0 );
1474
1475 menu.AppendSeparator();
1476
1477 wxMenuItem* showZeroNetPads = new wxMenuItem( &menu, ID_SHOW_ZERO_NET_PADS, _( "Show Zero Pad Nets" ),
1478 wxEmptyString, wxITEM_CHECK );
1479 menu.Append( showZeroNetPads );
1480 showZeroNetPads->Check( m_showZeroPadNets );
1481
1482 wxMenuItem* showUnconnectedNets = new wxMenuItem( &menu, ID_SHOW_UNCONNECTED_NETS, _( "Show Unconnected Nets" ),
1483 wxEmptyString, wxITEM_CHECK );
1484 menu.Append( showUnconnectedNets );
1485 showUnconnectedNets->Check( m_showUnconnectedNets );
1486
1487 menu.AppendSeparator();
1488
1489 wxMenuItem* showTimeDomainDetails = new wxMenuItem( &menu, ID_SHOW_TIME_DOMAIN_DETAILS,
1490 _( "Show Time Domain Details" ),
1491 wxEmptyString, wxITEM_CHECK );
1492 menu.Append( showTimeDomainDetails );
1493 showTimeDomainDetails->Check( m_showTimeDomainDetails );
1494
1495 menu.AppendSeparator();
1496
1497 // Report generation
1498 wxMenuItem* generateReport = new wxMenuItem( &menu, ID_GENERATE_REPORT, _( "Save Net Inspector Report..." ),
1499 wxEmptyString, wxITEM_NORMAL );
1500 menu.Append( generateReport );
1501
1502 menu.AppendSeparator();
1503
1504 // Show / hide columns menu items
1505 wxMenu* colsMenu = new wxMenu();
1506 generateShowHideColumnMenu( colsMenu );
1507 menu.AppendSubMenu( colsMenu, _( "Show / Hide Columns" ) );
1508
1509 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PCB_NET_INSPECTOR_PANEL::onContextMenuSelection, this );
1510
1511 PopupMenu( &menu );
1512}
1513
1514
1516{
1517 for( int i = 1; i <= COLUMN_LAST_STATIC_COL; ++i )
1518 {
1519 wxMenuItem* opt = new wxMenuItem( target, ID_HIDE_COLUMN + i, m_columns[i].display_name,
1520 wxEmptyString, wxITEM_CHECK );
1521 wxDataViewColumn* col = getDisplayedColumnForModelField( i );
1522 target->Append( opt );
1523 opt->Check( !col->IsHidden() );
1524 }
1525
1526 target->AppendSeparator();
1527
1528 for( std::size_t i = COLUMN_LAST_STATIC_COL + 1; i < m_columns.size(); ++i )
1529 {
1530 wxMenuItem* opt = new wxMenuItem( target, ID_HIDE_COLUMN + i, m_columns[i].display_name,
1531 wxEmptyString, wxITEM_CHECK );
1532 wxDataViewColumn* col = getDisplayedColumnForModelField( i );
1533 target->Append( opt );
1534 opt->Check( !col->IsHidden() );
1535 }
1536}
1537
1538
1540{
1541 bool saveAndRebuild = true;
1542
1543 switch( event.GetId() )
1544 {
1545 case ID_ADD_NET:
1546 onAddNet();
1547 break;
1548
1549 case ID_RENAME_NET:
1551 break;
1552
1553 case ID_DELETE_NET:
1555 break;
1556
1557 case ID_ADD_GROUP:
1558 onAddGroup();
1559 break;
1560
1563 break;
1564
1567 break;
1568
1571 break;
1572
1575 break;
1576
1579 break;
1580
1583 break;
1584
1585 case ID_REMOVE_GROUPS:
1586 m_custom_group_rules.clear();
1587 break;
1588
1591 break;
1592
1595 break;
1596
1599 break;
1600
1601 case ID_GENERATE_REPORT:
1603 saveAndRebuild = false;
1604 break;
1605
1608 saveAndRebuild = false;
1609 break;
1610
1613 saveAndRebuild = false;
1614 break;
1615
1616 case ID_AUTOFIT_COLUMN:
1619
1620 saveAndRebuild = false;
1621 break;
1622
1624 for( unsigned int i = 0; i < m_netsList->GetColumnCount(); ++i )
1625 autosizeColumn( m_netsList->GetColumn( i ) );
1626
1627 saveAndRebuild = false;
1628 break;
1629
1630 default:
1631 if( event.GetId() >= ID_HIDE_COLUMN )
1632 {
1633 const int columnId = event.GetId() - ID_HIDE_COLUMN;
1634 wxDataViewColumn* col = getDisplayedColumnForModelField( columnId );
1635 // Make sure we end up with something non-zero so we can resize it
1636 col->SetWidth( std::max( col->GetWidth(), 10 ) );
1637 col->SetHidden( !col->IsHidden() );
1638 }
1639 break;
1640 }
1641
1642 if( saveAndRebuild )
1643 {
1644 SaveSettings();
1645 buildNetsList();
1646 }
1647}
1648
1649
1651{
1652 if( m_netsList->GetSelectedItemsCount() == 1 )
1653 {
1654 auto* selItem = static_cast<const LIST_ITEM*>( m_netsList->GetSelection().GetID() );
1655
1656 if( selItem->GetIsGroup() )
1657 {
1658 const wxString groupName = selItem->GetGroupName();
1659 const auto groupIter = std::ranges::find_if( m_custom_group_rules,
1660 [&]( std::unique_ptr<EDA_COMBINED_MATCHER>& rule )
1661 {
1662 return rule->GetPattern() == groupName;
1663 } );
1664
1665 if( groupIter != m_custom_group_rules.end() )
1666 {
1667 m_custom_group_rules.erase( groupIter );
1668 SaveSettings();
1669 buildNetsList();
1670 }
1671 }
1672 }
1673}
1674
1675
1677{
1678 wxFileDialog dlg( this, _( "Save Net Inspector Report File" ), "", "",
1679 _( "Report file" ) + AddFileExtListToFilter( { "csv" } ),
1680 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
1681
1683
1684 if( dlg.ShowModal() == wxID_CANCEL )
1685 return;
1686
1687 wxTextFile f( dlg.GetPath() );
1688
1689 f.Create();
1690
1691 wxString txt;
1692
1693 m_inReporting = true;
1694
1695 // Print Header:
1696 for( auto&& col : m_columns )
1697 {
1698 txt += '"';
1699
1700 if( col.has_units )
1701 {
1702 txt += wxString::Format( _( "%s (%s)" ),
1703 col.csv_name,
1704 EDA_UNIT_UTILS::GetLabel( m_frame->GetUserUnits() ) );
1705 }
1706 else
1707 {
1708 txt += col.csv_name;
1709 }
1710
1711 txt += wxT( "\";" );
1712 }
1713
1714 f.AddLine( txt );
1715
1716 // Print list of nets:
1717 const unsigned int num_rows = m_dataModel->itemCount();
1718
1719 for( unsigned int row = 0; row < num_rows; row++ )
1720 {
1721 auto& i = m_dataModel->itemAt( row );
1722
1723 if( i.GetIsGroup() || i.GetNetCode() == 0 )
1724 continue;
1725
1726 txt = "";
1727
1728 for( auto&& col : m_columns )
1729 {
1730 if( static_cast<int>( col.csv_flags ) & static_cast<int>( CSV_COLUMN_DESC::CSV_QUOTE ) )
1731 txt += '"' + m_dataModel->valueAt( col.num, row ).GetString() + wxT( "\";" );
1732 else
1733 txt += m_dataModel->valueAt( col.num, row ).GetString() + ';';
1734 }
1735
1736 f.AddLine( txt );
1737 }
1738
1739 m_inReporting = false;
1740
1741 f.Write();
1742 f.Close();
1743}
1744
1745
1747{
1749}
1750
1751
1753{
1754 // ignore selection changes while the whole list is being rebuilt.
1755 if( m_inBuildNetsList )
1756 return;
1757
1758 m_highlightingNets = true;
1759
1760 RENDER_SETTINGS* renderSettings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
1761
1762 if( m_netsList->HasSelection() )
1763 {
1764 wxDataViewItemArray sel;
1765 m_netsList->GetSelections( sel );
1766
1767 renderSettings->SetHighlight( false );
1768
1769 for( unsigned int i = 0; i < sel.GetCount(); ++i )
1770 {
1771 const LIST_ITEM* ii = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
1772
1773 if( ii->GetIsGroup() )
1774 {
1775 for( auto c = ii->ChildrenBegin(), end = ii->ChildrenEnd(); c != end; ++c )
1776 renderSettings->SetHighlight( true, ( *c )->GetNetCode(), true );
1777 }
1778 else
1779 {
1780 renderSettings->SetHighlight( true, ii->GetNetCode(), true );
1781 }
1782 }
1783 }
1784 else
1785 {
1786 renderSettings->SetHighlight( false );
1787 }
1788
1789 m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
1790 m_frame->GetCanvas()->Refresh();
1791
1792 m_highlightingNets = false;
1793}
1794
1795
1796void PCB_NET_INSPECTOR_PANEL::OnColumnSorted( wxDataViewEvent& event )
1797{
1798 if( !m_inBuildNetsList )
1799 SaveSettings();
1800}
1801
1802
1804{
1805 // Rebuilt the nets list, and force rebuild of columns in case the stackup has changed
1806 buildNetsList( true );
1807}
1808
1809
1811{
1812 wxString newNetName;
1813 NETNAME_VALIDATOR validator( &newNetName );
1814
1815 WX_TEXT_ENTRY_DIALOG dlg( this, _( "Net name:" ), _( "New Net" ), newNetName );
1817
1818 while( true )
1819 {
1820 if( dlg.ShowModal() != wxID_OK || dlg.GetValue().IsEmpty() )
1821 return; //Aborted by user
1822
1823 newNetName = dlg.GetValue();
1824
1825 if( m_board->FindNet( newNetName ) )
1826 {
1827 DisplayError( this, wxString::Format( _( "Net name '%s' is already in use." ), newNetName ) );
1828 newNetName = wxEmptyString;
1829 }
1830 else
1831 {
1832 break;
1833 }
1834 }
1835
1836 NETINFO_ITEM* newnet = new NETINFO_ITEM( m_board, dlg.GetValue(), 0 );
1837
1838 m_board->Add( newnet );
1839
1840 // We'll get an OnBoardItemAdded callback from this to update our listbox
1841 m_frame->OnModify();
1842}
1843
1844
1846{
1847 if( m_netsList->GetSelectedItemsCount() == 1 )
1848 {
1849 const LIST_ITEM* sel = static_cast<const LIST_ITEM*>( m_netsList->GetSelection().GetID() );
1850
1851 if( sel->GetIsGroup() )
1852 return;
1853
1854 NETINFO_ITEM* net = sel->GetNet();
1855 wxString fullNetName = net->GetNetname();
1856 wxString netPath;
1857 wxString shortNetName;
1858
1859 if( fullNetName.Contains( wxT( "/" ) ) )
1860 {
1861 netPath = fullNetName.BeforeLast( '/' ) + '/';
1862 shortNetName = fullNetName.AfterLast( '/' );
1863 }
1864 else
1865 {
1866 shortNetName = fullNetName;
1867 }
1868
1869 wxString unescapedShortName = UnescapeString( shortNetName );
1870
1871 WX_TEXT_ENTRY_DIALOG dlg( this, _( "Net name:" ), _( "Rename Net" ), unescapedShortName );
1872 NETNAME_VALIDATOR validator( &unescapedShortName );
1874
1875 while( true )
1876 {
1877 if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == unescapedShortName )
1878 return;
1879
1880 unescapedShortName = dlg.GetValue();
1881
1882 if( unescapedShortName.IsEmpty() )
1883 {
1884 DisplayError( this, _( "Net name cannot be empty." ) );
1885 continue;
1886 }
1887
1888 shortNetName = EscapeString( unescapedShortName, CTX_NETNAME );
1889 fullNetName = netPath + shortNetName;
1890
1891 if( m_board->FindNet( shortNetName ) || m_board->FindNet( fullNetName ) )
1892 {
1893 DisplayError( this, wxString::Format( _( "Net name '%s' is already in use." ), unescapedShortName ) );
1894 unescapedShortName = wxEmptyString;
1895 }
1896 else
1897 {
1898 break;
1899 }
1900 }
1901
1902 for( BOARD_CONNECTED_ITEM* boardItem : m_frame->GetBoard()->AllConnectedItems() )
1903 {
1904 if( boardItem->GetNet() == net )
1905 boardItem->SetFlags( CANDIDATE );
1906 else
1907 boardItem->ClearFlags( CANDIDATE );
1908 }
1909
1910 // the changed name might require re-grouping. remove/re-insert is easier.
1911 auto removed_item = m_dataModel->deleteItem( m_dataModel->findItem( net ) );
1912
1913 m_board->Remove( net );
1914 net->SetNetname( fullNetName );
1915 m_board->Add( net );
1916
1917 for( BOARD_CONNECTED_ITEM* boardItem : m_frame->GetBoard()->AllConnectedItems() )
1918 {
1919 if( boardItem->GetFlags() & CANDIDATE )
1920 boardItem->SetNet( net );
1921 }
1922
1923 buildNetsList();
1924
1925 if( std::optional<LIST_ITEM_ITER> r = m_dataModel->findItem( net ) )
1926 m_netsList->Select( wxDataViewItem( r.value()->get() ) );
1927
1928 m_frame->OnModify();
1929
1930 // Currently only tracks and pads have netname annotations and need to be redrawn,
1931 // but zones are likely to follow. Since we don't have a way to ask what is current,
1932 // just refresh all items.
1933 m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
1934 m_frame->GetCanvas()->Refresh();
1935 }
1936}
1937
1938
1940{
1941 if( !m_netsList->HasSelection() )
1942 return;
1943
1944 wxDataViewItemArray sel;
1945 m_netsList->GetSelections( sel );
1946
1947 auto delete_one = [this]( const LIST_ITEM* i )
1948 {
1949 if( i->GetPadCount() == 0
1950 || IsOK( this, wxString::Format( _( "Net '%s' is in use. Delete anyway?" ), i->GetNetName() ) ) )
1951 {
1952 // This is a bit hacky, but it will do for now, since this is the only path
1953 // outside the netlist updater where you can remove a net from a BOARD.
1954 int removedCode = i->GetNetCode();
1955
1956 m_frame->GetCanvas()->GetView()->UpdateAllItemsConditionally(
1957 [removedCode]( KIGFX::VIEW_ITEM* aItem ) -> int
1958 {
1959 auto boardItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
1960
1961 if( boardItem && boardItem->GetNetCode() == removedCode )
1962 return KIGFX::REPAINT;
1963
1964 EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
1965
1966 if( text && text->HasTextVars() )
1967 {
1968 text->ClearRenderCache();
1969 text->ClearBoundingBoxCache();
1971 }
1972
1973 return 0;
1974 } );
1975
1976 m_board->Remove( i->GetNet() );
1977 m_frame->OnModify();
1978
1979 // We'll get an OnBoardItemRemoved callback from this to update our listbox
1980 }
1981 };
1982
1983 for( unsigned int i = 0; i < sel.GetCount(); ++i )
1984 {
1985 const LIST_ITEM* ii = static_cast<const LIST_ITEM*>( sel.Item( i ).GetID() );
1986
1987 if( ii->GetIsGroup() )
1988 {
1989 if( ii->ChildrenCount() != 0
1990 && IsOK( this, wxString::Format( _( "Delete all nets in group '%s'?" ), ii->GetGroupName() ) ) )
1991 {
1992 // we can't be iterating the children container and deleting items from
1993 // it at the same time. thus take a copy of it first.
1994 std::vector<const LIST_ITEM*> children;
1995 children.reserve( ii->ChildrenCount() );
1996 std::copy( ii->ChildrenBegin(), ii->ChildrenEnd(), std::back_inserter( children ) );
1997
1998 for( const LIST_ITEM* c : children )
1999 delete_one( c );
2000 }
2001 }
2002 else
2003 {
2004 delete_one( ii );
2005 }
2006 }
2007}
2008
2009/*****************************************************************************************
2010 *
2011 * Application-generated event handling
2012 *
2013 * ***************************************************************************************/
2014
2015
2017{
2018 SaveSettings();
2019 buildNetsList( true );
2020 m_dataModel->updateAllItems();
2021}
2022
2023
2024void PCB_NET_INSPECTOR_PANEL::onUnitsChanged( wxCommandEvent& event )
2025{
2026 m_dataModel->updateAllItems();
2027 event.Skip();
2028}
2029
2030
2031/*****************************************************************************************
2032 *
2033 * Settings persistence
2034 *
2035 * ***************************************************************************************/
2036
2037
2039{
2040 // Don't save settings if a board has not yet been loaded or the panel hasn't been displayed.
2041 // Events fire while we set up the panel which overwrite the settings we haven't yet loaded.
2042 bool displayed = false;
2043
2044 for( unsigned int ii = 0; ii < m_dataModel->columnCount() && !displayed; ++ii )
2045 {
2046 if( m_netsList->GetColumn( ii )->GetWidth() > 0 )
2047 displayed = true;
2048 }
2049
2050 if( !displayed || !m_boardLoaded || m_boardLoading )
2051 return;
2052
2054 auto& cfg = localSettings.m_NetInspectorPanel;
2055
2056 // User-defined filters / grouping
2057 cfg.filter_text = m_searchCtrl->GetValue();
2058 cfg.filter_by_net_name = m_filterByNetName;
2059 cfg.filter_by_netclass = m_filterByNetclass;
2060 cfg.group_by_netclass = m_groupByNetclass;
2061 cfg.group_by_net_chain = m_groupByNetChain;
2062 cfg.group_by_constraint = m_groupByConstraint;
2063 cfg.show_zero_pad_nets = m_showZeroPadNets;
2064 cfg.show_unconnected_nets = m_showUnconnectedNets;
2065 cfg.show_time_domain_details = m_showTimeDomainDetails;
2066
2067 // Grid sorting
2068 wxDataViewColumn* sortingCol = m_netsList->GetSortingColumn();
2069 cfg.sorting_column = sortingCol ? static_cast<int>( sortingCol->GetModelColumn() ) : -1;
2070 cfg.sort_order_asc = sortingCol ? sortingCol->IsSortOrderAscending() : true;
2071
2072 // Column arrangement / sizes
2073 cfg.col_order.resize( m_dataModel->columnCount() );
2074 cfg.col_widths.resize( m_dataModel->columnCount() );
2075 cfg.col_hidden.resize( m_dataModel->columnCount() );
2076
2077 for( unsigned int ii = 0; ii < m_dataModel->columnCount(); ++ii )
2078 {
2079 cfg.col_order[ii] = (int) m_netsList->GetColumn( ii )->GetModelColumn();
2080 cfg.col_widths[ii] = m_netsList->GetColumn( ii )->GetWidth();
2081 cfg.col_hidden[ii] = m_netsList->GetColumn( ii )->IsHidden();
2082 }
2083
2084 // Expanded rows
2085 cfg.expanded_rows.clear();
2086 std::vector<std::pair<wxString, wxDataViewItem>> groupItems = m_dataModel->getGroupDataViewItems();
2087
2088 for( std::pair<wxString, wxDataViewItem>& item : groupItems )
2089 {
2090 if( m_netsList->IsExpanded( item.second ) )
2091 cfg.expanded_rows.push_back( item.first );
2092 }
2093
2094 // Customer group rules
2095 cfg.custom_group_rules.clear();
2096
2097 for( const std::unique_ptr<EDA_COMBINED_MATCHER>& rule : m_custom_group_rules )
2098 cfg.custom_group_rules.push_back( rule->GetPattern() );
2099}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
CN_ITEM represents a BOARD_CONNECTED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
int Net() const
int ShowModal() override
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Lightweight class which holds a pad, via, or a routed trace outline.
Class which calculates lengths (and associated routing statistics) in a BOARD context.
LENGTH_DELAY_STATS CalculateLengthDetails(std::vector< LENGTH_DELAY_CALCULATION_ITEM > &aItems, PATH_OPTIMISATIONS aOptimisations, const PAD *aStartPad=nullptr, const PAD *aEndPad=nullptr, LENGTH_DELAY_LAYER_OPT aLayerOpt=LENGTH_DELAY_LAYER_OPT::NO_LAYER_DETAIL, LENGTH_DELAY_DOMAIN_OPT aDomain=LENGTH_DELAY_DOMAIN_OPT::NO_DELAY_DETAIL, LENGTH_DELAY_ITEM_DETAILS *aPerItemLengthDelays=nullptr) const
Calculates the electrical length of the given items.
LENGTH_DELAY_CALCULATION_ITEM GetLengthCalculationItem(const BOARD_CONNECTED_ITEM *aBoardItem) const
Return a LENGTH_CALCULATION_ITEM constructed from the given BOARD_CONNECTED_ITEM.
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition netclass.cpp:382
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetChain() const
Definition netinfo.h:122
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
const wxString & GetNetname() const
Definition netinfo.h:110
NETCLASS * GetNetClass()
Definition netinfo.h:101
int GetNetCode() const
Definition netinfo.h:104
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)
WX_DATAVIEWCTRL * m_netsList
wxSearchCtrl * m_searchCtrl
Definition pad.h:61
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)
int getMinColumnWidth(int aModelColumn) const
Computes the minimum display width for a column based on its header text.
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.
void autosizeColumn(wxDataViewColumn *aCol)
Auto-sizes a column to fit both its header text and content.
wxDataViewColumn * m_contextMenuColumn
Tracks which column the header context menu was opened for.
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 OnHeaderContextMenu(wxDataViewEvent &event)
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.
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.
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.
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.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
The project local settings are things that are attached to a particular project, but also might be pa...
PANEL_NET_INSPECTOR_SETTINGS m_NetInspectorPanel
The state of the net inspector panel.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:207
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
wxBoxSizer * m_ContentSizer
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
void SetTextValidator(const wxValidator &validator)
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define _(s)
#define CANDIDATE
flag indicating that the structure is connected
Abstract pattern-matching tool and implementations.
@ CTX_NET
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
KICOMMON_API wxString GetLabel(EDA_UNITS aUnits, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Get the units string for a given units type.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:741
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
double ChainBridgingDelayPerMm(const BOARD *aBoard, const wxString &aNetChain, const double aDefaultBridgeUnitDelay)
Pick a single per-IU-per-mm delay for a given chain.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Class that computes missing connections on a PCB.
static bool highlightNet(TOOL_MANAGER *aToolMgr, const SCH_SHEET_PATH &aSheetPath, const VECTOR2D &aPosition)
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
Holds length measurement result details and statistics.
bool operator()(const CN_ITEM *a, const CN_ITEM *b) const
bool operator()(int a, const CN_ITEM *b) const
bool operator()(const CN_ITEM *a, int b) const
Persisted state for the net inspector panel.
std::vector< wxString > expanded_rows
std::vector< wxString > custom_group_rules
JSON_SCHEMA_VALIDATOR validator(schema)
KIBIS_MODEL * model
const SHAPE_LINE_CHAIN chain
VECTOR2I end
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
static thread_pool * tp
BS::priority_thread_pool thread_pool
Definition thread_pool.h:27
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
Custom text control validator definitions.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Definition of file extensions used in Kicad.