39using namespace std::placeholders;
44 m_forceFullParse( false )
62 expandedPath.Replace(
'\\',
'/' );
64 wxFileName fn( expandedPath );
67 return fn.GetFullPath();
69 wxFileName projectFn( aProject ? aProject->
AbsolutePath( expandedPath ) : expandedPath );
71 if( projectFn.Exists() )
72 return projectFn.GetFullPath();
74 wxFileName spiceLibFn( expandedPath );
77 wxGetEnv( wxT(
"SPICE_LIB_DIR" ), &spiceLibDir );
79 if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
80 return spiceLibFn.GetFullPath();
82 if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
84 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
85 projectFn.GetFullPath() ) );
89 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s' or '%s'" ),
90 projectFn.GetFullPath(),
91 spiceLibFn.GetFullPath() ) );
99 const wxString& aRelativeLib,
102 wxFileName testPath( aLibPath );
103 wxString fullPath( aLibPath );
105 if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
107 wxString relLib( aRelativeLib );
111 wxFileName fn( relLib );
113 testPath.MakeAbsolute( fn.GetPath(
true ) );
114 fullPath = testPath.GetFullPath();
117 wxFileName fn( fullPath );
135 if( !wxFileName::Exists(
path ) )
137 aReporter.
Report( wxString::Format(
_(
"Simulation model library not found at '%s'" ),
143 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
162 const std::vector<SCH_PIN*>& aPins,
REPORTER& aReporter )
170 const std::vector<SCH_PIN*>& aPins,
171 const std::vector<SCH_FIELD>& aFields,
REPORTER& aReporter )
187 std::vector<SCH_FIELD> fields;
193 fields.emplace_back(
VECTOR2I(), -1, &aSymbol, field.GetName() );
194 fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
197 || field.GetName().StartsWith( wxS(
"Sim." ) ) )
199 fields.emplace_back(
VECTOR2I(), -1, &aSymbol, field.GetName() );
200 fields.back().SetText( field.GetShownText( aSheetPath,
false ) );
204 auto getOrCreateField =
209 if( field.GetName().IsSameAs(
name ) )
213 fields.emplace_back( &aSymbol, -1,
name );
214 return &fields.back();
219 wxString modelParams;
221 bool storeInValue =
false;
225 &deviceType, &modelType, &modelParams, &pinMap ) )
229 if( !modelType.IsEmpty() )
240 std::sort( sourcePins.begin(), sourcePins.end(),
243 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
255 const std::vector<SCH_PIN*>& aPins,
bool aResolved,
261 if( libraryPath !=
"" )
263 return CreateModel( libraryPath, baseModelName, aFields, aPins, aReporter );
268 return { baseModelName, *
m_models.back() };
274 const std::string& aBaseModelName,
275 const std::vector<SCH_FIELD>& aFields,
276 const std::vector<SCH_PIN*>& aPins,
282 std::string modelName;
290 [&](
const wxString& libPath,
const wxString& relativeLib ) -> wxString
298 if( aBaseModelName ==
"" )
300 msg.Printf(
_(
"Error loading simulation model: no '%s' field" ),
305 modelName =
_(
"unknown" ).ToStdString();
309 baseModel =
library->FindModel( aBaseModelName );
310 modelName = aBaseModelName;
314 msg.Printf(
_(
"Error loading simulation model: could not find base model '%s' "
325 return { modelName, *
m_models.back() };
331 m_models.at( aIndex ) = std::move( aModel );
337 std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
348 std::vector<std::reference_wrapper<SIM_MODEL>> models;
350 for(
const std::unique_ptr<SIM_MODEL>& model :
m_models )
351 models.emplace_back( *model );
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 HasMessage() const =0
Returns true if the reporter client is non-empty.
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,...
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...
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, 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)
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, 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
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 SIM_DEVICE_SUBTYPE_FIELD
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< int32_t > VECTOR2I