Fix some instance-data issues in netlist exporters.
Also removes the final requirements for setting the current sheet so that we no longer need to do a save/restore.
This commit is contained in:
parent
ae671c07e1
commit
1964087960
|
@ -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-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2022 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
|
||||
|
@ -113,8 +113,7 @@ SCH_SYMBOL* NETLIST_EXPORTER_BASE::findNextSymbol( EDA_ITEM* aItem, SCH_SHEET_PA
|
|||
}
|
||||
|
||||
|
||||
void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
|
||||
SCH_SHEET_PATH* aSheetPath,
|
||||
void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheetPath,
|
||||
bool aKeepUnconnectedPins )
|
||||
{
|
||||
wxString ref( aSymbol->GetRef( aSheetPath ) );
|
||||
|
@ -141,8 +140,7 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
|
|||
// 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.
|
||||
findAllUnitsOfSymbol( aSymbol, aSymbol->GetLibSymbolRef().get(),
|
||||
aSheetPath, aKeepUnconnectedPins );
|
||||
findAllUnitsOfSymbol( aSymbol, aSheetPath, aKeepUnconnectedPins );
|
||||
}
|
||||
|
||||
else // GetUnitCount() <= 1 means one part per package
|
||||
|
@ -160,7 +158,7 @@ void NETLIST_EXPORTER_BASE::CreatePinList( SCH_SYMBOL* aSymbol,
|
|||
CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
|
||||
|
||||
if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
|
||||
|
@ -216,7 +214,7 @@ void NETLIST_EXPORTER_BASE::eraseDuplicatePins()
|
|||
}
|
||||
|
||||
|
||||
void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSymbol,
|
||||
void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol,
|
||||
SCH_SHEET_PATH* aSheetPath,
|
||||
bool aKeepUnconnectedPins )
|
||||
{
|
||||
|
|
|
@ -193,8 +193,8 @@ protected:
|
|||
* if aKeepUnconnectedPins = false, unconnected pins will be removed from list
|
||||
* but usually we need all pins in netlists.
|
||||
*/
|
||||
void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSymbol,
|
||||
SCH_SHEET_PATH* aSheetPath, bool aKeepUnconnectedPins );
|
||||
void findAllUnitsOfSymbol( SCH_SYMBOL* aSchSymbol, SCH_SHEET_PATH* aSheetPath,
|
||||
bool aKeepUnconnectedPins );
|
||||
|
||||
/// 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.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 1992-2018 jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 1992-2022 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
|
||||
|
@ -76,9 +76,9 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName,
|
|||
if( !symbol )
|
||||
continue;
|
||||
|
||||
if( !symbol->GetField( FOOTPRINT_FIELD )->IsVoid() )
|
||||
footprint = symbol->GetField( FOOTPRINT_FIELD )->GetShownText();
|
||||
else
|
||||
footprint = symbol->GetFootprint( &sheetList[i], true );
|
||||
|
||||
if( footprint.IsEmpty() )
|
||||
footprint = "$noname";
|
||||
|
||||
msg = symbol->GetRef( &sheetList[i] );
|
||||
|
@ -116,11 +116,9 @@ bool NETLIST_EXPORTER_CADSTAR::writeListOfNets( FILE* f )
|
|||
wxString InitNetDescLine;
|
||||
wxString netName;
|
||||
|
||||
for( const auto& it : m_schematic->ConnectionGraph()->GetNetMap() )
|
||||
for( const auto& [ key, subgraphs ] : m_schematic->ConnectionGraph()->GetNetMap() )
|
||||
{
|
||||
const std::vector<CONNECTION_SUBGRAPH*>& subgraphs = it.second;
|
||||
|
||||
netName.Printf( wxT( "\"%s\"" ), it.first.Name );
|
||||
netName.Printf( wxT( "\"%s\"" ), key.Name );
|
||||
|
||||
std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items;
|
||||
|
||||
|
|
|
@ -206,6 +206,11 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
|
|||
CreatePinList( symbol, &sheet, true );
|
||||
|
||||
SPICE_ITEM spiceItem;
|
||||
|
||||
// This is a little bit dangerous as any value fetched from the fields will not
|
||||
// be instance-data aware, and will just fetch the value of some random sheet
|
||||
// (whatever sheet the user happens to be looking at). However, we currently only
|
||||
// use it to fetch "Sim_*" fields, which have no instance data.
|
||||
spiceItem.fields = &symbol->GetFields();
|
||||
|
||||
try
|
||||
|
@ -269,14 +274,14 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
|
|||
|
||||
for( const SCH_SHEET_PATH& sheet : GetSheets( aNetlistOptions ) )
|
||||
{
|
||||
for( SCH_ITEM* SPICE_ITEM : sheet.LastScreen()->Items() )
|
||||
for( SCH_ITEM* item : sheet.LastScreen()->Items() )
|
||||
{
|
||||
wxString text;
|
||||
|
||||
if( SPICE_ITEM->Type() == SCH_TEXT_T )
|
||||
text = static_cast<SCH_TEXT*>( SPICE_ITEM )->GetShownText();
|
||||
else if( SPICE_ITEM->Type() == SCH_TEXTBOX_T )
|
||||
text = static_cast<SCH_TEXTBOX*>( SPICE_ITEM )->GetShownText();
|
||||
if( item->Type() == SCH_TEXT_T )
|
||||
text = static_cast<SCH_TEXT*>( item )->GetShownText();
|
||||
else if( item->Type() == SCH_TEXTBOX_T )
|
||||
text = static_cast<SCH_TEXTBOX*>( item )->GetShownText();
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -320,7 +325,9 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_directives.emplace_back( node->string() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -436,7 +443,9 @@ void NETLIST_EXPORTER_SPICE::writeInclude( OUTPUTFORMATTER& aFormatter, unsigned
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fullPath = expandedPath;
|
||||
}
|
||||
|
||||
aFormatter.Print( 0, ".include \"%s\"\n", TO_UTF8( fullPath ) );
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2022 Mikolaj Wielgus, see AUTHORS.TXT for contributors.
|
||||
* Copyright (C) 2022 Mikolaj Wielgus.
|
||||
* Copyright (C) 2022 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
|
||||
|
@ -89,12 +90,16 @@ void NETLIST_EXPORTER_SPICE_MODEL::readPorts( unsigned aNetlistOptions )
|
|||
{
|
||||
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
|
||||
{
|
||||
auto label = static_cast<SCH_LABEL_BASE*>( item );
|
||||
SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
|
||||
|
||||
if( SCH_CONNECTION* conn = label->Connection( &sheet ) )
|
||||
{
|
||||
m_ports.insert( { std::string( conn->Name().ToUTF8() ),
|
||||
PORT_INFO{ std::string( label->GetText().ToUTF8() ),
|
||||
label->GetShape() } } );
|
||||
label->GetShape()
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -233,7 +233,6 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
|
|||
for( unsigned ii = 0; ii < sheetList.size(); ii++ )
|
||||
{
|
||||
SCH_SHEET_PATH sheet = sheetList[ii];
|
||||
m_schematic->SetCurrentSheet( sheet );
|
||||
|
||||
auto cmp = [sheet]( SCH_SYMBOL* a, SCH_SYMBOL* b )
|
||||
{
|
||||
|
@ -283,7 +282,7 @@ XNODE* NETLIST_EXPORTER_XML::makeSymbols( unsigned aCtl )
|
|||
xcomps->AddChild( xcomp = node( wxT( "comp" ) ) );
|
||||
|
||||
xcomp->AddAttribute( wxT( "ref" ), symbol->GetRef( &sheet ) );
|
||||
addSymbolFields( xcomp, symbol, &sheetList[ ii ] );
|
||||
addSymbolFields( xcomp, symbol, &sheet );
|
||||
|
||||
XNODE* xlibsource;
|
||||
xcomp->AddChild( xlibsource = node( wxT( "libsource" ) ) );
|
||||
|
@ -674,11 +673,10 @@ XNODE* NETLIST_EXPORTER_XML::makeListOfNets( unsigned aCtl )
|
|||
|
||||
std::vector<NET_RECORD*> nets;
|
||||
|
||||
for( const auto& it : m_schematic->ConnectionGraph()->GetNetMap() )
|
||||
for( const auto& [ key, subgraphs ] : m_schematic->ConnectionGraph()->GetNetMap() )
|
||||
{
|
||||
wxString net_name = it.first.Name;
|
||||
const std::vector<CONNECTION_SUBGRAPH*>& subgraphs = it.second;
|
||||
NET_RECORD* net_record = nullptr;
|
||||
wxString net_name = key.Name;
|
||||
NET_RECORD* net_record = nullptr;
|
||||
|
||||
if( subgraphs.empty() )
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue