diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp index e600824510..7e2097c602 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp @@ -479,7 +479,8 @@ void NETLIST_EXPORTER_SPICE::readModel( SCH_SHEET_PATH& aSheet, SCH_SYMBOL& aSym auto spiceGenerator = static_cast( kibisModel->SpiceGenerator() ); 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 ) ); m_rawIncludes.insert( cacheFn.GetFullPath() ); diff --git a/eeschema/sim/sim_model_kibis.cpp b/eeschema/sim/sim_model_kibis.cpp index ba4951f459..daaabba1bf 100644 --- a/eeschema/sim/sim_model_kibis.cpp +++ b/eeschema/sim/sim_model_kibis.cpp @@ -59,7 +59,8 @@ std::vector SPICE_GENERATOR_KIBIS::CurrentNames( const SPICE_ITEM& 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 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.m_cacheDir = std::string( aCacheDir.c_str() ); + kibis.m_reporter = &aReporter; if( !kibis.m_valid ) 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 ); 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" ) ) - 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" ) ) waveform->m_delay = SIM_VALUE::ToDouble( td->value, 0 ); diff --git a/eeschema/sim/sim_model_kibis.h b/eeschema/sim/sim_model_kibis.h index d121d96001..8a5b69b702 100644 --- a/eeschema/sim/sim_model_kibis.h +++ b/eeschema/sim/sim_model_kibis.h @@ -30,6 +30,7 @@ #include class SIM_LIBRARY_KIBIS; +class REPORTER; class SPICE_GENERATOR_KIBIS : public SPICE_GENERATOR @@ -42,7 +43,7 @@ public: std::vector CurrentNames( const SPICE_ITEM& aItem ) const override; std::string IbisDevice( const SPICE_ITEM& aItem, const PROJECT& aProject, - const wxString& aCacheDir ) const; + const wxString& aCacheDir, REPORTER& aReporter ) const; protected: std::vector> GetInstanceParams() const override; diff --git a/eeschema/sim/simulator_frame.cpp b/eeschema/sim/simulator_frame.cpp index 651a6ac89a..211f575e83 100644 --- a/eeschema/sim/simulator_frame.cpp +++ b/eeschema/sim/simulator_frame.cpp @@ -61,6 +61,11 @@ #include +// 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 { public: @@ -338,8 +343,7 @@ void SIMULATOR_FRAME::UpdateTitle() bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions ) { - wxString errors; - WX_STRING_REPORTER reporter( &errors ); + s_errors.clear(); if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) ) return false; @@ -349,9 +353,9 @@ bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimO m_schematicFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP ); 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; } @@ -361,13 +365,10 @@ bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimO 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(), - 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(); DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() ); - wxString errors; - WX_STRING_REPORTER reporter( &errors ); + + s_errors.clear(); if( !simTab ) return false; if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS, - reporter ) ) + s_reporter ) ) { DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) - + errors ); + + s_errors ); } dlg.SetSimCommand( simTab->GetSimCommand() );