KiCad PCB EDA Suite
FOOTPRINT_INFO_GENERATOR Class Reference

Public Member Functions

 FOOTPRINT_INFO_GENERATOR (SYMBOL_LIB_TABLE *aSymbolLibTable, LIB_ID const &aLibId, int aUnit)
 
void GenerateHtml ()
 Generate the HTML internally. More...
 
wxString GetHtml ()
 Return the generated HTML. More...
 
 FOOTPRINT_INFO_GENERATOR (FP_LIB_TABLE *aFpLibTable, LIB_ID const &aLibId)
 
void GenerateHtml ()
 Generate the HTML internally. More...
 
wxString GetHtml ()
 Return the generated HTML. More...
 

Protected Member Functions

void SetHtmlName ()
 
void SetHtmlAliasOf ()
 
void SetHtmlDesc ()
 
void SetHtmlKeywords ()
 
wxString GetHtmlFieldRow (LIB_FIELD const &aField)
 
void SetHtmlFieldTable ()
 

Private Attributes

wxString m_html
 
SYMBOL_LIB_TABLEm_sym_lib_table
 
LIB_ID const m_lib_id
 
LIB_PARTm_symbol
 
int m_unit
 
FP_LIB_TABLEm_fp_lib_table
 
MODULEm_module
 

Detailed Description

Definition at line 48 of file generate_alias_info.cpp.

Constructor & Destructor Documentation

◆ FOOTPRINT_INFO_GENERATOR() [1/2]

FOOTPRINT_INFO_GENERATOR::FOOTPRINT_INFO_GENERATOR ( SYMBOL_LIB_TABLE aSymbolLibTable,
LIB_ID const &  aLibId,
int  aUnit 
)
inline

Definition at line 57 of file generate_alias_info.cpp.

59  m_sym_lib_table( aSymbolLibTable ),
60  m_lib_id( aLibId ),
61  m_symbol( nullptr ),
62  m_unit( aUnit )
63  { }
static const wxString DescriptionFormat
SYMBOL_LIB_TABLE * m_sym_lib_table

◆ FOOTPRINT_INFO_GENERATOR() [2/2]

FOOTPRINT_INFO_GENERATOR::FOOTPRINT_INFO_GENERATOR ( FP_LIB_TABLE aFpLibTable,
LIB_ID const &  aLibId 
)
inline

Definition at line 55 of file generate_footprint_info.cpp.

57  m_fp_lib_table( aFpLibTable ),
58  m_lib_id( aLibId ),
59  m_module( nullptr )
60  { }
static const wxString DescriptionFormat

Member Function Documentation

◆ GenerateHtml() [1/2]

void FOOTPRINT_INFO_GENERATOR::GenerateHtml ( )
inline

Generate the HTML internally.

Definition at line 65 of file generate_footprint_info.cpp.

