KiCad PCB EDA Suite
fp_lib_table.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) 2010-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2012-2017 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2012-2017 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef FP_LIB_TABLE_H_
27 #define FP_LIB_TABLE_H_
28 
29 #include <lib_table_base.h>
30 #include <io_mgr.h>
31 
32 class MODULE;
33 class FP_LIB_TABLE_GRID;
34 
35 
43 {
44  friend class FP_LIB_TABLE;
45 
46 public:
48 
49  FP_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
50  const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
51  LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
52  {
53  SetType( aType );
54  }
55 
57  type( IO_MGR::KICAD_SEXP )
58  {
59  }
60 
61  bool operator==( const FP_LIB_TABLE_ROW& aRow ) const;
62 
63  bool operator!=( const FP_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
64 
70  const wxString GetType() const override { return IO_MGR::ShowType( type ); }
71 
77  void SetType( const wxString& aType ) override;
78 
79 protected:
81  LIB_TABLE_ROW( aRow ),
82  type( aRow.type )
83  {
84  }
85 
86 private:
87 
88  virtual LIB_TABLE_ROW* do_clone() const override
89  {
90  return new FP_LIB_TABLE_ROW( *this );
91  }
92 
93  void setPlugin( PLUGIN* aPlugin )
94  {
95  plugin.set( aPlugin );
96  }
97 
99  LIB_T type;
100 };
101 
102 
103 class FP_LIB_TABLE : public LIB_TABLE
104 {
105  friend class FP_LIB_TABLE_GRID;
106 
107 public:
108  KICAD_T Type() override { return FP_LIB_TABLE_T; }
109 
110  virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
111 
112  virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
113 
124  FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL );
125 
126 
127  bool operator==( const FP_LIB_TABLE& aFpTable ) const;
128 
129  bool operator!=( const FP_LIB_TABLE& r ) const { return !( *this == r ); }
130 
140  const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
141 
142  //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
143 
153  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname );
154 
159  long long GenerateTimestamp( const wxString* aNickname );
160 
172  void PrefetchLib( const wxString& aNickname );
173 
188  MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName );
189 
195  bool FootprintExists( const wxString& aNickname, const wxString& aFootprintName );
196 
204  const MODULE* GetEnumeratedFootprint( const wxString& aNickname,
205  const wxString& aFootprintName );
210  enum SAVE_T
211  {
214  };
215 
234  SAVE_T FootprintSave( const wxString& aNickname, const MODULE* aFootprint,
235  bool aOverwrite = true );
236 
248  void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );
249 
258  bool IsFootprintLibWritable( const wxString& aNickname );
259 
260  void FootprintLibDelete( const wxString& aNickname );
261 
262  void FootprintLibCreate( const wxString& aNickname );
263 
264  //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
265 
278  MODULE* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId );
279 
293  static bool LoadGlobalTable( FP_LIB_TABLE& aTable );
294 
300  static wxString GetGlobalTableFileName();
301 
311  static const wxString GlobalPathEnvVariableName();
312 };
313 
314 
315 extern FP_LIB_TABLE GFootprintTable; // KIFACE scope.
316 
317 #endif // FP_LIB_TABLE_H_
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:93
bool operator!=(const FP_LIB_TABLE &r) const
Definition: fp_lib_table.h:129
bool IsFootprintLibWritable(const wxString &aNickname)
Function IsFootprintLibWritable.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE...
void Format(OUTPUTFORMATTER *out, int nestLevel) const
Serialize this object as utf8 text to an OUTPUTFORMATTER, and tries to make it look good using multip...
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
bool operator!=(const FP_LIB_TABLE_ROW &aRow) const
Definition: fp_lib_table.h:63
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
virtual LIB_TABLE_ROW * do_clone() const override
Definition: fp_lib_table.h:88
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:333
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void FootprintLibDelete(const wxString &aNickname)
friend class FP_LIB_TABLE
Definition: fp_lib_table.h:44
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
IO_MGR::PCB_FILE_T LIB_T
Definition: fp_lib_table.h:47
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname...
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:563
Class IO_MGR is a factory which returns an instance of a PLUGIN.
Definition: io_mgr.h:43
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Function LoadGlobalTable loads the global footprint library table into aTable.
const MODULE * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
Function GetEnumeratedFootprint.
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:591
void PrefetchLib(const wxString &aNickname)
Function PrefetchLib If possible, prefetches the specified library (e.g.
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
KICAD_T Type() override
Definition: fp_lib_table.h:108
FP_LIB_TABLE_ROW(const FP_LIB_TABLE_ROW &aRow)
Definition: fp_lib_table.h:80
void FootprintLibCreate(const wxString &aNickname)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
FP_LIB_TABLE_ROW(const wxString &aNick, const wxString &aURI, const wxString &aType, const wxString &aOptions, const wxString &aDescr=wxEmptyString)
Definition: fp_lib_table.h:49
SAVE_T
Enum SAVE_T is the set of return values from FootprintSave() below.
Definition: fp_lib_table.h:210
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
static void Parse(std::unique_ptr< LIB_TABLE_ROW > &aRow, LIB_TABLE_LEXER *in)
MODULE * FootprintLoadWithOptionalNickname(const LIB_ID &aFootprintId)
Function FootprintLoadWithOptionalNickname loads a footprint having aFootprintId with possibly an emp...
void SetType(const wxString &aType) override
Function SetType.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname)
Return a list of footprint names contained within the library given by aNickname. ...
SAVE_T FootprintSave(const wxString &aNickname, const MODULE *aFootprint, bool aOverwrite=true)
Function FootprintSave.
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintDelete.
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:52
const wxString GetType() const override
Function GetType.
Definition: fp_lib_table.h:70
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintExists.
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.