2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <template_fieldnames.h>
|
|
|
|
#include <dsnlexer.h>
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <macros.h>
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-01-17 17:26:19 +00:00
|
|
|
using namespace TFIELD_T;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx )
|
|
|
|
{
|
|
|
|
// Fixed values for the first few default fields used by EESCHEMA
|
|
|
|
static const wxString fixedNames[] = {
|
|
|
|
_( "Reference" ), // The component reference, R1, C1, etc.
|
|
|
|
_( "Value" ), // The component value + name
|
2011-09-30 18:15:37 +00:00
|
|
|
_( "Footprint" ), // The footprint for use with Pcbnew
|
2010-06-17 16:30:10 +00:00
|
|
|
_( "Datasheet" ), // Link to a datasheet for component
|
|
|
|
};
|
|
|
|
|
2011-01-28 20:18:30 +00:00
|
|
|
if( (unsigned) aFieldNdx < DIM(fixedNames) )
|
2010-06-17 16:30:10 +00:00
|
|
|
return fixedNames[aFieldNdx];
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString fieldName = _("Field");
|
|
|
|
|
|
|
|
fieldName << aFieldNdx;
|
|
|
|
|
|
|
|
return fieldName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 15:45:11 +00:00
|
|
|
void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2011-02-02 19:41:35 +00:00
|
|
|
out->Print( nestLevel, "(field (name %s)", out->Quotew( m_Name ).c_str() );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
if( !m_Value.IsEmpty() )
|
2011-02-02 19:41:35 +00:00
|
|
|
out->Print( 0, "(value %s)", out->Quotew( m_Value ).c_str() );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
if( m_Visible )
|
|
|
|
out->Print( 0, " visible" );
|
|
|
|
|
|
|
|
out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-09 15:45:11 +00:00
|
|
|
void TEMPLATE_FIELDNAME::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2011-01-17 17:26:19 +00:00
|
|
|
T tok;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-06-18 16:00:16 +00:00
|
|
|
in->NeedLEFT(); // begin (name ...)
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-08-09 02:03:16 +00:00
|
|
|
if( (tok = in->NextTok()) != T_name )
|
2010-06-17 16:30:10 +00:00
|
|
|
in->Expecting( T_name );
|
|
|
|
|
2010-06-18 16:00:16 +00:00
|
|
|
in->NeedSYMBOLorNUMBER();
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2011-02-02 15:31:48 +00:00
|
|
|
m_Name = FROM_UTF8( in->CurText() );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-06-18 16:00:16 +00:00
|
|
|
in->NeedRIGHT(); // end (name ...)
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-08-09 02:03:16 +00:00
|
|
|
while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2010-06-18 16:00:16 +00:00
|
|
|
// "visible" has no '(' prefix, "value" does, so T_LEFT is optional.
|
2010-06-17 16:30:10 +00:00
|
|
|
if( tok == T_LEFT )
|
2010-08-09 02:03:16 +00:00
|
|
|
tok = in->NextTok();
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
switch( tok )
|
|
|
|
{
|
|
|
|
case T_value:
|
2010-06-18 16:00:16 +00:00
|
|
|
in->NeedSYMBOLorNUMBER();
|
2011-02-02 15:31:48 +00:00
|
|
|
m_Value = FROM_UTF8( in->CurText() );
|
2010-06-18 16:00:16 +00:00
|
|
|
in->NeedRIGHT();
|
2010-06-17 16:30:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_visible:
|
|
|
|
m_Visible = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-01-19 20:46:07 +00:00
|
|
|
in->Expecting( "value|visible" );
|
2010-06-17 16:30:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-09 15:45:11 +00:00
|
|
|
void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2010-08-09 02:03:16 +00:00
|
|
|
// We'll keep this general, and include the \n, even though the only known
|
|
|
|
// use at this time will not want the newlines or the indentation.
|
2010-06-17 16:30:10 +00:00
|
|
|
out->Print( nestLevel, "(templatefields" );
|
|
|
|
for( unsigned i=0; i<m_Fields.size(); ++i )
|
|
|
|
m_Fields[i].Format( out, nestLevel+1 );
|
|
|
|
out->Print( 0, ")\n" );
|
|
|
|
}
|
|
|
|
|
2011-01-17 17:26:19 +00:00
|
|
|
|
2010-11-09 15:45:11 +00:00
|
|
|
void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
2011-01-17 17:26:19 +00:00
|
|
|
T tok;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2012-10-08 19:34:04 +00:00
|
|
|
while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
if( tok == T_LEFT )
|
2010-08-09 02:03:16 +00:00
|
|
|
tok = in->NextTok();
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
switch( tok )
|
|
|
|
{
|
|
|
|
case T_templatefields: // a token indicating class TEMPLATES.
|
|
|
|
|
2010-08-09 02:03:16 +00:00
|
|
|
// Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
|
2010-06-17 16:30:10 +00:00
|
|
|
// stream. Caller may not have read the first two tokens out of the
|
|
|
|
// stream: T_LEFT and T_templatefields, so ignore them if seen here.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_field:
|
|
|
|
{
|
|
|
|
// instantiate on stack, so if exception is thrown,
|
|
|
|
// destructor runs
|
|
|
|
TEMPLATE_FIELDNAME field;
|
|
|
|
|
|
|
|
field.Parse( in );
|
|
|
|
|
|
|
|
// add the field
|
|
|
|
AddTemplateFieldName( field );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-01-19 20:46:07 +00:00
|
|
|
in->Unexpected( in->CurText() );
|
2010-06-17 16:30:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName )
|
|
|
|
{
|
|
|
|
// Ensure that the template fieldname does not match a fixed fieldname.
|
|
|
|
for( int i=0; i<MANDATORY_FIELDS; ++i )
|
|
|
|
{
|
|
|
|
if( TEMPLATE_FIELDNAME::GetDefaultFieldName(i) == aFieldName.m_Name )
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure uniqueness, overwrite any template fieldname by the same name.
|
|
|
|
for( unsigned i=0; i<m_Fields.size(); ++i )
|
|
|
|
{
|
|
|
|
if( m_Fields[i].m_Name == aFieldName.m_Name )
|
|
|
|
{
|
2013-09-10 15:07:46 +00:00
|
|
|
DBG( printf( "inserting template fieldname:'%s' at %d\n",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( aFieldName.m_Name ), i ); )
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
m_Fields[i] = aFieldName;
|
|
|
|
return i; // return the container index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 15:07:46 +00:00
|
|
|
// DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );)
|
2010-06-17 16:30:10 +00:00
|
|
|
|
|
|
|
// the name is legal and not previously added to the config container, append
|
|
|
|
// it and return its index within the container.
|
|
|
|
m_Fields.push_back( aFieldName );
|
|
|
|
|
|
|
|
return m_Fields.size() - 1; // return the index of insertion.
|
|
|
|
}
|
|
|
|
|
2011-08-30 19:24:28 +00:00
|
|
|
|
|
|
|
bool TEMPLATES::HasFieldName( const wxString& aName ) const
|
|
|
|
{
|
|
|
|
for( size_t i=0; i<m_Fields.size(); ++i )
|
|
|
|
{
|
|
|
|
if( m_Fields[i].m_Name == aName )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|