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

Constructor & Destructor Documentation

◆ TEMPLATE_FIELDNAME() [1/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( )
inline

Definition at line 77 of file template_fieldnames.h.

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

◆ TEMPLATE_FIELDNAME() [2/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const wxString &  aName)
inline

Definition at line 83 of file template_fieldnames.h.

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

◆ TEMPLATE_FIELDNAME() [3/3]

TEMPLATE_FIELDNAME::TEMPLATE_FIELDNAME ( const TEMPLATE_FIELDNAME ref)
inline

Definition at line 90 of file template_fieldnames.h.

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

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

67 {
68  out->Print( nestLevel, "(field (name %s)", out->Quotew( m_Name ).c_str() );
69 
70  if( m_Visible )
71  out->Print( 0, " visible" );
72 
73  if( m_URL )
74  out->Print( 0, " url" );
75 
76  out->Print( 0, ")\n" );
77 }
std::string Quotew(const wxString &aWrapee)
Definition: richio.cpp:472
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(), and OUTPUTFORMATTER::Quotew().

◆ GetDefaultFieldName()

const wxString TEMPLATE_FIELDNAME::GetDefaultFieldName ( int  aFieldNdx)
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

Definition at line 34 of file template_fieldnames.cpp.

35 {
36  static void* locale = nullptr;
37  static wxString referenceDefault;
38  static wxString valueDefault;
39  static wxString footprintDefault;
40  static wxString datasheetDefault;
41  static wxString fieldDefault;
42 
43  // Fetching translations can take a surprising amount of time when loading libraries,
44  // so only do it when necessary.
45  if( Pgm().GetLocale() != locale )
46  {
47  referenceDefault = _( "Reference" );
48  valueDefault = _( "Value" );
49  footprintDefault = _( "Footprint" );
50  datasheetDefault = _( "Datasheet" );
51  fieldDefault = _( "Field%d" );
52  locale = Pgm().GetLocale();
53  }
54 
55  // Fixed values for the mandatory fields
56  switch( aFieldNdx )
57  {
58  case REFERENCE: return referenceDefault; // The component reference, R1, C1, etc.
59  case VALUE: return valueDefault; // The component value + name
60  case FOOTPRINT: return footprintDefault; // The footprint for use with Pcbnew
61  case DATASHEET: return datasheetDefault; // Link to a datasheet for component
62  default: return wxString::Format( fieldDefault, aFieldNdx );
63  }
64 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
name of datasheet
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
#define VALUE
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:205
#define _(s)
Definition: 3d_actions.cpp:33

References _, DATASHEET, FOOTPRINT, Format(), Pgm(), REFERENCE, and VALUE.

Referenced by TEMPLATES::AddTemplateFieldName(), 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_EDIT_COMPONENT_IN_SCHEMATIC::OnAddField(), SCH_SEXPR_PLUGIN::saveField(), SCH_LEGACY_PLUGIN_CACHE::saveField(), and DIALOG_UPDATE_FIELDS::updateFields().

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

81 {
82  T tok;
83 
84  in->NeedLEFT(); // begin (name ...)
85 
86  if( (tok = in->NextTok()) != T_name )
87  in->Expecting( T_name );
88 
89  in->NeedSYMBOLorNUMBER();
90 
91  m_Name = FROM_UTF8( in->CurText() );
92 
93  in->NeedRIGHT(); // end (name ...)
94 
95  while( (tok = in->NextTok() ) != T_RIGHT && tok != T_EOF )
96  {
97  // "visible" has no '(' prefix, "value" does, so T_LEFT is optional.
98  if( tok == T_LEFT )
99  tok = in->NextTok();
100 
101  switch( tok )
102  {
103  case T_value:
104  // older format; silently skip
105  in->NeedSYMBOLorNUMBER();
106  in->NeedRIGHT();
107  break;
108 
109  case T_visible:
110  m_Visible = true;
111  break;
112 
113  case T_url:
114  m_URL = true;
115  break;
116 
117  default:
118  in->Expecting( "value|url|visible" );
119  break;
120  }
121  }
122 }
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:114

References FROM_UTF8().

Referenced by TEMPLATES::Parse().

Member Data Documentation

◆ m_Name

wxString TEMPLATE_FIELDNAME::m_Name

Definition at line 73 of file template_fieldnames.h.

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

◆ m_URL

bool TEMPLATE_FIELDNAME::m_URL

◆ m_Visible

bool TEMPLATE_FIELDNAME::m_Visible

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