KiCad PCB EDA Suite
TEMPLATE_FIELDNAME Struct Reference

Hold a name of a symbol's field, field value, and default visibility. More...

#include <template_fieldnames.h>

Public Member Functions

 TEMPLATE_FIELDNAME ()
 
 TEMPLATE_FIELDNAME (const wxString &aName)
 
 TEMPLATE_FIELDNAME (const TEMPLATE_FIELDNAME &ref)
 
void Format (OUTPUTFORMATTER *out, int nestLevel) const
 Serialize this object out as text into the given OUTPUTFORMATTER. More...
 
void Parse (TEMPLATE_FIELDNAMES_LEXER *aSpec)
 Fill this object from information in the input stream aSpec, which is a #TEMPLATE_FIELDNAMES_LEXER. More...
 

Static Public Member Functions

static const wxString GetDefaultFieldName (int aFieldNdx, bool aTranslate=true)
 Return a default symbol field name for field aFieldNdx for all components. More...
 

Public Attributes

wxString m_Name
 
bool m_Visible
 
bool m_URL
 

Detailed Description

Hold a name of a symbol's field, field value, and default visibility.

Template fieldnames are wanted field names for use in the symbol property editors.

Definition at line 59 of file template_fieldnames.h.

Constructor & Destructor Documentation

◆ TEMPLATE_FIELDNAME() [1/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( )
inline

Definition at line 61 of file template_fieldnames.h.

61  :
62  m_Visible( false ),
63  m_URL( false )
64  {
65  }

◆ TEMPLATE_FIELDNAME() [2/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const wxString &  aName)
inline

Definition at line 67 of file template_fieldnames.h.

67  :
68  m_Name( aName ),
69  m_Visible( false ),
70  m_URL( false )
71  {
72  }

◆ TEMPLATE_FIELDNAME() [3/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const TEMPLATE_FIELDNAME ref)
inline

Definition at line 74 of file template_fieldnames.h.

75  {
76  m_Name = ref.m_Name;
77  m_Visible = ref.m_Visible;
78  m_URL = ref.m_URL;
79  }

References m_Name, m_URL, and m_Visible.

Member Function Documentation

◆ Format()

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

Serialize this object out as text into the given OUTPUTFORMATTER.

Definition at line 94 of file template_fieldnames.cpp.

95 {
96  out->Print( nestLevel, "(field (name %s)", out->Quotew( m_Name ).c_str() );
97 
98  if( m_Visible )
99  out->Print( 0, " visible" );
100 
101  if( m_URL )
102  out->Print( 0, " url" );
103 
104  out->Print( 0, ")\n" );
105 }
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:408
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:476

References OUTPUTFORMATTER::Print(), and OUTPUTFORMATTER::Quotew().

◆ GetDefaultFieldName()

const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName ( int  aFieldNdx,
bool  aTranslate = true 
)
static

Return a default symbol field name for field aFieldNdx for all components.

These field names are not modifiable but template field names are.

Parameters
aFieldNdxThe field number index, > 0.
aTranslateIf true, return the translated field name, else get the canonical name.

Definition at line 40 of file template_fieldnames.cpp.

41 {
42  static void* locale = nullptr;
43  static wxString referenceDefault;
44  static wxString valueDefault;
45  static wxString footprintDefault;
46  static wxString datasheetDefault;
47  static wxString fieldDefault;
48 
49  if( !aTranslate )
50  {
51  switch( aFieldNdx )
52  {
53  case REFERENCE_FIELD: return REFCANONICAL; // The component reference, R1, C1, etc.
54  case VALUE_FIELD: return VALCANONICAL; // The component value + name
55  case FOOTPRINT_FIELD: return FTPCANONICAL; // The footprint for use with Pcbnew
56  case DATASHEET_FIELD: return DSHCANONICAL; // Link to a datasheet for component
57  }
58  }
59 
60  // Mutex protection is needed so that multiple loader threads don't write to the static variables
61  // at once
62  std::lock_guard<std::mutex> lock( s_defaultFieldMutex );
63 
64  // Fetching translations can take a surprising amount of time when loading libraries,
65  // so only do it when necessary.
66  if( Pgm().GetLocale() != locale )
67  {
68  referenceDefault = _( REFCANONICAL );
69  valueDefault = _( VALCANONICAL );
70  footprintDefault = _( FTPCANONICAL );
71  datasheetDefault = _( DSHCANONICAL );
72  fieldDefault = _( "Field%d" );
73  locale = Pgm().GetLocale();
74  }
75 
76  // Fixed values for the mandatory fields
77  switch( aFieldNdx )
78  {
79  case REFERENCE_FIELD: return referenceDefault; // The component reference, R1, C1, etc.
80  case VALUE_FIELD: return valueDefault; // The component value + name
81  case FOOTPRINT_FIELD: return footprintDefault; // The footprint for use with Pcbnew
82  case DATASHEET_FIELD: return datasheetDefault; // Link to a datasheet for component
83  default: return wxString::Format( fieldDefault, aFieldNdx );
84  }
85 
86 }
Field Reference of part, i.e. "IC21".
#define DSHCANONICAL
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
name of datasheet
#define VALCANONICAL
Field Value of part, i.e. "3.3K".
static std::mutex s_defaultFieldMutex
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
#define _(s)
Definition: 3d_actions.cpp:33
#define REFCANONICAL
#define FTPCANONICAL
Field Name Module PCB, i.e. "16DIP300".

References _, DATASHEET_FIELD, DSHCANONICAL, FOOTPRINT_FIELD, Format(), FTPCANONICAL, Pgm(), REFCANONICAL, REFERENCE_FIELD, s_defaultFieldMutex, VALCANONICAL, and VALUE_FIELD.

Referenced by TEMPLATES::AddTemplateFieldName(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), DIALOG_UPDATE_SYMBOL_FIELDS::DIALOG_UPDATE_SYMBOL_FIELDS(), FIELDS_EDITOR_GRID_DATA_MODEL::GetColLabelValue(), SCH_FIELD::GetName(), LIB_FIELD::GetName(), FIELDS_GRID_TABLE< SCH_FIELD >::GetValue(), LIB_FIELD::Init(), SCH_COMPONENT::Init(), SCH_LEGACY_PLUGIN::loadComponent(), SCH_LEGACY_PLUGIN_CACHE::loadField(), DIALOG_SYMBOL_PROPERTIES::OnAddField(), SCH_SEXPR_PLUGIN::saveField(), SCH_SEXPR_PLUGIN_CACHE::saveField(), and SCH_LEGACY_PLUGIN_CACHE::saveField().

◆ Parse()

void TEMPLATE_FIELDNAME::Parse ( TEMPLATE_FIELDNAMES_LEXER *  aSpec)

Fill this object from information in the input stream aSpec, which is a #TEMPLATE_FIELDNAMES_LEXER.

The entire textual element spec is
(field (name yourfieldname)(value yourvalue) visible)). The presence of value is optional, the presence of visible is optional. When this function is called, the input token stream given by aSpec is assumed to be positioned at the '^' in the following example, i.e. just after the identifying keyword and before the content specifying stuff.
(field ^ (....) ).

