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, see <https://www.gnu.org/licenses/>.
19 */
20#ifndef PROJECT_H_
21#define PROJECT_H_
22
26#include <array>
27#include <map>
28#include <mutex>
29#include <vector>
30#include <kiid.h>
31#include <wx_filename.h>
32#include <wx/string.h>
33#include <core/typeinfo.h>
34
37#define PROJECT_VAR_NAME wxT( "KIPRJMOD" )
38
40#define NAMELESS_PROJECT _( "untitled" )
41
45class SEARCH_STACK;
46class S3D_CACHE;
47class KIWAY;
50class PROJECT_FILE;
52class LOCKFILE;
53
54
62{
63public:
79
89 {
90 public:
91 virtual ~_ELEM() {}
92
93 virtual PROJECT::ELEM ProjectElementType() = 0; // Sanity-checking for returned values.
94 };
95
96 PROJECT();
97 virtual ~PROJECT();
98
99 //-----<Cross Module API>----------------------------------------------------
100
101 virtual bool TextVarResolver( wxString* aToken ) const;
102
103 virtual std::map<wxString, wxString>& GetTextVars() const;
104
108 virtual void ApplyTextVars( const std::map<wxString, wxString>& aVarsMap );
109
110 int GetTextVarsTicker() const { return m_textVarsTicker; }
112
115
122 virtual const wxString GetProjectFullName() const;
123
130 virtual const wxString GetProjectPath() const;
131
138 virtual const wxString GetProjectDirectory() const;
139
145 virtual const wxString GetProjectName() const;
146
156 virtual bool IsNullProject() const;
157
158 virtual bool IsReadOnly() const { return m_readOnly || IsNullProject(); }
159
160 virtual void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
161
162 virtual bool IsLockOverrideGranted() const { return m_lockOverrideGranted; }
163
164 virtual void SetLockOverrideGranted( bool aGranted = true ) { m_lockOverrideGranted = aGranted; }
165
169 virtual const wxString GetSheetName( const KIID& aSheetID );
170
176 virtual const wxString FootprintLibTblName() const;
177
181 virtual const wxString SymbolLibTableName() const;
182
186 virtual const wxString DesignBlockLibTblName() const;
187
196
197 void PinLibrary( const wxString& aLibrary, enum LIB_TYPE_T aLibType );
198 void UnpinLibrary( const wxString& aLibrary, enum LIB_TYPE_T aLibType );
199
201 {
202 wxASSERT( m_projectFile );
203 return *m_projectFile;
204 }
205
207 {
208 wxASSERT( m_localSettings );
209 return *m_localSettings;
210 }
211
234
242 virtual const wxString& GetRString( RSTRING_T aStringId );
243
251 virtual void SetRString( RSTRING_T aStringId, const wxString& aString );
252
265 virtual _ELEM* GetElem( PROJECT::ELEM aIndex );
266 virtual void SetElem( PROJECT::ELEM aIndex, _ELEM* aElem );
267
271 void Clear() // inline not virtual
272 {
273 elemsClear();
274
275 for( unsigned i = 0; i < RSTRING_COUNT; ++i )
276 SetRString( RSTRING_T( i ), wxEmptyString );
277 }
278
285 virtual const wxString AbsolutePath( const wxString& aFileName ) const;
286
290 virtual FOOTPRINT_LIBRARY_ADAPTER* FootprintLibAdapter( KIWAY& aKiway );
291
295 virtual DESIGN_BLOCK_LIBRARY_ADAPTER* DesignBlockLibs();
296
297 void SetProjectLock( LOCKFILE* aLockFile );
298
299 LOCKFILE* GetProjectLock() const;
300
310 void SaveToHistory( const wxString& aProjectPath, std::vector<HISTORY_FILE_DATA>& aFileData );
311
312private:
313 friend class SETTINGS_MANAGER; // so that SM can set project path
314 friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
315
316
320 virtual void elemsClear();
321
329 virtual void setProjectFullName( const wxString& aFullPathAndName );
330
338 virtual void setProjectFile( PROJECT_FILE* aFile )
339 {
340 m_projectFile = aFile;
341 }
342
350 virtual void setLocalSettings( PROJECT_LOCAL_SETTINGS* aSettings )
351 {
352 m_localSettings = aSettings;
353 }
354
358 const wxString libTableName( const wxString& aLibTableName ) const;
359
360private:
361 wxFileName m_project_name;
362
367
370
373
374 std::map<KIID, wxString> m_sheetNames;
375
377 std::array<wxString,RSTRING_COUNT> m_rstrings;
378
380 std::array<_ELEM*,static_cast<unsigned int>( PROJECT::ELEM::COUNT )> m_elems;
381
383 std::unique_ptr<LOCKFILE> m_project_lock;
384
387};
388
389
390#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:44
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
A collection of #SYMBOL_LIB objects.
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition project.h:89
virtual PROJECT::ELEM ProjectElementType()=0
virtual ~_ELEM()
Definition project.h:91
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:369
bool m_lockOverrideGranted
User granted override at project level.
Definition project.h:364
virtual void SetReadOnly(bool aReadOnly=true)
Definition project.h:160
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
Definition project.h:338
virtual bool IsReadOnly() const
Definition project.h:158
@ SYMBOL_LIB
Definition project.h:190
@ DESIGN_BLOCK_LIB
Definition project.h:192
@ FOOTPRINT_LIB
Definition project.h:191
@ LIB_TYPE_COUNT
Definition project.h:194
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition project.h:214
@ RSTRING_COUNT
Definition project.h:232
@ VIEWER_3D_FILTER_INDEX
Definition project.h:222
@ PCB_FOOTPRINT
Definition project.h:226
@ PCB_LIB_PATH
Definition project.h:224
@ VIEWER_3D_PATH
Definition project.h:221
@ SCH_LIBEDIT_CUR_LIB
Definition project.h:218
@ PCB_FOOTPRINT_EDITOR_FP_NAME
Definition project.h:227
@ PCB_FOOTPRINT_EDITOR_LIB_NICKNAME
Definition project.h:228
@ PCB_FOOTPRINT_VIEWER_FP_NAME
Definition project.h:229
@ DOC_PATH
Definition project.h:215
@ SCH_LIB_SELECT
Definition project.h:217
@ PCB_LIB_NICKNAME
Definition project.h:225
@ PCB_FOOTPRINT_VIEWER_LIB_NICKNAME
Definition project.h:230
@ SCH_LIBEDIT_CUR_SYMBOL
Definition project.h:219
@ SCH_LIB_PATH
Definition project.h:216
std::map< KIID, wxString > m_sheetNames
Definition project.h:374
std::unique_ptr< LOCKFILE > m_project_lock
Lock.
Definition project.h:383
virtual void setLocalSettings(PROJECT_LOCAL_SETTINGS *aSettings)
Set the local settings backing store.
Definition project.h:350
int m_netclassesTicker
Update counter on netclasses.
Definition project.h:366
virtual void ApplyTextVars(const std::map< wxString, wxString > &aVarsMap)
Applies the given var map, it will create or update existing vars.
Definition project.cpp:132
int GetNetclassesTicker() const
Definition project.h:113
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition project.h:206
friend class SETTINGS_MANAGER
Definition project.h:313
void IncrementNetclassesTicker()
Definition project.h:114
virtual bool TextVarResolver(wxString *aToken) const
Definition project.cpp:81
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:200
virtual void SetLockOverrideGranted(bool aGranted=true)
Definition project.h:164
std::mutex m_designBlockLibsMutex
Synchronise access to DesignBlockLibs()
Definition project.h:386
int GetTextVarsTicker() const
Definition project.h:110
std::array< _ELEM *, static_cast< unsigned int >(PROJECT::ELEM::COUNT)> m_elems
Definition project.h:380
virtual void elemsClear()
Delete all the _ELEMs and set their pointers to NULL.
Definition project.cpp:64
friend class TEST_NETLISTS_FIXTURE
Definition project.h:314
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:355
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition project.h:361
void Clear()
Clear the _ELEMs and RSTRINGs.
Definition project.h:271
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition project.h:372
int m_textVarsTicker
Update counter on text vars.
Definition project.h:365
virtual bool IsLockOverrideGranted() const
Definition project.h:162
std::array< wxString, RSTRING_COUNT > m_rstrings
Definition project.h:377
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
Definition project.cpp:147
bool m_readOnly
No project files will be written to disk.
Definition project.h:363
void IncrementTextVarsTicker()
Definition project.h:111
virtual std::map< wxString, wxString > & GetTextVars() const
Definition project.cpp:126
PROJECT()
Definition project.cpp:52
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition project.cpp:201
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:68
@ SCH_SEARCH_STACK
Definition project.h:70
@ LEGACY_SYMBOL_LIBS
Definition project.h:69
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
Look for files in a number of paths.
#define KICOMMON_API
Definition kicommon.h:27
Data produced by a registered saver on the UI thread, consumed by either the background local-history...