KiCad PCB EDA Suite
TEMPLATES Class Reference

#include <template_fieldnames.h>

Public Member Functions

 TEMPLATES ()
 
void Format (OUTPUTFORMATTER *out, int nestLevel, bool aGlobal) const
 Serialize this object out as text into the given OUTPUTFORMATTER. More...
 
void Parse (TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
 Fill this object from information in the input stream handled by #TEMPLATE_FIELDNAMES_LEXER. More...
 
void AddTemplateFieldName (const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
 Insert or append a wanted symbol field name into the field names template. More...
 
void DeleteAllFieldNameTemplates (bool aGlobal)
 Delete the entire contents. More...
 
const TEMPLATE_FIELDNAMESGetTemplateFieldNames ()
 Return a template field name list for read only access. More...
 
const TEMPLATE_FIELDNAMESGetTemplateFieldNames (bool aGlobal)
 Return a specific list (global or project) for read only access. More...
 
const TEMPLATE_FIELDNAMEGetFieldName (const wxString &aName)
 Search for aName in the the template field name list. More...
 

Protected Member Functions

void resolveTemplates ()
 

Private Attributes

TEMPLATE_FIELDNAMES m_globals
 
TEMPLATE_FIELDNAMES m_project
 
TEMPLATE_FIELDNAMES m_resolved
 
bool m_resolvedDirty
 

Detailed Description

Definition at line 118 of file template_fieldnames.h.

Constructor & Destructor Documentation

◆ TEMPLATES()

TEMPLATES::TEMPLATES ( )
inline

Definition at line 121 of file template_fieldnames.h.

121  :
122  m_resolvedDirty( true )
123  { }

Member Function Documentation

◆ AddTemplateFieldName()

void TEMPLATES::AddTemplateFieldName ( const TEMPLATE_FIELDNAME aFieldName,
bool  aGlobal 
)

Insert or append a wanted symbol field name into the field names 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 field names.
aGlobalindicates whether to add to the global or project table.

Definition at line 225 of file template_fieldnames.cpp.

226 {
227  // Ensure that the template fieldname does not match a fixed fieldname.
228  for( int i = 0; i < MANDATORY_FIELDS; ++i )
229  {
230  if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
231  return;
232  }
233 
234  TEMPLATE_FIELDNAMES& target = aGlobal ? m_globals : m_project;
235 
236  // ensure uniqueness, overwrite any template fieldname by the same name.
237  for( TEMPLATE_FIELDNAME& temp : target )
238  {
239  if( temp.m_Name == aFieldName.m_Name )
240  {
241  temp = aFieldName;
242  m_resolvedDirty = true;
243  return;
244  }
245  }
246 
247  // the name is legal and not previously added to the config container, append
248  // it and return its index within the container.
249  target.push_back( aFieldName );
250  m_resolvedDirty = true;
251 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslate=true)
Return a default symbol field name for field aFieldNdx for all components.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Hold a name of a symbol's field, field value, and default visibility.

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

Referenced by SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow().

◆ DeleteAllFieldNameTemplates()

void TEMPLATES::DeleteAllFieldNameTemplates ( bool  aGlobal)

Delete the entire contents.

Definition at line 254 of file template_fieldnames.cpp.

255 {
256  if( aGlobal )
257  {
258  m_globals.clear();
260  }
261  else
262  {
263  m_project.clear();
265  }
266 
267  m_resolvedDirty = false;
268 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
TEMPLATE_FIELDNAMES m_resolved

Referenced by SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), and PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow().

◆ Format()

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

Serialize this object out as text into the given OUTPUTFORMATTER.

Definition at line 145 of file template_fieldnames.cpp.

146 {
147  // We'll keep this general, and include the \n, even though the only known
148  // use at this time will not want the newlines or the indentation.
149  out->Print( nestLevel, "(templatefields" );
150 
151  const TEMPLATE_FIELDNAMES& source = aGlobal ? m_globals : m_project;
152 
153  for( const TEMPLATE_FIELDNAME& temp : source )
154  temp.Format( out, nestLevel+1 );
155 
156  out->Print( 0, ")\n" );
157 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
Hold a name of a symbol's field, field value, and default visibility.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408

References OUTPUTFORMATTER::Print().

Referenced by PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow().

◆ GetFieldName()

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

Search for aName in the the template field name list.

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

Definition at line 289 of file template_fieldnames.cpp.

290 {
291  if( m_resolvedDirty )
293 
294  for( const TEMPLATE_FIELDNAME& field : m_resolved )
295  {
296  if( field.m_Name == aName )
297  return &field;
298  }
299 
300  return nullptr;
301 }
TEMPLATE_FIELDNAMES m_resolved
Hold a name of a symbol's field, field value, and default visibility.

Referenced by FIELDS_GRID_TABLE< SCH_FIELD >::GetAttr().

◆ GetTemplateFieldNames() [1/2]

const TEMPLATE_FIELDNAMES & TEMPLATES::GetTemplateFieldNames ( )

◆ GetTemplateFieldNames() [2/2]

const TEMPLATE_FIELDNAMES & TEMPLATES::GetTemplateFieldNames ( bool  aGlobal)

Return a specific list (global or project) for read only access.

Definition at line 280 of file template_fieldnames.cpp.

281 {
282  if( aGlobal )
283  return m_globals;
284  else
285  return m_project;
286 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals

◆ Parse()

void TEMPLATES::Parse ( TEMPLATE_FIELDNAMES_LEXER *  in,
bool  aGlobal 
)

Fill this object from information in the input stream handled by #TEMPLATE_FIELDNAMES_LEXER.

Definition at line 160 of file template_fieldnames.cpp.

161 {
162  T tok;
163 
164  while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
165  {
166  if( tok == T_LEFT )
167  tok = in->NextTok();
168 
169  switch( tok )
170  {
171  case T_templatefields: // a token indicating class TEMPLATES.
172 
173  // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
174  // stream. Caller may not have read the first two tokens out of the
175  // stream: T_LEFT and T_templatefields, so ignore them if seen here.
176  break;
177 
178  case T_field:
179  {
180  // instantiate on stack, so if exception is thrown,
181  // destructor runs
182  TEMPLATE_FIELDNAME field;
183 
184  field.Parse( in );
185 
186  // add the field
187  AddTemplateFieldName( field, aGlobal );
188  }
189  break;
190 
191  default:
192  in->Unexpected( in->CurText() );
193  break;
194  }
195  }
196 }
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Insert or append a wanted symbol field name into the field names template.
void Parse(TEMPLATE_FIELDNAMES_LEXER *aSpec)
Fill this object from information in the input stream aSpec, which is a #TEMPLATE_FIELDNAMES_LEXER.
Hold a name of a symbol's field, field value, and default visibility.

References TEMPLATE_FIELDNAME::Parse().

Referenced by SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS().

◆ resolveTemplates()

void TEMPLATES::resolveTemplates ( )
protected

Definition at line 203 of file template_fieldnames.cpp.

204 {
206 
207  // Note: order N^2 algorithm. Would need changing if fieldname template sets ever
208  // get large.
209 
210  for( const TEMPLATE_FIELDNAME& global : m_globals )
211  {
212  for( const TEMPLATE_FIELDNAME& project : m_project )
213  {
214  if( global.m_Name == project.m_Name )
215  continue;
216  }
217 
218  m_resolved.push_back( global );
219  }
220 
221  m_resolvedDirty = false;
222 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
TEMPLATE_FIELDNAMES m_resolved
Hold a name of a symbol's field, field value, and default visibility.

References project.

Member Data Documentation

◆ m_globals

TEMPLATE_FIELDNAMES TEMPLATES::m_globals
private

Definition at line 176 of file template_fieldnames.h.

◆ m_project

TEMPLATE_FIELDNAMES TEMPLATES::m_project
private

Definition at line 177 of file template_fieldnames.h.

◆ m_resolved

TEMPLATE_FIELDNAMES TEMPLATES::m_resolved
private

Definition at line 180 of file template_fieldnames.h.

◆ m_resolvedDirty

bool TEMPLATES::m_resolvedDirty
private

Definition at line 181 of file template_fieldnames.h.


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