KiCad PCB EDA Suite
symbol_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) 2016 Wayne Stambaugh <stambaughw@gmail.com>
5  * Copyright (C) 2016-2017 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef _SYMBOL_LIB_TABLE_H_
26 #define _SYMBOL_LIB_TABLE_H_
27 
28 #include <lib_table_base.h>
29 #include <sch_io_mgr.h>
30 #include <lib_id.h>
31 #include <class_libentry.h>
32 
33 //class LIB_PART;
35 class DIALOG_SYMBOL_LIB_TABLE;
36 
37 
43 {
44  friend class SYMBOL_LIB_TABLE;
45 
46 public:
47  typedef SCH_IO_MGR::SCH_FILE_T LIB_T;
48 
49  SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
50  const wxString& aOptions = wxEmptyString,
51  const wxString& aDescr = wxEmptyString ) :
52  LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
53  {
54  SetType( aType );
55  SetEnabled( true );
56  }
57 
59  type( SCH_IO_MGR::SCH_LEGACY )
60  {
61  SetEnabled( true );
62  }
63 
64  bool operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const;
65 
66  bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
67 
71  const wxString GetType() const override { return SCH_IO_MGR::ShowType( type ); }
72 
76  void SetType( const wxString& aType ) override;
77 
78 protected:
80  LIB_TABLE_ROW( aRow ),
81  type( aRow.type )
82  {
83  SetEnabled( aRow.GetIsEnabled() );
84  }
85 
86 private:
87 
88  virtual LIB_TABLE_ROW* do_clone() const override
89  {
90  return new SYMBOL_LIB_TABLE_ROW( *this );
91  }
92 
93  void setPlugin( SCH_PLUGIN* aPlugin )
94  {
95  plugin.set( aPlugin );
96  }
97 
100 };
101 
102 
104 {
105  friend class SYMBOL_LIB_TABLE_GRID;
106  friend class PANEL_SYM_LIB_TABLE;
107 
108  static int m_modifyHash;
109 
110 public:
111  KICAD_T Type() override { return SYMBOL_LIB_TABLE_T; }
112 
113  static const char* PropPowerSymsOnly;
114  static const char* PropNonPowerSymsOnly;
115 
116  virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
117 
118  virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
119 
128  SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = NULL );
129 
143  SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
144 
145  int GetModifyHash();
146 
147  //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
148 
158  void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
159  bool aPowerSymbolsOnly = false );
160 
161  void LoadSymbolLib( std::vector<LIB_PART*>& aAliasList, const wxString& aNickname,
162  bool aPowerSymbolsOnly = false );
163 
176  LIB_PART* LoadSymbol( const wxString& aNickname, const wxString& aName );
177 
178  LIB_PART* LoadSymbol( const LIB_ID& aLibId )
179  {
180  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
181  }
182 
186  enum SAVE_T
187  {
190  };
191 
210  SAVE_T SaveSymbol( const wxString& aNickname, const LIB_PART* aSymbol,
211  bool aOverwrite = true );
212 
222  void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
223 
234  bool IsSymbolLibWritable( const wxString& aNickname );
235 
236  void DeleteSymbolLib( const wxString& aNickname );
237 
238  void CreateSymbolLib( const wxString& aNickname );
239 
240  //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
241 
254 
268  static bool LoadGlobalTable( SYMBOL_LIB_TABLE& aTable );
269 
276  static wxString GetGlobalTableFileName();
277 
286  static const wxString GlobalPathEnvVariableName();
287 
289 
290  static const wxString& GetSymbolLibTableFileName();
291 };
292 
293 
294 #endif // _SYMBOL_LIB_TABLE_H_
SCH_IO_MGR is a factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:45
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_PART *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
static const wxString & GetSymbolLibTableFileName()
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
SYMBOL_LIB_TABLE(SYMBOL_LIB_TABLE *aFallBackTable=NULL)
Build a symbol library table by pre-pending this table fragment in front of aFallBackTable.
SYMBOL_LIB_TABLE_ROW(const SYMBOL_LIB_TABLE_ROW &aRow)
void CreateSymbolLib(const wxString &aNickname)
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
void DeleteSymbolLib(const wxString &aNickname)
void SetType(const wxString &aType) override
Change the schematic plugin type represented by this row.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:79
LIB_PART * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_PART having aName from the library given by aNickname.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
bool operator!=(const SYMBOL_LIB_TABLE_ROW &aRow) const
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:544
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
bool operator==(const SYMBOL_LIB_TABLE_ROW &aRow) const
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:201
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
bool GetIsEnabled() const
#define NULL
KICAD_T Type() override
Class LIB_PIN definition.
const wxString GetType() const override
Return the type of symbol library table represented by this row.
void LoadSymbolLib(std::vector< LIB_PART * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
Define a library symbol object.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
Dialog to show and edit symbol library tables.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indention level of aIndentLevel.
void setPlugin(SCH_PLUGIN *aPlugin)
SCH_IO_MGR::SCH_FILE_T LIB_T
LIB_PART * LoadSymbol(const LIB_ID &aLibId)
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:516
virtual LIB_TABLE_ROW * do_clone() const override
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
static int m_modifyHash
helper for GetModifyHash()
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...
SAVE_T
The set of return values from SaveSymbol() below.
static const char * PropNonPowerSymsOnly
LIB_PART * LoadSymbolWithOptionalNickname(const LIB_ID &aId)
Load a LIB_PART having aFootprintId with possibly an empty library nickname.
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
static const char * PropPowerSymsOnly
SYMBOL_LIB_TABLE_ROW(const wxString &aNick, const wxString &aURI, const wxString &aType, const wxString &aOptions=wxEmptyString, const wxString &aDescr=wxEmptyString)
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.