KiCad PCB EDA Suite
TEMPLATES Class Reference

#include <template_fieldnames.h>

Public Member Functions

 TEMPLATES ()
 
void Format (OUTPUTFORMATTER *out, int nestLevel, bool aGlobal) const
 Function Format serializes this object out as text into the given OUTPUTFORMATTER. More...
 
void Parse (TEMPLATE_FIELDNAMES_LEXER *in, bool aGlobal)
 Function Parse fills this object from information in the input stream handled by TEMPLATE_FIELDNAMES_LEXER. More...
 
void AddTemplateFieldName (const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
 Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames template. More...
 
void DeleteAllFieldNameTemplates (bool aGlobal)
 Function DeleteAllFieldNameTemplates deletes the entire contents. More...
 
const TEMPLATE_FIELDNAMESGetTemplateFieldNames ()
 Function GetTemplateFieldName returns a template fieldnames list for read only access. More...
 
const TEMPLATE_FIELDNAMESGetTemplateFieldNames (bool aGlobal)
 Function GetTemplateFieldName returns a specific list (global or project) for read only access. More...
 
const TEMPLATE_FIELDNAMEGetFieldName (const wxString &aName)
 Function GetFieldName searches 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 130 of file template_fieldnames.h.

Constructor & Destructor Documentation

◆ TEMPLATES()

TEMPLATES::TEMPLATES ( )
inline

Definition at line 141 of file template_fieldnames.h.

141  :
142  m_resolvedDirty( true )
143  { }

Member Function Documentation

◆ AddTemplateFieldName()

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

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.
aGlobalindicates whether to add to the global or project table.

Definition at line 205 of file template_fieldnames.cpp.

206 {
207  // Ensure that the template fieldname does not match a fixed fieldname.
208  for( int i = 0; i < MANDATORY_FIELDS; ++i )
209  {
210  if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
211  return;
212  }
213 
214  TEMPLATE_FIELDNAMES& target = aGlobal ? m_globals : m_project;
215 
216  // ensure uniqueness, overwrite any template fieldname by the same name.
217  for( TEMPLATE_FIELDNAME& temp : target )
218  {
219  if( temp.m_Name == aFieldName.m_Name )
220  {
221  temp = aFieldName;
222  m_resolvedDirty = true;
223  return;
224  }
225  }
226 
227  // the name is legal and not previously added to the config container, append
228  // it and return its index within the container.
229  target.push_back( aFieldName );
230  m_resolvedDirty = true;
231 }
TEMPLATE_FIELDNAMES m_project
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...
TEMPLATE_FIELDNAMES m_globals
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

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

Referenced by SCH_EDIT_FRAME::AddTemplateFieldName(), and SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS().

◆ DeleteAllFieldNameTemplates()

void TEMPLATES::DeleteAllFieldNameTemplates ( bool  aGlobal)

Function DeleteAllFieldNameTemplates deletes the entire contents.

Definition at line 234 of file template_fieldnames.cpp.

235 {
236  if( aGlobal )
237  {
238  m_globals.clear();
240  }
241  else
242  {
243  m_project.clear();
245  }
246 
247  m_resolvedDirty = false;
248 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
TEMPLATE_FIELDNAMES m_resolved

Referenced by SCH_EDIT_FRAME::DeleteAllTemplateFieldNames(), and SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS().

◆ Format()

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

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

Definition at line 125 of file template_fieldnames.cpp.

126 {
127  // We'll keep this general, and include the \n, even though the only known
128  // use at this time will not want the newlines or the indentation.
129  out->Print( nestLevel, "(templatefields" );
130 
131  const TEMPLATE_FIELDNAMES& source = aGlobal ? m_globals : m_project;
132 
133  for( const TEMPLATE_FIELDNAME& temp : source )
134  temp.Format( out, nestLevel+1 );
135 
136  out->Print( 0, ")\n" );
137 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404

References OUTPUTFORMATTER::Print().

Referenced by PARAM_CFG_FIELDNAMES::SaveParam(), and SCH_BASE_FRAME::SaveSettings().

◆ GetFieldName()

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

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

270 {
271  if( m_resolvedDirty )
273 
274  for( const TEMPLATE_FIELDNAME& field : m_resolved )
275  {
276  if( field.m_Name == aName )
277  return &field;
278  }
279 
280  return nullptr;
281 }
TEMPLATE_FIELDNAMES m_resolved
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

Referenced by SCH_BASE_FRAME::GetTemplateFieldName().

◆ GetTemplateFieldNames() [1/2]

const TEMPLATE_FIELDNAMES & TEMPLATES::GetTemplateFieldNames ( )

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

Definition at line 251 of file template_fieldnames.cpp.

252 {
253  if( m_resolvedDirty )
255 
256  return m_resolved;
257 }
TEMPLATE_FIELDNAMES m_resolved

Referenced by SCH_BASE_FRAME::GetTemplateFieldNames(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::ImportSettingsFrom(), and SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS().

◆ GetTemplateFieldNames() [2/2]

const TEMPLATE_FIELDNAMES & TEMPLATES::GetTemplateFieldNames ( bool  aGlobal)

Function GetTemplateFieldName returns a specific list (global or project) for read only access.

Definition at line 260 of file template_fieldnames.cpp.

261 {
262  if( aGlobal )
263  return m_globals;
264  else
265  return m_project;
266 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals

◆ Parse()

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

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

Definition at line 140 of file template_fieldnames.cpp.

141 {
142  T tok;
143 
144  while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
145  {
146  if( tok == T_LEFT )
147  tok = in->NextTok();
148 
149  switch( tok )
150  {
151  case T_templatefields: // a token indicating class TEMPLATES.
152 
153  // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
154  // stream. Caller may not have read the first two tokens out of the
155  // stream: T_LEFT and T_templatefields, so ignore them if seen here.
156  break;
157 
158  case T_field:
159  {
160  // instantiate on stack, so if exception is thrown,
161  // destructor runs
162  TEMPLATE_FIELDNAME field;
163 
164  field.Parse( in );
165 
166  // add the field
167  AddTemplateFieldName( field, aGlobal );
168  }
169  break;
170 
171  default:
172  in->Unexpected( in->CurText() );
173  break;
174  }
175  }
176 }
void AddTemplateFieldName(const TEMPLATE_FIELDNAME &aFieldName, bool aGlobal)
Function AddTemplateFieldName inserts or appends a wanted symbol field name into the fieldnames templ...
void Parse(TEMPLATE_FIELDNAMES_LEXER *aSpec)
Function Parse fills this object from information in the input stream aSpec, which is a TEMPLATE_FIEL...
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

References TEMPLATE_FIELDNAME::Parse().

Referenced by SCH_BASE_FRAME::LoadSettings(), and PARAM_CFG_FIELDNAMES::ReadParam().

◆ resolveTemplates()

void TEMPLATES::resolveTemplates ( )
protected

Definition at line 183 of file template_fieldnames.cpp.

184 {
186 
187  // Note: order N^2 algorithm. Would need changing if fieldname template sets ever
188  // get large.
189 
190  for( const TEMPLATE_FIELDNAME& global : m_globals )
191  {
192  for( const TEMPLATE_FIELDNAME& project : m_project )
193  {
194  if( global.m_Name == project.m_Name )
195  continue;
196  }
197 
198  m_resolved.push_back( global );
199  }
200 
201  m_resolvedDirty = false;
202 }
TEMPLATE_FIELDNAMES m_project
TEMPLATE_FIELDNAMES m_globals
TEMPLATE_FIELDNAMES m_resolved
Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

Member Data Documentation

◆ m_globals

TEMPLATE_FIELDNAMES TEMPLATES::m_globals
private

Definition at line 133 of file template_fieldnames.h.

◆ m_project

TEMPLATE_FIELDNAMES TEMPLATES::m_project
private

Definition at line 134 of file template_fieldnames.h.

◆ m_resolved

TEMPLATE_FIELDNAMES TEMPLATES::m_resolved
private

Definition at line 137 of file template_fieldnames.h.

◆ m_resolvedDirty

bool TEMPLATES::m_resolvedDirty
private

Definition at line 138 of file template_fieldnames.h.


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