Embarking on the next adventure: component -> symbol.

This commit is contained in:
Jeff Young 2020-11-15 13:58:21 +00:00
parent 42687a33ff
commit 6654c03041
25 changed files with 291 additions and 296 deletions

View File

@ -237,9 +237,9 @@ set( EESCHEMA_SRCS
transform.cpp
sch_iref.cpp
netlist_exporters/netlist_exporter.cpp
netlist_exporters/netlist_exporter_base.cpp
netlist_exporters/netlist_exporter_cadstar.cpp
netlist_exporters/netlist_exporter_generic.cpp
netlist_exporters/netlist_exporter_xml.cpp
netlist_exporters/netlist_exporter_kicad.cpp
netlist_exporters/netlist_exporter_orcadpcb2.cpp
netlist_exporters/netlist_exporter_pspice.cpp

View File

@ -77,7 +77,7 @@ bool CONNECTION_SUBGRAPH::ResolveDrivers( bool aCreateMarkers )
PRIORITY item_priority = GetDriverPriority( item );
if( item_priority == PRIORITY::PIN
&& !static_cast<SCH_PIN*>( item )->GetParentComponent()->IsInNetlist() )
&& !static_cast<SCH_PIN*>( item )->GetParentSymbol()->IsInNetlist() )
continue;
if( item_priority >= PRIORITY::HIER_LABEL )

View File

@ -368,7 +368,7 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
}
std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aComp )
std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aSymbol )
{
// This is a keyword followed by a quoted string.
@ -376,17 +376,17 @@ std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aComp )
switch( aItem->Type() )
{
case SCH_FIELD_T:
if( aComp )
if( aSymbol )
{
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aComp->GetField( REFERENCE_FIELD )->GetText() ) );
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
break;
case SCH_COMPONENT_T:
aComp = (SCH_COMPONENT*) aItem;
aSymbol = (SCH_COMPONENT*) aItem;
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aComp->GetField( REFERENCE_FIELD )->GetText() ) );
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
case SCH_SHEET_T:
{
@ -413,18 +413,18 @@ std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aComp )
case SCH_PIN_T:
{
SCH_PIN* pin = (SCH_PIN*) aItem;
aComp = pin->GetParentComponent();
aSymbol = pin->GetParentSymbol();
if( !pin->GetNumber().IsEmpty() )
{
return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
TO_UTF8( pin->GetNumber() ),
TO_UTF8( aComp->GetField( REFERENCE_FIELD )->GetText() ) );
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
else
{
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aComp->GetField( REFERENCE_FIELD )->GetText() ) );
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
}

View File

@ -39,7 +39,7 @@
#include <invoke_sch_dialog.h>
#include <kiface_i.h>
#include <netlist.h>
#include <netlist_exporter_generic.h>
#include <netlist_exporter_xml.h>
#include <pgm_base.h>
#include <reporter.h>
#include <sch_edit_frame.h>

View File

