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 
51 #define VTBL_ENTRY virtual
52 
59 class PROJECT
60 {
61 public:
62 
69  class _ELEM
70  {
71  public:
72  virtual ~_ELEM() {}
73 
74  virtual KICAD_T Type() = 0; // Sanity-checking for returned values.
75  };
76 
77  PROJECT();
79 
80  //-----<Cross Module API>----------------------------------------------------
81 
82  // VTBL_ENTRY bool MaybeLoadProjectSettings( const std::vector<wxString>& aFileSet );
83 
92  VTBL_ENTRY void SetProjectFullName( const wxString& aFullPathAndName );
93 
99  VTBL_ENTRY const wxString GetProjectFullName() const;
100 
106  VTBL_ENTRY const wxString GetProjectPath() const;
107 
113  VTBL_ENTRY const wxString GetProjectName() const;
114 
118  VTBL_ENTRY const wxString GetSheetName( const KIID& aSheetID );
119 
125  VTBL_ENTRY const wxString FootprintLibTblName() const;
126 
130  VTBL_ENTRY const wxString SymbolLibTableName() const;
131 
145  VTBL_ENTRY void ConfigSave( const SEARCH_STACK& aSList, const wxString& aGroupName,
146  const std::vector<PARAM_CFG*>& aParams,
147  const wxString& aFileName = wxEmptyString );
148 
167  VTBL_ENTRY bool ConfigLoad( const SEARCH_STACK& aSearchS, const wxString& aGroupName,
168  const std::vector<PARAM_CFG*>& aParams,
169  const wxString& aForeignConfigFileName = wxEmptyString );
170 
173  {
176  SCH_LIB_SELECT, // eeschema/selpart.cpp
178  SCH_LIBEDIT_CUR_PART, // eeschema/libeditframe.cpp
179 
182 
189 
191  };
192 
199  VTBL_ENTRY const wxString& GetRString( RSTRING_T aStringId );
200 
207  VTBL_ENTRY void SetRString( RSTRING_T aStringId, const wxString& aString );
208 
213  enum ELEM_T
214  {
216 
221 
223  };
224 
234  VTBL_ENTRY _ELEM* GetElem( ELEM_T aIndex );
235  VTBL_ENTRY void SetElem( ELEM_T aIndex, _ELEM* aElem );
236 
241  VTBL_ENTRY void ElemsClear();
242 
247  void Clear() // inline not virtual
248  {
249  ElemsClear();
250 
251  for( unsigned i = 0; i<RSTRING_COUNT; ++i )
252  SetRString( RSTRING_T( i ), wxEmptyString );
253  }
254 
261  VTBL_ENTRY const wxString AbsolutePath( const wxString& aFileName ) const;
262 
268 
269  //-----</Cross Module API>---------------------------------------------------
270 
271  //-----<KIFACE Specific APIs>------------------------------------------------
272 
273  // These are the non-virtual DATA LOAD ON DEMAND members. They load project related
274  // data on demand, and do so typicallly into m_elems[] at a particular index using
275  // SetElem() & GetElem(). That is, they wrap SetElem() and GetElem().
276  // To get the data to reload on demand, first SetProjectFullName(),
277  // then call SetElem( ELEM_T, NULL ) from client code.
278 
279  // non-virtuals resident in PCBNEW link image(s). By being non-virtual, these
280  // functions can get linked into the KIFACE that needs them, and only there.
281  // In fact, the other KIFACEs don't even know they exist.
282 #if defined(PCBNEW) || defined(CVPCB)
283 
288 
296  S3D_CACHE* Get3DCacheManager( bool updateProjDir = false );
297 
299  FILENAME_RESOLVER* Get3DFilenameResolver();
300 #endif
301 
302 
303 #if defined(EESCHEMA)
304  // These are all prefaced with "Sch"
305  PART_LIBS* SchLibs();
306 
308  SEARCH_STACK* SchSearchS();
309 
311  SYMBOL_LIB_TABLE* SchSymbolLibTable();
312 
314  FILENAME_RESOLVER* Get3DFilenameResolver() { return nullptr; }
315 #endif
316 
317  //-----</KIFACE Specific APIs>-----------------------------------------------
318 
319 private:
320 
329  wxConfigBase* configCreate( const SEARCH_STACK& aSList,
330  const wxString& aGroupName, const wxString& aProjectFileName = wxEmptyString );
331 
335  const wxString libTableName( const wxString& aLibTableName ) const;
336 
337  wxFileName m_project_name;
339 
340  std::map<KIID, wxString> m_sheetNames;
341 
344 
347 };
348 
349 
350 //-----<possible futures>---------------------------------------------------------
351 
352 #if 0
353 
364  VTBL_ENTRY bool Value( const wxString& aVariable, wxString* aFetchedValue = NULL );
365 
372  VTBL_ENTRY const wxString Substitute( const wxString& aString );
373 
381  VTBL_ENTRY const wxString SubstituteAndEvaluate( const wxString& aString );
382 #endif
383 
384 #endif // PROJECT_H_
wxConfigBase * configCreate(const SEARCH_STACK &aSList, const wxString &aGroupName, const wxString &aProjectFileName=wxEmptyString)
Function configCreate loads a *.pro file and returns a wxConfigBase.
Definition: project.cpp:318
_ELEM * m_elems[ELEM_COUNT]
Definition: project.h:346
void Clear()
Function Clear clears the _ELEMs and RSTRINGs.
Definition: project.h:247
PROJECT holds project specific data.
Definition: project.h:59
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:232
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:102
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:413
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:244
VTBL_ENTRY bool ConfigLoad(const SEARCH_STACK &aSearchS, const wxString &aGroupName, const std::vector< PARAM_CFG * > &aParams, const wxString &aForeignConfigFileName=wxEmptyString)
Function ConfigLoad reads a subset of parameters from the "project" file.
Definition: project.cpp:385
Definition: common.h:65
#define NULL
wxFileName m_project_name
<fullpath>/<basename>.pro
Definition: project.h:337
VTBL_ENTRY const wxString GetSheetName(const KIID &aSheetID)
Return the name of the sheet identified by the given UUID.
Definition: project.cpp:171
VTBL_ENTRY void ConfigSave(const SEARCH_STACK &aSList, const wxString &aGroupName, const std::vector< PARAM_CFG * > &aParams, const wxString &aFileName=wxEmptyString)
Function ConfigSave saves the current "project" parameters into the wxConfigBase* derivative.
Definition: project.cpp:350
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
VTBL_ENTRY void SetProjectFullName(const wxString &aFullPathAndName)
Function SetProjectFullName sets the: 1) full directory, 2) basename, and 3) extension of the project...
Definition: project.cpp:64
VTBL_ENTRY void ElemsClear()
Function ElemsClear deletes all the _ELEMs and set their pointers to NULL.
Definition: project.cpp:47
PROJECT()
Definition: project.cpp:41
VTBL_ENTRY const wxString SymbolLibTableName() const
Return the path and file name of this projects symbol library table.
Definition: project.cpp:114
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:198
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:427
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:213
ELEM_T
Enum ELEM_T is the set of _ELEMs that a PROJECT can hold.
Definition: project.h:213
#define VTBL_ENTRY
Definition: project.h:51
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:98
RSTRING_T
Retain a number of project specific wxStrings, enumerated here:
Definition: project.h:172
wxString m_rstrings[RSTRING_COUNT]
Definition: project.h:343
The common library.
std::map< KIID, wxString > m_sheetNames
Definition: project.h:340
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:69
VTBL_ENTRY const wxString GetProjectName() const
Function GetProjectName returns the short name of the project.
Definition: project.cpp:108
wxString m_pro_date_and_time
Definition: project.h:338
virtual ~_ELEM()
Definition: project.h:72
VTBL_ENTRY ~PROJECT()
Definition: project.cpp:58
VTBL_ENTRY const wxString FootprintLibTblName() const
Function FootprintLibTblName returns the path and filename of this project's fp-lib-table,...
Definition: project.cpp:120
const wxString libTableName(const wxString &aLibTableName) const
Return the full path and file name of the project specific library table aLibTableName.
Definition: project.cpp:126