Hold off on one-library-per-SIM_LIB_MGR. It's too risky for 7.0.
This commit is contained in:
parent
631fd54f9f
commit
52163c7b31
|
@ -209,7 +209,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
|
||||||
{
|
{
|
||||||
if( strs.first == SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD ) )
|
if( strs.first == SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD ) )
|
||||||
{
|
{
|
||||||
auto kibisLibrary = static_cast<const SIM_LIBRARY_KIBIS*>( m_libraryModelsMgr.GetLibrary() );
|
auto kibisLibrary = static_cast<const SIM_LIBRARY_KIBIS*>( library() );
|
||||||
|
|
||||||
kibismodel->ChangePin( *kibisLibrary, strs.first );
|
kibismodel->ChangePin( *kibisLibrary, strs.first );
|
||||||
m_ibisPinCombobox->SetSelection( static_cast<int>( i ) );
|
m_ibisPinCombobox->SetSelection( static_cast<int>( i ) );
|
||||||
|
@ -309,8 +309,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
|
||||||
|
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
if( ( m_libraryModelsMgr.GetLibrary() && m_useLibraryModelRadioButton->GetValue() )
|
if( ( library() && m_useLibraryModelRadioButton->GetValue() ) || isIbisLoaded() )
|
||||||
|| isIbisLoaded() )
|
|
||||||
{
|
{
|
||||||
path = m_libraryPathText->GetValue();
|
path = m_libraryPathText->GetValue();
|
||||||
wxFileName fn( path );
|
wxFileName fn( path );
|
||||||
|
@ -697,7 +696,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
|
||||||
|
|
||||||
std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
|
std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
|
||||||
|
|
||||||
for( auto& [baseModelName, baseModel] : m_libraryModelsMgr.GetLibrary()->GetModels() )
|
for( auto& [baseModelName, baseModel] : library()->GetModels() )
|
||||||
{
|
{
|
||||||
if( baseModelName == modelName )
|
if( baseModelName == modelName )
|
||||||
m_libraryModelsMgr.CreateModel( &baseModel, sourcePins, m_fields );
|
m_libraryModelsMgr.CreateModel( &baseModel, sourcePins, m_fields );
|
||||||
|
@ -713,7 +712,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
|
||||||
|
|
||||||
wxArrayString modelNames;
|
wxArrayString modelNames;
|
||||||
|
|
||||||
for( auto& [name, model] : m_libraryModelsMgr.GetLibrary()->GetModels() )
|
for( auto& [name, model] : library()->GetModels() )
|
||||||
modelNames.Add( name );
|
modelNames.Add( name );
|
||||||
|
|
||||||
m_modelNameChoice->Clear();
|
m_modelNameChoice->Clear();
|
||||||
|
@ -922,6 +921,16 @@ SIM_MODEL& DIALOG_SIM_MODEL<T_symbol, T_field>::curModel() const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_symbol, typename T_field>
|
||||||
|
const SIM_LIBRARY* DIALOG_SIM_MODEL<T_symbol, T_field>::library() const
|
||||||
|
{
|
||||||
|
if( m_libraryModelsMgr.GetLibraries().size() == 1 )
|
||||||
|
return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T_symbol, typename T_field>
|
template <typename T_symbol, typename T_field>
|
||||||
wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getSymbolPinString( int symbolPinIndex ) const
|
wxString DIALOG_SIM_MODEL<T_symbol, T_field>::getSymbolPinString( int symbolPinIndex ) const
|
||||||
{
|
{
|
||||||
|
@ -1092,7 +1101,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onIbisPinCombobox( wxCommandEvent& aEv
|
||||||
std::vector<std::pair<std::string, std::string>> strs = ibisModel.GetIbisPins();
|
std::vector<std::pair<std::string, std::string>> strs = ibisModel.GetIbisPins();
|
||||||
std::string pinNumber = strs.at( m_ibisPinCombobox->GetSelection() ).first;
|
std::string pinNumber = strs.at( m_ibisPinCombobox->GetSelection() ).first;
|
||||||
|
|
||||||
auto ibisLibrary = static_cast<const SIM_LIBRARY_KIBIS*>( m_libraryModelsMgr.GetLibrary() );
|
const SIM_LIBRARY_KIBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_KIBIS*>( library() );
|
||||||
|
|
||||||
ibisModel.ChangePin( *ibisLibrary, pinNumber );
|
ibisModel.ChangePin( *ibisLibrary, pinNumber );
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ private:
|
||||||
int findSymbolPinRow( const wxString& aSymbolPinNumber ) const;
|
int findSymbolPinRow( const wxString& aSymbolPinNumber ) const;
|
||||||
|
|
||||||
SIM_MODEL& curModel() const;
|
SIM_MODEL& curModel() const;
|
||||||
|
const SIM_LIBRARY* library() const;
|
||||||
|
|
||||||
wxString getSymbolPinString( int aSymbolPinNumber ) const;
|
wxString getSymbolPinString( int aSymbolPinNumber ) const;
|
||||||
wxString getModelPinString( int aModelPinIndex ) const;
|
wxString getModelPinString( int aModelPinIndex ) const;
|
||||||
|
@ -113,10 +114,7 @@ private:
|
||||||
|
|
||||||
void adjustParamGridColumns( int aWidth, bool aForce );
|
void adjustParamGridColumns( int aWidth, bool aForce );
|
||||||
|
|
||||||
bool isIbisLoaded()
|
bool isIbisLoaded() { return dynamic_cast<const SIM_LIBRARY_KIBIS*>( library() ); }
|
||||||
{
|
|
||||||
return dynamic_cast<const SIM_LIBRARY_KIBIS*>( m_libraryModelsMgr.GetLibrary() ) != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T_symbol& m_symbol;
|
T_symbol& m_symbol;
|
||||||
|
|
|
@ -392,9 +392,29 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
|
||||||
}
|
}
|
||||||
catch( const tao::pegtl::parse_error& )
|
catch( const tao::pegtl::parse_error& )
|
||||||
{
|
{
|
||||||
// If we couldn't parse it, but it -looks- like SPICE, then send it as raw SPICE
|
// Even if we couldn't parse it, send anything that _looks_ like a directive to
|
||||||
if( text.StartsWith( "." ) || text.StartsWith( "*" ) )
|
// SPICE
|
||||||
m_directives.emplace_back( text );
|
wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK );
|
||||||
|
bool inDirective = false;
|
||||||
|
|
||||||
|
while( tokenizer.HasMoreTokens() )
|
||||||
|
{
|
||||||
|
wxString line = tokenizer.GetNextToken();
|
||||||
|
|
||||||
|
if( line.StartsWith( "." ) )
|
||||||
|
{
|
||||||
|
m_directives.emplace_back( line );
|
||||||
|
inDirective = true;
|
||||||
|
}
|
||||||
|
else if( inDirective && line.StartsWith( "+" ) )
|
||||||
|
{
|
||||||
|
m_directives.emplace_back( line );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inDirective = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,13 @@ SIM_LIB_MGR::SIM_LIB_MGR( const PROJECT* aPrj, REPORTER* aReporter ) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SIM_LIB_MGR::Clear()
|
||||||
|
{
|
||||||
|
m_libraries.clear();
|
||||||
|
m_models.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject )
|
wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject )
|
||||||
{
|
{
|
||||||
wxString expandedPath = ExpandEnvVarSubstitutions( aLibraryPath, aProject );
|
wxString expandedPath = ExpandEnvVarSubstitutions( aLibraryPath, aProject );
|
||||||
|
@ -114,9 +121,6 @@ std::string SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const std::string& aLibPath
|
||||||
|
|
||||||
void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath )
|
void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath )
|
||||||
{
|
{
|
||||||
m_models.clear();
|
|
||||||
m_library = nullptr;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wxString path = ResolveLibraryPath( aLibraryPath, m_project );
|
wxString path = ResolveLibraryPath( aLibraryPath, m_project );
|
||||||
|
@ -124,7 +128,10 @@ void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath )
|
||||||
std::function<std::string(const std::string&, const std::string&)> f2 =
|
std::function<std::string(const std::string&, const std::string&)> f2 =
|
||||||
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
||||||
|
|
||||||
m_library = SIM_LIBRARY::Create( path, m_reporter, &f2 );
|
std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_reporter, &f2 );
|
||||||
|
|
||||||
|
Clear();
|
||||||
|
m_libraries[path] = std::move( library );
|
||||||
}
|
}
|
||||||
catch( const IO_ERROR& e )
|
catch( const IO_ERROR& e )
|
||||||
{
|
{
|
||||||
|
@ -264,11 +271,10 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
||||||
{
|
{
|
||||||
wxString path;
|
wxString path;
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
SIM_LIBRARY* library = nullptr;
|
||||||
SIM_MODEL* baseModel = nullptr;
|
SIM_MODEL* baseModel = nullptr;
|
||||||
std::string modelName;
|
std::string modelName;
|
||||||
|
|
||||||
wxASSERT( !m_library );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
path = ResolveLibraryPath( aLibraryPath, m_project );
|
path = ResolveLibraryPath( aLibraryPath, m_project );
|
||||||
|
@ -276,7 +282,8 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
||||||
std::function<std::string( const std::string&, const std::string& )> f2 =
|
std::function<std::string( const std::string&, const std::string& )> f2 =
|
||||||
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
||||||
|
|
||||||
m_library = SIM_LIBRARY::Create( path, m_reporter, &f2 );
|
auto it = m_libraries.try_emplace( path, SIM_LIBRARY::Create( path, m_reporter, &f2 ) ).first;
|
||||||
|
library = &*it->second;
|
||||||
}
|
}
|
||||||
catch( const IO_ERROR& e )
|
catch( const IO_ERROR& e )
|
||||||
{
|
{
|
||||||
|
@ -302,9 +309,9 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
||||||
|
|
||||||
modelName = _( "unknown" ).ToStdString();
|
modelName = _( "unknown" ).ToStdString();
|
||||||
}
|
}
|
||||||
else if( m_library )
|
else if( library )
|
||||||
{
|
{
|
||||||
baseModel = m_library->FindModel( aBaseModelName );
|
baseModel = library->FindModel( aBaseModelName );
|
||||||
modelName = aBaseModelName;
|
modelName = aBaseModelName;
|
||||||
|
|
||||||
if( !baseModel )
|
if( !baseModel )
|
||||||
|
@ -327,18 +334,23 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const SIM_LIBRARY* SIM_LIB_MGR::GetLibrary() const
|
|
||||||
{
|
|
||||||
return m_library.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SIM_LIB_MGR::SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel )
|
void SIM_LIB_MGR::SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel )
|
||||||
{
|
{
|
||||||
m_models.at( aIndex ) = std::move( aModel );
|
m_models.at( aIndex ) = std::move( aModel );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> SIM_LIB_MGR::GetLibraries() const
|
||||||
|
{
|
||||||
|
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
|
||||||
|
|
||||||
|
for( auto& [path, library] : m_libraries )
|
||||||
|
libraries.try_emplace( path, *library );
|
||||||
|
|
||||||
|
return libraries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<std::reference_wrapper<SIM_MODEL>> SIM_LIB_MGR::GetModels() const
|
std::vector<std::reference_wrapper<SIM_MODEL>> SIM_LIB_MGR::GetModels() const
|
||||||
{
|
{
|
||||||
std::vector<std::reference_wrapper<SIM_MODEL>> models;
|
std::vector<std::reference_wrapper<SIM_MODEL>> models;
|
||||||
|
|
|
@ -45,8 +45,9 @@ public:
|
||||||
|
|
||||||
void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
|
void SetReporter( REPORTER* aReporter ) { m_reporter = aReporter; }
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
void SetLibrary( const wxString& aLibraryPath );
|
void SetLibrary( const wxString& aLibraryPath );
|
||||||
const SIM_LIBRARY* GetLibrary() const;
|
|
||||||
|
|
||||||
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 );
|
||||||
|
|
||||||
|
@ -71,6 +72,7 @@ public:
|
||||||
|
|
||||||
void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel );
|
void SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel );
|
||||||
|
|
||||||
|
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> GetLibraries() const;
|
||||||
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
std::vector<std::reference_wrapper<SIM_MODEL>> GetModels() const;
|
||||||
|
|
||||||
static wxString ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject );
|
static wxString ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject );
|
||||||
|
@ -79,10 +81,10 @@ public:
|
||||||
const std::string& aRelativeLib );
|
const std::string& aRelativeLib );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const PROJECT* m_project;
|
const PROJECT* m_project;
|
||||||
REPORTER* m_reporter;
|
REPORTER* m_reporter;
|
||||||
std::unique_ptr<SIM_LIBRARY> m_library;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue