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 The 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
28
29#ifndef CACHE_3D_H
30#define CACHE_3D_H
31
32#include "3d_info.h"
34#include <core/typeinfo.h>
35#include "string_utils.h"
36#include <hash_128.h>
37#include <list>
38#include <map>
39#include <mutex>
41#include <project.h>
42#include <wx/string.h>
43
44class EMBEDDED_FILES;
45class PGM_BASE;
46class S3D_CACHE_ENTRY;
47class SCENEGRAPH;
50
51
57{
58public:
59 S3D_CACHE();
60 virtual ~S3D_CACHE();
61
63 {
65 }
66
76 bool Set3DConfigDir( const wxString& aConfigDir );
77
81 bool SetProject( PROJECT* aProject );
82
88 void SetProgramBase( PGM_BASE* aBase );
89
104 SCENEGRAPH* Load( const wxString& aModelFile, const wxString& aBasePath,
105 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack );
106
107 FILENAME_RESOLVER* GetResolver() noexcept;
108
116 std::list< wxString > const* GetFileFilters() const;
117
121 void FlushCache( bool closePlugins = true );
122
126 void ClosePlugins();
127
138 S3DMODEL* GetModel( const wxString& aModelFileName, const wxString& aBasePath,
139 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack );
140
148 void CleanCacheDir( int aNumDaysOld );
149
150private:
161 SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = nullptr );
162
170 bool getHash( const wxString& aFileName, HASH_128& aHash );
171
172 // load scene data from a cache file
173 bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
174
175 // save scene data to a cache file
176 bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
177
178 // the real load function (can supply a cache entry pointer to member functions)
179 SCENEGRAPH* load( const wxString& aModelFile, const wxString& aBasePath,
180 S3D_CACHE_ENTRY** aCachePtr = nullptr,
181 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack = {} );
182
184 std::list< S3D_CACHE_ENTRY* > m_CacheList;
185
187 std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > m_CacheMap;
188
190
192
194 wxString m_CacheDir;
195 wxString m_ConfigDir;
196
200 mutable std::mutex m_substCatalogMutex;
201 mutable bool m_substCatalogBuilt = false;
203};
204
205#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.
An index of STEP-family model files keyed by normalised filename stem.
Container for data for KiCad programs.
Definition pgm_base.h:108
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition project.h:93
Container for project specific data.
Definition project.h:66
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:72
Definition 3d_cache.cpp:72
void SetProgramBase(PGM_BASE *aBase)
Set the filename resolver's pointer to the application's PGM_BASE instance.
Definition 3d_cache.cpp:539
wxString m_CacheDir
Definition 3d_cache.h:194
bool loadCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition 3d_cache.cpp:353
virtual ~S3D_CACHE()
Definition 3d_cache.cpp:135
void FlushCache(bool closePlugins=true)
Free all data in the cache and by default closes all plugins.
Definition 3d_cache.cpp:557
PROJECT::ELEM ProjectElementType() noexcept override
Definition 3d_cache.h:62
bool Set3DConfigDir(const wxString &aConfigDir)
Set the configuration directory to be used by the model manager for storing 3D model manager configur...
Definition 3d_cache.cpp:447
S3DMODEL * GetModel(const wxString &aModelFileName, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Attempt to load the scene data for a model and to translate it into an S3D_MODEL structure for displa...
Definition 3d_cache.cpp:583
SCENEGRAPH * checkCache(const wxString &aFileName, S3D_CACHE_ENTRY **aCachePtr=nullptr)
Find or create cache entry for file name.
Definition 3d_cache.cpp:254
MODEL_SUBSTITUTION::STEP_CATALOG m_substCatalog
Definition 3d_cache.h:202
PROJECT * m_project
Definition 3d_cache.h:193
S3D_PLUGIN_MANAGER * m_Plugins
Definition 3d_cache.h:191
bool saveCacheData(S3D_CACHE_ENTRY *aCacheItem)
Definition 3d_cache.cpp:393
SCENEGRAPH * load(const wxString &aModelFile, const wxString &aBasePath, S3D_CACHE_ENTRY **aCachePtr=nullptr, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack={})
Definition 3d_cache.cpp:144
wxString m_ConfigDir
base configuration path for 3D items.
Definition 3d_cache.h:195
std::mutex m_substCatalogMutex
Lazy STEP-catalog used by the headless resolver fallback in load().
Definition 3d_cache.h:200
bool m_substCatalogBuilt
Definition 3d_cache.h:201
std::list< wxString > const * GetFileFilters() const
Return the list of file filters retrieved from the plugins.
Definition 3d_cache.cpp:551
FILENAME_RESOLVER * GetResolver() noexcept
Definition 3d_cache.cpp:545
std::list< S3D_CACHE_ENTRY * > m_CacheList
Cache entries.
Definition 3d_cache.h:184
bool SetProject(PROJECT *aProject)
Set the current project's working directory; this affects the model search path.
Definition 3d_cache.cpp:511
void CleanCacheDir(int aNumDaysOld)
Delete up old cache files in cache directory.
Definition 3d_cache.cpp:610
std::map< wxString, S3D_CACHE_ENTRY *, rsort_wxString > m_CacheMap
Mapping of file names to cache names and data.
Definition 3d_cache.h:187
SCENEGRAPH * Load(const wxString &aModelFile, const wxString &aBasePath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Attempt to load the scene data for a model.
Definition 3d_cache.cpp:247
void ClosePlugins()
Unload plugins to free memory.
Definition 3d_cache.cpp:576
bool getHash(const wxString &aFileName, HASH_128 &aHash)
Calculate the SHA1 hash of the given file.
Definition 3d_cache.cpp:321
FILENAME_RESOLVER * m_FNResolver
Definition 3d_cache.h:189
Define the basic data set required to represent a 3D model.
Definition scenegraph.h:45
STL namespace.
A storage class for 128-bit hash value.
Definition hash_128.h:36
Store the a model based on meshes and materials.
Definition c3dmodel.h:95