66  {
67  wxCHECK_RET( m_fp_lib_table, "Footprint library table pointer is not valid" );
68 
69  if( !m_lib_id.IsValid() )
70  return;
71 
72  try
73  {
76  }
77  catch( const IO_ERROR& ioe )
78  {
79  wxLogError( wxString::Format( _( "Error loading footprint %s from library %s.\n\n%s" ),
82  ioe.What() ) );
83  return;
84  }
85 
86  if( m_module )
87  {
88  wxString name = m_lib_id.GetLibItemName();
89  wxString desc = m_module->GetDescription();
90  wxString keywords = m_module->GetKeywords();
91  wxString doc;
92 
93  // It is currently common practice to store a documentation link in the description.
94  int idx = desc.find( wxT( "http:" ) );
95 
96  if( idx >= 0 )
97  {
98  doc = desc.substr( (unsigned) idx );
99 
100  desc = desc.substr( 0, (unsigned) idx );
101  desc = desc.Trim( true );
102 
103  if( !desc.IsEmpty() && desc.Last() == ',' )
104  desc.RemoveLast( 1 );
105  }
106 
107  m_html.Replace( "__NAME__", EscapedHTML( name ) );
108  m_html.Replace( "__DESC__", EscapedHTML( desc ) );
109 
110  wxString keywordsHtml = KeywordsFormat;
111  keywordsHtml.Replace( "__KEYWORDS__", EscapedHTML( keywords ) );
112 
113  wxString docHtml = DocFormat;
114  docHtml.Replace( "__HREF__", EscapedHTML( doc ) );
115 
116  if( doc.Length() > 75 )
117  doc = doc.Left( 72 ) + wxT( "..." );
118 
119  docHtml.Replace( "__TEXT__", EscapedHTML( doc ) );
120 
121  m_html.Replace( "__FIELDS__", keywordsHtml + docHtml );
122  }
123  }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
static const wxString KeywordsFormat
static const wxString DocFormat
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
bool IsValid() const
Definition: lib_id.h:171
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
const wxString & GetKeywords() const
Definition: class_module.h:234
const wxString & GetDescription() const
Definition: class_module.h:231
const char * name
Definition: DXF_plotter.cpp:60
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
wxString wx_str() const
Definition: utf8.cpp:51
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, DocFormat, EscapedHTML(), FP_LIB_TABLE::FootprintLoad(), Format(), MODULE::GetDescription(), MODULE::GetKeywords(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_ID::IsValid(), KeywordsFormat, m_fp_lib_table, m_html, m_lib_id, m_module, name, IO_ERROR::What(), and UTF8::wx_str().

◆ GenerateHtml() [2/2]

void FOOTPRINT_INFO_GENERATOR::GenerateHtml ( )
inline

Generate the HTML internally.

Definition at line 68 of file generate_alias_info.cpp.

69  {
70  wxCHECK_RET( m_sym_lib_table, "Symbol library table pointer is not valid" );
71 
72  if( !m_lib_id.IsValid() )
73  return;
74 
75  try
76  {
77  m_symbol = const_cast< LIB_PART* >( m_sym_lib_table->LoadSymbol( m_lib_id ) );
78  }
79  catch( const IO_ERROR& ioe )
80  {
81  wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
82  "\n\n%s" ),
85  ioe.What() ) );
86  return;
87  }
88 
89  if( m_symbol )
90  {
91  SetHtmlName();
93  SetHtmlDesc();
96  }
97  }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
bool IsValid() const
Definition: lib_id.h:171
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
SYMBOL_LIB_TABLE * m_sym_lib_table
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
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
wxString wx_str() const
Definition: utf8.cpp:51
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References _, Format(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_ID::IsValid(), SYMBOL_LIB_TABLE::LoadSymbol(), m_lib_id, m_sym_lib_table, m_symbol, SetHtmlAliasOf(), SetHtmlDesc(), SetHtmlFieldTable(), SetHtmlKeywords(), SetHtmlName(), IO_ERROR::What(), and UTF8::wx_str().

Referenced by GenerateAliasInfo(), and GenerateFootprintInfo().

◆ GetHtml() [1/2]

wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 102 of file generate_alias_info.cpp.

103  {
104  return m_html;
105  }

References m_html.

Referenced by GenerateAliasInfo(), and GenerateFootprintInfo().

◆ GetHtml() [2/2]

wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 128 of file generate_footprint_info.cpp.

129  {
130  return m_html;
131  }

References m_html.

◆ GetHtmlFieldRow()

wxString FOOTPRINT_INFO_GENERATOR::GetHtmlFieldRow ( LIB_FIELD const &  aField)
inlineprotected

Definition at line 160 of file generate_alias_info.cpp.

161  {
162  wxString name = aField.GetCanonicalName();
163  wxString text = aField.GetFullText( m_unit > 0 ? m_unit : 1 );
164  wxString fieldhtml = FieldFormat;
165 
166  fieldhtml.Replace( "__NAME__", EscapedHTML( name ) );
167 
168  switch( aField.GetId() )
169  {
170  case DATASHEET:
171  text = m_symbol->GetDatasheetField().GetText();
172 
173  if( text.IsEmpty() || text == wxT( "~" ) )
174  {
175  fieldhtml.Replace( "__VALUE__", text );
176  }
177  else
178  {
179  wxString datasheetlink = DatasheetLinkFormat;
180  datasheetlink.Replace( "__HREF__", EscapedHTML( text ) );
181 
182  if( text.Length() > 75 )
183  text = text.Left( 72 ) + wxT( "..." );
184 
185  datasheetlink.Replace( "__TEXT__", EscapedHTML( text ) );
186 
187  fieldhtml.Replace( "__VALUE__", datasheetlink );
188  }
189 
190  break;
191 
192  case VALUE:
193  // showing the value just repeats the name, so that's not much use...
194  return wxEmptyString;
195 
196  default:
197  fieldhtml.Replace( "__VALUE__", EscapedHTML( text ) );
198  }
199 
200  return fieldhtml;
201  }
name of datasheet
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341
Field Value of part, i.e. "3.3K".
const char * name
Definition: DXF_plotter.cpp:60
static const wxString FieldFormat
static const wxString DatasheetLinkFormat
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127

References DATASHEET, DatasheetLinkFormat, EscapedHTML(), FieldFormat, LIB_FIELD::GetCanonicalName(), LIB_PART::GetDatasheetField(), LIB_FIELD::GetFullText(), LIB_FIELD::GetId(), EDA_TEXT::GetText(), m_symbol, m_unit, name, and VALUE.

Referenced by SetHtmlFieldTable().

◆ SetHtmlAliasOf()

void FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf ( )
inlineprotected

Definition at line 114 of file generate_alias_info.cpp.

115  {
116  if( m_symbol->IsRoot() )
117  {
118  m_html.Replace( "__ALIASOF__", wxEmptyString );
119  }
120  else
121  {
122  wxString root_name = _( "Unknown" );
123  wxString root_desc = "";
124 
125  std::shared_ptr< LIB_PART > parent = m_symbol->GetParent().lock();
126 
127  if( parent )
128  {
129  root_name = parent->GetName();
130  root_desc = parent->GetDescription();
131  }
132 
133  m_html.Replace(
134  "__ALIASOF__", wxString::Format(
135  AliasOfFormat, EscapedHTML( root_name ), EscapedHTML( root_desc ) ) );
136  }
137  }
static const wxString AliasOfFormat
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341
PART_REF & GetParent()
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
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.

References _, AliasOfFormat, EscapedHTML(), Format(), LIB_PART::GetParent(), LIB_PART::IsRoot(), m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlDesc()

void FOOTPRINT_INFO_GENERATOR::SetHtmlDesc ( )
inlineprotected

Definition at line 140 of file generate_alias_info.cpp.

141  {
142  wxString raw_desc = m_symbol->GetDescription();
143 
144  m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapedHTML( raw_desc ) ) );
145  }
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341
static const wxString DescFormat
wxString GetDescription() override
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

