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 122 of file template_fieldnames.h.

Constructor & Destructor Documentation

◆ TEMPLATES()

TEMPLATES::TEMPLATES ( )
inline

Definition at line 125 of file template_fieldnames.h.

125 :
126 m_resolvedDirty( true )
127 { }

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

204{
205 // Ensure that the template fieldname does not match a fixed fieldname.
206 for( int i = 0; i < MANDATORY_FIELDS; ++i )
207 {
208 if( TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) == aFieldName.m_Name )
209 return;
210 }
211
212 TEMPLATE_FIELDNAMES& target = aGlobal ? m_globals : m_project;
213
214 // ensure uniqueness, overwrite any template fieldname by the same name.
215 for( TEMPLATE_FIELDNAME& temp : target )
216 {
217 if( temp.m_Name == aFieldName.m_Name )
218 {
219 temp = aFieldName;
220 m_resolvedDirty = true;
221 return;
222 }
223 }
224
225 // the name is legal and not previously added to the config container, append
226 // it and return its index within the container.
227 target.push_back( aFieldName );
228 m_resolvedDirty = true;
229}
TEMPLATE_FIELDNAMES m_globals
TEMPLATE_FIELDNAMES m_project
Hold a name of a symbol's field, field value, and default visibility.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
std::vector< TEMPLATE_FIELDNAME > TEMPLATE_FIELDNAMES

References TEMPLATE_FIELDNAME::GetDefaultFieldName(), m_globals, TEMPLATE_FIELDNAME::m_Name, m_project, m_resolvedDirty, and MANDATORY_FIELDS.

Referenced by Parse(), SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), and PANEL_TEMPLATE_FIELDNAMES::TransferDataFromWindow().

◆ DeleteAllFieldNameTemplates()

void TEMPLATES::DeleteAllFieldNameTemplates ( bool  aGlobal)

Delete the entire contents.

Definition at line 232 of file template_fieldnames.cpp.

233{
234 if( aGlobal )
235 {
236 m_globals.clear();
238 }
239 else
240 {
241 m_project.clear();
243 }
244
245 m_resolvedDirty = false;
246}
TEMPLATE_FIELDNAMES m_resolved

References m_globals, m_project, m_resolved, and m_resolvedDirty.

Referenced by SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS(), and PANEL_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 123 of file template_fieldnames.cpp.

124{
125 // We'll keep this general, and include the \n, even though the only known
126 // use at this time will not want the newlines or the indentation.
127 out->Print( nestLevel, "(templatefields" );
128
129 const TEMPLATE_FIELDNAMES& source = aGlobal ? m_globals : m_project;
130
131 for( const TEMPLATE_FIELDNAME& temp : source )
132 temp.Format( out, nestLevel+1 );
133
134 out->Print( 0, ")\n" );
135}
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:431

References m_globals, m_project, and OUTPUTFORMATTER::Print().

Referenced by PANEL_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 267 of file template_fieldnames.cpp.

268{
269 if( m_resolvedDirty )
271
272 for( const TEMPLATE_FIELDNAME& field : m_resolved )
273 {
274 if( field.m_Name == aName )
275 return &field;
276 }
277
278 return nullptr;
279}

References m_resolved, m_resolvedDirty, and resolveTemplates().

Referenced by FIELDS_GRID_TABLE< T >::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 258 of file template_fieldnames.cpp.

259{
260 if( aGlobal )
261 return m_globals;
262 else
263 return m_project;
264}

References m_globals, and m_project.

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

139{
140 T tok;
141
142 while( ( tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
143 {
144 if( tok == T_LEFT )
145 tok = in->NextTok();
146
147 switch( tok )
148 {
149 case T_templatefields: // a token indicating class TEMPLATES.
150
151 // Be flexible regarding the starting point of the TEMPLATE_FIELDNAMES_LEXER
152 // stream. Caller may not have read the first two tokens out of the
153 // stream: T_LEFT and T_templatefields, so ignore them if seen here.
154 break;
155
156 case T_field:
157 {
158 // instantiate on stack, so if exception is thrown,
159 // destructor runs
160 TEMPLATE_FIELDNAME field;
161
162 field.Parse( in );
163
164 // add the field
165 AddTemplateFieldName( field, aGlobal );
166 }
167 break;
168
169 default:
170 in->Unexpected( in->CurText() );
171 break;
172 }
173 }
174}
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.

References AddTemplateFieldName(), and TEMPLATE_FIELDNAME::Parse().

Referenced by PANEL_TEMPLATE_FIELDNAMES::PANEL_TEMPLATE_FIELDNAMES(), and SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS().

◆ resolveTemplates()

void TEMPLATES::resolveTemplates ( )
protected

Definition at line 181 of file template_fieldnames.cpp.

182{
184
185 // Note: order N^2 algorithm. Would need changing if fieldname template sets ever
186 // get large.
187
188 for( const TEMPLATE_FIELDNAME& global : m_globals )
189 {
190 for( const TEMPLATE_FIELDNAME& project : m_project )
191 {
192 if( global.m_Name == project.m_Name )
193 continue;
194 }
195
196 m_resolved.push_back( global );
197 }
198
199 m_resolvedDirty = false;
200}

References m_globals, m_project, m_resolved, m_resolvedDirty, and project.

Referenced by GetFieldName(), and GetTemplateFieldNames().

Member Data Documentation

◆ m_globals

◆ m_project

◆ m_resolved

TEMPLATE_FIELDNAMES TEMPLATES::m_resolved
private

◆ m_resolvedDirty

bool TEMPLATES::m_resolvedDirty
private

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