|
KiCad PCB EDA Suite
|
Cache for storing the 3D shapes. More...
#include <3d_cache.h>
Public Member Functions | |
| S3D_CACHE () | |
| virtual | ~S3D_CACHE () |
| PROJECT::ELEM | ProjectElementType () noexcept override |
| bool | Set3DConfigDir (const wxString &aConfigDir) |
| Set the configuration directory to be used by the model manager for storing 3D model manager configuration data and the model cache. | |
| bool | SetProject (PROJECT *aProject) |
| Set the current project's working directory; this affects the model search path. | |
| void | SetProgramBase (PGM_BASE *aBase) |
| Set the filename resolver's pointer to the application's PGM_BASE instance. | |
| SCENEGRAPH * | Load (const wxString &aModelFile, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack) |
| Attempt to load the scene data for a model. | |
| FILENAME_RESOLVER * | GetResolver () noexcept |
| std::list< wxString > const * | GetFileFilters () const |
| Return the list of file filters retrieved from the plugins. | |
| void | FlushCache (bool closePlugins=true) |
| Free all data in the cache and by default closes all plugins. | |
| void | ClosePlugins () |
| Unload plugins to free memory. | |
| S3DMODEL * | GetModel (const wxString &aModelFileName, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack) |
| Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for display by a renderer. | |
| void | CleanCacheDir (int aNumDaysOld) |
| Delete up old cache files in cache directory. | |
Private Member Functions | |
| SCENEGRAPH * | checkCache (const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=nullptr) |
| Find or create cache entry for file name. | |
| bool | getHash (const wxString &aFileName, HASH_128 &aHash) |
| Calculate the SHA1 hash of the given file. | |
| bool | loadCacheData (S3D_CACHE_ENTRY *aCacheItem) |
| bool | saveCacheData (S3D_CACHE_ENTRY *aCacheItem) |
| SCENEGRAPH * | load (const wxString &aModelFile, const wxString &aBasePath, S3D_CACHE_ENTRY **aCachePtr=nullptr, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack={}) |
Private Attributes | |
| std::list< S3D_CACHE_ENTRY * > | m_CacheList |
| Cache entries. | |
| std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > | m_CacheMap |
| Mapping of file names to cache names and data. | |
| FILENAME_RESOLVER * | m_FNResolver |
| S3D_PLUGIN_MANAGER * | m_Plugins |
| PROJECT * | m_project |
| wxString | m_CacheDir |
| wxString | m_ConfigDir |
| base configuration path for 3D items. | |
| std::mutex | m_substCatalogMutex |
| Lazy STEP-catalog used by the headless resolver fallback in load(). | |
| bool | m_substCatalogBuilt = false |
| MODEL_SUBSTITUTION::STEP_CATALOG | m_substCatalog |
Cache for storing the 3D shapes.
This cache is able to be stored as a project element (since it inherits from PROJECT::_ELEM).
Definition at line 56 of file 3d_cache.h.
| S3D_CACHE::S3D_CACHE | ( | ) |
Definition at line 127 of file 3d_cache.cpp.
References m_FNResolver, m_Plugins, and m_project.
|
virtual |
Definition at line 135 of file 3d_cache.cpp.
References FlushCache(), m_FNResolver, and m_Plugins.
|
private |
Find or create cache entry for file name.
Searches the cache list for the given filename and retrieves the cache data; a cache entry is created if one does not already exist.
| aFileName | is the file name (full or partial path). |
| aCachePtr | is an optional return address for cache entry pointer. |
Definition at line 254 of file 3d_cache.cpp.
References S3D_CACHE_ENTRY::GetCacheBaseName(), ADVANCED_CFG::GetCfg(), getHash(), loadCacheData(), m_CacheDir, m_CacheList, m_CacheMap, m_Plugins, MASK_3D_CACHE, S3D_CACHE_ENTRY::modTime, S3D_CACHE_ENTRY::pluginInfo, saveCacheData(), S3D_CACHE_ENTRY::sceneData, and S3D_CACHE_ENTRY::SetHash().
Referenced by load().
| void S3D_CACHE::CleanCacheDir | ( | int | aNumDaysOld | ) |
Delete up old cache files in cache directory.
Deletes ".3dc" files in the cache directory that are older than aNumDaysOld.
| aNumDaysOld | is age threshold to delete ".3dc" cache files. |
Definition at line 610 of file 3d_cache.cpp.
References m_CacheDir.
Referenced by PROJECT_PCB::Cleanup3DCache().
| void S3D_CACHE::ClosePlugins | ( | ) |
Unload plugins to free memory.
Definition at line 576 of file 3d_cache.cpp.
References m_Plugins.
Referenced by FlushCache().
| void S3D_CACHE::FlushCache | ( | bool | closePlugins = true | ) |
Free all data in the cache and by default closes all plugins.
Definition at line 557 of file 3d_cache.cpp.
References ClosePlugins(), m_CacheList, and m_CacheMap.
Referenced by DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES(), PANEL_FP_PROPERTIES_3D_MODEL::~PANEL_FP_PROPERTIES_3D_MODEL(), and ~S3D_CACHE().
| std::list< wxString > const * S3D_CACHE::GetFileFilters | ( | ) | const |
Return the list of file filters retrieved from the plugins.
This will contain at least the default "All Files (*.*)|*.*"
Definition at line 551 of file 3d_cache.cpp.
References m_Plugins.
|
private |
Calculate the SHA1 hash of the given file.
| aFileName | file name (full path). |
| aHash | a 128 bit hash to hold the hash. |
Definition at line 321 of file 3d_cache.cpp.
References MMH3_HASH::add(), MMH3_HASH::digest(), L, and MASK_3D_CACHE.
Referenced by checkCache(), and load().
| S3DMODEL * S3D_CACHE::GetModel | ( | const wxString & | aModelFileName, |
| const wxString & | aBasePath, | ||
| std::vector< const EMBEDDED_FILES * > | aEmbeddedFilesStack ) |
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for display by a renderer.
| aModelFileName | is the full path to the model to be loaded. |
| aBasePath | is the path to search for any relative files. |
| aEmbeddedFilesStack | is a stack of pointers to the embedded files lists. They will be searched from the bottom of the stack. |
Definition at line 583 of file 3d_cache.cpp.
References S3D::GetModel(), load(), MASK_3D_CACHE, and S3D_CACHE_ENTRY::renderData.
Referenced by RENDER_3D_RAYTRACE_BASE::load3DModels(), and RENDER_3D_OPENGL::load3dModels().
|
noexcept |
Definition at line 545 of file 3d_cache.cpp.
References m_FNResolver.
Referenced by PANEL_FP_PROPERTIES_3D_MODEL::cleanupFilename(), PCB_CONTROL::CollectAndEmbed3DModels(), PCB_EDIT_FRAME::Export_IDF3(), PROJECT_PCB::Get3DFilenameResolver(), PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel(), and PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint().
| SCENEGRAPH * S3D_CACHE::Load | ( | const wxString & | aModelFile, |
| const wxString & | aBasePath, | ||
| std::vector< const EMBEDDED_FILES * > | aEmbeddedFilesStack ) |
Attempt to load the scene data for a model.
It will consult the internal cache list and load from cache if possible before invoking the load() function of the available plugins. The model may fail to load if, for example, the plugin does not support rendering of the 3D model.
| aModelFile | is the partial or full path to the model to be loaded. |
| aBasePath | is the path to search for any relative files |
| aEmbeddedFilesStack | is a list of pointers to the embedded files list. They will be searched from the front of the list. |
Definition at line 247 of file 3d_cache.cpp.
References load().
|
private |
Definition at line 144 of file 3d_cache.cpp.
References checkCache(), S3D::Destroy3DModel(), S3D::DestroyNode(), ADVANCED_CFG::GetCfg(), getHash(), MODEL_SUBSTITUTION::IsWrlExtension(), m_CacheMap, m_FNResolver, m_Plugins, m_project, ADVANCED_CFG::m_Skip3DModelMemoryCache, m_substCatalog, m_substCatalogBuilt, m_substCatalogMutex, MASK_3D_CACHE, mutex3D_cache, Pgm(), and reload.
Referenced by GetModel(), and Load().
|
private |
Definition at line 353 of file 3d_cache.cpp.
References checkTag(), S3D::DestroyNode(), S3D_CACHE_ENTRY::GetCacheBaseName(), m_CacheDir, m_Plugins, MASK_3D_CACHE, S3D::ReadCache(), and S3D_CACHE_ENTRY::sceneData.
Referenced by checkCache().
|
inlineoverridevirtualnoexcept |
|
private |
Definition at line 393 of file 3d_cache.cpp.
References S3D_CACHE_ENTRY::GetCacheBaseName(), m_CacheDir, MASK_3D_CACHE, S3D_CACHE_ENTRY::pluginInfo, S3D_CACHE_ENTRY::sceneData, and S3D::WriteCache().
Referenced by checkCache().
| bool S3D_CACHE::Set3DConfigDir | ( | const wxString & | aConfigDir | ) |
Set the configuration directory to be used by the model manager for storing 3D model manager configuration data and the model cache.
The config directory may only be set once in the lifetime of the object.
| aConfigDir | is the configuration directory to use for 3D model manager data |
Definition at line 447 of file 3d_cache.cpp.
References ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, PATHS::GetUserCachePath(), m_CacheDir, m_ConfigDir, m_FNResolver, m_project, and MASK_3D_CACHE.
Referenced by PROJECT_PCB::Get3DCacheManager().
| void S3D_CACHE::SetProgramBase | ( | PGM_BASE * | aBase | ) |
Set the filename resolver's pointer to the application's PGM_BASE instance.
The pointer is used to extract the local environment variables.
Definition at line 539 of file 3d_cache.cpp.
References m_FNResolver.
Referenced by PROJECT_PCB::Get3DCacheManager().
| bool S3D_CACHE::SetProject | ( | PROJECT * | aProject | ) |
Set the current project's working directory; this affects the model search path.
Definition at line 511 of file 3d_cache.cpp.
References m_CacheList, m_CacheMap, m_FNResolver, and m_project.
Referenced by PROJECT_PCB::Get3DCacheManager().
|
private |
Definition at line 194 of file 3d_cache.h.
Referenced by checkCache(), CleanCacheDir(), loadCacheData(), saveCacheData(), and Set3DConfigDir().
|
private |
Cache entries.
Definition at line 184 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), and SetProject().
|
private |
Mapping of file names to cache names and data.
Definition at line 187 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), load(), and SetProject().
|
private |
base configuration path for 3D items.
Definition at line 195 of file 3d_cache.h.
Referenced by Set3DConfigDir().
|
private |
Definition at line 189 of file 3d_cache.h.
Referenced by GetResolver(), load(), S3D_CACHE(), Set3DConfigDir(), SetProgramBase(), SetProject(), and ~S3D_CACHE().
|
private |
Definition at line 191 of file 3d_cache.h.
Referenced by checkCache(), ClosePlugins(), GetFileFilters(), load(), loadCacheData(), S3D_CACHE(), and ~S3D_CACHE().
|
private |
Definition at line 193 of file 3d_cache.h.
Referenced by load(), S3D_CACHE(), Set3DConfigDir(), and SetProject().
|
mutableprivate |
Definition at line 202 of file 3d_cache.h.
Referenced by load().
|
mutableprivate |
Definition at line 201 of file 3d_cache.h.
Referenced by load().
|
mutableprivate |
Lazy STEP-catalog used by the headless resolver fallback in load().
Built on first missing WRL and reused for the lifetime of the cache to avoid re-walking the 3D library tree for every missed lookup.
Definition at line 200 of file 3d_cache.h.
Referenced by load().