2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2020-12-16 18:19:28 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file 3d_cache.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CACHE_3D_H
|
|
|
|
#define CACHE_3D_H
|
|
|
|
|
2020-01-15 23:32:05 +00:00
|
|
|
#include "3d_info.h"
|
|
|
|
#include <core/typeinfo.h>
|
|
|
|
#include "kicad_string.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2015-12-09 07:30:48 +00:00
|
|
|
#include "plugins/3dapi/c3dmodel.h"
|
2020-01-15 23:32:05 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <wx/string.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-04-17 22:35:32 +00:00
|
|
|
class PGM_BASE;
|
2015-12-08 07:31:57 +00:00
|
|
|
class S3D_CACHE_ENTRY;
|
|
|
|
class SCENEGRAPH;
|
2018-03-07 13:05:12 +00:00
|
|
|
class FILENAME_RESOLVER;
|
2015-12-08 07:31:57 +00:00
|
|
|
class S3D_PLUGIN_MANAGER;
|
|
|
|
|
|
|
|
|
2020-01-15 23:32:05 +00:00
|
|
|
/**
|
|
|
|
* Cache for storing the 3D shapes. This cache is able to be stored as a project
|
|
|
|
* element (since it inherits from PROJECT::_ELEM).
|
|
|
|
*/
|
|
|
|
class S3D_CACHE : public PROJECT::_ELEM
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
S3D_CACHE();
|
|
|
|
virtual ~S3D_CACHE();
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
KICAD_T Type() noexcept override
|
2020-01-15 23:32:05 +00:00
|
|
|
{
|
|
|
|
return S3D_CACHE_T;
|
|
|
|
}
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Sets the configuration directory to be used by the model manager for storing 3D
|
|
|
|
* model manager configuration data and the model cache.
|
|
|
|
*
|
|
|
|
* The config directory may only be set once in the lifetime of the object.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* @param aConfigDir is the configuration directory to use for 3D model manager data
|
2015-12-08 07:31:57 +00:00
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
bool Set3DConfigDir( const wxString& aConfigDir );
|
|
|
|
|
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Set the current project's working directory; this affects the model search path.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2020-04-05 19:51:48 +00:00
|
|
|
bool SetProject( PROJECT* aProject );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-04-17 22:35:32 +00:00
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Set the filename resolver's pointer to the application's PGM_BASE instance.
|
|
|
|
*
|
|
|
|
* The pointer is used to extract the local environment variables.
|
2016-04-17 22:35:32 +00:00
|
|
|
*/
|
|
|
|
void SetProgramBase( PGM_BASE* aBase );
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Attempt to load the scene data for a model.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* It will consult the internal cache list and load from cache if possible before invoking
|
|
|
|
* the load() function of the available plugins. The model may fail to load if, for example,
|
|
|
|
* the plugin does not support rendering of the 3D model.
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param aModelFile is the partial or full path to the model to be loaded.
|
2015-12-08 07:31:57 +00:00
|
|
|
* @return true if the model was successfully loaded, otherwise false.
|
|
|
|
*/
|
|
|
|
SCENEGRAPH* Load( const wxString& aModelFile );
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
FILENAME_RESOLVER* GetResolver() noexcept;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Return the list of file filters retrieved from the plugins.
|
|
|
|
*
|
|
|
|
* This will contain at least the default "All Files (*.*)|*.*"
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* @return a pointer to the filter list.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2020-04-05 19:51:48 +00:00
|
|
|
std::list< wxString > const* GetFileFilters() const;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Free all data in the cache and by default closes all plugins.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2016-02-21 00:54:34 +00:00
|
|
|
void FlushCache( bool closePlugins = true );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Unload plugins to free memory.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2020-04-05 19:51:48 +00:00
|
|
|
void ClosePlugins();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2016-01-15 00:28:28 +00:00
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Attempt to load the scene data for a model and to translate it into an S3D_MODEL
|
|
|
|
* structure for display by a renderer.
|
2016-01-15 00:28:28 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* @param aModelFileName is the full path to the model to be loaded.
|
|
|
|
* @return is a pointer to the render data or NULL if not available.
|
2016-01-15 00:28:28 +00:00
|
|
|
*/
|
2015-12-16 22:21:30 +00:00
|
|
|
S3DMODEL* GetModel( const wxString& aModelFileName );
|
2020-08-09 10:41:45 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-16 18:19:28 +00:00
|
|
|
* Delete up old cache files in cache directory.
|
2020-08-09 10:41:45 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* Deletes ".3dc" files in the cache directory that are older than \a aNumDaysOld.
|
2020-08-09 10:41:45 +00:00
|
|
|
*
|
2020-12-16 18:19:28 +00:00
|
|
|
* @param aNumDaysOld is age threshold to delete ".3dc" cache files.
|
2020-08-09 10:41:45 +00:00
|
|
|
*/
|
|
|
|
void CleanCacheDir( int aNumDaysOld );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Find or create cache entry for file name
|
|
|
|
*
|
|
|
|
* Searches the cache list for the given filename and retrieves the cache data; a cache
|
|
|
|
* entry is created if one does not already exist.
|
|
|
|
*
|
|
|
|
* @param aFileName is the file name (full or partial path).
|
|
|
|
* @param aCachePtr is an optional return address for cache entry pointer.
|
|
|
|
* @return SCENEGRAPH object associated with file name or NULL on error.
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
SCENEGRAPH* checkCache( const wxString& aFileName, S3D_CACHE_ENTRY** aCachePtr = nullptr );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the SHA1 hash of the given file.
|
|
|
|
*
|
|
|
|
* @param aFileName file name (full path).
|
|
|
|
* @param aSHA1Sum a 20 byte character array to hold the SHA1 hash.
|
|
|
|
* @return true on success, otherwise false.
|
|
|
|
*/
|
|
|
|
bool getSHA1( const wxString& aFileName, unsigned char* aSHA1Sum );
|
|
|
|
|
|
|
|
// load scene data from a cache file
|
|
|
|
bool loadCacheData( S3D_CACHE_ENTRY* aCacheItem );
|
|
|
|
|
|
|
|
// save scene data to a cache file
|
|
|
|
bool saveCacheData( S3D_CACHE_ENTRY* aCacheItem );
|
|
|
|
|
|
|
|
// the real load function (can supply a cache entry pointer to member functions)
|
2021-01-02 21:05:29 +00:00
|
|
|
SCENEGRAPH* load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCachePtr = nullptr );
|
2020-12-16 18:19:28 +00:00
|
|
|
|
|
|
|
/// cache entries
|
|
|
|
std::list< S3D_CACHE_ENTRY* > m_CacheList;
|
|
|
|
|
|
|
|
/// mapping of file names to cache names and data
|
|
|
|
std::map< wxString, S3D_CACHE_ENTRY*, rsort_wxString > m_CacheMap;
|
|
|
|
|
|
|
|
FILENAME_RESOLVER* m_FNResolver;
|
|
|
|
|
|
|
|
S3D_PLUGIN_MANAGER* m_Plugins;
|
|
|
|
|
|
|
|
PROJECT* m_project;
|
|
|
|
wxString m_CacheDir;
|
|
|
|
wxString m_ConfigDir; /// base configuration path for 3D items
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CACHE_3D_H
|