Commit 272936ef authored by Dick Hollenbeck's avatar Dick Hollenbeck

populate PCB_PARSER::m_layerMap with English layernames so footprints

can be parsed, since they do not have an overriding layer name map
like a BOARD does.

Avoid doubly looking up hashtable entries in m_layerMap.

Minor code reformatting.
parent b4ab7ef7
This diff is collapsed.
......@@ -376,38 +376,38 @@ wxString BOARD::GetLayerName( int aLayerIndex, bool aTranslate ) const
// Default layer names are statically initialized,
// because we want the English name and the translation
// because we want the English name and the translation.
// The English name is stored here, and to get the translation
// wxGetTranslation must be called explicitly
static const wxChar * layer_FRONT_name = _( "Front" );
static const wxChar * layer_INNER1_name = _( "Inner1" );
static const wxChar * layer_INNER2_name = _( "Inner2" );
static const wxChar * layer_INNER3_name = _( "Inner3" );
static const wxChar * layer_INNER4_name = _( "Inner4" );
static const wxChar * layer_INNER5_name = _( "Inner5" );
static const wxChar * layer_INNER6_name = _( "Inner6" );
static const wxChar * layer_INNER7_name = _( "Inner7" );
static const wxChar * layer_INNER8_name = _( "Inner8" );
static const wxChar * layer_INNER9_name = _( "Inner9" );
static const wxChar * layer_INNER10_name = _( "Inner10" );
static const wxChar * layer_INNER11_name = _( "Inner11" );
static const wxChar * layer_INNER12_name = _( "Inner12" );
static const wxChar * layer_INNER13_name = _( "Inner13" );
static const wxChar * layer_INNER14_name = _( "Inner14" );
static const wxChar * layer_BACK_name = _( "Back" );
static const wxChar * layer_ADHESIVE_BACK_name = _( "Adhes_Back" );
static const wxChar * layer_ADHESIVE_FRONT_name = _( "Adhes_Front" );
static const wxChar * layer_SOLDERPASTE_BACK_namet = _( "SoldP_Back" );
static const wxChar * layer_SOLDERPASTE_FRONT_name = _( "SoldP_Front" );
static const wxChar * layer_SILKSCREEN_BACK_name = _( "SilkS_Back" );
static const wxChar * layer_SILKSCREEN_FRONT_name = _( "SilkS_Front" );
static const wxChar * layer_SOLDERMASK_BACK_name = _( "Mask_Back" );
static const wxChar * layer_SOLDERMASK_FRONT_name = _( "Mask_Front" );
static const wxChar * layer_DRAW_name = _( "Drawings" );
static const wxChar * layer_COMMENT_name = _( "Comments" );
static const wxChar * layer_ECO1_name = _( "Eco1" );
static const wxChar * layer_ECO2_name = _( "Eco2" );
static const wxChar * layer_EDGE_name = _( "PCB_Edges" );
// wxGetTranslation must be called explicitly.
static const wxChar* layer_FRONT_name = _( "Front" );
static const wxChar* layer_INNER1_name = _( "Inner1" );
static const wxChar* layer_INNER2_name = _( "Inner2" );
static const wxChar* layer_INNER3_name = _( "Inner3" );
static const wxChar* layer_INNER4_name = _( "Inner4" );
static const wxChar* layer_INNER5_name = _( "Inner5" );
static const wxChar* layer_INNER6_name = _( "Inner6" );
static const wxChar* layer_INNER7_name = _( "Inner7" );
static const wxChar* layer_INNER8_name = _( "Inner8" );
static const wxChar* layer_INNER9_name = _( "Inner9" );
static const wxChar* layer_INNER10_name = _( "Inner10" );
static const wxChar* layer_INNER11_name = _( "Inner11" );
static const wxChar* layer_INNER12_name = _( "Inner12" );
static const wxChar* layer_INNER13_name = _( "Inner13" );
static const wxChar* layer_INNER14_name = _( "Inner14" );
static const wxChar* layer_BACK_name = _( "Back" );
static const wxChar* layer_ADHESIVE_BACK_name = _( "Adhes_Back" );
static const wxChar* layer_ADHESIVE_FRONT_name = _( "Adhes_Front" );
static const wxChar* layer_SOLDERPASTE_BACK_name = _( "SoldP_Back" );
static const wxChar* layer_SOLDERPASTE_FRONT_name = _( "SoldP_Front" );
static const wxChar* layer_SILKSCREEN_BACK_name = _( "SilkS_Back" );
static const wxChar* layer_SILKSCREEN_FRONT_name = _( "SilkS_Front" );
static const wxChar* layer_SOLDERMASK_BACK_name = _( "Mask_Back" );
static const wxChar* layer_SOLDERMASK_FRONT_name = _( "Mask_Front" );
static const wxChar* layer_DRAW_name = _( "Drawings" );
static const wxChar* layer_COMMENT_name = _( "Comments" );
static const wxChar* layer_ECO1_name = _( "Eco1" );
static const wxChar* layer_ECO2_name = _( "Eco2" );
static const wxChar* layer_EDGE_name = _( "PCB_Edges" );
wxString BOARD::GetDefaultLayerName( int aLayerNumber, bool aTranslate )
{
......@@ -428,40 +428,42 @@ wxString BOARD::GetDefaultLayerName( int aLayerNumber, bool aTranslate )
case LAYER_N_7: txt = layer_INNER6_name; break;
case LAYER_N_8: txt = layer_INNER7_name; break;
case LAYER_N_9: txt = layer_INNER8_name; break;
case LAYER_N_10: txt = layer_INNER9_name; break;
case LAYER_N_10: txt = layer_INNER9_name; break;
case LAYER_N_11: txt = layer_INNER10_name; break;
case LAYER_N_12: txt = layer_INNER11_name; break;
case LAYER_N_13: txt = layer_INNER12_name; break;
case LAYER_N_14: txt = layer_INNER13_name; break;
case LAYER_N_15: txt = layer_INNER14_name; break;
case LAYER_N_BACK: txt = layer_BACK_name; break;
case ADHESIVE_N_BACK: txt =layer_ADHESIVE_BACK_name; break;
case ADHESIVE_N_FRONT: txt = layer_ADHESIVE_FRONT_name; break;
case SOLDERPASTE_N_BACK: txt = layer_SOLDERPASTE_BACK_namet; break;
case SOLDERPASTE_N_FRONT: txt = layer_SOLDERPASTE_FRONT_name; break;
case SILKSCREEN_N_BACK: txt = layer_SILKSCREEN_BACK_name; break;
case SILKSCREEN_N_FRONT: txt = layer_SILKSCREEN_FRONT_name; break;
case SOLDERMASK_N_BACK: txt = layer_SOLDERMASK_BACK_name; break;
case SOLDERMASK_N_FRONT: txt = layer_SOLDERMASK_FRONT_name; break;
case DRAW_N: txt = layer_DRAW_name; break;
case COMMENT_N: txt = layer_COMMENT_name; break;
case ADHESIVE_N_BACK: txt = layer_ADHESIVE_BACK_name; break;
case ADHESIVE_N_FRONT: txt = layer_ADHESIVE_FRONT_name; break;
case SOLDERPASTE_N_BACK: txt = layer_SOLDERPASTE_BACK_name; break;
case SOLDERPASTE_N_FRONT: txt = layer_SOLDERPASTE_FRONT_name; break;
case SILKSCREEN_N_BACK: txt = layer_SILKSCREEN_BACK_name; break;
case SILKSCREEN_N_FRONT: txt = layer_SILKSCREEN_FRONT_name; break;
case SOLDERMASK_N_BACK: txt = layer_SOLDERMASK_BACK_name; break;
case SOLDERMASK_N_FRONT: txt = layer_SOLDERMASK_FRONT_name; break;
case DRAW_N: txt = layer_DRAW_name; break;
case COMMENT_N: txt = layer_COMMENT_name; break;
case ECO1_N: txt = layer_ECO1_name; break;
case ECO2_N: txt = layer_ECO2_name; break;
case EDGE_N: txt = layer_EDGE_name; break;
default: txt = wxT( "BAD_INDEX" ); break;
case EDGE_N: txt = layer_EDGE_name; break;
default: txt = wxT( "BAD_INDEX" ); break;
}
wxString name;
if( aTranslate )
{
name = wxGetTranslation( txt );
wxString name = wxGetTranslation( txt );
/* would someone translate into a name with leading or trailing spaces?
name.Trim( true );
name.Trim( false );
*/
return name;
}
else
name = txt;
return name;
return txt;
}
......@@ -573,55 +575,6 @@ LAYER_T LAYER::ParseType( const char* aType )
}
int LAYER::GetDefaultIndex( const wxString& aName )
{
static LAYER_INDEX_HASH_MAP layerIndices;
if( layerIndices.empty() )
{
// These are only default layer names. The copper names may be over-ridden in
// the BOARD (*.brd) file.
layerIndices[ _( "Front" ) ] = LAYER_N_FRONT;
layerIndices[ _( "Inner2" ) ] = LAYER_N_2;
layerIndices[ _( "Inner3" ) ] = LAYER_N_3;
layerIndices[ _( "Inner4" ) ] = LAYER_N_4;
layerIndices[ _( "Inner5" ) ] = LAYER_N_5;
layerIndices[ _( "Inner6" ) ] = LAYER_N_6;
layerIndices[ _( "Inner7" ) ] = LAYER_N_7;
layerIndices[ _( "Inner8" ) ] = LAYER_N_8;
layerIndices[ _( "Inner9" ) ] = LAYER_N_9;
layerIndices[ _( "Inner10" ) ] = LAYER_N_10;
layerIndices[ _( "Inner11" ) ] = LAYER_N_11;
layerIndices[ _( "Inner12" ) ] = LAYER_N_12;
layerIndices[ _( "Inner13" ) ] = LAYER_N_13;
layerIndices[ _( "Inner14" ) ] = LAYER_N_14;
layerIndices[ _( "Inner15" ) ] = LAYER_N_15;
layerIndices[ _( "Back" ) ] = LAYER_N_BACK;
layerIndices[ _( "Adhes_Back" ) ] = ADHESIVE_N_BACK;
layerIndices[ _( "Adhes_Front" ) ] = ADHESIVE_N_FRONT;
layerIndices[ _( "SoldP_Back" ) ] = SOLDERPASTE_N_BACK;
layerIndices[ _( "SoldP_Front" ) ] = SOLDERPASTE_N_FRONT;
layerIndices[ _( "SilkS_Back" ) ] = SILKSCREEN_N_BACK;
layerIndices[ _( "SilkS_Front" ) ] = SILKSCREEN_N_FRONT;
layerIndices[ _( "Mask_Back" ) ] = SOLDERMASK_N_BACK;
layerIndices[ _( "Mask_Front" ) ] = SOLDERMASK_N_FRONT;
layerIndices[ _( "Drawings" ) ] = DRAW_N;
layerIndices[ _( "Comments" ) ] = COMMENT_N;
layerIndices[ _( "Eco1" ) ] = ECO1_N;
layerIndices[ _( "Eco2" ) ] = ECO2_N;
layerIndices[ _( "PCB_Edges" ) ] = EDGE_N;
}
const LAYER_INDEX_HASH_MAP::iterator it = layerIndices.find( aName );
if( it == layerIndices.end() )
return UNDEFINED_LAYER;
return layerIndices[ aName ];
}
int BOARD::GetCopperLayerCount() const
{
return m_designSettings.GetCopperLayerCount();
......
......@@ -19,8 +19,6 @@
#include <class_zone_settings.h>
#include <pcb_plot_params.h>
#include <wx/hashmap.h>
class PCB_BASE_FRAME;
class PCB_EDIT_FRAME;
......@@ -34,10 +32,9 @@ class MARKER_PCB;
// non-owning container of item candidates when searching for items on the same track.
typedef std::vector< TRACK* > TRACK_PTRS;
typedef std::vector< TRACK* > TRACK_PTRS;
#define HISTORY_MAX_COUNT 8
#define HISTORY_MAX_COUNT 8
/**
......@@ -101,24 +98,12 @@ public:
*/
static LAYER_T ParseType( const char* aType );
/**
* Function GetDefaultIndex
* returns the layer index of the layer \a aName.
*
* @param aName A reference to a wxString object containing the default layer name.
* @return The index of the layer \a aName if found otherwise #UNDEFINED_LAYER_INDEX.
*/
static int GetDefaultIndex( const wxString& aName );
private:
bool m_visible;
int m_fixedListIndex;
bool m_visible;
int m_fixedListIndex;
};
WX_DECLARE_STRING_HASH_MAP( int, LAYER_INDEX_HASH_MAP );
/**
* Struct VIA_DIMENSION
* is a small helper container to handle a stock of specific vias each with
......
......@@ -56,7 +56,14 @@ void PCB_PARSER::init()
{
m_layerMap.clear();
// @todo add default layernames here.
// Add untranslated default (i.e. english) layernames.
// Some may be overridden later if parsing a board rather than a footprint.
// The english name will survive if parsing only a footprint.
for( int layerNdx = 0; layerNdx < NB_LAYERS; ++layerNdx )
{
wxString untranslated = BOARD::GetDefaultLayerName( layerNdx, false );
m_layerMap[ untranslated ] = layerNdx;
}
}
......@@ -594,38 +601,38 @@ void PCB_PARSER::parseTITLE_BLOCK() throw( IO_ERROR, PARSE_ERROR )
break;
case T_comment:
{
int commentNumber = parseInt( "comment" );
switch( commentNumber )
{
case 1:
NextTok();
titleBlock.SetComment1( FromUTF8() );
break;
int commentNumber = parseInt( "comment" );
case 2:
NextTok();
titleBlock.SetComment2( FromUTF8() );
break;
switch( commentNumber )
{
case 1:
NextTok();
titleBlock.SetComment1( FromUTF8() );
break;
case 3:
NextTok();
titleBlock.SetComment3( FromUTF8() );
break;
case 2:
NextTok();
titleBlock.SetComment2( FromUTF8() );
break;
case 4:
NextTok();
titleBlock.SetComment4( FromUTF8() );
break;
case 3:
NextTok();
titleBlock.SetComment3( FromUTF8() );
break;
default:
wxString err;
err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber );
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
case 4:
NextTok();
titleBlock.SetComment4( FromUTF8() );
break;
break;
default:
wxString err;
err.Printf( wxT( "%d is not a valid title block comment number" ), commentNumber );
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
break;
}
default:
......@@ -644,14 +651,14 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
wxCHECK_RET( CurTok() == T_layers,
wxT( "Cannot parse " ) + GetTokenString( CurTok() ) + wxT( " as layers." ) );
T token;
wxString name;
wxString type;
int layerIndex;
bool isVisible = true;
int visibleLayers = 0;
int enabledLayers = 0;
int copperLayerCount = 0;
T token;
wxString name;
std::string type;
int layerIndex;
bool isVisible = true;
int visibleLayers = 0;
int enabledLayers = 0;
int copperLayerCount = 0;
for( token = NextTok(); token != T_RIGHT; token = NextTok() )
{
......@@ -662,8 +669,9 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
NeedSYMBOL();
name = FromUTF8();
NeedSYMBOL();
type = FromUTF8();
type = CurText();
token = NextTok();
......@@ -686,7 +694,7 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
if( isVisible )
visibleLayers |= 1 << layerIndex;
enum LAYER_T layerType = LAYER::ParseType( TO_UTF8( type ) );
enum LAYER_T layerType = LAYER::ParseType( type.c_str() );
LAYER layer( name, layerType, isVisible );
layer.SetFixedListIndex( layerIndex );
......@@ -694,7 +702,7 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
m_layerMap[ name ] = layerIndex;
wxLogDebug( wxT( "Mapping layer %s index index %d" ),
wxLogDebug( wxT( "Mapping layer %s to index %d" ),
GetChars( name ), layerIndex );
if( layerType != LT_UNDEFINED )
......@@ -704,8 +712,9 @@ void PCB_PARSER::parseLayers() throw( IO_ERROR, PARSE_ERROR )
// We need at least 2 copper layers and there must be an even number of them.
if( (copperLayerCount < 2) || ((copperLayerCount % 2) != 0) )
{
wxString err;
err.Printf( _( "%d is not a valid layer count" ), copperLayerCount );
wxString err = wxString::Format(
_( "%d is not a valid layer count" ), copperLayerCount );
THROW_PARSE_ERROR( err, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
......@@ -722,13 +731,14 @@ int PCB_PARSER::lookUpLayer() throw( PARSE_ERROR, IO_ERROR )
if( it == m_layerMap.end() )
{
wxString error;
error.Printf( wxT( "Layer '%s' in file <%s> at line %d, position %d was not defined in the layers section" ),
GetChars( name ), GetChars( CurSource() ), CurLineNumber(), CurOffset() );
wxString error = wxString::Format(
_( "Layer '%s' in file <%s> at line %d, position %d, was not defined in the layers section" ),
GetChars( name ), GetChars( CurSource() ), CurLineNumber(), CurOffset() );
THROW_IO_ERROR( error );
}
return m_layerMap[ name ];
return it->second;
}
......
......@@ -64,7 +64,7 @@ WX_DECLARE_STRING_HASH_MAP( int, LAYER_HASH_MAP );
class PCB_PARSER : public PCB_LEXER
{
BOARD* m_board;
LAYER_HASH_MAP m_layerMap; //< Map layer name to it's index saved in BOARD::m_Layer.
LAYER_HASH_MAP m_layerMap; ///< Map layer name to it's index saved in BOARD::m_Layer.
/**
......@@ -220,6 +220,7 @@ public:
PCB_LEXER( aReader ),
m_board( 0 )
{
init();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment