KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.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/sch_io.h>
30#include <sch_io/sch_io_mgr.h>
31#include <lib_id.h>
32
33//class LIB_SYMBOL;
35class DIALOG_SYMBOL_LIB_TABLE;
36
37
43{
44public:
45 typedef SCH_IO_MGR::SCH_FILE_T LIB_T;
46
47 SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
48 const wxString& aOptions = wxEmptyString,
49 const wxString& aDescr = wxEmptyString ) :
50 LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
51 {
52 SetType( aType );
53 SetEnabled( true );
54 }
55
57 type( SCH_IO_MGR::SCH_KICAD )
58 {
59 SetEnabled( true );
60 }
61
62 bool operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const;
63
64 bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
65
66 LIB_T SchLibType() const { return type; }
67
71 const wxString GetType() const override { return SCH_IO_MGR::ShowType( type ); }
72
76 void SetType( const wxString& aType ) override;
77
84 bool Refresh() override;
85
86 bool SupportsSubLibraries() const { return plugin ? plugin->SupportsSubLibraries() : false; }
87
88 bool SupportsSettingsDialog() const override
89 {
90 // Only database libraries have dialog-configurable options at the moment
91 return type == SCH_IO_MGR::SCH_FILE_T::SCH_DATABASE;
92 }
93
94 void ShowSettingsDialog( wxWindow* aWindow ) const override;
95
96 void GetSubLibraryNames( std::vector<wxString>& aNames ) const;
97
101 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) const
102 {
103 if( plugin )
104 plugin->GetAvailableSymbolFields( aNames );
105 }
106
110 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) const
111 {
112 if( plugin )
113 plugin->GetDefaultSymbolFields( aNames );
114 }
115
116 SCH_IO_MGR::SCH_FILE_T GetFileType() { return type; }
117
118protected:
120 LIB_TABLE_ROW( aRow ),
121 type( aRow.type )
122 {
123 SetEnabled( aRow.GetIsEnabled() );
124 }
125
126private:
127 friend class SYMBOL_LIB_TABLE;
128
129 virtual LIB_TABLE_ROW* do_clone() const override
130 {
131 return new SYMBOL_LIB_TABLE_ROW( *this );
132 }
133
134 void setPlugin( SCH_IO* aPlugin )
135 {
136 plugin.reset( aPlugin );
137 }
138
141};
142
143
145{
146public:
147 KICAD_T Type() override { return SYMBOL_LIB_TABLE_T; }
148
149 static const char* PropPowerSymsOnly;
150 static const char* PropNonPowerSymsOnly;
151
152 virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
153
154 virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
155
164 SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = nullptr );
165
177 SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName, bool aCheckIfEnabled = false );
178
179 int GetModifyHash();
180
181 //-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
182
191 void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
192 bool aPowerSymbolsOnly = false );
193
194 void LoadSymbolLib( std::vector<LIB_SYMBOL*>& aAliasList, const wxString& aNickname,
195 bool aPowerSymbolsOnly = false );
196
207 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
208
209 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
210 {
211 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
212 }
213
218 {
221 };
222
239 SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
240 bool aOverwrite = true );
241
249 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
250
260 bool IsSymbolLibWritable( const wxString& aNickname );
261
268 bool IsSymbolLibLoaded( const wxString& aNickname );
269
270 void DeleteSymbolLib( const wxString& aNickname );
271
272 void CreateSymbolLib( const wxString& aNickname );
273
274 //-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
275
286
298 static bool LoadGlobalTable( SYMBOL_LIB_TABLE& aTable );
299
306 static wxString GetGlobalTableFileName();
307
316 static const wxString GlobalPathEnvVariableName();
317
319
320 static const wxString& GetSymbolLibTableFileName();
321
326 bool operator==( const SYMBOL_LIB_TABLE& aOther ) const;
327
328 bool operator!=( const SYMBOL_LIB_TABLE& aOther ) const { return !( *this == aOther ); }
329
330
331private:
334
335 static int m_modifyHash;
336};
337
338
339#endif // _SYMBOL_LIB_TABLE_H_
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Define a library symbol object.
Definition: lib_symbol.h:99
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
void SetEnabled(bool aEnabled=true)
Change the enabled status of this library.
bool GetIsEnabled() const
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
Dialog to show and edit symbol library tables.
A factory which returns an instance of a SCH_IO.
Definition: sch_io_mgr.h:52
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:83
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
bool operator==(const SYMBOL_LIB_TABLE_ROW &aRow) const
void SetType(const wxString &aType) override
Change the schematic plugin type represented by this row.
bool operator!=(const SYMBOL_LIB_TABLE_ROW &aRow) const
void GetAvailableSymbolFields(std::vector< wxString > &aNames) const
void GetSubLibraryNames(std::vector< wxString > &aNames) const
bool Refresh() override
Attempt to reload the library.
SYMBOL_LIB_TABLE_ROW(const wxString &aNick, const wxString &aURI, const wxString &aType, const wxString &aOptions=wxEmptyString, const wxString &aDescr=wxEmptyString)
void setPlugin(SCH_IO *aPlugin)
SYMBOL_LIB_TABLE_ROW(const SYMBOL_LIB_TABLE_ROW &aRow)
void ShowSettingsDialog(wxWindow *aWindow) const override
void GetDefaultSymbolFields(std::vector< wxString > &aNames) const
LIB_T SchLibType() const
virtual LIB_TABLE_ROW * do_clone() const override
bool SupportsSubLibraries() const
SCH_IO_MGR::SCH_FILE_T LIB_T
SCH_IO_MGR::SCH_FILE_T GetFileType()
bool SupportsSettingsDialog() const override
const wxString GetType() const override
Return the type of symbol library table represented by this row.
IO_RELEASER< SCH_IO > plugin
void LoadSymbolLib(std::vector< LIB_SYMBOL * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
bool operator!=(const SYMBOL_LIB_TABLE &aOther) const
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
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 const wxString & GetSymbolLibTableFileName()
static const char * PropPowerSymsOnly
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
bool IsSymbolLibLoaded(const wxString &aNickname)
Return true if the library given by aNickname was successfully loaded.
virtual void Format(OUTPUTFORMATTER *aOutput, int aIndentLevel) const override
Generate the table in s-expression format to aOutput with an indentation level of aIndentLevel.
void DeleteSymbolLib(const wxString &aNickname)
void CreateSymbolLib(const wxString &aNickname)
static wxString GetGlobalTableFileName()
Fetch the global symbol library table file name.
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
static bool LoadGlobalTable(SYMBOL_LIB_TABLE &aTable)
Load the global symbol library table into aTable.
static const wxString GlobalPathEnvVariableName()
Return the name of the environment variable used to hold the directory of locally installed "KiCad sp...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
LIB_SYMBOL * LoadSymbolWithOptionalNickname(const LIB_ID &aId)
Load a LIB_SYMBOL having aFootprintId with possibly an empty library nickname.
static const char * PropNonPowerSymsOnly
bool operator==(const SYMBOL_LIB_TABLE &aOther) const
Compares this table against another.
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
KICAD_T Type() override
SAVE_T
The set of return values from SaveSymbol() below.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
static int m_modifyHash
helper for GetModifyHash()
LIB_SYMBOL * LoadSymbol(const LIB_ID &aLibId)
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SYMBOL_LIB_TABLE_T
Definition: typeinfo.h:238