20#ifndef PCB_NET_INSPECTOR_PANEL_DATA_MODEL
21#define PCB_NET_INSPECTOR_PANEL_DATA_MODEL
333 template <
typename T>
336 return a->GetNetCode() < b->GetNetCode();
339 template <
typename T>
342 return a->GetNetCode() < b;
345 template <
typename T>
348 return a < b->GetNetCode();
355 template <
typename T>
358 return a->GetGroupNumber() < b->GetGroupNumber();
361 template <
typename T>
364 return a->GetGroupNumber() < b;
367 template <
typename T>
370 return a < b->GetGroupNumber();
387 wxVariant
valueAt(
unsigned int aCol,
unsigned int aRow )
const
398 std::vector<std::pair<wxString, wxDataViewItem>> ret;
400 for( std::unique_ptr<LIST_ITEM>& item :
m_items )
402 if( item->GetIsGroup() )
404 std::make_pair( item->GetGroupName(), wxDataViewItem( item.get() ) ) );
411 std::optional<LIST_ITEM_ITER>
findItem(
int aNetCode )
413 auto i = std::lower_bound(
m_items.begin(),
m_items.end(), aNetCode,
416 if( i ==
m_items.end() || ( *i )->GetNetCode() != aNetCode )
425 if( aNet !=
nullptr )
434 auto i = std::lower_bound(
m_items.begin(),
m_items.end(), aGroupNumber,
437 if( i ==
m_items.end() || ( *i )->GetGroupNumber() != aGroupNumber )
448 [&](
const std::unique_ptr<LIST_ITEM>& x )
450 return x->GetGroupName() == groupName
451 && x->GetGroupType() == groupType;
454 if(
group == groupsEnd )
456 int dist = std::distance( groupsBegin, groupsEnd );
457 std::unique_ptr<LIST_ITEM> groupItem =
458 std::make_unique<LIST_ITEM>( dist, groupName, groupType );
459 group =
m_items.insert( groupsEnd, std::move( groupItem ) );
460 ItemAdded( wxDataViewItem( ( *group )->Parent() ), wxDataViewItem( &**
group ) );
467 std::optional<LIST_ITEM_ITER>
addItem( std::unique_ptr<LIST_ITEM> aItem )
469 if( aItem ==
nullptr )
472 bool groupMatched =
false;
477 wxString searchName = aItem->GetNetName().Upper();
481 if( searchName.Find( groupName.Upper() ) != wxNOT_FOUND )
495 [](
const std::unique_ptr<LIST_ITEM>& x )
497 return x->GetIsGroup();
500 wxString match_str = aItem->GetNetclassName();
503 aItem->SetParent( &**
group );
510 auto new_iter = std::lower_bound(
m_items.begin(),
m_items.end(), aItem->GetNetCode(),
513 new_iter =
m_items.insert( new_iter, std::move( aItem ) );
514 const std::unique_ptr<LIST_ITEM>& new_item = *new_iter;
516 ItemAdded( wxDataViewItem( new_item->Parent() ), wxDataViewItem( new_item.get() ) );
521 void addItems( std::vector<std::unique_ptr<LIST_ITEM>> aItems )
525 for( std::unique_ptr<LIST_ITEM>& i : aItems )
529 std::unique_ptr<LIST_ITEM>
deleteItem(
const std::optional<LIST_ITEM_ITER>& aRow )
534 std::unique_ptr<LIST_ITEM> i = std::move( **aRow );
540 ItemDeleted( wxDataViewItem( parent ), wxDataViewItem( &*i ) );
544 ItemChanged( wxDataViewItem( parent ) );
549 [&]( std::unique_ptr<LIST_ITEM>& x )
551 return x.get() == parent;
554 wxASSERT( p !=
m_items.end() );
557 ItemDeleted( wxDataViewItem( parent->
Parent() ), wxDataViewItem( parent ) );
578 std::unique_ptr<LIST_ITEM>&
group =
m_items.emplace_back( std::make_unique<LIST_ITEM>(
581 ItemAdded( wxDataViewItem(
group->Parent() ), wxDataViewItem(
group.get() ) );
598 const std::unique_ptr<LIST_ITEM>& listItem = *aRow.value();
600 if( listItem->Parent() )
601 ItemChanged( wxDataViewItem( listItem->Parent() ) );
603 ItemChanged( wxDataViewItem( listItem.get() ) );
610 for( std::unique_ptr<LIST_ITEM>& i :
m_items )
611 ItemChanged( wxDataViewItem( i.get() ) );
618 bool changed =
false;
624 i->ResetColumnChangedBits();
669 void GetValue( wxVariant& aOutValue,
const wxDataViewItem& aItem,
670 unsigned int aCol )
const override
674 if( i->GetIsGroup() )
677 switch( i->GetGroupType() )
680 aOutValue =
_(
"Netclass" ) +
": " + i->GetGroupName();
683 aOutValue =
_(
"Custom" ) +
": " + i->GetGroupName();
685 default: aOutValue = i->GetGroupName();
break;
693 aOutValue = i->GetNetName();
696 aOutValue = i->GetNetclassName();
725 static int compareUInt( uint64_t aValue1, uint64_t aValue2,
bool aAsc )
728 return aValue1 < aValue2 ? -1 : 1;
730 return aValue2 < aValue1 ? -1 : 1;
733 int Compare(
const wxDataViewItem& aItem1,
const wxDataViewItem& aItem2,
unsigned int aCol,
734 bool aAsc )
const override
783 wxUIntPtr id1 = wxPtrToUInt( aItem1.GetID() );
784 wxUIntPtr id2 = wxPtrToUInt( aItem2.GetID() );
786 return aAsc ? id1 - id2 : id2 - id1;
789 bool SetValue(
const wxVariant& aInValue,
const wxDataViewItem& aItem,
790 unsigned int aCol )
override
795 wxDataViewItem
GetParent(
const wxDataViewItem& aItem )
const override
798 return wxDataViewItem();
800 return wxDataViewItem(
static_cast<const LIST_ITEM*
>( aItem.GetID() )->
Parent() );
808 return static_cast<const LIST_ITEM*
>( aItem.GetID() )->GetIsGroup();
817 wxDataViewItemArray& aChildren )
const override
821 if( !aParent.IsOk() )
823 aChildren.Alloc(
m_items.size() );
825 for(
const std::unique_ptr<LIST_ITEM>& i :
m_items )
827 if( i->Parent() == nullptr )
828 aChildren.Add( wxDataViewItem( &*i ) );
831 return aChildren.GetCount();
840 aChildren.Alloc( count );
843 aChildren.Add( wxDataViewItem( *i ) );
845 return aChildren.GetCount();
851 wxString
GetColumnType(
unsigned int )
const override {
return wxS(
"string" ); }
859 std::vector<std::unique_ptr<LIST_ITEM>>
m_items;
A collection of nets and the parameters used to route or test these nets.
const wxString GetName() const
Handle the data for a net.
const wxString & GetNetname() const
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
void resortIfChanged(LIST_ITEM *aItem)
bool itemColumnChanged(const LIST_ITEM *aItem, unsigned int aCol) const
void addCustomGroups()
Adds all custom group-by entries to the items table.
unsigned int GetColumnCount() const override
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
PCB_NET_INSPECTOR_PANEL & m_parent
std::optional< LIST_ITEM_ITER > findItem(int aNetCode)
unsigned int itemCount() const
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
unsigned int columnCount() const
DATA_MODEL(PCB_NET_INSPECTOR_PANEL &parent)
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.
void AddViaCount(unsigned int aValue)
bool PadCountChanged() const
LIST_ITEM(unsigned int aGroupNumber, const wxString &aGroupName, GROUP_TYPE aGroupType)
void SetPadCount(unsigned int aValue)
auto ChildrenBegin() const
unsigned int ChildrenCount() const
void SubViaCount(unsigned int aValue)
unsigned GetViaCount() const
std::vector< LIST_ITEM * > m_children
void SetViaCount(unsigned int aValue)
uint64_t GetPadDieLength() const
void ResetColumnChangedBits()
uint64_t GetLayerWireLength(size_t aLayer) const
LIST_ITEM * Parent() const
uint64_t m_pad_die_length
bool BoardWireLengthChanged() const
const wxString & GetNetclassName() const
unsigned int GetPadCount() const
void SetViaLength(unsigned int aValue)
void SubLayerWireLength(const uint64_t aValue, size_t aLayer)
uint64_t GetViaLength() const
uint64_t GetBoardWireLength() const
void SubViaLength(uint64_t aValue)
unsigned long long int GetTotalLength() const
void SetParent(LIST_ITEM *aParent)
int GetGroupNumber() const
bool ViaCountChanged() const
LIST_ITEM & operator=(const LIST_ITEM &)=delete
void AddPadDieLength(uint64_t aValue)
const wxString & GetGroupName() const
std::vector< int > m_column_changed
void SetLayerWireLength(const uint64_t aValue, size_t aLayer)
LIST_ITEM(NETINFO_ITEM *aNet)
const wxString & GetNetName() const
void AddLayerWireLength(const uint64_t aValue, size_t aLayer)
bool ViaLengthChanged() const
unsigned int m_group_number
bool PadDieLengthChanged() const
NETINFO_ITEM * GetNet() const
void AddPadCount(unsigned int aValue)
void SetPadDieLength(uint64_t aValue)
bool TotalLengthChanged() const
GROUP_TYPE GetGroupType() const
void AddViaLength(unsigned int aValue)
void SubPadCount(unsigned int aValue)
void SubPadDieLength(uint64_t aValue)
std::array< uint64_t, MAX_CU_LAYERS > m_layer_wire_length
Net inspection panel for pcbnew.
std::vector< std::unique_ptr< LIST_ITEM > >::iterator LIST_ITEM_ITER
std::vector< wxString > m_custom_group_rules
wxString formatCount(unsigned int aValue) const
wxString formatLength(int64_t aValue) const
std::vector< COLUMN_DESC > m_columns
All displayed (or hidden) columns.
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...
bool operator()(const T &a, const T &b) const
bool operator()(const T &a, int b) const
bool operator()(int a, const T &b) const
bool operator()(const T &a, const T &b) const
bool operator()(int a, const T &b) const
bool operator()(const T &a, int b) const