KiCad PCB EDA Suite
CACHE_WRAPPER Class Reference

#include <3d_cache_wrapper.h>

Inheritance diagram for CACHE_WRAPPER:
S3D_CACHE PROJECT::_ELEM

Public Member Functions

KICAD_T Type () override
 
 CACHE_WRAPPER ()
 
virtual ~CACHE_WRAPPER ()
 
bool Set3DConfigDir (const wxString &aConfigDir)
 Function Set3DConfigDir Sets the configuration directory to be used by the model manager for storing 3D model manager configuration data and the model cache. More...
 
wxString Get3DConfigDir (bool createDefault=false)
 Function Get3DConfigDir returns the current 3D configuration directory on success, otherwise it returns wxEmptyString. More...
 
bool SetProjectDir (const wxString &aProjDir)
 Function SetProjectDir sets the current project's working directory; this affects the model search path. More...
 
void SetProgramBase (PGM_BASE *aBase)
 Function SetProgramBase sets the filename resolver's pointer to the application's PGM_BASE instance; the pointer is used to extract the local env vars. More...
 
wxString GetProjectDir (void)
 Function GetProjectDir returns the current project's working directory. More...
 
SCENEGRAPHLoad (const wxString &aModelFile)
 Function Load attempts 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. More...
 
FILENAME_RESOLVERGetResolver (void)
 
std::list< wxString > const * GetFileFilters (void) const
 Function GetFileFilters returns the list of file filters retrieved from the plugins; this will contain at least the default "All Files (*.*)|*.*". More...
 
void FlushCache (bool closePlugins=true)
 Function FlushCache frees all data in the cache and by default closes all plugins. More...
 
void ClosePlugins (void)
 Function ClosePlugins unloads plugins to free memory. More...
 
S3DMODELGetModel (const wxString &aModelFileName)
 Function GetModel attempts to load the scene data for a model and to translate it into an S3D_MODEL structure for display by a renderer. More...
 
wxString GetModelHash (const wxString &aModelFileName)
 

Detailed Description

Definition at line 30 of file 3d_cache_wrapper.h.

Constructor & Destructor Documentation

CACHE_WRAPPER::CACHE_WRAPPER ( )

Definition at line 31 of file 3d_cache_wrapper.cpp.

Referenced by Type(), and ~CACHE_WRAPPER().

32 {
33  return;
34 }
CACHE_WRAPPER::~CACHE_WRAPPER ( )
virtual

Member Function Documentation

void S3D_CACHE::ClosePlugins ( void  )
inherited

Function ClosePlugins unloads plugins to free memory.

Definition at line 716 of file 3d_cache.cpp.

717 {
718  if( NULL != m_Plugins )
720 
721  return;
722 }
void ClosePlugins(void)
Function ClosePlugins iterates through all discovered plugins and closes them to reclaim memory...
S3D_PLUGIN_MANAGER * m_Plugins
plugin manager
Definition: 3d_cache.h:62
void S3D_CACHE::FlushCache ( bool  closePlugins = true)
inherited

Function FlushCache frees all data in the cache and by default closes all plugins.

Definition at line 695 of file 3d_cache.cpp.

696 {
697  std::list< S3D_CACHE_ENTRY* >::iterator sCL = m_CacheList.begin();
698  std::list< S3D_CACHE_ENTRY* >::iterator eCL = m_CacheList.end();
699 
700  while( sCL != eCL )
701  {
702  delete *sCL;
703  ++sCL;
704  }
705 
706  m_CacheList.clear();
707  m_CacheMap.clear();
708 
709  if( closePlugins )
710  ClosePlugins();
711 
712  return;
713 }
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:56
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:53
void ClosePlugins(void)
Function ClosePlugins unloads plugins to free memory.
Definition: 3d_cache.cpp:716
wxString S3D_CACHE::Get3DConfigDir ( bool  createDefault = false)
inherited

Function Get3DConfigDir returns the current 3D configuration directory on success, otherwise it returns wxEmptyString.

If the directory was not previously set via Set3DConfigDir() then a default is used which is based on kicad's configuration directory code as of September 2015.

Definition at line 589 of file 3d_cache.cpp.

References ExpandEnvVarSubstitutions(), and MASK_3D_CACHE.

