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-2021 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/string.h>
33 #include <wx/filename.h>
34 #include <core/typeinfo.h>
35 
38 #define PROJECT_VAR_NAME wxT( "KIPRJMOD" )
39 
41 #define NAMELESS_PROJECT wxT( "noname" )
42 
43 class wxConfigBase;
44 class PARAM_CFG;
45 class FP_LIB_TABLE;
46 class PART_LIBS;
47 class SEARCH_STACK;
48 class S3D_CACHE;
49 class KIWAY;
50 class SYMBOL_LIB_TABLE;
51 class FILENAME_RESOLVER;
52 class PROJECT_FILE;
54 
55 
62 class PROJECT
63 {
64 public:
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  virtual PROJECT_FILE& GetProjectFile() const
146  {
147  wxASSERT( m_projectFile );
148  return *m_projectFile;
149  }
150 
152  {
153  wxASSERT( m_localSettings );
154  return *m_localSettings;
155  }
156 
159  {
162  SCH_LIB_SELECT, // eeschema/selpart.cpp
164  SCH_LIBEDIT_CUR_PART, // eeschema/libeditframe.cpp
165 
168 
175 
177  };
178 
186  virtual const wxString& GetRString( RSTRING_T aStringId );
187 
195  virtual void SetRString( RSTRING_T aStringId, const wxString& aString );
196 
200  enum ELEM_T
201  {
203 
208 
210  };
211 
224  virtual _ELEM* GetElem( ELEM_T aIndex );
225  virtual void SetElem( ELEM_T aIndex, _ELEM* aElem );
226 
230  virtual void ElemsClear();
231 
235  void Clear() // inline not virtual
236  {
237  ElemsClear();
238 
239  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
240  SetRString( RSTRING_T( i ), wxEmptyString );
241  }
242 
249  virtual const wxString AbsolutePath( const wxString& aFileName ) const;
250 
255  virtual FP_LIB_TABLE* PcbFootprintLibs( KIWAY& aKiway );
256 
257  // These are the non-virtual DATA LOAD ON DEMAND members. They load project related
258  // data on demand, and do so typically into m_elems[] at a particular index using
259  // SetElem() & GetElem(). That is, they wrap SetElem() and GetElem().
260  // To get the data to reload on demand, first SetProjectFullName(),
261  // then call SetElem( ELEM_T, NULL ) from client code.
262 
263  // non-virtuals resident in PCBNEW link image(s). By being non-virtual, these
264  // functions can get linked into the KIFACE that needs them, and only there.
265  // In fact, the other KIFACEs don't even know they exist.
266 #if defined( PCBNEW ) || defined( CVPCB )
267 
271 
279  S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
280 
282  FILENAME_RESOLVER* Get3DFilenameResolver();
283 #endif
284 
285 
286 #if defined( EESCHEMA )
287  // These are all prefaced with "Sch"
288  PART_LIBS* SchLibs();
289 
291  SEARCH_STACK* SchSearchS();
292 
294  SYMBOL_LIB_TABLE* SchSymbolLibTable();
295 
297  FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
298 #endif
299 
300 private:
301  friend class SETTINGS_MANAGER; // so that SM can set project path
302  friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
303 
311  virtual void setProjectFullName( const wxString& aFullPathAndName );
312 
320  virtual void setProjectFile( PROJECT_FILE* aFile )
321  {
322  m_projectFile = aFile;
323  }
324 
332  virtual void setLocalSettings( PROJECT_LOCAL_SETTINGS* aSettings )
333  {
334  m_localSettings = aSettings;
335  }
336 
340  const wxString libTableName( const wxString& aLibTableName ) const;
341 
342  wxFileName m_project_name;
344 
347 
350 
353 
354  std::map<KIID, wxString> m_sheetNames;
355 
358 
361 };
362 
363 
364 #endif // PROJECT_H_
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:360
virtual bool IsReadOnly() const
Definition: project.h:124
void Clear()
Clear the _ELEMs and RSTRINGs.
Definition: project.h:235
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:79
Container for project specific data.
Definition: project.h:62
bool m_readOnly
Definition: project.h:346
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
virtual void setLocalSettings(PROJECT_LOCAL_SETTINGS *aSettings)
Set the local settings backing store.
Definition: project.h:332
The project local settings are things that are attached to a particular project, but also might be pa...
Look for files in a number of paths.
Definition: search_stack.h:41
virtual _ELEM * GetElem(ELEM_T aIndex)
Get and set the elements for this project.
Definition: project.cpp:247
Cache for storing the 3D shapes.
Definition: 3d_cache.h:52
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:123
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
virtual KICAD_T Type()=0
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:271
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:151
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:259
Definition: kiid.h:44
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:342
virtual const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:198
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:67
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:117
virtual void ElemsClear()
Delete all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:50
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
Definition: project.cpp:135
PROJECT()
Definition: project.cpp:41
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
Definition: project.cpp:85
virtual const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Definition: project.cpp:141
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:213
virtual FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:285
A collection of PART_LIB objects.
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:228
ELEM_T
The set of #_ELEMs that a PROJECT can hold.
Definition: project.h:200
virtual void SetReadOnly(bool aReadOnly=true)
Definition: project.h:126
Provide an extensible class to resolve 3D model paths.
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
Definition: config_params.h:81
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:158
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:357
std::map< KIID, wxString > m_sheetNames
Definition: project.h:354
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:73
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
Definition: project.h:349
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:129
wxString m_pro_date_and_time
True if the project is read-only: no project files will be written.
Definition: project.h:343
virtual ~_ELEM()
Definition: project.h:76
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
Definition: project.h:320
virtual ~PROJECT()
Definition: project.cpp:61
virtual const wxString FootprintLibTblName() const
Returns the path and filename of this project's footprint library table.
Definition: project.cpp:147
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition: project.h:352
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:153