37using namespace std::placeholders;
60 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
63 embeddedFilesStack.push_back( embeddedFiles );
65 wxString resolvedPath = resolver.
ResolvePath( aLibraryPath, wxEmptyString, std::move( embeddedFilesStack ) );
68 if( !resolvedPath.IsEmpty() )
70 wxFileName fn( resolvedPath );
73 return fn.GetFullPath();
81 expandedPath.Replace(
'\\',
'/' );
83 wxFileName fn( expandedPath );
85 if( fn.IsAbsolute() && fn.Exists() )
86 return fn.GetFullPath();
88 wxFileName projectFn(
m_project ?
m_project->AbsolutePath( expandedPath ) : expandedPath );
90 if( projectFn.Exists() )
91 return projectFn.GetFullPath();
94 wxFileName spiceLibFn( expandedPath );
97 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
99 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
100 return spiceLibFn.GetFullPath();
102 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
104 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
105 projectFn.GetFullPath() ) );
109 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
110 projectFn.GetFullPath(),
111 spiceLibFn.GetFullPath() ) );
119 const wxString& aRelativeLib,
122 wxFileName testPath( aLibPath );
123 wxString fullPath( aLibPath );
125 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
127 wxString relLib( aRelativeLib );
131 wxFileName fn( relLib );
133 testPath.MakeAbsolute( fn.GetPath(
true ) );
134 fullPath = testPath.GetFullPath();
137 wxFileName fn( fullPath );
155 if( !wxFileName::Exists(
path ) )
157 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
163 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
182 std::span<const wxString> aPins,
REPORTER& aReporter )
190 const std::vector<SCH_FIELD>& aFields,
bool aResolve,
int aDepth,
199 int aDepth,
const wxString& aVariantName,
200 const wxString& aMergedSimPins )
209 input.
fields.emplace_back( field.GetName(), aSymbol.
GetRef( aSheetPath ) );
211 else if( field.GetId() ==
FIELD_T::VALUE || field.GetName().StartsWith( wxS(
"Sim." ) ) )
213 const wxString value = !aMergedSimPins.IsEmpty() && field.GetName() ==
SIM_PINS_FIELD
215 : field.GetShownText( aSheetPath,
FOR_NETNAME, aVariantName, aDepth );
216 input.
fields.emplace_back( field.GetName(), value );
224 [](
const wxString& lhs,
const wxString& rhs )
226 return StrNumCmp( lhs, rhs, CMP_T::IGNORE_CASE ) < 0;
233 bool aResolve,
int aDepth,
const wxString& aVariantName,
234 REPORTER& aReporter,
const wxString& aMergedSimPins )
237 aResolve, aReporter );
244 std::vector<SCH_FIELD> fields;
246 for(
const auto& [
name, value] : aInput.
fields )
249 fields.back().SetText( value );
252 auto getOrCreateField =
259 return &fields.back();
264 wxString modelParams;
266 bool storeInValue =
false;
274 if( !modelType.IsEmpty() )
285 model.model.SetIsStoredInValue( storeInValue );
292 bool aResolve,
int aDepth,
293 std::span<const wxString> aPins,
296 return createModel( aFields, aResolve, aDepth, aPins, aReporter, aResolve );
301 std::span<const wxString> aPins,
REPORTER& aReporter,
302 bool aAllowRawFallback )
307 if( libraryPath !=
"" )
309 return CreateModel( libraryPath, baseModelName, aFields, aResolve, aDepth, aPins, aReporter );
314 return { baseModelName, *
m_models.back() };
320 const std::string& aBaseModelName,
321 const std::vector<SCH_FIELD>& aFields,
322 bool aResolve,
int aDepth,
323 std::span<const wxString> aPins,
329 std::string modelName;
337 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
345 if( aBaseModelName ==
"" )
347 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
352 modelName =
_(
"unknown" ).ToStdString();
356 baseModel =
library->FindModel( aBaseModelName );
357 modelName = aBaseModelName;
361 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
372 return { modelName, *
m_models.back() };
378 m_models.at( aIndex ) = std::move( aModel );
384 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
395 std::vector<std::reference_wrapper<SIM_MODEL>> models;
398 models.emplace_back( *
model );
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
bool SetProject(const PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
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...
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
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
wxString GetPrefix() const
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)
SIM_LIBRARY::MODEL createModel(const std::vector< SCH_FIELD > &aFields, bool aResolve, int aDepth, std::span< const wxString > aPins, REPORTER &aReporter, bool aAllowRawFallback)
wxString ResolveLibraryPath(const wxString &aLibraryPath, REPORTER &aReporter)
const PROJECT * m_project
std::vector< EMBEDDED_FILES * > m_embeddedFilesStack
SIM_LIB_MGR(const PROJECT *aPrj)
std::vector< std::unique_ptr< SIM_MODEL > > m_models
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
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
static SIM_MODEL_INPUT CaptureModelInput(const SCH_SHEET_PATH *aSheetPath, const SCH_SYMBOL &aSymbol, int aDepth, const wxString &aVariantName, const wxString &aMergedSimPins=wxEmptyString)
Resolve instance fields once; editors use the field-based overloads for unresolved input.
void SetLibrary(const wxString &aLibraryPath, REPORTER &aReporter)
std::map< wxString, std::unique_ptr< SIM_LIBRARY > > m_libraries
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
static bool InferSimModel(const wxString &aPrefix, std::span< const wxString > aPins, std::vector< SCH_FIELD > *aFields, bool aResolve, int aDepth, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
aPins follows lexical symbol-pin number order, including duplicate numbers.
static std::vector< wxString > PinNumbers(std::span< const SCH_PIN *const > aPins)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject, bool aAllowEscapes)
Replace any environment variable & text variable references with their values.
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
#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".