Browse Source

Dedupe ODB++ symbol names

If we have duplicate symbol names (can happen from plugins), suffix a
number

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21803

(cherry picked from commit 8cfac03444)
9.0
Seth Hillbrand 1 week ago
parent
commit
b7d7403e6f
  1. 15
      pcbnew/pcb_io/odbpp/odb_component.cpp
  2. 2
      pcbnew/pcb_io/odbpp/odb_component.h
  3. 3
      pcbnew/pcb_io/odbpp/odb_entity.cpp

15
pcbnew/pcb_io/odbpp/odb_component.cpp

@ -61,6 +61,21 @@ ODB_COMPONENT& COMPONENTS_MANAGER::AddComponent( const FOOTPRINT* aFp,
comp.m_comp_name = wxString::Format( "UNNAMED%zu", m_compList.size() );
}
wxString base_comp_name = comp.m_comp_name;
if( !m_usedCompNames.insert( comp.m_comp_name ).second )
{
size_t suffix = 1;
wxString candidate;
do
{
candidate = wxString::Format( "%s_%zu", base_comp_name, suffix++ );
} while( !m_usedCompNames.insert( candidate ).second );
comp.m_comp_name = candidate;
}
for( PCB_FIELD* field : aFp->GetFields() )
{
if( field->GetId() == REFERENCE_FIELD )

2
pcbnew/pcb_io/odbpp/odb_component.h

@ -24,6 +24,7 @@
#include "odb_util.h"
#include <list>
#include <set>
#include <wx/string.h>
#include "odb_attribute.h"
#include "odb_eda_data.h"
@ -42,6 +43,7 @@ public:
private:
std::list<ODB_COMPONENT> m_compList;
std::set<wxString> m_usedCompNames;
};

3
pcbnew/pcb_io/odbpp/odb_entity.cpp

@ -728,6 +728,9 @@ void ODB_STEP_ENTITY::InitEdaData()
const EDA_DATA::PACKAGE& eda_pkg =
m_edaData.GetPackage( hash_fp_item( fp_pkg.get(), HASH_POS | REL_COORD ) );
if( fp->Pads().empty() )
continue;
ODB_COMPONENT& comp = iter->second->InitComponentData( fp, eda_pkg );
for( int i = 0; i < fp->Pads().size(); ++i )

Loading…
Cancel
Save