KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project_pcb.cpp
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 The KiCad Developers, see AUTHORS.txt for contributors.
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
24#include "project_pcb.h"
25#include <project.h>
26#include <confirm.h>
27#include <pgm_base.h>
28#include <3d_cache/3d_cache.h>
29#include <paths.h>
32
33#include <mutex>
34
35static std::mutex mutex3D_cacheManager;
37
38
40{
41 std::scoped_lock lock( s_libAdapterMutex );
42
44 std::optional<LIBRARY_MANAGER_ADAPTER*> adapter = mgr.Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT );
45
46 if( !adapter )
47 {
49 std::make_unique<FOOTPRINT_LIBRARY_ADAPTER>( mgr ) );
50
51 std::optional<LIBRARY_MANAGER_ADAPTER*> created = mgr.Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT );
52 wxCHECK( created && ( *created )->Type() == LIBRARY_TABLE_TYPE::FOOTPRINT, nullptr );
53 return static_cast<FOOTPRINT_LIBRARY_ADAPTER*>( *created );
54 }
55
56 wxCHECK( ( *adapter )->Type() == LIBRARY_TABLE_TYPE::FOOTPRINT, nullptr );
57 return static_cast<FOOTPRINT_LIBRARY_ADAPTER*>( *adapter );
58}
59
60
61S3D_CACHE* PROJECT_PCB::Get3DCacheManager( PROJECT* aProject, bool aUpdateProjDir )
62{
63 std::lock_guard<std::mutex> lock( mutex3D_cacheManager );
64
65 // Get the existing cache from the project
66 S3D_CACHE* cache = static_cast<S3D_CACHE*>( aProject->GetElem( PROJECT::ELEM::S3DCACHE ) );
67
68 if( !cache )
69 {
70 // Create a cache if there is not one already
71 cache = new S3D_CACHE();
72
73 wxFileName cfgpath;
74 cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
75 cfgpath.AppendDir( wxT( "3d" ) );
76
77 cache->SetProgramBase( &Pgm() );
78 cache->Set3DConfigDir( cfgpath.GetFullPath() );
79
80 aProject->SetElem( PROJECT::ELEM::S3DCACHE, cache );
81 aUpdateProjDir = true;
82 }
83
84 if( aUpdateProjDir )
85 cache->SetProject( aProject );
86
87 return cache;
88}
89
90
95
96
98{
99 std::lock_guard<std::mutex> lock( mutex3D_cacheManager );
100
101 // Get the existing cache from the project
102 S3D_CACHE* cache = static_cast<S3D_CACHE*>( aProject->GetElem( PROJECT::ELEM::S3DCACHE ) );
103
104 if( cache )
105 {
106 // We'll delete ".3dc" cache files older than this many days
107 int clearCacheInterval = 0;
108
109 if( Pgm().GetCommonSettings() )
110 clearCacheInterval = Pgm().GetCommonSettings()->m_System.clear_3d_cache_interval;
111
112 // An interval of zero means the user doesn't want to ever clear the cache
113
114 if( clearCacheInterval > 0 )
115 cache->CleanCacheDir( clearCacheInterval );
116 }
117}
Provide an extensible class to resolve 3D model paths.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIBRARY_MANAGER_ADAPTER * > Adapter(LIBRARY_TABLE_TYPE aType) const
void RegisterAdapter(LIBRARY_TABLE_TYPE aType, std::unique_ptr< LIBRARY_MANAGER_ADAPTER > &&aAdapter)
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Definition paths.cpp:592
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:537
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:131
static std::mutex s_libAdapterMutex
Used to synchronise access to FootprintLibAdapter.
Definition project_pcb.h:56
static void Cleanup3DCache(PROJECT *aProject)
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
static FILENAME_RESOLVER * Get3DFilenameResolver(PROJECT *aProject)
Accessor for 3D path resolver.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
Container for project specific data.
Definition project.h:65
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition project.cpp:380
virtual _ELEM * GetElem(PROJECT::ELEM aIndex)
Get and set the elements for this project.
Definition project.cpp:369
Cache for storing the 3D shapes.
Definition 3d_cache.h:55
void SetProgramBase(PGM_BASE *aBase)
Set the filename resolver's pointer to the application's PGM_BASE instance.
Definition 3d_cache.cpp:507
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:415
FILENAME_RESOLVER * GetResolver() noexcept
Definition 3d_cache.cpp:513
bool SetProject(PROJECT *aProject)
Set the current project's working directory; this affects the model search path.
Definition 3d_cache.cpp:479
void CleanCacheDir(int aNumDaysOld)
Delete up old cache files in cache directory.
Definition 3d_cache.cpp:578
This file is part of the common library.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition pgm_base.cpp:946
see class PGM_BASE
static std::mutex mutex3D_cacheManager