Browse Source

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

(cherry picked from commit 8f625086b1)
9.0
Seth Hillbrand 3 months ago
parent
commit
9fe656a33c
  1. 29
      pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp
  2. 5
      pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.h

29
pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.cpp

@ -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;
}

5
pcbnew/pcb_io/ipc2581/pcb_io_ipc2581.h

@ -32,6 +32,8 @@
#include <wx/xml/xml.h>
#include <memory>
#include <map>
#include <set>
class BOARD;
class BOARD_ITEM;
@ -328,6 +330,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…
Cancel
Save