KiCad PCB EDA Suite
ALIAS_INFO_GENERATOR Class Reference

Public Member Functions

 ALIAS_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
 
SYMBOL_LIB_TABLEm_sym_lib_table
 
LIB_ID const m_lib_id
 
LIB_ALIASm_alias
 
int m_unit
 

Detailed Description

Definition at line 48 of file generate_alias_info.cpp.

Constructor & Destructor Documentation

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

Member Function Documentation

void ALIAS_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().

Referenced by GenerateAliasInfo().

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_alias = 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_alias )
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:155
Part library alias object definition.
SYMBOL_LIB_TABLE * m_sym_lib_table
wxString wx_str() const
Definition: utf8.cpp:48
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
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:98
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
wxString ALIAS_INFO_GENERATOR::GetHtml ( )
inline

Return the generated HTML.

Definition at line 102 of file generate_alias_info.cpp.

References m_html.

Referenced by GenerateAliasInfo().

103  {
104  return m_html;
105  }
wxString ALIAS_INFO_GENERATOR::GetHtmlFieldRow ( LIB_FIELD const &  aField)
inlineprotected

Definition at line 161 of file generate_alias_info.cpp.

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

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  wxString datasheetlink = DatasheetLinkFormat;
174  datasheetlink.Replace( "__VALUE__", EscapedHTML( text ) );
175  fieldhtml.Replace( "__VALUE__", datasheetlink );
176  }
177  break;
178 
179  default:
180  fieldhtml.Replace( "__VALUE__", EscapedHTML( text ) );
181  }
182 
183  return fieldhtml;
184  }
name of datasheet
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:170
const char * name
static const wxString FieldFormat
static const wxString DatasheetLinkFormat
void ALIAS_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_alias->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_alias->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:170
bool IsRoot() const
wxString GetDescription() const
Define a library symbol object.
LIB_PART * GetPart() const
Get the shared LIB_PART.
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 ALIAS_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_alias->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:170
static const wxString DescFormat
wxString GetDescription() const
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 ALIAS_INFO_GENERATOR::SetHtmlFieldTable ( )
inlineprotected

Definition at line 187 of file generate_alias_info.cpp.

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

Referenced by GenerateHtml().

188  {
189  wxString fieldtable;
190  LIB_FIELDS fields;
191  m_alias->GetPart()->GetFields( fields );
192 
193  for( auto const & field: fields )
194  {
195  fieldtable += GetHtmlFieldRow( field );
196  }
197 
198  m_html.Replace( "__FIELDS__", fieldtable );
199  }
wxString GetHtmlFieldRow(LIB_FIELD const &aField)
LIB_PART * GetPart() const
Get the shared LIB_PART.
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:252
void GetFields(LIB_FIELDS &aList)
Return a list of fields withing this part.
void ALIAS_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_alias->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:170
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
wxString GetKeyWords() const
void ALIAS_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_alias->GetName() ) );
111  }
wxString EscapedHTML(const wxString &aString)
Return a new wxString escaped for embedding in HTML.
Definition: string.cpp:170
const wxString & GetName() const

Member Data Documentation

LIB_ALIAS* ALIAS_INFO_GENERATOR::m_alias
private

Definition at line 53 of file generate_alias_info.cpp.

wxString ALIAS_INFO_GENERATOR::m_html
private

Definition at line 50 of file generate_alias_info.cpp.

Referenced by GetHtml().

LIB_ID const ALIAS_INFO_GENERATOR::m_lib_id
private

Definition at line 52 of file generate_alias_info.cpp.

SYMBOL_LIB_TABLE* ALIAS_INFO_GENERATOR::m_sym_lib_table
private

Definition at line 51 of file generate_alias_info.cpp.

int ALIAS_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 file: