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 )
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 
109  virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
110 
111  virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
112 
123  FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = NULL );
124 
134  const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName ) throw( IO_ERROR );
135 
136  //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
137 
149  wxArrayString FootprintEnumerate( const wxString& aNickname );
150 
162  void PrefetchLib( const wxString& aNickname );
163 
178  MODULE* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName );
179 
184  enum SAVE_T
185  {
188  };
189 
208  SAVE_T FootprintSave( const wxString& aNickname, const MODULE* aFootprint,
209  bool aOverwrite = true );
210 
222  void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );
223 
232  bool IsFootprintLibWritable( const wxString& aNickname );
233 
234  void FootprintLibDelete( const wxString& aNickname );
235 
236  void FootprintLibCreate( const wxString& aNickname );
237 
238  //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
239 
252  MODULE* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId )
253  throw( IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception );
254 
268  static bool LoadGlobalTable( FP_LIB_TABLE& aTable )
269  throw (IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception );
270 
276  static wxString GetGlobalTableFileName();
277 
287  static const wxString GlobalPathEnvVariableName();
288 };
289 
290 
291 extern FP_LIB_TABLE GFootprintTable; // KIFACE scope.
292 
293 #endif // FP_LIB_TABLE_H_
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:93
bool IsFootprintLibWritable(const wxString &aNickname)
Function IsFootprintLibWritable.
Class LIB_TABLE_ROW.
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
wxArrayString FootprintEnumerate(const wxString &aNickname)
Function FootprintEnumerate returns a list of footprint names contained within the library given by a...
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
FP_LIB_TABLE(FP_LIB_TABLE *aFallBackTable=NULL)
Constructor FP_LIB_TABLE.
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:321
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:105
Class LIB_ID.
Definition: lib_id.h:56
void FootprintLibDelete(const wxString &aNickname)
IO_MGR::PCB_FILE_T LIB_T
Definition: fp_lib_table.h:47
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:98
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:476
Class IO_MGR is a factory which returns an instance of a PLUGIN.
Definition: io_mgr.h:42
static const wxString GlobalPathEnvVariableName()
Function GlobalPathEnvVarVariableName.
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Function Parse.
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Function LoadGlobalTable loads the global footprint library table into aTable.
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:504
void PrefetchLib(const wxString &aNickname)
Function PrefetchLib If possible, prefetches the specified library (e.g.
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Function Format.
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:184
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:193
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
Class LIB_TABLE_LEXER is an automatically generated class using the TokenList2DnsLexer.cmake technology, based on keywords provided by file: /home/kicad/workspace/kicad-doxygen/common/lib_table.keywords.
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.
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:51
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
const wxString GetType() const override
Function GetType.
Definition: fp_lib_table.h:70
static wxString GetGlobalTableFileName()
Function GetGlobalTableFileName.
Class LIB_TABLE.