mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Remove namespacing from IPC2581 output
Because some readers maintain global namespace per the standard, we make sure that we don't overlap names between namespaces but keep the minimum viable name for each element Fixes https://gitlab.com/kicad/code/kicad/-/issues/19914
This commit is contained in:
parent
da92279436
commit
8f625086b1
@ -153,23 +153,24 @@ wxXmlNode* PCB_IO_IPC2581::appendNode( wxXmlNode* aParent, const wxString& aName
|
||||
|
||||
wxString PCB_IO_IPC2581::genString( const wxString& aStr, const char* aPrefix ) const
|
||||
{
|
||||
// Build a key using the prefix and original string so that repeated calls for the same
|
||||
// element return the same generated name.
|
||||
wxString key = aPrefix ? wxString( aPrefix ) + wxT( ":" ) + aStr : aStr;
|
||||
|
||||
auto it = m_generated_names.find( key );
|
||||
|
||||
if( it != m_generated_names.end() )
|
||||
return it->second;
|
||||
|
||||
wxString str;
|
||||
|
||||
if( m_version == 'C' )
|
||||
{
|
||||
str = aStr;
|
||||
str.Replace( wxT( ":" ), wxT( "_" ) );
|
||||
|
||||
if( aPrefix )
|
||||
str.Prepend( wxString( aPrefix ) + wxT( ":" ) );
|
||||
else
|
||||
str.Prepend( wxT( "KI:" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( aPrefix )
|
||||
str = wxString::Format( "%s_", aPrefix );
|
||||
|
||||
for( wxString::const_iterator iter = aStr.begin(); iter != aStr.end(); ++iter )
|
||||
{
|
||||
if( !m_acceptable_chars.count( *iter ) )
|
||||
@ -179,7 +180,17 @@ wxString PCB_IO_IPC2581::genString( const wxString& aStr, const char* aPrefix )
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
wxString base = str;
|
||||
wxString name = base;
|
||||
int suffix = 1;
|
||||
|
||||
while( m_element_names.count( name ) )
|
||||
name = wxString::Format( "%s_%d", base, suffix++ );
|
||||
|
||||
m_element_names.insert( name );
|
||||
m_generated_names[key] = name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
@ -34,6 +34,8 @@
|
||||
|
||||
#include <wx/xml/xml.h>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class BOARD;
|
||||
class BOARD_ITEM;
|
||||
@ -337,6 +339,9 @@ private:
|
||||
|
||||
PROGRESS_REPORTER* m_progress_reporter;
|
||||
|
||||
mutable std::set<wxString> m_element_names; //<! Track generated element names
|
||||
mutable std::map<wxString, wxString> m_generated_names; //<! Map input keys to unique names
|
||||
|
||||
std::set<wxUniChar> m_acceptable_chars; //<! IPC2581B and C have differing sets of allowed characters in names
|
||||
|
||||
wxXmlDocument* m_xml_doc;
|
||||
|
Loading…
x
Reference in New Issue
Block a user