KiCad PCB EDA Suite
TEMPLATE_FIELDNAME Struct Reference

Struct TEMPLATE_FIELDNAME holds a name of a component'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
 Function Format serializes this object out as text into the given OUTPUTFORMATTER. More...
 
void Parse (TEMPLATE_FIELDNAMES_LEXER *aSpec)
 Function Parse fills 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)
 Function GetDefaultFieldName returns 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

Struct TEMPLATE_FIELDNAME holds a name of a component's field, field value, and default visibility.

Template fieldnames are wanted fieldnames for use in the symbol/component property editors.

Definition at line 70 of file template_fieldnames.h.

Constructor & Destructor Documentation

◆ TEMPLATE_FIELDNAME() [1/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( )
inline

Definition at line 76 of file template_fieldnames.h.

76  :
77  m_Visible( false ),
78  m_URL( false )
79  {
80  }

◆ TEMPLATE_FIELDNAME() [2/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const wxString &  aName)
inline

Definition at line 82 of file template_fieldnames.h.

82  :
83  m_Name( aName ),
84  m_Visible( false ),
85  m_URL( false )
86  {
87  }

◆ TEMPLATE_FIELDNAME() [3/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const TEMPLATE_FIELDNAME ref)
inline

Definition at line 89 of file template_fieldnames.h.

90  {
91  m_Name = ref.m_Name;
92  m_Visible = ref.m_Visible;
93  m_URL = ref.m_URL;
94  }

References m_Name, m_URL, and m_Visible.

Member Function Documentation

◆ Format()

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

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

Definition at line 86 of file template_fieldnames.cpp.

87 {
88  out->Print( nestLevel, "(field (name %s)", out->Quotew( m_Name ).c_str() );
89 
90  if( m_Visible )
91  out->Print( 0, " visible" );
92 
93  if( m_URL )
94  out->Print( 0, " url" );
95 
96  out->Print( 0, ")\n" );
97 }
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:476
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408

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

◆ GetDefaultFieldName()

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

Function GetDefaultFieldName returns a default symbol field name for field aFieldNdx for all components.

These fieldnames are not modifiable, but template fieldnames are.

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

Definition at line 36 of file template_fieldnames.cpp.

37 {
38  static void* locale = nullptr;
39  static wxString referenceDefault;
40  static wxString valueDefault;
41  static wxString footprintDefault;
42  static wxString datasheetDefault;
43  static wxString fieldDefault;
44 
45  if( !aTranslate )
46  {
47  switch( aFieldNdx )
48  {
49  case REFERENCE: return REFCANONICAL; // The component reference, R1, C1, etc.
50  case VALUE: return VALCANONICAL; // The component value + name
51  case FOOTPRINT: return FTPCANONICAL; // The footprint for use with Pcbnew
52  case DATASHEET: return DSHCANONICAL; // Link to a datasheet for component
53  }
54  }
55 
56  // Fetching translations can take a surprising amount of time when loading libraries,
57  // so only do it when necessary.
58  if( Pgm().GetLocale() != locale )
59  {
60  referenceDefault = _( REFCANONICAL );
61  valueDefault = _( VALCANONICAL );
62  footprintDefault = _( FTPCANONICAL );
63  datasheetDefault = _( DSHCANONICAL );
64  fieldDefault = _( "Field%d" );
65  locale = Pgm().GetLocale();
66  }
67 
68  // Fixed values for the mandatory fields
69  switch( aFieldNdx )
70  {
71  case REFERENCE: return referenceDefault; // The component reference, R1, C1, etc.
72  case VALUE: return valueDefault; // The component value + name
73  case FOOTPRINT: return footprintDefault; // The footprint for use with Pcbnew
74  case DATASHEET: return datasheetDefault; // Link to a datasheet for component
75  default: return wxString::Format( fieldDefault, aFieldNdx );
76  }
77 
78 }
name of datasheet
#define DSHCANONICAL
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:102
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
#define VALCANONICAL
Field Value of part, i.e. "3.3K".
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
#define _(s)
Definition: 3d_actions.cpp:33
#define REFCANONICAL
#define FTPCANONICAL

References _, DATASHEET, DSHCANONICAL, FOOTPRINT, Format(), FTPCANONICAL, Pgm(), REFCANONICAL, REFERENCE, VALCANONICAL, and VALUE.

Referenced by TEMPLATES::AddTemplateFieldName(), DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS(), 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(), and SCH_LEGACY_PLUGIN_CACHE::saveField().

◆ Parse()

void TEMPLATE_FIELDNAME::Parse ( TEMPLATE_FIELDNAMES_LEXER *  aSpec)

Function Parse fills 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 100 of file template_fieldnames.cpp.

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

References FROM_UTF8().

Referenced by TEMPLATES::Parse().

Member Data Documentation

◆ m_Name

wxString TEMPLATE_FIELDNAME::m_Name

Definition at line 72 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: