Make IBIS errors visible / more obvious.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18041
This commit is contained in:
Alex Shvartzkop 2024-05-19 01:44:12 +03:00
parent 585f11a01d
commit 6dfd417767
4 changed files with 23 additions and 18 deletions

View File

@ -479,7 +479,8 @@ void NETLIST_EXPORTER_SPICE::readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSym
auto spiceGenerator = static_cast<const SPICE_GENERATOR_KIBIS&>( kibisModel->SpiceGenerator() ); auto spiceGenerator = static_cast<const SPICE_GENERATOR_KIBIS&>( kibisModel->SpiceGenerator() );
std::string modelData = spiceGenerator.IbisDevice( std::string modelData = spiceGenerator.IbisDevice(
aItem, m_schematic->Prj(), cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR ) ); aItem, m_schematic->Prj(),
cacheFn.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR ), aReporter );
cacheFile.Write( wxString( modelData ) ); cacheFile.Write( wxString( modelData ) );
m_rawIncludes.insert( cacheFn.GetFullPath() ); m_rawIncludes.insert( cacheFn.GetFullPath() );

View File

@ -59,7 +59,8 @@ std::vector<std::string> SPICE_GENERATOR_KIBIS::CurrentNames( const SPICE_ITEM&
std::string SPICE_GENERATOR_KIBIS::IbisDevice( const SPICE_ITEM& aItem, const PROJECT& aProject, std::string SPICE_GENERATOR_KIBIS::IbisDevice( const SPICE_ITEM& aItem, const PROJECT& aProject,
const wxString& aCacheDir ) const const wxString& aCacheDir,
REPORTER& aReporter ) const
{ {
std::string ibisLibFilename = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY::LIBRARY_FIELD ); std::string ibisLibFilename = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY::LIBRARY_FIELD );
std::string ibisCompName = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY::NAME_FIELD ); std::string ibisCompName = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY::NAME_FIELD );
@ -71,6 +72,7 @@ std::string SPICE_GENERATOR_KIBIS::IbisDevice( const SPICE_ITEM& aItem, const PR
KIBIS kibis( std::string( path.c_str() ) ); KIBIS kibis( std::string( path.c_str() ) );
kibis.m_cacheDir = std::string( aCacheDir.c_str() ); kibis.m_cacheDir = std::string( aCacheDir.c_str() );
kibis.m_reporter = &aReporter;
if( !kibis.m_valid ) if( !kibis.m_valid )
THROW_IO_ERROR( wxString::Format( _( "Invalid IBIS file '%s'" ), ibisLibFilename ) ); THROW_IO_ERROR( wxString::Format( _( "Invalid IBIS file '%s'" ), ibisLibFilename ) );
@ -167,10 +169,10 @@ std::string SPICE_GENERATOR_KIBIS::IbisDevice( const SPICE_ITEM& aItem, const PR
KIBIS_WAVEFORM_RECTANGULAR* waveform = new KIBIS_WAVEFORM_RECTANGULAR( &kibis ); KIBIS_WAVEFORM_RECTANGULAR* waveform = new KIBIS_WAVEFORM_RECTANGULAR( &kibis );
if( const SIM_MODEL::PARAM* ton = m_model.FindParam( "ton" ) ) if( const SIM_MODEL::PARAM* ton = m_model.FindParam( "ton" ) )
waveform->m_ton = SIM_VALUE::ToDouble( ton->value, 1 ); waveform->m_ton = SIM_VALUE::ToDouble( ton->value, 0 );
if( const SIM_MODEL::PARAM* toff = m_model.FindParam( "toff" ) ) if( const SIM_MODEL::PARAM* toff = m_model.FindParam( "toff" ) )
waveform->m_toff = SIM_VALUE::ToDouble( toff->value, 1 ); waveform->m_toff = SIM_VALUE::ToDouble( toff->value, 0 );
if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) ) if( const SIM_MODEL::PARAM* td = m_model.FindParam( "td" ) )
waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 ); waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 );

View File

@ -30,6 +30,7 @@
#include <project.h> #include <project.h>
class SIM_LIBRARY_KIBIS; class SIM_LIBRARY_KIBIS;
class REPORTER;
class SPICE_GENERATOR_KIBIS : public SPICE_GENERATOR class SPICE_GENERATOR_KIBIS : public SPICE_GENERATOR
@ -42,7 +43,7 @@ public:
std::vector<std::string> CurrentNames( const SPICE_ITEM& aItem ) const override; std::vector<std::string> CurrentNames( const SPICE_ITEM& aItem ) const override;
std::string IbisDevice( const SPICE_ITEM& aItem, const PROJECT& aProject, std::string IbisDevice( const SPICE_ITEM& aItem, const PROJECT& aProject,
const wxString& aCacheDir ) const; const wxString& aCacheDir, REPORTER& aReporter ) const;
protected: protected:
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> GetInstanceParams() const override; std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> GetInstanceParams() const override;

View File

@ -61,6 +61,11 @@
#include <memory> #include <memory>
// Reporter is stored by pointer in KIBIS, so keep this here to avoid crashes
static wxString s_errors;
static WX_STRING_REPORTER s_reporter( &s_errors );
class SIM_THREAD_REPORTER : public SIMULATOR_REPORTER class SIM_THREAD_REPORTER : public SIMULATOR_REPORTER
{ {
public: public:
@ -338,8 +343,7 @@ void SIMULATOR_FRAME::UpdateTitle()
bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions ) bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
{ {
wxString errors; s_errors.clear();
WX_STRING_REPORTER reporter( &errors );
if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) ) if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) )
return false; return false;
@ -349,9 +353,9 @@ bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimO
m_schematicFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP ); m_schematicFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(), if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(),
reporter ) ) s_reporter ) )
{ {
DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + errors ); DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + s_errors );
return false; return false;
} }
@ -361,13 +365,10 @@ bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimO
void SIMULATOR_FRAME::ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions ) void SIMULATOR_FRAME::ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
{ {
wxString errors;
WX_STRING_REPORTER reporter( &errors );
if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(), if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(),
reporter ) ) s_reporter ) )
{ {
DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + errors ); DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + s_errors );
} }
} }
@ -550,17 +551,17 @@ bool SIMULATOR_FRAME::EditAnalysis()
{ {
SIM_TAB* simTab = m_ui->GetCurrentSimTab(); SIM_TAB* simTab = m_ui->GetCurrentSimTab();
DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() ); DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() );
wxString errors;
WX_STRING_REPORTER reporter( &errors ); s_errors.clear();
if( !simTab ) if( !simTab )
return false; return false;
if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS, if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS,
reporter ) ) s_reporter ) )
{ {
DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" )
+ errors ); + s_errors );
} }
dlg.SetSimCommand( simTab->GetSimCommand() ); dlg.SetSimCommand( simTab->GetSimCommand() );