KiCad PCB EDA Suite
3d_cache.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
29 #ifndef CACHE_3D_H
30 #define CACHE_3D_H
31 
32 #include <list>
33 #include <map>
34 #include <wx/string.h>
35 #include "str_rsort.h"
36 #include "3d_filename_resolver.h"
37 #include "3d_info.h"
38 #include "plugins/3dapi/c3dmodel.h"
39 
40 
41 class PGM_BASE;
42 class S3D_CACHE;
43 class S3D_CACHE_ENTRY;
44 class SCENEGRAPH;
46 class S3D_PLUGIN_MANAGER;
47 struct S3D_INFO;
48 
49 
50 class S3D_CACHE
51 {
52 private:
54  std::list< S3D_CACHE_ENTRY* > m_CacheList;
55 
57  std::map< wxString, S3D_CACHE_ENTRY*, S3D::rsort_wxString > m_CacheMap;
58 
61 
64 
67 
69  wxString m_CacheDir;
70 
72  wxString m_ConfigDir;
73 
75  wxString m_ProjDir;
76 
87  SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = NULL );
88 
97  bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
98 
99  // load scene data from a cache file
100  bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
101 
102  // save scene data to a cache file
103  bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
104 
105  // the real load function (can supply a cache entry pointer to member functions)
106  SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = NULL );
107 
108 public:
109  S3D_CACHE();
110  virtual ~S3D_CACHE();
111 
123  bool Set3DConfigDir( const wxString& aConfigDir );
124 
133  wxString Get3DConfigDir( bool createDefault = false );
134 
140  bool SetProjectDir( const wxString& aProjDir );
141 
148  void SetProgramBase( PGM_BASE* aBase );
149 
154  wxString GetProjectDir( void );
155 
167  SCENEGRAPH* Load( const wxString& aModelFile );
168 
170 
178  std::list< wxString > const* GetFileFilters( void ) const;
179 
184  void FlushCache( bool closePlugins = true );
185 
190  void ClosePlugins( void );
191 
200  S3DMODEL* GetModel( const wxString& aModelFileName );
201 
202  wxString GetModelHash( const wxString& aModelFileName );
203 };
204 
205 #endif // CACHE_3D_H
define an internal structure to be used by the 3D renders
wxString m_ProjDir
current KiCad project dir
Definition: 3d_cache.h:75
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
provides a wxString sorting functino which works from the end of the string towards the beginning ...
wxString Get3DConfigDir(bool createDefault=false)
Function Get3DConfigDir returns the current 3D configuration directory on success, otherwise it returns wxEmptyString.
Definition: 3d_cache.cpp:642
void SetProgramBase(PGM_BASE *aBase)
Function SetProgramBase sets the filename resolver's pointer to the application's PGM_BASE instance; ...
Definition: 3d_cache.cpp:726
bool loadCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:431
defines the basic data associated with a single 3D model.
wxString GetModelHash(const wxString &aModelFileName)
Definition: 3d_cache.cpp:813
S3DMODEL * GetModel(const wxString &aModelFileName)
Function GetModel attempts to load the scene data for a model and to translate it into an S3D_MODEL s...
Definition: 3d_cache.cpp:781
std::map< wxString, S3D_CACHE_ENTRY *, S3D::rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:57
bool saveCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:474
std::list< wxString > const * GetFileFilters(void) const
Function GetFileFilters returns the list of file filters retrieved from the plugins; this will contai...
Definition: 3d_cache.cpp:745
void FlushCache(bool closePlugins=true)
Function FlushCache frees all data in the cache and by default closes all plugins.
Definition: 3d_cache.cpp:751
bool SetProjectDir(const wxString &aProjDir)
Function SetProjectDir sets the current project's working directory; this affects the model search pa...
Definition: 3d_cache.cpp:700
wxString m_CacheDir
3D cache directory
Definition: 3d_cache.h:69
bool getSHA1(const wxString &aFileName, unsigned char *aSHA1Sum)
Function getSHA1 calculates the SHA1 hash of the given file.
Definition: 3d_cache.cpp:363
SCENEGRAPH * checkCache(const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=NULL)
Function checkCache searches the cache list for the given filename and retrieves the cache data; a ca...
Definition: 3d_cache.cpp:277
bool m_DirtyCache
set true if the cache needs to be updated
Definition: 3d_cache.h:66
virtual ~S3D_CACHE()
Definition: 3d_cache.cpp:189
SCENEGRAPH * load(const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=NULL)
Definition: 3d_cache.cpp:203
S3D_FILENAME_RESOLVER * GetResolver(void)
Definition: 3d_cache.cpp:739
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:54
provides an extensible class to resolve 3D model paths.
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir Sets the configuration directory to be used by the model manager for storing ...
Definition: 3d_cache.cpp:542
wxString m_ConfigDir
base configuration path for 3D items
Definition: 3d_cache.h:72
wxString GetProjectDir(void)
Function GetProjectDir returns the current project's working directory.
Definition: 3d_cache.cpp:733
void ClosePlugins(void)
Function ClosePlugins unloads plugins to free memory.
Definition: 3d_cache.cpp:772
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
S3D_FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:60
SCENEGRAPH * Load(const wxString &aModelFile)
Function Load attempts to load the scene data for a model; it will consult the internal cache list an...
Definition: 3d_cache.cpp:271
Definition: 3d_cache.cpp:108
S3D_PLUGIN_MANAGER * m_Plugins
plugin manager
Definition: 3d_cache.h:63