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 
32 class LIB_PART;
34 class DIALOG_SYMBOL_LIB_TABLE;
35 
36 
42 {
43  friend class SYMBOL_LIB_TABLE;
44 
45 public:
46  typedef SCH_IO_MGR::SCH_FILE_T LIB_T;
47 
48  SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
49  const wxString& aOptions = wxEmptyString,
50  const wxString& aDescr = wxEmptyString ) :
51  LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
52  {
53  SetType( aType );
54  SetEnabled( true );
55  }
56 
58  type( SCH_IO_MGR::SCH_LEGACY )
59  {
60  SetEnabled( true );
61  }
62 
63  bool operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const;
64 
65  bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
66 
70  const wxString GetType() const override { return SCH_IO_MGR::ShowType( type ); }
71 
75  void SetType( const wxString& aType ) override;
76 
77 protected:
79  LIB_TABLE_ROW( aRow ),
80  type( aRow.type )
81  {
82  SetEnabled( aRow.GetIsEnabled() );
83  }
84 
85 private:
86 
87  virtual LIB_TABLE_ROW* do_clone() const override
88  {
89  return new SYMBOL_LIB_TABLE_ROW( *this );
90  }
91 
92  void setPlugin( SCH_PLUGIN* aPlugin )
93  {
94  plugin.set( aPlugin );
95  }
96 
98  LIB_T type;
99 };
100 
101 
103 {
104  friend class SYMBOL_LIB_TABLE_GRID;
105  friend class PANEL_SYM_LIB_TABLE;
106 
107  static int m_modifyHash;
108 
109 public:
110  KICAD_T Type() override { return SYMBOL_LIB_TABLE_T; }
111 
112  static const char* PropPowerSymsOnly;
113  static const char* PropNonPowerSymsOnly;
114 
115  virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
116 
117  virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
118 
127  SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = NULL );
128 
142  SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
143 
144  int GetModifyHash();
145 
146  //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
147 
151  size_t GetSymbolCount( const wxString& aNickname );
152 
162  void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
163  bool aPowerSymbolsOnly = false );
164 
165  void LoadSymbolLib( std::vector<LIB_ALIAS*>& aAliasList, const wxString& aNickname,
166  bool aPowerSymbolsOnly = false );
167 
181  LIB_ALIAS* LoadSymbol( const wxString& aNickname, const wxString& aAliasName );
182 
183  LIB_ALIAS* LoadSymbol( const LIB_ID& aLibId )
184  {
185  return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
186  }
187 
191  enum SAVE_T
192  {
195  };
196 
215  SAVE_T SaveSymbol( const wxString& aNickname, const LIB_PART* aSymbol,
216  bool aOverwrite = true );
217 
227  void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
228 
243  void DeleteAlias( const wxString& aNickname, const wxString& aAliasName );
244 
255  bool IsSymbolLibWritable( const wxString& aNickname );
256 
257  void DeleteSymbolLib( const wxString& aNickname );
258 
259  void CreateSymbolLib( const wxString& aNickname );
260 
261  //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
262 
274  LIB_ALIAS* LoadSymbolWithOptionalNickname( const LIB_ID& aId );
275 
289  static bool LoadGlobalTable( SYMBOL_LIB_TABLE& aTable );
290 
297  static wxString GetGlobalTableFileName();
298 
307  static const wxString GlobalPathEnvVariableName();
308 
309  static SYMBOL_LIB_TABLE& GetGlobalLibTable();
310 
311  static const wxString& GetSymbolLibTableFileName();
312 };
313 
314 
315 #endif // _SYMBOL_LIB_TABLE_H_
bool operator!=(const SYMBOL_LIB_TABLE_ROW &aRow) const
Class SCH_IO_MGR is a factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:46
Part library alias object definition.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ALIAS * LoadSymbol(const LIB_ID &aLibId)
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...
SYMBOL_LIB_TABLE_ROW(const SYMBOL_LIB_TABLE_ROW &aRow)
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin
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:76
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:551
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
bool operator==(const SYMBOL_LIB_TABLE_ROW &aRow) const
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:188
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
KICAD_T Type() override
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const wxString GetType() const override
Return the type of symbol library table represented by this row.
Define a library symbol object.
Dialog to show and edit symbol library tables.
void setPlugin(SCH_PLUGIN *aPlugin)
SCH_IO_MGR::SCH_FILE_T LIB_T
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:523
virtual LIB_TABLE_ROW * do_clone() const override
static int m_modifyHash
helper for GetModifyHash()
static void Parse(std::unique_ptr< LIB_TABLE_ROW > &aRow, LIB_TABLE_LEXER *in)
SAVE_T
The set of return values from SaveSymbol() below.
bool GetIsEnabled() const
static const char * PropNonPowerSymsOnly
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
static const char * PropPowerSymsOnly
friend class SYMBOL_LIB_TABLE
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.