39using namespace std::placeholders;
44 m_forceFullParse( false )
61 expandedPath.Replace(
'\\',
'/' );
63 wxFileName fn( expandedPath );
66 return fn.GetFullPath();
68 wxFileName projectFn( aProject ? aProject->
AbsolutePath( expandedPath ) : expandedPath );
70 if( projectFn.Exists() )
71 return projectFn.GetFullPath();
73 wxFileName spiceLibFn( expandedPath );
76 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
78 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
79 return spiceLibFn.GetFullPath();
81 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
83 THROW_IO_ERROR( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
84 projectFn.GetFullPath() ) );
88 THROW_IO_ERROR( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
89 projectFn.GetFullPath(),
90 spiceLibFn.GetFullPath() ) );
96 const wxString& aRelativeLib )
98 wxFileName testPath( aLibPath );
99 wxString fullPath( aLibPath );
101 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
103 wxString relLib( aRelativeLib );
112 wxFileName fn( relLib );
114 testPath.MakeAbsolute( fn.GetPath(
true ) );
115 fullPath = testPath.GetFullPath();
120 wxFileName fn( fullPath );
140 std::function<wxString(
const wxString&,
const wxString&)> f2 =
165 const std::vector<SCH_PIN*>& aPins,
REPORTER& aReporter )
173 const std::vector<SCH_PIN*>& aPins,
174 const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter )
190 std::vector<SCH_FIELD> fields;
196 fields.emplace_back(
VECTOR2I(), -1, &aSymbol, field.GetName() );
197 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
200 || field.GetName().StartsWith( wxS(
"Sim." ) ) )
202 fields.emplace_back(
VECTOR2I(), -1, &aSymbol, field.GetName() );
203 fields.back().SetText( field.GetShownText( aSheetPath,
false ) );
209 wxString modelParams;
211 bool storeInValue =
false;
215 &deviceType, &modelType, &modelParams, &pinMap ) )
218 fields.back().SetText( deviceType );
220 if( !modelType.IsEmpty() )
223 fields.back().SetText( modelType );
227 fields.back().SetText( modelParams );
230 fields.back().SetText( pinMap );
237 std::sort( sourcePins.begin(), sourcePins.end(),
240 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
252 const std::vector<SCH_PIN*>& aPins,
bool aResolved,
258 if( libraryPath !=
"" )
260 return CreateModel( libraryPath, baseModelName, aFields, aPins, aReporter );
265 return { baseModelName, *
m_models.back() };
271 const std::string& aBaseModelName,
272 const std::vector<SCH_FIELD>& aFields,
273 const std::vector<SCH_PIN*>& aPins,
280 std::string modelName;
290 std::function<wxString(
const wxString&,
const wxString& )> f2 =
294 aReporter, &f2 ) ).first;
301 msg.Printf(
_(
"Error loading simulation model library '%s': %s" ),
308 if( aBaseModelName ==
"" )
310 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
315 modelName =
_(
"unknown" ).ToStdString();
319 baseModel =
library->FindModel( aBaseModelName );
320 modelName = aBaseModelName;
324 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
335 return { modelName, *
m_models.back() };
341 m_models.at( aIndex ) = std::move( aModel );
347 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
358 std::vector<std::reference_wrapper<SIM_MODEL>> models;
360 for(
const std::unique_ptr<SIM_MODEL>& model :
m_models )
361 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...
std::vector< SCH_PIN * > GetAllLibPins() const
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
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
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
SIM_LIB_MGR(const PROJECT *aPrj)
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
void SetLibrary(const wxString &aLibraryPath, REPORTER &aReporter)
std::map< wxString, std::unique_ptr< SIM_LIBRARY > > m_libraries
static bool InferSimModel(T &aSymbol, std::vector< SCH_FIELD > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
static std::string GetFieldValue(const std::vector< SCH_FIELD > *aFields, const wxString &aFieldName, bool aResolve=true)
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
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_SUBTYPE_FIELD
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".