KiCad PCB EDA Suite
Loading...
Searching...
No Matches
S3D_CACHE Class Reference

Cache for storing the 3D shapes. More...

#include <3d_cache.h>

Inheritance diagram for S3D_CACHE:
PROJECT::_ELEM

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.
 
SCENEGRAPHLoad (const wxString &aModelFile, const wxString &aBasePath, const EMBEDDED_FILES *aEmbeddedFiles)
 Attempt to load the scene data for a model.
 
FILENAME_RESOLVERGetResolver () 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.
 
S3DMODELGetModel (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

SCENEGRAPHcheckCache (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)
 
SCENEGRAPHload (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_wxStringm_CacheMap
 mapping of file names to cache names and data
 
FILENAME_RESOLVERm_FNResolver
 
S3D_PLUGIN_MANAGERm_Plugins
 
PROJECTm_project
 
wxString m_CacheDir
 
wxString m_ConfigDir
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ S3D_CACHE()

S3D_CACHE::S3D_CACHE ( )

Definition at line 126 of file 3d_cache.cpp.

References m_FNResolver, m_Plugins, and m_project.

◆ ~S3D_CACHE()

S3D_CACHE::~S3D_CACHE ( )
virtual

Definition at line 134 of file 3d_cache.cpp.

References FlushCache(), m_FNResolver, and m_Plugins.

Member Function Documentation

◆ checkCache()

SCENEGRAPH * S3D_CACHE::checkCache ( const wxString &  aFileName,
S3D_CACHE_ENTRY **  aCachePtr = nullptr 
)
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.

Parameters
aFileNameis the file name (full or partial path).
aCachePtris an optional return address for cache entry pointer.
Returns
SCENEGRAPH object associated with file name or NULL on error.

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().

◆ CleanCacheDir()

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.

Parameters
aNumDaysOldis age threshold to delete ".3dc" cache files.

Definition at line 576 of file 3d_cache.cpp.

References m_CacheDir.

Referenced by PROJECT_PCB::Cleanup3DCache().

◆ ClosePlugins()

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().

◆ 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().

◆ GetFileFilters()

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 (*.*)|*.*"

Returns
a pointer to the filter list.

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().

◆ getHash()

bool S3D_CACHE::getHash ( const wxString &  aFileName,
HASH_128 aHash 
)
private

Calculate the SHA1 hash of the given file.

Parameters
aFileNamefile name (full path).
aHasha 128 bit hash to hold the hash.
Returns
true on success, otherwise false.

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().

◆ GetModel()

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.

Parameters
aModelFileNameis the full path to the model to be loaded.
aBasePathis the path to search for any relative files.
aEmbeddedFilesis a pointer to the embedded files list.
Returns
is a pointer to the render data or NULL if not available.

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().

◆ GetResolver()

◆ Load()

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.

Parameters
aModelFileis the partial or full path to the model to be loaded.
aBasePathis the path to search for any relative files
aEmbeddedFilesis a pointer to the embedded files list.
Returns
true if the model was successfully loaded, otherwise false.

Definition at line 214 of file 3d_cache.cpp.

References load().

Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint().

◆ load()

SCENEGRAPH * S3D_CACHE::load ( const wxString &  aModelFile,
const wxString &  aBasePath,
S3D_CACHE_ENTRY **  aCachePtr = nullptr,
const EMBEDDED_FILES aEmbeddedFiles = nullptr 
)
private

◆ loadCacheData()

bool S3D_CACHE::loadCacheData ( S3D_CACHE_ENTRY aCacheItem)
private

◆ ProjectElementType()

PROJECT::ELEM S3D_CACHE::ProjectElementType ( )
inlineoverridevirtualnoexcept

Implements PROJECT::_ELEM.

Definition at line 60 of file 3d_cache.h.

References PROJECT::S3DCACHE.

◆ saveCacheData()

bool S3D_CACHE::saveCacheData ( S3D_CACHE_ENTRY aCacheItem)
private

◆ Set3DConfigDir()

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.

Parameters
aConfigDiris the configuration directory to use for 3D model manager data
Returns
true on success

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().

◆ SetProgramBase()

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().

◆ SetProject()

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().

Member Data Documentation

◆ m_CacheDir

wxString S3D_CACHE::m_CacheDir
private

Definition at line 188 of file 3d_cache.h.

Referenced by checkCache(), CleanCacheDir(), loadCacheData(), saveCacheData(), and Set3DConfigDir().

◆ m_CacheList

std::list< S3D_CACHE_ENTRY* > S3D_CACHE::m_CacheList
private

cache entries

Definition at line 178 of file 3d_cache.h.

Referenced by checkCache(), FlushCache(), and SetProject().

◆ m_CacheMap

std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > S3D_CACHE::m_CacheMap
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().

◆ m_ConfigDir

wxString S3D_CACHE::m_ConfigDir
private

Definition at line 189 of file 3d_cache.h.

Referenced by Set3DConfigDir().

◆ m_FNResolver

FILENAME_RESOLVER* S3D_CACHE::m_FNResolver
private

◆ m_Plugins

S3D_PLUGIN_MANAGER* S3D_CACHE::m_Plugins
private

◆ m_project

PROJECT* S3D_CACHE::m_project
private

Definition at line 187 of file 3d_cache.h.

Referenced by S3D_CACHE(), Set3DConfigDir(), and SetProject().


The documentation for this class was generated from the following files: