KiCad PCB EDA Suite
FOOTPRINT_INFO_GENERATOR Class Reference

Public Member Functions

 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...
 
 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...
 

Protected Member Functions

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

Private Attributes

wxString m_html
 
FP_LIB_TABLEm_fp_lib_table
 
LIB_ID const m_lib_id
 
MODULEm_module
 
SYMBOL_LIB_TABLEm_sym_lib_table
 
LIB_ALIASm_module
 
int m_unit
 

Detailed Description

Definition at line 47 of file generate_footprint_info.cpp.

Constructor & Destructor Documentation

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
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_module( nullptr ),
62  m_unit( aUnit )
63  { }
static const wxString DescriptionFormat
SYMBOL_LIB_TABLE * m_sym_lib_table

Member Function Documentation

void FOOTPRINT_INFO_GENERATOR::GenerateHtml ( )
inline

Generate the HTML internally.

Definition at line 65 of file generate_footprint_info.cpp.

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

Referenced by GenerateAliasInfo(), and GenerateFootprintInfo().

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  }
bool IsValid() const
Definition: lib_id.h:171
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:247
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
wxString wx_str() const
Definition: utf8.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const wxString & GetKeywords() const
Definition: class_module.h:199
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
const char * name
Definition: DXF_plotter.cpp:61
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
const wxString & GetDescription() const
Definition: class_module.h:196
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
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
void FOOTPRINT_INFO_GENERATOR::GenerateHtml ( )
inline

Generate the HTML internally.

Definition at line 68 of file generate_alias_info.cpp.

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

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_module = const_cast< LIB_ALIAS* >( 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_module )
90  {
91  SetHtmlName();
93  SetHtmlDesc();
96  }
97  }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
bool IsValid() const
Definition: lib_id.h:171
Part library alias object definition.
wxString wx_str() const
Definition: utf8.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
SYMBOL_LIB_TABLE * m_sym_lib_table
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
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
wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 102 of file generate_alias_info.cpp.

References m_html.

103  {
104  return m_html;
105  }
wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 128 of file generate_footprint_info.cpp.

References m_html.

Referenced by GenerateAliasInfo(), and GenerateFootprintInfo().

129  {
130  return m_html;
131  }
wxString FOOTPRINT_INFO_GENERATOR::GetHtmlFieldRow ( LIB_FIELD const &  aField)
inlineprotected

Definition at line 161 of file generate_alias_info.cpp.

References DATASHEET, DatasheetLinkFormat, EscapedHTML(), FieldFormat, LIB_ALIAS::GetDocFileName(), LIB_FIELD::GetFullText(), LIB_FIELD::GetId(), LIB_FIELD::GetName(), name, and VALUE.

Referenced by SetHtmlFieldTable().

162  {
163  wxString name = aField.GetName();
164  wxString text = aField.GetFullText( m_unit > 0 ? m_unit : 1 );
165  wxString fieldhtml = FieldFormat;
166 
167  fieldhtml.Replace( "__NAME__", EscapedHTML( name ) );
168 
169  switch( aField.GetId() )
170  {
171  case DATASHEET:
172  {
173  text = m_module->GetDocFileName();
174 
175  if( text.IsEmpty() || text == wxT( "~" ) )
176  {
177  fieldhtml.Replace( "__VALUE__", text );
178  }
179  else
180  {
181  wxString datasheetlink = DatasheetLinkFormat;
182  datasheetlink.Replace( "__HREF__", EscapedHTML( text ) );
183 
184  if( text.Length() > 75 )
185  text = text.Left( 72 ) + wxT( "..." );
186 
187  datasheetlink.Replace( "__TEXT__", EscapedHTML( text ) );
188 
189  fieldhtml.Replace( "__VALUE__", datasheetlink );
190  }
191  }
192  break;
193 
194  case VALUE:
195  // showing the value just repeats the name, so that's not much use...
196  return wxEmptyString;
197 
198  default:
199  fieldhtml.Replace( "__VALUE__", EscapedHTML( text ) );
200  }
201 
202  return fieldhtml;
203  }
name of datasheet
bool Replace(wxFindReplaceData &aSearchData, wxString &aText)
Helper function used in search and replace dialog Function Replace performs a text replace on aText u...
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:247
const char * name
Definition: DXF_plotter.cpp:61
static const wxString FieldFormat
#define VALUE
static const wxString DatasheetLinkFormat
void FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf ( )
inlineprotected

