mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Restore accidentally-removed schematic parity code from CLI
This will need a better fix later Fixes https://gitlab.com/kicad/code/kicad/-/issues/19929
This commit is contained in:
parent
df8f6f5cc0
commit
667bafc8bb
@ -76,6 +76,68 @@ SCH_SHEET* g_RootSheet = nullptr;
|
|||||||
namespace SCH {
|
namespace SCH {
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: This should move out of this file
|
||||||
|
static std::unique_ptr<SCHEMATIC> readSchematicFromFile( const std::string& aFilename )
|
||||||
|
{
|
||||||
|
SCH_IO* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
|
||||||
|
std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr );
|
||||||
|
|
||||||
|
SETTINGS_MANAGER& manager = Pgm().GetSettingsManager();
|
||||||
|
|
||||||
|
manager.LoadProject( "" );
|
||||||
|
schematic->Reset();
|
||||||
|
schematic->SetProject( &manager.Prj() );
|
||||||
|
schematic->SetRoot( pi->LoadSchematicFile( aFilename, schematic.get() ) );
|
||||||
|
schematic->CurrentSheet().push_back( &schematic->Root() );
|
||||||
|
|
||||||
|
SCH_SCREENS screens( schematic->Root() );
|
||||||
|
|
||||||
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
||||||
|
screen->UpdateLocalLibSymbolLinks();
|
||||||
|
|
||||||
|
SCH_SHEET_LIST sheets = schematic->Hierarchy();
|
||||||
|
|
||||||
|
// Restore all of the loaded symbol instances from the root sheet screen.
|
||||||
|
sheets.UpdateSymbolInstanceData( schematic->RootScreen()->GetSymbolInstances() );
|
||||||
|
|
||||||
|
if( schematic->RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
|
||||||
|
{
|
||||||
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
||||||
|
screen->FixLegacyPowerSymbolMismatches();
|
||||||
|
}
|
||||||
|
|
||||||
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
||||||
|
screen->MigrateSimModels();
|
||||||
|
|
||||||
|
sheets.AnnotatePowerSymbols();
|
||||||
|
|
||||||
|
// NOTE: This is required for multi-unit symbols to be correct
|
||||||
|
for( SCH_SHEET_PATH& sheet : sheets )
|
||||||
|
sheet.UpdateAllScreenReferences();
|
||||||
|
|
||||||
|
// NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
|
||||||
|
// SchematicCleanUp must be freed from its UI dependencies.
|
||||||
|
|
||||||
|
schematic->ConnectionGraph()->Recalculate( sheets, true );
|
||||||
|
|
||||||
|
return schematic;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: This should move out of this file
|
||||||
|
bool generateSchematicNetlist( const wxString& aFilename, std::string& aNetlist )
|
||||||
|
{
|
||||||
|
std::unique_ptr<SCHEMATIC> schematic = readSchematicFromFile( aFilename.ToStdString() );
|
||||||
|
NETLIST_EXPORTER_KICAD exporter( schematic.get() );
|
||||||
|
STRING_FORMATTER formatter;
|
||||||
|
|
||||||
|
exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD );
|
||||||
|
aNetlist = formatter.GetString();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
|
static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
|
||||||
{
|
{
|
||||||
// Of course all are virtual overloads, implementations of the KIFACE.
|
// Of course all are virtual overloads, implementations of the KIFACE.
|
||||||
@ -265,6 +327,12 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER
|
|||||||
*/
|
*/
|
||||||
void* IfaceOrAddress( int aDataId ) override
|
void* IfaceOrAddress( int aDataId ) override
|
||||||
{
|
{
|
||||||
|
switch( aDataId )
|
||||||
|
{
|
||||||
|
case KIFACE_NETLIST_SCHEMATIC:
|
||||||
|
return (void*) generateSchematicNetlist;
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ enum KIFACE_ADDR_ID : int
|
|||||||
KIFACE_GLOBAL_FOOTPRINT_TABLE,
|
KIFACE_GLOBAL_FOOTPRINT_TABLE,
|
||||||
|
|
||||||
KIFACE_LOAD_SCHEMATIC,
|
KIFACE_LOAD_SCHEMATIC,
|
||||||
|
KIFACE_NETLIST_SCHEMATIC,
|
||||||
KIFACE_SCRIPTING_LEGACY,
|
KIFACE_SCRIPTING_LEGACY,
|
||||||
KIFACE_SCRIPTING,
|
KIFACE_SCRIPTING,
|
||||||
|
|
||||||
|
@ -1820,7 +1820,37 @@ int PCBNEW_JOBS_HANDLER::JobExportDrc( JOB* aJob )
|
|||||||
wxString annotateMsg = _( "Schematic parity tests require a fully annotated schematic." );
|
wxString annotateMsg = _( "Schematic parity tests require a fully annotated schematic." );
|
||||||
netlist_str = annotateMsg;
|
netlist_str = annotateMsg;
|
||||||
|
|
||||||
m_kiway->ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, netlist_str );
|
// The KIFACE_NETLIST_SCHEMATIC function has some broken-ness that the schematic
|
||||||
|
// frame's version does not, but it is the only one that works in CLI, so we use it
|
||||||
|
// if we don't have the sch frame open.
|
||||||
|
// TODO: clean this up, see https://gitlab.com/kicad/code/kicad/-/issues/19929
|
||||||
|
if( m_kiway->Player( FRAME_SCH, false ) )
|
||||||
|
{
|
||||||
|
m_kiway->ExpressMail( FRAME_SCH, MAIL_SCH_GET_NETLIST, netlist_str );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxFileName schematicPath( drcJob->m_filename );
|
||||||
|
schematicPath.SetExt( FILEEXT::KiCadSchematicFileExtension );
|
||||||
|
|
||||||
|
if( !schematicPath.Exists() )
|
||||||
|
schematicPath.SetExt( FILEEXT::LegacySchematicFileExtension );
|
||||||
|
|
||||||
|
if( !schematicPath.Exists() )
|
||||||
|
{
|
||||||
|
m_reporter->Report( _( "Failed to fetch schematic netlist for parity tests.\n" ),
|
||||||
|
RPT_SEVERITY_ERROR );
|
||||||
|
checkParity = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
typedef bool ( *NETLIST_FN_PTR )( const wxString&, std::string& );
|
||||||
|
KIFACE* eeschema = m_kiway->KiFACE( KIWAY::FACE_SCH );
|
||||||
|
NETLIST_FN_PTR netlister =
|
||||||
|
(NETLIST_FN_PTR) eeschema->IfaceOrAddress( KIFACE_NETLIST_SCHEMATIC );
|
||||||
|
( *netlister )( schematicPath.GetFullPath(), netlist_str );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( netlist_str == annotateMsg )
|
if( netlist_str == annotateMsg )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user