41using namespace std::placeholders;
47 m_forceFullParse( false )
67 wxFileName fn( expandedPath );
70 return fn.GetFullPath();
74 if( projectFn.Exists() )
75 return projectFn.GetFullPath();
77 wxFileName spiceLibFn( expandedPath );
80 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
82 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
83 return spiceLibFn.GetFullPath();
85 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
87 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
88 projectFn.GetFullPath() ) );
92 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
93 projectFn.GetFullPath(),
94 spiceLibFn.GetFullPath() ) );
102 const wxString& aRelativeLib,
105 wxFileName testPath( aLibPath );
106 wxString fullPath( aLibPath );
108 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
110 wxString relLib( aRelativeLib );
114 wxFileName fn( relLib );
116 testPath.MakeAbsolute( fn.GetPath(
true ) );
117 fullPath = testPath.GetFullPath();
120 wxFileName fn( fullPath );
138 if( !wxFileName::Exists(
path ) )
140 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
146 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
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;
194 if( field.GetId() == FIELD_T::REFERENCE )
196 fields.emplace_back(
VECTOR2I(), FIELD_T::USER, &aSymbol, field.GetName() );
197 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
199 else if( field.GetId() == FIELD_T::VALUE || field.GetName().StartsWith( wxS(
"Sim." ) ) )
201 fields.emplace_back(
VECTOR2I(), FIELD_T::USER, &aSymbol, field.GetName() );
202 fields.back().SetText( field.GetShownText( aSheetPath,
false ) );
206 auto getOrCreateField =
211 if( field.GetName().IsSameAs(
name ) )
215 fields.emplace_back( &aSymbol, FIELD_T::USER,
name );
216 return &fields.back();
221 wxString modelParams;
223 bool storeInValue =
false;
227 &deviceType, &modelType, &modelParams, &pinMap ) )
231 if( !modelType.IsEmpty() )
242 std::sort( sourcePins.begin(), sourcePins.end(),
245 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
257 const std::vector<SCH_PIN*>& aPins,
bool aResolved,
263 if( libraryPath !=
"" )
265 return CreateModel( libraryPath, baseModelName, aFields, aPins, aReporter );
270 return { baseModelName, *
m_models.back() };
276 const std::string& aBaseModelName,
277 const std::vector<SCH_FIELD>& aFields,
278 const std::vector<SCH_PIN*>& aPins,
284 std::string modelName;
292 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
300 if( aBaseModelName ==
"" )
302 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
307 modelName =
_(
"unknown" ).ToStdString();
311 baseModel =
library->FindModel( aBaseModelName );
312 modelName = aBaseModelName;
316 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
327 return { modelName, *
m_models.back() };
333 m_models.at( aIndex ) = std::move( aModel );
339 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
350 std::vector<std::reference_wrapper<SIM_MODEL>> models;
352 for(
const std::unique_ptr<SIM_MODEL>& model :
m_models )
353 models.emplace_back( *model );
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles)
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.
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 bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
void SetText(const wxString &aText) override
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
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
std::vector< std::unique_ptr< SIM_MODEL > > m_models
SIM_LIB_MGR(const PROJECT *aPrj, EMBEDDED_FILES *aFiles)
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, 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)
void SetIsStoredInValue(bool aIsStoredInValue)
static FILENAME_RESOLVER * resolver
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
#define SIM_DEVICE_SUBTYPE_FIELD
VECTOR2< int32_t > VECTOR2I