![]() |
KiCad PCB EDA Suite
|
Cache for storing the 3D shapes. More...
#include <3d_cache.h>
Public Member Functions | |
S3D_CACHE () | |
virtual | ~S3D_CACHE () |
KICAD_T | Type () noexcept override |
bool | Set3DConfigDir (const wxString &aConfigDir) |
Sets the configuration directory to be used by the model manager for storing 3D model manager configuration data and the model cache. More... | |
bool | SetProject (PROJECT *aProject) |
Set the current project's working directory; this affects the model search path. More... | |
void | SetProgramBase (PGM_BASE *aBase) |
Set the filename resolver's pointer to the application's PGM_BASE instance. More... | |
SCENEGRAPH * | Load (const wxString &aModelFile) |
Attempt to load the scene data for a model. More... | |
FILENAME_RESOLVER * | GetResolver () noexcept |
std::list< wxString > const * | GetFileFilters () const |
Return the list of file filters retrieved from the plugins. More... | |
void | FlushCache (bool closePlugins=true) |
Free all data in the cache and by default closes all plugins. More... | |
void | ClosePlugins () |
Unload plugins to free memory. More... | |
S3DMODEL * | GetModel (const wxString &aModelFileName) |
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for display by a renderer. More... | |
void | CleanCacheDir (int aNumDaysOld) |
Delete up old cache files in cache directory. More... | |
Private Member Functions | |
SCENEGRAPH * | checkCache (const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=nullptr) |
Find or create cache entry for file name. More... | |
bool | getSHA1 (const wxString &aFileName, unsigned char *aSHA1Sum) |
Calculate the SHA1 hash of the given file. More... | |
bool | loadCacheData (S3D_CACHE_ENTRY *aCacheItem) |
bool | saveCacheData (S3D_CACHE_ENTRY *aCacheItem) |
SCENEGRAPH * | load (const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=nullptr) |
Private Attributes | |
std::list< S3D_CACHE_ENTRY * > | m_CacheList |
cache entries More... | |
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > | m_CacheMap |
mapping of file names to cache names and data More... | |
FILENAME_RESOLVER * | m_FNResolver |
S3D_PLUGIN_MANAGER * | m_Plugins |
PROJECT * | m_project |
wxString | m_CacheDir |
wxString | m_ConfigDir |
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 52 of file 3d_cache.h.
S3D_CACHE::S3D_CACHE | ( | ) |
Definition at line 186 of file 3d_cache.cpp.
References m_FNResolver, m_Plugins, and m_project.
|
virtual |
Definition at line 194 of file 3d_cache.cpp.
References CleanCacheDir(), COMMON_SETTINGS::SYSTEM::clear_3d_cache_interval, FlushCache(), m_FNResolver, m_Plugins, COMMON_SETTINGS::m_System, and Pgm().
|
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 289 of file 3d_cache.cpp.
References S3D_CACHE_ENTRY::GetCacheBaseName(), getSHA1(), S3D_PLUGIN_MANAGER::Load3DModel(), 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::SetSHA1().
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 672 of file 3d_cache.cpp.
References m_CacheDir.
Referenced by ~S3D_CACHE().
void S3D_CACHE::ClosePlugins | ( | ) |
Unload plugins to free memory.
Definition at line 639 of file 3d_cache.cpp.
References S3D_PLUGIN_MANAGER::ClosePlugins(), and 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 620 of file 3d_cache.cpp.
References ClosePlugins(), m_CacheList, and m_CacheMap.
Referenced by ~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 614 of file 3d_cache.cpp.
References S3D_PLUGIN_MANAGER::GetFileFilters(), and m_Plugins.
Referenced by DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL().
S3DMODEL * S3D_CACHE::GetModel | ( | const wxString & | aModelFileName | ) |
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. |
Definition at line 646 of file 3d_cache.cpp.
References S3D::GetModel(), load(), MASK_3D_CACHE, and S3D_CACHE_ENTRY::renderData.
Referenced by RENDER_3D_LEGACY::load3dModels(), RENDER_3D_RAYTRACE::loadModels(), and C3D_MODEL_VIEWER::Set3DModel().
|
noexcept |
Definition at line 608 of file 3d_cache.cpp.
References m_FNResolver.
Referenced by DLG_SELECT_3DMODEL::DLG_SELECT_3DMODEL(), and EXPORTER_PCB_VRML::ExportVrmlFootprint().
|
private |
Calculate the SHA1 hash of the given file.
aFileName | file name (full path). |
aSHA1Sum | a 20 byte character array to hold the SHA1 hash. |
Definition at line 360 of file 3d_cache.cpp.
References MASK_3D_CACHE.
Referenced by checkCache(), and load().
SCENEGRAPH * S3D_CACHE::Load | ( | const wxString & | aModelFile | ) |
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. |
Definition at line 283 of file 3d_cache.cpp.
References load().
Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint().
|
private |
Definition at line 213 of file 3d_cache.cpp.
References checkCache(), S3D::Destroy3DModel(), S3D::DestroyNode(), getSHA1(), isSHA1Same(), S3D_PLUGIN_MANAGER::Load3DModel(), m_CacheMap, m_FNResolver, m_Plugins, MASK_3D_CACHE, mutex3D_cache, reload, FILENAME_RESOLVER::ResolvePath(), and S3D_CACHE_ENTRY::sceneData.
Referenced by GetModel(), and Load().
|
private |
Definition at line 416 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().
|
private |
Definition at line 457 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 | ) |
Sets 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 511 of file 3d_cache.cpp.
References ExpandEnvVarSubstitutions(), PATHS::GetUserCachePath(), m_CacheDir, m_ConfigDir, m_FNResolver, m_project, MASK_3D_CACHE, and FILENAME_RESOLVER::Set3DConfigDir().
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 602 of file 3d_cache.cpp.
References m_FNResolver, and FILENAME_RESOLVER::SetProgramBase().
bool S3D_CACHE::SetProject | ( | PROJECT * | aProject | ) |
Set the current project's working directory; this affects the model search path.
Definition at line 574 of file 3d_cache.cpp.
References m_CacheList, m_CacheMap, m_FNResolver, m_project, and FILENAME_RESOLVER::SetProject().
|
inlineoverridevirtualnoexcept |
|
private |
Definition at line 180 of file 3d_cache.h.
Referenced by checkCache(), CleanCacheDir(), loadCacheData(), saveCacheData(), and Set3DConfigDir().
|
private |
cache entries
Definition at line 170 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), and SetProject().
|
private |
mapping of file names to cache names and data
Definition at line 173 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), load(), and SetProject().
|
private |
Definition at line 181 of file 3d_cache.h.
Referenced by Set3DConfigDir().
|
private |
Definition at line 175 of file 3d_cache.h.
Referenced by GetResolver(), load(), S3D_CACHE(), Set3DConfigDir(), SetProgramBase(), SetProject(), and ~S3D_CACHE().
|
private |
Definition at line 177 of file 3d_cache.h.
Referenced by checkCache(), ClosePlugins(), GetFileFilters(), load(), loadCacheData(), S3D_CACHE(), and ~S3D_CACHE().
|
private |
Definition at line 179 of file 3d_cache.h.
Referenced by S3D_CACHE(), Set3DConfigDir(), and SetProject().