Output resolved text to generic BOM XML.

This commit is contained in:
Jeff Young 2020-08-20 12:32:46 +01:00
parent 3ddee6503a
commit c5b91c9bb2
1 changed files with 60 additions and 46 deletions

View File

@ -123,15 +123,15 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
// field value) // field value)
if( !comp2->GetField( VALUE )->IsVoid() if( !comp2->GetField( VALUE )->IsVoid()
&& ( unit < minUnit || fields.value.IsEmpty() ) ) && ( unit < minUnit || fields.value.IsEmpty() ) )
fields.value = comp2->GetField( VALUE )->GetText(); fields.value = comp2->GetField( VALUE )->GetShownText();
if( !comp2->GetField( FOOTPRINT )->IsVoid() if( !comp2->GetField( FOOTPRINT )->IsVoid()
&& ( unit < minUnit || fields.footprint.IsEmpty() ) ) && ( unit < minUnit || fields.footprint.IsEmpty() ) )
fields.footprint = comp2->GetField( FOOTPRINT )->GetText(); fields.footprint = comp2->GetField( FOOTPRINT )->GetShownText();
if( !comp2->GetField( DATASHEET )->IsVoid() if( !comp2->GetField( DATASHEET )->IsVoid()
&& ( unit < minUnit || fields.datasheet.IsEmpty() ) ) && ( unit < minUnit || fields.datasheet.IsEmpty() ) )
fields.datasheet = comp2->GetField( DATASHEET )->GetText(); fields.datasheet = comp2->GetField( DATASHEET )->GetShownText();
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp2->GetFieldCount(); ++fldNdx ) for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp2->GetFieldCount(); ++fldNdx )
{ {
@ -140,27 +140,26 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
if( f->GetText().size() if( f->GetText().size()
&& ( unit < minUnit || fields.f.count( f->GetName() ) == 0 ) ) && ( unit < minUnit || fields.f.count( f->GetName() ) == 0 ) )
{ {
fields.f[ f->GetName() ] = f->GetText(); fields.f[ f->GetName() ] = f->GetShownText();
} }
} }
minUnit = std::min( unit, minUnit ); minUnit = std::min( unit, minUnit );
} }
} }
} }
else else
{ {
fields.value = comp->GetField( VALUE )->GetText(); fields.value = comp->GetField( VALUE )->GetShownText();
fields.footprint = comp->GetField( FOOTPRINT )->GetText(); fields.footprint = comp->GetField( FOOTPRINT )->GetShownText();
fields.datasheet = comp->GetField( DATASHEET )->GetText(); fields.datasheet = comp->GetField( DATASHEET )->GetShownText();
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx ) for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
{ {
SCH_FIELD* f = comp->GetField( fldNdx ); SCH_FIELD* f = comp->GetField( fldNdx );
if( f->GetText().size() ) if( f->GetText().size() )
fields.f[ f->GetName() ] = f->GetText(); fields.f[ f->GetName() ] = f->GetShownText();
} }
} }
@ -209,12 +208,11 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
{ {
SCH_SHEET_PATH sheet = sheetList[ii]; SCH_SHEET_PATH sheet = sheetList[ii];
auto cmp = auto cmp = [sheet]( SCH_COMPONENT* a, SCH_COMPONENT* b )
[sheet]( SCH_COMPONENT* a, SCH_COMPONENT* b ) {
{ return ( UTIL::RefDesStringCompare( a->GetRef( &sheet ),
return ( UTIL::RefDesStringCompare( a->GetRef( &sheet ), b->GetRef( &sheet ) ) < 0 );
b->GetRef( &sheet ) ) < 0 ); };
};
std::set<SCH_COMPONENT*, decltype( cmp )> ordered_components( cmp ); std::set<SCH_COMPONENT*, decltype( cmp )> ordered_components( cmp );
@ -303,12 +301,13 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
{ {
SCH_SCREEN* screen; SCH_SCREEN* screen;
XNODE* xdesign = node( "design" ); XNODE* xdesign = node( "design" );
XNODE* xtitleBlock; XNODE* xtitleBlock;
XNODE* xsheet; XNODE* xsheet;
XNODE* xcomment; XNODE* xcomment;
wxString sheetTxt; XNODE* xtextvar;
wxFileName sourceFileName; wxString sheetTxt;
wxFileName sourceFileName;
// the root sheet is a special sheet, call it source // the root sheet is a special sheet, call it source
xdesign->AddChild( node( "source", m_schematic->GetFileName() ) ); xdesign->AddChild( node( "source", m_schematic->GetFileName() ) );
@ -318,9 +317,17 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
// which Eeschema tool // which Eeschema tool
xdesign->AddChild( node( "tool", wxString( "Eeschema " ) + GetBuildVersion() ) ); xdesign->AddChild( node( "tool", wxString( "Eeschema " ) + GetBuildVersion() ) );
const std::map<wxString, wxString>& properties = m_schematic->Prj().GetTextVars();
for( const std::pair<const wxString, wxString>& prop : properties )
{
xdesign->AddChild( xtextvar = node( "textvar", prop.second ) );
xtextvar->AddAttribute( "name", prop.first );
}
/* /*
Export the sheets information * Export the sheets information
*/ */
SCH_SHEET_LIST sheetList = m_schematic->GetSheets(); SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
for( unsigned i = 0; i < sheetList.size(); i++ ) for( unsigned i = 0; i < sheetList.size(); i++ )
@ -394,19 +401,19 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
XNODE* NETLIST_EXPORTER_GENERIC::makeLibraries() XNODE* NETLIST_EXPORTER_GENERIC::makeLibraries()
{ {
XNODE* xlibs = node( "libraries" ); // auto_ptr XNODE* xlibs = node( "libraries" ); // auto_ptr
SYMBOL_LIB_TABLE* symbolLibTable = m_schematic->Prj().SchSymbolLibTable();
for( std::set<wxString>::iterator it = m_libraries.begin(); it!=m_libraries.end(); ++it ) for( std::set<wxString>::iterator it = m_libraries.begin(); it!=m_libraries.end(); ++it )
{ {
wxString libNickname = *it; wxString libNickname = *it;
XNODE* xlibrary; XNODE* xlibrary;
if( m_schematic->Prj().SchSymbolLibTable()->HasLibrary( libNickname ) ) if( symbolLibTable->HasLibrary( libNickname ) )
{ {
xlibs->AddChild( xlibrary = node( "library" ) ); xlibs->AddChild( xlibrary = node( "library" ) );
xlibrary->AddAttribute( "logical", libNickname ); xlibrary->AddAttribute( "logical", libNickname );
xlibrary->AddChild( node( xlibrary->AddChild( node( "uri", symbolLibTable->GetFullURI( libNickname ) ) );
"uri", m_schematic->Prj().SchSymbolLibTable()->GetFullURI( libNickname ) ) );
} }
// @todo: add more fun stuff here // @todo: add more fun stuff here
@ -549,45 +556,52 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets()
XNODE* xnode; XNODE* xnode;
std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items; std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items;
for( auto subgraph : subgraphs ) for( CONNECTION_SUBGRAPH* subgraph : subgraphs )
{ {
auto sheet = subgraph->m_sheet; const SCH_SHEET_PATH& sheet = subgraph->m_sheet;
for( auto item : subgraph->m_items ) for( SCH_ITEM* item : subgraph->m_items )
{
if( item->Type() == SCH_PIN_T ) if( item->Type() == SCH_PIN_T )
sorted_items.emplace_back( sorted_items.emplace_back( static_cast<SCH_PIN*>( item ), sheet );
std::make_pair( static_cast<SCH_PIN*>( item ), sheet ) ); }
} }
// Netlist ordering: Net name, then ref des, then pin name // Netlist ordering: Net name, then ref des, then pin name
std::sort( sorted_items.begin(), sorted_items.end(), [] ( auto a, auto b ) { std::sort( sorted_items.begin(), sorted_items.end(),
auto ref_a = a.first->GetParentComponent()->GetRef( &a.second ); []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
auto ref_b = b.first->GetParentComponent()->GetRef( &b.second ); const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
{
wxString ref_a = a.first->GetParentComponent()->GetRef( &a.second );
wxString ref_b = b.first->GetParentComponent()->GetRef( &b.second );
if( ref_a == ref_b ) if( ref_a == ref_b )
return a.first->GetNumber() < b.first->GetNumber(); return a.first->GetNumber() < b.first->GetNumber();
return ref_a < ref_b; return ref_a < ref_b;
} ); } );
// Some duplicates can exist, for example on multi-unit parts with duplicated // Some duplicates can exist, for example on multi-unit parts with duplicated
// pins across units. If the user connects the pins on each unit, they will // pins across units. If the user connects the pins on each unit, they will
// appear on separate subgraphs. Remove those here: // appear on separate subgraphs. Remove those here:
sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(), sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
[] ( auto a, auto b ) { []( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
auto ref_a = a.first->GetParentComponent()->GetRef( &a.second ); const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
auto ref_b = b.first->GetParentComponent()->GetRef( &b.second ); {
wxString ref_a = a.first->GetParentComponent()->GetRef( &a.second );
wxString ref_b = b.first->GetParentComponent()->GetRef( &b.second );
return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber(); return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber();
} ), sorted_items.end() ); } ),
sorted_items.end() );
for( const auto& pair : sorted_items ) for( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& pair : sorted_items )
{ {
SCH_PIN* pin = pair.first; SCH_PIN* pin = pair.first;
SCH_SHEET_PATH sheet = pair.second; SCH_SHEET_PATH sheet = pair.second;
auto refText = pin->GetParentComponent()->GetRef( &sheet ); wxString refText = pin->GetParentComponent()->GetRef( &sheet );
const auto& pinText = pin->GetNumber(); wxString pinText = pin->GetNumber();
// Skip power symbols and virtual components // Skip power symbols and virtual components
if( refText[0] == wxChar( '#' ) ) if( refText[0] == wxChar( '#' ) )