KiCad PCB EDA Suite
symbol_library.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) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2008 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 2004-2022 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
31#ifndef SYMBOL_LIBRARY_H
32#define SYMBOL_LIBRARY_H
33
34#include <mutex>
35#include <boost/ptr_container/ptr_vector.hpp>
36#include <wx/filename.h>
37
38#include <project.h>
39#include <sch_io_mgr.h>
41
42
43class LIB_SYMBOL;
44class LIB_ID;
45class LINE_READER;
46class OUTPUTFORMATTER;
47class PROPERTIES;
48class SCH_PLUGIN;
49class SYMBOL_LIB;
50
51
52/* Helpers for creating a list of symbol libraries. */
53typedef boost::ptr_vector< SYMBOL_LIB > SYMBOL_LIBS_BASE;
54
55
63{
64public:
65 KICAD_T Type() override { return SYMBOL_LIBS_T; }
66
68
75 SYMBOL_LIB* AddLibrary( const wxString& aFileName );
76
85 SYMBOL_LIB* AddLibrary( const wxString& aFileName, SYMBOL_LIBS::iterator& aIterator );
86
94 void LoadAllLibraries( PROJECT* aProject, bool aShowProgress=true );
95
99 static void LibNamesAndPaths( PROJECT* aProject, bool doSave,
100 wxString* aPaths, wxArrayString* aNames = nullptr );
101
108 static const wxString CacheName( const wxString& aFullProjectFilename );
109
116 SYMBOL_LIB* FindLibrary( const wxString& aName );
117
118 SYMBOL_LIB* FindLibraryByFullFileName( const wxString& aFullFileName );
119
121
128 wxArrayString GetLibraryNames( bool aSorted = true );
129
140 LIB_SYMBOL* FindLibSymbol( const LIB_ID& aLibId, const wxString& aLibraryName = wxEmptyString );
141
155 void FindLibraryNearEntries( std::vector<LIB_SYMBOL*>& aCandidates, const wxString& aEntryName,
156 const wxString& aLibraryName = wxEmptyString );
157
158 int GetLibraryCount() { return size(); }
159};
160
161
169{
170public:
171 SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName,
172 SCH_IO_MGR::SCH_FILE_T aPluginType = SCH_IO_MGR::SCH_LEGACY );
173 ~SYMBOL_LIB();
174
178 int GetModHash() const { return m_mod_hash; }
179
180 SCH_IO_MGR::SCH_FILE_T GetPluginType() const { return m_pluginType; }
181
182 void SetPluginType( SCH_IO_MGR::SCH_FILE_T aPluginType );
183
184 void Create( const wxString& aFileName = wxEmptyString );
185
186 void SetFileName( const wxString& aFileName ) { fileName = aFileName; }
187
188 bool IsModified() const
189 {
190 return isModified;
191 }
192
193 bool IsCache() const;
194
195 void SetCache();
196
197 bool IsBuffering() const;
198
199 void EnableBuffering( bool aEnable = true );
200
201 void Save( bool aSaveDocFile = true );
202
206 bool IsReadOnly() const { return !fileName.IsFileWritable(); }
207
213 void GetSymbolNames( wxArrayString& aNames ) const;
214
220 void GetSymbols( std::vector<LIB_SYMBOL*>& aSymbols ) const;
221
228 LIB_SYMBOL* FindSymbol( const wxString& aName ) const;
229
230 LIB_SYMBOL* FindSymbol( const LIB_ID& aLibId ) const;
231
240 void AddSymbol( LIB_SYMBOL* aSymbol );
241
254
264 LIB_SYMBOL* ReplaceSymbol( LIB_SYMBOL* aOldSymbol, LIB_SYMBOL* aNewSymbol );
265
271 const wxString GetName() const { return fileName.GetName(); }
272
278 wxString GetFullFileName() const { return fileName.GetFullPath(); }
279
285 const wxString GetLogicalName() const
286 {
287 /* for now is the filename without path or extension.
288
289 Technically the library should not know its logical name!
290 This will eventually come out of a pair of lookup tables using a
291 reverse lookup using the full name or library pointer as a key.
292 Search will be by project lookup table and then user lookup table if
293 not found.
294 */
295 return fileName.GetName();
296 }
297
305 static SYMBOL_LIB* LoadLibrary( const wxString& aFileName );
306
307private:
309 wxFileName fileName;
310 wxDateTime timeStamp;
313 wxString header;
316
317 SCH_IO_MGR::SCH_FILE_T m_pluginType;
318 std::unique_ptr< SCH_PLUGIN > m_plugin;
319 std::unique_ptr< PROPERTIES > m_properties;
320};
321
322
326bool operator==( const SYMBOL_LIB& aLibrary, const wxString& aName );
327bool operator!=( const SYMBOL_LIB& aLibrary, const wxString& aName );
328
329#endif // SYMBOL_LIBRARY_H
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
Define a library symbol object.
Definition: lib_symbol.h:98
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition: project.h:74
Container for project specific data.
Definition: project.h:63
A name/value tuple with unique names and optional values.
Definition: properties.h:34
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:155
A collection of SYMBOL_LIB objects.
int GetLibraryCount()
void FindLibraryNearEntries(std::vector< LIB_SYMBOL * > &aCandidates, const wxString &aEntryName, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a LIB_SYMBOL using a case insensitive comparison.
SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
KICAD_T Type() override
SYMBOL_LIB * FindLibraryByFullFileName(const wxString &aFullFileName)
wxArrayString GetLibraryNames(bool aSorted=true)
Return the list of symbol library file names without path and extension.
void LoadAllLibraries(PROJECT *aProject, bool aShowProgress=true)
Load all of the project's libraries into this container, which should be cleared before calling it.
static const wxString CacheName(const wxString &aFullProjectFilename)
Return the name of the cache library after potentially fixing it from an older naming scheme.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
SYMBOL_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a symbol library to the library list.
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=nullptr)
Save or load the names of the currently configured symbol libraries (without paths).
SYMBOL_LIB * GetCacheLibrary()
Object used to load, save, search, and otherwise manipulate symbol library files.
void SetFileName(const wxString &aFileName)
wxString GetFullFileName() const
Return the full file library name with path and extension.
SCH_IO_MGR::SCH_FILE_T m_pluginType
int GetModHash() const
std::unique_ptr< PROPERTIES > m_properties
Library properties.
void Create(const wxString &aFileName=wxEmptyString)
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
bool IsBuffering() const
bool IsCache() const
std::unique_ptr< SCH_PLUGIN > m_plugin
void SetPluginType(SCH_IO_MGR::SCH_FILE_T aPluginType)
SCH_LIB_TYPE type
Library type indicator.
SYMBOL_LIB(SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
bool IsModified() const
void EnableBuffering(bool aEnable=true)
SCH_IO_MGR::SCH_FILE_T GetPluginType() const
bool IsReadOnly() const
void Save(bool aSaveDocFile=true)
static SYMBOL_LIB * LoadLibrary(const wxString &aFileName)
Allocate and load a symbol library file.
const wxString GetLogicalName() const
Return the logical name of the library.
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
void AddSymbol(LIB_SYMBOL *aSymbol)
Add aSymbol entry to library.
bool isModified
Library modification status.
void GetSymbolNames(wxArrayString &aNames) const
Load a string array with the names of all the entries in this library.
wxDateTime timeStamp
Library save time and date.
int versionMinor
Library minor version number.
int m_mod_hash
incremented each time library is changed.
LIB_SYMBOL * ReplaceSymbol(LIB_SYMBOL *aOldSymbol, LIB_SYMBOL *aNewSymbol)
Replace an existing symbol entry in the library.
wxFileName fileName
Library file name.
int versionMajor
Library major version number.
wxString header
first line of loaded library.
const wxString GetName() const
Return the file name without path or extension.
LIB_SYMBOL * RemoveSymbol(LIB_SYMBOL *aEntry)
Safely remove aEntry from the library and return the next entry.
bool operator==(const SYMBOL_LIB &aLibrary, const wxString &aName)
Case insensitive library name comparison.
boost::ptr_vector< SYMBOL_LIB > SYMBOL_LIBS_BASE
bool operator!=(const SYMBOL_LIB &aLibrary, const wxString &aName)
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SYMBOL_LIBS_T
Definition: typeinfo.h:236