Output defined default fields to netlists & BOMs.

Fixes: lp:1746814
* https://bugs.launchpad.net/kicad/+bug/1746814
This commit is contained in:
Jeff Young 2018-05-24 18:24:08 +01:00
parent 6090f9001e
commit cb925a6646
5 changed files with 56 additions and 66 deletions

View File

@ -89,6 +89,8 @@ struct COMP_FIELDS
void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT* comp, SCH_SHEET_PATH* aSheet )
{
COMP_FIELDS fields;
if( comp->GetUnitCount() > 1 )
{
// Sadly, each unit of a component can have its own unique fields. This
@ -98,7 +100,6 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
// any non blank fields in all units and use the first non-blank field
// for each unique field name.
COMP_FIELDS fields;
wxString ref = comp->GetRef( aSheet );
SCH_SHEET_LIST sheetList( g_RootSheet );
@ -149,65 +150,54 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
}
}
// Do not output field values blank in netlist:
if( fields.value.size() )
xcomp->AddChild( node( "value", fields.value ) );
else // value field always written in netlist
xcomp->AddChild( node( "value", "~" ) );
if( fields.footprint.size() )
xcomp->AddChild( node( "footprint", fields.footprint ) );
if( fields.datasheet.size() )
xcomp->AddChild( node( "datasheet", fields.datasheet ) );
if( fields.f.size() )
{
XNODE* xfields;
xcomp->AddChild( xfields = node( "fields" ) );
// non MANDATORY fields are output alphabetically
for( std::map< wxString, wxString >::const_iterator it = fields.f.begin();
it != fields.f.end(); ++it )
{
XNODE* xfield;
xfields->AddChild( xfield = node( "field", it->second ) );
xfield->AddAttribute( "name", it->first );
}
}
}
else
{
xcomp->AddChild( node( "value", comp->GetField( VALUE )->GetText() ) );
fields.value = comp->GetField( VALUE )->GetText();
fields.footprint = comp->GetField( FOOTPRINT )->GetText();
fields.datasheet = comp->GetField( DATASHEET )->GetText();
if( !comp->GetField( FOOTPRINT )->IsVoid() )
xcomp->AddChild( node( "footprint", comp->GetField( FOOTPRINT )->GetText() ) );
if( !comp->GetField( DATASHEET )->IsVoid() )
xcomp->AddChild( node( "datasheet", comp->GetField( DATASHEET )->GetText() ) );
// Export all user defined fields within the component,
// which start at field index MANDATORY_FIELDS. Only output the <fields>
// container element if there are any <field>s.
if( comp->GetFieldCount() > MANDATORY_FIELDS )
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
{
XNODE* xfields;
xcomp->AddChild( xfields = node( "fields" ) );
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
{
SCH_FIELD* f = comp->GetField( fldNdx );
// only output a field if non empty and not just "~"
if( !f->IsVoid() )
{
XNODE* xfield;
xfields->AddChild( xfield = node( "field", f->GetText() ) );
xfield->AddAttribute( "name", f->GetName() );
}
}
SCH_FIELD* f = comp->GetField( fldNdx );
fields.f[ f->GetName() ] = f->GetText();
}
}
// Add in non-empty default fields which have not been explicitly defined
for( auto defaultField : m_frame->GetTemplateFieldNames() )
{
if( defaultField.m_Value.size() && fields.f.count( defaultField.m_Name ) == 0 )
fields.f[ defaultField.m_Name ] = defaultField.m_Value;
}
// Do not output field values blank in netlist:
if( fields.value.size() )
xcomp->AddChild( node( "value", fields.value ) );
else // value field always written in netlist
xcomp->AddChild( node( "value", "~" ) );
if( fields.footprint.size() )
xcomp->AddChild( node( "footprint", fields.footprint ) );
if( fields.datasheet.size() )
xcomp->AddChild( node( "datasheet", fields.datasheet ) );
if( fields.f.size() )
{
XNODE* xfields;
xcomp->AddChild( xfields = node( "fields" ) );
// non MANDATORY fields are output alphabetically
for( std::map< wxString, wxString >::const_iterator it = fields.f.begin();
it != fields.f.end(); ++it )
{
XNODE* xfield;
xfields->AddChild( xfield = node( "field", it->second ) );
xfield->AddAttribute( "name", it->first );
}
}
}

View File

@ -26,6 +26,7 @@
#ifndef NETLIST_EXPORT_GENERIC_H
#define NETLIST_EXPORT_GENERIC_H
#include <project.h>
#include <netlist_exporter.h>
#include <xnode.h> // also nests: <wx/xml/xml.h>
@ -56,17 +57,17 @@ enum GNL_T
class NETLIST_EXPORTER_GENERIC : public NETLIST_EXPORTER
{
private:
SCH_EDIT_FRAME* m_frame;
std::set< wxString > m_libraries; ///< Set of library nicknames.
SYMBOL_LIB_TABLE* m_libTable;
public:
NETLIST_EXPORTER_GENERIC( NETLIST_OBJECT_LIST* aMasterList, SYMBOL_LIB_TABLE* aLibTable ) :
NETLIST_EXPORTER_GENERIC( SCH_EDIT_FRAME* aFrame, NETLIST_OBJECT_LIST* aMasterList ) :
NETLIST_EXPORTER( aMasterList ),
m_libTable( aLibTable )
{
wxASSERT( aLibTable );
}
m_frame( aFrame ),
m_libTable( aFrame->Prj().SchSymbolLibTable() )
{}
/**
* Function WriteNetlist

View File

@ -38,10 +38,9 @@ class OUTPUTFORMATTER;
class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC
{
public:
NETLIST_EXPORTER_KICAD( NETLIST_OBJECT_LIST* aMasterList, SYMBOL_LIB_TABLE* aLibTable ) :
NETLIST_EXPORTER_GENERIC( aMasterList, aLibTable )
{
}
NETLIST_EXPORTER_KICAD( SCH_EDIT_FRAME* aFrame, NETLIST_OBJECT_LIST* aMasterList ) :
NETLIST_EXPORTER_GENERIC( aFrame, aMasterList )
{}
/**
* Function WriteNetlist

View File

@ -61,7 +61,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
switch( aFormat )
{
case NET_TYPE_PCBNEW:
helper = new NETLIST_EXPORTER_KICAD( aConnectedItemsList, Prj().SchSymbolLibTable() );
helper = new NETLIST_EXPORTER_KICAD( this, aConnectedItemsList );
break;
case NET_TYPE_ORCADPCB2:
@ -82,7 +82,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT );
fileName = tmpFile.GetFullPath();
helper = new NETLIST_EXPORTER_GENERIC( aConnectedItemsList, Prj().SchSymbolLibTable() );
helper = new NETLIST_EXPORTER_GENERIC( this, aConnectedItemsList );
executeCommandLine = true;
}
break;
@ -193,7 +193,7 @@ void SCH_EDIT_FRAME::sendNetlist()
{
NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();
NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchSymbolLibTable() );
NETLIST_EXPORTER_KICAD exporter( this, net_atoms );
STRING_FORMATTER formatter;

View File

@ -905,7 +905,7 @@ void SCH_EDIT_FRAME::doUpdatePcb( const wxString& aUpdateOptions )
}
NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();
NETLIST_EXPORTER_KICAD exporter( net_atoms, Prj().SchSymbolLibTable() );
NETLIST_EXPORTER_KICAD exporter( this, net_atoms );
STRING_FORMATTER formatter;
exporter.Format( &formatter, GNL_ALL );