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 () const
 Function GetTemplateFieldName returns a template fieldnames list for read only access. More...
 
const TEMPLATE_FIELDNAMEGetFieldName (const wxString &aName) const
 Function GetFieldName searches for aName in the the template field name list. More...
 

Private Attributes

TEMPLATE_FIELDNAMES m_Fields
 

Detailed Description

Definition at line 130 of file template_fieldnames.h.

Member Function Documentation

◆ AddTemplateFieldName()

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

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

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

Referenced by SCH_EDIT_FRAME::AddTemplateFieldName().

◆ DeleteAllTemplateFieldNames()

void TEMPLATES::DeleteAllTemplateFieldNames ( )
inline

Function DeleteAllTemplateFieldNames deletes the entire contents.

Definition at line 167 of file template_fieldnames.h.

168  {
169  m_Fields.clear();
170  }
TEMPLATE_FIELDNAMES m_Fields

References m_Fields.

Referenced by SCH_EDIT_FRAME::DeleteAllTemplateFieldNames().

◆ Format()

void TEMPLATES::Format ( OUTPUTFORMATTER out,
int  nestLevel 
) const

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

Definition at line 140 of file template_fieldnames.cpp.

141 {
142  // We'll keep this general, and include the \n, even though the only known
143  // use at this time will not want the newlines or the indentation.
144  out->Print( nestLevel, "(templatefields" );
145 
146  for( unsigned i=0; i<m_Fields.size(); ++i )
147  m_Fields[i].Format( out, nestLevel+1 );
148 
149  out->Print( 0, ")\n" );
150 }
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Function Format serializes this object out as text into the given OUTPUTFORMATTER.
TEMPLATE_FIELDNAMES m_Fields
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

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

Referenced by SCH_EDIT_FRAME::SaveSettings().

◆ GetFieldName()

const TEMPLATE_FIELDNAME * TEMPLATES::GetFieldName ( const wxString &  aName) const

Function GetFieldName searches for aName in the the template field name list.

Parameters
aNameA wxString object containing the field name to search for.
Returns
the template fieldname if found; NULL otherwise.

Definition at line 226 of file template_fieldnames.cpp.

227 {
228  for( const TEMPLATE_FIELDNAME& field : m_Fields )
229  {
230  if( field.m_Name == aName )
231  return &field;
232  }
233 
234  return nullptr;
235 }
TEMPLATE_FIELDNAMES m_Fields
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

Referenced by SCH_BASE_FRAME::GetTemplateFieldName().

◆ GetTemplateFieldNames()

const TEMPLATE_FIELDNAMES& TEMPLATES::GetTemplateFieldNames ( ) const
inline

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

Definition at line 176 of file template_fieldnames.h.

177  {
178  return m_Fields;
179  }
TEMPLATE_FIELDNAMES m_Fields

References m_Fields.

Referenced by SCH_BASE_FRAME::GetTemplateFieldNames().

◆ Parse()

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

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

References TEMPLATE_FIELDNAME::Parse().

Referenced by LIB_EDIT_FRAME::LoadSettings(), and SCH_EDIT_FRAME::LoadSettings().

Member Data Documentation

◆ m_Fields

TEMPLATE_FIELDNAMES TEMPLATES::m_Fields
private

Definition at line 133 of file template_fieldnames.h.

Referenced by DeleteAllTemplateFieldNames(), and GetTemplateFieldNames().


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