@ -585,8 +585,8 @@ int ERC_TESTER::TestMultUnitPinConflicts()
if( !pin->GetLibPin()->GetParent()->IsMulti() )
continue;
wxString name = ( pin->GetParentComponent()->GetRef( &subgraph->m_sheet ) +
":" + pin->GetNumber() );
wxString name = pin->GetParentSymbol()->GetRef( &subgraph->m_sheet ) +
+ ":" + pin->GetNumber();
if( !pinToNetMap.count( name ) )
{

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 1992-2017 jp.charras at wanadoo.fr
* Copyright (C) 2013-2017 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.TXT for contributors.
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,9 +23,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <netlist_exporter.h>
#include <netlist_exporter_base.h>
#include <confirm.h>
#include <pgm_base.h>
#include <refdes_utils.h>
@ -36,8 +35,10 @@
#include <schematic.h>
wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
const wxString& aNetlistFile, const wxString& aFinalFile, const wxString& aProjectPath )
wxString NETLIST_EXPORTER_BASE::MakeCommandLine( const wxString& aFormatString,
const wxString& aNetlistFile,
const wxString& aFinalFile,
const wxString& aProjectPath )
{
// Expand format symbols in the command line:
// %B => base filename of selected output file, minus path and extension.
@ -70,7 +71,7 @@ wxString NETLIST_EXPORTER::MakeCommandLine( const wxString& aFormatString,
}
SCH_COMPONENT* NETLIST_EXPORTER::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath )
SCH_COMPONENT* NETLIST_EXPORTER_BASE::findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath )
{
wxString ref;
@ -78,36 +79,35 @@ SCH_COMPONENT* NETLIST_EXPORTER::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_P
return nullptr;
// found next component
SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
SCH_COMPONENT* symbol = (SCH_COMPONENT*) aItem;
// Power symbols and other components which have the reference starting
// with "#" are not included in netlist (pseudo or virtual components)
ref = comp->GetRef( aSheetPath );
// Power symbols and other symbols which have the reference starting with "#" are not
// included in netlist (pseudo or virtual symbols)
ref = symbol->GetRef( aSheetPath );
if( ref[0] == wxChar( '#' ) )
return nullptr;
// if( Component->m_FlagControlMulti == 1 )
// if( symbol->m_FlagControlMulti == 1 )
// continue; /* yes */
// removed because with multiple instances of one schematic
// (several sheets pointing to 1 screen), this will be erroneously be
// toggled.
// removed because with multiple instances of one schematic (several sheets pointing to
// 1 screen), this will be erroneously be toggled.
if( !comp->GetPartRef() )
if( !symbol->GetPartRef() )
return nullptr;
// If component is a "multi parts per package" type
if( comp->GetPartRef()->GetUnitCount() > 1 )
if( symbol->GetPartRef()->GetUnitCount() > 1 )
{
// test if this reference has already been processed, and if so skip
if( m_ReferencesAlreadyFound.Lookup( ref ) )
if( m_referencesAlreadyFound.Lookup( ref ) )
return nullptr;
}
// record the usage of this library component entry.
m_LibParts.insert( comp->GetPartRef().get() ); // rejects non-unique pointers
m_libParts.insert( symbol->GetPartRef().get() ); // rejects non-unique pointers
return comp;
return symbol;
}
@ -119,72 +119,72 @@ static bool sortPinsByNum( PIN_INFO& aPin1, PIN_INFO& aPin2 )
}
void NETLIST_EXPORTER::CreatePinList( SCH_COMPONENT* comp, SCH_SHEET_PATH* aSheetPath )
void NETLIST_EXPORTER_BASE::CreatePinList( SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aSheetPath )
{
wxString ref( comp->GetRef( aSheetPath ) );
wxString ref( aSymbol->GetRef( aSheetPath ) );
// Power symbols and other components which have the reference starting
// with "#" are not included in netlist (pseudo or virtual components)
// Power symbols and other symbols which have the reference starting with "#" are not
// included in netlist (pseudo or virtual symbols)
if( ref[0] == wxChar( '#' ) )
return;
// if( Component->m_FlagControlMulti == 1 )
// if( aSymbol->m_FlagControlMulti == 1 )
// continue; /* yes */
// removed because with multiple instances of one schematic
// (several sheets pointing to 1 screen), this will be erroneously be
// toggled.
// removed because with multiple instances of one schematic (several sheets pointing to
// 1 screen), this will be erroneously be toggled.
if( !comp->GetPartRef() )
if( !aSymbol->GetPartRef() )
return;
m_SortedComponentPinList.clear();
m_sortedSymbolPinList.clear();
// If component is a "multi parts per package" type
if( comp->GetPartRef()->GetUnitCount() > 1 )
// If symbol is a "multi parts per package" type
if( aSymbol->GetPartRef()->GetUnitCount() > 1 )
{
// Collect all pins for this reference designator by searching
// the entire design for other parts with the same reference designator.
// Collect all pins for this reference designator by searching the entire design for
// other parts with the same reference designator.
// This is only done once, it would be too expensive otherwise.
findAllUnitsOfComponent( comp, comp->GetPartRef().get(), aSheetPath );
findAllUnitsOfSymbol( aSymbol, aSymbol->GetPartRef().get(), aSheetPath );
}
else // entry->GetUnitCount() <= 1 means one part per package
else // GetUnitCount() <= 1 means one part per package
{
for( const auto& pin : comp->GetPins( aSheetPath ) )
CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
for( const SCH_PIN* pin : aSymbol->GetPins( aSheetPath ) )
{
if( auto conn = pin->Connection( aSheetPath ) )
if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
{
const wxString& netName = conn->Name();
// Skip unconnected pins
CONNECTION_SUBGRAPH* sg =
m_schematic->ConnectionGraph()->FindSubgraphByName( netName, *aSheetPath );
CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
continue;
m_SortedComponentPinList.emplace_back( pin->GetNumber(), netName );
m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName );
}
}
}
// Sort pins in m_SortedComponentPinList by pin number
sort( m_SortedComponentPinList.begin(), m_SortedComponentPinList.end(), sortPinsByNum );
sort( m_sortedSymbolPinList.begin(), m_sortedSymbolPinList.end(), sortPinsByNum );
// Remove duplicate Pins in m_SortedComponentPinList
eraseDuplicatePins();
// record the usage of this library component entry.
m_LibParts.insert( comp->GetPartRef().get() ); // rejects non-unique pointers
m_libParts.insert( aSymbol->GetPartRef().get() ); // rejects non-unique pointers
}
void NETLIST_EXPORTER::eraseDuplicatePins()
void NETLIST_EXPORTER_BASE::eraseDuplicatePins()
{
for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
for( unsigned ii = 0; ii < m_sortedSymbolPinList.size(); ii++ )
{
if( m_SortedComponentPinList[ii].num.empty() ) /* already deleted */
if( m_sortedSymbolPinList[ii].num.empty() ) /* already deleted */
continue;
/* Search for duplicated pins
@ -197,33 +197,34 @@ void NETLIST_EXPORTER::eraseDuplicatePins()
*/
int idxref = ii;
for( unsigned jj = ii + 1; jj < m_SortedComponentPinList.size(); jj++ )
for( unsigned jj = ii + 1; jj < m_sortedSymbolPinList.size(); jj++ )
{
if( m_SortedComponentPinList[jj].num.empty() ) // Already removed
if( m_sortedSymbolPinList[jj].num.empty() ) // Already removed
continue;
// if other pin num, stop search,
// because all pins having the same number are consecutive in list.
if( m_SortedComponentPinList[idxref].num != m_SortedComponentPinList[jj].num )
if( m_sortedSymbolPinList[idxref].num != m_sortedSymbolPinList[jj].num )
break;
m_SortedComponentPinList[jj].num.clear();
m_sortedSymbolPinList[jj].num.clear();
}
}
}
void NETLIST_EXPORTER::findAllUnitsOfComponent( SCH_COMPONENT* aComponent,
LIB_PART* aEntry, SCH_SHEET_PATH* aSheetPath )
void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_COMPONENT* aSymbol,
LIB_PART* aPart, SCH_SHEET_PATH* aSheetPath )
{
wxString ref = aComponent->GetRef( aSheetPath );
wxString ref = aSymbol->GetRef( aSheetPath );
wxString ref2;
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
CONNECTION_GRAPH* graph = m_schematic->ConnectionGraph();
for( unsigned i = 0; i < sheetList.size(); i++ )
{
for( auto item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
SCH_COMPONENT* comp2 = static_cast<SCH_COMPONENT*>( item );
@ -232,20 +233,19 @@ void NETLIST_EXPORTER::findAllUnitsOfComponent( SCH_COMPONENT* aComponent,
if( ref2.CmpNoCase( ref ) != 0 )
continue;
for( const auto& pin : comp2->GetPins( aSheetPath ) )
for( const SCH_PIN* pin : comp2->GetPins( aSheetPath ) )
{
if( auto conn = pin->Connection( aSheetPath ) )
if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
{
const wxString& netName = conn->Name();
// Skip unconnected pins
CONNECTION_SUBGRAPH* sg = m_schematic->ConnectionGraph()->FindSubgraphByName(
netName, *aSheetPath );
CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
continue;
m_SortedComponentPinList.emplace_back( pin->GetNumber(), netName );
m_sortedSymbolPinList.emplace_back( pin->GetNumber(), netName );
}
}
}

View File

@ -90,71 +90,68 @@ struct PIN_INFO
};
/**
* NETLIST_EXPORTER
* NETLIST_EXPORTER_BASE
* is a abstract class used for the netlist exporters that eeschema supports.
*/
class NETLIST_EXPORTER
class NETLIST_EXPORTER_BASE
{
protected:
/// Used to temporarily store and filter the list of pins of a schematic component
/// when generating schematic component data in netlist (comp section). No ownership
/// of members.
/// Used to temporarily store and filter the list of pins of a schematic symbol when
/// generating schematic symbol data in netlist (comp section). No ownership of members.
/// TODO(snh): Descope this object
std::vector<PIN_INFO> m_SortedComponentPinList;
std::vector<PIN_INFO> m_sortedSymbolPinList;
/// Used for "multi parts per package" components,
/// avoids processing a lib component more than once.
UNIQUE_STRINGS m_ReferencesAlreadyFound;
/// Used for "multiple parts per package" symbols to avoid processing a lib part more than
/// once
UNIQUE_STRINGS m_referencesAlreadyFound;
/// unique library parts used. LIB_PART items are s
/// orted by names
std::set<LIB_PART*, LIB_PART_LESS_THAN> m_LibParts;
/// unique library parts used. LIB_PART items are sorted by names
std::set<LIB_PART*, LIB_PART_LESS_THAN> m_libParts;
/// The schematic we're generating a netlist for
SCHEMATIC* m_schematic;
SCHEMATIC* m_schematic;
/**
* Function findNextComponentAndCreatePinList
* finds a component from the DrawList and builds
* its pin list in m_SortedComponentPinList. This list is sorted by pin num.
* the component is the next actual component after aItem
* (power symbols and virtual components that have their reference starting by '#'are skipped).
* Function findNextSymbolAndCreatePinList
* finds a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList. This
* list is sorted by pin num. The symbol is the next actual symbol after aSymbol.
*
* Power symbols and virtual symbols that have their reference designators starting with
* '#' are skipped.
*/
void CreatePinList( SCH_COMPONENT* aItem, SCH_SHEET_PATH* aSheetPath );
void CreatePinList( SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aSheetPath );
/**
* Checks if the given component should be processed for netlisting.
* Prevents processing multi-unit components more than once, etc.
* @param aItem is a component to check
* @param aSheetPath is the sheet to check the component for
* @return the component if it should be processed, or nullptr
* Checks if the given symbol should be processed for netlisting.
* Prevents processing multi-unit symbols more than once, etc.
* @param aItem is a symbol to check
* @param aSheetPath is the sheet to check the symbol for
* @return the symbol if it should be processed, or nullptr
*/
SCH_COMPONENT* findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
SCH_COMPONENT* findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
/**
* Function eraseDuplicatePins
* erase duplicate Pins from m_SortedComponentPinList (i.e. set pointer in this list to NULL).
* (This is a list of pins found in the whole schematic, for a single
* component.) These duplicate pins were put in list because some pins (powers... )
* are found more than one time when we have a multiple parts per package
* component. For instance, a 74ls00 has 4 parts, and therefore the VCC pin
* and GND pin appears 4 times in the list.
* erase duplicate Pins from m_sortedSymbolPinList (i.e. set pointer in this list to NULL).
* (This is a list of pins found in the whole schematic, for a single symbol.) These
* duplicate pins were put in list because some pins (power pins...) are found more than
* once when in "multiple parts per package" symbols. For instance, a 74ls00 has 4 parts,
* and therefore the VCC pin and GND pin appears 4 times in the list.
* Note: this list *MUST* be sorted by pin number (.m_PinNum member value)
* Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1
*/
void eraseDuplicatePins();
/**
* Function findAllUnitsOfComponent
* is used for "multiple parts per package" components.
* Function findAllUnitsOfSymbol
* is used for "multiple parts per package" symbols.
* <p>
* Search the entire design for all units of \a aComponent based on
* matching reference designator, and for each unit, add all its pins
* to the temporary sorted pin list, m_SortedComponentPinList.
* Search the entire design for all units of \a aSymbol based on matching reference
* designator, and for each unit, add all its pins to the temporary sorted pin list,
* m_sortedSymbolPinList.
*/
void findAllUnitsOfComponent( SCH_COMPONENT* aComponent,
LIB_PART* aEntry,
SCH_SHEET_PATH* aSheetPath );
void findAllUnitsOfSymbol( SCH_COMPONENT* aSymbol, LIB_PART* aPart,
SCH_SHEET_PATH* aSheetPath );
public:
@ -164,13 +161,13 @@ public:
* @param aMasterList we take ownership of this here.
* @param aLibTable is the symbol library table of the project.
*/
NETLIST_EXPORTER( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_BASE( SCHEMATIC* aSchematic ) :
m_schematic( aSchematic )
{
wxASSERT( aSchematic );
}
virtual ~NETLIST_EXPORTER()
virtual ~NETLIST_EXPORTER_BASE()
{
}
@ -185,9 +182,8 @@ public:
/**
* Function MakeCommandLine
* builds up a string that describes a command line for
* executing a child process. The input and output file names
* along with any options to the executable are all possibly
* builds up a string that describes a command line for executing a child process. The
* input and output file names along with any options to the executable are all possibly
* in the returned string.
*
* @param aFormatString holds:
@ -197,12 +193,10 @@ public:
* <li>formatting sequences, see below.
* </ul>
*
* @param aNetlistFile is the name of the input file for the
* external program, that is a intermediate netlist file in xml format.
* @param aFinalFile is the name of the output file that
* the user expects.
* @param aProjectDirectory is used for %P replacement, it should omit
* the trailing '/'.
* @param aNetlistFile is the name of the input file for the external program, that is a
* intermediate netlist file in xml format.
* @param aFinalFile is the name of the output file that the user expects.
* @param aProjectDirectory is used for %P replacement, it should omit the trailing '/'.
*
* <p> Supported formatting sequences and their meaning:
* <ul>
@ -215,10 +209,8 @@ public:
* <li> %P => project directory, without name and without trailing '/'
* </ul>
*/
static wxString MakeCommandLine( const wxString& aFormatString,
const wxString& aNetlistFile, const wxString& aFinalFile,
const wxString& aProjectDirectory
);
static wxString MakeCommandLine( const wxString& aFormatString, const wxString& aNetlistFile,
const wxString& aFinalFile, const wxString& aProjectDirectory );
};
#endif

View File

@ -53,7 +53,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
wxString msg;
wxString footprint;
SCH_COMPONENT* component;
SCH_COMPONENT* symbol;
wxString title = wxT( "Eeschema " ) + GetBuildVersion();
ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) );
@ -63,7 +63,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
ret |= fprintf( f, ".TYP FULL\n\n" );
// Create netlist footprints section
m_ReferencesAlreadyFound.Clear();
m_referencesAlreadyFound.Clear();
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
@ -71,23 +71,23 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
{
std::vector<SCH_COMPONENT*> cmps;
for( auto item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
component = findNextComponent( item, &sheetList[i] );
symbol = findNextSymbol( item, &sheetList[ i ] );
if( !component )
if( !symbol )
continue;
if( !component->GetField( FOOTPRINT_FIELD )->IsVoid() )
footprint = component->GetField( FOOTPRINT_FIELD )->GetShownText();
if( !symbol->GetField( FOOTPRINT_FIELD )->IsVoid() )
footprint = symbol->GetField( FOOTPRINT_FIELD )->GetShownText();
else
footprint = "$noname";
msg = component->GetRef( &sheetList[i] );
msg = symbol->GetRef( &sheetList[i] );
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
ret |= fprintf( f, "%s", TO_UTF8( msg ) );
msg = component->GetValue( &sheetList[i] );
msg = symbol->GetValue( &sheetList[i] );
msg.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( footprint ) );
@ -139,10 +139,10 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
// Netlist ordering: Net name, then ref des, then pin name
std::sort( sorted_items.begin(), sorted_items.end(),
[]( auto a, auto b )
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, 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 );
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
if( ref_a == ref_b )
return a.first->GetNumber() < b.first->GetNumber();
@ -154,10 +154,10 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
// pins across units. If the user connects the pins on each unit, they will
// appear on separate subgraphs. Remove those here:
sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
[]( auto a, auto b )
[]( std::pair<SCH_PIN*, SCH_SHEET_PATH> a, 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 );
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber();
} ),
@ -170,20 +170,21 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
SCH_PIN* pin = pair.first;
SCH_SHEET_PATH sheet = pair.second;
wxString refText = pin->GetParentComponent()->GetRef( &sheet );
wxString refText = pin->GetParentSymbol()->GetRef( &sheet );
wxString pinText = pin->GetNumber();
// Skip power symbols and virtual components
// Skip power symbols and virtual symbols
if( refText[0] == wxChar( '#' ) )
continue;
switch( print_ter )
{
case 0:
{
InitNetDescLine.Printf(
wxT( "\n%s %s %.4s %s" ), InitNetDesc, refText, pinText, netName );
}
InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
InitNetDesc,
refText,
pinText,
netName );
print_ter++;
break;