References DescFormat, EscapedHTML(), Format(), LIB_PART::GetDescription(), m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlFieldTable()

void FOOTPRINT_INFO_GENERATOR::SetHtmlFieldTable ( )
inlineprotected

Definition at line 204 of file generate_alias_info.cpp.

205  {
206  wxString fieldtable;
207  LIB_FIELDS fields;
208  m_symbol->GetFields( fields );
209 
210  for( auto const & field: fields )
211  {
212  fieldtable += GetHtmlFieldRow( field );
213  }
214 
215  if( m_symbol->IsAlias() )
216  {
217  std::shared_ptr< LIB_PART > parent = m_symbol->GetParent().lock();
218 
219  // Append all of the unique parent fields if this is an alias.
220  if( parent )
221  {
222  LIB_FIELDS parentFields;
223 
224  parent->GetFields( parentFields );
225 
226  for( auto const& parentField : parentFields )
227  {
228  if( m_symbol->FindField( parentField.GetCanonicalName() ) )
229  continue;
230 
231  fieldtable += GetHtmlFieldRow( parentField );
232  }
233  }
234  }
235 
236  m_html.Replace( "__FIELDS__", fieldtable );
237  }
wxString GetHtmlFieldRow(LIB_FIELD const &aField)
LIB_FIELD * FindField(const wxString &aFieldName)
Find a field within this part matching aFieldName and returns it or NULL if not found.
PART_REF & GetParent()
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
bool IsAlias() const
void GetFields(LIB_FIELDS &aList)
Return a list of fields within this part.

References LIB_PART::FindField(), LIB_PART::GetFields(), GetHtmlFieldRow(), LIB_PART::GetParent(), LIB_PART::IsAlias(), m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlKeywords()

void FOOTPRINT_INFO_GENERATOR::SetHtmlKeywords ( )
inlineprotected

Definition at line 148 of file generate_alias_info.cpp.

149  {
150  wxString keywords = m_symbol->GetKeyWords();
151 
152  if( keywords.empty() )
153  m_html.Replace( "__KEY__", wxEmptyString );
154  else
155  m_html.Replace( "__KEY__",
156  wxString::Format( KeywordsFormat, EscapedHTML( keywords ) ) );
157  }
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341
wxString GetKeyWords() const
static const wxString KeywordsFormat
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

References EscapedHTML(), Format(), LIB_PART::GetKeyWords(), KeywordsFormat, m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlName()

void FOOTPRINT_INFO_GENERATOR::SetHtmlName ( )
inlineprotected

Definition at line 108 of file generate_alias_info.cpp.

109  {
110  m_html.Replace( "__NAME__", EscapedHTML( m_symbol->GetName() ) );
111  }
wxString GetName() const override
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:341

References EscapedHTML(), LIB_PART::GetName(), m_html, and m_symbol.

Referenced by GenerateHtml().

Member Data Documentation

◆ m_fp_lib_table

FP_LIB_TABLE* FOOTPRINT_INFO_GENERATOR::m_fp_lib_table
private

Definition at line 50 of file generate_footprint_info.cpp.

Referenced by GenerateHtml().

◆ m_html

wxString FOOTPRINT_INFO_GENERATOR::m_html
private

◆ m_lib_id

LIB_ID const FOOTPRINT_INFO_GENERATOR::m_lib_id
private

Definition at line 52 of file generate_alias_info.cpp.

Referenced by GenerateHtml().

◆ m_module

MODULE* FOOTPRINT_INFO_GENERATOR::m_module
private

Definition at line 52 of file generate_footprint_info.cpp.

Referenced by GenerateHtml().

◆ m_sym_lib_table

SYMBOL_LIB_TABLE* FOOTPRINT_INFO_GENERATOR::m_sym_lib_table
private

Definition at line 51 of file generate_alias_info.cpp.

Referenced by GenerateHtml().

◆ m_symbol

LIB_PART* FOOTPRINT_INFO_GENERATOR::m_symbol
private

◆ m_unit

int FOOTPRINT_INFO_GENERATOR::m_unit
private

Definition at line 54 of file generate_alias_info.cpp.

Referenced by GetHtmlFieldRow().


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