mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 00:21:25 +00:00
Clean up more exception processing in simulation GUI.
This allows us to more correctly report errors without dialog issues, logs popping up, etc. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18259
This commit is contained in:
parent
e59417aff3
commit
7f6ab7043b
@ -153,7 +153,8 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject, std::s
|
||||
wxString strResult;
|
||||
strResult.Alloc( strlen ); // best guess (improves performance)
|
||||
|
||||
auto getVersionedEnvVar = []( const wxString& aMatch, wxString& aResult ) -> bool
|
||||
auto getVersionedEnvVar =
|
||||
[]( const wxString& aMatch, wxString& aResult ) -> bool
|
||||
{
|
||||
for ( const wxString& var : ENV_VAR::GetPredefinedEnvVars() )
|
||||
{
|
||||
@ -186,7 +187,9 @@ wxString KIwxExpandEnvVars( const wxString& str, const PROJECT* aProject, std::s
|
||||
Bracket bracket;
|
||||
#ifdef __WINDOWS__
|
||||
if( str_n == wxT( '%' ) )
|
||||
bracket = Bracket_Windows;
|
||||
{
|
||||
bracket = Bracket_Windows;
|
||||
}
|
||||
else
|
||||
#endif // __WINDOWS__
|
||||
if( n == strlen - 1 )
|
||||
|
@ -159,7 +159,10 @@ void WX_INFOBAR::ShowMessage( const wxString& aMessage, int aFlags )
|
||||
|
||||
m_updateLock = true;
|
||||
|
||||
wxInfoBarGeneric::ShowMessage( aMessage, aFlags );
|
||||
wxString msg = aMessage;
|
||||
msg.Trim();
|
||||
|
||||
wxInfoBarGeneric::ShowMessage( msg, aFlags );
|
||||
|
||||
if( m_auiManager )
|
||||
updateAuiLayout( true );
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <sch_edit_frame.h>
|
||||
#include <sim/sim_model_l_mutual.h>
|
||||
#include <sim/spice_circuit_model.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
|
||||
|
||||
@ -74,8 +75,7 @@ DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame
|
||||
m_scintillaTricksSubckt( nullptr ),
|
||||
m_firstCategory( nullptr ),
|
||||
m_prevParamGridSelection( nullptr ),
|
||||
m_lastParamGridWidth( 0 ),
|
||||
m_inKillFocus( false )
|
||||
m_lastParamGridWidth( 0 )
|
||||
{
|
||||
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
||||
|
||||
@ -216,12 +216,14 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
||||
// The model is sourced from a library, optionally with instance overrides.
|
||||
m_rbLibraryModel->SetValue( true );
|
||||
|
||||
if( !loadLibrary( libraryFilename ) )
|
||||
if( !loadLibrary( libraryFilename, reporter ) )
|
||||
{
|
||||
if( reporter.HasMessage() )
|
||||
m_infoBar->ShowMessage( msg );
|
||||
|
||||
m_libraryPathText->ChangeValue( libraryFilename );
|
||||
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, reporter );
|
||||
|
||||
// load library will mangle the set reporter
|
||||
m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields, reporter );
|
||||
|
||||
m_modelNameChoice->Append( _( "<unknown>" ) );
|
||||
@ -234,14 +236,15 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
||||
|
||||
if( modelIdx == wxNOT_FOUND )
|
||||
{
|
||||
DisplayErrorMessage( this, wxString::Format( _( "No model named '%s' in library." ),
|
||||
modelName ) );
|
||||
m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in library." ),
|
||||
modelName ) );
|
||||
|
||||
// Default to first item in library
|
||||
m_modelNameChoice->SetSelection( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_infoBar->Hide();
|
||||
m_modelNameChoice->SetSelection( modelIdx );
|
||||
}
|
||||
|
||||
@ -803,36 +806,28 @@ void DIALOG_SIM_MODEL<T>::removeOrphanedPinAssignments( SIM_MODEL* aModel )
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, bool aForceReload )
|
||||
bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter,
|
||||
bool aForceReload )
|
||||
{
|
||||
if( m_prevLibrary == aLibraryPath && !aForceReload )
|
||||
return true;
|
||||
|
||||
wxString msg;
|
||||
WX_STRING_REPORTER reporter( &msg );
|
||||
|
||||
m_libraryModelsMgr.SetForceFullParse();
|
||||
m_libraryModelsMgr.SetLibrary( aLibraryPath, reporter );
|
||||
m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
|
||||
|
||||
if( reporter.HasMessage() )
|
||||
{
|
||||
DisplayErrorMessage( this, msg );
|
||||
if( aReporter.HasMessage() )
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
|
||||
|
||||
for( const auto& [baseModelName, baseModel] : library()->GetModels() )
|
||||
{
|
||||
if( baseModelName == modelName )
|
||||
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, reporter );
|
||||
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, aReporter );
|
||||
else
|
||||
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, reporter );
|
||||
m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
|
||||
}
|
||||
|
||||
if( reporter.HasMessage() )
|
||||
DisplayErrorMessage( this, msg );
|
||||
|
||||
m_rbLibraryModel->SetValue( true );
|
||||
m_libraryPathText->ChangeValue( aLibraryPath );
|
||||
|
||||
@ -1169,22 +1164,7 @@ void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
|
||||
template <typename T>
|
||||
void DIALOG_SIM_MODEL<T>::onLibraryPathText( wxCommandEvent& aEvent )
|
||||
{
|
||||
if( m_rbLibraryModel->GetValue() )
|
||||
{
|
||||
wxString path = m_libraryPathText->GetValue();
|
||||
|
||||
if( loadLibrary( path, true ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
updateWidgets();
|
||||
}
|
||||
catch( const IO_ERROR& )
|
||||
{
|
||||
// TODO: Add an infobar to report the error?
|
||||
}
|
||||
}
|
||||
}
|
||||
m_rbLibraryModel->SetValue( true );
|
||||
}
|
||||
|
||||
|
||||
@ -1192,21 +1172,33 @@ template <typename T>
|
||||
void DIALOG_SIM_MODEL<T>::onLibraryPathTextEnter( wxCommandEvent& aEvent )
|
||||
{
|
||||
m_rbLibraryModel->SetValue( true );
|
||||
|
||||
wxString msg;
|
||||
WX_STRING_REPORTER reporter( &msg );
|
||||
wxString path = m_libraryPathText->GetValue();
|
||||
|
||||
if( loadLibrary( path, reporter, true ) )
|
||||
m_infoBar->Hide();
|
||||
else if( reporter.HasMessage() )
|
||||
m_infoBar->ShowMessage( msg );
|
||||
|
||||
updateWidgets();
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void DIALOG_SIM_MODEL<T>::onLibraryPathTextKillFocus( wxFocusEvent& aEvent )
|
||||
{
|
||||
if( !m_inKillFocus )
|
||||
{
|
||||
m_inKillFocus = true;
|
||||
CallAfter(
|
||||
[this]()
|
||||
{
|
||||
// Disable logging -- otherwise we'll end up in an endless loop of show-log,
|
||||
// kill-focus, show-log, kill-focus, etc.
|
||||
wxLogNull doNotLog;
|
||||
|
||||
wxCommandEvent dummy;
|
||||
onLibraryPathTextEnter( dummy );
|
||||
|
||||
m_inKillFocus = false;
|
||||
}
|
||||
wxCommandEvent dummy;
|
||||
onLibraryPathTextEnter( dummy );
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@ -1231,7 +1223,14 @@ void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
|
||||
if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS( ".." ) ) )
|
||||
path = fn.GetFullPath();
|
||||
|
||||
loadLibrary( path, true );
|
||||
wxString msg;
|
||||
WX_STRING_REPORTER reporter( &msg );
|
||||
|
||||
if( loadLibrary( path, reporter, true ) )
|
||||
m_infoBar->Hide();
|
||||
else
|
||||
m_infoBar->ShowMessage( msg );
|
||||
|
||||
updateWidgets();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ private:
|
||||
|
||||
void removeOrphanedPinAssignments( SIM_MODEL* aModel );
|
||||
|
||||
bool loadLibrary( const wxString& aLibraryPath, bool aForceReload = false );
|
||||
bool loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter,
|
||||
bool aForceReload = false );
|
||||
|
||||
void addParamPropertyIfRelevant( SIM_MODEL* aModel, int aParamIndex );
|
||||
wxPGProperty* newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const;
|
||||
@ -141,7 +142,6 @@ private:
|
||||
wxPGProperty* m_prevParamGridSelection;
|
||||
|
||||
int m_lastParamGridWidth;
|
||||
bool m_inKillFocus;
|
||||
};
|
||||
|
||||
#endif /* DIALOG_SIM_MODEL_H */
|
||||
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
#include "widgets/std_bitmap_button.h"
|
||||
#include "widgets/wx_grid.h"
|
||||
#include "widgets/wx_infobar.h"
|
||||
|
||||
#include "dialog_sim_model_base.h"
|
||||
|
||||
@ -19,6 +20,13 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
|
||||
wxBoxSizer* bSizer8;
|
||||
bSizer8 = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_infoBar = new WX_INFOBAR( this );
|
||||
m_infoBar->SetShowHideEffects( wxSHOW_EFFECT_NONE, wxSHOW_EFFECT_NONE );
|
||||
m_infoBar->SetEffectDuration( 500 );
|
||||
m_infoBar->Hide();
|
||||
|
||||
bSizer8->Add( m_infoBar, 0, wxEXPAND, 5 );
|
||||
|
||||
m_notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_modelPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
|
||||
wxBoxSizer* bSizerPanel;
|
||||
|
@ -1,36 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<wxFormBuilder_Project>
|
||||
<FileVersion major="1" minor="18"/>
|
||||
<FileVersion major="1" minor="17"/>
|
||||
<object class="Project" expanded="true">
|
||||
<property name="class_decoration">; </property>
|
||||
<property name="code_generation">C++</property>
|
||||
<property name="cpp_class_decoration">; </property>
|
||||
<property name="cpp_disconnect_events">1</property>
|
||||
<property name="cpp_event_generation">connect</property>
|
||||
<property name="cpp_help_provider">none</property>
|
||||
<property name="cpp_namespace"></property>
|
||||
<property name="cpp_precompiled_header"></property>
|
||||
<property name="cpp_use_array_enum">0</property>
|
||||
<property name="cpp_use_enum">0</property>
|
||||
<property name="disconnect_events">1</property>
|
||||
<property name="disconnect_mode">source_name</property>
|
||||
<property name="disconnect_php_events">0</property>
|
||||
<property name="disconnect_python_events">0</property>
|
||||
<property name="embedded_files_path">res</property>
|
||||
<property name="encoding">UTF-8</property>
|
||||
<property name="event_generation">connect</property>
|
||||
<property name="file">dialog_sim_model_base</property>
|
||||
<property name="first_id">1000</property>
|
||||
<property name="help_provider">none</property>
|
||||
<property name="image_path_wrapper_function_name"></property>
|
||||
<property name="indent_with_spaces"></property>
|
||||
<property name="internationalize">1</property>
|
||||
<property name="lua_skip_events">1</property>
|
||||
<property name="lua_ui_table">UI</property>
|
||||
<property name="name">DIALOG_SIM_MODEL_BASE</property>
|
||||
<property name="namespace"></property>
|
||||
<property name="path">.</property>
|
||||
<property name="php_disconnect_events">0</property>
|
||||
<property name="php_disconnect_mode">source_name</property>
|
||||
<property name="php_skip_events">1</property>
|
||||
<property name="python_disconnect_events">0</property>
|
||||
<property name="python_disconnect_mode">source_name</property>
|
||||
<property name="python_image_path_wrapper_function_name"></property>
|
||||
<property name="python_indent_with_spaces"></property>
|
||||
<property name="python_skip_events">1</property>
|
||||
<property name="precompiled_header"></property>
|
||||
<property name="relative_path">1</property>
|
||||
<property name="skip_lua_events">1</property>
|
||||
<property name="skip_php_events">1</property>
|
||||
<property name="skip_python_events">1</property>
|
||||
<property name="ui_table">UI</property>
|
||||
<property name="use_array_enum">0</property>
|
||||
<property name="use_enum">0</property>
|
||||
<property name="use_microsoft_bom">0</property>
|
||||
<property name="use_native_eol">0</property>
|
||||
<object class="Dialog" expanded="true">
|
||||
<property name="aui_managed">0</property>
|
||||
<property name="aui_manager_style">wxAUI_MGR_DEFAULT</property>
|
||||
@ -64,6 +62,67 @@
|
||||
<property name="name">bSizer8</property>
|
||||
<property name="orient">wxVERTICAL</property>
|
||||
<property name="permission">none</property>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">5</property>
|
||||
<property name="flag">wxEXPAND</property>
|
||||
<property name="proportion">0</property>
|
||||
<object class="wxInfoBar" expanded="true">
|
||||
<property name="BottomDockable">1</property>
|
||||
<property name="LeftDockable">1</property>
|
||||
<property name="RightDockable">1</property>
|
||||
<property name="TopDockable">1</property>
|
||||
<property name="aui_layer"></property>
|
||||
<property name="aui_name"></property>
|
||||
<property name="aui_position"></property>
|
||||
<property name="aui_row"></property>
|
||||
<property name="best_size"></property>
|
||||
<property name="bg"></property>
|
||||
<property name="caption"></property>
|
||||
<property name="caption_visible">1</property>
|
||||
<property name="center_pane">0</property>
|
||||
<property name="close_button">1</property>
|
||||
<property name="context_help"></property>
|
||||
<property name="context_menu">1</property>
|
||||
<property name="default_pane">0</property>
|
||||
<property name="dock">Dock</property>
|
||||
<property name="dock_fixed">0</property>
|
||||
<property name="docking">Left</property>
|
||||
<property name="drag_accept_files">0</property>
|
||||
<property name="duration">500</property>
|
||||
<property name="enabled">1</property>
|
||||
<property name="fg"></property>
|
||||
<property name="floatable">1</property>
|
||||
<property name="font"></property>
|
||||
<property name="gripper">0</property>
|
||||
<property name="hidden">1</property>
|
||||
<property name="hide_effect">wxSHOW_EFFECT_NONE</property>
|
||||
<property name="id">wxID_ANY</property>
|
||||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">m_infoBar</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
<property name="permission">protected</property>
|
||||
<property name="pin_button">1</property>
|
||||
<property name="pos"></property>
|
||||
<property name="resize">Resizable</property>
|
||||
<property name="show">1</property>
|
||||
<property name="show_effect">wxSHOW_EFFECT_NONE</property>
|
||||
<property name="size"></property>
|
||||
<property name="subclass">WX_INFOBAR; widgets/wx_infobar.h; forward_declare</property>
|
||||
<property name="toolbar_pane">0</property>
|
||||
<property name="tooltip"></property>
|
||||
<property name="window_extra_style"></property>
|
||||
<property name="window_name"></property>
|
||||
<property name="window_style"></property>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem" expanded="true">
|
||||
<property name="border">10</property>
|
||||
<property name="flag">wxEXPAND|wxTOP|wxRIGHT|wxLEFT</property>
|
||||
|
@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
|
||||
// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO *NOT* EDIT THIS FILE!
|
||||
@ -12,14 +12,16 @@
|
||||
#include <wx/intl.h>
|
||||
class STD_BITMAP_BUTTON;
|
||||
class WX_GRID;
|
||||
class WX_INFOBAR;
|
||||
|
||||
#include "dialog_shim.h"
|
||||
#include <wx/string.h>
|
||||
#include <wx/radiobut.h>
|
||||
#include <wx/infobar.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/font.h>
|
||||
#include <wx/colour.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/string.h>
|
||||
#include <wx/radiobut.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/bmpbuttn.h>
|
||||
@ -43,6 +45,7 @@ class WX_GRID;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/// Class DIALOG_SIM_MODEL_BASE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -51,6 +54,7 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM
|
||||
private:
|
||||
|
||||
protected:
|
||||
WX_INFOBAR* m_infoBar;
|
||||
wxNotebook* m_notebook;
|
||||
wxPanel* m_modelPanel;
|
||||
wxRadioButton* m_rbLibraryModel;
|
||||
|
@ -53,7 +53,8 @@ void SIM_LIB_MGR::Clear()
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject )
|
||||
wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject,
|
||||
REPORTER& aReporter )
|
||||
{
|
||||
wxString expandedPath = ExpandEnvVarSubstitutions( aLibraryPath, aProject );
|
||||
|
||||
@ -80,20 +81,23 @@ wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PR
|
||||
|
||||
if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Simulation model library not found at '%s'" ),
|
||||
projectFn.GetFullPath() ) );
|
||||
aReporter.Report( wxString::Format( _( "Simulation model library not found at '%s'" ),
|
||||
projectFn.GetFullPath() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Simulation model library not found at '%s' or '%s'" ),
|
||||
projectFn.GetFullPath(),
|
||||
spiceLibFn.GetFullPath() ) );
|
||||
aReporter.Report( wxString::Format( _( "Simulation model library not found at '%s' or '%s'" ),
|
||||
projectFn.GetFullPath(),
|
||||
spiceLibFn.GetFullPath() ) );
|
||||
}
|
||||
|
||||
return aLibraryPath;
|
||||
}
|
||||
|
||||
|
||||
wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
|
||||
const wxString& aRelativeLib )
|
||||
const wxString& aRelativeLib,
|
||||
REPORTER& aReporter )
|
||||
{
|
||||
wxFileName testPath( aLibPath );
|
||||
wxString fullPath( aLibPath );
|
||||
@ -102,12 +106,7 @@ wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
|
||||
{
|
||||
wxString relLib( aRelativeLib );
|
||||
|
||||
try
|
||||
{
|
||||
relLib = ResolveLibraryPath( relLib, m_project );
|
||||
}
|
||||
catch( ... )
|
||||
{}
|
||||
relLib = ResolveLibraryPath( relLib, m_project, aReporter );
|
||||
|
||||
wxFileName fn( relLib );
|
||||
|
||||
@ -115,17 +114,12 @@ wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
|
||||
fullPath = testPath.GetFullPath();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
wxFileName fn( fullPath );
|
||||
wxFileName fn( fullPath );
|
||||
|
||||
if( !fn.Exists() )
|
||||
fullPath = aLibPath;
|
||||
if( !fn.Exists() )
|
||||
fullPath = aLibPath;
|
||||
|
||||
fullPath = ResolveLibraryPath( fullPath, m_project );
|
||||
}
|
||||
catch( ... )
|
||||
{}
|
||||
fullPath = ResolveLibraryPath( fullPath, m_project, aReporter );
|
||||
|
||||
return fullPath;
|
||||
}
|
||||
@ -133,23 +127,26 @@ wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
|
||||
|
||||
void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter )
|
||||
{
|
||||
try
|
||||
wxString path = ResolveLibraryPath( aLibraryPath, m_project, aReporter );
|
||||
|
||||
if( aReporter.HasMessage() )
|
||||
return;
|
||||
|
||||
if( !wxFileName::Exists( path ) )
|
||||
{
|
||||
wxString path = ResolveLibraryPath( aLibraryPath, m_project );
|
||||
|
||||
std::function<wxString(const wxString&, const wxString&)> f2 =
|
||||
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
||||
|
||||
std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_forceFullParse,
|
||||
aReporter, &f2 );
|
||||
|
||||
Clear();
|
||||
m_libraries[path] = std::move( library );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
aReporter.Report( e.What() );
|
||||
aReporter.Report( wxString::Format( _( "Simulation model library not found at '%s'" ),
|
||||
path ) );
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_forceFullParse, aReporter,
|
||||
[&]( const wxString& libPath, const wxString& relativeLib ) -> wxString
|
||||
{
|
||||
return ResolveEmbeddedLibraryPath( libPath, relativeLib, aReporter );
|
||||
} );
|
||||
|
||||
Clear();
|
||||
m_libraries[path] = std::move( library );
|
||||
}
|
||||
|
||||
|
||||
@ -279,37 +276,24 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
||||
const std::vector<SCH_PIN*>& aPins,
|
||||
REPORTER& aReporter )
|
||||
{
|
||||
wxString path;
|
||||
wxString msg;
|
||||
SIM_LIBRARY* library = nullptr;
|
||||
SIM_MODEL* baseModel = nullptr;
|
||||
std::string modelName;
|
||||
wxString path = ResolveLibraryPath( aLibraryPath, m_project, aReporter );
|
||||
|
||||
try
|
||||
auto it = m_libraries.find( path );
|
||||
|
||||
if( it == m_libraries.end() )
|
||||
{
|
||||
path = ResolveLibraryPath( aLibraryPath, m_project );
|
||||
|
||||
auto it = m_libraries.find( path );
|
||||
|
||||
if( it == m_libraries.end() )
|
||||
{
|
||||
std::function<wxString( const wxString&, const wxString& )> f2 =
|
||||
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
||||
|
||||
it = m_libraries.emplace( path, SIM_LIBRARY::Create( path, m_forceFullParse,
|
||||
aReporter, &f2 ) ).first;
|
||||
}
|
||||
|
||||
library = &*it->second;
|
||||
it = m_libraries.emplace( path, SIM_LIBRARY::Create( path, m_forceFullParse, aReporter,
|
||||
[&]( const wxString& libPath, const wxString& relativeLib ) -> wxString
|
||||
{
|
||||
return ResolveEmbeddedLibraryPath( libPath, relativeLib, aReporter );
|
||||
} ) ).first;
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
{
|
||||
msg.Printf( _( "Error loading simulation model library '%s': %s" ),
|
||||
path,
|
||||
e.What() );
|
||||
|
||||
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
||||
}
|
||||
library = &*it->second;
|
||||
|
||||
if( aBaseModelName == "" )
|
||||
{
|
||||
|
@ -74,8 +74,10 @@ public:
|
||||
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> GetLibraries() const;
|
||||
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
||||
|
||||
static wxString ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject );
|
||||
wxString ResolveEmbeddedLibraryPath( const wxString& aLibPath, const wxString& aRelativeLib );
|
||||
static wxString ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject,
|
||||
REPORTER& aReporter );
|
||||
wxString ResolveEmbeddedLibraryPath( const wxString& aLibPath, const wxString& aRelativeLib,
|
||||
REPORTER& aReporter );
|
||||
|
||||
private:
|
||||
const PROJECT* m_project;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
std::unique_ptr<SIM_LIBRARY>
|
||||
SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
|
||||
std::function<wxString( const wxString&, const wxString& )>* aResolver )
|
||||
const std::function<wxString( const wxString&, const wxString& )>& aResolver )
|
||||
{
|
||||
std::unique_ptr<SIM_LIBRARY> library;
|
||||
|
||||
|
@ -56,7 +56,7 @@ public:
|
||||
*/
|
||||
static std::unique_ptr<SIM_LIBRARY>
|
||||
Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
|
||||
std::function<wxString( const wxString&, const wxString& )>* aResolver );
|
||||
const std::function<wxString( const wxString&, const wxString& )>& aResolver );
|
||||
|
||||
/**
|
||||
* Read library from a source file. Must be in the format appropriate to the subclass, e.g.
|
||||
@ -77,7 +77,7 @@ protected:
|
||||
std::vector<std::string> m_modelNames;
|
||||
std::vector<std::unique_ptr<SIM_MODEL>> m_models;
|
||||
|
||||
std::function<wxString( const wxString&, const wxString& )>* m_pathResolver;
|
||||
std::function<wxString( const wxString&, const wxString& )> m_pathResolver;
|
||||
|
||||
std::string m_filePath;
|
||||
};
|
||||
|
@ -68,7 +68,12 @@ std::string SPICE_GENERATOR_IBIS::IbisDevice( const SPICE_ITEM& aItem, const PRO
|
||||
std::string ibisModelName = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY_IBIS::MODEL_FIELD );
|
||||
bool diffMode = SIM_MODEL::GetFieldValue( &aItem.fields, SIM_LIBRARY_IBIS::DIFF_FIELD ) == "1";
|
||||
|
||||
wxString path = SIM_LIB_MGR::ResolveLibraryPath( ibisLibFilename, &aProject );
|
||||
wxString msg;
|
||||
WX_STRING_REPORTER reporter( &msg );
|
||||
wxString path = SIM_LIB_MGR::ResolveLibraryPath( ibisLibFilename, &aProject, reporter );
|
||||
|
||||
if( reporter.HasMessage() )
|
||||
THROW_IO_ERROR( msg );
|
||||
|
||||
KIBIS kibis( std::string( path.c_str() ) );
|
||||
kibis.m_cacheDir = std::string( aCacheDir.c_str() );
|
||||
|
@ -118,10 +118,7 @@ void SPICE_LIBRARY_PARSER::readFallbacks( const wxString& aFilePath, REPORTER& a
|
||||
}
|
||||
else if( token == wxS( ".inc" ) )
|
||||
{
|
||||
wxString lib = tokenizer.GetNextToken();
|
||||
|
||||
if( m_library.m_pathResolver )
|
||||
lib = ( *m_library.m_pathResolver )( lib, aFilePath );
|
||||
wxString lib = m_library.m_pathResolver( tokenizer.GetNextToken(), aFilePath );
|
||||
|
||||
parseFile( lib, aReporter );
|
||||
}
|
||||
@ -170,13 +167,10 @@ void SPICE_LIBRARY_PARSER::parseFile( const wxString &aFilePath, REPORTER& aRepo
|
||||
}
|
||||
else if( node->is_type<SIM_LIBRARY_SPICE_PARSER::dotInclude>() )
|
||||
{
|
||||
wxString lib = node->children.at( 0 )->string();
|
||||
wxString lib = m_library.m_pathResolver( node->children.at( 0 )->string(), aFilePath );
|
||||
|
||||
try
|
||||
{
|
||||
if( m_library.m_pathResolver )
|
||||
lib = ( *m_library.m_pathResolver )( lib, aFilePath );
|
||||
|
||||
parseFile( lib, aReporter );
|
||||
}
|
||||
catch( const IO_ERROR& e )
|
||||
|
Loading…
Reference in New Issue
Block a user