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 ) );
158 if( sameName == aNewElement )
162 else if( sameName !=
nullptr )
193 std::unordered_map<int, wxString> preservedNetChains;
194 std::unordered_map<int, KIID> preservedPad0;
195 std::unordered_map<int, KIID> preservedPad1;
214 auto it = preservedNetChains.find( net->
GetNetCode() );
215 if( it != preservedNetChains.end() )
218 auto ip0 = preservedPad0.find( net->
GetNetCode() );
219 if( ip0 != preservedPad0.end() )
222 auto ip1 = preservedPad1.find( net->
GetNetCode() );
223 if( ip1 != preservedPad1.end() )
227 m_parent->SynchronizeNetsAndNetClasses(
false );
228 m_parent->SetAreasNetCodesFromNetNames();
234 std::map<wxString, std::vector<wxString>> shortNameMap;
247 wxArrayString parts = wxSplit( net->
m_netname,
'/' );
248 std::vector<wxArrayString> aggregateParts;
249 std::optional<size_t> firstNonCommon;
251 for(
const wxString& longName : shortNameMap[net->
m_shortNetname] )
252 aggregateParts.push_back( wxSplit( longName,
'/' ) );
254 for(
size_t ii = 0; ii < parts.size() && !firstNonCommon; ++ii )
256 for(
const wxArrayString& otherParts : aggregateParts )
258 if( ii < otherParts.size() && otherParts[ii] == parts[ii] )
266 if( firstNonCommon.value_or( 0 ) > 0 && firstNonCommon.value() < parts.size() )
268 wxString disambiguatedName;
270 for(
size_t ii = firstNonCommon.value(); ii < parts.size(); ++ii )
272 if( !disambiguatedName.IsEmpty() )
273 disambiguatedName += wxS(
"/" );
275 disambiguatedName += parts[ii];
292void NETINFO_LIST::Show()
const
295 NETNAMES_MAP::const_iterator it, itEnd;
299 wxLogDebug( wxT(
"[%d]: netcode:%d netname:<%s>\n" ),
301 it->second->GetNetCode(),
302 TO_UTF8( it->second->GetNetname() ) );
322 if( aNewNames.empty() )
327 std::vector<std::pair<NETINFO_ITEM*, wxString>> renames;
330 for(
const auto& [
source, target] : aNewNames )
345 if( net->
GetNetCode() <= 0 || target.IsEmpty() )
347 aReporter.
Report( wxString::Format(
_(
"Cannot rename net '%s' to '%s': net zero and empty "
348 "names are reserved for unconnected items." ),
356 renames.emplace_back( net, target );
357 finalNames.erase(
source );
361 renames.size(), aNewNames.size(), missing );
363 if( renames.empty() )
366 for(
const auto& [net, target] : renames )
368 if( !finalNames.emplace( target, net ).second )
370 aReporter.
Report( wxString::Format(
_(
"Cannot rename net '%s' to '%s': another net would "
371 "have the same name." ),
378 for(
const auto& [net, target] : renames )
379 net->SetNetname( target );
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
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).
bool AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
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.