2022-10-05 16:08:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
2023-01-03 15:29:45 +00:00
|
|
|
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-10-05 16:08:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-11-12 19:45:56 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <string>
|
2022-12-17 15:21:35 +00:00
|
|
|
#include <string_utils.h>
|
2022-12-07 15:02:35 +00:00
|
|
|
#include <common.h>
|
2022-12-15 23:34:00 +00:00
|
|
|
#include <functional>
|
2022-11-19 10:25:58 +00:00
|
|
|
#include <sch_symbol.h>
|
2022-11-12 17:41:29 +00:00
|
|
|
|
2022-11-19 10:25:58 +00:00
|
|
|
// Include simulator headers after wxWidgets headers to avoid conflicts with Windows headers
|
|
|
|
// (especially on msys2 + wxWidgets 3.0.x)
|
|
|
|
#include <sim/sim_lib_mgr.h>
|
|
|
|
#include <sim/sim_library.h>
|
|
|
|
#include <sim/sim_model.h>
|
2022-12-06 14:00:11 +00:00
|
|
|
#include <sim/sim_model_ideal.h>
|
|
|
|
|
2023-01-12 12:46:52 +00:00
|
|
|
using namespace std::placeholders;
|
2022-10-05 16:08:07 +00:00
|
|
|
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIB_MGR::SIM_LIB_MGR( const PROJECT* aPrj ) :
|
2023-01-12 12:46:52 +00:00
|
|
|
m_project( aPrj ),
|
2023-04-22 20:17:08 +00:00
|
|
|
m_forceFullParse( false )
|
2022-11-19 00:45:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 16:29:51 +00:00
|
|
|
void SIM_LIB_MGR::Clear()
|
|
|
|
{
|
|
|
|
m_libraries.clear();
|
|
|
|
m_models.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
wxString SIM_LIB_MGR::ResolveLibraryPath( const wxString& aLibraryPath, const PROJECT* aProject )
|
2022-11-26 02:47:41 +00:00
|
|
|
{
|
2023-10-21 12:30:51 +00:00
|
|
|
wxString expandedPath = ExpandEnvVarSubstitutions( aLibraryPath, aProject );
|
|
|
|
|
|
|
|
// Convert it to UNIX format
|
|
|
|
expandedPath.Replace( '\\', '/' );
|
|
|
|
|
2022-12-07 22:32:50 +00:00
|
|
|
wxFileName fn( expandedPath );
|
|
|
|
|
|
|
|
if( fn.IsAbsolute() )
|
|
|
|
return fn.GetFullPath();
|
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
wxFileName projectFn( aProject ? aProject->AbsolutePath( expandedPath ) : expandedPath );
|
2022-12-07 22:32:50 +00:00
|
|
|
|
|
|
|
if( projectFn.Exists() )
|
|
|
|
return projectFn.GetFullPath();
|
|
|
|
|
|
|
|
wxFileName spiceLibFn( expandedPath );
|
|
|
|
wxString spiceLibDir;
|
|
|
|
|
|
|
|
wxGetEnv( wxT( "SPICE_LIB_DIR" ), &spiceLibDir );
|
|
|
|
|
|
|
|
if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
|
|
|
|
return spiceLibFn.GetFullPath();
|
|
|
|
|
2023-10-21 12:30:51 +00:00
|
|
|
if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
|
2023-01-18 11:51:19 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Simulation model library not found at '%s'" ),
|
2023-10-21 12:30:51 +00:00
|
|
|
projectFn.GetFullPath() ) );
|
2023-01-18 11:51:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Simulation model library not found at '%s' or '%s'" ),
|
|
|
|
projectFn.GetFullPath(),
|
|
|
|
spiceLibFn.GetFullPath() ) );
|
|
|
|
}
|
2022-12-07 22:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-24 10:58:03 +00:00
|
|
|
wxString SIM_LIB_MGR::ResolveEmbeddedLibraryPath( const wxString& aLibPath,
|
|
|
|
const wxString& aRelativeLib )
|
2022-12-15 23:34:00 +00:00
|
|
|
{
|
|
|
|
wxFileName testPath( aLibPath );
|
|
|
|
wxString fullPath( aLibPath );
|
|
|
|
|
|
|
|
if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
|
|
|
|
{
|
|
|
|
wxString relLib( aRelativeLib );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
relLib = ResolveLibraryPath( relLib, m_project );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{}
|
|
|
|
|
|
|
|
wxFileName fn( relLib );
|
|
|
|
|
|
|
|
testPath.MakeAbsolute( fn.GetPath( true ) );
|
|
|
|
fullPath = testPath.GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
wxFileName fn( fullPath );
|
|
|
|
|
|
|
|
if( !fn.Exists() )
|
|
|
|
fullPath = aLibPath;
|
|
|
|
|
|
|
|
fullPath = ResolveLibraryPath( fullPath, m_project );
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{}
|
|
|
|
|
2023-04-24 10:58:03 +00:00
|
|
|
return fullPath;
|
2022-12-15 23:34:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
void SIM_LIB_MGR::SetLibrary( const wxString& aLibraryPath, REPORTER& aReporter )
|
2022-12-07 22:32:50 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
wxString path = ResolveLibraryPath( aLibraryPath, m_project );
|
|
|
|
|
2023-04-24 10:58:03 +00:00
|
|
|
std::function<wxString(const wxString&, const wxString&)> f2 =
|
2023-01-12 12:46:52 +00:00
|
|
|
std::bind( &SIM_LIB_MGR::ResolveEmbeddedLibraryPath, this, _1, _2 );
|
2022-12-13 03:23:55 +00:00
|
|
|
|
2023-04-22 20:17:08 +00:00
|
|
|
std::unique_ptr<SIM_LIBRARY> library = SIM_LIBRARY::Create( path, m_forceFullParse,
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter, &f2 );
|
2023-01-12 16:29:51 +00:00
|
|
|
|
|
|
|
Clear();
|
|
|
|
m_libraries[path] = std::move( library );
|
2023-01-03 15:29:45 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e )
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter.Report( e.What() );
|
2023-01-03 15:29:45 +00:00
|
|
|
}
|
2022-11-26 02:47:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-12 17:11:11 +00:00
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_MODEL& SIM_LIB_MGR::CreateModel( SIM_MODEL::TYPE aType, const std::vector<LIB_PIN*>& aPins,
|
|
|
|
REPORTER& aReporter )
|
2022-11-12 17:11:11 +00:00
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( aType, aPins, aReporter ) );
|
2022-11-12 17:11:11 +00:00
|
|
|
return *m_models.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins, REPORTER& aReporter )
|
2022-11-12 17:11:11 +00:00
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aReporter ) );
|
2022-11-12 17:11:11 +00:00
|
|
|
return *m_models.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-19 00:45:28 +00:00
|
|
|
template <typename T>
|
2023-01-03 15:29:45 +00:00
|
|
|
SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<T>& aFields, REPORTER& aReporter )
|
2022-11-19 00:45:28 +00:00
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( aBaseModel, aPins, aFields, aReporter ) );
|
2022-11-19 00:45:28 +00:00
|
|
|
return *m_models.back();
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<SCH_FIELD>& aFields,
|
|
|
|
REPORTER& aReporter );
|
2023-01-03 15:29:45 +00:00
|
|
|
template SIM_MODEL& SIM_LIB_MGR::CreateModel( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<LIB_FIELD>& aFields,
|
|
|
|
REPORTER& aReporter );
|
2022-11-19 00:45:28 +00:00
|
|
|
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, SCH_SYMBOL& aSymbol,
|
|
|
|
REPORTER& aReporter )
|
2022-10-05 16:08:07 +00:00
|
|
|
{
|
2022-12-09 20:02:47 +00:00
|
|
|
// Note: currently this creates a resolved model (all Kicad variables references are resolved
|
|
|
|
// before building the model).
|
|
|
|
//
|
|
|
|
// That's not what we want if this is ever called from the Simulation Model Editor (or other
|
|
|
|
// editors, but it is what we want if called to generate a netlist or other exported items.
|
|
|
|
|
|
|
|
|
2022-12-05 02:07:45 +00:00
|
|
|
std::vector<SCH_FIELD> fields;
|
|
|
|
|
2023-04-28 15:19:14 +00:00
|
|
|
for( const SCH_FIELD& field : aSymbol.GetFields() )
|
2022-12-05 02:07:45 +00:00
|
|
|
{
|
2023-04-28 15:19:14 +00:00
|
|
|
fields.emplace_back( VECTOR2I(), -1, &aSymbol, field.GetName() );
|
2022-12-05 02:07:45 +00:00
|
|
|
|
2023-04-28 15:19:14 +00:00
|
|
|
if( field.GetId() == REFERENCE_FIELD )
|
2022-12-05 02:07:45 +00:00
|
|
|
fields.back().SetText( aSymbol.GetRef( aSheetPath ) );
|
|
|
|
else
|
2023-05-05 13:21:56 +00:00
|
|
|
fields.back().SetText( field.GetShownText( aSheetPath, false ) );
|
2022-12-05 02:07:45 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString deviceType;
|
|
|
|
wxString modelType;
|
|
|
|
wxString modelParams;
|
|
|
|
wxString pinMap;
|
2022-12-23 17:26:16 +00:00
|
|
|
bool storeInValue = false;
|
2022-12-18 22:53:53 +00:00
|
|
|
|
|
|
|
// Infer RLC and VI models if they aren't specified
|
2022-12-19 18:10:57 +00:00
|
|
|
if( SIM_MODEL::InferSimModel( aSymbol, &fields, true, SIM_VALUE_GRAMMAR::NOTATION::SI,
|
|
|
|
&deviceType, &modelType, &modelParams, &pinMap ) )
|
2022-12-06 14:00:11 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
fields.emplace_back( &aSymbol, -1, SIM_DEVICE_TYPE_FIELD );
|
2022-12-18 22:53:53 +00:00
|
|
|
fields.back().SetText( deviceType );
|
2022-12-06 14:00:11 +00:00
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
if( !modelType.IsEmpty() )
|
2022-12-06 14:00:11 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
fields.emplace_back( &aSymbol, -1, SIM_TYPE_FIELD );
|
2022-12-18 22:53:53 +00:00
|
|
|
fields.back().SetText( modelType );
|
|
|
|
}
|
2022-12-09 15:09:34 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
fields.emplace_back( &aSymbol, -1, SIM_PARAMS_FIELD );
|
2022-12-18 22:53:53 +00:00
|
|
|
fields.back().SetText( modelParams );
|
2022-12-14 23:21:35 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
fields.emplace_back( &aSymbol, -1, SIM_PINS_FIELD );
|
2022-12-18 22:53:53 +00:00
|
|
|
fields.back().SetText( pinMap );
|
2022-12-23 17:26:16 +00:00
|
|
|
|
|
|
|
storeInValue = true;
|
2022-12-06 14:00:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
std::vector<LIB_PIN*> sourcePins = aSymbol.GetAllLibPins();
|
|
|
|
|
|
|
|
std::sort( sourcePins.begin(), sourcePins.end(),
|
|
|
|
[]( const LIB_PIN* lhs, const LIB_PIN* rhs )
|
|
|
|
{
|
|
|
|
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
|
|
|
|
} );
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIBRARY::MODEL model = CreateModel( fields, sourcePins, true, aReporter );
|
2022-12-23 17:26:16 +00:00
|
|
|
|
|
|
|
model.model.SetIsStoredInValue( storeInValue );
|
|
|
|
|
|
|
|
return model;
|
2022-11-12 17:11:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-11-19 00:45:28 +00:00
|
|
|
template <typename T>
|
2022-12-17 15:21:35 +00:00
|
|
|
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<T>& aFields,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins, bool aResolved,
|
|
|
|
REPORTER& aReporter )
|
2022-11-19 00:45:28 +00:00
|
|
|
{
|
|
|
|
std::string libraryPath = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::LIBRARY_FIELD );
|
|
|
|
std::string baseModelName = SIM_MODEL::GetFieldValue( &aFields, SIM_LIBRARY::NAME_FIELD );
|
|
|
|
|
|
|
|
if( libraryPath != "" )
|
2022-12-09 20:02:47 +00:00
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
return CreateModel( libraryPath, baseModelName, aFields, aPins, aReporter );
|
2022-12-09 20:02:47 +00:00
|
|
|
}
|
2022-11-19 00:45:28 +00:00
|
|
|
else
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( aFields, aPins, aResolved, aReporter ) );
|
2022-11-19 00:45:28 +00:00
|
|
|
return { baseModelName, *m_models.back() };
|
|
|
|
}
|
|
|
|
}
|
2022-11-12 22:12:29 +00:00
|
|
|
|
|
|
|
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<SCH_FIELD>& aFields,
|
2023-01-03 15:29:45 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-09-06 10:37:50 +00:00
|
|
|
bool aResolved, REPORTER& aReporter );
|
2022-11-12 22:12:29 +00:00
|
|
|
template SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const std::vector<LIB_FIELD>& aFields,
|
2023-01-03 15:29:45 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-09-06 10:37:50 +00:00
|
|
|
bool aResolved, REPORTER& aReporter );
|
2022-11-12 22:12:29 +00:00
|
|
|
|
2022-11-19 00:45:28 +00:00
|
|
|
|
2022-11-12 22:12:29 +00:00
|
|
|
template <typename T>
|
2022-12-07 15:02:35 +00:00
|
|
|
SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const wxString& aLibraryPath,
|
2022-11-19 00:45:28 +00:00
|
|
|
const std::string& aBaseModelName,
|
|
|
|
const std::vector<T>& aFields,
|
2023-09-06 10:37:50 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
|
|
|
REPORTER& aReporter )
|
2022-11-12 17:11:11 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
wxString path;
|
2023-01-02 22:47:46 +00:00
|
|
|
wxString msg;
|
2023-01-12 16:29:51 +00:00
|
|
|
SIM_LIBRARY* library = nullptr;
|
2023-01-03 15:29:45 +00:00
|
|
|
SIM_MODEL* baseModel = nullptr;
|
|
|
|
std::string modelName;
|
2022-12-15 23:34:00 +00:00
|
|
|
|
2022-11-19 00:45:28 +00:00
|
|
|
try
|
2022-10-05 16:08:07 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
path = ResolveLibraryPath( aLibraryPath, m_project );
|
|
|
|
|
2023-04-22 20:23:42 +00:00
|
|
|
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 );
|
|
|
|
|
2023-04-22 20:17:08 +00:00
|
|
|
it = m_libraries.emplace( path, SIM_LIBRARY::Create( path, m_forceFullParse,
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter, &f2 ) ).first;
|
2023-04-22 20:23:42 +00:00
|
|
|
}
|
2023-01-03 15:29:45 +00:00
|
|
|
|
2023-01-12 16:29:51 +00:00
|
|
|
library = &*it->second;
|
2022-11-19 00:45:28 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e )
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
msg.Printf( _( "Error loading simulation model library '%s': %s" ),
|
|
|
|
path,
|
|
|
|
e.What() );
|
2023-01-12 12:46:52 +00:00
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2022-10-05 16:08:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-19 00:45:28 +00:00
|
|
|
if( aBaseModelName == "" )
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
msg.Printf( _( "Error loading simulation model: no '%s' field" ),
|
|
|
|
SIM_LIBRARY::NAME_FIELD );
|
2023-01-12 12:46:52 +00:00
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2022-11-19 00:45:28 +00:00
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
modelName = _( "unknown" ).ToStdString();
|
|
|
|
}
|
2023-01-12 16:29:51 +00:00
|
|
|
else if( library )
|
2022-11-19 00:45:28 +00:00
|
|
|
{
|
2023-01-12 16:29:51 +00:00
|
|
|
baseModel = library->FindModel( aBaseModelName );
|
2023-01-03 15:29:45 +00:00
|
|
|
modelName = aBaseModelName;
|
2023-01-02 22:47:46 +00:00
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
if( !baseModel )
|
|
|
|
{
|
2023-09-06 10:37:50 +00:00
|
|
|
msg.Printf( _( "Error loading simulation model: could not find base model '%s' "
|
|
|
|
"in library '%s'" ),
|
|
|
|
aBaseModelName,
|
|
|
|
path );
|
|
|
|
|
|
|
|
aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
2023-01-03 15:29:45 +00:00
|
|
|
}
|
2022-11-19 00:45:28 +00:00
|
|
|
}
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( baseModel, aPins, aFields, aReporter ) );
|
2022-11-19 00:45:28 +00:00
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
return { modelName, *m_models.back() };
|
2022-11-19 00:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 16:29:51 +00:00
|
|
|
void SIM_LIB_MGR::SetModel( int aIndex, std::unique_ptr<SIM_MODEL> aModel )
|
2022-11-19 00:45:28 +00:00
|
|
|
{
|
2023-01-12 16:29:51 +00:00
|
|
|
m_models.at( aIndex ) = std::move( aModel );
|
2022-10-06 07:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-12 16:29:51 +00:00
|
|
|
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> SIM_LIB_MGR::GetLibraries() const
|
2022-10-06 07:47:03 +00:00
|
|
|
{
|
2023-01-12 16:29:51 +00:00
|
|
|
std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
|
|
|
|
|
|
|
|
for( auto& [path, library] : m_libraries )
|
|
|
|
libraries.try_emplace( path, *library );
|
|
|
|
|
|
|
|
return libraries;
|
2022-11-12 22:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::reference_wrapper<SIM_MODEL>> SIM_LIB_MGR::GetModels() const
|
|
|
|
{
|
|
|
|
std::vector<std::reference_wrapper<SIM_MODEL>> models;
|
2022-10-06 07:47:03 +00:00
|
|
|
|
2022-11-12 22:12:29 +00:00
|
|
|
for( const std::unique_ptr<SIM_MODEL>& model : m_models )
|
|
|
|
models.emplace_back( *model );
|
2022-10-06 07:47:03 +00:00
|
|
|
|
2022-11-12 22:12:29 +00:00
|
|
|
return models;
|
2022-10-05 16:08:07 +00:00
|
|
|
}
|