pcbnew: Handle old stable translated layers

This inserts a translation map in the layer names so that the old stable
files with Italian/French layer names get updated to the standard
English layer names (instead of not opening).

Fixes: lp:1370575
* https://bugs.launchpad.net/kicad/+bug/1370575

(cherry picked from commit 6f4d1345f3)
This commit is contained in:
Seth Hillbrand 2019-04-01 06:17:32 -07:00
parent 658820a25e
commit 031173bc47
2 changed files with 82 additions and 11 deletions

View File

@ -928,6 +928,55 @@ void PCB_PARSER::parseLayer( LAYER* aLayer )
}
void PCB_PARSER::createOldLayerMapping( std::unordered_map< std::string, std::string >& aMap )
{
// N.B. This mapping only includes Italian, Polish and French as they were the only languages that
// mapped the layer names as of cc2022b1ac739aa673d2a0b7a2047638aa7a47b3 (kicad-i18n) when the
// bug was fixed in KiCad source.
// Italian
aMap["Adesivo.Retro"] = "B.Adhes";
aMap["Adesivo.Fronte"] = "F.Adhes";
aMap["Pasta.Retro"] = "B.Paste";
aMap["Pasta.Fronte"] = "F.Paste";
aMap["Serigrafia.Retro"] = "B.SilkS";
aMap["Serigrafia.Fronte"] = "F.SilkS";
aMap["Maschera.Retro"] = "B.Mask";
aMap["Maschera.Fronte"] = "F.Mask";
aMap["Grafica"] = "Dwgs.User";
aMap["Commenti"] = "Cmts.User";
aMap["Eco1"] = "Eco1.User";
aMap["Eco2"] = "Eco2.User";
aMap["Contorno.scheda"] = "Edge.Cuts";
// Polish
aMap["Kleju_Dolna"] = "B.Adhes";
aMap["Kleju_Gorna"] = "F.Adhes";
aMap["Pasty_Dolna"] = "B.Paste";
aMap["Pasty_Gorna"] = "F.Paste";
aMap["Opisowa_Dolna"] = "B.SilkS";
aMap["Opisowa_Gorna"] = "F.SilkS";
aMap["Maski_Dolna"] = "B.Mask";
aMap["Maski_Gorna"] = "F.Mask";
aMap["Rysunkowa"] = "Dwgs.User";
aMap["Komentarzy"] = "Cmts.User";
aMap["ECO1"] = "Eco1.User";
aMap["ECO2"] = "Eco2.User";
aMap["Krawedziowa"] = "Edge.Cuts";
// French
aMap["Dessous.Adhes"] = "B.Adhes";
aMap["Dessus.Adhes"] = "F.Adhes";
aMap["Dessous.Pate"] = "B.Paste";
aMap["Dessus.Pate"] = "F.Paste";
aMap["Dessous.SilkS"] = "B.SilkS";
aMap["Dessus.SilkS"] = "F.SilkS";
aMap["Dessous.Masque"] = "B.Mask";
aMap["Dessus.Masque"] = "F.Mask";
aMap["Dessin.User"] = "Dwgs.User";
aMap["Contours.Ci"] = "Edge.Cuts";
}
void PCB_PARSER::parseLayers()
{
@ -940,8 +989,11 @@ void PCB_PARSER::parseLayers()
int copperLayerCount = 0;
LAYER layer;
std::unordered_map< std::string, std::string > v3_layer_names;
std::vector<LAYER> cu;
createOldLayerMapping( v3_layer_names );
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{
parseLayer( &layer );
@ -992,6 +1044,13 @@ void PCB_PARSER::parseLayers()
{
LAYER_ID_MAP::const_iterator it = m_layerIndices.find( UTF8( layer.m_name ) );
if( it == m_layerIndices.end() )
{
auto new_layer_it = v3_layer_names.find( layer.m_name.ToStdString() );
if( new_layer_it != v3_layer_names.end() )
it = m_layerIndices.find( new_layer_it->second );
if( it == m_layerIndices.end() )
{
wxString error = wxString::Format(
@ -1005,15 +1064,19 @@ void PCB_PARSER::parseLayers()
THROW_IO_ERROR( error );
}
layer.m_number = it->second;
// If we are here, then we have found a translated layer name. Put it in the maps so that
// items on this layer get the appropriate layer ID number
m_layerIndices[ UTF8( layer.m_name ) ] = it->second;
m_layerMasks[ UTF8( layer.m_name ) ] = it->second;
layer.m_name = it->first;
}
layer.m_number = it->second;
enabledLayers.set( layer.m_number );
if( layer.m_visible )
visibleLayers.set( layer.m_number );
// DBG( printf( "aux m_visible:%s\n", layer.m_visible ? "true" : "false" );)
m_board->SetLayerDescr( it->second, layer );
token = NextTok();

View File

@ -102,6 +102,14 @@ class PCB_PARSER : public PCB_LEXER
*/
void init();
/**
* Creates a mapping from the (short-lived) bug where layer names were translated
* TODO: Remove this once we support custom layer names
*
* @param aMap string mapping from translated to English layer names
*/
void createOldLayerMapping( std::unordered_map< std::string, std::string >& aMap );
void parseHeader();
void parseGeneralSection();
void parsePAGE_INFO();