KiCad PCB EDA Suite
TEMPLATES Class Reference

#include <template_fieldnames.h>

Public Member Functions

void Format (OUTPUTFORMATTER *out, int nestLevel) const
 Function Format serializes this object out as text into the given OUTPUTFORMATTER. More...
 
void Parse (TEMPLATE_FIELDNAMES_LEXER *in)
 Function Parse fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER. More...
 
int AddTemplateFieldName (const TEMPLATE_FIELDNAME &aFieldName)
 Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames template. More...
 
void DeleteAllTemplateFieldNames ()
 Function DeleteAllTemplateFieldNames deletes the entire contents. More...
 
const TEMPLATE_FIELDNAMESGetTemplateFieldNames ()
 Function GetTemplateFieldName returns a template fieldnames list for read only access. More...
 
bool HasFieldName (const wxString &aName) const
 Function HasFieldName checks for aName in the the template field name list. More...
 

Private Attributes

TEMPLATE_FIELDNAMES m_Fields
 

Detailed Description

Definition at line 129 of file template_fieldnames.h.

Member Function Documentation

int TEMPLATES::AddTemplateFieldName ( const TEMPLATE_FIELDNAME aFieldName)

Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames template.

Should be used for any symbol property editor. If the name already exists, it overwrites the same name.

Parameters
aFieldNameis a full description of the wanted field, and it must not match any of the default fieldnames.
Returns
int - the index within the config container at which aFieldName was added, or -1 if the name is illegal because it matches a default fieldname.

Definition at line 167 of file template_fieldnames.cpp.

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), TEMPLATE_FIELDNAME::m_Name, and MANDATORY_FIELDS.

Referenced by SCH_EDIT_FRAME::AddTemplateFieldName().

168 {
169  // Ensure that the template fieldname does not match a fixed fieldname.
170  for( int i=0; i<MANDATORY_FIELDS; ++i )
171  {
172  if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
173  {
174  return -1;
175  }
176  }
177 
178  // ensure uniqueness, overwrite any template fieldname by the same name.
179  for( unsigned i=0; i<m_Fields.size(); ++i )
180  {
181  if( m_Fields[i].m_Name == aFieldName.m_Name )
182  {
183  // DBG( printf( "inserting template fieldname:'%s' at %d\n",
184  // TO_UTF8( aFieldName.m_Name ), i ); )
185 
186  m_Fields[i] = aFieldName;
187  return i; // return the container index
188  }
189  }
190 
191  // DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );)
192 
193  // the name is legal and not previously added to the config container, append
194  // it and return its index within the container.
195  m_Fields.push_back( aFieldName );
196 
197  return m_Fields.size() - 1; // return the index of insertion.
198 }
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
static const wxString GetDefaultFieldName(int aFieldNdx)
Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all componen...
wxString m_Name
The field name.
TEMPLATE_FIELDNAMES m_Fields
void TEMPLATES::DeleteAllTemplateFieldNames ( )
inline

Function DeleteAllTemplateFieldNames deletes the entire contents.

Definition at line 166 of file template_fieldnames.h.

Referenced by SCH_EDIT_FRAME::DeleteAllTemplateFieldNames().

167  {
168  m_Fields.clear();
169  }
TEMPLATE_FIELDNAMES m_Fields
void TEMPLATES::Format ( OUTPUTFORMATTER out,
int  nestLevel 
) const

Function Format serializes this object out as text into the given OUTPUTFORMATTER.

Definition at line 115 of file template_fieldnames.cpp.

References Format(), and OUTPUTFORMATTER::Print().

Referenced by SCH_EDIT_FRAME::SaveSettings().

116 {
117  // We'll keep this general, and include the \n, even though the only known
118  // use at this time will not want the newlines or the indentation.
119  out->Print( nestLevel, "(templatefields" );
120 
121  for( unsigned i=0; i<m_Fields.size(); ++i )
122  m_Fields[i].Format( out, nestLevel+1 );
123 
124  out->Print( 0, ")\n" );
125 }
TEMPLATE_FIELDNAMES m_Fields
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Function Format serializes this object out as text into the given OUTPUTFORMATTER.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
const TEMPLATE_FIELDNAMES& TEMPLATES::GetTemplateFieldNames ( )
inline

Function GetTemplateFieldName returns a template fieldnames list for read only access.

Definition at line 175 of file template_fieldnames.h.

References m_Fields.

Referenced by SCH_EDIT_FRAME::GetTemplateFieldNames(), and SCH_EDIT_FRAME::OnPreferencesOptions().

176  {
177  return m_Fields;
178  }
TEMPLATE_FIELDNAMES m_Fields
bool TEMPLATES::HasFieldName ( const wxString &  aName) const

Function HasFieldName checks for aName in the the template field name list.

Parameters
aNameA wxString object containing the field name to search for.
Returns
True if aName is found in the list.

Definition at line 201 of file template_fieldnames.cpp.

Referenced by DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick().

202 {
203  for( size_t i=0; i<m_Fields.size(); ++i )
204  {
205  if( m_Fields[i].m_Name == aName )
206  return true;
207  }
208 
209  return false;
210 }
TEMPLATE_FIELDNAMES m_Fields
void TEMPLATES::Parse ( TEMPLATE_FIELDNAMES_LEXER in)

Function Parse fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER.

Definition at line 128 of file template_fieldnames.cpp.

References DSNLEXER::CurText(), TEMPLATE_FIELDNAMES_LEXER::NextTok(), TEMPLATE_FIELDNAME::Parse(), TFIELD_T::T_EOF, TFIELD_T::T_field, TFIELD_T::T_LEFT, TFIELD_T::T_RIGHT, TFIELD_T::T_templatefields, and DSNLEXER::Unexpected().

Referenced by SCH_EDIT_FRAME::LoadSettings().

129 {
130  T tok;
131 
132  while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
133  {
134  if( tok == T_LEFT )
135  tok = in->NextTok();
136 
137  switch( tok )
138  {
139  case T_templatefields: // a token indicating class TEMPLATES.
140 
141  // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
142  // stream. Caller may not have read the first two tokens out of the
143  // stream: T_LEFT and T_templatefields, so ignore them if seen here.
144  break;
145 
146  case T_field:
147  {
148  // instantiate on stack, so if exception is thrown,
149  // destructor runs
150  TEMPLATE_FIELDNAME field;
151 
152  field.Parse( in );
153 
154  // add the field
155  AddTemplateFieldName( field );
156  }
157  break;
158 
159  default:
160  in->Unexpected( in->CurText() );
161  break;
162  }
163  }
164 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:369
void Parse(TEMPLATE_FIELDNAMES_LEXER *aSpec)
Function Parse fills this object from information in the input stream aSpec, which is a TEMPLATE_FIEL...
int AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName)
Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames templ...
T
enum T contains all this lexer's tokens.
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility...
TFIELD_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479

Member Data Documentation

TEMPLATE_FIELDNAMES TEMPLATES::m_Fields
private

Definition at line 132 of file template_fieldnames.h.

Referenced by GetTemplateFieldNames().


The documentation for this class was generated from the following files: