KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_net_inspector_panel_data_model.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_PANEL_DATA_MODEL
21#define PCB_NET_INSPECTOR_PANEL_DATA_MODEL
22
23#include <eda_pattern_match.h>
24
25
32{
33public:
34 enum class GROUP_TYPE
35 {
36 NONE,
39 };
40
41 LIST_ITEM( unsigned int aGroupNumber, const wxString& aGroupName, GROUP_TYPE aGroupType ) :
42 m_group_type( aGroupType ),
43 m_group_number( aGroupNumber ),
44 m_net_name( aGroupName )
45 {
46 m_group_name = aGroupName;
47 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + 2, 0 ); // 2 for default layer count
48 }
49
52 m_net( aNet )
53 {
54 wxASSERT( aNet );
57 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + 2, 0 );
58 }
59
61
62 LIST_ITEM& operator=( const LIST_ITEM& ) = delete;
63
64 bool GetIsGroup() const { return m_group_type != GROUP_TYPE::NONE; }
65 const wxString& GetGroupName() const { return m_group_name; }
67 int GetGroupNumber() const { return m_group_number; }
68
69 auto ChildrenBegin() const { return m_children.begin(); }
70 auto ChildrenEnd() const { return m_children.end(); }
71 unsigned int ChildrenCount() const { return m_children.size(); }
72
73 void SetLayerCount( unsigned int aValue )
74 {
75 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + aValue, 0 );
76 }
77
78 NETINFO_ITEM* GetNet() const { return m_net; }
79
80 int GetNetCode() const
81 {
82 return GetIsGroup() ? ( 0 - int( m_group_number ) - 1 ) : m_net->GetNetCode();
83 }
84
85 const wxString& GetNetName() const { return m_net_name; }
86 const wxString& GetNetclassName() const { return m_net_class; }
87
89 {
90 std::fill( m_column_changed.begin(), m_column_changed.end(), 0 );
91 }
92
93 unsigned int GetPadCount() const { return m_pad_count; }
94
96
97 void SetPadCount( unsigned int aValue )
98 {
99 if( m_parent )
101
103 m_pad_count = aValue;
104 }
105
106 void AddPadCount( unsigned int aValue )
107 {
108 if( m_parent )
109 m_parent->AddPadCount( aValue );
110
111 m_column_changed[COLUMN_PAD_COUNT] |= ( aValue != 0 );
112 m_pad_count += aValue;
113 }
114
115 void SubPadCount( unsigned int aValue )
116 {
117 if( m_parent )
118 m_parent->SubPadCount( aValue );
119
120 m_column_changed[COLUMN_PAD_COUNT] |= ( aValue != 0 );
121 m_pad_count -= aValue;
122 }
123
124 unsigned GetViaCount() const { return m_via_count; }
125
127
128 void SetViaCount( unsigned int aValue )
129 {
130 if( m_parent )
132
134 m_via_count = aValue;
135 }
136
137 void AddViaCount( unsigned int aValue )
138 {
139 if( m_parent )
140 m_parent->AddViaCount( aValue );
141
142 m_column_changed[COLUMN_VIA_COUNT] |= ( aValue != 0 );
143 m_via_count += aValue;
144 }
145
146 void SubViaCount( unsigned int aValue )
147 {
148 if( m_parent )
149 m_parent->SubViaCount( aValue );
150
151 m_column_changed[COLUMN_VIA_COUNT] |= ( aValue != 0 );
152 m_via_count -= aValue;
153 }
154
155 uint64_t GetViaLength() const { return m_via_length; }
156
158
159 void SetViaLength( unsigned int aValue )
160 {
161 if( m_parent )
163
165 m_via_length = aValue;
166 }
167
168 void AddViaLength( unsigned int aValue )
169 {
170 if( m_parent )
171 m_parent->AddViaLength( aValue );
172
173 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
174 m_via_length += aValue;
175 }
176
177 void SubViaLength( uint64_t aValue )
178 {
179 if( m_parent )
180 m_parent->SubViaLength( aValue );
181
182 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
183 m_via_length -= aValue;
184 }
185
186 uint64_t GetBoardWireLength() const
187 {
188 uint64_t retval = 0;
189
190 for( auto& [layer, length] : m_layer_wire_length )
191 retval += length;
192
193 return retval;
194 }
195
196 uint64_t GetLayerWireLength( PCB_LAYER_ID aLayer ) const
197 {
198 auto it = m_layer_wire_length.find( aLayer );
199 return it != m_layer_wire_length.end() ? it->second : 0;
200 }
201
203
204 void SetLayerWireLength( const uint64_t aValue, PCB_LAYER_ID aLayer )
205 {
206 auto it = m_layer_wire_length.find( aLayer );
207
208 wxCHECK_RET( it != m_layer_wire_length.end(), wxT( "Invalid layer specified" ) );
209
210 auto& [_, length] = *it;
211
212 if( m_parent )
213 {
215 aLayer );
216 }
217
218 m_column_changed[COLUMN_BOARD_LENGTH] |= ( length != aValue );
219 length = aValue;
220 }
221
222 std::map<PCB_LAYER_ID, uint64_t> GetLayerWireLength() const { return m_layer_wire_length; }
223
224 void SetLayerWireLength( const std::map<PCB_LAYER_ID, uint64_t>& aValue )
225 {
226 m_layer_wire_length = aValue;
227 }
228
229 void AddLayerWireLength( const uint64_t aValue, PCB_LAYER_ID aLayer )
230 {
231 if( m_parent )
232 m_parent->AddLayerWireLength( aValue, aLayer );
233
235 m_layer_wire_length[aLayer] += aValue;
236 }
237
238 void SubLayerWireLength( const uint64_t aValue, PCB_LAYER_ID aLayer )
239 {
240 if( m_parent )
241 m_parent->SubLayerWireLength( aValue, aLayer );
242
244 m_layer_wire_length[aLayer] -= aValue;
245 }
246
247 uint64_t GetPadDieLength() const { return m_pad_die_length; }
248
250
251 void SetPadDieLength( uint64_t aValue )
252 {
253 if( m_parent )
255
257 m_pad_die_length = aValue;
258 }
259
260 void AddPadDieLength( uint64_t aValue )
261 {
262 if( m_parent )
263 m_parent->AddPadDieLength( aValue );
264
265 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
266 m_pad_die_length += aValue;
267 }
268
269 void SubPadDieLength( uint64_t aValue )
270 {
271 if( m_parent )
272 m_parent->SubPadDieLength( aValue );
273
274 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
275 m_pad_die_length -= aValue;
276 }
277
278 // the total length column is always computed, never stored.
279 unsigned long long int GetTotalLength() const
280 {
282 }
283
285 {
287 }
288
289 LIST_ITEM* Parent() const { return m_parent; }
290
291 void SetParent( LIST_ITEM* aParent )
292 {
293 if( m_parent == aParent )
294 return;
295
296 if( m_parent != nullptr )
297 {
301
302 for( auto& [layer, length] : m_layer_wire_length )
303 m_parent->SubLayerWireLength( length, layer );
304
306
307 m_parent->m_children.erase( std::find( m_parent->m_children.begin(),
308 m_parent->m_children.end(), this ) );
309 }
310
311 m_parent = aParent;
312
313 if( m_parent != nullptr )
314 {
318
319 for( auto& [layer, length] : m_layer_wire_length )
320 m_parent->AddLayerWireLength( length, layer );
321
323
324 m_parent->m_children.push_back( this );
325 }
326 }
327
328private:
329 LIST_ITEM* m_parent = nullptr;
330 std::vector<LIST_ITEM*> m_children;
331
333 unsigned int m_group_number = 0;
334 NETINFO_ITEM* m_net = nullptr;
335 unsigned int m_pad_count = 0;
336 unsigned int m_via_count = 0;
337 uint64_t m_via_length = 0;
338 uint64_t m_pad_die_length = 0;
339
340 std::map<PCB_LAYER_ID, uint64_t> m_layer_wire_length{};
341
342 // Dirty bits to record when some attribute has changed, in order to avoid unnecessary sort
343 // operations.
344 // The values are semantically bools, but STL auto-promotes a std::vector<bool> to a bitset,
345 // and then operator|= doesn't work.
346 std::vector<int> m_column_changed;
347
348 // cached formatted names for faster display sorting
349 wxString m_net_name;
350 wxString m_net_class;
351 wxString m_group_name;
352};
353
354
356{
357 template <typename T>
358 bool operator()( const T& a, const T& b ) const
359 {
360 return a->GetNetCode() < b->GetNetCode();
361 }
362
363 template <typename T>
364 bool operator()( const T& a, int b ) const
365 {
366 return a->GetNetCode() < b;
367 }
368
369 template <typename T>
370 bool operator()( int a, const T& b ) const
371 {
372 return a < b->GetNetCode();
373 }
374};
375
376
378{
379 template <typename T>
380 bool operator()( const T& a, const T& b ) const
381 {
382 return a->GetGroupNumber() < b->GetGroupNumber();
383 }
384
385 template <typename T>
386 bool operator()( const T& a, int b ) const
387 {
388 return a->GetGroupNumber() < b;
389 }
390
391 template <typename T>
392 bool operator()( int a, const T& b ) const
393 {
394 return a < b->GetGroupNumber();
395 }
396};
397
398
402class PCB_NET_INSPECTOR_PANEL::DATA_MODEL : public wxDataViewModel
403{
404public:
406
407 unsigned int columnCount() const { return m_parent.m_columns.size(); }
408
409 unsigned int itemCount() const { return m_items.size(); }
410
411 wxVariant valueAt( unsigned int aCol, unsigned int aRow ) const
412 {
413 wxVariant r;
414 GetValue( r, wxDataViewItem( const_cast<LIST_ITEM*>( &*( m_items[aRow] ) ) ), aCol );
415 return r;
416 }
417
418 const LIST_ITEM& itemAt( unsigned int aRow ) const { return *m_items.at( aRow ); }
419
420 std::vector<std::pair<wxString, wxDataViewItem>> getGroupDataViewItems()
421 {
422 std::vector<std::pair<wxString, wxDataViewItem>> ret;
423
424 for( std::unique_ptr<LIST_ITEM>& item : m_items )
425 {
426 if( item->GetIsGroup() )
427 {
428 ret.push_back( std::make_pair( item->GetGroupName(),
429 wxDataViewItem( item.get() ) ) );
430 }
431 }
432
433 return ret;
434 }
435
436
437 std::optional<LIST_ITEM_ITER> findItem( int aNetCode )
438 {
439 auto i = std::lower_bound( m_items.begin(), m_items.end(), aNetCode,
441
442 if( i == m_items.end() || ( *i )->GetNetCode() != aNetCode )
443 return std::nullopt;
444
445 return { i };
446 }
447
448
449 std::optional<LIST_ITEM_ITER> findItem( NETINFO_ITEM* aNet )
450 {
451 if( aNet != nullptr )
452 return findItem( aNet->GetNetCode() );
453 else
454 return std::nullopt;
455 }
456
457
458 std::optional<LIST_ITEM_ITER> findGroupItem( int aGroupNumber )
459 {
460 auto i = std::lower_bound( m_items.begin(), m_items.end(), aGroupNumber,
462
463 if( i == m_items.end() || ( *i )->GetGroupNumber() != aGroupNumber )
464 return std::nullopt;
465
466 return { i };
467 }
468
469
471 wxString groupName, LIST_ITEM::GROUP_TYPE groupType )
472 {
473 LIST_ITEM_ITER group = std::find_if( groupsBegin, groupsEnd,
474 [&]( const std::unique_ptr<LIST_ITEM>& x )
475 {
476 return x->GetGroupName() == groupName
477 && x->GetGroupType() == groupType;
478 } );
479
480 if( group == groupsEnd )
481 {
482 int dist = std::distance( groupsBegin, groupsEnd );
483 std::unique_ptr<LIST_ITEM> groupItem = std::make_unique<LIST_ITEM>( dist, groupName,
484 groupType );
485 group = m_items.insert( groupsEnd, std::move( groupItem ) );
486 ItemAdded( wxDataViewItem( ( *group )->Parent() ), wxDataViewItem( &**group ) );
487 }
488
489 return group;
490 }
491
492
493 std::optional<LIST_ITEM_ITER> addItem( std::unique_ptr<LIST_ITEM> aItem )
494 {
495 if( aItem == nullptr )
496 return {};
497
498 bool groupMatched = false;
499
500 // First see if item matches a group-by rule
501 if( m_parent.m_custom_group_rules.size() > 0 )
502 {
503 wxString searchName = aItem->GetNetName().Upper();
504
505 for( const std::unique_ptr<EDA_COMBINED_MATCHER>& rule : m_parent.m_custom_group_rules )
506 {
507 if( rule->Find( searchName.Upper() ) )
508 {
509 aItem->SetParent( m_custom_group_map[ rule->GetPattern() ] );
510 groupMatched = true;
511 break;
512 }
513 }
514 }
515
516 // Then add any netclass groups required by this item
517 if( m_parent.m_group_by_netclass && !groupMatched )
518 {
519 LIST_ITEM_ITER groups_begin = m_items.begin();
520 LIST_ITEM_ITER groups_end = std::find_if_not( m_items.begin(), m_items.end(),
521 []( const std::unique_ptr<LIST_ITEM>& x )
522 {
523 return x->GetIsGroup();
524 } );
525
526 wxString match_str = aItem->GetNetclassName();
527 LIST_ITEM_ITER group = addGroup( groups_begin, groups_end, match_str,
529 aItem->SetParent( &**group );
530 }
531
532 // Now add the item itself. Usually when new nets are added,
533 // they always get a higher netcode number than the already existing ones.
534 // however, if we've got filtering enabled, we might not have all the nets in
535 // our list, so do a sorted insertion.
536 auto new_iter = std::lower_bound( m_items.begin(), m_items.end(), aItem->GetNetCode(),
538
539 new_iter = m_items.insert( new_iter, std::move( aItem ) );
540 const std::unique_ptr<LIST_ITEM>& new_item = *new_iter;
541
542 ItemAdded( wxDataViewItem( new_item->Parent() ), wxDataViewItem( new_item.get() ) );
543
544 return { new_iter };
545 }
546
547 void addItems( std::vector<std::unique_ptr<LIST_ITEM>> aItems )
548 {
549 m_items.reserve( m_items.size() + aItems.size() );
550
551 for( std::unique_ptr<LIST_ITEM>& i : aItems )
552 addItem( std::move( i ) );
553 }
554
555 std::unique_ptr<LIST_ITEM> deleteItem( const std::optional<LIST_ITEM_ITER>& aRow )
556 {
557 if( !aRow )
558 return {};
559
560 std::unique_ptr<LIST_ITEM> i = std::move( **aRow );
561
562 LIST_ITEM* parent = i->Parent();
563 i->SetParent( nullptr );
564
565 m_items.erase( *aRow );
566 ItemDeleted( wxDataViewItem( parent ), wxDataViewItem( &*i ) );
567
568 if( parent )
569 {
570 ItemChanged( wxDataViewItem( parent ) );
571
572 if( m_parent.m_group_by_netclass && parent != nullptr && parent->ChildrenCount() == 0 )
573 {
574 auto p = std::find_if( m_items.begin(), m_items.end(),
575 [&]( std::unique_ptr<LIST_ITEM>& x )
576 {
577 return x.get() == parent;
578 } );
579
580 wxASSERT( p != m_items.end() );
581 m_items.erase( p );
582
583 ItemDeleted( wxDataViewItem( parent->Parent() ), wxDataViewItem( parent ) );
584 }
585 }
586
587 Resort();
588 return i;
589 }
590
591
598 {
599 m_custom_group_map.clear();
600 int groupId = 0;
601
602 for( const std::unique_ptr<EDA_COMBINED_MATCHER>& rule : m_parent.m_custom_group_rules )
603 {
604 std::unique_ptr<LIST_ITEM>& group = m_items.emplace_back( std::make_unique<LIST_ITEM>(
605 groupId, rule->GetPattern(), LIST_ITEM::GROUP_TYPE::USER_DEFINED ) );
606 m_custom_group_map[ rule->GetPattern() ] = group.get();
607 group->SetLayerCount( m_parent.m_brd->GetCopperLayerCount() );
608 ItemAdded( wxDataViewItem( group->Parent() ), wxDataViewItem( group.get() ) );
609 ++groupId;
610 }
611 }
612
613
615 {
616 BeforeReset();
617 m_items.clear();
618 AfterReset();
619 }
620
621 void updateItem( const std::optional<LIST_ITEM_ITER>& aRow )
622 {
623 if( aRow )
624 {
625 const std::unique_ptr<LIST_ITEM>& listItem = *aRow.value();
626
627 if( listItem->Parent() )
628 ItemChanged( wxDataViewItem( listItem->Parent() ) );
629
630 ItemChanged( wxDataViewItem( listItem.get() ) );
631 resortIfChanged( listItem.get() );
632 }
633 }
634
636 {
637 for( std::unique_ptr<LIST_ITEM>& i : m_items )
638 ItemChanged( wxDataViewItem( i.get() ) );
639 }
640
642 {
643 if( wxDataViewColumn* column = m_parent.m_netsList->GetSortingColumn() )
644 {
645 bool changed = false;
646
647 for( const LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
648 changed |= itemColumnChanged( i, column->GetModelColumn() );
649
650 for( LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
651 i->ResetColumnChangedBits();
652
653 if( changed )
654 Resort();
655 }
656 }
657
658 bool itemColumnChanged( const LIST_ITEM* aItem, unsigned int aCol ) const
659 {
660 if( aItem == nullptr || aCol >= m_parent.m_columns.size() )
661 return false;
662
663 if( aCol == COLUMN_PAD_COUNT )
664 return aItem->PadCountChanged();
665
666 else if( aCol == COLUMN_VIA_COUNT )
667 return aItem->ViaCountChanged();
668
669 else if( aCol == COLUMN_VIA_LENGTH )
670 return aItem->ViaLengthChanged();
671
672 else if( aCol == COLUMN_BOARD_LENGTH )
673 return aItem->BoardWireLengthChanged();
674
675 else if( aCol == COLUMN_PAD_DIE_LENGTH )
676 return aItem->PadDieLengthChanged();
677
678 else if( aCol == COLUMN_TOTAL_LENGTH )
679 return aItem->TotalLengthChanged();
680
681 else if( aCol > COLUMN_LAST_STATIC_COL )
682 return aItem->BoardWireLengthChanged();
683
684
685 return false;
686 }
687
688 // implementation of wxDataViewModel interface
689 // these are used to query the data model by the GUI view implementation.
690 // these are not supposed to be used to modify the data model. for that
691 // use the public functions above.
692
693protected:
694 unsigned int GetColumnCount() const override { return columnCount(); }
695
696 void GetValue( wxVariant& aOutValue, const wxDataViewItem& aItem,
697 unsigned int aCol ) const override
698 {
699 if( LIST_ITEM* i = static_cast<LIST_ITEM*>( aItem.GetID() ) )
700 {
701 if( i->GetIsGroup() )
702 {
703 if( aCol == COLUMN_NAME )
704 {
705 switch( i->GetGroupType() )
706 {
708 aOutValue = _( "Netclass" ) + ": " + i->GetGroupName();
709 break;
711 aOutValue = _( "Custom" ) + ": " + i->GetGroupName();
712 break;
713 default:
714 aOutValue = i->GetGroupName();
715 break;
716 }
717 }
718 else
719 {
720 aOutValue = "";
721 }
722 }
723
724 else if( aCol == COLUMN_NAME )
725 aOutValue = i->GetNetName();
726
727 else if( aCol == COLUMN_NETCLASS )
728 aOutValue = i->GetNetclassName();
729
730 else if( aCol == COLUMN_PAD_COUNT )
731 aOutValue = m_parent.formatCount( i->GetPadCount() );
732
733 else if( aCol == COLUMN_VIA_COUNT )
734 aOutValue = m_parent.formatCount( i->GetViaCount() );
735
736 else if( aCol == COLUMN_VIA_LENGTH )
737 aOutValue = m_parent.formatLength( i->GetViaLength() );
738
739 else if( aCol == COLUMN_BOARD_LENGTH )
740 aOutValue = m_parent.formatLength( i->GetBoardWireLength() );
741
742 else if( aCol == COLUMN_PAD_DIE_LENGTH )
743 aOutValue = m_parent.formatLength( i->GetPadDieLength() );
744
745 else if( aCol == COLUMN_TOTAL_LENGTH )
746 aOutValue = m_parent.formatLength( i->GetTotalLength() );
747
748 else if( aCol > COLUMN_LAST_STATIC_COL && aCol <= m_parent.m_columns.size() )
749 aOutValue = m_parent.formatLength( i->GetLayerWireLength( m_parent.m_columns[aCol].layer ) );
750
751 else
752 aOutValue = "";
753 }
754 }
755
756 static int compareUInt( uint64_t aValue1, uint64_t aValue2, bool aAsc )
757 {
758 if( aAsc )
759 return aValue1 < aValue2 ? -1 : 1;
760 else
761 return aValue2 < aValue1 ? -1 : 1;
762 }
763
764 int Compare( const wxDataViewItem& aItem1, const wxDataViewItem& aItem2, unsigned int aCol,
765 bool aAsc ) const override
766 {
767 const LIST_ITEM& i1 = *static_cast<const LIST_ITEM*>( aItem1.GetID() );
768 const LIST_ITEM& i2 = *static_cast<const LIST_ITEM*>( aItem2.GetID() );
769
770 if( i1.GetIsGroup() && !i2.GetIsGroup() )
771 return -1;
772
773 if( i2.GetIsGroup() && !i1.GetIsGroup() )
774 return 1;
775
776 if( aCol == COLUMN_NAME )
777 {
778 const wxString& s1 = i1.GetNetName();
779 const wxString& s2 = i2.GetNetName();
780
781 int res = aAsc ? ValueStringCompare( s1, s2 ) : ValueStringCompare( s2, s1 );
782
783 if( res != 0 )
784 return res;
785 }
786
787 else if( aCol == COLUMN_PAD_COUNT && i1.GetPadCount() != i2.GetPadCount() )
788 return compareUInt( i1.GetPadCount(), i2.GetPadCount(), aAsc );
789
790 else if( aCol == COLUMN_VIA_COUNT && i1.GetViaCount() != i2.GetViaCount() )
791 return compareUInt( i1.GetViaCount(), i2.GetViaCount(), aAsc );
792
793 else if( aCol == COLUMN_VIA_LENGTH && i1.GetViaLength() != i2.GetViaLength() )
794 return compareUInt( i1.GetViaLength(), i2.GetViaLength(), aAsc );
795
796 else if( aCol == COLUMN_BOARD_LENGTH && i1.GetBoardWireLength() != i2.GetBoardWireLength() )
797 return compareUInt( i1.GetBoardWireLength(), i2.GetBoardWireLength(), aAsc );
798
799 else if( aCol == COLUMN_PAD_DIE_LENGTH && i1.GetPadDieLength() != i2.GetPadDieLength() )
800 return compareUInt( i1.GetPadDieLength(), i2.GetPadDieLength(), aAsc );
801
802 else if( aCol == COLUMN_TOTAL_LENGTH && i1.GetTotalLength() != i2.GetTotalLength() )
803 return compareUInt( i1.GetTotalLength(), i2.GetTotalLength(), aAsc );
804
805 else if( aCol > COLUMN_LAST_STATIC_COL && aCol < m_parent.m_columns.size()
806 && i1.GetLayerWireLength( m_parent.m_columns[aCol].layer )
807 != i2.GetLayerWireLength( m_parent.m_columns[aCol].layer ) )
808 {
809 return compareUInt( i1.GetLayerWireLength( m_parent.m_columns[aCol].layer ),
810 i2.GetLayerWireLength( m_parent.m_columns[aCol].layer ), aAsc );
811 }
812
813 // when the item values compare equal resort to pointer comparison.
814 wxUIntPtr id1 = wxPtrToUInt( aItem1.GetID() );
815 wxUIntPtr id2 = wxPtrToUInt( aItem2.GetID() );
816
817 return aAsc ? id1 - id2 : id2 - id1;
818 }
819
820 bool SetValue( const wxVariant& aInValue, const wxDataViewItem& aItem,
821 unsigned int aCol ) override
822 {
823 return false;
824 }
825
826 wxDataViewItem GetParent( const wxDataViewItem& aItem ) const override
827 {
828 if( !aItem.IsOk() )
829 return wxDataViewItem();
830
831 return wxDataViewItem( static_cast<const LIST_ITEM*>( aItem.GetID() )->Parent() );
832 }
833
834 bool IsContainer( const wxDataViewItem& aItem ) const override
835 {
836 if( !aItem.IsOk() )
837 return true;
838
839 return static_cast<const LIST_ITEM*>( aItem.GetID() )->GetIsGroup();
840 }
841
842 bool HasContainerColumns( const wxDataViewItem& aItem ) const override
843 {
844 return IsContainer( aItem );
845 }
846
847 unsigned int GetChildren( const wxDataViewItem& aParent,
848 wxDataViewItemArray& aChildren ) const override
849 {
850 const LIST_ITEM* p = static_cast<const LIST_ITEM*>( aParent.GetID() );
851
852 if( !aParent.IsOk() )
853 {
854 aChildren.Alloc( m_items.size() );
855
856 for( const std::unique_ptr<LIST_ITEM>& i : m_items )
857 {
858 if( i->Parent() == nullptr )
859 aChildren.Add( wxDataViewItem( &*i ) );
860 }
861
862 return aChildren.GetCount();
863 }
864 else if( p->GetIsGroup() )
865 {
866 const int count = p->ChildrenCount();
867
868 if( count == 0 )
869 return 0;
870
871 aChildren.Alloc( count );
872
873 for( auto i = p->ChildrenBegin(), end = p->ChildrenEnd(); i != end; ++i )
874 aChildren.Add( wxDataViewItem( *i ) );
875
876 return aChildren.GetCount();
877 }
878
879 return 0;
880 }
881
882 wxString GetColumnType( unsigned int /* aCol */ ) const override { return wxS( "string" ); }
883
884private:
886
887 // primary container, sorted by netcode number.
888 // groups have netcode < 0, so they always come first, in the order
889 // of the filter strings as input by the user
890 std::vector<std::unique_ptr<LIST_ITEM>> m_items;
891
893 std::map<wxString, LIST_ITEM*> m_custom_group_map;
894};
895
896#endif
int GetCopperLayerCount() const
Definition: board.cpp:738
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
const wxString GetName() const
Gets the consolidated name of this netclass (which may be an aggregate)
Definition: netclass.cpp:151
Handle the data for a net.
Definition: netinfo.h:56
const wxString & GetNetname() const
Definition: netinfo.h:114
NETCLASS * GetNetClass()
Definition: netinfo.h:101
int GetNetCode() const
Definition: netinfo.h:108
wxDataViewCtrl * m_netsList
Data model for display in the Net Inspector panel.
std::unique_ptr< LIST_ITEM > deleteItem(const std::optional< LIST_ITEM_ITER > &aRow)
bool IsContainer(const wxDataViewItem &aItem) const override
bool itemColumnChanged(const LIST_ITEM *aItem, unsigned int aCol) const
void addCustomGroups()
Adds all custom group-by entries to the items table.
wxString GetColumnType(unsigned int) const override
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
bool HasContainerColumns(const wxDataViewItem &aItem) const override
bool SetValue(const wxVariant &aInValue, const wxDataViewItem &aItem, unsigned int aCol) override
void addItems(std::vector< std::unique_ptr< LIST_ITEM > > aItems)
void GetValue(wxVariant &aOutValue, const wxDataViewItem &aItem, unsigned int aCol) const override
std::vector< std::pair< wxString, wxDataViewItem > > getGroupDataViewItems()
std::optional< LIST_ITEM_ITER > findItem(NETINFO_ITEM *aNet)
static int compareUInt(uint64_t aValue1, uint64_t aValue2, bool aAsc)
unsigned int GetChildren(const wxDataViewItem &aParent, wxDataViewItemArray &aChildren) const override
std::optional< LIST_ITEM_ITER > findItem(int aNetCode)
std::map< wxString, LIST_ITEM * > m_custom_group_map
Map of custom group names to their representative list item.
wxVariant valueAt(unsigned int aCol, unsigned int aRow) const
int Compare(const wxDataViewItem &aItem1, const wxDataViewItem &aItem2, unsigned int aCol, bool aAsc) const override
std::optional< LIST_ITEM_ITER > findGroupItem(int aGroupNumber)
std::vector< std::unique_ptr< LIST_ITEM > > m_items
const LIST_ITEM & itemAt(unsigned int aRow) const
void updateItem(const std::optional< LIST_ITEM_ITER > &aRow)
LIST_ITEM_ITER addGroup(LIST_ITEM_ITER groupsBegin, LIST_ITEM_ITER groupsEnd, wxString groupName, LIST_ITEM::GROUP_TYPE groupType)
std::optional< LIST_ITEM_ITER > addItem(std::unique_ptr< LIST_ITEM > aItem)
Primary data item for entries in the Net Inspector list.
LIST_ITEM(unsigned int aGroupNumber, const wxString &aGroupName, GROUP_TYPE aGroupType)
void SubLayerWireLength(const uint64_t aValue, PCB_LAYER_ID aLayer)
uint64_t GetLayerWireLength(PCB_LAYER_ID aLayer) const
void AddLayerWireLength(const uint64_t aValue, PCB_LAYER_ID aLayer)
void SetLayerWireLength(const uint64_t aValue, PCB_LAYER_ID aLayer)
void SetLayerWireLength(const std::map< PCB_LAYER_ID, uint64_t > &aValue)
LIST_ITEM & operator=(const LIST_ITEM &)=delete
std::map< PCB_LAYER_ID, uint64_t > m_layer_wire_length
std::map< PCB_LAYER_ID, uint64_t > GetLayerWireLength() const
Net inspection panel for pcbnew.
std::vector< std::unique_ptr< LIST_ITEM > >::iterator LIST_ITEM_ITER
wxString formatCount(unsigned int aValue) const
std::vector< std::unique_ptr< EDA_COMBINED_MATCHER > > m_custom_group_rules
wxString formatLength(int64_t aValue) const
std::vector< COLUMN_DESC > m_columns
All displayed (or hidden) columns.
#define _(s)
Abstract pattern-matching tool and implementations.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
wxString UnescapeString(const wxString &aSource)
int ValueStringCompare(const wxString &strFWord, const wxString &strSWord)
Compare strings like the strcmp function but handle numbers and modifiers within the string text corr...
VECTOR3I res