Parameters
aSpecis the input token stream of keywords and symbols.

Definition at line 108 of file template_fieldnames.cpp.

109 {
110  T tok;
111 
112  in->NeedLEFT(); // begin (name ...)
113 
114  if( ( tok = in->NextTok() ) != T_name )
115  in->Expecting( T_name );
116 
117  in->NeedSYMBOLorNUMBER();
118 
119  m_Name = FROM_UTF8( in->CurText() );
120 
121  in->NeedRIGHT(); // end (name ...)
122 
123  while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
124  {
125  // "visible" has no '(' prefix, "value" does, so T_LEFT is optional.
126  if( tok == T_LEFT )
127  tok = in->NextTok();
128 
129  switch( tok )
130  {
131  case T_value:
132  // older format; silently skip
133  in->NeedSYMBOLorNUMBER();
134  in->NeedRIGHT();
135  break;
136 
137  case T_visible:
138  m_Visible = true;
139  break;
140 
141  case T_url:
142  m_URL = true;
143  break;
144 
145  default:
146  in->Expecting( "value|url|visible" );
147  break;
148  }
149  }
150 }
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110

References FROM_UTF8().

Referenced by TEMPLATES::Parse().

Member Data Documentation

◆ m_Name

wxString TEMPLATE_FIELDNAME::m_Name

Definition at line 110 of file template_fieldnames.h.

Referenced by TEMPLATES::AddTemplateFieldName(), and TEMPLATE_FIELDNAME().

◆ m_URL

bool TEMPLATE_FIELDNAME::m_URL

◆ m_Visible


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