Definition at line 114 of file generate_alias_info.cpp.

References AliasOfFormat, EscapedHTML(), Format(), LIB_PART::GetAlias(), LIB_ALIAS::GetDescription(), LIB_PART::GetName(), LIB_ALIAS::GetPart(), and LIB_ALIAS::IsRoot().

Referenced by GenerateHtml().

115  {
116  if( m_module->IsRoot() )
117  {
118  m_html.Replace( "__ALIASOF__", wxEmptyString );
119  }
120  else
121  {
122  wxString root_name = _( "Unknown" );
123  wxString root_desc = "";
124 
125  LIB_PART* root = m_module->GetPart();
126  LIB_ALIAS* root_alias = root ? root->GetAlias( 0 ) : nullptr;
127 
128  if( root )
129  root_name = root->GetName();
130 
131  if( root_alias )
132  root_desc = root_alias->GetDescription();
133 
134  m_html.Replace(
135  "__ALIASOF__", wxString::Format(
136  AliasOfFormat, EscapedHTML( root_name ), EscapedHTML( root_desc ) ) );
137  }
138  }
Part library alias object definition.
LIB_ALIAS * GetAlias(size_t aIndex)
static const wxString AliasOfFormat
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:247
Define a library symbol object.
const 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:205
const wxString & GetName() const
void FOOTPRINT_INFO_GENERATOR::SetHtmlDesc ( )
inlineprotected

Definition at line 141 of file generate_alias_info.cpp.

References DescFormat, EscapedHTML(), Format(), and LIB_ALIAS::GetDescription().

Referenced by GenerateHtml().

142  {
143  wxString raw_desc = m_module->GetDescription();
144 
145  m_html.Replace( "__DESC__", wxString::Format( DescFormat, EscapedHTML( raw_desc ) ) );
146  }
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:247
static const wxString DescFormat
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
const wxString & GetDescription() const
Definition: class_module.h:196
void FOOTPRINT_INFO_GENERATOR::SetHtmlFieldTable ( )
inlineprotected

Definition at line 206 of file generate_alias_info.cpp.

References LIB_PART::GetFields(), GetHtmlFieldRow(), and LIB_ALIAS::GetPart().

Referenced by GenerateHtml().

207  {
208  wxString fieldtable;
209  LIB_FIELDS fields;
210  m_module->GetPart()->GetFields( fields );
211 
212  for( auto const & field: fields )
213  {
214  fieldtable += GetHtmlFieldRow( field );
215  }
216 
217  m_html.Replace( "__FIELDS__", fieldtable );
218  }
wxString GetHtmlFieldRow(LIB_FIELD const &aField)
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:259
void FOOTPRINT_INFO_GENERATOR::SetHtmlKeywords ( )
inlineprotected

Definition at line 149 of file generate_alias_info.cpp.

References EscapedHTML(), Format(), LIB_ALIAS::GetKeyWords(), and KeywordsFormat.

Referenced by GenerateHtml().

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

Definition at line 108 of file generate_alias_info.cpp.

References EscapedHTML(), and LIB_ALIAS::GetName().

Referenced by GenerateHtml().

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

Member Data Documentation

FP_LIB_TABLE* FOOTPRINT_INFO_GENERATOR::m_fp_lib_table
private

Definition at line 50 of file generate_footprint_info.cpp.

wxString FOOTPRINT_INFO_GENERATOR::m_html
private

Definition at line 49 of file generate_footprint_info.cpp.

Referenced by GetHtml().

LIB_ID const FOOTPRINT_INFO_GENERATOR::m_lib_id
private

Definition at line 51 of file generate_footprint_info.cpp.

MODULE* FOOTPRINT_INFO_GENERATOR::m_module
private

Definition at line 52 of file generate_footprint_info.cpp.

LIB_ALIAS* FOOTPRINT_INFO_GENERATOR::m_module
private

Definition at line 53 of file generate_alias_info.cpp.

SYMBOL_LIB_TABLE* FOOTPRINT_INFO_GENERATOR::m_sym_lib_table
private

Definition at line 51 of file generate_alias_info.cpp.

int FOOTPRINT_INFO_GENERATOR::m_unit
private

Definition at line 54 of file generate_alias_info.cpp.


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