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 
30 #include <vector>
31 #include <wx/string.h>
32 #include <wx/filename.h>
33 #include <core/typeinfo.h>
34 #include <common.h>
35 
38 #define PROJECT_VAR_NAME wxT( "KIPRJMOD" )
39 
40 
41 class wxConfigBase;
42 class PARAM_CFG;
43 class FP_LIB_TABLE;
44 class PART_LIBS;
45 class SEARCH_STACK;
46 class S3D_CACHE;
47 class KIWAY;
48 class SYMBOL_LIB_TABLE;
49 class FILENAME_RESOLVER;
50 class PROJECT_FILE;
52 
53 #define VTBL_ENTRY virtual
54 
61 class PROJECT
62 {
63  friend class SETTINGS_MANAGER; // so that SM can set project path
64  friend class TEST_NETLISTS_FIXTURE; // TODO(JE) make this not required
65 
66 public:
67 
74  class _ELEM
75  {
76  public:
77  virtual ~_ELEM() {}
78 
79  virtual KICAD_T Type() = 0; // Sanity-checking for returned values.
80  };
81 
82  PROJECT();
84 
85  //-----<Cross Module API>----------------------------------------------------
86 
87  VTBL_ENTRY bool TextVarResolver( wxString* aToken ) const;
88 
89  VTBL_ENTRY std::map<wxString, wxString>& GetTextVars() const;
90 
96  VTBL_ENTRY const wxString GetProjectFullName() const;
97 
103  VTBL_ENTRY const wxString GetProjectPath() const;
104 
110  VTBL_ENTRY const wxString GetProjectName() const;
111 
118  VTBL_ENTRY bool IsNullProject() const;
119 
120  VTBL_ENTRY bool IsReadOnly() const { return m_readOnly || IsNullProject(); }
121 
122  VTBL_ENTRY void SetReadOnly( bool aReadOnly = true ) { m_readOnly = aReadOnly; }
123 
127  VTBL_ENTRY const wxString GetSheetName( const KIID& aSheetID );
128 
134  VTBL_ENTRY const wxString FootprintLibTblName() const;
135 
139  VTBL_ENTRY const wxString SymbolLibTableName() const;
140 
142  {
143  wxASSERT( m_projectFile );
144  return *m_projectFile;
145  }
146 
148  {
149  wxASSERT( m_localSettings );
150  return *m_localSettings;
151  }
152 
155  {
158  SCH_LIB_SELECT, // eeschema/selpart.cpp
160  SCH_LIBEDIT_CUR_PART, // eeschema/libeditframe.cpp
161 
164 
171 
173  };
174 
181  VTBL_ENTRY const wxString& GetRString( RSTRING_T aStringId );
182 
189  VTBL_ENTRY void SetRString( RSTRING_T aStringId, const wxString& aString );
190 
195  enum ELEM_T
196  {
198 
203 
205  };
206 
216  VTBL_ENTRY _ELEM* GetElem( ELEM_T aIndex );
217  VTBL_ENTRY void SetElem( ELEM_T aIndex, _ELEM* aElem );
218 
223  VTBL_ENTRY void ElemsClear();
224 
229  void Clear() // inline not virtual
230  {
231  ElemsClear();
232 
233  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
234  SetRString( RSTRING_T( i ), wxEmptyString );
235  }
236 
243  VTBL_ENTRY const wxString AbsolutePath( const wxString& aFileName ) const;
244 
250 
251  //-----</Cross Module API>---------------------------------------------------
252 
253  //-----<KIFACE Specific APIs>------------------------------------------------
254 
255  // These are the non-virtual DATA LOAD ON DEMAND members. They load project related
256  // data on demand, and do so typicallly into m_elems[] at a particular index using
257  // SetElem() & GetElem(). That is, they wrap SetElem() and GetElem().
258  // To get the data to reload on demand, first SetProjectFullName(),
259  // then call SetElem( ELEM_T, NULL ) from client code.
260 
261  // non-virtuals resident in PCBNEW link image(s). By being non-virtual, these
262  // functions can get linked into the KIFACE that needs them, and only there.
263  // In fact, the other KIFACEs don't even know they exist.
264 #if defined(PCBNEW) || defined(CVPCB)
265 
270 
278  S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
279 
281  FILENAME_RESOLVER* Get3DFilenameResolver();
282 #endif
283 
284 
285 #if defined(EESCHEMA)
286  // These are all prefaced with "Sch"
287  PART_LIBS* SchLibs();
288 
290  SEARCH_STACK* SchSearchS();
291 
293  SYMBOL_LIB_TABLE* SchSymbolLibTable();
294 
296  FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
297 #endif
298 
299  //-----</KIFACE Specific APIs>-----------------------------------------------
300 
301 private:
302 
310  VTBL_ENTRY void setProjectFullName( const wxString& aFullPathAndName );
311 
318  {
319  m_projectFile = aFile;
320  }
321 
327  {
328  m_localSettings = aSettings;
329  }
330 
334  const wxString libTableName( const wxString& aLibTableName ) const;
335 
336  wxFileName m_project_name;
338 
341 
344 
347 
348  std::map<KIID, wxString> m_sheetNames;
349 
352 
355 };
356 
357 
358 #endif // PROJECT_H_
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:354
void Clear()
Function Clear clears the _ELEMs and RSTRINGs.
Definition: project.h:229
VTBL_ENTRY std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:80
PROJECT holds project specific data.
Definition: project.h:61
bool m_readOnly
True if the project is read-only: no project files will be written
Definition: project.h:340
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:317
VTBL_ENTRY PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:147
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:248
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:124
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:272
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:260
Definition: common.h:68
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:336
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:141
VTBL_ENTRY const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:199
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:326
VTBL_ENTRY bool TextVarResolver(wxString *aToken) const
Definition: project.cpp:68
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:118
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:51
VTBL_ENTRY bool IsNullProject() const
Checks if this project is a null project (i.e.
Definition: project.cpp:136
PROJECT()
Definition: project.cpp:42
VTBL_ENTRY void setProjectFullName(const wxString &aFullPathAndName)
Sets the: 1) full directory, 2) basename, and 3) extension of the project.
Definition: project.cpp:86
VTBL_ENTRY const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Definition: project.cpp:142
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:214
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:286
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:229
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:195
#define VTBL_ENTRY
Definition: project.h:53
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:154
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:351
VTBL_ENTRY bool IsReadOnly() const
Definition: project.h:120
The common library.
std::map< KIID, wxString > m_sheetNames
Definition: project.h:348
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:74
PROJECT_FILE * m_projectFile
Backing store for project data – owned by SETTINGS_MANAGER.
Definition: project.h:343
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:130
wxString m_pro_date_and_time
Definition: project.h:337
virtual ~_ELEM()
Definition: project.h:77
VTBL_ENTRY ~PROJECT()
Definition: project.cpp:62
VTBL_ENTRY void SetReadOnly(bool aReadOnly=true)
Definition: project.h:122
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
Definition: project.cpp:148
PROJECT_LOCAL_SETTINGS * m_localSettings
Backing store for project local settings – owned by SETTINGS_MANAGER.
Definition: project.h:346
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:154