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) |
Sets 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, const EMBEDDED_FILES *aEmbeddedFiles) |
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, const EMBEDDED_FILES *aEmbeddedFiles) |
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, const EMBEDDED_FILES *aEmbeddedFiles=nullptr) |
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 |
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 54 of file 3d_cache.h.
S3D_CACHE::S3D_CACHE | ( | ) |
Definition at line 126 of file 3d_cache.cpp.
References m_FNResolver, m_Plugins, and m_project.
|
virtual |
Definition at line 134 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 220 of file 3d_cache.cpp.
References S3D_CACHE_ENTRY::GetCacheBaseName(), ADVANCED_CFG::GetCfg(), getHash(), 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::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 576 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 542 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 523 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 517 of file 3d_cache.cpp.
References S3D_PLUGIN_MANAGER::GetFileFilters(), and m_Plugins.
Referenced by DIALOG_SELECT_3DMODEL::DIALOG_SELECT_3DMODEL().
|
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 287 of file 3d_cache.cpp.
References MMH3_HASH::add(), MMH3_HASH::digest(), and MASK_3D_CACHE.
Referenced by checkCache(), and load().
S3DMODEL * S3D_CACHE::GetModel | ( | const wxString & | aModelFileName, |
const wxString & | aBasePath, | ||
const EMBEDDED_FILES * | aEmbeddedFiles | ||
) |
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. |
aEmbeddedFiles | is a pointer to the embedded files list. |
Definition at line 549 of file 3d_cache.cpp.
References S3D::GetModel(), load(), MASK_3D_CACHE, and S3D_CACHE_ENTRY::renderData.
Referenced by RENDER_3D_RAYTRACE_BASE::load3DModels(), RENDER_3D_OPENGL::load3dModels(), and EDA_3D_MODEL_VIEWER::Set3DModel().
|
noexcept |
Definition at line 511 of file 3d_cache.cpp.
References m_FNResolver.
Referenced by PCB_EDIT_FRAME::Export_IDF3(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), PROJECT_PCB::Get3DFilenameResolver(), PANEL_FP_PROPERTIES_3D_MODEL::On3DModelCellChanged(), PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel(), PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), and PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint().
SCENEGRAPH * S3D_CACHE::Load | ( | const wxString & | aModelFile, |
const wxString & | aBasePath, | ||
const EMBEDDED_FILES * | aEmbeddedFiles | ||
) |
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 |
aEmbeddedFiles | is a pointer to the embedded files list. |
Definition at line 214 of file 3d_cache.cpp.
References load().
Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint().
|
private |
Definition at line 143 of file 3d_cache.cpp.
References checkCache(), S3D::Destroy3DModel(), S3D::DestroyNode(), ADVANCED_CFG::GetCfg(), getHash(), S3D_PLUGIN_MANAGER::Load3DModel(), m_CacheMap, m_FNResolver, m_Plugins, ADVANCED_CFG::m_Skip3DModelMemoryCache, MASK_3D_CACHE, mutex3D_cache, reload, FILENAME_RESOLVER::ResolvePath(), and S3D_CACHE_ENTRY::sceneData.
Referenced by GetModel(), and Load().
|
private |
Definition at line 319 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 359 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 413 of file 3d_cache.cpp.
References ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, PATHS::GetUserCachePath(), m_CacheDir, m_ConfigDir, m_FNResolver, m_project, MASK_3D_CACHE, and FILENAME_RESOLVER::Set3DConfigDir().
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 505 of file 3d_cache.cpp.
References m_FNResolver, and FILENAME_RESOLVER::SetProgramBase().
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 477 of file 3d_cache.cpp.
References m_CacheList, m_CacheMap, m_FNResolver, m_project, and FILENAME_RESOLVER::SetProject().
Referenced by PROJECT_PCB::Get3DCacheManager().
|
private |
Definition at line 188 of file 3d_cache.h.
Referenced by checkCache(), CleanCacheDir(), loadCacheData(), saveCacheData(), and Set3DConfigDir().
|
private |
cache entries
Definition at line 178 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), and SetProject().
|
private |
mapping of file names to cache names and data
Definition at line 181 of file 3d_cache.h.
Referenced by checkCache(), FlushCache(), load(), and SetProject().
|
private |
Definition at line 189 of file 3d_cache.h.
Referenced by Set3DConfigDir().
|
private |
Definition at line 183 of file 3d_cache.h.
Referenced by GetResolver(), load(), S3D_CACHE(), Set3DConfigDir(), SetProgramBase(), SetProject(), and ~S3D_CACHE().
|
private |
Definition at line 185 of file 3d_cache.h.
Referenced by checkCache(), ClosePlugins(), GetFileFilters(), load(), loadCacheData(), S3D_CACHE(), and ~S3D_CACHE().
|
private |
Definition at line 187 of file 3d_cache.h.
Referenced by S3D_CACHE(), Set3DConfigDir(), and SetProject().