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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PCB_NET_INSPECTOR_PANEL_DATA_MODEL
21#define PCB_NET_INSPECTOR_PANEL_DATA_MODEL
22
23#include <eda_pattern_match.h>
24#include <string_utils.h>
25#include <board.h>
28
29
36{
37public:
45
46 LIST_ITEM( unsigned int aGroupNumber, const wxString& aGroupName, GROUP_TYPE aGroupType ) :
47 m_group_type( aGroupType ),
48 m_group_number( aGroupNumber ),
49 m_net_name( aGroupName )
50 {
51 m_group_name = aGroupName;
52 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + 2, 0 ); // 2 for default layer count
53 }
54
57 m_net( aNet )
58 {
59 wxASSERT( aNet );
63 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + 2, 0 );
64 }
65
67 {
68 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + 2, 0 );
69 }
70
71 LIST_ITEM& operator=( const LIST_ITEM& ) = delete;
72
73 bool GetIsGroup() const { return m_group_type != GROUP_TYPE::NONE; }
74 const wxString& GetGroupName() const { return m_group_name; }
76 int GetGroupNumber() const { return m_group_number; }
77
78 auto ChildrenBegin() const { return m_children.begin(); }
79 auto ChildrenEnd() const { return m_children.end(); }
80 unsigned int ChildrenCount() const { return m_children.size(); }
81
82 void SetLayerCount( unsigned int aValue )
83 {
84 m_column_changed.resize( COLUMN_LAST_STATIC_COL + 1 + aValue, 0 );
85 }
86
87 NETINFO_ITEM* GetNet() const { return m_net; }
88
89 int GetNetCode() const
90 {
91 return GetIsGroup() ? ( 0 - int( m_group_number ) - 1 ) : m_net->GetNetCode();
92 }
93
94 const wxString& GetNetName() const { return m_net_name; }
95 const wxString& GetNetclassName() const { return m_net_class; }
96 const wxString& GetNetChainName() const { return m_netChainName; }
97
99 {
100 std::fill( m_column_changed.begin(), m_column_changed.end(), 0 );
101 }
102
103 unsigned int GetPadCount() const { return m_pad_count; }
104
106
107 void SetPadCount( unsigned int aValue )
108 {
109 if( m_parent )
110 m_parent->SetPadCount( m_parent->GetPadCount() - m_pad_count + aValue );
111
113 m_pad_count = aValue;
114 }
115
117
118 void SetNetChainName( const wxString& aValue )
119 {
121 m_netChainName = aValue;
122 }
123
124 void AddPadCount( unsigned int aValue )
125 {
126 if( m_parent )
127 m_parent->AddPadCount( aValue );
128
129 m_column_changed[COLUMN_PAD_COUNT] |= ( aValue != 0 );
130 m_pad_count += aValue;
131 }
132
133 void SubPadCount( unsigned int aValue )
134 {
135 if( m_parent )
136 m_parent->SubPadCount( aValue );
137
138 m_column_changed[COLUMN_PAD_COUNT] |= ( aValue != 0 );
139 m_pad_count -= aValue;
140 }
141
142 unsigned GetViaCount() const { return m_via_count; }
143
145
146 void SetViaCount( unsigned int aValue )
147 {
148 if( m_parent )
149 m_parent->SetViaCount( m_parent->GetViaCount() - m_via_count + aValue );
150
152 m_via_count = aValue;
153 }
154
155 void AddViaCount( unsigned int aValue )
156 {
157 if( m_parent )
158 m_parent->AddViaCount( aValue );
159
160 m_column_changed[COLUMN_VIA_COUNT] |= ( aValue != 0 );
161 m_via_count += aValue;
162 }
163
164 void SubViaCount( unsigned int aValue )
165 {
166 if( m_parent )
167 m_parent->SubViaCount( aValue );
168
169 m_column_changed[COLUMN_VIA_COUNT] |= ( aValue != 0 );
170 m_via_count -= aValue;
171 }
172
173 int64_t GetViaLength() const { return m_via_length; }
174
176
177 void SetViaLength( unsigned int aValue )
178 {
179 if( m_parent )
180 m_parent->SetViaLength( m_parent->GetViaLength() - m_via_length + aValue );
181
183 m_via_length = aValue;
184 }
185
186 void AddViaLength( unsigned int aValue )
187 {
188 if( m_parent )
189 m_parent->AddViaLength( aValue );
190
191 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
192 m_via_length += aValue;
193 }
194
195 void SubViaLength( int64_t aValue )
196 {
197 if( m_parent )
198 m_parent->SubViaLength( aValue );
199
200 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
201 m_via_length -= aValue;
202 }
203
204 int64_t GetViaDelay() const { return m_via_delay; }
205
206 void SetViaDelay( unsigned int aValue )
207 {
208 if( m_parent )
209 m_parent->SetViaDelay( m_parent->GetViaDelay() - m_via_delay + aValue );
210
212 m_via_delay = aValue;
213 }
214
215 void AddViaDelay( unsigned int aValue )
216 {
217 if( m_parent )
218 m_parent->AddViaDelay( aValue );
219
220 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
221 m_via_delay += aValue;
222 }
223
224 void SubViaDelay( int64_t aValue )
225 {
226 if( m_parent )
227 m_parent->SubViaDelay( aValue );
228
229 m_column_changed[COLUMN_VIA_LENGTH] |= ( aValue != 0 );
230 m_via_delay -= aValue;
231 }
232
233 int64_t GetBoardWireLength() const
234 {
235 int64_t retval = 0;
236
237 for( auto& [layer, length] : m_layer_wire_length )
238 retval += length;
239
240 return retval;
241 }
242
243 int64_t GetBoardWireDelay() const
244 {
245 int64_t retval = 0;
246
247 for( auto& [layer, delay] : m_layer_wire_delay )
248 retval += delay;
249
250 return retval;
251 }
252
253 int64_t GetLayerWireLength( PCB_LAYER_ID aLayer ) const
254 {
255 auto it = m_layer_wire_length.find( aLayer );
256 return it != m_layer_wire_length.end() ? it->second : 0;
257 }
258
259 int64_t GetLayerWireDelay( PCB_LAYER_ID aLayer ) const
260 {
261 auto it = m_layer_wire_delay.find( aLayer );
262 return it != m_layer_wire_delay.end() ? it->second : 0;
263 }
264
266
267 void SetLayerWireLength( const int64_t aValue, PCB_LAYER_ID aLayer )
268 {
269 auto it = m_layer_wire_length.find( aLayer );
270
271 wxCHECK_RET( it != m_layer_wire_length.end(), wxT( "Invalid layer specified" ) );
272
273 auto& [_, length] = *it;
274
275 if( m_parent )
276 {
277 m_parent->SetLayerWireLength( m_parent->GetBoardWireLength() - length + aValue,
278 aLayer );
279 }
280
281 m_column_changed[COLUMN_BOARD_LENGTH] |= ( length != aValue );
282 length = aValue;
283 }
284
285 std::map<PCB_LAYER_ID, int64_t> GetLayerWireLengths() const { return m_layer_wire_length; }
286
287 std::map<PCB_LAYER_ID, int64_t> GetLayerWireDelays() const { return m_layer_wire_delay; }
288
289 void SetLayerWireLengths( const std::map<PCB_LAYER_ID, int64_t>& aValue )
290 {
291 if( m_parent )
292 {
293 for( auto& [oldLayer, oldLength] : m_layer_wire_length )
294 m_parent->SubLayerWireLength( oldLength, oldLayer );
295
296 for( auto& [newLayer, newLength] : aValue )
297 m_parent->AddLayerWireLength( newLength, newLayer );
298 }
299
300 m_layer_wire_length = aValue;
301 }
302
303 void AddLayerWireLength( const int64_t aValue, PCB_LAYER_ID aLayer )
304 {
305 if( m_parent )
306 m_parent->AddLayerWireLength( aValue, aLayer );
307
309 m_layer_wire_length[aLayer] += aValue;
310 }
311
312 void SubLayerWireLength( const int64_t aValue, PCB_LAYER_ID aLayer )
313 {
314 if( m_parent )
315 m_parent->SubLayerWireLength( aValue, aLayer );
316
318 m_layer_wire_length[aLayer] -= aValue;
319 }
320
321 void SetLayerWireDelays( const std::map<PCB_LAYER_ID, int64_t>& aValue )
322 {
323 if( m_parent )
324 {
325 for( auto& [oldLayer, oldLength] : m_layer_wire_delay )
326 m_parent->SubLayerWireDelay( oldLength, oldLayer );
327
328 for( auto& [newLayer, newLength] : aValue )
329 m_parent->AddLayerWireDelay( newLength, newLayer );
330 }
331
332 m_layer_wire_delay = aValue;
333 }
334
335 void AddLayerWireDelay( const int64_t aValue, PCB_LAYER_ID aLayer )
336 {
337 if( m_parent )
338 m_parent->AddLayerWireDelay( aValue, aLayer );
339
341 m_layer_wire_delay[aLayer] += aValue;
342 }
343
344 void SubLayerWireDelay( const int64_t aValue, PCB_LAYER_ID aLayer )
345 {
346 if( m_parent )
347 m_parent->SubLayerWireDelay( aValue, aLayer );
348
350 m_layer_wire_delay[aLayer] -= aValue;
351 }
352
353 int64_t GetPadDieLength() const { return m_pad_die_length; }
354
356
357 void SetPadDieLength( int64_t aValue )
358 {
359 if( m_parent )
360 m_parent->SetPadDieLength( m_parent->GetPadDieLength() - m_pad_die_length + aValue );
361
363 m_pad_die_length = aValue;
364 }
365
366 void AddPadDieLength( int64_t aValue )
367 {
368 if( m_parent )
369 m_parent->AddPadDieLength( aValue );
370
371 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
372 m_pad_die_length += aValue;
373 }
374
375 void SubPadDieLength( int64_t aValue )
376 {
377 if( m_parent )
378 m_parent->SubPadDieLength( aValue );
379
380 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
381 m_pad_die_length -= aValue;
382 }
383
384 int64_t GetNetChainLength() const { return m_netChainLength; }
385
387
388 void SetNetChainLength( int64_t aValue )
389 {
391 m_netChainLength = aValue;
392 }
393
394 int64_t GetPadDieDelay() const { return m_pad_die_delay; }
395
396 void SetPadDieDelay( int64_t aValue )
397 {
398 if( m_parent )
399 m_parent->SetPadDieDelay( m_parent->GetPadDieDelay() - m_pad_die_delay + aValue );
400
402 m_pad_die_delay = aValue;
403 }
404
405 void AddPadDieDelay( int64_t aValue )
406 {
407 if( m_parent )
408 m_parent->AddPadDieDelay( aValue );
409
410 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
411 m_pad_die_delay += aValue;
412 }
413
414 void SubPadDieDelay( int64_t aValue )
415 {
416 if( m_parent )
417 m_parent->SubPadDieDelay( aValue );
418
419 m_column_changed[COLUMN_PAD_DIE_LENGTH] |= ( aValue != 0 );
420 m_pad_die_delay -= aValue;
421 }
422
423 // the total length column is always computed, never stored.
424 unsigned long long int GetTotalLength() const
425 {
427 }
428
429 unsigned long long int GetTotalDelay() const { return GetBoardWireDelay() + GetViaDelay() + GetPadDieDelay(); }
430
432 {
434 }
435
436 LIST_ITEM* Parent() const { return m_parent; }
437
438 void SetParent( LIST_ITEM* aParent )
439 {
440 if( m_parent == aParent )
441 return;
442
443 if( m_parent != nullptr )
444 {
445 m_parent->SubPadCount( GetPadCount() );
446 m_parent->SubViaCount( GetViaCount() );
447 m_parent->SubViaLength( GetViaLength() );
448 m_parent->SubViaDelay( GetViaDelay() );
449
450 for( auto& [layer, length] : m_layer_wire_length )
451 m_parent->SubLayerWireLength( length, layer );
452
453 for( auto& [layer, delay] : m_layer_wire_delay )
454 m_parent->SubLayerWireDelay( delay, layer );
455
456 m_parent->SubPadDieLength( GetPadDieLength() );
457 m_parent->SubPadDieDelay( GetPadDieDelay() );
458
459 m_parent->m_children.erase( std::find( m_parent->m_children.begin(),
460 m_parent->m_children.end(), this ) );
461 }
462
463 m_parent = aParent;
464
465 if( m_parent != nullptr )
466 {
467 m_parent->AddPadCount( GetPadCount() );
468 m_parent->AddViaCount( GetViaCount() );
469 m_parent->AddViaLength( GetViaLength() );
470 m_parent->AddViaDelay( GetViaDelay() );
471
472 for( auto& [layer, length] : m_layer_wire_length )
473 m_parent->AddLayerWireLength( length, layer );
474
475 for( auto& [layer, delay] : m_layer_wire_delay )
476 m_parent->AddLayerWireDelay( delay, layer );
477
478 m_parent->AddPadDieLength( GetPadDieLength() );
479 m_parent->AddPadDieDelay( GetPadDieDelay() );
480
481 m_parent->m_children.push_back( this );
482 }
483 }
484
485private:
486 LIST_ITEM* m_parent = nullptr;
487 std::vector<LIST_ITEM*> m_children;
488
490 unsigned int m_group_number = 0;
491 NETINFO_ITEM* m_net = nullptr;
492 unsigned int m_pad_count = 0;
493 unsigned int m_via_count = 0;
494 int64_t m_via_length = 0;
495 int64_t m_via_delay = 0;
496 int64_t m_pad_die_length = 0;
497 int64_t m_pad_die_delay = 0;
498 int64_t m_netChainLength = 0;
499
500 std::map<PCB_LAYER_ID, int64_t> m_layer_wire_length{};
501 std::map<PCB_LAYER_ID, int64_t> m_layer_wire_delay{};
502
503 // Dirty bits to record when some attribute has changed, in order to avoid unnecessary sort
504 // operations.
505 // The values are semantically bools, but STL auto-promotes a std::vector<bool> to a bitset,
506 // and then operator|= doesn't work.
507 std::vector<int> m_column_changed;
508
509 // cached formatted names for faster display sorting
510 wxString m_net_name;
511 wxString m_net_class;
513 wxString m_group_name;
514};
515
516
518{
519 template <typename T>
520 bool operator()( const T& a, const T& b ) const
521 {
522 return a->GetNetCode() < b->GetNetCode();
523 }
524
525 template <typename T>
526 bool operator()( const T& a, int b ) const
527 {
528 return a->GetNetCode() < b;
529 }
530
531 template <typename T>
532 bool operator()( int a, const T& b ) const
533 {
534 return a < b->GetNetCode();
535 }
536};
537
538
540{
541 template <typename T>
542 bool operator()( const T& a, const T& b ) const
543 {
544 return a->GetGroupNumber() < b->GetGroupNumber();
545 }
546
547 template <typename T>
548 bool operator()( const T& a, int b ) const
549 {
550 return a->GetGroupNumber() < b;
551 }
552
553 template <typename T>
554 bool operator()( int a, const T& b ) const
555 {
556 return a < b->GetGroupNumber();
557 }
558};
559
560
564class PCB_NET_INSPECTOR_PANEL::DATA_MODEL : public wxDataViewModel
565{
566public:
568 m_parent( parent )
569 {}
570
571 unsigned int columnCount() const { return m_parent.m_columns.size(); }
572
573 unsigned int itemCount() const { return m_items.size(); }
574
575 wxVariant valueAt( unsigned int aCol, unsigned int aRow ) const
576 {
577 wxVariant r;
578 GetValue( r, wxDataViewItem( const_cast<LIST_ITEM*>( &*( m_items[aRow] ) ) ), aCol );
579 return r;
580 }
581
582 const LIST_ITEM& itemAt( unsigned int aRow ) const { return *m_items.at( aRow ); }
583
584 wxVariant valueForItem( const LIST_ITEM* aItem, unsigned int aCol ) const
585 {
586 wxVariant r;
587 GetValue( r, wxDataViewItem( const_cast<LIST_ITEM*>( aItem ) ), aCol );
588 return r;
589 }
590
591 std::vector<std::pair<wxString, wxDataViewItem>> getGroupDataViewItems()
592 {
593 std::vector<std::pair<wxString, wxDataViewItem>> ret;
594
595 for( std::unique_ptr<LIST_ITEM>& item : m_items )
596 {
597 if( item->GetIsGroup() )
598 ret.push_back( std::make_pair( item->GetGroupName(), wxDataViewItem( item.get() ) ) );
599 }
600
601 return ret;
602 }
603
604 std::optional<LIST_ITEM_ITER> findItem( int aNetCode )
605 {
606 auto i = std::lower_bound( m_items.begin(), m_items.end(), aNetCode,
608
609 if( i == m_items.end() || ( *i )->GetNetCode() != aNetCode )
610 return std::nullopt;
611
612 return { i };
613 }
614
615 std::optional<LIST_ITEM_ITER> findItem( NETINFO_ITEM* aNet )
616 {
617 if( aNet != nullptr )
618 return findItem( aNet->GetNetCode() );
619 else
620 return std::nullopt;
621 }
622
623 std::optional<LIST_ITEM_ITER> findGroupItem( int aGroupNumber )
624 {
625 auto i = std::lower_bound( m_items.begin(), m_items.end(), aGroupNumber,
627
628 if( i == m_items.end() || ( *i )->GetGroupNumber() != aGroupNumber )
629 return std::nullopt;
630
631 return { i };
632 }
633
635 wxString groupName, LIST_ITEM::GROUP_TYPE groupType )
636 {
637 LIST_ITEM_ITER group = std::find_if( groupsBegin, groupsEnd,
638 [&]( const std::unique_ptr<LIST_ITEM>& x )
639 {
640 return x->GetGroupName() == groupName
641 && x->GetGroupType() == groupType;
642 } );
643
644 if( group == groupsEnd )
645 {
646 int dist = std::distance( groupsBegin, groupsEnd );
647 std::unique_ptr<LIST_ITEM> groupItem = std::make_unique<LIST_ITEM>( dist, groupName, groupType );
648
649 group = m_items.insert( groupsEnd, std::move( groupItem ) );
650 ItemAdded( wxDataViewItem( ( *group )->Parent() ), wxDataViewItem( ( *group ).get() ) );
651 }
652
653 return ( *group ).get();
654 }
655
656 std::optional<LIST_ITEM_ITER> addItem( std::unique_ptr<LIST_ITEM> aItem )
657 {
658 if( aItem == nullptr )
659 return {};
660
661 bool groupMatched = false;
662
663 // First see if item matches a group-by rule
664 if( m_parent.m_custom_group_rules.size() > 0 )
665 {
666 wxString searchName = aItem->GetNetName();
667
668 for( const std::unique_ptr<EDA_COMBINED_MATCHER>& rule : m_parent.m_custom_group_rules )
669 {
670 if( rule->Find( searchName ) )
671 {
672 aItem->SetParent( m_custom_group_map[ rule->GetPattern() ] );
673 groupMatched = true;
674 break;
675 }
676 }
677 }
678
679 // Then add any chain groups required by this item
680 if( m_parent.m_groupByNetChain && !groupMatched )
681 {
682 LIST_ITEM_ITER groups_begin = m_items.begin();
683 LIST_ITEM_ITER groups_end = std::find_if_not( m_items.begin(), m_items.end(),
684 []( const std::unique_ptr<LIST_ITEM>& x )
685 {
686 return x->GetIsGroup();
687 } );
688
689 wxString match_str = aItem->GetNetChainName();
690 LIST_ITEM* group = addGroup( groups_begin, groups_end, match_str,
692 aItem->SetParent( group );
693 groupMatched = true;
694 }
695
696 // Then add any netclass groups required by this item
697 if( m_parent.m_groupByNetclass && !groupMatched )
698 {
699 LIST_ITEM_ITER groups_begin = m_items.begin();
700 LIST_ITEM_ITER groups_end = std::find_if_not( m_items.begin(), m_items.end(),
701 []( const std::unique_ptr<LIST_ITEM>& x )
702 {
703 return x->GetIsGroup();
704 } );
705
706 wxString match_str = aItem->GetNetclassName();
707 LIST_ITEM* group = addGroup( groups_begin, groups_end, match_str, LIST_ITEM::GROUP_TYPE::NETCLASS );
708 aItem->SetParent( group );
709 groupMatched = true;
710 }
711
712 // Now add the item itself. Usually when new nets are added,
713 // they always get a higher netcode number than the already existing ones.
714 // however, if we've got filtering enabled, we might not have all the nets in
715 // our list, so do a sorted insertion.
716 auto new_iter = std::lower_bound( m_items.begin(), m_items.end(), aItem->GetNetCode(),
718
719 new_iter = m_items.insert( new_iter, std::move( aItem ) );
720 const std::unique_ptr<LIST_ITEM>& new_item = *new_iter;
721
722 ItemAdded( wxDataViewItem( new_item->Parent() ), wxDataViewItem( new_item.get() ) );
723
724 return { new_iter };
725 }
726
727 void addItems( std::vector<std::unique_ptr<LIST_ITEM>>& aItems )
728 {
729 m_items.reserve( m_items.size() + aItems.size() );
730
731 for( std::unique_ptr<LIST_ITEM>& i : aItems )
732 addItem( std::move( i ) );
733 }
734
735 std::unique_ptr<LIST_ITEM> deleteItem( const std::optional<LIST_ITEM_ITER>& aRow )
736 {
737 if( !aRow )
738 return {};
739
740 std::unique_ptr<LIST_ITEM> i = std::move( **aRow );
741
742 LIST_ITEM* parent = i->Parent();
743 i->SetParent( nullptr );
744
745 m_items.erase( *aRow );
746 ItemDeleted( wxDataViewItem( parent ), wxDataViewItem( &*i ) );
747
748 if( parent )
749 {
750 ItemChanged( wxDataViewItem( parent ) );
751
752 if( parent != nullptr && parent->ChildrenCount() == 0
753 && ( ( m_parent.m_groupByNetclass && parent->GetGroupType() == LIST_ITEM::GROUP_TYPE::NETCLASS )
754 || ( m_parent.m_groupByNetChain && parent->GetGroupType() == LIST_ITEM::GROUP_TYPE::NET_CHAIN ) ) )
755 {
756 auto p = std::find_if( m_items.begin(), m_items.end(),
757 [&]( std::unique_ptr<LIST_ITEM>& x )
758 {
759 return x.get() == parent;
760 } );
761
762 wxASSERT( p != m_items.end() );
763 m_items.erase( p );
764
765 ItemDeleted( wxDataViewItem( parent->Parent() ), wxDataViewItem( parent ) );
766 }
767 }
768
769 Resort();
770 return i;
771 }
772
779 {
780 m_custom_group_map.clear();
781 int groupId = 0;
782
783 for( const std::unique_ptr<EDA_COMBINED_MATCHER>& rule : m_parent.m_custom_group_rules )
784 {
785 std::unique_ptr<LIST_ITEM>& group = m_items.emplace_back( std::make_unique<LIST_ITEM>(
786 groupId, rule->GetPattern(), LIST_ITEM::GROUP_TYPE::USER_DEFINED ) );
787 m_custom_group_map[ rule->GetPattern() ] = group.get();
788 group->SetLayerCount( m_parent.m_board->GetCopperLayerCount() );
789 ItemAdded( wxDataViewItem( group->Parent() ), wxDataViewItem( group.get() ) );
790 ++groupId;
791 }
792 }
793
795 {
796 BeforeReset();
797 m_items.clear();
798 AfterReset();
799 }
800
801 void updateItem( const std::optional<LIST_ITEM_ITER>& aRow )
802 {
803 if( aRow )
804 {
805 const std::unique_ptr<LIST_ITEM>& listItem = *aRow.value();
806
807 if( listItem->Parent() )
808 ItemChanged( wxDataViewItem( listItem->Parent() ) );
809
810 ItemChanged( wxDataViewItem( listItem.get() ) );
811 resortIfChanged( listItem.get() );
812 }
813 }
814
816 {
817 for( std::unique_ptr<LIST_ITEM>& i : m_items )
818 ItemChanged( wxDataViewItem( i.get() ) );
819 }
820
822 {
823 if( wxDataViewColumn* column = m_parent.m_netsList->GetSortingColumn() )
824 {
825 bool changed = false;
826
827 for( const LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
828 changed |= itemColumnChanged( i, column->GetModelColumn() );
829
830 for( LIST_ITEM* i = aItem; i != nullptr; i = i->Parent() )
831 i->ResetColumnChangedBits();
832
833 if( changed )
834 Resort();
835 }
836 }
837
838 bool itemColumnChanged( const LIST_ITEM* aItem, unsigned int aCol ) const
839 {
840 if( aItem == nullptr || aCol >= m_parent.m_columns.size() )
841 return false;
842
843 if( aCol == COLUMN_PAD_COUNT )
844 return aItem->PadCountChanged();
845
846 else if( aCol == COLUMN_VIA_COUNT )
847 return aItem->ViaCountChanged();
848
849 else if( aCol == COLUMN_VIA_LENGTH )
850 return aItem->ViaLengthChanged();
851
852 else if( aCol == COLUMN_BOARD_LENGTH )
853 return aItem->BoardWireLengthChanged();
854
855 else if( aCol == COLUMN_PAD_DIE_LENGTH )
856 return aItem->PadDieLengthChanged();
857
858 else if( aCol == COLUMN_TOTAL_LENGTH )
859 return aItem->TotalLengthChanged();
860
861 else if( aCol > COLUMN_LAST_STATIC_COL )
862 return aItem->BoardWireLengthChanged();
863
864
865 return false;
866 }
867
868 void SetIsTimeDomain( const bool aIsTimeDomain ) { m_show_time_domain_details = aIsTimeDomain; }
869
870 // implementation of wxDataViewModel interface
871 // these are used to query the data model by the GUI view implementation.
872 // these are not supposed to be used to modify the data model. for that
873 // use the public functions above.
874
875protected:
876 unsigned int GetColumnCount() const override { return columnCount(); }
877
878 void GetValue( wxVariant& aOutValue, const wxDataViewItem& aItem,
879 unsigned int aCol ) const override
880 {
881 if( LIST_ITEM* i = static_cast<LIST_ITEM*>( aItem.GetID() ) )
882 {
883 if( aCol == COLUMN_NAME )
884 {
885 if( i->GetIsGroup() )
886 {
887 switch( i->GetGroupType() )
888 {
890 aOutValue = _( "Netclass" ) + ": " + i->GetGroupName();
891 break;
893 aOutValue = _( "Custom" ) + ": " + i->GetGroupName();
894 break;
895 default:
896 aOutValue = i->GetGroupName();
897 break;
898 }
899 }
900 else
901 {
902 aOutValue = i->GetNetName();
903 }
904 }
905 else if( aCol == COLUMN_NET_CHAIN )
906 {
907 wxString chainName = i->GetNetChainName();
908
909 // If the chain is assigned to a class, append it for visibility:
910 // "DDR_DQ0 [DDR_DATA]"
911 if( !chainName.IsEmpty() && m_parent.m_board )
912 {
913 if( const std::shared_ptr<NET_SETTINGS>& ns =
914 m_parent.m_board->GetDesignSettings().m_NetSettings )
915 {
916 wxString className = ns->GetNetChainClass( chainName );
917
918 if( !className.IsEmpty() )
919 chainName += wxString::Format( wxT( " [%s]" ), className );
920 }
921 }
922
923 aOutValue = chainName;
924 }
925 else if( aCol == COLUMN_NETCLASS )
926 {
927 aOutValue = i->GetNetclassName();
928 }
929 else if( aCol == COLUMN_PAD_COUNT )
930 {
931 aOutValue = m_parent.formatCount( i->GetPadCount() );
932 }
933 else if( aCol == COLUMN_VIA_COUNT )
934 {
935 aOutValue = m_parent.formatCount( i->GetViaCount() );
936 }
937 else if( aCol == COLUMN_VIA_LENGTH )
938 {
940 aOutValue = m_parent.formatDelay( i->GetViaDelay() );
941 else
942 aOutValue = m_parent.formatLength( i->GetViaLength() );
943 }
944 else if( aCol == COLUMN_BOARD_LENGTH )
945 {
947 aOutValue = m_parent.formatDelay( i->GetBoardWireDelay() );
948 else
949 aOutValue = m_parent.formatLength( i->GetBoardWireLength() );
950 }
951 else if( aCol == COLUMN_PAD_DIE_LENGTH )
952 {
954 aOutValue = m_parent.formatDelay( i->GetPadDieDelay() );
955 else
956 aOutValue = m_parent.formatLength( i->GetPadDieLength() );
957 }
958 else if( aCol == COLUMN_TOTAL_LENGTH )
959 {
961 aOutValue = m_parent.formatDelay( i->GetTotalDelay() );
962 else
963 aOutValue = m_parent.formatLength( i->GetTotalLength() );
964 }
965 else if( aCol == COLUMN_NET_CHAIN_LENGTH )
966 {
967 aOutValue = m_parent.formatLength( i->GetNetChainLength() );
968 }
969 else if( aCol > COLUMN_LAST_STATIC_COL && aCol <= m_parent.m_columns.size() )
970 {
972 aOutValue = m_parent.formatDelay( i->GetLayerWireDelay( m_parent.m_columns[aCol].layer ) );
973 else
974 aOutValue = m_parent.formatLength( i->GetLayerWireLength( m_parent.m_columns[aCol].layer ) );
975 }
976 else
977 {
978 aOutValue = "";
979 }
980 }
981 }
982
983 static int compareUInt( int64_t aValue1, int64_t aValue2, bool aAsc )
984 {
985 if( aAsc )
986 return aValue1 < aValue2 ? -1 : 1;
987 else
988 return aValue2 < aValue1 ? -1 : 1;
989 }
990
991 int Compare( const wxDataViewItem& aItem1, const wxDataViewItem& aItem2, unsigned int aCol,
992 bool aAsc ) const override
993 {
994 const LIST_ITEM& i1 = *static_cast<const LIST_ITEM*>( aItem1.GetID() );
995 const LIST_ITEM& i2 = *static_cast<const LIST_ITEM*>( aItem2.GetID() );
996
997 if( i1.GetIsGroup() && !i2.GetIsGroup() )
998 return -1;
999
1000 if( i2.GetIsGroup() && !i1.GetIsGroup() )
1001 return 1;
1002
1003 if( aCol == COLUMN_NAME )
1004 {
1005 const wxString& s1 = i1.GetNetName();
1006 const wxString& s2 = i2.GetNetName();
1007
1008 int res = aAsc ? ValueStringCompare( s1, s2 ) : ValueStringCompare( s2, s1 );
1009
1010 if( res != 0 )
1011 return res;
1012 }
1013 else if( aCol == COLUMN_NETCLASS )
1014 {
1015 const wxString& s1 = i1.GetNetclassName();
1016 const wxString& s2 = i2.GetNetclassName();
1017
1018 int res = aAsc ? ValueStringCompare( s1, s2 ) : ValueStringCompare( s2, s1 );
1019
1020 if( res != 0 )
1021 return res;
1022 }
1023 else if( aCol == COLUMN_NET_CHAIN )
1024 {
1025 const wxString& s1 = i1.GetNetChainName();
1026 const wxString& s2 = i2.GetNetChainName();
1027
1028 int res = aAsc ? ValueStringCompare( s1, s2 ) : ValueStringCompare( s2, s1 );
1029
1030 if( res != 0 )
1031 return res;
1032 }
1033 else if( aCol == COLUMN_PAD_COUNT && i1.GetPadCount() != i2.GetPadCount() )
1034 {
1035 return compareUInt( i1.GetPadCount(), i2.GetPadCount(), aAsc );
1036 }
1037 else if( aCol == COLUMN_VIA_COUNT && i1.GetViaCount() != i2.GetViaCount() )
1038 {
1039 return compareUInt( i1.GetViaCount(), i2.GetViaCount(), aAsc );
1040 }
1041 else if( aCol == COLUMN_VIA_LENGTH )
1042 {
1044 return compareUInt( i1.GetViaDelay(), i2.GetViaDelay(), aAsc );
1045
1047 return compareUInt( i1.GetViaLength(), i2.GetViaLength(), aAsc );
1048 }
1049 else if( aCol == COLUMN_BOARD_LENGTH )
1050 {
1052 return compareUInt( i1.GetBoardWireDelay(), i2.GetBoardWireDelay(), aAsc );
1053
1055 return compareUInt( i1.GetBoardWireLength(), i2.GetBoardWireLength(), aAsc );
1056 }
1057 else if( aCol == COLUMN_PAD_DIE_LENGTH )
1058 {
1060 return compareUInt( i1.GetPadDieDelay(), i2.GetPadDieDelay(), aAsc );
1061
1063 return compareUInt( i1.GetPadDieLength(), i2.GetPadDieLength(), aAsc );
1064 }
1065 else if( aCol == COLUMN_TOTAL_LENGTH )
1066 {
1068 return compareUInt( i1.GetTotalDelay(), i2.GetTotalDelay(), aAsc );
1069
1071 return compareUInt( i1.GetTotalLength(), i2.GetTotalLength(), aAsc );
1072 }
1073 else if( aCol == COLUMN_NET_CHAIN_LENGTH && i1.GetNetChainLength() != i2.GetNetChainLength() )
1074 {
1075 return compareUInt( i1.GetNetChainLength(), i2.GetNetChainLength(), aAsc );
1076 }
1077 else if( aCol > COLUMN_LAST_STATIC_COL && aCol < m_parent.m_columns.size() )
1078 {
1080 && i1.GetLayerWireDelay( m_parent.m_columns[aCol].layer )
1081 != i2.GetLayerWireDelay( m_parent.m_columns[aCol].layer ) )
1082 {
1083 return compareUInt( i1.GetLayerWireDelay( m_parent.m_columns[aCol].layer ),
1084 i2.GetLayerWireDelay( m_parent.m_columns[aCol].layer ), aAsc );
1085 }
1086
1088 && i1.GetLayerWireLength( m_parent.m_columns[aCol].layer )
1089 != i2.GetLayerWireLength( m_parent.m_columns[aCol].layer ) )
1090 {
1091 return compareUInt( i1.GetLayerWireLength( m_parent.m_columns[aCol].layer ),
1092 i2.GetLayerWireLength( m_parent.m_columns[aCol].layer ), aAsc );
1093 }
1094 }
1095
1096 // when the item values compare equal resort to pointer comparison.
1097 wxUIntPtr id1 = wxPtrToUInt( aItem1.GetID() );
1098 wxUIntPtr id2 = wxPtrToUInt( aItem2.GetID() );
1099
1100 return aAsc ? id1 - id2 : id2 - id1;
1101 }
1102
1103 bool SetValue( const wxVariant& aInValue, const wxDataViewItem& aItem,
1104 unsigned int aCol ) override
1105 {
1106 return false;
1107 }
1108
1109 wxDataViewItem GetParent( const wxDataViewItem& aItem ) const override
1110 {
1111 if( !aItem.IsOk() )
1112 return wxDataViewItem();
1113
1114 return wxDataViewItem( static_cast<const LIST_ITEM*>( aItem.GetID() )->Parent() );
1115 }
1116
1117 bool IsContainer( const wxDataViewItem& aItem ) const override
1118 {
1119 if( !aItem.IsOk() )
1120 return true;
1121
1122 return static_cast<const LIST_ITEM*>( aItem.GetID() )->GetIsGroup();
1123 }
1124
1125 bool HasContainerColumns( const wxDataViewItem& aItem ) const override
1126 {
1127 return IsContainer( aItem );
1128 }
1129
1130 unsigned int GetChildren( const wxDataViewItem& aParent,
1131 wxDataViewItemArray& aChildren ) const override
1132 {
1133 const LIST_ITEM* p = static_cast<const LIST_ITEM*>( aParent.GetID() );
1134
1135 if( !aParent.IsOk() )
1136 {
1137 aChildren.Alloc( m_items.size() );
1138
1139 for( const std::unique_ptr<LIST_ITEM>& i : m_items )
1140 {
1141 if( i->Parent() == nullptr )
1142 aChildren.Add( wxDataViewItem( &*i ) );
1143 }
1144
1145 return aChildren.GetCount();
1146 }
1147 else if( p->GetIsGroup() )
1148 {
1149 const int count = p->ChildrenCount();
1150
1151 if( count == 0 )
1152 return 0;
1153
1154 aChildren.Alloc( count );
1155
1156 for( auto i = p->ChildrenBegin(), end = p->ChildrenEnd(); i != end; ++i )
1157 aChildren.Add( wxDataViewItem( *i ) );
1158
1159 return aChildren.GetCount();
1160 }
1161
1162 return 0;
1163 }
1164
1165 wxString GetColumnType( unsigned int /* aCol */ ) const override { return wxS( "string" ); }
1166
1167private:
1169
1170 // primary container, sorted by netcode number.
1171 // groups have netcode < 0, so they always come first, in the order
1172 // of the filter strings as input by the user
1173 std::vector<std::unique_ptr<LIST_ITEM>> m_items;
1174
1176 std::map<wxString, LIST_ITEM*> m_custom_group_map;
1177
1179};
1180
1181#endif
const wxString GetHumanReadableName() const
Gets the consolidated name of this netclass (which may be an aggregate).
Definition netclass.cpp:294
Handle the data for a net.
Definition netinfo.h:50
const wxString & GetNetChain() const
Definition netinfo.h:115
const wxString & GetNetname() const
Definition netinfo.h:103
NETCLASS * GetNetClass()
Definition netinfo.h:95
int GetNetCode() const
Definition netinfo.h:97
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
static int compareUInt(int64_t aValue1, int64_t aValue2, bool aAsc)
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 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)
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
void addItems(std::vector< std::unique_ptr< LIST_ITEM > > &aItems)
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
wxVariant valueForItem(const LIST_ITEM *aItem, unsigned int aCol) const
const LIST_ITEM & itemAt(unsigned int aRow) const
void updateItem(const std::optional< LIST_ITEM_ITER > &aRow)
LIST_ITEM * 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)
std::map< PCB_LAYER_ID, int64_t > m_layer_wire_length
void AddLayerWireDelay(const int64_t aValue, PCB_LAYER_ID aLayer)
void SetLayerWireLengths(const std::map< PCB_LAYER_ID, int64_t > &aValue)
void AddLayerWireLength(const int64_t aValue, PCB_LAYER_ID aLayer)
std::map< PCB_LAYER_ID, int64_t > m_layer_wire_delay
LIST_ITEM & operator=(const LIST_ITEM &)=delete
int64_t GetLayerWireDelay(PCB_LAYER_ID aLayer) const
std::map< PCB_LAYER_ID, int64_t > GetLayerWireDelays() const
std::map< PCB_LAYER_ID, int64_t > GetLayerWireLengths() const
int64_t GetLayerWireLength(PCB_LAYER_ID aLayer) const
void SetLayerWireLength(const int64_t aValue, PCB_LAYER_ID aLayer)
void SubLayerWireDelay(const int64_t aValue, PCB_LAYER_ID aLayer)
void SetLayerWireDelays(const std::map< PCB_LAYER_ID, int64_t > &aValue)
void SubLayerWireLength(const int64_t aValue, PCB_LAYER_ID aLayer)
PCB_NET_INSPECTOR_PANEL(wxWindow *parent, PCB_EDIT_FRAME *aFrame)
std::vector< std::unique_ptr< LIST_ITEM > >::iterator LIST_ITEM_ITER
#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
VECTOR2I end