31 std::istringstream stream( aPayload );
40 while( std::getline( stream, line ) )
42 size_t tab = line.find(
'\t' );
44 if( tab == std::string::npos )
47 SHEET_REF_SUFFIX& entry = suffixes[wxString::FromUTF8( line.substr( 0, tab ) )];
49 entry.
Suffix = wxString::FromUTF8( line.substr( tab + 1 ) );
63 bool Suffixed =
false;
66 std::map<KIID, FOOTPRINT_REF_SPLIT> splits;
67 std::map<std::pair<KIID, wxString>, GROUP> groups;
68 std::set<KIID> grouped;
73 return std::make_pair( aFootprint->
GetPath().back(), aSplit.Base );
76 for(
const FOOTPRINT* footprint : aFootprints )
79 const wxString ref = footprint->GetReference();
84 split.Representative = footprint->m_Uuid;
86 if( aSuffixes && !sheet.empty() )
89 if(
auto it = aSuffixes->find( sheet.
AsString() ); it != aSuffixes->end() )
97 if( it = aSuffixes->find( sheet.
AsString() + wxS(
"/" ) ); it != aSuffixes->end() )
102 if( !aSuffixes && aSuffixMode && footprint->GetPath().size() > 1 )
105 split.Unknown =
true;
109 const wxString suffix = entry ? entry->
Suffix : wxString();
111 if( !suffix.IsEmpty() && ( ref.length() <= suffix.length() || !ref.EndsWith( suffix ) ) )
113 split.Unknown =
true;
117 const wxString base = ref.Left( ref.length() - suffix.length() );
118 const size_t firstDigit = base.find_first_of( wxS(
"0123456789" ) );
121 if( firstDigit == wxString::npos )
125 if( base.find_first_not_of( wxS(
"0123456789" ), firstDigit ) != wxString::npos )
127 split.Unknown =
true;
135 split.Suffix = suffix;
137 grouped.insert( footprint->m_Uuid );
139 auto [it, added] = groups.try_emplace( groupKey( footprint,
split ) );
140 GROUP&
group = it->second;
145 group.Representative = footprint->m_Uuid;
148 group.Suffixed |= !suffix.IsEmpty();
152 for(
const FOOTPRINT* footprint : aFootprints )
156 if( !grouped.count( footprint->m_Uuid ) )
159 if(
auto it = groups.find( groupKey( footprint,
split ) ); it != groups.end() && it->second.Suffixed )
161 split.Representative = it->second.Representative;
std::map< KIID, FOOTPRINT_REF_SPLIT > SplitRefSuffixes(const FOOTPRINTS &aFootprints, const SHEET_REF_SUFFIXES *aSuffixes, bool aSuffixMode)
Split each footprint reference into its base and sheet suffix.