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

234 {
235  // Ensure that the template fieldname does not match a fixed fieldname.
236  for( int i = 0; i < MANDATORY_FIELDS; ++i )
237  {
238  if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
239  return;
240  }
241 
242  TEMPLATE_FIELDNAMES& target = aGlobal ? m_globals : m_project;
243 
244  // ensure uniqueness, overwrite any template fieldname by the same name.
245  for( TEMPLATE_FIELDNAME& temp : target )
246  {
247  if( temp.m_Name == aFieldName.m_Name )
248  {
249  temp = aFieldName;
250  m_resolvedDirty = true;
251  return;
252  }
253  }
254 
255  // the name is legal and not previously added to the config container, append
256  // it and return its index within the container.
257  target.push_back( aFieldName );
258  m_resolvedDirty = true;
259 }
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 262 of file template_fieldnames.cpp.

263 {
264  if( aGlobal )
265  {
266  m_globals.clear();
268  }
269  else
270  {
271  m_project.clear();
273  }
274 
275  m_resolvedDirty = false;
276 }
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 153 of file template_fieldnames.cpp.

154 {
155  // We'll keep this general, and include the \n, even though the only known
156  // use at this time will not want the newlines or the indentation.
157  out->Print( nestLevel, "(templatefields" );
158 
159  const TEMPLATE_FIELDNAMES& source = aGlobal ? m_globals : m_project;
160 
161  for( const TEMPLATE_FIELDNAME& temp : source )
162  temp.Format( out, nestLevel+1 );
163 
164  out->Print( 0, ")\n" );
165 }
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:426

References OUTPUTFORMATTER::Print().

Referenced by PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromWindow().

◆ GetFieldName()

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

Search for aName in 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 297 of file template_fieldnames.cpp.

298 {
299  if( m_resolvedDirty )
301 
302  for( const TEMPLATE_FIELDNAME& field : m_resolved )
303  {
304  if( field.m_Name == aName )
305  return &field;
306  }
307 
308  return nullptr;
309 }
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]

◆ GetTemplateFieldNames() [2/2]

const TEMPLATE_FIELDNAMES & TEMPLATES::GetTemplateFieldNames ( bool  aGlobal)

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

Definition at line 288 of file template_fieldnames.cpp.

289 {
290  if( aGlobal )
291  return m_globals;
292  else
293  return m_project;
294 }
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 168 of file template_fieldnames.cpp.

169 {
170  T tok;
171 
172  while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
173  {
174  if( tok == T_LEFT )
175  tok = in->NextTok();
176 
177  switch( tok )
178  {
179  case T_templatefields: // a token indicating class TEMPLATES.
180 
181  // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
182  // stream. Caller may not have read the first two tokens out of the
183  // stream: T_LEFT and T_templatefields, so ignore them if seen here.
184  break;
185 
186  case T_field:
187  {
188  // instantiate on stack, so if exception is thrown,
189  // destructor runs
190  TEMPLATE_FIELDNAME field;
191 
192  field.Parse( in );
193 
194  // add the field
195  AddTemplateFieldName( field, aGlobal );
196  }
197  break;
198 
199  default:
200  in->Unexpected( in->CurText() );
201  break;
202  }
203  }
204 }
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 211 of file template_fieldnames.cpp.

212 {
214 
215  // Note: order N^2 algorithm. Would need changing if fieldname template sets ever
216  // get large.
217 
218  for( const TEMPLATE_FIELDNAME& global : m_globals )
219  {
220  for( const TEMPLATE_FIELDNAME& project : m_project )
221  {
222  if( global.m_Name == project.m_Name )
223  continue;
224  }
225 
226  m_resolved.push_back( global );
227  }
228 
229  m_resolvedDirty = false;
230 }
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: