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 () const
 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 (const LIB_FIELD &aField) const
 
void SetHtmlFieldTable ()
 

Private Attributes

wxString m_html
 
SYMBOL_LIB_TABLEm_sym_lib_table
 
LIB_ID const m_lib_id
 
LIB_SYMBOLm_symbol
 
int m_unit
 
FP_LIB_TABLEm_fp_lib_table
 
const FOOTPRINTm_footprint
 

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 { }
SYMBOL_LIB_TABLE * m_sym_lib_table
static const wxString DescriptionFormat

◆ FOOTPRINT_INFO_GENERATOR() [2/2]

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

Definition at line 57 of file generate_footprint_info.cpp.

59 m_fp_lib_table( aFpLibTable ),
60 m_lib_id( aLibId ),
61 m_footprint( nullptr )
62 { }
static const wxString DescriptionFormat

Member Function Documentation

◆ GenerateHtml() [1/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 {
78 }
79 catch( const IO_ERROR& ioe )
80 {
81 wxLogError( _( "Error loading symbol %s from library '%s'." ) + wxS( "\n%s" ),
84 ioe.What() );
85 return;
86 }
87
88 if( m_symbol )
89 {
95 }
96 }
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:172
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
wxString wx_str() const
Definition: utf8.cpp:46
#define _(s)

References _, 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().

◆ GenerateHtml() [2/2]

void FOOTPRINT_INFO_GENERATOR::GenerateHtml ( )
inline

Generate the HTML internally.

Definition at line 67 of file generate_footprint_info.cpp.

68 {
69 wxCHECK_RET( m_fp_lib_table, wxT( "Footprint library table pointer is not valid" ) );
70
71 if( !m_lib_id.IsValid() )
72 return;
73
74 try
75 {
78 }
79 catch( const IO_ERROR& ioe )
80 {
81 wxLogError( _( "Error loading footprint %s from library '%s'." ) + wxS( "\n%s" ),
84 ioe.What() );
85 return;
86 }
87
88 if( m_footprint )
89 {
90 wxString name = m_lib_id.GetLibItemName();
91 wxString desc = m_footprint->GetDescription();
92 wxString keywords = m_footprint->GetKeywords();
93 wxString doc;
94
95 // It is currently common practice to store a documentation link in the description.
96 int idx = desc.find( wxT( "http:" ) );
97
98 if( idx < 0 )
99 idx = desc.find( wxT( "https:" ) );
100
101 if( idx >= 0 )
102 {
103 int nesting = 0;
104
105 for( auto chit = desc.begin() + idx; chit != desc.end(); ++chit )
106 {
107 int ch = *chit;
108
109 // Break on invalid URI characters
110 if( ch <= 0x20 || ch >= 0x7F || ch == '"' )
111 break;
112
113 // Check for nesting parentheses, e.g. (Body style from: https://this.url/part.pdf)
114 if( ch == '(' )
115 ++nesting;
116 else if( ch == ')' && --nesting < 0 )
117 break;
118
119 doc += ch;
120 }
121
122 desc.Replace( doc, _( "doc url" ) );
123 }
124
125 m_html.Replace( "__NAME__", EscapeHTML( name ) );
126 m_html.Replace( "__DESC__", EscapeHTML( desc ) );
127
128 wxString keywordsHtml = KeywordsFormat;
129 keywordsHtml.Replace( "__KEYWORDS__", EscapeHTML( keywords ) );
130
131 wxString docHtml = DocFormat;
132 docHtml.Replace( "__HREF__", EscapeHTML( doc ) );
133
134 if( doc.Length() > 75 )
135 doc = doc.Left( 72 ) + wxT( "..." );
136
137 docHtml.Replace( "__TEXT__", EscapeHTML( doc ) );
138
139 m_html.Replace( "__FIELDS__", keywordsHtml + docHtml );
140 }
141 }
const char * name
Definition: DXF_plotter.cpp:56
wxString GetDescription() const
Definition: footprint.h:218
wxString GetKeywords() const
Definition: footprint.h:221
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
static const wxString KeywordsFormat
static const wxString DocFormat
wxString EscapeHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.

References _, DocFormat, EscapeHTML(), FOOTPRINT::GetDescription(), FP_LIB_TABLE::GetEnumeratedFootprint(), FOOTPRINT::GetKeywords(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_ID::IsValid(), KeywordsFormat, m_footprint, m_fp_lib_table, m_html, m_lib_id, name, IO_ERROR::What(), and UTF8::wx_str().

◆ GetHtml() [1/2]

wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 146 of file generate_footprint_info.cpp.

147 {
148 return m_html;
149 }

References m_html.

◆ GetHtml() [2/2]

wxString FOOTPRINT_INFO_GENERATOR::GetHtml ( ) const
inline

Return the generated HTML.

Definition at line 101 of file generate_alias_info.cpp.

102 {
103 return m_html;
104 }

References m_html.

Referenced by GenerateAliasInfo(), and GenerateFootprintInfo().

◆ GetHtmlFieldRow()

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

Definition at line 158 of file generate_alias_info.cpp.

159 {
160 wxString name = aField.GetCanonicalName();
161 wxString text;
162 wxString fieldhtml = FieldFormat;
163
164 fieldhtml.Replace( wxS( "__NAME__" ), EscapeHTML( name ) );
165
166 switch( aField.GetId() )
167 {
168 case DATASHEET_FIELD:
170
171 if( text.IsEmpty() || text == wxT( "~" ) )
172 {
173 fieldhtml.Replace( wxS( "__VALUE__" ), text );
174 }
175 else
176 {
177 wxString datasheetlink = DatasheetLinkFormat;
178 datasheetlink.Replace( wxS( "__HREF__" ), EscapeHTML( text ) );
179
180 if( text.Length() > 75 )
181 text = text.Left( 72 ) + wxT( "..." );
182
183 datasheetlink.Replace( wxS( "__TEXT__" ), EscapeHTML( text ) );
184
185 fieldhtml.Replace( wxS( "__VALUE__" ), datasheetlink );
186 }
187
188 break;
189
190 case VALUE_FIELD:
191 // showing the value just repeats the name, so that's not much use...
192 return wxEmptyString;
193
194 case REFERENCE_FIELD:
195 text = aField.GetFullText( m_unit > 0 ? m_unit : 1 );
196 fieldhtml.Replace( wxS( "__VALUE__" ), EscapeHTML( text ) );
197 break;
198
199 default:
200 text = aField.GetShownText( 0, false );
201 fieldhtml.Replace( wxS( "__VALUE__" ), EscapeHTML( text ) );
202 }
203
204 return fieldhtml;
205 }
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:397
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:485
int GetId() const
Definition: lib_field.h:114
wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
Definition: lib_field.cpp:414
LIB_FIELD & GetDatasheetField()
Return reference to the datasheet field.
static const wxString DatasheetLinkFormat
static const wxString FieldFormat
@ DATASHEET_FIELD
name of datasheet
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".

References DATASHEET_FIELD, DatasheetLinkFormat, EscapeHTML(), FieldFormat, LIB_FIELD::GetCanonicalName(), LIB_SYMBOL::GetDatasheetField(), LIB_FIELD::GetFullText(), LIB_FIELD::GetId(), LIB_FIELD::GetShownText(), m_symbol, m_unit, name, REFERENCE_FIELD, text, and VALUE_FIELD.

Referenced by SetHtmlFieldTable().

◆ SetHtmlAliasOf()

void FOOTPRINT_INFO_GENERATOR::SetHtmlAliasOf ( )
inlineprotected

Definition at line 113 of file generate_alias_info.cpp.

114 {
115 if( m_symbol->IsRoot() )
116 {
117 m_html.Replace( "__ALIASOF__", wxEmptyString );
118 }
119 else
120 {
121 wxString root_name = _( "Unknown" );
122 wxString root_desc = wxS( "" );
123
124 std::shared_ptr< LIB_SYMBOL > parent = m_symbol->GetParent().lock();
125
126 if( parent )
127 {
128 root_name = parent->GetName();
129 root_desc = parent->GetDescription();
130 }
131
132 m_html.Replace( wxS( "__ALIASOF__" ), wxString::Format( AliasOfFormat,
133 EscapeHTML( UnescapeString( root_name ) ),
134 EscapeHTML( root_desc ) ) );
135 }
136 }
bool IsRoot() const override
For symbols derived from other symbols, IsRoot() indicates no derivation.
Definition: lib_symbol.h:187
LIB_SYMBOL_REF & GetParent()
Definition: lib_symbol.h:127
static const wxString AliasOfFormat
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
wxString UnescapeString(const wxString &aSource)

References _, AliasOfFormat, EscapeHTML(), Format(), LIB_SYMBOL::GetParent(), LIB_SYMBOL::IsRoot(), m_html, m_symbol, and UnescapeString().

Referenced by GenerateHtml().

◆ SetHtmlDesc()

void FOOTPRINT_INFO_GENERATOR::SetHtmlDesc ( )
inlineprotected

Definition at line 139 of file generate_alias_info.cpp.

140 {
141 wxString raw_desc = m_symbol->GetDescription();
142
143 m_html.Replace( wxS( "__DESC__" ), wxString::Format( DescFormat, EscapeHTML( raw_desc ) ) );
144 }
wxString GetDescription() override
Definition: lib_symbol.h:151
static const wxString DescFormat

References DescFormat, EscapeHTML(), Format(), LIB_SYMBOL::GetDescription(), m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlFieldTable()

void FOOTPRINT_INFO_GENERATOR::SetHtmlFieldTable ( )
inlineprotected

Definition at line 208 of file generate_alias_info.cpp.

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

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

Referenced by GenerateHtml().

◆ SetHtmlKeywords()

void FOOTPRINT_INFO_GENERATOR::SetHtmlKeywords ( )
inlineprotected

Definition at line 147 of file generate_alias_info.cpp.

148 {
149 wxString keywords = m_symbol->GetKeyWords();
150
151 if( keywords.empty() )
152 m_html.Replace( wxS( "__KEY__" ), wxEmptyString );
153 else
154 m_html.Replace( wxS( "__KEY__" ), wxString::Format( KeywordsFormat, EscapeHTML( keywords ) ) );
155 }
wxString GetKeyWords() const
Definition: lib_symbol.h:164
static const wxString KeywordsFormat

References EscapeHTML(), Format(), LIB_SYMBOL::GetKeyWords(), KeywordsFormat, m_html, and m_symbol.

Referenced by GenerateHtml().

◆ SetHtmlName()

void FOOTPRINT_INFO_GENERATOR::SetHtmlName ( )
inlineprotected

Definition at line 107 of file generate_alias_info.cpp.

108 {
109 m_html.Replace( wxS( "__NAME__" ), EscapeHTML( UnescapeString( m_symbol->GetName() ) ) );
110 }
wxString GetName() const override
Definition: lib_symbol.h:138

References EscapeHTML(), LIB_SYMBOL::GetName(), m_html, m_symbol, and UnescapeString().

Referenced by GenerateHtml().

Member Data Documentation

◆ m_footprint

const FOOTPRINT* FOOTPRINT_INFO_GENERATOR::m_footprint
private

Definition at line 54 of file generate_footprint_info.cpp.

Referenced by GenerateHtml().

◆ m_fp_lib_table

FP_LIB_TABLE* FOOTPRINT_INFO_GENERATOR::m_fp_lib_table
private

Definition at line 51 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_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_SYMBOL* 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: