20#ifndef PCB_NET_INSPECTOR_PANEL_DATA_MODEL
21#define PCB_NET_INSPECTOR_PANEL_DATA_MODEL
25#include <wx/settings.h>
277 auto& [
_, length] = *it;
281 m_parent->SetLayerWireLength(
m_parent->GetBoardWireLength() - length + aValue,
298 m_parent->SubLayerWireLength( oldLength, oldLayer );
300 for(
auto& [newLayer, newLength] : aValue )
301 m_parent->AddLayerWireLength( newLength, newLayer );
310 m_parent->AddLayerWireLength( aValue, aLayer );
319 m_parent->SubLayerWireLength( aValue, aLayer );
330 m_parent->SubLayerWireDelay( oldLength, oldLayer );
332 for(
auto& [newLayer, newLength] : aValue )
333 m_parent->AddLayerWireDelay( newLength, newLayer );
342 m_parent->AddLayerWireDelay( aValue, aLayer );
351 m_parent->SubLayerWireDelay( aValue, aLayer );
373 m_parent->AddPadDieLength( aValue );
382 m_parent->SubPadDieLength( aValue );
451 m_parent->AddUnroutedLength( aValue );
460 m_parent->SubUnroutedLength( aValue );
494 m_parent->SubLayerWireLength( length, layer );
497 m_parent->SubLayerWireDelay( delay, layer );
504 m_parent->m_children.end(),
this ) );
517 m_parent->AddLayerWireLength( length, layer );
520 m_parent->AddLayerWireDelay( delay, layer );
526 m_parent->m_children.push_back(
this );
566 template <
typename T>
569 return a->GetNetCode() < b->GetNetCode();
572 template <
typename T>
575 return a->GetNetCode() < b;
578 template <
typename T>
581 return a < b->GetNetCode();
588 template <
typename T>
591 return a->GetGroupNumber() < b->GetGroupNumber();
594 template <
typename T>
597 return a->GetGroupNumber() < b;
600 template <
typename T>
603 return a < b->GetGroupNumber();
622 wxVariant
valueAt(
unsigned int aCol,
unsigned int aRow )
const
640 std::vector<std::pair<wxString, wxDataViewItem>> ret;
642 for( std::unique_ptr<LIST_ITEM>& item :
m_items )
644 if( item->GetIsGroup() )
645 ret.push_back( std::make_pair( item->GetGroupName(), wxDataViewItem( item.get() ) ) );
651 std::optional<LIST_ITEM_ITER>
findItem(
int aNetCode )
653 auto i = std::lower_bound(
m_items.begin(),
m_items.end(), aNetCode,
656 if( i ==
m_items.end() || ( *i )->GetNetCode() != aNetCode )
664 if( aNet !=
nullptr )
672 auto i = std::lower_bound(
m_items.begin(),
m_items.end(), aGroupNumber,
675 if( i ==
m_items.end() || ( *i )->GetGroupNumber() != aGroupNumber )
685 [&](
const std::unique_ptr<LIST_ITEM>& x )
687 return x->GetGroupName() == groupName
688 && x->GetGroupType() == groupType;
691 if(
group == groupsEnd )
693 int dist = std::distance( groupsBegin, groupsEnd );
694 std::unique_ptr<LIST_ITEM> groupItem = std::make_unique<LIST_ITEM>( dist, groupName, groupType );
696 group =
m_items.insert( groupsEnd, std::move( groupItem ) );
697 ItemAdded( wxDataViewItem( ( *group )->Parent() ), wxDataViewItem( ( *group ).get() ) );
700 return ( *group ).get();
703 std::optional<LIST_ITEM_ITER>
addItem( std::unique_ptr<LIST_ITEM> aItem )
705 if( aItem ==
nullptr )
708 bool groupMatched =
false;
711 if(
m_parent.m_custom_group_rules.size() > 0 )
713 wxString searchName = aItem->GetNetName();
715 for(
const std::unique_ptr<EDA_COMBINED_MATCHER>& rule :
m_parent.m_custom_group_rules )
717 if( rule->Find( searchName ) )
727 if(
m_parent.m_groupByNetChain && !groupMatched )
731 [](
const std::unique_ptr<LIST_ITEM>& x )
733 return x->GetIsGroup();
736 wxString match_str = aItem->GetNetChainName();
739 aItem->SetParent(
group );
744 if(
m_parent.m_groupByNetclass && !groupMatched )
748 [](
const std::unique_ptr<LIST_ITEM>& x )
750 return x->GetIsGroup();
753 wxString match_str = aItem->GetNetclassName();
755 aItem->SetParent(
group );
763 auto new_iter = std::lower_bound(
m_items.begin(),
m_items.end(), aItem->GetNetCode(),
766 new_iter =
m_items.insert( new_iter, std::move( aItem ) );
767 const std::unique_ptr<LIST_ITEM>& new_item = *new_iter;
769 ItemAdded( wxDataViewItem( new_item->Parent() ), wxDataViewItem( new_item.get() ) );
774 void addItems( std::vector<std::unique_ptr<LIST_ITEM>>& aItems )
778 for( std::unique_ptr<LIST_ITEM>& i : aItems )
782 std::unique_ptr<LIST_ITEM>
deleteItem(
const std::optional<LIST_ITEM_ITER>& aRow )
787 std::unique_ptr<LIST_ITEM> i = std::move( **aRow );
790 i->SetParent(
nullptr );
793 ItemDeleted( wxDataViewItem( parent ), wxDataViewItem( &*i ) );
797 ItemChanged( wxDataViewItem( parent ) );
804 [&]( std::unique_ptr<LIST_ITEM>& x )
806 return x.get() == parent;
809 wxASSERT( p !=
m_items.end() );
813 wxDataViewItem grandParent( parent->
Parent() );
814 std::unique_ptr<LIST_ITEM> removedParent = std::move( *p );
817 ItemDeleted( grandParent, wxDataViewItem( removedParent.get() ) );
835 for(
const std::unique_ptr<EDA_COMBINED_MATCHER>& rule :
m_parent.m_custom_group_rules )
837 std::unique_ptr<LIST_ITEM>&
group =
m_items.emplace_back( std::make_unique<LIST_ITEM>(
840 group->SetLayerCount(
m_parent.m_board->GetCopperLayerCount() );
841 ItemAdded( wxDataViewItem(
group->Parent() ), wxDataViewItem(
group.get() ) );
859 const std::unique_ptr<LIST_ITEM>& listItem = *aRow.value();
861 if( listItem->Parent() )
862 ItemChanged( wxDataViewItem( listItem->Parent() ) );
864 ItemChanged( wxDataViewItem( listItem.get() ) );
871 for( std::unique_ptr<LIST_ITEM>& i :
m_items )
872 ItemChanged( wxDataViewItem( i.get() ) );
877 if( wxDataViewColumn* column =
m_parent.m_netsList->GetSortingColumn() )
879 bool changed =
false;
885 i->ResetColumnChangedBits();
894 if( aItem ==
nullptr || aCol >=
m_parent.m_columns.size() )
935 void GetValue( wxVariant& aOutValue,
const wxDataViewItem& aItem,
936 unsigned int aCol )
const override
942 if( i->GetIsGroup() )
944 switch( i->GetGroupType() )
947 aOutValue =
_(
"Netclass" ) +
": " + i->GetGroupName();
950 aOutValue =
_(
"Custom" ) +
": " + i->GetGroupName();
953 aOutValue = i->GetGroupName();
959 aOutValue = i->GetNetName();
964 wxString chainName = i->GetNetChainName();
968 if( !chainName.IsEmpty() &&
m_parent.m_board )
970 if(
const std::shared_ptr<NET_SETTINGS>& ns =
971 m_parent.m_board->GetDesignSettings().m_NetSettings )
973 wxString className = ns->GetNetChainClass( chainName );
975 if( !className.IsEmpty() )
976 chainName += wxString::Format( wxT(
" [%s]" ), className );
980 aOutValue = chainName;
984 aOutValue = i->GetNetclassName();
988 aOutValue =
m_parent.formatCount( i->GetPadCount() );
992 aOutValue =
m_parent.formatCount( i->GetViaCount() );
997 aOutValue =
m_parent.formatDelay( i->GetViaDelay() );
999 aOutValue =
m_parent.formatLength( i->GetViaLength() );
1004 aOutValue =
m_parent.formatDelay( i->GetBoardWireDelay() );
1006 aOutValue =
m_parent.formatLength( i->GetBoardWireLength() );
1011 aOutValue =
m_parent.formatDelay( i->GetPadDieDelay() );
1013 aOutValue =
m_parent.formatLength( i->GetPadDieLength() );
1017 aOutValue =
m_parent.formatLength( i->GetUnroutedLength() );
1022 aOutValue =
m_parent.formatDelay( i->GetTotalDelay() );
1024 aOutValue =
m_parent.formatLength( i->GetTotalLength() );
1028 if( i->GetNetChainName().IsEmpty() )
1031 aOutValue =
m_parent.formatDelay( i->GetNetChainDelay() );
1033 aOutValue =
m_parent.formatLength( i->GetNetChainLength() );
1038 aOutValue =
m_parent.formatDelay( i->GetLayerWireDelay(
m_parent.m_columns[aCol].layer ) );
1040 aOutValue =
m_parent.formatLength( i->GetLayerWireLength(
m_parent.m_columns[aCol].layer ) );
1049 bool GetAttr(
const wxDataViewItem& aItem,
unsigned int aCol, wxDataViewItemAttr& aAttr )
const override
1051 if( !aItem.IsOk() || aCol >=
m_parent.m_columns.size() )
1056 if(
const auto zeroValued =
isZeroValued( item, aCol ); zeroValued.has_value() )
1058 if( zeroValued.value() )
1060 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
1071 return aValue1 < aValue2 ? -1 : 1;
1073 return aValue2 < aValue1 ? -1 : 1;
1076 int Compare(
const wxDataViewItem& aItem1,
const wxDataViewItem& aItem2,
unsigned int aCol,
1077 bool aAsc )
const override
1079 const auto compareNetNames =
1083 const wxString& s2 = i2.GetNetName();
1099 int res = compareNetNames( i1, i2 );
1199 int res = compareNetNames( i1, i2 );
1207 wxUIntPtr id1 = wxPtrToUInt( aItem1.GetID() );
1208 wxUIntPtr id2 = wxPtrToUInt( aItem2.GetID() );
1210 return aAsc ? id1 - id2 : id2 - id1;
1213 bool SetValue(
const wxVariant& aInValue,
const wxDataViewItem& aItem,
1214 unsigned int aCol )
override
1219 wxDataViewItem
GetParent(
const wxDataViewItem& aItem )
const override
1222 return wxDataViewItem();
1224 return wxDataViewItem(
static_cast<const LIST_ITEM*
>( aItem.GetID() )->
Parent() );
1241 wxDataViewItemArray& aChildren )
const override
1245 if( !aParent.IsOk() )
1247 aChildren.Alloc(
m_items.size() );
1249 for(
const std::unique_ptr<LIST_ITEM>& i :
m_items )
1251 if( i->Parent() ==
nullptr )
1252 aChildren.Add( wxDataViewItem( &*i ) );
1255 return aChildren.GetCount();
1264 aChildren.Alloc( count );
1267 aChildren.Add( wxDataViewItem( *i ) );
1269 return aChildren.GetCount();
1275 wxString
GetColumnType(
unsigned int )
const override {
return wxS(
"string" ); }
1373 return std::nullopt;
const wxString GetHumanReadableName() const
Gets the consolidated name of this netclass (which may be an aggregate).
Handle the data for a net.
const wxString & GetNetChain() const
const wxString & GetNetname() const
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
static int compareUInt(int64_t aValue1, int64_t aValue2, bool aAsc)
bool GetAttr(const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
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
std::optional< bool > isZeroValued(const LIST_ITEM &aItem, unsigned int aCol) const
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
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
void addItems(std::vector< std::unique_ptr< LIST_ITEM > > &aItems)
DATA_MODEL(PCB_NET_INSPECTOR_PANEL &parent)
int Compare(const wxDataViewItem &aItem1, const wxDataViewItem &aItem2, unsigned int aCol, bool aAsc) const override
void SetIsTimeDomain(const bool aIsTimeDomain)
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)
bool m_show_time_domain_details
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.
void AddViaCount(unsigned int aValue)
bool NetChainLengthChanged() const
void SetNetChainDelay(int64_t aValue)
int64_t GetUnroutedLength() const
void SetLayerCount(unsigned int aValue)
bool PadCountChanged() const
LIST_ITEM(unsigned int aGroupNumber, const wxString &aGroupName, GROUP_TYPE aGroupType)
std::map< PCB_LAYER_ID, int64_t > m_layer_wire_length
void SetPadCount(unsigned int aValue)
void SetPadDieLength(int64_t aValue)
bool NetChainNameChanged() const
auto ChildrenBegin() const
unsigned long long int GetTotalDelay() const
unsigned int ChildrenCount() const
void SetNetChainLength(int64_t aValue)
void AddViaDelay(unsigned int aValue)
void AddLayerWireDelay(const int64_t aValue, PCB_LAYER_ID aLayer)
void SubViaCount(unsigned int aValue)
unsigned GetViaCount() const
std::vector< LIST_ITEM * > m_children
void SubPadDieDelay(int64_t aValue)
void SubViaDelay(int64_t aValue)
void SetLayerWireLengths(const std::map< PCB_LAYER_ID, int64_t > &aValue)
void SetViaCount(unsigned int aValue)
void ResetColumnChangedBits()
int64_t GetNetChainDelay() const
void AddUnroutedLength(int64_t aValue)
void SetUnroutedLength(int64_t aValue)
int64_t m_unrouted_length
LIST_ITEM * Parent() const
int64_t GetViaLength() const
void SubUnroutedLength(int64_t aValue)
void AddPadDieDelay(int64_t aValue)
bool BoardWireLengthChanged() const
const wxString & GetNetclassName() const
unsigned int GetPadCount() const
int64_t GetBoardWireLength() const
void AddLayerWireLength(const int64_t aValue, PCB_LAYER_ID aLayer)
void SetViaLength(unsigned int aValue)
void AddPadDieLength(int64_t aValue)
void SetViaDelay(unsigned int aValue)
int64_t GetViaDelay() const
unsigned long long int GetTotalLength() const
int64_t GetPadDieLength() const
void SetParent(LIST_ITEM *aParent)
int GetGroupNumber() const
std::map< PCB_LAYER_ID, int64_t > m_layer_wire_delay
bool ViaCountChanged() const
LIST_ITEM & operator=(const LIST_ITEM &)=delete
const wxString & GetGroupName() const
std::vector< int > m_column_changed
int64_t GetBoardWireDelay() const
LIST_ITEM(NETINFO_ITEM *aNet)
int64_t GetPadDieDelay() const
int64_t GetLayerWireDelay(PCB_LAYER_ID aLayer) const
const wxString & GetNetName() const
bool ViaLengthChanged() const
std::map< PCB_LAYER_ID, int64_t > GetLayerWireDelays() const
unsigned int m_group_number
std::map< PCB_LAYER_ID, int64_t > GetLayerWireLengths() const
int64_t GetNetChainLength() const
bool PadDieLengthChanged() const
void SubViaLength(int64_t aValue)
const wxString & GetNetChainName() const
NETINFO_ITEM * GetNet() const
void SubPadDieLength(int64_t aValue)
void AddPadCount(unsigned int aValue)
int64_t GetLayerWireLength(PCB_LAYER_ID aLayer) const
void SetLayerWireLength(const int64_t aValue, PCB_LAYER_ID aLayer)
bool TotalLengthChanged() const
GROUP_TYPE GetGroupType() const
void SetPadDieDelay(int64_t aValue)
void AddViaLength(unsigned int aValue)
void SubPadCount(unsigned int aValue)
void SubLayerWireDelay(const int64_t aValue, PCB_LAYER_ID aLayer)
void SetLayerWireDelays(const std::map< PCB_LAYER_ID, int64_t > &aValue)
bool UnroutedLengthChanged() const
void SetNetChainName(const wxString &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
@ COLUMN_NET_CHAIN_LENGTH
Abstract pattern-matching tool and implementations.
PCB_LAYER_ID
A quick note on layer IDs:
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