Remove error-prone SetReporter() API.

This commit is contained in:
Jeff Young 2023-09-06 11:37:50 +01:00
parent e09a15ae4c
commit 7a2a2e2df0
24 changed files with 173 additions and 190 deletions

View File

@ -203,11 +203,10 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
if( !loadLibrary( libraryFilename ) ) if( !loadLibrary( libraryFilename ) )
{ {
m_libraryPathText->ChangeValue( libraryFilename ); m_libraryPathText->ChangeValue( libraryFilename );
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, &reporter ); m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, reporter );
// load library will mangle the set reporter // load library will mangle the set reporter
m_libraryModelsMgr.SetReporter( &reporter ); m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields, reporter );
m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields );
m_modelNameChoice->Append( _( "<unknown>" ) ); m_modelNameChoice->Append( _( "<unknown>" ) );
m_modelNameChoice->SetSelection( 0 ); m_modelNameChoice->SetSelection( 0 );
@ -285,20 +284,18 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
m_rbBuiltinModel->SetValue( true ); m_rbBuiltinModel->SetValue( true );
msg.clear(); msg.clear();
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, &reporter ); m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, reporter );
if( reporter.HasMessage() ) if( reporter.HasMessage() )
DisplayErrorMessage( this, msg ); DisplayErrorMessage( this, msg );
} }
m_builtinModelsMgr.SetReporter( &reporter );
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() ) for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
{ {
if( m_rbBuiltinModel->GetValue() && type == m_curModelType ) if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
{ {
msg.clear(); msg.clear();
m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins, false ); m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins, false, reporter );
if( reporter.HasMessage() ) if( reporter.HasMessage() )
{ {
@ -308,7 +305,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
} }
else else
{ {
m_builtinModelsMgr.CreateModel( type, m_sortedPartPins ); m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
} }
SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType; SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType;
@ -723,9 +720,8 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
wxString msg; wxString msg;
WX_STRING_REPORTER reporter( &msg ); WX_STRING_REPORTER reporter( &msg );
m_libraryModelsMgr.SetReporter( &reporter );
m_libraryModelsMgr.SetForceFullParse(); m_libraryModelsMgr.SetForceFullParse();
m_libraryModelsMgr.SetLibrary( aLibraryPath ); m_libraryModelsMgr.SetLibrary( aLibraryPath, reporter );
if( reporter.HasMessage() ) if( reporter.HasMessage() )
{ {
@ -738,9 +734,9 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
for( const auto& [baseModelName, baseModel] : library()->GetModels() ) for( const auto& [baseModelName, baseModel] : library()->GetModels() )
{ {
if( baseModelName == modelName ) if( baseModelName == modelName )
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields ); m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, reporter );
else else
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins ); m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, reporter );
} }
if( reporter.HasMessage() ) if( reporter.HasMessage() )

View File

@ -1048,7 +1048,7 @@ int ERC_TESTER::TestSimModelIssues()
WX_STRING_REPORTER reporter( &msg ); WX_STRING_REPORTER reporter( &msg );
SCH_SHEET_LIST sheets = m_schematic->GetSheets(); SCH_SHEET_LIST sheets = m_schematic->GetSheets();
int err_count = 0; int err_count = 0;
SIM_LIB_MGR libMgr( &m_schematic->Prj(), &reporter ); SIM_LIB_MGR libMgr( &m_schematic->Prj() );
for( SCH_SHEET_PATH& sheet : sheets ) for( SCH_SHEET_PATH& sheet : sheets )
{ {
@ -1066,7 +1066,7 @@ int ERC_TESTER::TestSimModelIssues()
// Reset for each symbol // Reset for each symbol
msg.Clear(); msg.Clear();
SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol ); SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
if( !msg.IsEmpty() ) if( !msg.IsEmpty() )
{ {

View File

@ -104,7 +104,6 @@ NETLIST_EXPORTER_SPICE::NETLIST_EXPORTER_SPICE( SCHEMATIC_IFACE* aSchematic,
bool NETLIST_EXPORTER_SPICE::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions, bool NETLIST_EXPORTER_SPICE::WriteNetlist( const wxString& aOutFileName, unsigned aNetlistOptions,
REPORTER& aReporter ) REPORTER& aReporter )
{ {
m_libMgr.SetReporter( &aReporter );
FILE_OUTPUTFORMATTER formatter( aOutFileName, wxT( "wt" ), '\'' ); FILE_OUTPUTFORMATTER formatter( aOutFileName, wxT( "wt" ), '\'' );
return DoWriteNetlist( wxEmptyString, aNetlistOptions, formatter, aReporter ); return DoWriteNetlist( wxEmptyString, aNetlistOptions, formatter, aReporter );
} }
@ -156,8 +155,6 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
std::set<std::string> refNames; // Set of reference names to check for duplication. std::set<std::string> refNames; // Set of reference names to check for duplication.
int ncCounter = 1; int ncCounter = 1;
m_libMgr.SetReporter( &aReporter );
ReadDirectives( aNetlistOptions ); ReadDirectives( aNetlistOptions );
m_nets.clear(); m_nets.clear();
@ -227,7 +224,7 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
} }
readRefName( sheet, *symbol, spiceItem, refNames ); readRefName( sheet, *symbol, spiceItem, refNames );
readModel( sheet, *symbol, spiceItem ); readModel( sheet, *symbol, spiceItem, aReporter );
readPinNumbers( *symbol, spiceItem, pins ); readPinNumbers( *symbol, spiceItem, pins );
readPinNetNames( *symbol, spiceItem, pins, ncCounter ); readPinNetNames( *symbol, spiceItem, pins, ncCounter );
@ -237,8 +234,6 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
} }
} }
m_libMgr.SetReporter( nullptr );
return !aReporter.HasMessage(); return !aReporter.HasMessage();
} }
@ -446,9 +441,9 @@ void NETLIST_EXPORTER_SPICE::readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aS
void NETLIST_EXPORTER_SPICE::readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, void NETLIST_EXPORTER_SPICE::readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol,
SPICE_ITEM& aItem ) SPICE_ITEM& aItem, REPORTER& aReporter )
{ {
SIM_LIBRARY::MODEL libModel = m_libMgr.CreateModel( &aSheet, aSymbol ); SIM_LIBRARY::MODEL libModel = m_libMgr.CreateModel( &aSheet, aSymbol, aReporter );
aItem.baseModelName = libModel.name; aItem.baseModelName = libModel.name;
aItem.model = &libModel.model; aItem.model = &libModel.model;

View File

@ -146,7 +146,8 @@ protected:
private: private:
void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem, void readRefName( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
std::set<std::string>& aRefNames ); std::set<std::string>& aRefNames );
void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem ); void readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
REPORTER& aReporter );
void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem, void readPinNumbers( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,
const std::vector<PIN_INFO>& aPins ); const std::vector<PIN_INFO>& aPins );
void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem, void readPinNetNames( SCH_SYMBOL& aSymbol, SPICE_ITEM& aItem,

View File

@ -1406,8 +1406,6 @@ void SCH_EDIT_FRAME::RefreshOperatingPointDisplay()
SIM_LIB_MGR simLibMgr( &Prj() ); SIM_LIB_MGR simLibMgr( &Prj() );
NULL_REPORTER devnull; NULL_REPORTER devnull;
simLibMgr.SetReporter( &devnull );
// Patch for bug early in V7.99 dev // Patch for bug early in V7.99 dev
if( settings.m_OPO_VRange.EndsWith( 'A' ) ) if( settings.m_OPO_VRange.EndsWith( 'A' ) )
settings.m_OPO_VRange[ settings.m_OPO_VRange.Length() - 1 ] = 'V'; settings.m_OPO_VRange[ settings.m_OPO_VRange.Length() - 1 ] = 'V';
@ -1493,7 +1491,7 @@ void SCH_EDIT_FRAME::RefreshOperatingPointDisplay()
} }
else else
{ {
SIM_MODEL& model = simLibMgr.CreateModel( &GetCurrentSheet(), *symbol ).model; SIM_MODEL& model = simLibMgr.CreateModel( &GetCurrentSheet(), *symbol, devnull ).model;
SPICE_ITEM spiceItem; SPICE_ITEM spiceItem;
spiceItem.refName = ref; spiceItem.refName = ref;

View File

@ -715,9 +715,10 @@ void SCH_FIELD::OnScintillaCharAdded( SCINTILLA_TRICKS* aScintillaTricks,
// SPICE operating points use ':' syntax for ports // SPICE operating points use ':' syntax for ports
if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) ) if( SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( parent ) )
{ {
NULL_REPORTER devnull;
SCH_SHEET_PATH& sheet = schematic->CurrentSheet(); SCH_SHEET_PATH& sheet = schematic->CurrentSheet();
SIM_LIB_MGR mgr( &schematic->Prj() ); SIM_LIB_MGR mgr( &schematic->Prj() );
SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol ).model; SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, devnull ).model;
for( wxString pin : model.GetPinNames() ) for( wxString pin : model.GetPinNames() )
{ {

View File

@ -49,13 +49,11 @@
#include <cstring> #include <cstring>
#define IBIS_REPORTER REPORTER
class IBIS_ANY class IBIS_ANY
{ {
public: public:
IBIS_ANY( IBIS_REPORTER* aReporter ) { m_reporter = aReporter; }; IBIS_ANY( REPORTER* aReporter ) { m_reporter = aReporter; };
IBIS_REPORTER* m_reporter; REPORTER* m_reporter;
/** @brief Print a message /** @brief Print a message
* *
@ -64,11 +62,12 @@ public:
* @param aMsg Message * @param aMsg Message
* @param aSeverity Message sevirity * @param aSeverity Message sevirity
*/ */
void Report( std::string aMsg, SEVERITY aSeverity = RPT_SEVERITY_INFO ) void Report( std::string aMsg, SEVERITY aSeverity = RPT_SEVERITY_INFO )
{ {
if( m_reporter ) if( m_reporter )
m_reporter->Report( aMsg, aSeverity ); m_reporter->Report( aMsg, aSeverity );
}; };
protected: protected:
/** @brief Convert a double to string using scientific notation /** @brief Convert a double to string using scientific notation
* *
@ -82,7 +81,7 @@ protected:
class IBIS_INPUT : public IBIS_ANY class IBIS_INPUT : public IBIS_ANY
{ {
public: public:
IBIS_INPUT( IBIS_REPORTER* aReporter ) : IBIS_ANY( aReporter ){}; IBIS_INPUT( REPORTER* aReporter ) : IBIS_ANY( aReporter ){};
/** @brief Check if the data held by the object is valid. /** @brief Check if the data held by the object is valid.
* *
* @return true in case of success * @return true in case of success
@ -111,7 +110,7 @@ enum class IBIS_MATRIX_TYPE
class IBIS_MATRIX : public IBIS_INPUT class IBIS_MATRIX : public IBIS_INPUT
{ {
public: public:
IBIS_MATRIX( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ){}; IBIS_MATRIX( REPORTER* aReporter ) : IBIS_INPUT( aReporter ){};
virtual ~IBIS_MATRIX(){}; virtual ~IBIS_MATRIX(){};
IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::UNDEFINED; IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::UNDEFINED;
@ -122,7 +121,7 @@ public:
class IBIS_MATRIX_BANDED : public IBIS_MATRIX class IBIS_MATRIX_BANDED : public IBIS_MATRIX
{ {
public: public:
IBIS_MATRIX_BANDED( IBIS_REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){}; IBIS_MATRIX_BANDED( REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){};
IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::BANDED; IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::BANDED;
int m_dim = -2; int m_dim = -2;
int m_bandwidth = 0; int m_bandwidth = 0;
@ -134,7 +133,7 @@ public:
class IBIS_MATRIX_SPARSE : public IBIS_MATRIX class IBIS_MATRIX_SPARSE : public IBIS_MATRIX
{ {
public: public:
IBIS_MATRIX_SPARSE( IBIS_REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){}; IBIS_MATRIX_SPARSE( REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){};
IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::BANDED; IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::BANDED;
int m_dim = -3; int m_dim = -3;
std::vector<double> m_data; std::vector<double> m_data;
@ -146,7 +145,7 @@ public:
class IBIS_MATRIX_FULL : public IBIS_MATRIX class IBIS_MATRIX_FULL : public IBIS_MATRIX
{ {
public: public:
IBIS_MATRIX_FULL( IBIS_REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){}; IBIS_MATRIX_FULL( REPORTER* aReporter ) : IBIS_MATRIX( aReporter ){};
IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::FULL; IBIS_MATRIX_TYPE m_type = IBIS_MATRIX_TYPE::FULL;
int m_dim = -4; int m_dim = -4;
std::vector<double> m_data; std::vector<double> m_data;
@ -158,14 +157,14 @@ public:
class IBIS_SECTION : public IBIS_INPUT class IBIS_SECTION : public IBIS_INPUT
{ {
public: public:
IBIS_SECTION( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ){}; IBIS_SECTION( REPORTER* aReporter ) : IBIS_INPUT( aReporter ){};
}; };
class IbisHeader : IBIS_SECTION class IbisHeader : IBIS_SECTION
{ {
public: public:
IbisHeader( IBIS_REPORTER* aReporter ) : IBIS_SECTION( aReporter ){}; IbisHeader( REPORTER* aReporter ) : IBIS_SECTION( aReporter ){};
double m_ibisVersion = -1; double m_ibisVersion = -1;
double m_fileRevision = -1; double m_fileRevision = -1;
std::string m_fileName; std::string m_fileName;
@ -182,7 +181,7 @@ public:
class TypMinMaxValue : public IBIS_INPUT class TypMinMaxValue : public IBIS_INPUT
{ {
public: public:
TypMinMaxValue( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ){}; TypMinMaxValue( REPORTER* aReporter ) : IBIS_INPUT( aReporter ){};
double value[3] = { -1, -1, -1 }; double value[3] = { -1, -1, -1 };
bool Check() override; bool Check() override;
@ -192,7 +191,7 @@ public:
class IbisComponentPackage : public IBIS_INPUT class IbisComponentPackage : public IBIS_INPUT
{ {
public: public:
IbisComponentPackage( IBIS_REPORTER* aReporter ) : IbisComponentPackage( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
m_Rpkg( aReporter ), m_Rpkg( aReporter ),
m_Lpkg( aReporter ), m_Lpkg( aReporter ),
@ -210,7 +209,7 @@ public:
class IbisComponentPin : public IBIS_INPUT class IbisComponentPin : public IBIS_INPUT
{ {
public: public:
IbisComponentPin( IBIS_REPORTER* aReporter ) : IbisComponentPin( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -237,7 +236,7 @@ public:
class IbisComponentPinMapping : public IBIS_INPUT class IbisComponentPinMapping : public IBIS_INPUT
{ {
public: public:
IbisComponentPinMapping( IBIS_REPORTER* aReporter ) : IbisComponentPinMapping( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -258,7 +257,7 @@ public:
class IbisDiffPinEntry : public IBIS_INPUT class IbisDiffPinEntry : public IBIS_INPUT
{ {
public: public:
IbisDiffPinEntry( IBIS_REPORTER* aReporter ) : IbisDiffPinEntry( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
tdelay( aReporter ) tdelay( aReporter )
{}; {};
@ -276,7 +275,7 @@ public:
class IbisDiffPin : IBIS_INPUT class IbisDiffPin : IBIS_INPUT
{ {
public: public:
IbisDiffPin( IBIS_REPORTER* aReporter ) : IbisDiffPin( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -286,7 +285,7 @@ public:
class IbisComponent : public IBIS_INPUT class IbisComponent : public IBIS_INPUT
{ {
public: public:
IbisComponent( IBIS_REPORTER* aReporter ) : IbisComponent( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
m_package( aReporter ), m_package( aReporter ),
m_diffPin( aReporter ) m_diffPin( aReporter )
@ -320,7 +319,7 @@ public:
class IbisModelSelector : public IBIS_INPUT class IbisModelSelector : public IBIS_INPUT
{ {
public: public:
IbisModelSelector( IBIS_REPORTER* aReporter ) : IbisModelSelector( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -337,7 +336,7 @@ public:
class IVtableEntry : public IBIS_INPUT class IVtableEntry : public IBIS_INPUT
{ {
public: public:
IVtableEntry( IBIS_REPORTER* aReporter ) : IVtableEntry( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
I( aReporter ) I( aReporter )
{}; {};
@ -353,7 +352,7 @@ public:
class IVtable : public IBIS_INPUT class IVtable : public IBIS_INPUT
{ {
public: public:
IVtable( IBIS_REPORTER* aReporter ) : IVtable( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -392,7 +391,7 @@ private:
class VTtableEntry : public IBIS_INPUT class VTtableEntry : public IBIS_INPUT
{ {
public: public:
VTtableEntry( IBIS_REPORTER* aReporter ) : VTtableEntry( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
V( aReporter ) V( aReporter )
{}; {};
@ -407,7 +406,7 @@ public:
class VTtable : public IBIS_INPUT class VTtable : public IBIS_INPUT
{ {
public: public:
VTtable( IBIS_REPORTER* aReporter ) : VTtable( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -460,7 +459,7 @@ public:
class dvdtTypMinMax : public IBIS_INPUT class dvdtTypMinMax : public IBIS_INPUT
{ {
public: public:
dvdtTypMinMax( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ){}; dvdtTypMinMax( REPORTER* aReporter ) : IBIS_INPUT( aReporter ){};
dvdt value[3]; dvdt value[3];
bool Check() override; bool Check() override;
@ -470,7 +469,7 @@ public:
class IbisRamp : public IBIS_INPUT class IbisRamp : public IBIS_INPUT
{ {
public: public:
IbisRamp( IBIS_REPORTER* aReporter ) : IbisRamp( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
m_falling( aReporter ), m_falling( aReporter ),
m_rising( aReporter ) m_rising( aReporter )
@ -492,7 +491,7 @@ enum class IBIS_WAVEFORM_TYPE
class IbisWaveform : public IBIS_INPUT class IbisWaveform : public IBIS_INPUT
{ {
public: public:
IbisWaveform( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ), m_table( aReporter ){}; IbisWaveform( REPORTER* aReporter ) : IBIS_INPUT( aReporter ), m_table( aReporter ){};
VTtable m_table; VTtable m_table;
IBIS_WAVEFORM_TYPE m_type = IBIS_WAVEFORM_TYPE::RISING; IBIS_WAVEFORM_TYPE m_type = IBIS_WAVEFORM_TYPE::RISING;
@ -517,7 +516,7 @@ enum class IBIS_MODEL_POLARITY
class IbisModel : IBIS_INPUT class IbisModel : IBIS_INPUT
{ {
public: public:
IbisModel( IBIS_REPORTER* aReporter ) : IbisModel( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
m_C_comp( aReporter ), m_C_comp( aReporter ),
m_voltageRange( aReporter ), m_voltageRange( aReporter ),
@ -580,7 +579,7 @@ public:
class IbisPackageModel : public IBIS_INPUT class IbisPackageModel : public IBIS_INPUT
{ {
public: public:
IbisPackageModel( IBIS_REPORTER* aReporter ) : IbisPackageModel( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ) IBIS_INPUT( aReporter )
{}; {};
@ -604,7 +603,7 @@ public:
class IbisFile : public IBIS_INPUT class IbisFile : public IBIS_INPUT
{ {
public: public:
IbisFile( IBIS_REPORTER* aReporter ) : IbisFile( REPORTER* aReporter ) :
IBIS_INPUT( aReporter ), IBIS_INPUT( aReporter ),
m_header( aReporter ) m_header( aReporter )
{}; {};
@ -653,7 +652,7 @@ enum class IBIS_PARSER_CONTEXT
class IbisParser : public IBIS_INPUT class IbisParser : public IBIS_INPUT
{ {
public: public:
IbisParser( IBIS_REPORTER* aReporter ) : IBIS_INPUT( aReporter ), m_ibisFile( aReporter ){}; IbisParser( REPORTER* aReporter ) : IBIS_INPUT( aReporter ), m_ibisFile( aReporter ){};
bool m_parrot = true; // Write back all lines. bool m_parrot = true; // Write back all lines.

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Fabien Corona f.corona<at>laposte.net * Copyright (C) 2022 Fabien Corona f.corona<at>laposte.net
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
@ -85,7 +86,7 @@ IBIS_CORNER ReverseLogic( IBIS_CORNER aIn )
return out; return out;
} }
KIBIS::KIBIS( std::string aFileName, IBIS_REPORTER* aReporter ) : KIBIS::KIBIS( std::string aFileName, REPORTER* aReporter ) :
KIBIS_ANY( this ), KIBIS_ANY( this ),
m_reporter( aReporter ), m_reporter( aReporter ),
m_file( this ) m_file( this )

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2022 Fabien Corona f.corona<at>laposte.net * Copyright (C) 2022 Fabien Corona f.corona<at>laposte.net
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
* *
* Redistribution and use in source and binary forms, with or without modification, * Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met: * are permitted provided that the following conditions are met:
@ -218,9 +219,10 @@ public:
{ {
m_valid = false; m_valid = false;
}; // Constructor for unitialized KIBIS members }; // Constructor for unitialized KIBIS members
KIBIS( std::string aFileName, IBIS_REPORTER* aReporter = nullptr );
IBIS_REPORTER* m_reporter; KIBIS( std::string aFileName, REPORTER* aReporter = nullptr );
REPORTER* m_reporter;
std::vector<KIBIS_COMPONENT> m_components; std::vector<KIBIS_COMPONENT> m_components;
std::vector<KIBIS_MODEL> m_models; std::vector<KIBIS_MODEL> m_models;
KIBIS_FILE m_file; KIBIS_FILE m_file;

View File

@ -39,9 +39,8 @@
using namespace std::placeholders; using namespace std::placeholders;
SIM_LIB_MGR::SIM_LIB_MGR( const PROJECT* aPrj, REPORTER* aReporter ) : SIM_LIB_MGR::SIM_LIB_MGR( const PROJECT* aPrj ) :
m_project( aPrj ), m_project( aPrj ),
m_reporter( aReporter ),
m_forceFullParse( false ) m_forceFullParse( false )
{ {
} }
@ -128,7 +127,7 @@ wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
} }
void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath ) void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter )
{ {
try try
{ {
@ -138,29 +137,30 @@ void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath )
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 ); std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_forceFullParse, std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_forceFullParse,
m_reporter, &f2 ); aReporter, &f2 );
Clear(); Clear();
m_libraries[path] = std::move( library ); m_libraries[path] = std::move( library );
} }
catch( const IO_ERROR& e ) catch( const IO_ERROR& e )
{ {
m_reporter->Report( e.What() ); aReporter.Report( e.What() );
} }
} }
SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector<LIB_PIN*>& aPins ) SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter )
{ {
m_models.push_back( SIM_MODEL::Create( aType, aPins, m_reporter ) ); m_models.push_back( SIM_MODEL::Create( aType, aPins, aReporter ) );
return *m_models.back(); return *m_models.back();
} }
SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins ) const std::vector<LIB_PIN*>& aPins, REPORTER& aReporter )
{ {
m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, m_reporter ) ); m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aReporter ) );
return *m_models.back(); return *m_models.back();
} }
@ -168,21 +168,24 @@ SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
template <typename T> template <typename T>
SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields ) const std::vector<T>& aFields, REPORTER& aReporter )
{ {
m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aFields, m_reporter ) ); m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aFields, aReporter ) );
return *m_models.back(); return *m_models.back();
} }
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<SCH_FIELD>& aFields ); const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter );
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel, template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<LIB_FIELD>& aFields ); const std::vector<LIB_FIELD>& aFields,
REPORTER& aReporter );
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol ) SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol,
REPORTER& aReporter )
{ {
// Note: currently this creates a resolved model (all Kicad variables references are resolved // Note: currently this creates a resolved model (all Kicad variables references are resolved
// before building the model). // before building the model).
@ -239,7 +242,7 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0; return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
} ); } );
SIM_LIBRARY::MODEL model = CreateModel( fields, sourcePins, true ); SIM_LIBRARY::MODEL model = CreateModel( fields, sourcePins, true, aReporter );
model.model.SetIsStoredInValue( storeInValue ); model.model.SetIsStoredInValue( storeInValue );
@ -249,35 +252,37 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S
template <typename T> template <typename T>
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields, SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins, bool aResolved ) const std::vector<LIB_PIN*>& aPins, bool aResolved,
REPORTER& aReporter )
{ {
std::string libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD ); std::string libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD );
std::string baseModelName = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::NAME_FIELD ); std::string baseModelName = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::NAME_FIELD );
if( libraryPath != "" ) if( libraryPath != "" )
{ {
return CreateModel( libraryPath, baseModelName, aFields, aPins ); return CreateModel( libraryPath, baseModelName, aFields, aPins, aReporter );
} }
else else
{ {
m_models.push_back( SIM_MODEL::Create( aFields, aPins, aResolved, m_reporter ) ); m_models.push_back( SIM_MODEL::Create( aFields, aPins, aResolved, aReporter ) );
return { baseModelName, *m_models.back() }; return { baseModelName, *m_models.back() };
} }
} }
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields, template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved ); bool aResolved, REPORTER& aReporter );
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<LIB_FIELD>& aFields, template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved ); bool aResolved, REPORTER& aReporter );
template <typename T> template <typename T>
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath, SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
const std::string& aBaseModelName, const std::string& aBaseModelName,
const std::vector<T>& aFields, const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins ) const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter )
{ {
wxString path; wxString path;
wxString msg; wxString msg;
@ -297,32 +302,26 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 ); std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
it = m_libraries.emplace( path, SIM_LIBRARY::Create( path, m_forceFullParse, it = m_libraries.emplace( path, SIM_LIBRARY::Create( path, m_forceFullParse,
m_reporter, &f2 ) ).first; aReporter, &f2 ) ).first;
} }
library = &*it->second; library = &*it->second;
} }
catch( const IO_ERROR& e ) catch( const IO_ERROR& e )
{ {
if( m_reporter ) msg.Printf( _( "Error loading simulation model library '%s': %s" ),
{ path,
msg.Printf( _( "Error loading simulation model library '%s': %s" ), e.What() );
path,
e.What() );
m_reporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter.Report( msg, RPT_SEVERITY_ERROR );
}
} }
if( aBaseModelName == "" ) if( aBaseModelName == "" )
{ {
if( m_reporter ) msg.Printf( _( "Error loading simulation model: no '%s' field" ),
{ SIM_LIBRARY::NAME_FIELD );
msg.Printf( _( "Error loading simulation model: no '%s' field" ),
SIM_LIBRARY::NAME_FIELD );
m_reporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter.Report( msg, RPT_SEVERITY_ERROR );
}
modelName = _( "unknown" ).ToStdString(); modelName = _( "unknown" ).ToStdString();
} }
@ -333,19 +332,16 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
if( !baseModel ) if( !baseModel )
{ {
if( m_reporter ) msg.Printf( _( "Error loading simulation model: could not find base model '%s' "
{ "in library '%s'" ),
msg.Printf( _( "Error loading simulation model: could not find base model '%s' " aBaseModelName,
"in library '%s'" ), path );
aBaseModelName,
path );
m_reporter->Report( msg, RPT_SEVERITY_ERROR ); aReporter.Report( msg, RPT_SEVERITY_ERROR );
}
} }
} }
m_models.push_back( SIM_MODEL::Create( baseModel, aPins, aFields, m_reporter ) ); m_models.push_back( SIM_MODEL::Create( baseModel, aPins, aFields, aReporter ) );
return { modelName, *m_models.back() }; return { modelName, *m_models.back() };
} }

View File

@ -40,36 +40,39 @@ class SCH_SYMBOL;
class SIM_LIB_MGR class SIM_LIB_MGR
{ {
public: public:
SIM_LIB_MGR( const PROJECT* aPrj, REPORTER* aReporter = nullptr ); SIM_LIB_MGR( const PROJECT* aPrj );
virtual ~SIM_LIB_MGR() = default; virtual ~SIM_LIB_MGR() = default;
void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
void SetForceFullParse() { m_forceFullParse = true; } void SetForceFullParse() { m_forceFullParse = true; }
void Clear(); void Clear();
void SetLibrary( const wxString& aLibraryPath ); void SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter );
SIM_MODEL& CreateModel( SIM_MODEL::TYPE aType, const std::vector<LIB_PIN*>& aPins ); SIM_MODEL& CreateModel( SIM_MODEL::TYPE aType, const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter );
SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins ); SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins,
REPORTER& aReporter );
template <typename T> template <typename T>
SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins, SIM_MODEL& CreateModel( const SIM_MODEL* aBaseModel, const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields ); const std::vector<T>& aFields, REPORTER& aReporter );
// TODO: The argument can be made const. // TODO: The argument can be made const.
SIM_LIBRARY::MODEL CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol ); SIM_LIBRARY::MODEL CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol,
REPORTER& aReporter );
template <typename T> template <typename T>
SIM_LIBRARY::MODEL CreateModel( const std::vector<T>& aFields, SIM_LIBRARY::MODEL CreateModel( const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins, bool aResolved ); const std::vector<LIB_PIN*>& aPins, bool aResolved,
REPORTER& aReporter );
template <typename T> template <typename T>
SIM_LIBRARY::MODEL CreateModel( const wxString& aLibraryPath, SIM_LIBRARY::MODEL CreateModel( const wxString& aLibraryPath,
const std::string& aBaseModelName, const std::string& aBaseModelName,
const std::vector<T>& aFields, const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins ); const std::vector<LIB_PIN*>& aPins, REPORTER& aReporter );
void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel ); void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel );
@ -81,7 +84,6 @@ public:
private: private:
const PROJECT* m_project; const PROJECT* m_project;
REPORTER* m_reporter;
bool m_forceFullParse; bool m_forceFullParse;
std::map<wxString, std::unique_ptr<SIM_LIBRARY>> m_libraries; std::map<wxString, std::unique_ptr<SIM_LIBRARY>> m_libraries;
std::vector<std::unique_ptr<SIM_MODEL>> m_models; std::vector<std::unique_ptr<SIM_MODEL>> m_models;

View File

@ -30,7 +30,7 @@
std::unique_ptr<SIM_LIBRARY> std::unique_ptr<SIM_LIBRARY>
SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER* aReporter, SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
std::function<wxString( const wxString&, const wxString& )>* aResolver ) std::function<wxString( const wxString&, const wxString& )>* aResolver )
{ {
std::unique_ptr<SIM_LIBRARY> library; std::unique_ptr<SIM_LIBRARY> library;
@ -40,7 +40,6 @@ SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER*
else else
library = std::make_unique<SIM_LIBRARY_SPICE>( aForceFullParse ); library = std::make_unique<SIM_LIBRARY_SPICE>( aForceFullParse );
library->m_reporter = aReporter;
library->m_pathResolver = aResolver; library->m_pathResolver = aResolver;
library->ReadFile( aFilePath, aReporter ); library->ReadFile( aFilePath, aReporter );
@ -48,7 +47,7 @@ SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER*
} }
void SIM_LIBRARY::ReadFile( const wxString& aFilePath, REPORTER* aReporter ) void SIM_LIBRARY::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
{ {
m_filePath = aFilePath; m_filePath = aFilePath;
} }

View File

@ -55,7 +55,7 @@ public:
* @return The library loaded in a newly constructed object. * @return The library loaded in a newly constructed object.
*/ */
static std::unique_ptr<SIM_LIBRARY> static std::unique_ptr<SIM_LIBRARY>
Create( const wxString& aFilePath, bool aForceFullParse, REPORTER* aReporter, Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
std::function<wxString( const wxString&, const wxString& )>* aResolver ); std::function<wxString( const wxString&, const wxString& )>* aResolver );
/** /**
@ -65,7 +65,7 @@ public:
* @param aFilePath Path to the file. * @param aFilePath Path to the file.
* @throw IO_ERROR on read or parsing error. * @throw IO_ERROR on read or parsing error.
*/ */
virtual void ReadFile( const wxString& aFilePath, REPORTER* aReporter ) = 0; virtual void ReadFile( const wxString& aFilePath, REPORTER& aReporter ) = 0;
SIM_MODEL* FindModel( const std::string& aModelName ) const; SIM_MODEL* FindModel( const std::string& aModelName ) const;
@ -80,8 +80,6 @@ protected:
std::function<wxString( const wxString&, const wxString& )>* m_pathResolver; std::function<wxString( const wxString&, const wxString& )>* m_pathResolver;
std::string m_filePath; std::string m_filePath;
REPORTER* m_reporter = nullptr;
}; };

View File

@ -29,15 +29,15 @@
#include <lib_pin.h> #include <lib_pin.h>
void SIM_LIBRARY_KIBIS::ReadFile( const wxString& aFilePath, REPORTER* aReporter ) void SIM_LIBRARY_KIBIS::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
{ {
SIM_LIBRARY::ReadFile( aFilePath, aReporter ); SIM_LIBRARY::ReadFile( aFilePath, aReporter );
m_kibis = KIBIS( aFilePath.ToStdString(), m_reporter ); m_kibis = KIBIS( aFilePath.ToStdString(), &aReporter );
if( !m_kibis.m_valid ) if( !m_kibis.m_valid )
{ {
aReporter->Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ), aReporter.Report( wxString::Format( _( "Invalid IBIS file '%s'" ), aFilePath ),
RPT_SEVERITY_ERROR ); RPT_SEVERITY_ERROR );
return; return;
} }

View File

@ -38,7 +38,7 @@ public:
static constexpr auto DIFF_FIELD = "Sim.Ibis.Diff"; static constexpr auto DIFF_FIELD = "Sim.Ibis.Diff";
// @copydoc SIM_LIBRARY::ReadFile() // @copydoc SIM_LIBRARY::ReadFile()
void ReadFile( const wxString& aFilePath, REPORTER* aReporter ) override; void ReadFile( const wxString& aFilePath, REPORTER& aReporter ) override;
bool InitModel( SIM_MODEL_KIBIS& aModel, wxString aCompName ); bool InitModel( SIM_MODEL_KIBIS& aModel, wxString aCompName );
bool isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const; bool isPinDiff( const std::string& aComp, const std::string& aPinNumber ) const;

View File

@ -33,7 +33,7 @@ SIM_LIBRARY_SPICE::SIM_LIBRARY_SPICE( bool aForceFullParse ) :
} }
void SIM_LIBRARY_SPICE::ReadFile( const wxString& aFilePath, REPORTER* aReporter ) void SIM_LIBRARY_SPICE::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
{ {
SIM_LIBRARY::ReadFile( aFilePath, aReporter ); SIM_LIBRARY::ReadFile( aFilePath, aReporter );
m_spiceLibraryParser->ReadFile( aFilePath, aReporter ); m_spiceLibraryParser->ReadFile( aFilePath, aReporter );

View File

@ -37,7 +37,7 @@ public:
SIM_LIBRARY_SPICE( bool aForceFullParse ); SIM_LIBRARY_SPICE( bool aForceFullParse );
// @copydoc SIM_LIBRARY::ReadFile() // @copydoc SIM_LIBRARY::ReadFile()
void ReadFile( const wxString& aFilePath, REPORTER* aReporter ) override; void ReadFile( const wxString& aFilePath, REPORTER& aReporter ) override;
private: private:
std::unique_ptr<SPICE_LIBRARY_PARSER> m_spiceLibraryParser; std::unique_ptr<SPICE_LIBRARY_PARSER> m_spiceLibraryParser;

View File

@ -373,12 +373,12 @@ SIM_MODEL::SPICE_INFO SIM_MODEL::SpiceInfo( TYPE aType )
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields, template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields,
REPORTER* aReporter ); REPORTER& aReporter );
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFields, template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFields,
REPORTER* aReporter ); REPORTER& aReporter );
template <typename T> template <typename T>
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER* aReporter ) TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER& aReporter )
{ {
std::string deviceTypeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_TYPE_FIELD ); std::string deviceTypeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_TYPE_FIELD );
std::string typeFieldValue = GetFieldValue( &aFields, SIM_TYPE_FIELD ); std::string typeFieldValue = GetFieldValue( &aFields, SIM_TYPE_FIELD );
@ -398,20 +398,17 @@ TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER* aRe
if( typeFieldValue != "" ) if( typeFieldValue != "" )
return TYPE::NONE; return TYPE::NONE;
if( aReporter ) if( aFields.size() > REFERENCE_FIELD )
{ {
if( aFields.size() > REFERENCE_FIELD ) aReporter.Report( wxString::Format( _( "No simulation model definition found for "
{ "symbol '%s'." ),
aReporter->Report( wxString::Format( _( "No simulation model definition found for " aFields[REFERENCE_FIELD].GetText() ),
"symbol '%s'." ), RPT_SEVERITY_ERROR );
aFields[REFERENCE_FIELD].GetText() ), }
RPT_SEVERITY_ERROR ); else
} {
else aReporter.Report( _( "No simulation model definition found." ),
{ RPT_SEVERITY_ERROR );
aReporter->Report( _( "No simulation model definition found." ),
RPT_SEVERITY_ERROR );
}
} }
return TYPE::NONE; return TYPE::NONE;
@ -449,7 +446,7 @@ void SIM_MODEL::WriteFields( std::vector<LIB_FIELD>& aFields ) const
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, const std::vector<LIB_PIN*>& aPins, std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, const std::vector<LIB_PIN*>& aPins,
REPORTER* aReporter ) REPORTER& aReporter )
{ {
std::unique_ptr<SIM_MODEL> model = Create( aType ); std::unique_ptr<SIM_MODEL> model = Create( aType );
@ -469,7 +466,7 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, const std::vector<LIB_
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel, std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
REPORTER* aReporter ) REPORTER& aReporter )
{ {
std::unique_ptr<SIM_MODEL> model; std::unique_ptr<SIM_MODEL> model;
@ -508,17 +505,18 @@ template <typename T>
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel, std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields, const std::vector<T>& aFields,
REPORTER* aReporter ) REPORTER& aReporter )
{ {
std::unique_ptr<SIM_MODEL> model; std::unique_ptr<SIM_MODEL> model;
if( aBaseModel ) if( aBaseModel )
{ {
TYPE type = aBaseModel->GetType(); NULL_REPORTER devnull;
TYPE type = aBaseModel->GetType();
// No REPORTER here; we're just checking to see if we have an override // No REPORTER here; we're just checking to see if we have an override
if( ReadTypeFromFields( aFields, nullptr ) != TYPE::NONE ) if( ReadTypeFromFields( aFields, devnull ) != TYPE::NONE )
type = ReadTypeFromFields( aFields, nullptr ); type = ReadTypeFromFields( aFields, devnull );
if( dynamic_cast<const SIM_MODEL_SPICE_FALLBACK*>( aBaseModel ) ) if( dynamic_cast<const SIM_MODEL_SPICE_FALLBACK*>( aBaseModel ) )
model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type ); model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
@ -541,14 +539,11 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
} }
catch( IO_ERROR& err ) catch( IO_ERROR& err )
{ {
if( aReporter ) aReporter.Report( wxString::Format( _( "Error reading simulation model from "
{ "symbol '%s':\n%s" ),
aReporter->Report( wxString::Format( _( "Error reading simulation model from " aFields[REFERENCE_FIELD].GetText(),
"symbol '%s':\n%s" ), err.Problem() ),
aFields[REFERENCE_FIELD].GetText(), RPT_SEVERITY_ERROR );
err.Problem() ),
RPT_SEVERITY_ERROR );
}
} }
return model; return model;
@ -557,18 +552,18 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel, template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<SCH_FIELD>& aFields, const std::vector<SCH_FIELD>& aFields,
REPORTER* aReporter ); REPORTER& aReporter );
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel, template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<LIB_FIELD>& aFields, const std::vector<LIB_FIELD>& aFields,
REPORTER* aReporter ); REPORTER& aReporter );
template <typename T> template <typename T>
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields, std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER* aReporter ) bool aResolved, REPORTER& aReporter )
{ {
TYPE type = ReadTypeFromFields( aFields, aReporter ); TYPE type = ReadTypeFromFields( aFields, aReporter );
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( type ); std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( type );
@ -581,7 +576,7 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
{ {
if( !aResolved ) if( !aResolved )
{ {
aReporter->Report( parse_err.What(), RPT_SEVERITY_ERROR ); aReporter.Report( parse_err.What(), RPT_SEVERITY_ERROR );
return model; return model;
} }
@ -603,14 +598,11 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
catch( const IO_ERROR& err ) catch( const IO_ERROR& err )
{ {
// We own the pin syntax, so if we can't parse it then there's an error. // We own the pin syntax, so if we can't parse it then there's an error.
if( aReporter ) aReporter.Report( wxString::Format( _( "Error reading simulation model from "
{ "symbol '%s':\n%s" ),
aReporter->Report( wxString::Format( _( "Error reading simulation model from " aFields[REFERENCE_FIELD].GetText(),
"symbol '%s':\n%s" ), err.Problem() ),
aFields[REFERENCE_FIELD].GetText(), RPT_SEVERITY_ERROR );
err.Problem() ),
RPT_SEVERITY_ERROR );
}
} }
} }
@ -619,10 +611,10 @@ std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<SCH_FIELD>& aFields, template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER* aReporter ); bool aResolved, REPORTER& aReporter );
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<LIB_FIELD>& aFields, template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER* aReporter ); bool aResolved, REPORTER& aReporter );
template <typename T> template <typename T>
@ -1729,7 +1721,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
{ {
wxString msg; wxString msg;
WX_STRING_REPORTER reporter( &msg ); WX_STRING_REPORTER reporter( &msg );
SIM_LIB_MGR libMgr( aProject, &reporter ); SIM_LIB_MGR libMgr( aProject );
std::vector<T_field> emptyFields; std::vector<T_field> emptyFields;
// Pull out any following parameters from model name // Pull out any following parameters from model name
@ -1737,7 +1729,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
spiceModelInfo.m_Text = spiceModel; spiceModelInfo.m_Text = spiceModel;
SIM_LIBRARY::MODEL model = libMgr.CreateModel( spiceLib, spiceModel.ToStdString(), SIM_LIBRARY::MODEL model = libMgr.CreateModel( spiceLib, spiceModel.ToStdString(),
emptyFields, sourcePins ); emptyFields, sourcePins, reporter );
if( reporter.HasMessage() ) if( reporter.HasMessage() )
libraryModel = false; // Fall back to raw spice model libraryModel = false; // Fall back to raw spice model

View File

@ -408,25 +408,25 @@ public:
template <typename T> template <typename T>
static TYPE ReadTypeFromFields( const std::vector<T>& aFields, REPORTER* aReporter ); static TYPE ReadTypeFromFields( const std::vector<T>& aFields, REPORTER& aReporter );
static std::unique_ptr<SIM_MODEL> Create( TYPE aType, const std::vector<LIB_PIN*>& aPins, static std::unique_ptr<SIM_MODEL> Create( TYPE aType, const std::vector<LIB_PIN*>& aPins,
REPORTER* aReporter ); REPORTER& aReporter );
static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL* aBaseModel, static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
REPORTER* aReporter ); REPORTER& aReporter );
template <typename T> template <typename T>
static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL* aBaseModel, static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL* aBaseModel,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
const std::vector<T>& aFields, const std::vector<T>& aFields,
REPORTER* aReporter ); REPORTER& aReporter );
template <typename T> template <typename T>
static std::unique_ptr<SIM_MODEL> Create( const std::vector<T>& aFields, static std::unique_ptr<SIM_MODEL> Create( const std::vector<T>& aFields,
const std::vector<LIB_PIN*>& aPins, const std::vector<LIB_PIN*>& aPins,
bool aResolved, REPORTER* aReporter ); bool aResolved, REPORTER& aReporter );
template <typename T> template <typename T>
static std::string GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName, static std::string GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,

View File

@ -1395,8 +1395,9 @@ void SIMULATOR_FRAME_UI::UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, con
return; return;
} }
SIM_LIB_MGR mgr( &m_schematicFrame->Prj() ); NULL_REPORTER devnull;
SIM_MODEL& model = mgr.CreateModel( &aSheetPath, *symbol ).model; SIM_LIB_MGR mgr( &m_schematicFrame->Prj() );
SIM_MODEL& model = mgr.CreateModel( &aSheetPath, *symbol, devnull ).model;
const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam(); const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam();

View File

@ -205,7 +205,7 @@ void SPICE_LIBRARY_PARSER::parseFile( const wxString &aFilePath, REPORTER& aRepo
} }
void SPICE_LIBRARY_PARSER::ReadFile( const wxString& aFilePath, REPORTER* aReporter ) void SPICE_LIBRARY_PARSER::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
{ {
m_library.m_models.clear(); m_library.m_models.clear();
m_library.m_modelNames.clear(); m_library.m_modelNames.clear();
@ -215,7 +215,7 @@ void SPICE_LIBRARY_PARSER::ReadFile( const wxString& aFilePath, REPORTER* aRepor
// (cmp/standard.bjt, cmp/standard.mos, etc.) have copious error which trip up our parser, // (cmp/standard.bjt, cmp/standard.mos, etc.) have copious error which trip up our parser,
// and our parser is *really* slow on such large files (nearly 5 seconds on my dev machine). // and our parser is *really* slow on such large files (nearly 5 seconds on my dev machine).
if( !m_forceFullParse && aFilePath.Contains( wxS( "/LTspiceXVII/lib/cmp/standard" ) ) ) if( !m_forceFullParse && aFilePath.Contains( wxS( "/LTspiceXVII/lib/cmp/standard" ) ) )
readFallbacks( aFilePath, *aReporter ); readFallbacks( aFilePath, aReporter );
else else
parseFile( aFilePath, *aReporter ); parseFile( aFilePath, aReporter );
} }

View File

@ -41,7 +41,7 @@ public:
virtual ~SPICE_LIBRARY_PARSER() virtual ~SPICE_LIBRARY_PARSER()
{}; {};
virtual void ReadFile( const wxString& aFilePath, REPORTER* aReporter ); virtual void ReadFile( const wxString& aFilePath, REPORTER& aReporter );
protected: protected:
void readFallbacks( const wxString& aFilePath, REPORTER& aReporter ); void readFallbacks( const wxString& aFilePath, REPORTER& aReporter );

View File

@ -545,9 +545,9 @@ int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
wxString msg; wxString msg;
WX_STRING_REPORTER reporter( &msg ); WX_STRING_REPORTER reporter( &msg );
SIM_LIB_MGR mgr( &m_frame->Prj(), &reporter ); SIM_LIB_MGR mgr( &m_frame->Prj() );
SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol ).model; SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, reporter ).model;
if( reporter.HasMessage() ) if( reporter.HasMessage() )
THROW_IO_ERROR( msg ); THROW_IO_ERROR( msg );

View File

@ -46,9 +46,11 @@ public:
void LoadLibrary( const std::string& aBaseName ) void LoadLibrary( const std::string& aBaseName )
{ {
std::string path = GetLibraryPath( aBaseName ); NULL_REPORTER devnull;
std::string path = GetLibraryPath( aBaseName );
m_library = std::make_unique<SIM_LIBRARY_SPICE>( true ); m_library = std::make_unique<SIM_LIBRARY_SPICE>( true );
m_library->ReadFile( path, nullptr ); m_library->ReadFile( path, devnull );
} }
void CompareToUsualDiodeModel( const SIM_MODEL& aModel, const std::string& aModelName, int aModelIndex ) void CompareToUsualDiodeModel( const SIM_MODEL& aModel, const std::string& aModelName, int aModelIndex )