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 
64 
66 
68  wxString m_CacheDir;
69  wxString m_ConfigDir;
70 
82  SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = NULL );
83 
93  bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
94 
95  // load scene data from a cache file
96  bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
97 
98  // save scene data to a cache file
99  bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
100 
101  // the real load function (can supply a cache entry pointer to member functions)
102  SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = NULL );
103 
104 public:
105  S3D_CACHE();
106  virtual ~S3D_CACHE();
107 
108  KICAD_T Type() noexcept override
109  {
110  return S3D_CACHE_T;
111  }
112 
124  bool Set3DConfigDir( const wxString& aConfigDir );
125 
131  bool SetProject( PROJECT* aProject );
132 
139  void SetProgramBase( PGM_BASE* aBase );
140 
152  SCENEGRAPH* Load( const wxString& aModelFile );
153 
154  FILENAME_RESOLVER* GetResolver() noexcept;
155 
163  std::list< wxString > const* GetFileFilters() const;
164 
169  void FlushCache( bool closePlugins = true );
170 
175  void ClosePlugins();
176 
185  S3DMODEL* GetModel( const wxString& aModelFileName );
186 
195  void CleanCacheDir( int aNumDaysOld );
196 };
197 
198 #endif // CACHE_3D_H
define an internal structure to be used by the 3D renders
PROJECT holds project specific data.
Definition: project.h:61
PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:137
std::list< wxString > const * GetFileFilters() const
Function GetFileFilters returns the list of file filters retrieved from the plugins; this will contai...
Definition: 3d_cache.cpp:633
void SetProgramBase(PGM_BASE *aBase)
Function SetProgramBase sets the filename resolver's pointer to the application's PGM_BASE instance; ...
Definition: 3d_cache.cpp:621
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
Definition: bitmap.cpp:56
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:419
S3D_CACHE.
Definition: 3d_cache.h:54
defines the basic data associated with a single 3D model.
FILENAME_RESOLVER * m_FNResolver
Definition: 3d_cache.h:63
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:665
bool saveCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:460
void FlushCache(bool closePlugins=true)
Function FlushCache frees all data in the cache and by default closes all plugins.
Definition: 3d_cache.cpp:639
#define NULL
wxString m_CacheDir
Definition: 3d_cache.h:68
void ClosePlugins()
Function ClosePlugins unloads plugins to free memory.
Definition: 3d_cache.cpp:658
void CleanCacheDir(int aNumDaysOld)
Function Delete up old cache files in cache directory.
Definition: 3d_cache.cpp:691
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)
base configuration path for 3D items
Definition: 3d_cache.cpp:291
virtual ~S3D_CACHE()
Definition: 3d_cache.cpp:197
SCENEGRAPH * load(const wxString &aModelFile, S3D_CACHE_ENTRY **aCachePtr=NULL)
Definition: 3d_cache.cpp:216
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:58
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir Sets the configuration directory to be used by the model manager for storing ...
Definition: 3d_cache.cpp:514
FILENAME_RESOLVER * GetResolver() noexcept
Definition: 3d_cache.cpp:627
wxString m_ConfigDir
Definition: 3d_cache.h:69
PROJECT * m_project
Definition: 3d_cache.h:67
KICAD_T Type() noexcept override
Definition: 3d_cache.h:108
bool SetProject(PROJECT *aProject)
Function SetProjectDir sets the current project's working directory; this affects the model search pa...
Definition: 3d_cache.cpp:593
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:74
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:285
Definition: 3d_cache.cpp:125
S3D_PLUGIN_MANAGER * m_Plugins
Definition: 3d_cache.h:65