Add output formatter to LIBRARY_TABLE

This commit is contained in:
Jon Evans
2025-10-15 22:18:50 -04:00
parent 00f5cbe045
commit 73dd8146fa
9 changed files with 470 additions and 382 deletions
+47
View File
@@ -28,6 +28,7 @@
#include <string_utils.h>
#include <trace_helpers.h>
#include <wx_filename.h>
#include <xnode.h>
std::map<std::string, UTF8> LIBRARY_TABLE_ROW::GetOptionsMap() const
@@ -151,3 +152,49 @@ void LIBRARY_TABLE::LoadNestedTables()
processOneTable( *this );
}
void LIBRARY_TABLE::Format( OUTPUTFORMATTER* aOutput ) const
{
if( !IsOk() )
return;
static const std::map<LIBRARY_TABLE_TYPE, wxString> types = {
{ LIBRARY_TABLE_TYPE::SYMBOL, "sym_lib_table" },
{ LIBRARY_TABLE_TYPE::FOOTPRINT, "fp_lib_table" },
{ LIBRARY_TABLE_TYPE::DESIGN_BLOCK, "design_block_lib_table" }
};
wxCHECK( types.contains( Type() ), /* void */ );
XNODE self( wxXML_ELEMENT_NODE, types.at( Type() ) );
// TODO(JE) library tables - version management?
self.AddAttribute( "version", 7 );
for( const LIBRARY_TABLE_ROW& row : Rows() )
{
if( !row.IsOk() )
continue;
wxString uri = row.URI();
uri.Replace( '\\', '/' );
XNODE* rowNode = new XNODE( wxXML_ELEMENT_NODE, "lib" );
rowNode->AddAttribute( "name", row.Nickname() );
rowNode->AddAttribute( "type", row.Type() );
rowNode->AddAttribute( "uri", uri );
rowNode->AddAttribute( "options", row.Options() );
rowNode->AddAttribute( "descr", row.Description() );
if( row.Disabled() )
rowNode->AddChild( new XNODE( wxXML_ELEMENT_NODE, "disabled" ) );
if( row.Hidden() )
rowNode->AddChild( new XNODE( wxXML_ELEMENT_NODE, "hidden" ) );
self.AddChild( rowNode );
}
self.Format( aOutput );
}