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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "project_pcb.h"
21#include <project.h>
22#include <confirm.h>
23#include <pgm_base.h>
24#include <3d_cache/3d_cache.h>
25#include <paths.h>
28
29#include <mutex>
30
31static std::mutex mutex3D_cacheManager;
33
34
36{
37 std::scoped_lock lock( s_libAdapterMutex );
38
40 std::optional<LIBRARY_MANAGER_ADAPTER*> adapter = mgr.Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT );
41
42 if( !adapter )
43 {
45 std::make_unique<FOOTPRINT_LIBRARY_ADAPTER>( mgr ) );
46
47 std::optional<LIBRARY_MANAGER_ADAPTER*> created = mgr.Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT );
48 wxCHECK( created && ( *created )->Type() == LIBRARY_TABLE_TYPE::FOOTPRINT, nullptr );
49 return static_cast<FOOTPRINT_LIBRARY_ADAPTER*>( *created );
50 }
51
52 wxCHECK( ( *adapter )->Type() == LIBRARY_TABLE_TYPE::FOOTPRINT, nullptr );
53 return static_cast<FOOTPRINT_LIBRARY_ADAPTER*>( *adapter );
54}
55
56
57S3D_CACHE* PROJECT_PCB::Get3DCacheManager( PROJECT* aProject, bool aUpdateProjDir )
58{
59 std::lock_guard<std::mutex> lock( mutex3D_cacheManager );
60
61 // Get the existing cache from the project
62 S3D_CACHE* cache = static_cast<S3D_CACHE*>( aProject->GetElem( PROJECT::ELEM::S3DCACHE ) );
63
64 if( !cache )
65 {
66 // Create a cache if there is not one already
67 cache = new S3D_CACHE();
68
69 wxFileName cfgpath;
70 cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
71 cfgpath.AppendDir( wxT( "3d" ) );
72
73 cache->SetProgramBase( &Pgm() );
74 cache->Set3DConfigDir( cfgpath.GetFullPath() );
75
76 aProject->SetElem( PROJECT::ELEM::S3DCACHE, cache );
77 aUpdateProjDir = true;
78 }
79
80 if( aUpdateProjDir )
81 cache->SetProject( aProject );
82
83 return cache;
84}
85
86
91
92
94{
95 std::lock_guard<std::mutex> lock( mutex3D_cacheManager );
96
97 // Get the existing cache from the project
98 S3D_CACHE* cache = static_cast<S3D_CACHE*>( aProject->GetElem( PROJECT::ELEM::S3DCACHE ) );
99
100 if( cache )
101 {
102 // We'll delete ".3dc" cache files older than this many days
103 int clearCacheInterval = 0;
104
105 if( Pgm().GetCommonSettings() )
106 clearCacheInterval = Pgm().GetCommonSettings()->m_System.clear_3d_cache_interval;
107
108 // An interval of zero means the user doesn't want to ever clear the cache
109
110 if( clearCacheInterval > 0 )
111 cache->CleanCacheDir( clearCacheInterval );
112 }
113}
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:634
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:528
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
static std::mutex s_libAdapterMutex
Used to synchronise access to FootprintLibAdapter.
Definition project_pcb.h:52
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:62
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition project.cpp:396
virtual _ELEM * GetElem(PROJECT::ELEM aIndex)
Get and set the elements for this project.
Definition project.cpp:385
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
void SetProgramBase(PGM_BASE *aBase)
Set the filename resolver's pointer to the application's PGM_BASE instance.
Definition 3d_cache.cpp:535
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:443
FILENAME_RESOLVER * GetResolver() noexcept
Definition 3d_cache.cpp:541
bool SetProject(PROJECT *aProject)
Set the current project's working directory; this affects the model search path.
Definition 3d_cache.cpp:507
void CleanCacheDir(int aNumDaysOld)
Delete up old cache files in cache directory.
Definition 3d_cache.cpp:606
This file is part of the common library.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
static std::mutex mutex3D_cacheManager