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 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2012-2021 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 FOOTPRINT;
33 class FP_LIB_TABLE_GRID;
34 
35 
41 {
42 public:
44 
45  FP_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
46  const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
47  LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
48  {
49  SetType( aType );
50  }
51 
53  type( IO_MGR::KICAD_SEXP )
54  {
55  }
56 
57  bool operator==( const FP_LIB_TABLE_ROW& aRow ) const;
58 
59  bool operator!=( const FP_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
60 
64  const wxString GetType() const override { return IO_MGR::ShowType( type ); }
65 
69  void SetType( const wxString& aType ) override;
70 
71 protected:
73  LIB_TABLE_ROW( aRow ),
74  type( aRow.type )
75  {
76  }
77 
78 private:
79  virtual LIB_TABLE_ROW* do_clone() const override
80  {
81  return new FP_LIB_TABLE_ROW( *this );
82  }
83 
84  void setPlugin( PLUGIN* aPlugin )
85  {
86  plugin.set( aPlugin );
87  }
88 
89  friend class FP_LIB_TABLE;
90 
93 };
94 
95 
96 class FP_LIB_TABLE : public LIB_TABLE
97 {
98 public:
99  KICAD_T Type() override { return FP_LIB_TABLE_T; }
100 
101  virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
102 
103  virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
104 
113  FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable = nullptr );
114 
115  bool operator==( const FP_LIB_TABLE& aFpTable ) const;
116 
117  bool operator!=( const FP_LIB_TABLE& r ) const { return !( *this == r ); }
118 
134  const FP_LIB_TABLE_ROW* FindRow( const wxString& aNickName, bool aCheckIfEnabled = false );
135 
145  void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aNickname,
146  bool aBestEfforts );
147 
152  long long GenerateTimestamp( const wxString* aNickname );
153 
164  void PrefetchLib( const wxString& aNickname );
165 
179  FOOTPRINT* FootprintLoad( const wxString& aNickname, const wxString& aFootprintName,
180  bool aKeepUUID = false );
181 
185  bool FootprintExists( const wxString& aNickname, const wxString& aFootprintName );
186 
193  const FOOTPRINT* GetEnumeratedFootprint( const wxString& aNickname,
194  const wxString& aFootprintName );
198  enum SAVE_T
199  {
202  };
203 
218  SAVE_T FootprintSave( const wxString& aNickname, const FOOTPRINT* aFootprint,
219  bool aOverwrite = true );
220 
229  void FootprintDelete( const wxString& aNickname, const wxString& aFootprintName );
230 
238  bool IsFootprintLibWritable( const wxString& aNickname );
239 
240  void FootprintLibDelete( const wxString& aNickname );
241 
242  void FootprintLibCreate( const wxString& aNickname );
243 
258  FOOTPRINT* FootprintLoadWithOptionalNickname( const LIB_ID& aFootprintId,
259  bool aKeepUUID = false );
260 
273  static bool LoadGlobalTable( FP_LIB_TABLE& aTable );
274 
278  static wxString GetGlobalTableFileName();
279 
288  static const wxString GlobalPathEnvVariableName();
289 
290 private:
291  friend class FP_LIB_TABLE_GRID;
292 };
293 
294 
295 extern FP_LIB_TABLE GFootprintTable; // KIFACE scope.
296 
297 #endif // FP_LIB_TABLE_H_
void setPlugin(PLUGIN *aPlugin)
Definition: fp_lib_table.h:84
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:40
FOOTPRINT * FootprintLoadWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID=false)
Load a footprint having aFootprintId with possibly an empty nickname.
FOOTPRINT * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName, bool aKeepUUID=false)
Load a footprint having aFootprintName from the library given by aNickname.
virtual LIB_TABLE_ROW * do_clone() const override
Definition: fp_lib_table.h:79
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:306
bool operator!=(const FP_LIB_TABLE &r) const
Definition: fp_lib_table.h:117
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
Definition: cvpcb.cpp:120
static const wxString ShowType(PCB_FILE_T aFileType)
Return 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)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
IO_MGR::PCB_FILE_T LIB_T
Definition: fp_lib_table.h:43
PLUGIN::RELEASER plugin
Definition: fp_lib_table.h:91
long long GenerateTimestamp(const wxString *aNickname)
Generate a hashed timestamp representing the last-mod-times of the library indicated by aNickname,...
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:550
bool operator!=(const FP_LIB_TABLE_ROW &aRow) const
Definition: fp_lib_table.h:59
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aNickname, bool aBestEfforts)
Return a list of footprint names contained within the library given by aNickname.
A factory which returns an instance of a PLUGIN.
Definition: io_mgr.h:44
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
static bool LoadGlobalTable(FP_LIB_TABLE &aTable)
Load the global footprint library table into aTable.
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:578
void PrefetchLib(const wxString &aNickname)
If possible, prefetches the specified library (e.g.
KICAD_T Type() override
Definition: fp_lib_table.h:99
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aNickname, const wxString &aFootprintName)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
FP_LIB_TABLE_ROW(const FP_LIB_TABLE_ROW &aRow)
Definition: fp_lib_table.h:72
bool operator==(const FP_LIB_TABLE &aFpTable) const
void FootprintLibCreate(const wxString &aNickname)
FP_LIB_TABLE(FP_LIB_TABLE *aFallBackTable=nullptr)
Build a footprint library table by pre-pending this table fragment in front of aFallBackTable.
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:45
SAVE_T
The set of return values from FootprintSave() below.
Definition: fp_lib_table.h:198
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:267
SAVE_T FootprintSave(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void SetType(const wxString &aType) override
Change the type represented by this row.
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:52
bool operator==(const FP_LIB_TABLE_ROW &aRow) const
const wxString GetType() const override
return the type of footprint library table represented by this row.
Definition: fp_lib_table.h:64
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
static wxString GetGlobalTableFileName()
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.