View File

@ -26,14 +26,14 @@
#ifndef NETLIST_EXPORTER_CADSTAR_H
#define NETLIST_EXPORTER_CADSTAR_H
#include "netlist_exporter.h"
#include "netlist_exporter_base.h"
/**
* NETLIST_EXPORTER_CADSTAR
* generates a netlist compatible with CADSTAR
*/
class NETLIST_EXPORTER_CADSTAR : public NETLIST_EXPORTER
class NETLIST_EXPORTER_CADSTAR : public NETLIST_EXPORTER_BASE
{
/**
* Function writeListOfNetsCADSTAR
@ -49,7 +49,7 @@ class NETLIST_EXPORTER_CADSTAR : public NETLIST_EXPORTER
public:
NETLIST_EXPORTER_CADSTAR( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER( aSchematic )
NETLIST_EXPORTER_BASE( aSchematic )
{
}

View File

@ -25,14 +25,16 @@
#include <algorithm>
#include <build_version.h>
#include <confirm.h>
#include <sch_edit_frame.h>
#include <xnode.h>
#include <connection_graph.h>
#include "netlist_exporter_kicad.h"
/**
* Generate the KiCad netlist format supported by Pcbnew. It is basically the XML netlist
* just formatted slightly different.
*/
bool NETLIST_EXPORTER_KICAD::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{
try

View File

@ -26,19 +26,19 @@
#ifndef NETLIST_EXPORTER_KICAD_H
#define NETLIST_EXPORTER_KICAD_H
#include <netlist_exporter_generic.h>
#include <netlist_exporter_xml.h>
class OUTPUTFORMATTER;
/**
* Generate the KiCad netlist format supported by Pcbnew. It is basically the generic
* netlist format just formatted slightly different.
* Generate the KiCad netlist format supported by Pcbnew. It is basically the XML netlist
* just formatted slightly different.
*/
class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_GENERIC
class NETLIST_EXPORTER_KICAD : public NETLIST_EXPORTER_XML
{
public:
NETLIST_EXPORTER_KICAD( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_GENERIC( aSchematic )
NETLIST_EXPORTER_XML( aSchematic )
{
m_resolveTextVars = false;
}

View File

@ -61,7 +61,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
// Create netlist footprints section
m_ReferencesAlreadyFound.Clear();
m_referencesAlreadyFound.Clear();
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
@ -72,7 +72,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
// Process component attributes
for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
SCH_COMPONENT* comp = findNextComponent( item, &sheet );
SCH_COMPONENT* comp = findNextSymbol( item, &sheet );
if( !comp )
continue;
@ -104,7 +104,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
ret |= fprintf( f, "\n" );
// Write pin list:
for( const PIN_INFO& pin : m_SortedComponentPinList )
for( const PIN_INFO& pin : m_sortedSymbolPinList )
{
netName = pin.netName;
netName.Replace( wxT( " " ), wxT( "_" ) );

View File

@ -26,17 +26,17 @@
#ifndef NETLIST_EXPORTER_ORCADPCB2_H
#define NETLIST_EXPORTER_ORCADPCB2_H
#include "netlist_exporter.h"
#include "netlist_exporter_base.h"
/**
* NETLIST_EXPORTER_ORCADPCB2
* generates a netlist compatible with OrCAD
*/
class NETLIST_EXPORTER_ORCADPCB2 : public NETLIST_EXPORTER
class NETLIST_EXPORTER_ORCADPCB2 : public NETLIST_EXPORTER_BASE
{
public:
NETLIST_EXPORTER_ORCADPCB2( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER( aSchematic )
NETLIST_EXPORTER_BASE( aSchematic )
{
}

View File

@ -274,8 +274,8 @@ bool NETLIST_EXPORTER_PSPICE::ProcessNetlist( unsigned aCtl )
int netIdx = 1;
m_libraries.clear();
m_ReferencesAlreadyFound.Clear();
m_LibParts.clear();
m_referencesAlreadyFound.Clear();
m_libParts.clear();
UpdateDirectives( aCtl );
@ -286,7 +286,7 @@ bool NETLIST_EXPORTER_PSPICE::ProcessNetlist( unsigned aCtl )
// Process component attributes to find Spice directives
for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
SCH_COMPONENT* comp = findNextComponent( item, &sheet );
SCH_COMPONENT* comp = findNextSymbol( item, &sheet );
if( !comp )
continue;
@ -322,7 +322,7 @@ bool NETLIST_EXPORTER_PSPICE::ProcessNetlist( unsigned aCtl )
wxArrayString pinNames;
// Store pin information
for( const PIN_INFO& pin : m_SortedComponentPinList )
for( const PIN_INFO& pin : m_sortedSymbolPinList )
{
// Create net mapping
spiceItem.m_pins.push_back( pin.netName );

View File

@ -26,7 +26,7 @@
#ifndef NETLIST_EXPORTER_PSPICE_H
#define NETLIST_EXPORTER_PSPICE_H
#include "netlist_exporter.h"
#include "netlist_exporter_base.h"
#include <list>
#include <map>
@ -98,11 +98,11 @@ struct SPICE_ITEM
* NETLIST_EXPORTER_PSPICE
* generates a PSPICE compatible netlist
*/
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER
class NETLIST_EXPORTER_PSPICE : public NETLIST_EXPORTER_BASE
{
public:
NETLIST_EXPORTER_PSPICE( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER( aSchematic )
NETLIST_EXPORTER_BASE( aSchematic )
{
}
@ -140,7 +140,7 @@ public:
*/
bool WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions ) override;
///> @copydoc NETLIST_EXPORTER::Format()
///> @copydoc NETLIST_EXPORTER_BASE::Format()
bool Format( OUTPUTFORMATTER* aFormatter, unsigned aCtl );
/**

View File

@ -23,7 +23,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "netlist_exporter_generic.h"
#include "netlist_exporter_xml.h"
#include <build_version.h>
#include <sch_base_frame.h>
@ -37,8 +37,7 @@
static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 );
bool NETLIST_EXPORTER_GENERIC::WriteNetlist( const wxString& aOutFileName,
unsigned aNetlistOptions )
bool NETLIST_EXPORTER_XML::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions )
{
// output the XML format netlist.
wxXmlDocument xdoc;
@ -49,7 +48,7 @@ bool NETLIST_EXPORTER_GENERIC::WriteNetlist( const wxString& aOutFileName,
}
XNODE* NETLIST_EXPORTER_GENERIC::makeRoot( unsigned aCtl )
XNODE* NETLIST_EXPORTER_XML::makeRoot( unsigned aCtl )
{
XNODE* xroot = node( "export" );
@ -60,7 +59,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeRoot( unsigned aCtl )
xroot->AddChild( makeDesignHeader() );
if( aCtl & GNL_COMPONENTS )
xroot->AddChild( makeComponents( aCtl ) );
xroot->AddChild( makeSymbols( aCtl ) );
if( aCtl & GNL_PARTS )
xroot->AddChild( makeLibParts() );
@ -87,12 +86,12 @@ struct COMP_FIELDS
};
void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT* comp,
SCH_SHEET_PATH* aSheet )
void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_COMPONENT* aSymbol,
SCH_SHEET_PATH* aSheet )
{
COMP_FIELDS fields;
if( comp->GetUnitCount() > 1 )
if( aSymbol->GetUnitCount() > 1 )
{
// Sadly, each unit of a component can have its own unique fields. This
// block finds the unit with the lowest number having a non blank field
@ -101,10 +100,10 @@ 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.
wxString ref = comp->GetRef( aSheet );
wxString ref = aSymbol->GetRef( aSheet );
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
int minUnit = comp->GetUnit();
int minUnit = aSymbol->GetUnit();
for( unsigned i = 0; i < sheetList.size(); i++ )
{
@ -170,23 +169,23 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
else
{
if( m_resolveTextVars )
fields.value = comp->GetField( VALUE_FIELD )->GetShownText();
fields.value = aSymbol->GetField( VALUE_FIELD )->GetShownText();
else
fields.value = comp->GetField( VALUE_FIELD )->GetText();
fields.value = aSymbol->GetField( VALUE_FIELD )->GetText();
if( m_resolveTextVars )
fields.footprint = comp->GetField( FOOTPRINT_FIELD )->GetShownText();
fields.footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetShownText();
else
fields.footprint = comp->GetField( FOOTPRINT_FIELD )->GetText();
fields.footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
if( m_resolveTextVars )
fields.datasheet = comp->GetField( DATASHEET_FIELD )->GetShownText();
fields.datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetShownText();
else
fields.datasheet = comp->GetField( DATASHEET_FIELD )->GetText();
fields.datasheet = aSymbol->GetField( DATASHEET_FIELD )->GetText();
for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
for( int fldNdx = MANDATORY_FIELDS; fldNdx < aSymbol->GetFieldCount(); ++fldNdx )
{
SCH_FIELD* f = comp->GetField( fldNdx );
SCH_FIELD* f = aSymbol->GetField( fldNdx );
if( f->GetText().size() )
{
@ -200,20 +199,20 @@ 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 ) );
aNode->AddChild( node( "value", fields.value ) );
else // value field always written in netlist
xcomp->AddChild( node( "value", "~" ) );
aNode->AddChild( node( "value", "~" ) );
if( fields.footprint.size() )
xcomp->AddChild( node( "footprint", fields.footprint ) );
aNode->AddChild( node( "footprint", fields.footprint ) );
if( fields.datasheet.size() )
xcomp->AddChild( node( "datasheet", fields.datasheet ) );
aNode->AddChild( node( "datasheet", fields.datasheet ) );
if( fields.f.size() )
{
XNODE* xfields;
xcomp->AddChild( xfields = node( "fields" ) );
aNode->AddChild( xfields = node( "fields" ) );
// non MANDATORY fields are output alphabetically
for( std::map< wxString, wxString >::const_iterator it = fields.f.begin();
@ -227,12 +226,12 @@ void NETLIST_EXPORTER_GENERIC::addComponentFields( XNODE* xcomp, SCH_COMPONENT*
}
XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
{
XNODE* xcomps = node( "components" );
m_ReferencesAlreadyFound.Clear();
m_LibParts.clear();
m_referencesAlreadyFound.Clear();
m_libParts.clear();
SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
@ -249,62 +248,61 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
b->GetRef( &sheet ) ) < 0 );
};
std::set<SCH_COMPONENT*, decltype( cmp )> ordered_components( cmp );
std::set<SCH_COMPONENT*, decltype( cmp )> ordered_symbols( cmp );
for( SCH_ITEM* item : sheetList[ii].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( item );
auto test = ordered_components.insert( comp );
SCH_COMPONENT* symbol = static_cast<SCH_COMPONENT*>( item );
auto test = ordered_symbols.insert( symbol );
if( !test.second )
{
if( ( *( test.first ) )->GetUnit() > comp->GetUnit() )
if( ( *( test.first ) )->GetUnit() > symbol->GetUnit() )
{
ordered_components.erase( test.first );
ordered_components.insert( comp );
ordered_symbols.erase( test.first );
ordered_symbols.insert( symbol );
}
}
}
for( EDA_ITEM* item : ordered_components )
for( EDA_ITEM* item : ordered_symbols )
{
SCH_COMPONENT* comp = findNextComponent( item, &sheet );
SCH_COMPONENT* symbol = findNextSymbol( item, &sheet );
if( !comp
|| ( ( aCtl & GNL_OPT_BOM ) && !comp->GetIncludeInBom() )
|| ( ( aCtl & GNL_OPT_KICAD ) && !comp->GetIncludeOnBoard() ) )
if( !symbol
|| ( ( aCtl & GNL_OPT_BOM ) && !symbol->GetIncludeInBom() )
|| ( ( aCtl & GNL_OPT_KICAD ) && !symbol->GetIncludeOnBoard() ) )
{
continue;
}
// Output the component's elements in order of expected access frequency.
// This may not always look best, but it will allow faster execution
// under XSL processing systems which do sequential searching within
// an element.
// Output the symbol's elements in order of expected access frequency. This may
// not always look best, but it will allow faster execution under XSL processing
// systems which do sequential searching within an element.
XNODE* xcomp; // current component being constructed
xcomps->AddChild( xcomp = node( "comp" ) );
xcomp->AddAttribute( "ref", comp->GetRef( &sheet ) );
addComponentFields( xcomp, comp, &sheetList[ii] );
xcomp->AddAttribute( "ref", symbol->GetRef( &sheet ) );
addSymbolFields( xcomp, symbol, &sheetList[ ii ] );
XNODE* xlibsource;
xcomp->AddChild( xlibsource = node( "libsource" ) );
// "logical" library name, which is in anticipation of a better search
// algorithm for parts based on "logical_lib.part" and where logical_lib
// is merely the library name minus path and extension.
if( comp->GetPartRef() )
xlibsource->AddAttribute( "lib", comp->GetPartRef()->GetLibId().GetLibNickname() );
// "logical" library name, which is in anticipation of a better search algorithm
// for parts based on "logical_lib.part" and where logical_lib is merely the library
// name minus path and extension.
if( symbol->GetPartRef() )
xlibsource->AddAttribute( "lib", symbol->GetPartRef()->GetLibId().GetLibNickname() );
// We only want the symbol name, not the full LIB_ID.
xlibsource->AddAttribute( "part", comp->GetLibId().GetLibItemName() );
xlibsource->AddAttribute( "part", symbol->GetLibId().GetLibItemName() );
xlibsource->AddAttribute( "description", comp->GetDescription() );
xlibsource->AddAttribute( "description", symbol->GetDescription() );
XNODE* xproperty;
std::vector<SCH_FIELD>& fields = comp->GetFields();
std::vector<SCH_FIELD>& fields = symbol->GetFields();
for( size_t jj = MANDATORY_FIELDS; jj < fields.size(); ++jj )
{
@ -320,13 +318,13 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
xproperty->AddAttribute( "value", sheetField.GetText() );
}
if( !comp->GetIncludeInBom() )
if( !symbol->GetIncludeInBom() )
{
xcomp->AddChild( xproperty = node( "property" ) );
xproperty->AddAttribute( "name", "exclude_from_bom" );
}
if( !comp->GetIncludeOnBoard() )
if( !symbol->GetIncludeOnBoard() )
{
xcomp->AddChild( xproperty = node( "property" ) );
xproperty->AddAttribute( "name", "exclude_from_board" );
@ -337,7 +335,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
xsheetpath->AddAttribute( "names", sheet.PathHumanReadable() );
xsheetpath->AddAttribute( "tstamps", sheet.PathAsString() );
xcomp->AddChild( node( "tstamp", comp->m_Uuid.AsString() ) );
xcomp->AddChild( node( "tstamp", symbol->m_Uuid.AsString() ) );
}
}
@ -345,7 +343,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeComponents( unsigned aCtl )
}
XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
XNODE* NETLIST_EXPORTER_XML::makeDesignHeader()
{
SCH_SCREEN* screen;
XNODE* xdesign = node( "design" );
@ -446,7 +444,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader()
}
XNODE* NETLIST_EXPORTER_GENERIC::makeLibraries()
XNODE* NETLIST_EXPORTER_XML::makeLibraries()
{
XNODE* xlibs = node( "libraries" ); // auto_ptr
SYMBOL_LIB_TABLE* symbolLibTable = m_schematic->Prj().SchSymbolLibTable();
@ -470,7 +468,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeLibraries()
}
XNODE* NETLIST_EXPORTER_GENERIC::makeLibParts()
XNODE* NETLIST_EXPORTER_XML::makeLibParts()
{
XNODE* xlibparts = node( "libparts" ); // auto_ptr
@ -479,7 +477,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeLibParts()
m_libraries.clear();
for( auto lcomp : m_LibParts )
for( auto lcomp : m_libParts )
{
wxString libNickname = lcomp->GetLibId().GetLibNickname();;
@ -573,7 +571,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeLibParts()
}
XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
{
XNODE* xnets = node( "nets" ); // auto_ptr if exceptions ever get used.
wxString netCodeTxt;
@ -612,11 +610,11 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
if( item->Type() == SCH_PIN_T )
{
SCH_PIN* pin = static_cast<SCH_PIN*>( item );
SCH_COMPONENT* comp = pin->GetParentComponent();
SCH_COMPONENT* symbol = pin->GetParentSymbol();
if( !comp
|| ( ( aCtl & GNL_OPT_BOM ) && !comp->GetIncludeInBom() )
|| ( ( aCtl & GNL_OPT_KICAD ) && !comp->GetIncludeOnBoard() ) )
if( !symbol
|| ( ( aCtl & GNL_OPT_BOM ) && !symbol->GetIncludeInBom() )
|| ( ( aCtl & GNL_OPT_KICAD ) && !symbol->GetIncludeOnBoard() ) )
{
continue;
}
@ -631,8 +629,8 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
[]( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
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 );
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
if( ref_a == ref_b )
return a.first->GetNumber() < b.first->GetNumber();
@ -647,8 +645,8 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
[]( const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
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 );
wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber();
} ),
@ -659,7 +657,7 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
SCH_PIN* pin = pair.first;
SCH_SHEET_PATH sheet = pair.second;
wxString refText = pin->GetParentComponent()->GetRef( &sheet );
wxString refText = pin->GetParentSymbol()->GetRef( &sheet );
wxString pinText = pin->GetNumber();
// Skip power symbols and virtual components
@ -694,8 +692,8 @@ XNODE* NETLIST_EXPORTER_GENERIC::makeListOfNets( unsigned aCtl )
}
XNODE* NETLIST_EXPORTER_GENERIC::node( const wxString& aName,
const wxString& aTextualContent /* = wxEmptyString*/ )
XNODE* NETLIST_EXPORTER_XML::node( const wxString& aName,
const wxString& aTextualContent /* = wxEmptyString*/ )
{
XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );

View File

@ -23,10 +23,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef NETLIST_EXPORT_GENERIC_H
#define NETLIST_EXPORT_GENERIC_H
#ifndef NETLIST_EXPORT_XML_H
#define NETLIST_EXPORT_XML_H
#include <netlist_exporter.h>
#include <netlist_exporter_base.h>
#include <project.h>
#include <xnode.h> // also nests: <wx/xml/xml.h>
@ -59,7 +59,7 @@ enum GNL_T
* This allows using XSLT or other methods to transform the XML to other netlist formats
* outside of the C++ codebase.
*/
class NETLIST_EXPORTER_GENERIC : public NETLIST_EXPORTER
class NETLIST_EXPORTER_XML : public NETLIST_EXPORTER_BASE
{
private:
std::set<wxString> m_libraries; // Set of library nicknames.
@ -68,9 +68,9 @@ protected:
bool m_resolveTextVars; // Export textVar references resolved
public:
NETLIST_EXPORTER_GENERIC( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER( aSchematic ),
m_resolveTextVars( true )
NETLIST_EXPORTER_XML( SCHEMATIC* aSchematic ) :
NETLIST_EXPORTER_BASE( aSchematic ),
m_resolveTextVars( true )
{}
/**
@ -108,7 +108,7 @@ protected:
/**
* @return XNODE* - returns a sub-tree holding all the schematic components.
*/
XNODE* makeComponents( unsigned aCtl );
XNODE* makeSymbols( unsigned aCtl );
/**
* Fills out a project "design" header into an XML node.
@ -135,7 +135,7 @@ protected:
*/
XNODE* makeLibraries();
void addComponentFields( XNODE* xcomp, SCH_COMPONENT* comp, SCH_SHEET_PATH* aSheet );
void addSymbolFields( XNODE* aNode, SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aSheet );
};
#endif

View File

@ -34,12 +34,12 @@
#include <erc.h>
#include <netlist.h>
#include <netlist_exporter.h>
#include <netlist_exporter_base.h>
#include <netlist_exporter_orcadpcb2.h>
#include <netlist_exporter_cadstar.h>
#include <netlist_exporter_pspice.h>
#include <netlist_exporter_kicad.h>
#include <netlist_exporter_generic.h>
#include <netlist_exporter_xml.h>
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
@ -59,7 +59,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
wxString fileName = aFullFileName;
NETLIST_EXPORTER *helper;
NETLIST_EXPORTER_BASE *helper;
SCHEMATIC* sch = &Schematic();
@ -87,7 +87,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT );
fileName = tmpFile.GetFullPath();
helper = new NETLIST_EXPORTER_GENERIC( sch );
helper = new NETLIST_EXPORTER_XML( sch );
executeCommandLine = true;
}
break;
@ -101,14 +101,16 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam
{
wxString prj_dir = Prj().GetProjectPath();
// strip trailing '/'
prj_dir = prj_dir.SubString( 0, prj_dir.Len() - 2 );
// build full command line from user's format string, e.g.:
// "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I"
// becomes, after the user selects /tmp/s1.net as the output file from the file dialog:
// "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml"
wxString commandLine = NETLIST_EXPORTER::MakeCommandLine( m_netListerCommand,
fileName, aFullFileName,
prj_dir.SubString( 0, prj_dir.Len() - 2 ) // strip trailing '/'
);
wxString commandLine = NETLIST_EXPORTER_BASE::MakeCommandLine( m_netListerCommand,
fileName, aFullFileName,
prj_dir );
if( aReporter )
{

View File

@ -264,8 +264,7 @@ bool SCH_CONNECTION::IsDriver() const
auto pin = static_cast<SCH_PIN*>( Parent() );
// Only annotated components should drive nets
return ( pin->IsPowerConnection()
|| pin->GetParentComponent()->IsAnnotated( &m_sheet ) );
return pin->IsPowerConnection() || pin->GetParentSymbol()->IsAnnotated( &m_sheet );
}
default:

View File

@ -139,7 +139,7 @@ bool SCH_PIN::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
}
SCH_COMPONENT* SCH_PIN::GetParentComponent() const
SCH_COMPONENT* SCH_PIN::GetParentSymbol() const
{
return static_cast<SCH_COMPONENT*>( GetParent() );
}
@ -148,7 +148,7 @@ SCH_COMPONENT* SCH_PIN::GetParentComponent() const
wxString SCH_PIN::GetSelectMenuText( EDA_UNITS aUnits ) const
{
return wxString::Format( "%s %s",
GetParentComponent()->GetSelectMenuText( aUnits ),
GetParentSymbol()->GetSelectMenuText( aUnits ),
m_libPin->GetSelectMenuText( aUnits ) );
}
@ -200,9 +200,9 @@ void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
SCH_EDIT_FRAME* schframe = dynamic_cast<SCH_EDIT_FRAME*>( aFrame );
SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
SCH_COMPONENT* comp = GetParentComponent();
SCH_COMPONENT* symbol = GetParentSymbol();
aList.emplace_back( comp->GetRef( currentSheet ), comp->GetValue( currentSheet ), DARKCYAN );
aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet ), DARKCYAN );
#if defined(DEBUG)
@ -244,14 +244,14 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath )
wxString name = "Net-(";
name << GetParentComponent()->GetRef( &aPath );
name << GetParentSymbol()->GetRef( &aPath );
bool annotated = true;
// Add timestamp for uninitialized components
if( name.Last() == '?' )
{
name << GetParentComponent()->m_Uuid.AsString();
name << GetParentSymbol()->m_Uuid.AsString();
annotated = false;
}
@ -266,20 +266,20 @@ wxString SCH_PIN::GetDefaultNetName( const SCH_SHEET_PATH& aPath )
wxPoint SCH_PIN::GetTransformedPosition() const
{
TRANSFORM t = GetParentComponent()->GetTransform();
return ( t.TransformCoordinate( GetLocalPosition() ) + GetParentComponent()->GetPosition() );
TRANSFORM t = GetParentSymbol()->GetTransform();
return t.TransformCoordinate( GetLocalPosition() ) + GetParentSymbol()->GetPosition();
}
const EDA_RECT SCH_PIN::GetBoundingBox() const
{
TRANSFORM t = GetParentComponent()->GetTransform();
TRANSFORM t = GetParentSymbol()->GetTransform();
EDA_RECT r = m_libPin->GetBoundingBox();
r.RevertYAxis();
r = t.TransformCoordinate( r );
r.Offset( GetParentComponent()->GetPosition() );
r.Offset( GetParentSymbol()->GetPosition() );
return r;
}

View File

@ -64,7 +64,7 @@ public:
return wxT( "SCH_PIN" );
}
SCH_COMPONENT* GetParentComponent() const;
SCH_COMPONENT* GetParentSymbol() const;
LIB_PIN* GetLibPin() const { return m_libPin; }

View File

@ -186,8 +186,10 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
SCH_SHEET_LIST sheetHierarchy( newSheet.get() ); // This is the hierarchy of the loaded file.
if( CheckSheetForRecursion( newSheet.get(), aHierarchy )
|| checkForNoFullyDefinedLibIds( newSheet.get() ) )
|| checkForNoFullyDefinedLibIds( newSheet.get() ) )
{
return false;
}
// Make a valiant attempt to warn the user of all possible scenarios where there could
// be broken symbol library links.
@ -202,7 +204,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
wxMessageDialog::ButtonLabel cancelButtonLabel( _( "Cancel Load" ) );
if( fileName.GetPathWithSep() == Prj().GetProjectPath()
&& !prjScreens.HasSchematic( fullFilename ) )
&& !prjScreens.HasSchematic( fullFilename ) )
{
// A schematic in the current project path that isn't part of the current project.
// It's possible the user copied this schematic from another project so the library
@ -276,8 +278,7 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier
}
catch( const IO_ERROR& ioe )
{
msg.Printf( _( "An error occurred loading the symbol library table "
"\"%s\"." ),
msg.Printf( _( "An error occurred loading the symbol library table \"%s\"." ),
symLibTableFn.GetFullPath() );
DisplayErrorMessage( NULL, msg, ioe.What() );
return false;

View File

@ -259,7 +259,7 @@ private:
/**
* @brief Filters out tuners for components that do not exist anymore.
* Decisions are based on the current NETLIST_EXPORTER data.
* Decisions are based on the current NETLIST_EXPORTER_BASE data.
*/
void updateTuners();

View File

@ -447,7 +447,7 @@ static LABEL_SPIN_STYLE orientLabel( SCH_PIN* aPin )
ORIENT o = orientations[ 0 ];
SCH_COMPONENT* comp = aPin->GetParentComponent();
SCH_COMPONENT* comp = aPin->GetParentSymbol();
if( !comp )
return spin;

View File

@ -47,25 +47,25 @@ public:
m_lib_pin->SetPosition( wxPoint( 1, -2 ) ); // local coord system is upside-down
SCH_SHEET_PATH path;
m_parent_comp = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
&path, 0, 0, wxPoint( 1, 2 ) );
m_parent_comp->SetRef( &path, "U2" );
m_parent_comp->UpdatePins();
m_parent_symbol = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
&path, 0, 0, wxPoint( 1, 2 ) );
m_parent_symbol->SetRef( &path, "U2" );
m_parent_symbol->UpdatePins();
m_sch_pin = m_parent_comp->GetPins( &path )[0];
m_sch_pin = m_parent_symbol->GetPins( &path )[0];
}
~TEST_SCH_PIN_FIXTURE()
{
delete m_parent_comp;
delete m_parent_symbol;
delete m_parent_part;
}
LIB_PART* m_parent_part;
LIB_PIN* m_lib_pin;
SCH_COMPONENT* m_parent_comp;
SCH_PIN* m_sch_pin; // owned by m_parent_comp, not us
SCH_COMPONENT* m_parent_symbol;
SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
};
@ -79,7 +79,7 @@ BOOST_FIXTURE_TEST_SUITE( SchPin, TEST_SCH_PIN_FIXTURE )
*/
BOOST_AUTO_TEST_CASE( DefaultProperties )
{
BOOST_CHECK_EQUAL( m_sch_pin->GetParentComponent(), m_parent_comp );
BOOST_CHECK_EQUAL( m_sch_pin->GetParentSymbol(), m_parent_symbol );
// Note: local coord system is upside-down; schematic coord system is not.
BOOST_CHECK_EQUAL( m_sch_pin->GetLocalPosition(), wxPoint( 1, -2 ) );
@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE( Assign )
{
SCH_PIN assigned = *m_sch_pin;
BOOST_CHECK_EQUAL( assigned.GetParentComponent(), m_parent_comp );
BOOST_CHECK_EQUAL( assigned.GetParentSymbol(), m_parent_symbol );
BOOST_CHECK_EQUAL( assigned.GetNumber(), m_lib_pin->GetNumber() );
}
@ -112,7 +112,7 @@ BOOST_AUTO_TEST_CASE( Copy )
{
SCH_PIN copied( *m_sch_pin );
BOOST_CHECK_EQUAL( copied.GetParentComponent(), m_parent_comp );
BOOST_CHECK_EQUAL( copied.GetParentSymbol(), m_parent_symbol );
BOOST_CHECK_EQUAL( copied.GetNumber(), m_lib_pin->GetNumber() );
}
@ -158,15 +158,15 @@ BOOST_AUTO_TEST_CASE( PinNumberingPower )
m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
m_parent_part->SetPower();
// and update component from library...
// and update symbol from library...
SCH_SHEET_PATH path;
delete m_parent_comp;
m_parent_comp = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
&path, 0, 0, wxPoint( 1, 2 ) );
m_parent_comp->SetRef( &path, "U2" );
m_parent_comp->UpdatePins();
delete m_parent_symbol;
m_parent_symbol = new SCH_COMPONENT( *m_parent_part, m_parent_part->GetLibId(),
&path, 0, 0, wxPoint( 1, 2 ) );
m_parent_symbol->SetRef( &path, "U2" );
m_parent_symbol->UpdatePins();
m_sch_pin = m_parent_comp->GetPins( &path )[0];
m_sch_pin = m_parent_symbol->GetPins( &path )[0];
// ... then the name is just the pin name
const wxString pwr_name = m_sch_pin->GetDefaultNetName( path );