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 ()
 
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.
 
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)
 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)
 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 getSHA1 (const wxString &aFileName, unsigned char *aSHA1Sum)
 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)
 

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 52 of file 3d_cache.h.

Constructor & Destructor Documentation

◆ S3D_CACHE()

S3D_CACHE::S3D_CACHE ( )

Definition at line 187 of file 3d_cache.cpp.

References m_FNResolver, m_Plugins, and m_project.

◆ ~S3D_CACHE()

S3D_CACHE::~S3D_CACHE ( )
virtual

Definition at line 195 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 281 of file 3d_cache.cpp.

References S3D_CACHE_ENTRY::GetCacheBaseName(), ADVANCED_CFG::GetCfg(), 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().

◆ 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 660 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 627 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 608 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 602 of file 3d_cache.cpp.

References S3D_PLUGIN_MANAGER::GetFileFilters(), and m_Plugins.

Referenced by DIALOG_SELECT_3DMODEL::DIALOG_SELECT_3DMODEL().

◆ GetModel()

S3DMODEL * S3D_CACHE::GetModel ( const wxString &  aModelFileName,
const wxString &  aBasePath 
)

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.
Returns
is a pointer to the render data or NULL if not available.

Definition at line 634 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()

◆ getSHA1()

bool S3D_CACHE::getSHA1 ( const wxString &  aFileName,
unsigned char *  aSHA1Sum 
)
private

Calculate the SHA1 hash of the given file.

Parameters
aFileNamefile name (full path).
aSHA1Suma 20 byte character array to hold the SHA1 hash.
Returns
true on success, otherwise false.

Definition at line 348 of file 3d_cache.cpp.

References MASK_3D_CACHE.

Referenced by checkCache(), and load().

◆ Load()

SCENEGRAPH * S3D_CACHE::Load ( const wxString &  aModelFile,
const wxString &  aBasePath 
)

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
Returns
true if the model was successfully loaded, otherwise false.

Definition at line 275 of file 3d_cache.cpp.

References load().

Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint().

◆ load()

◆ loadCacheData()

bool S3D_CACHE::loadCacheData ( S3D_CACHE_ENTRY aCacheItem)
private

◆ 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 498 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 590 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 562 of file 3d_cache.cpp.

References m_CacheList, m_CacheMap, m_FNResolver, m_project, and FILENAME_RESOLVER::SetProject().

Referenced by PROJECT_PCB::Get3DCacheManager().

◆ Type()

KICAD_T S3D_CACHE::Type ( )
inlineoverridevirtualnoexcept

Implements PROJECT::_ELEM.

Definition at line 58 of file 3d_cache.h.

References S3D_CACHE_T.

Member Data Documentation

◆ m_CacheDir

wxString S3D_CACHE::m_CacheDir
private

Definition at line 181 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 171 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 174 of file 3d_cache.h.

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

◆ m_ConfigDir

wxString S3D_CACHE::m_ConfigDir
private

Definition at line 182 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 180 of file 3d_cache.h.

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


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