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 128 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 188 of file template_fieldnames.cpp.

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

Referenced by SCH_EDIT_FRAME::AddTemplateFieldName().

189 {
190  // Ensure that the template fieldname does not match a fixed fieldname.
191  for( int i=0; i<MANDATORY_FIELDS; ++i )
192  {
193  if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
194  {
195  return -1;
196  }
197  }
198 
199  // ensure uniqueness, overwrite any template fieldname by the same name.
200  for( unsigned i=0; i<m_Fields.size(); ++i )
201  {
202  if( m_Fields[i].m_Name == aFieldName.m_Name )
203  {
204  // DBG( printf( "inserting template fieldname:'%s' at %d\n",
205  // TO_UTF8( aFieldName.m_Name ), i ); )
206 
207  m_Fields[i] = aFieldName;
208  return i; // return the container index
209  }
210  }
211 
212  // DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );)
213 
214  // the name is legal and not previously added to the config container, append
215  // it and return its index within the container.
216  m_Fields.push_back( aFieldName );
217 
218  return m_Fields.size() - 1; // return the index of insertion.
219 }
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
size_t i
Definition: json11.cpp:597
void TEMPLATES::DeleteAllTemplateFieldNames ( )
inline

Function DeleteAllTemplateFieldNames deletes the entire contents.

Definition at line 165 of file template_fieldnames.h.

Referenced by SCH_EDIT_FRAME::DeleteAllTemplateFieldNames().

166  {
167  m_Fields.clear();
168  }
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 136 of file template_fieldnames.cpp.

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

137 {
138  // We'll keep this general, and include the \n, even though the only known
139  // use at this time will not want the newlines or the indentation.
140  out->Print( nestLevel, "(templatefields" );
141 
142  for( unsigned i=0; i<m_Fields.size(); ++i )
143  m_Fields[i].Format( out, nestLevel+1 );
144 
145  out->Print( 0, ")\n" );
146 }
TEMPLATE_FIELDNAMES m_Fields
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Function Format serializes this object out as text into the given OUTPUTFORMATTER.
size_t i
Definition: json11.cpp:597
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
const TEMPLATE_FIELDNAMES& TEMPLATES::GetTemplateFieldNames ( )
inline

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

Definition at line 174 of file template_fieldnames.h.

Referenced by SCH_EDIT_FRAME::GetTemplateFieldNames().

175  {
176  return m_Fields;
177  }
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 222 of file template_fieldnames.cpp.

References i.

Referenced by DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick().

223 {
224  for( size_t i=0; i<m_Fields.size(); ++i )
225  {
226  if( m_Fields[i].m_Name == aName )
227  return true;
228  }
229 
230  return false;
231 }
TEMPLATE_FIELDNAMES m_Fields
size_t i
Definition: json11.cpp:597
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 149 of file template_fieldnames.cpp.

References TEMPLATE_FIELDNAME::Parse().

150 {
151  T tok;
152 
153  while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
154  {
155  if( tok == T_LEFT )
156  tok = in->NextTok();
157 
158  switch( tok )
159  {
160  case T_templatefields: // a token indicating class TEMPLATES.
161 
162  // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
163  // stream. Caller may not have read the first two tokens out of the
164  // stream: T_LEFT and T_templatefields, so ignore them if seen here.
165  break;
166 
167  case T_field:
168  {
169  // instantiate on stack, so if exception is thrown,
170  // destructor runs
171  TEMPLATE_FIELDNAME field;
172 
173  field.Parse( in );
174 
175  // add the field
176  AddTemplateFieldName( field );
177  }
178  break;
179 
180  default:
181  in->Unexpected( in->CurText() );
182  break;
183  }
184  }
185 }
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...
Struct TEMPLATE_FIELDNAME holds a name of a component&#39;s field, field value, and default visibility...

Member Data Documentation

TEMPLATE_FIELDNAMES TEMPLATES::m_Fields
private

Definition at line 131 of file template_fieldnames.h.


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