41using namespace std::placeholders;
64 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
67 embeddedFilesStack.push_back( embeddedFiles );
69 wxString resolvedPath =
resolver.ResolvePath( aLibraryPath, wxEmptyString,
70 std::move( embeddedFilesStack ) );
73 if( !resolvedPath.IsEmpty() )
75 wxFileName fn( resolvedPath );
78 return fn.GetFullPath();
86 expandedPath.Replace(
'\\',
'/' );
88 wxFileName fn( expandedPath );
90 if( fn.IsAbsolute() && fn.Exists() )
91 return fn.GetFullPath();
93 wxFileName projectFn(
m_project ?
m_project->AbsolutePath( expandedPath ) : expandedPath );
95 if( projectFn.Exists() )
96 return projectFn.GetFullPath();
99 wxFileName spiceLibFn( expandedPath );
100 wxString spiceLibDir;
102 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
104 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
105 return spiceLibFn.GetFullPath();
107 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
109 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
110 projectFn.GetFullPath() ) );
114 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
115 projectFn.GetFullPath(),
116 spiceLibFn.GetFullPath() ) );
124 const wxString& aRelativeLib,
127 wxFileName testPath( aLibPath );
128 wxString fullPath( aLibPath );
130 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
132 wxString relLib( aRelativeLib );
136 wxFileName fn( relLib );
138 testPath.MakeAbsolute( fn.GetPath(
true ) );
139 fullPath = testPath.GetFullPath();
142 wxFileName fn( fullPath );
160 if( !wxFileName::Exists(
path ) )
162 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
168 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
187 const std::vector<SCH_PIN*>& aPins,
REPORTER& aReporter )
195 const std::vector<SCH_FIELD>& aFields,
bool aResolve,
int aDepth,
203 bool aResolve,
int aDepth,
const wxString& aVariantName,
204 REPORTER& aReporter,
const wxString& aMergedSimPins )
213 std::vector<SCH_FIELD> fields;
219 fields.emplace_back( &aSymbol,
FIELD_T::USER, field.GetName() );
220 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
222 else if( field.GetId() ==
FIELD_T::VALUE || field.GetName().StartsWith( wxS(
"Sim." ) ) )
224 fields.emplace_back( &aSymbol,
FIELD_T::USER, field.GetName() );
227 if( !aMergedSimPins.IsEmpty() && field.GetName() ==
SIM_PINS_FIELD )
228 fields.back().SetText( aMergedSimPins );
230 fields.back().SetText( field.GetShownText( aSheetPath,
false, aDepth, aVariantName ) );
234 auto getOrCreateField =
239 if( field.GetName().IsSameAs(
name ) )
244 return &fields.back();
249 wxString modelParams;
251 bool storeInValue =
false;
255 &deviceType, &modelType, &modelParams, &pinMap ) )
259 if( !modelType.IsEmpty() )
270 std::sort( sourcePins.begin(), sourcePins.end(),
273 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
278 model.model.SetIsStoredInValue( storeInValue );
285 bool aResolve,
int aDepth,
286 const std::vector<SCH_PIN*>& aPins,
292 if( libraryPath !=
"" )
294 return CreateModel( libraryPath, baseModelName, aFields, aResolve, aDepth, aPins, aReporter );
299 return { baseModelName, *
m_models.back() };
305 const std::string& aBaseModelName,
306 const std::vector<SCH_FIELD>& aFields,
307 bool aResolve,
int aDepth,
308 const std::vector<SCH_PIN*>& aPins,
314 std::string modelName;
322 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
330 if( aBaseModelName ==
"" )
332 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
337 modelName =
_(
"unknown" ).ToStdString();
341 baseModel =
library->FindModel( aBaseModelName );
342 modelName = aBaseModelName;
346 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
357 return { modelName, *
m_models.back() };
363 m_models.at( aIndex ) = std::move( aModel );
369 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
380 std::vector<std::reference_wrapper<SIM_MODEL>> models;
383 models.emplace_back( *
model );
Provide an extensible class to resolve 3D model paths.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
std::vector< SCH_PIN * > GetAllLibPins() const
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, const 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 ResolveLibraryPath(const wxString &aLibraryPath, REPORTER &aReporter)
const PROJECT * m_project
std::vector< EMBEDDED_FILES * > m_embeddedFilesStack
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
std::map< wxString, std::reference_wrapper< const SIM_LIBRARY > > GetLibraries() const
wxString ResolveEmbeddedLibraryPath(const wxString &aLibPath, const wxString &aRelativeLib, REPORTER &aReporter)
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, int aDepth, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
static FILENAME_RESOLVER * resolver
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
#define SIM_DEVICE_SUBTYPE_FIELD
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".