35#include <unordered_map>
56 NETNAMES_MAP::iterator it, itEnd;
78 return (*result).second;
89 return (*result).second;
101 if ( i->second == aNet )
111 if ( i->second == aNet )
113 wxASSERT_MSG( removed, wxT(
"NETINFO_LIST::RemoveNet: target net found in m_netNames "
114 "but not m_netCodes!" ) );
131 std::vector<NETINFO_ITEM*> unusedNets;
136 for(
const auto& [ netCode, netInfo ] : existingNets )
138 if( netInfo->IsCurrent() )
140 m_netNames.insert( std::make_pair( netInfo->GetNetname(), netInfo ) );
141 m_netCodes.insert( std::make_pair( netCode, netInfo ) );
159 if( sameName !=
nullptr )
190 std::unordered_map<int, wxString> preservedNetChains;
191 std::unordered_map<int, KIID> preservedPad0;
192 std::unordered_map<int, KIID> preservedPad1;
211 auto it = preservedNetChains.find( net->
GetNetCode() );
212 if( it != preservedNetChains.end() )
215 auto ip0 = preservedPad0.find( net->
GetNetCode() );
216 if( ip0 != preservedPad0.end() )
219 auto ip1 = preservedPad1.find( net->
GetNetCode() );
220 if( ip1 != preservedPad1.end() )
224 m_parent->SynchronizeNetsAndNetClasses(
false );
225 m_parent->SetAreasNetCodesFromNetNames();
231 std::map<wxString, std::vector<wxString>> shortNameMap;
244 wxArrayString parts = wxSplit( net->
m_netname,
'/' );
245 std::vector<wxArrayString> aggregateParts;
246 std::optional<size_t> firstNonCommon;
248 for(
const wxString& longName : shortNameMap[net->
m_shortNetname] )
249 aggregateParts.push_back( wxSplit( longName,
'/' ) );
251 for(
size_t ii = 0; ii < parts.size() && !firstNonCommon; ++ii )
253 for(
const wxArrayString& otherParts : aggregateParts )
255 if( ii < otherParts.size() && otherParts[ii] == parts[ii] )
263 if( firstNonCommon.value_or( 0 ) > 0 && firstNonCommon.value() < parts.size() )
265 wxString disambiguatedName;
267 for(
size_t ii = firstNonCommon.value(); ii < parts.size(); ++ii )
269 if( !disambiguatedName.IsEmpty() )
270 disambiguatedName += wxS(
"/" );
272 disambiguatedName += parts[ii];
289void NETINFO_LIST::Show()
const
292 NETNAMES_MAP::const_iterator it, itEnd;
296 wxLogDebug( wxT(
"[%d]: netcode:%d netname:<%s>\n" ),
298 it->second->GetNetCode(),
299 TO_UTF8( it->second->GetNetname() ) );
319 if( aNewNames.empty() )
324 std::vector<std::pair<NETINFO_ITEM*, wxString>> renames;
327 for(
const auto& [source, target] : aNewNames )
342 if( net->
GetNetCode() <= 0 || target.IsEmpty() )
344 aReporter.
Report( wxString::Format(
_(
"Cannot rename net '%s' to '%s': net zero and empty "
345 "names are reserved for unconnected items." ),
350 if( source == target )
353 renames.emplace_back( net, target );
354 finalNames.erase( source );
358 renames.size(), aNewNames.size(), missing );
360 if( renames.empty() )
363 for(
const auto& [net, target] : renames )
365 if( !finalNames.emplace( target, net ).second )
367 aReporter.
Report( wxString::Format(
_(
"Cannot rename net '%s' to '%s': another net would "
368 "have the same name." ),
375 for(
const auto& [net, target] : renames )
376 net->SetNetname( target );
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Handle the data for a net.
wxString m_shortNetname
Short net name, like vout from /sheet/subsheet/vout.
const wxString & GetNetChain() const
const KIID & GetTerminalPadUuid(int aIndex) const
wxString m_displayNetname
Unescaped netname for display.
const wxString & GetNetname() const
void Clear()
Set all fields to their default values.
void SetTerminalPadUuid(int aIndex, const KIID &aUuid)
int m_netCode
A number equivalent to the net name.
void SetNetChain(const wxString &aNetChain)
wxString m_netname
Full net name like /sheet/subsheet/vout used by Eeschema.
int getFreeNetCode()
Return the first available net code that is not used by any other net.
void RemoveUnusedNets(BOARD_COMMIT *aCommit)
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
int m_newNetCode
possible value for new net code assignment
unsigned GetNetCount() const
void detachAll()
Drop all entries from the lookup maps without freeing the items.
void RemoveNet(NETINFO_ITEM *aNet)
Remove a net from the net list.
bool RenameNets(const std::map< wxString, wxString > &aNewNames, REPORTER &aReporter)
Rename nets in place, keeping the name lookup in sync.
NETINFO_ITEM * GetNetItem(int aNetCode) const
NETINFO_LIST(BOARD *aParent)
void clear()
Delete the list of nets (and free memory).
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
bool m_DisplayNetnamesDirty
void RebuildDisplayNetnames() const
void buildListOfNets()
Rebuild the list of NETINFO_ITEMs.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
const wxChar *const traceImportNetNames
Flag to enable tracing of imported net-name reconciliation between a schematic and its board.
This file contains miscellaneous commonly used macros and functions.
std::map< int, NETINFO_ITEM * > NETCODES_MAP
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
wxString UnescapeString(const wxString &aSource)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.