KiCad PCB EDA Suite
Loading...
Searching...
No Matches
project.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * Copyright (C) 2022 CERN
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#ifndef PROJECT_H_
25#define PROJECT_H_
26
30#include <array>
31#include <map>
32#include <mutex>
33#include <vector>
34#include <kiid.h>
35#include <wx_filename.h>
36#include <wx/string.h>
37#include <core/typeinfo.h>
38
41#define PROJECT_VAR_NAME wxT( "KIPRJMOD" )
42
44#define NAMELESS_PROJECT _( "untitled" )
45
48class SEARCH_STACK;
49class S3D_CACHE;
50class KIWAY;
53class PROJECT_FILE;
55class LOCKFILE;
56
57
65{
66public:
82
92 {
93 public:
94 virtual ~_ELEM() {}
95
96 virtual PROJECT::ELEM ProjectElementType() = 0; // Sanity-checking for returned values.
97 };
98
99 PROJECT();
100 virtual ~PROJECT();
101
102 //-----<Cross Module API>----------------------------------------------------
103
104 virtual bool TextVarResolver( wxString* aToken ) const;
105
106 virtual std::map<wxString, wxString>& GetTextVars() const;
107
111 virtual void ApplyTextVars( const std::map<wxString, wxString>& aVarsMap );
112
113 int GetTextVarsTicker() const { return m_textVarsTicker; }
115
118
125 virtual const wxString GetProjectFullName() const;
126
133 virtual const wxString GetProjectPath() const;
134
141 virtual const wxString GetProjectDirectory() const;
142
148 virtual const wxString GetProjectName() const;
149
159 virtual bool IsNullProject() const;
160
161 virtual bool IsReadOnly() const { return m_readOnly || IsNullProject(); }
162
163 virtual void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
164
165 virtual bool IsLockOverrideGranted() const { return m_lockOverrideGranted; }
166
167 virtual void SetLockOverrideGranted( bool aGranted = true ) { m_lockOverrideGranted = aGranted; }
168
172 virtual const wxString GetSheetName( const KIID& aSheetID );
173
179 virtual const wxString FootprintLibTblName() const;
180
184 virtual const wxString SymbolLibTableName() const;
185
189 virtual const wxString DesignBlockLibTblName() const;
190
199
200 void PinLibrary( const wxString& aLibrary, enum LIB_TYPE_T aLibType );
201 void UnpinLibrary( const wxString& aLibrary, enum LIB_TYPE_T aLibType );
202
204 {
205 wxASSERT( m_projectFile );
206 return *m_projectFile;
207 }
208
210 {
211 wxASSERT( m_localSettings );
212 return *m_localSettings;
213 }
214
237
245 virtual const wxString& GetRString( RSTRING_T aStringId );
246
254 virtual void SetRString( RSTRING_T aStringId, const wxString& aString );
255
268 virtual _ELEM* GetElem( PROJECT::ELEM aIndex );
269 virtual void SetElem( PROJECT::ELEM aIndex, _ELEM* aElem );
270
274 void Clear() // inline not virtual
275 {
276 elemsClear();
277
278 for( unsigned i = 0; i < RSTRING_COUNT; ++i )
279 SetRString( RSTRING_T( i ), wxEmptyString );
280 }
281
288 virtual const wxString AbsolutePath( const wxString& aFileName ) const;
289
293 virtual FOOTPRINT_LIBRARY_ADAPTER* FootprintLibAdapter( KIWAY& aKiway );
294
298 virtual DESIGN_BLOCK_LIBRARY_ADAPTER* DesignBlockLibs();
299
300 void SetProjectLock( LOCKFILE* aLockFile );
301
302 LOCKFILE* GetProjectLock() const;
303
312 void SaveToHistory( const wxString& aProjectPath, std::vector<wxString>& aFiles );
313
314private:
315 friend class SETTINGS_MANAGER; // so that SM can set project path
316 friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
317
318
322 virtual void elemsClear();
323
331 virtual void setProjectFullName( const wxString& aFullPathAndName );
332
340 virtual void setProjectFile( PROJECT_FILE* aFile )
341 {
342 m_projectFile = aFile;
343 }
344
352 virtual void setLocalSettings( PROJECT_LOCAL_SETTINGS* aSettings )
353 {
354 m_localSettings = aSettings;
355 }
356
360 const wxString libTableName( const wxString& aLibTableName ) const;
361
362private:
363 wxFileName m_project_name;
364
369
372
375
376 std::map<KIID, wxString> m_sheetNames;
377
379 std::array<wxString,RSTRING_COUNT> m_rstrings;
380
382 std::array<_ELEM*,static_cast<unsigned int>( PROJECT::ELEM::COUNT )> m_elems;
383
385 std::unique_ptr<LOCKFILE> m_project_lock;
386
389};
390
391
392#endif // PROJECT_H_
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...
Definition kiid.h:49
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:294
A collection of #SYMBOL_LIB objects.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition project.h:92
virtual PROJECT::ELEM ProjectElementType()=0
virtual ~_ELEM()
Definition project.h:94
The backing store for a PROJECT, in JSON format.
The project local settings are things that are attached to a particular project, but also might be pa...
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
Definition project.h:371
bool m_lockOverrideGranted
User granted override at project level.
Definition project.h:366
virtual void SetReadOnly(bool aReadOnly=true)
Definition project.h:163
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
Definition project.h:340
virtual bool IsReadOnly() const
Definition project.h:161
@ SYMBOL_LIB
Definition project.h:193
@ DESIGN_BLOCK_LIB
Definition project.h:195
@ FOOTPRINT_LIB
Definition project.h:194
@ LIB_TYPE_COUNT
Definition project.h:197
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition project.h:217
@ RSTRING_COUNT
Definition project.h:235
@ VIEWER_3D_FILTER_INDEX
Definition project.h:225
@ PCB_FOOTPRINT
Definition project.h:229
@ PCB_LIB_PATH
Definition project.h:227
@ VIEWER_3D_PATH
Definition project.h:224
@ SCH_LIBEDIT_CUR_LIB
Definition project.h:221
@ PCB_FOOTPRINT_EDITOR_FP_NAME
Definition project.h:230
@ PCB_FOOTPRINT_EDITOR_LIB_NICKNAME
Definition project.h:231
@ PCB_FOOTPRINT_VIEWER_FP_NAME
Definition project.h:232
@ DOC_PATH
Definition project.h:218
@ SCH_LIB_SELECT
Definition project.h:220
@ PCB_LIB_NICKNAME
Definition project.h:228
@ PCB_FOOTPRINT_VIEWER_LIB_NICKNAME
Definition project.h:233
@ SCH_LIBEDIT_CUR_SYMBOL
Definition project.h:222
@ SCH_LIB_PATH
Definition project.h:219
std::map< KIID, wxString > m_sheetNames
Definition project.h:376
std::unique_ptr< LOCKFILE > m_project_lock
Lock.
Definition project.h:385
virtual void setLocalSettings(PROJECT_LOCAL_SETTINGS *aSettings)
Set the local settings backing store.
Definition project.h:352
int m_netclassesTicker
Update counter on netclasses.
Definition project.h:368
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
Definition project.cpp:123
int GetNetclassesTicker() const
Definition project.h:116
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:209
friend class SETTINGS_MANAGER
Definition project.h:315
void IncrementNetclassesTicker()
Definition project.h:117
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:85
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:203
virtual void SetLockOverrideGranted(bool aGranted=true)
Definition project.h:167
std::mutex m_designBlockLibsMutex
Synchronise access to DesignBlockLibs()
Definition project.h:388
int GetTextVarsTicker() const
Definition project.h:113
std::array< _ELEM *, static_cast< unsigned int >(PROJECT::ELEM::COUNT)> m_elems
Definition project.h:382
virtual void elemsClear()
Delete all the _ELEMs and set their pointers to NULL.
Definition project.cpp:68
friend class TEST_NETLISTS_FIXTURE
Definition project.h:316
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
Definition project.cpp:340
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition project.h:363
void Clear()
Clear the _ELEMs and RSTRINGs.
Definition project.h:274
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition project.h:374
int m_textVarsTicker
Update counter on text vars.
Definition project.h:367
virtual bool IsLockOverrideGranted() const
Definition project.h:165
std::array< wxString, RSTRING_COUNT > m_rstrings
Definition project.h:379
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
Definition project.cpp:138
bool m_readOnly
No project files will be written to disk.
Definition project.h:365
void IncrementTextVarsTicker()
Definition project.h:114
virtual std::map< wxString, wxString > & GetTextVars() const
Definition project.cpp:117
PROJECT()
Definition project.cpp:56
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition project.cpp:186
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:71
@ SCH_SEARCH_STACK
Definition project.h:73
@ LEGACY_SYMBOL_LIBS
Definition project.h:72
Cache for storing the 3D shapes.
Definition 3d_cache.h:55
Look for files in a number of paths.
#define KICOMMON_API
Definition kicommon.h:28