41using namespace std::placeholders;
 
   64    std::vector<const EMBEDDED_FILES*> embeddedFilesStack;
 
   67        embeddedFilesStack.push_back( embeddedFiles );
 
   69    wxString expandedPath = 
resolver.ResolvePath( aLibraryPath, wxEmptyString, std::move( embeddedFilesStack ) );
 
   71    wxFileName fn( expandedPath );
 
   74        return fn.GetFullPath();
 
   76    wxFileName projectFn( 
m_project ? 
m_project->AbsolutePath( expandedPath ) : expandedPath );
 
   78    if( projectFn.Exists() )
 
   79        return projectFn.GetFullPath();
 
   81    wxFileName spiceLibFn( expandedPath );
 
   84    wxGetEnv( wxT( 
"SPICE_LIB_DIR" ), &spiceLibDir );
 
   86    if( !spiceLibDir.IsEmpty() && spiceLibFn.MakeAbsolute( spiceLibDir ) && spiceLibFn.Exists() )
 
   87        return spiceLibFn.GetFullPath();
 
   89    if( spiceLibDir.IsEmpty() || spiceLibFn.GetFullPath() == projectFn.GetFullPath() )
 
   91        aReporter.
Report( wxString::Format( 
_( 
"Simulation model library not found at '%s'" ),
 
   92                                            projectFn.GetFullPath() ) );
 
   96        aReporter.
Report( wxString::Format( 
_( 
"Simulation model library not found at '%s' or '%s'" ),
 
   97                                            projectFn.GetFullPath(),
 
   98                                            spiceLibFn.GetFullPath() ) );
 
 
  106                                                  const wxString& aRelativeLib,
 
  109    wxFileName testPath( aLibPath );
 
  110    wxString fullPath( aLibPath );
 
  112    if( !testPath.IsAbsolute() && !aRelativeLib.empty() )
 
  114        wxString relLib( aRelativeLib );
 
  118        wxFileName fn( relLib );
 
  120        testPath.MakeAbsolute( fn.GetPath( 
true ) );
 
  121        fullPath = testPath.GetFullPath();
 
  124    wxFileName fn( fullPath );
 
 
  142    if( !wxFileName::Exists( 
path ) )
 
  144        aReporter.
Report( wxString::Format( 
_( 
"Simulation model library not found at '%s'" ),
 
  150            [&]( 
const wxString& libPath, 
const wxString& relativeLib ) -> wxString
 
 
  169                                     const std::vector<SCH_PIN*>& aPins, 
REPORTER& aReporter )
 
 
  177                                     const std::vector<SCH_FIELD>& aFields, 
bool aResolve, 
int aDepth,
 
 
  185                                             bool aResolve, 
int aDepth, 
REPORTER& aReporter )
 
  194    std::vector<SCH_FIELD> fields;
 
  200            fields.emplace_back( &aSymbol, 
FIELD_T::USER, field.GetName() );
 
  201            fields.back().SetText( aSymbol.
GetRef( aSheetPath ) );
 
  203        else if( field.GetId() == 
FIELD_T::VALUE || field.GetName().StartsWith( wxS( 
"Sim." ) ) )
 
  205            fields.emplace_back( &aSymbol, 
FIELD_T::USER, field.GetName() );
 
  206            fields.back().SetText( field.GetShownText( aSheetPath, 
false, aDepth ) );
 
  210    auto getOrCreateField =
 
  215                    if( field.GetName().IsSameAs( 
name ) )
 
  220                return &fields.back();
 
  225    wxString modelParams;
 
  227    bool     storeInValue = 
false;
 
  231                                  &deviceType, &modelType, &modelParams, &pinMap ) )
 
  235        if( !modelType.IsEmpty() )
 
  246    std::sort( sourcePins.begin(), sourcePins.end(),
 
  249                   return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
 
 
  261                                             bool aResolve, 
int aDepth,
 
  262                                             const std::vector<SCH_PIN*>& aPins,
 
  268    if( libraryPath != 
"" )
 
  270        return CreateModel( libraryPath, baseModelName, aFields, aResolve, aDepth, aPins, aReporter );
 
  275        return { baseModelName, *
m_models.back() };
 
 
  281                                             const std::string& aBaseModelName,
 
  282                                             const std::vector<SCH_FIELD>& aFields,
 
  283                                             bool aResolve, 
int aDepth,
 
  284                                             const std::vector<SCH_PIN*>& aPins,
 
  290    std::string  modelName;
 
  298                [&]( 
const wxString& libPath, 
const wxString& relativeLib ) -> wxString
 
  306    if( aBaseModelName == 
"" )
 
  308        msg.Printf( 
_( 
"Error loading simulation model: no '%s' field" ),
 
  313        modelName = 
_( 
"unknown" ).ToStdString();
 
  317        baseModel = 
library->FindModel( aBaseModelName );
 
  318        modelName = aBaseModelName;
 
  322            msg.Printf( 
_( 
"Error loading simulation model: could not find base model '%s' " 
  333    return { modelName, *
m_models.back() };
 
 
  339    m_models.at( aIndex ) = std::move( aModel );
 
 
  345    std::map<wxString, std::reference_wrapper<const SIM_LIBRARY>> libraries;
 
 
  356    std::vector<std::reference_wrapper<SIM_MODEL>> models;
 
  358    for( 
const std::unique_ptr<SIM_MODEL>& model : 
m_models )
 
  359        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)
 
void SetIsStoredInValue(bool aIsStoredInValue)
 
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".