37using namespace std::placeholders;
60 std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
63 embeddedFilesStack.push_back( embeddedFiles );
65 wxString resolvedPath =
resolver.ResolvePath( aLibraryPath, wxEmptyString,
66 std::move( embeddedFilesStack ) );
69 if( !resolvedPath.IsEmpty() )
71 wxFileName fn( resolvedPath );
74 return fn.GetFullPath();
82 expandedPath.Replace(
'\\',
'/' );
84 wxFileName fn( expandedPath );
86 if( fn.IsAbsolute() && fn.Exists() )
87 return fn.GetFullPath();
89 wxFileName projectFn(
m_project ?
m_project->AbsolutePath( expandedPath ) : expandedPath );
91 if( projectFn.Exists() )
92 return projectFn.GetFullPath();
95 wxFileName spiceLibFn( expandedPath );
98 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
100 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
101 return spiceLibFn.GetFullPath();
103 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
105 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
106 projectFn.GetFullPath() ) );
110 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
111 projectFn.GetFullPath(),
112 spiceLibFn.GetFullPath() ) );
120 const wxString& aRelativeLib,
123 wxFileName testPath( aLibPath );
124 wxString fullPath( aLibPath );
126 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
128 wxString relLib( aRelativeLib );
132 wxFileName fn( relLib );
134 testPath.MakeAbsolute( fn.GetPath(
true ) );
135 fullPath = testPath.GetFullPath();
138 wxFileName fn( fullPath );
156 if( !wxFileName::Exists(
path ) )
158 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
164 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
183 const std::vector<SCH_PIN*>& aPins,
REPORTER& aReporter )
191 const std::vector<SCH_FIELD>& aFields,
bool aResolve,
int aDepth,
199 bool aResolve,
int aDepth,
const wxString& aVariantName,
200 REPORTER& aReporter,
const wxString& aMergedSimPins )
209 std::vector<SCH_FIELD> fields;
215 fields.emplace_back( &aSymbol,
FIELD_T::USER, field.GetName() );
216 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
218 else if( field.GetId() ==
FIELD_T::VALUE || field.GetName().StartsWith( wxS(
"Sim." ) ) )
220 fields.emplace_back( &aSymbol,
FIELD_T::USER, field.GetName() );
223 if( !aMergedSimPins.IsEmpty() && field.GetName() ==
SIM_PINS_FIELD )
224 fields.back().SetText( aMergedSimPins );
226 fields.back().SetText( field.GetShownText( aSheetPath,
false, aDepth, aVariantName ) );
230 auto getOrCreateField =
235 if( field.GetName().IsSameAs(
name ) )
240 return &fields.back();
245 wxString modelParams;
247 bool storeInValue =
false;
251 &deviceType, &modelType, &modelParams, &pinMap ) )
255 if( !modelType.IsEmpty() )
266 std::sort( sourcePins.begin(), sourcePins.end(),
269 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
274 model.model.SetIsStoredInValue( storeInValue );
281 bool aResolve,
int aDepth,
282 const std::vector<SCH_PIN*>& aPins,
288 if( libraryPath !=
"" )
290 return CreateModel( libraryPath, baseModelName, aFields, aResolve, aDepth, aPins, aReporter );
295 return { baseModelName, *
m_models.back() };
301 const std::string& aBaseModelName,
302 const std::vector<SCH_FIELD>& aFields,
303 bool aResolve,
int aDepth,
304 const std::vector<SCH_PIN*>& aPins,
310 std::string modelName;
318 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
326 if( aBaseModelName ==
"" )
328 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
333 modelName =
_(
"unknown" ).ToStdString();
337 baseModel =
library->FindModel( aBaseModelName );
338 modelName = aBaseModelName;
342 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
353 return { modelName, *
m_models.back() };
359 m_models.at( aIndex ) = std::move( aModel );
365 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
376 std::vector<std::reference_wrapper<SIM_MODEL>> models;
379 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".