39using namespace std::placeholders;
44 m_reporter( aReporter ),
45 m_forceFullParse( false )
60 wxFileName fn( expandedPath );
63 return fn.GetFullPath();
65 wxFileName projectFn( aProject ? aProject->
AbsolutePath( expandedPath ) : expandedPath );
67 if( projectFn.Exists() )
68 return projectFn.GetFullPath();
70 wxFileName spiceLibFn( expandedPath );
73 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
75 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
76 return spiceLibFn.GetFullPath();
78 if( projectFn.GetFullPath() == spiceLibFn.GetFullPath() )
80 THROW_IO_ERROR( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
81 spiceLibFn.GetFullPath() ) );
85 THROW_IO_ERROR( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
86 projectFn.GetFullPath(),
87 spiceLibFn.GetFullPath() ) );
93 const wxString& aRelativeLib )
95 wxFileName testPath( aLibPath );
96 wxString fullPath( aLibPath );
98 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
100 wxString relLib( aRelativeLib );
109 wxFileName fn( relLib );
111 testPath.MakeAbsolute( fn.GetPath(
true ) );
112 fullPath = testPath.GetFullPath();
117 wxFileName fn( fullPath );
137 std::function<wxString(
const wxString&,
const wxString&)> f2 =
161 const std::vector<LIB_PIN*>& aPins )
170 const std::vector<LIB_PIN*>& aPins,
171 const std::vector<T>& aFields )
178 const std::vector<LIB_PIN*>& aPins,
179 const std::vector<SCH_FIELD>& aFields );
181 const std::vector<LIB_PIN*>& aPins,
182 const std::vector<LIB_FIELD>& aFields );
194 std::vector<SCH_FIELD> fields;
198 fields.emplace_back(
VECTOR2I(), -1, &aSymbol, field.GetName() );
201 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
203 fields.back().SetText( field.GetShownText( aSheetPath,
false ) );
208 wxString modelParams;
210 bool storeInValue =
false;
214 &deviceType, &modelType, &modelParams, &pinMap ) )
217 fields.back().SetText( deviceType );
219 if( !modelType.IsEmpty() )
222 fields.back().SetText( modelType );
226 fields.back().SetText( modelParams );
229 fields.back().SetText( pinMap );
236 std::sort( sourcePins.begin(), sourcePins.end(),
239 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
252 const std::vector<LIB_PIN*>& aPins,
bool aResolved )
257 if( libraryPath !=
"" )
259 return CreateModel( libraryPath, baseModelName, aFields, aPins );
264 return { baseModelName, *
m_models.back() };
269 const std::vector<LIB_PIN*>& aPins,
272 const std::vector<LIB_PIN*>& aPins,
278 const std::string& aBaseModelName,
279 const std::vector<T>& aFields,
280 const std::vector<LIB_PIN*>& aPins )
286 std::string modelName;
296 std::function<wxString(
const wxString&,
const wxString& )> f2 =
309 msg.Printf(
_(
"Error loading simulation model library '%s': %s" ),
317 if( aBaseModelName ==
"" )
321 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
327 modelName =
_(
"unknown" ).ToStdString();
331 baseModel =
library->FindModel( aBaseModelName );
332 modelName = aBaseModelName;
338 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
350 return { modelName, *
m_models.back() };
356 m_models.at( aIndex ) = std::move( aModel );
362 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
373 std::vector<std::reference_wrapper<SIM_MODEL>> models;
375 for(
const std::unique_ptr<SIM_MODEL>& model :
m_models )
376 models.emplace_back( *model );
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Container for project specific data.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
std::vector< LIB_PIN * > GetAllLibPins() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
static std::unique_ptr< SIM_LIBRARY > Create(const wxString &aFilePath, bool aForceFullParse, REPORTER *aReporter, std::function< wxString(const wxString &, const wxString &)> *aResolver)
Read library from a source file (e.g.
static constexpr auto LIBRARY_FIELD
static constexpr auto NAME_FIELD
void SetModel(int aIndex, std::unique_ptr< SIM_MODEL > aModel)
wxString ResolveEmbeddedLibraryPath(const wxString &aLibPath, const wxString &aRelativeLib)
const PROJECT * m_project
void SetLibrary(const wxString &aLibraryPath)
SIM_LIB_MGR(const PROJECT *aPrj, REPORTER *aReporter=nullptr)
std::vector< std::unique_ptr< SIM_MODEL > > m_models
static wxString ResolveLibraryPath(const wxString &aLibraryPath, const PROJECT *aProject)
std::map< wxString, std::reference_wrapper< const SIM_LIBRARY > > GetLibraries() const
std::vector< std::reference_wrapper< SIM_MODEL > > GetModels() const
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< LIB_PIN * > &aPins)
std::map< wxString, std::unique_ptr< SIM_LIBRARY > > m_libraries
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< LIB_PIN * > &aPins, REPORTER *aReporter)
static bool InferSimModel(T_symbol &aSymbol, std::vector< T_field > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
static std::string GetFieldValue(const std::vector< T > *aFields, const wxString &aFieldName, bool aResolve=true)
void SetIsStoredInValue(bool aIsStoredInValue)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
#define THROW_IO_ERROR(msg)
#define SIM_DEVICE_TYPE_FIELD
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".