KiCad PCB EDA Suite
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 (C) 2014-2022 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#ifndef PROJECT_H_
24#define PROJECT_H_
25
29#include <map>
30#include <vector>
31#include <kiid.h>
32#include <wx_filename.h>
33#include <wx/string.h>
34#include <core/typeinfo.h>
35
38#define PROJECT_VAR_NAME wxT( "KIPRJMOD" )
39
41#define NAMELESS_PROJECT _( "untitled" )
42
43class wxConfigBase;
44class PARAM_CFG;
45class FP_LIB_TABLE;
46class SYMBOL_LIBS;
47class SEARCH_STACK;
48class S3D_CACHE;
49class KIWAY;
52class PROJECT_FILE;
54
55
63{
64public:
73 class _ELEM
74 {
75 public:
76 virtual ~_ELEM() {}
77
78 virtual KICAD_T Type() = 0; // Sanity-checking for returned values.
79 };
80
81 PROJECT();
82 virtual ~PROJECT();
83
84 //-----<Cross Module API>----------------------------------------------------
85
86 virtual bool TextVarResolver( wxString* aToken ) const;
87
88 virtual std::map<wxString, wxString>& GetTextVars() const;
89
96 virtual const wxString GetProjectFullName() const;
97
104 virtual const wxString GetProjectPath() const;
105
111 virtual const wxString GetProjectName() const;
112
122 virtual bool IsNullProject() const;
123
124 virtual bool IsReadOnly() const { return m_readOnly || IsNullProject(); }
125
126 virtual void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
127
131 virtual const wxString GetSheetName( const KIID& aSheetID );
132
138 virtual const wxString FootprintLibTblName() const;
139
143 virtual const wxString SymbolLibTableName() const;
144
145 void PinLibrary( const wxString& aLibrary, bool isSymbolLibrary );
146 void UnpinLibrary( const wxString& aLibrary, bool isSymbolLibrary );
147
149 {
150 wxASSERT( m_projectFile );
151 return *m_projectFile;
152 }
153
155 {
156 wxASSERT( m_localSettings );
157 return *m_localSettings;
158 }
159
162 {
165 SCH_LIB_SELECT, // eeschema/selpart.cpp
167 SCH_LIBEDIT_CUR_SYMBOL, // eeschema/libeditframe.cpp
168
171
178
180 };
181
189 virtual const wxString& GetRString( RSTRING_T aStringId );
190
198 virtual void SetRString( RSTRING_T aStringId, const wxString& aString );
199
204 {
206
211
213 };
214
227 virtual _ELEM* GetElem( ELEM_T aIndex );
228 virtual void SetElem( ELEM_T aIndex, _ELEM* aElem );
229
233 virtual void ElemsClear();
234
238 void Clear() // inline not virtual
239 {
240 ElemsClear();
241
242 for( unsigned i = 0; i<RSTRING_COUNT; ++i )
243 SetRString( RSTRING_T( i ), wxEmptyString );
244 }
245
252 virtual const wxString AbsolutePath( const wxString& aFileName ) const;
253
258 virtual FP_LIB_TABLE* PcbFootprintLibs( KIWAY& aKiway );
259
260 // These are the non-virtual DATA LOAD ON DEMAND members. They load project related
261 // data on demand, and do so typically into m_elems[] at a particular index using
262 // SetElem() & GetElem(). That is, they wrap SetElem() and GetElem().
263 // To get the data to reload on demand, first SetProjectFullName(),
264 // then call SetElem( ELEM_T, NULL ) from client code.
265
266 // non-virtuals resident in PCBNEW link image(s). By being non-virtual, these
267 // functions can get linked into the KIFACE that needs them, and only there.
268 // In fact, the other KIFACEs don't even know they exist.
269#if defined( PCBNEW ) || defined( CVPCB )
274
282 S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
283
285 FILENAME_RESOLVER* Get3DFilenameResolver();
286#endif
287
288
289#if defined( EESCHEMA )
290 // These are all prefaced with "Sch"
291 SYMBOL_LIBS* SchLibs();
292
294 SEARCH_STACK* SchSearchS();
295
297 SYMBOL_LIB_TABLE* SchSymbolLibTable();
298
300 FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
301#endif
302
303private:
304 friend class SETTINGS_MANAGER; // so that SM can set project path
305 friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
306
314 virtual void setProjectFullName( const wxString& aFullPathAndName );
315
323 virtual void setProjectFile( PROJECT_FILE* aFile )
324 {
325 m_projectFile = aFile;
326 }
327
335 virtual void setLocalSettings( PROJECT_LOCAL_SETTINGS* aSettings )
336 {
337 m_localSettings = aSettings;
338 }
339
343 const wxString libTableName( const wxString& aLibTableName ) const;
344
345 wxFileName m_project_name;
347
350
353
356
357 std::map<KIID, wxString> m_sheetNames;
358
361
364};
365
366
367#endif // PROJECT_H_
Provide an extensible class to resolve 3D model paths.
Definition: kiid.h:47
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:267
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
Definition: config_params.h:82
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:74
virtual KICAD_T Type()=0
virtual ~_ELEM()
Definition: project.h:76
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
The project local settings are things that are attached to a particular project, but also might be pa...
Container for project specific data.
Definition: project.h:63
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
Definition: project.h:352
virtual void SetReadOnly(bool aReadOnly=true)
Definition: project.h:126
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
Definition: project.h:323
virtual bool IsReadOnly() const
Definition: project.h:124
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:119
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:176
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:162
@ RSTRING_COUNT
Definition: project.h:179
@ VIEWER_3D_FILTER_INDEX
Definition: project.h:170
@ PCB_FOOTPRINT
Definition: project.h:173
@ VIEWER_3D_PATH
Definition: project.h:169
@ SCH_LIBEDIT_CUR_LIB
Definition: project.h:166
@ PCB_FOOTPRINT_EDITOR_FP_NAME
Definition: project.h:174
@ PCB_FOOTPRINT_EDITOR_LIB_NICKNAME
Definition: project.h:175
@ PCB_FOOTPRINT_VIEWER_FP_NAME
Definition: project.h:176
@ DOC_PATH
Definition: project.h:163
@ SCH_LIB_SELECT
Definition: project.h:165
@ PCB_LIB_NICKNAME
Definition: project.h:172
@ PCB_FOOTPRINT_VIEWER_LIB_NICKNAME
Definition: project.h:177
@ SCH_LIBEDIT_CUR_SYMBOL
Definition: project.h:167
@ SCH_LIB_PATH
Definition: project.h:164
wxString m_pro_date_and_time
True if the project is read-only: no project files will be written.
Definition: project.h:346
std::map< KIID, wxString > m_sheetNames
Definition: project.h:357
virtual void setLocalSettings(PROJECT_LOCAL_SETTINGS *aSettings)
Set the local settings backing store.
Definition: project.h:335
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:125
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:131
virtual const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Definition: project.cpp:143
virtual ~PROJECT()
Definition: project.cpp:63
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:318
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:154
virtual void ElemsClear()
Delete all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:52
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:155
virtual bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:69
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
virtual const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:238
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:360
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:149
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:283
friend class TEST_NETLISTS_FIXTURE
Definition: project.h:305
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:363
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:293
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:253
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:345
void Clear()
Clear the _ELEMs and RSTRINGs.
Definition: project.h:238
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition: project.h:355
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:304
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:193
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
Definition: project.cpp:87
bool m_readOnly
Definition: project.h:349
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:81
PROJECT()
Definition: project.cpp:43
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
Definition: project.cpp:264
ELEM_T
The set of #_ELEMs that a PROJECT can hold.
Definition: project.h:204
@ ELEM_SYMBOL_LIB_TABLE
Definition: project.h:210
@ ELEM_SCH_SEARCH_STACK
Definition: project.h:208
@ ELEM_3DCACHE
Definition: project.h:209
@ ELEM_COUNT
Definition: project.h:212
@ ELEM_FPTBL
Definition: project.h:205
@ ELEM_SCH_SYMBOL_LIBS
Definition: project.h:207
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:137
Cache for storing the 3D shapes.
Definition: 3d_cache.h:53
Look for files in a number of paths.
Definition: search_stack.h:42
A collection of SYMBOL_LIB objects.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78