From aa35045840b78d3f48212db45da59a2e5c69b223 Mon Sep 17 00:00:00 2001 From: saurabhb17 Date: Wed, 26 Feb 2020 15:57:49 +0530 Subject: Added main execs --- eeschema/template_fieldnames.cpp | 211 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 eeschema/template_fieldnames.cpp (limited to 'eeschema/template_fieldnames.cpp') diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp new file mode 100644 index 0000000..28be5dd --- /dev/null +++ b/eeschema/template_fieldnames.cpp @@ -0,0 +1,211 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include + +using namespace TFIELD_T; + +const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName( int aFieldNdx ) +{ + // Fixed values for the first few default fields used by EESCHEMA + // (mandatory fields) + switch( aFieldNdx ) + { + case REFERENCE: + return _( "Reference" ); // The component reference, R1, C1, etc. + + case VALUE: + return _( "Value" ); // The component value + name + + case FOOTPRINT: + return _( "Footprint" ); // The footprint for use with Pcbnew + + case DATASHEET: + return _( "Datasheet" ); // Link to a datasheet for component + + default: + break; + } + + // Other fields are use fields, give a default name: + wxString fieldName = _( "Field" ); + fieldName << aFieldNdx; + return fieldName; +} + +void TEMPLATE_FIELDNAME::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR ) +{ + out->Print( nestLevel, "(field (name %s)", out->Quotew( m_Name ).c_str() ); + + if( !m_Value.IsEmpty() ) + out->Print( 0, "(value %s)", out->Quotew( m_Value ).c_str() ); + + if( m_Visible ) + out->Print( 0, " visible" ); + + out->Print( 0, ")\n" ); +} + + +void TEMPLATE_FIELDNAME::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR ) +{ + T tok; + + in->NeedLEFT(); // begin (name ...) + + if( (tok = in->NextTok()) != T_name ) + in->Expecting( T_name ); + + in->NeedSYMBOLorNUMBER(); + + m_Name = FROM_UTF8( in->CurText() ); + + in->NeedRIGHT(); // end (name ...) + + while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF ) + { + // "visible" has no '(' prefix, "value" does, so T_LEFT is optional. + if( tok == T_LEFT ) + tok = in->NextTok(); + + switch( tok ) + { + case T_value: + in->NeedSYMBOLorNUMBER(); + m_Value = FROM_UTF8( in->CurText() ); + in->NeedRIGHT(); + break; + + case T_visible: + m_Visible = true; + break; + + default: + in->Expecting( "value|visible" ); + break; + } + } +} + + +void TEMPLATES::Format( OUTPUTFORMATTER* out, int nestLevel ) const throw( IO_ERROR ) +{ + // 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. + out->Print( nestLevel, "(templatefields" ); + + for( unsigned i=0; iPrint( 0, ")\n" ); +} + + +void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR ) +{ + T tok; + + while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF ) + { + if( tok == T_LEFT ) + tok = in->NextTok(); + + switch( tok ) + { + case T_templatefields: // a token indicating class TEMPLATES. + + // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER + // 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: + in->Unexpected( in->CurText() ); + break; + } + } +} + + +int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName ) +{ + // Ensure that the template fieldname does not match a fixed fieldname. + for( int i=0; i