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-2017 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 #define VTBL_ENTRY virtual
56 
63 class PROJECT
64 {
65  friend class SETTINGS_MANAGER; // so that SM can set project path
66  friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
67 
68 public:
69 
76  class _ELEM
77  {
78  public:
79  virtual ~_ELEM() {}
80 
81  virtual KICAD_T Type() = 0; // Sanity-checking for returned values.
82  };
83 
84  PROJECT();
86 
87  //-----<Cross Module API>----------------------------------------------------
88 
89  VTBL_ENTRY bool TextVarResolver( wxString* aToken ) const;
90 
91  VTBL_ENTRY std::map<wxString, wxString>& GetTextVars() const;
92 
98  VTBL_ENTRY const wxString GetProjectFullName() const;
99 
105  VTBL_ENTRY const wxString GetProjectPath() const;
106 
112  VTBL_ENTRY const wxString GetProjectName() const;
113 
120  VTBL_ENTRY bool IsNullProject() const;
121 
122  VTBL_ENTRY bool IsReadOnly() const { return m_readOnly || IsNullProject(); }
123 
124  VTBL_ENTRY void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
125 
129  VTBL_ENTRY const wxString GetSheetName( const KIID& aSheetID );
130 
136  VTBL_ENTRY const wxString FootprintLibTblName() const;
137 
141  VTBL_ENTRY const wxString SymbolLibTableName() const;
142 
144  {
145  wxASSERT( m_projectFile );
146  return *m_projectFile;
147  }
148 
150  {
151  wxASSERT( m_localSettings );
152  return *m_localSettings;
153  }
154 
157  {
160  SCH_LIB_SELECT, // eeschema/selpart.cpp
162  SCH_LIBEDIT_CUR_PART, // eeschema/libeditframe.cpp
163 
166 
173 
175  };
176 
183  VTBL_ENTRY const wxString& GetRString( RSTRING_T aStringId );
184 
191  VTBL_ENTRY void SetRString( RSTRING_T aStringId, const wxString& aString );
192 
197  enum ELEM_T
198  {
200 
205 
207  };
208 
218  VTBL_ENTRY _ELEM* GetElem( ELEM_T aIndex );
219  VTBL_ENTRY void SetElem( ELEM_T aIndex, _ELEM* aElem );
220 
225  VTBL_ENTRY void ElemsClear();
226 
231  void Clear() // inline not virtual
232  {
233  ElemsClear();
234 
235  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
236  SetRString( RSTRING_T( i ), wxEmptyString );
237  }
238 
245  VTBL_ENTRY const wxString AbsolutePath( const wxString& aFileName ) const;
246 
252 
253  //-----</Cross Module API>---------------------------------------------------
254 
255  //-----<KIFACE Specific APIs>------------------------------------------------
256 
257  // These are the non-virtual DATA LOAD ON DEMAND members. They load project related
258  // data on demand, and do so typicallly 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 
272 
280  S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
281 
283  FILENAME_RESOLVER* Get3DFilenameResolver();
284 #endif
285 
286 
287 #if defined(EESCHEMA)
288  // These are all prefaced with "Sch"
289  PART_LIBS* SchLibs();
290 
292  SEARCH_STACK* SchSearchS();
293 
295  SYMBOL_LIB_TABLE* SchSymbolLibTable();
296 
298  FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
299 #endif
300 
301  //-----</KIFACE Specific APIs>-----------------------------------------------
302 
303 private:
304 
312  VTBL_ENTRY void setProjectFullName( const wxString& aFullPathAndName );
313 
320  {
321  m_projectFile = aFile;
322  }
323 
329  {
330  m_localSettings = aSettings;
331  }
332 
336  const wxString libTableName( const wxString& aLibTableName ) const;
337 
338  wxFileName m_project_name;
340 
343 
346 
349 
350  std::map<KIID, wxString> m_sheetNames;
351 
354 
357 };
358 
359 
360 #endif // PROJECT_H_
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:356
void Clear()
Function Clear clears the _ELEMs and RSTRINGs.
Definition: project.h:231
VTBL_ENTRY std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:78
PROJECT holds project specific data.
Definition: project.h:63
bool m_readOnly
True if the project is read-only: no project files will be written
Definition: project.h:342
VTBL_ENTRY void setProjectFile(PROJECT_FILE *aFile)
Sets the backing store file for this project Should only be called by SETTINGS_MANGER on load.
Definition: project.h:319
VTBL_ENTRY PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:149
The project local settings are things that are attached to a particular project, but also might be pa...
SEARCH_STACK looks for files in a number of places.
Definition: search_stack.h:41
VTBL_ENTRY _ELEM * GetElem(ELEM_T aIndex)
Typically wrapped somewhere else in a more meaningful function wrapper.
Definition: project.cpp:246
S3D_CACHE.
Definition: 3d_cache.h:54
VTBL_ENTRY const wxString GetProjectPath() const
Function GetProjectPath returns the full path of the project.
Definition: project.cpp:122
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:62
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
virtual KICAD_T Type()=0
VTBL_ENTRY const wxString AbsolutePath(const wxString &aFileName) const
Function AbsolutePath fixes up aFileName if it is relative to the project's directory to be an absolu...
Definition: project.cpp:270
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:258
Definition: kiid.h:44
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:338
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:143
VTBL_ENTRY const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:197
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
VTBL_ENTRY void setLocalSettings(PROJECT_LOCAL_SETTINGS *aSettings)
Sets the local settings backing store.
Definition: project.h:328
VTBL_ENTRY bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:66
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:116
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:49
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:134
PROJECT()
Definition: project.cpp:40
VTBL_ENTRY void setProjectFullName(const wxString &aFullPathAndName)
Sets the: 1) full directory, 2) basename, and 3) extension of the project.
Definition: project.cpp:84
VTBL_ENTRY const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Definition: project.cpp:140
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:212
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:284
A collection of PART_LIB objects.
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:227
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:197
#define VTBL_ENTRY
Definition: project.h:55
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:85
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:156
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:353
VTBL_ENTRY bool IsReadOnly() const
Definition: project.h:122
std::map< KIID, wxString > m_sheetNames
Definition: project.h:350
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:76
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
Definition: project.h:345
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:128
wxString m_pro_date_and_time
Definition: project.h:339
virtual ~_ELEM()
Definition: project.h:79
VTBL_ENTRY ~PROJECT()
Definition: project.cpp:60
VTBL_ENTRY void SetReadOnly(bool aReadOnly=true)
Definition: project.h:124
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
Definition: project.cpp:146
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition: project.h:348
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:152