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 "3d_info.h"
33 #include <core/typeinfo.h>
34 #include "kicad_string.h"
35 #include <list>
36 #include <map>
37 #include "plugins/3dapi/c3dmodel.h"
38 #include <project.h>
39 #include <wx/string.h>
40 
41 class PGM_BASE;
42 class S3D_CACHE_ENTRY;
43 class SCENEGRAPH;
44 class FILENAME_RESOLVER;
45 class S3D_PLUGIN_MANAGER;
46 
47 
54 class S3D_CACHE : public PROJECT::_ELEM
55 {
56 private:
58  std::list< S3D_CACHE_ENTRY* > m_CacheList;
59 
61  std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > m_CacheMap;
62 
65 
68 
71 
73  wxString m_CacheDir;
74 
76  wxString m_ConfigDir;
77 
79  wxString m_ProjDir;
80 
92  SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = NULL );
93 
103  bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
104 
105  // load scene data from a cache file
106  bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
107 
108  // save scene data to a cache file
109  bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
110 
111  // the real load function (can supply a cache entry pointer to member functions)
112  SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = NULL );
113 
114 public:
115  S3D_CACHE();
116  virtual ~S3D_CACHE();
117 
118  KICAD_T Type() override
119  {
120  return S3D_CACHE_T;
121  }
122 
134  bool Set3DConfigDir( const wxString& aConfigDir );
135 
144  wxString Get3DConfigDir( bool createDefault = false );
145 
151  bool SetProjectDir( const wxString& aProjDir );
152 
159  void SetProgramBase( PGM_BASE* aBase );
160 
165  wxString GetProjectDir( void );
166 
178  SCENEGRAPH* Load( const wxString& aModelFile );
179 
181 
189  std::list< wxString > const* GetFileFilters( void ) const;
190 
195  void FlushCache( bool closePlugins = true );
196 
201  void ClosePlugins( void );
202 
211  S3DMODEL* GetModel( const wxString& aModelFileName );
212 
213  wxString GetModelHash( const wxString& aModelFileName );
214 };
215 
216 #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:79
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
wxString Get3DConfigDir(bool createDefault=false)
Function Get3DConfigDir returns the current 3D configuration directory on success,...
Definition: 3d_cache.cpp:596
void SetProgramBase(PGM_BASE *aBase)
Function SetProgramBase sets the filename resolver's pointer to the application's PGM_BASE instance; ...
Definition: 3d_cache.cpp:677
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:61
bool loadCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:417
S3D_CACHE.
Definition: 3d_cache.h:54
defines the basic data associated with a single 3D model.
wxString GetModelHash(const wxString &aModelFileName)
Definition: 3d_cache.cpp:759
FILENAME_RESOLVER * m_FNResolver
object to resolve file names
Definition: 3d_cache.h:64
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
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:732
bool saveCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:458
void FlushCache(bool closePlugins=true)
Function FlushCache frees all data in the cache and by default closes all plugins.
Definition: 3d_cache.cpp:702
bool SetProjectDir(const wxString &aProjDir)
Function SetProjectDir sets the current project's working directory; this affects the model search pa...
Definition: 3d_cache.cpp:651
#define NULL
wxString m_CacheDir
3D cache directory
Definition: 3d_cache.h:73
bool getSHA1(const wxString &aFileName, unsigned char *aSHA1Sum)
Function getSHA1 calculates the SHA1 hash of the given file.
Definition: 3d_cache.cpp:361
SCENEGRAPH * checkCache(const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=NULL)
Find or create cache entry for file name.
Definition: 3d_cache.cpp:289
bool m_DirtyCache
set true if the cache needs to be updated
Definition: 3d_cache.h:70
virtual ~S3D_CACHE()
Definition: 3d_cache.cpp:200
SCENEGRAPH * load(const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=NULL)
Definition: 3d_cache.cpp:214
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:58
KICAD_T Type() override
Definition: 3d_cache.h:118
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir Sets the configuration directory to be used by the model manager for storing ...
Definition: 3d_cache.cpp:512
wxString m_ConfigDir
base configuration path for 3D items
Definition: 3d_cache.h:76
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:69
wxString GetProjectDir(void)
Function GetProjectDir returns the current project's working directory.
Definition: 3d_cache.cpp:684
FILENAME_RESOLVER * GetResolver(void)
Definition: 3d_cache.cpp:690
void ClosePlugins(void)
Function ClosePlugins unloads plugins to free memory.
Definition: 3d_cache.cpp:723
Store the a model based on meshes and materials.
Definition: c3dmodel.h:90
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:283
Definition: 3d_cache.cpp:124
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:696
S3D_PLUGIN_MANAGER * m_Plugins
plugin manager
Definition: 3d_cache.h:67