KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
29#ifndef CACHE_3D_H
30#define CACHE_3D_H
31
32#include "3d_info.h"
33#include <core/typeinfo.h>
34#include "string_utils.h"
35#include <list>
36#include <map>
38#include <project.h>
39#include <wx/string.h>
40
41class EMBEDDED_FILES;
42class PGM_BASE;
43class S3D_CACHE_ENTRY;
44class SCENEGRAPH;
47
48
54{
55public:
56 S3D_CACHE();
57 virtual ~S3D_CACHE();
58
59 KICAD_T Type() noexcept override
60 {
61 return S3D_CACHE_T;
62 }
63
73 bool Set3DConfigDir( const wxString& aConfigDir );
74
78 bool SetProject( PROJECT* aProject );
79
85 void SetProgramBase( PGM_BASE* aBase );
86
100 SCENEGRAPH* Load( const wxString& aModelFile, const wxString& aBasePath, const EMBEDDED_FILES* aEmbeddedFiles );
101
102 FILENAME_RESOLVER* GetResolver() noexcept;
103
111 std::list< wxString > const* GetFileFilters() const;
112
116 void FlushCache( bool closePlugins = true );
117
121 void ClosePlugins();
122
132 S3DMODEL* GetModel( const wxString& aModelFileName, const wxString& aBasePath, const EMBEDDED_FILES* aEmbeddedFiles );
133
141 void CleanCacheDir( int aNumDaysOld );
142
143private:
154 SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = nullptr );
155
163 bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
164
165 // load scene data from a cache file
166 bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
167
168 // save scene data to a cache file
169 bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
170
171 // the real load function (can supply a cache entry pointer to member functions)
172 SCENEGRAPH* load( const wxString& aModelFile, const wxString& aBasePath,
173 S3D_CACHE_ENTRY** aCachePtr = nullptr,
174 const EMBEDDED_FILES* aEmbeddedFiles = nullptr );
175
178
181
183
185
187 wxString m_CacheDir;
188 wxString m_ConfigDir;
189};
190
191#endif // CACHE_3D_H
defines the basic data associated with a single 3D model.
define an internal structure to be used by the 3D renders
Provide an extensible class to resolve 3D model paths.
Container for data for KiCad programs.
Definition: pgm_base.h:102
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:73
Container for project specific data.
Definition: project.h:62
Definition: 3d_cache.cpp:124
Cache for storing the 3D shapes.
Definition: 3d_cache.h:54
bool getSHA1(const wxString &aFileName, unsigned char *aSHA1Sum)
Calculate the SHA1 hash of the given file.
Definition: 3d_cache.cpp:348
SCENEGRAPH * Load(const wxString &aModelFile, const wxString &aBasePath, const EMBEDDED_FILES *aEmbeddedFiles)
Attempt to load the scene data for a model.
Definition: 3d_cache.cpp:275
void SetProgramBase(PGM_BASE *aBase)
Set the filename resolver's pointer to the application's PGM_BASE instance.
Definition: 3d_cache.cpp:590
wxString m_CacheDir
Definition: 3d_cache.h:187
bool loadCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:404
virtual ~S3D_CACHE()
Definition: 3d_cache.cpp:195
void FlushCache(bool closePlugins=true)
Free all data in the cache and by default closes all plugins.
Definition: 3d_cache.cpp:608
KICAD_T Type() noexcept override
Definition: 3d_cache.h:59
bool Set3DConfigDir(const wxString &aConfigDir)
Sets the configuration directory to be used by the model manager for storing 3D model manager configu...
Definition: 3d_cache.cpp:498
S3DMODEL * GetModel(const wxString &aModelFileName, const wxString &aBasePath, const EMBEDDED_FILES *aEmbeddedFiles)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
Definition: 3d_cache.cpp:634
SCENEGRAPH * load(const wxString &aModelFile, const wxString &aBasePath, S3D_CACHE_ENTRY **aCachePtr=nullptr, const EMBEDDED_FILES *aEmbeddedFiles=nullptr)
Definition: 3d_cache.cpp:204
SCENEGRAPH * checkCache(const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=nullptr)
Find or create cache entry for file name.
Definition: 3d_cache.cpp:281
PROJECT * m_project
Definition: 3d_cache.h:186
S3D_PLUGIN_MANAGER * m_Plugins
Definition: 3d_cache.h:184
bool saveCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition: 3d_cache.cpp:444
wxString m_ConfigDir
Definition: 3d_cache.h:188
std::list< wxString > const * GetFileFilters() const
Return the list of file filters retrieved from the plugins.
Definition: 3d_cache.cpp:602
FILENAME_RESOLVER * GetResolver() noexcept
Definition: 3d_cache.cpp:596
std::list< S3D_CACHE_ENTRY * > m_CacheList
cache entries
Definition: 3d_cache.h:177
bool SetProject(PROJECT *aProject)
Set the current project's working directory; this affects the model search path.
Definition: 3d_cache.cpp:562
void CleanCacheDir(int aNumDaysOld)
Delete up old cache files in cache directory.
Definition: 3d_cache.cpp:661
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
mapping of file names to cache names and data
Definition: 3d_cache.h:180
void ClosePlugins()
Unload plugins to free memory.
Definition: 3d_cache.cpp:627
FILENAME_RESOLVER * m_FNResolver
Definition: 3d_cache.h:182
Define the basic data set required to represent a 3D model.
Definition: scenegraph.h:45
STL namespace.
Store the a model based on meshes and materials.
Definition: c3dmodel.h:91
A helper for sorting strings from the rear.
Definition: string_utils.h:258
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ S3D_CACHE_T
Definition: typeinfo.h:233