590 {
591  if( !m_ConfigDir.empty() || !createDefault )
592  return m_ConfigDir;
593 
594  // note: duplicated from common/common.cpp GetKicadConfigPath() to avoid
595  // code coupling; ideally the instantiating code should call
596  // Set3DConfigDir() to set the directory rather than relying on this
597  // directory remaining the same in future KiCad releases.
598  wxFileName cfgpath;
599 
600  // From the wxWidgets wxStandardPaths::GetUserConfigDir() help:
601  // Unix: ~ (the home directory)
602  // Windows: "C:\Documents and Settings\username\Application Data"
603  // Mac: ~/Library/Preferences
604  cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
605 
606 #if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
607  wxString envstr = ExpandEnvVarSubstitutions( "${XDG_CONFIG_HOME}" );
608 
609  if( envstr.IsEmpty() || envstr == "${XDG_CONFIG_HOME}" )
610  {
611  // XDG_CONFIG_HOME is not set, so use the fallback
612  cfgpath.AppendDir( wxT( ".config" ) );
613  }
614  else
615  {
616  // Override the assignment above with XDG_CONFIG_HOME
617  cfgpath.AssignDir( envstr );
618  }
619 #endif
620 
621  cfgpath.AppendDir( wxT( "kicad" ) );
622  cfgpath.AppendDir( wxT( "3d" ) );
623 
624  if( !cfgpath.DirExists() )
625  {
626  cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
627  }
628 
629  if( !cfgpath.DirExists() )
630  {
631  wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * failed to create 3D configuration directory '%s'",
632  __FILE__, __FUNCTION__, __LINE__, cfgpath.GetPath() );
633 
634  return wxT( "" );
635  }
636 
637  if( Set3DConfigDir( cfgpath.GetPath() ) )
638  return m_ConfigDir;
639 
640  return wxEmptyString;
641 }
#define MASK_3D_CACHE
Definition: 3d_cache.cpp:58
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:417
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir Sets the configuration directory to be used by the model manager for storing ...
Definition: 3d_cache.cpp:505
wxString m_ConfigDir
base configuration path for 3D items
Definition: 3d_cache.h:71
std::list< wxString > const * S3D_CACHE::GetFileFilters ( void  ) const
inherited

Function GetFileFilters returns 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 689 of file 3d_cache.cpp.

690 {
691  return m_Plugins->GetFileFilters();
692 }
std::list< wxString > const * GetFileFilters(void) const
Function GetFileFilters returns the list of file filters; this will contain at least the default "All...
S3D_PLUGIN_MANAGER * m_Plugins
plugin manager
Definition: 3d_cache.h:62
S3DMODEL * S3D_CACHE::GetModel ( const wxString &  aModelFileName)
inherited

Function GetModel attempts 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 725 of file 3d_cache.cpp.

References S3D::GetModel(), MASK_3D_CACHE, and S3D_CACHE_ENTRY::renderData.

Referenced by C3D_RENDER_OGL_LEGACY::load_3D_models(), C3D_RENDER_RAYTRACING::load_3D_models(), and C3D_MODEL_VIEWER::Set3DModel().

726 {
727  S3D_CACHE_ENTRY* cp = NULL;
728  SCENEGRAPH* sp = load( aModelFileName, &cp );
729 
730  if( !sp )
731  return NULL;
732 
733  if( !cp )
734  {
735  wxLogTrace( MASK_3D_CACHE,
736  "%s:%s:%d\n * [BUG] model loaded with no associated S3D_CACHE_ENTRY",
737  __FILE__, __FUNCTION__, __LINE__ );
738 
739  return NULL;
740  }
741 
742  if( cp->renderData )
743  return cp->renderData;
744 
745  S3DMODEL* mp = S3D::GetModel( sp );
746  cp->renderData = mp;
747 
748  return mp;
749 }
#define MASK_3D_CACHE
Definition: 3d_cache.cpp:58
SCENEGRAPH * load(const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=NULL)
Definition: 3d_cache.cpp:208
S3DMODEL * renderData
Definition: 3d_cache.cpp:138
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
Definition: 3d_cache.cpp:118
SGLIB_API S3DMODEL * GetModel(SCENEGRAPH *aNode)
Function GetModel creates an S3DMODEL representation of aNode (raw data, no transforms) ...
Definition: ifsg_api.cpp:471
wxString S3D_CACHE::GetModelHash ( const wxString &  aModelFileName)
inherited

Definition at line 752 of file 3d_cache.cpp.

References S3D_CACHE_ENTRY::GetCacheBaseName().

753 {
754  wxString full3Dpath = m_FNResolver->ResolvePath( aModelFileName );
755 
756  if( full3Dpath.empty() || !wxFileName::FileExists( full3Dpath ) )
757  return wxEmptyString;
758 
759  // check cache if file is already loaded
760  std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString >::iterator mi;
761  mi = m_CacheMap.find( full3Dpath );
762 
763  if( mi != m_CacheMap.end() )
764  return mi->second->GetCacheBaseName();
765 
766  // a cache item does not exist; search the Filename->Cachename map
767  S3D_CACHE_ENTRY* cp = NULL;
768  checkCache( full3Dpath, &cp );
769 
770  if( NULL != cp )
771  return cp->GetCacheBaseName();
772 
773  return wxEmptyString;
774 }
const wxString GetCacheBaseName(void)
Definition: 3d_cache.cpp:175
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:56
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
SCENEGRAPH * checkCache(const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=NULL)
Find or create cache entry for file name.
Definition: 3d_cache.cpp:282
wxString ResolvePath(const wxString &aFileName)
Function ResolvePath determines the full path of the given file name.
Definition: 3d_cache.cpp:118
wxString S3D_CACHE::GetProjectDir ( void  )
inherited

Function GetProjectDir returns the current project's working directory.

Definition at line 677 of file 3d_cache.cpp.

678 {
679  return m_FNResolver->GetProjectDir();
680 }
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
wxString GetProjectDir(void)
FILENAME_RESOLVER * S3D_CACHE::GetResolver ( void  )
inherited

Definition at line 683 of file 3d_cache.cpp.

Referenced by export_vrml_module().

684 {
685  return m_FNResolver;
686 }
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
SCENEGRAPH * S3D_CACHE::Load ( const wxString &  aModelFile)
inherited

Function Load attempts 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.

Parameters
aModelFile[in] is the partial or full path to the model to be loaded
Returns
true if the model was successfully loaded, otherwise false. The model may fail to load if, for example, the plugin does not support rendering of the 3D model.

Definition at line 276 of file 3d_cache.cpp.

Referenced by export_vrml_module().

277 {
278  return load( aModelFile );
279 }
SCENEGRAPH * load(const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=NULL)
Definition: 3d_cache.cpp:208
bool S3D_CACHE::Set3DConfigDir ( const wxString &  aConfigDir)
inherited

Function Set3DConfigDir 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 505 of file 3d_cache.cpp.

References ExpandEnvVarSubstitutions(), and MASK_3D_CACHE.

Referenced by ~CACHE_WRAPPER().

