kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #39983
[PATCH] Old Stable file handling
Recently, there was a question on the user forum about opening an old
stable file that had layer names translated[1]. I had suggested
following the instructions that we have posted about this issue on the
website[2]. But after I posted that, I tried it myself and found that
it didn't work correctly (and was a real pain).
Simon observed that this is something we should be able to handle
programatically, so I took a stab at it.
I'm attaching the patch here for comments. If you'd like a copy of an
oldstable board with translated layer names, you can download one from
here [3]
If this is merged, I'll submit a PR to remove that part of the website.
If we decide not to merge this (or similar), we should at a minimum,
revise the instructions on the website to use the correct (new) layer
numbers.
-Seth
[1]
https://forum.kicad.info/t/problem-opening-old-file-with-kicad-5-1-0/16077
[2] http://kicad-pcb.org/help/upgrading/
[3] https://drive.google.com/open?id=10OaglGiBMD_WUY20AFWRhoditUtiCax4
From 4bafeef8922369173b130b41935c6684a7dad23d Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <hillbrand@xxxxxxxxxxx>
Date: Mon, 1 Apr 2019 06:17:32 -0700
Subject: [PATCH] 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).
---
pcbnew/pcb_parser.cpp | 62 ++++++++++++++++++++++++++++++++++---------
1 file changed, 50 insertions(+), 12 deletions(-)
diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp
index e641ce4ad5..416b10aa31 100644
--- a/pcbnew/pcb_parser.cpp
+++ b/pcbnew/pcb_parser.cpp
@@ -941,6 +941,33 @@ void PCB_PARSER::parseLayers()
int copperLayerCount = 0;
LAYER layer;
+ std::unordered_map< std::string, std::string > v3_layer_names;
+
+ v3_layer_names["Adesivo.Retro"] = "B.Adhes";
+ v3_layer_names["Adesivo.Fronte"] = "F.Adhes";
+ v3_layer_names["Pasta.Retro"] = "B.Paste";
+ v3_layer_names["Pasta.Fronte"] = "F.Paste";
+ v3_layer_names["Serigrafia.Retro"] = "B.SilkS";
+ v3_layer_names["Serigrafia.Fronte"] = "F.SilkS";
+ v3_layer_names["Maschera.Retro"] = "B.Mask";
+ v3_layer_names["Maschera.Fronte"] = "F.Mask";
+ v3_layer_names["Grafica"] = "Dwgs.User";
+ v3_layer_names["Commenti"] = "Cmts.User";
+ v3_layer_names["Eco1"] = "Eco1.User";
+ v3_layer_names["Eco2"] = "Eco2.User";
+ v3_layer_names["Contorno.scheda"] = "Edge.Cuts";
+
+ v3_layer_names["Dessous.Adhes"] = "B.Adhes";
+ v3_layer_names["Dessus.Adhes"] = "F.Adhes";
+ v3_layer_names["Dessous.Pate"] = "B.Paste";
+ v3_layer_names["Dessus.Pate"] = "F.Paste";
+ v3_layer_names["Dessous.SilkS"] = "B.SilkS";
+ v3_layer_names["Dessus.SilkS"] = "F.SilkS";
+ v3_layer_names["Dessous.Masque"] = "B.Mask";
+ v3_layer_names["Dessus.Masque"] = "F.Mask";
+ v3_layer_names["Dessin.User"] = "Dwgs.User";
+ v3_layer_names["Contours.Ci"] = "Edge.Cuts";
+
std::vector<LAYER> cu;
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
@@ -995,26 +1022,37 @@ void PCB_PARSER::parseLayers()
if( it == m_layerIndices.end() )
{
- wxString error = wxString::Format(
- _( "Layer \"%s\" in file \"%s\" at line %d, is not in fixed layer hash" ),
- GetChars( layer.m_name ),
- GetChars( CurSource() ),
- CurLineNumber(),
- CurOffset()
- );
-
- THROW_IO_ERROR( error );
+ 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(
+ _( "Layer \"%s\" in file \"%s\" at line %d, is not in fixed layer hash" ),
+ GetChars( layer.m_name ),
+ GetChars( CurSource() ),
+ CurLineNumber(),
+ CurOffset()
+ );
+
+ THROW_IO_ERROR( error );
+ }
+
+ // 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();
--
2.20.1
Follow ups