506 {
507  if( !m_ConfigDir.empty() )
508  return false;
509 
510  wxFileName cfgdir;
511 
512  if( aConfigDir.StartsWith( "${" ) || aConfigDir.StartsWith( "$(" ) )
513  cfgdir.Assign( ExpandEnvVarSubstitutions( aConfigDir ), "" );
514  else
515  cfgdir.Assign( aConfigDir, "" );
516 
517  cfgdir.Normalize();
518 
519  if( !cfgdir.DirExists() )
520  {
521  cfgdir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
522 
523  if( !cfgdir.DirExists() )
524  {
525  wxLogTrace( MASK_3D_CACHE,
526  "%s:%s:%d\n * failed to create 3D configuration directory '%s'",
527  __FILE__, __FUNCTION__, __LINE__, cfgdir.GetPath() );
528 
529  return false;
530  }
531  }
532 
533  m_ConfigDir = cfgdir.GetPath();
534 
535  // inform the file resolver of the config directory
537  {
538  wxLogTrace( MASK_3D_CACHE,
539  "%s:%s:%d\n * could not set 3D Config Directory on filename resolver\n"
540  " * config directory: '%s'",
541  __FILE__, __FUNCTION__, __LINE__, m_ConfigDir );
542  }
543 
544  // 3D cache data must go to a user's cache directory;
545  // unfortunately wxWidgets doesn't seem to provide
546  // functions to retrieve such a directory.
547  //
548  // 1. OSX: ~/Library/Caches/kicad/3d/
549  // 2. Linux: ${XDG_CACHE_HOME}/kicad/3d ~/.cache/kicad/3d/
550  // 3. MSWin: AppData\Local\kicad\3d
551  wxString cacheDir;
552 
553 #if defined(_WIN32)
554  wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
555  cacheDir = wxStandardPaths::Get().GetUserLocalDataDir();
556  cacheDir.append( "\\kicad\\3d" );
557 #elif defined(__APPLE)
558  cacheDir = "${HOME}/Library/Caches/kicad/3d";
559 #else // assume Linux
560  cacheDir = ExpandEnvVarSubstitutions( "${XDG_CACHE_HOME}" );
561 
562  if( cacheDir.empty() || cacheDir == "${XDG_CACHE_HOME}" )
563  cacheDir = "${HOME}/.cache";
564 
565  cacheDir.append( "/kicad/3d" );
566 #endif
567 
568  cacheDir = ExpandEnvVarSubstitutions( cacheDir );
569  cfgdir.Assign( cacheDir, "" );
570 
571  if( !cfgdir.DirExists() )
572  {
573  cfgdir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
574 
575  if( !cfgdir.DirExists() )
576  {
577  wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * failed to create 3D cache directory '%s'",
578  __FILE__, __FUNCTION__, __LINE__, cfgdir.GetPath() );
579 
580  return false;
581  }
582  }
583 
584  m_CacheDir = cfgdir.GetPathWithSep();
585  return true;
586 }
#define MASK_3D_CACHE
Definition: 3d_cache.cpp:58
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
const wxString ExpandEnvVarSubstitutions(const wxString &aString)
Replace any environment variable references with their values.
Definition: common.cpp:417
wxString m_CacheDir
3D cache directory
Definition: 3d_cache.h:68
wxString m_ConfigDir
base configuration path for 3D items
Definition: 3d_cache.h:71
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir sets the user&#39;s configuration directory for 3D models.
void S3D_CACHE::SetProgramBase ( PGM_BASE aBase)
inherited

Function SetProgramBase sets the filename resolver's pointer to the application's PGM_BASE instance; the pointer is used to extract the local env vars.

Definition at line 670 of file 3d_cache.cpp.

Referenced by ~CACHE_WRAPPER().

671 {
672  m_FNResolver->SetProgramBase( aBase );
673  return;
674 }
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
void SetProgramBase(PGM_BASE *aBase)
Function SetProgramBase sets a pointer to the application&#39;s PGM_BASE instance; the pointer is used to...
bool S3D_CACHE::SetProjectDir ( const wxString &  aProjDir)
inherited

Function SetProjectDir sets the current project's working directory; this affects the model search path.

Definition at line 644 of file 3d_cache.cpp.

Referenced by ~CACHE_WRAPPER().

645 {
646  bool hasChanged = false;
647 
648  if( m_FNResolver->SetProjectDir( aProjDir, &hasChanged ) && hasChanged )
649  {
650  m_CacheMap.clear();
651 
652  std::list< S3D_CACHE_ENTRY* >::iterator sL = m_CacheList.begin();
653  std::list< S3D_CACHE_ENTRY* >::iterator eL = m_CacheList.end();
654 
655  while( sL != eL )
656  {
657  delete *sL;
658  ++sL;
659  }
660 
661  m_CacheList.clear();
662 
663  return true;
664  }
665 
666  return false;
667 }
bool SetProjectDir(const wxString &aProjDir, bool *flgChanged=NULL)
Function SetProjectDir sets the current KiCad project directory as the first entry in the model path ...
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:56
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:59
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:53
KICAD_T CACHE_WRAPPER::Type ( )
inlineoverridevirtual

Implements PROJECT::_ELEM.

Definition at line 33 of file 3d_cache_wrapper.h.

References CACHE_WRAPPER(), CACHE_WRAPPER_T, and ~CACHE_WRAPPER().

33 { return CACHE_WRAPPER_T; }

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