KiCad PCB EDA Suite
Loading...
Searching...
No Matches
legacy_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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
26
27#ifndef SYMBOL_LIBRARY_H
28#define SYMBOL_LIBRARY_H
29
30#include <mutex>
31#include <boost/ptr_container/ptr_vector.hpp>
32#include <wx/filename.h>
33
34#include <project.h>
35#include <sch_io/sch_io_mgr.h>
37
38
39class LIB_SYMBOL;
40class LIB_ID;
41class LINE_READER;
42class OUTPUTFORMATTER;
43class SCH_IO;
45
46
53class LEGACY_SYMBOL_LIBS : public boost::ptr_vector<LEGACY_SYMBOL_LIB>, public PROJECT::_ELEM
54{
55public:
57
59
66 LEGACY_SYMBOL_LIB* AddLibrary( const wxString& aFileName );
67
76 LEGACY_SYMBOL_LIB* AddLibrary( const wxString& aFileName, LEGACY_SYMBOL_LIBS::iterator& aIterator );
77
84 bool ReloadLibrary( const wxString& aFileName );
85
93 void LoadAllLibraries( PROJECT* aProject, bool aShowProgress=true );
94
95 static void GetLibNamesAndPaths( PROJECT* aProject, wxString* aPaths,
96 wxArrayString* aNames = nullptr );
97
98 static void SetLibNamesAndPaths( PROJECT* aProject, const wxString& aPaths,
99 const wxArrayString& aNames );
100
107 static const wxString CacheName( const wxString& aFullProjectFilename );
108
115 LEGACY_SYMBOL_LIB* FindLibrary( const wxString& aName );
116
117 LEGACY_SYMBOL_LIB* FindLibraryByFullFileName( const wxString& aFullFileName );
118
120
127 wxArrayString GetLibraryNames( bool aSorted = true );
128
139 LIB_SYMBOL* FindLibSymbol( const LIB_ID& aLibId, const wxString& aLibraryName = wxEmptyString );
140
154 void FindLibraryNearEntries( std::vector<LIB_SYMBOL*>& aCandidates, const wxString& aEntryName,
155 const wxString& aLibraryName = wxEmptyString );
156
157 int GetLibraryCount() { return size(); }
158};
159
160
168{
169public:
170 LEGACY_SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName,
171 SCH_IO_MGR::SCH_FILE_T aPluginType = SCH_IO_MGR::SCH_LEGACY );
173
177 int GetModHash() const { return m_mod_hash; }
178
179 SCH_IO_MGR::SCH_FILE_T GetPluginType() const { return m_pluginType; }
180
181 void SetPluginType( SCH_IO_MGR::SCH_FILE_T aPluginType );
182
183 void Create( const wxString& aFileName = wxEmptyString );
184
185 void SetFileName( const wxString& aFileName ) { fileName = aFileName; }
186
187 bool IsModified() const
188 {
189 return isModified;
190 }
191
192 bool IsCache() const;
193
194 void SetCache();
195
196 bool IsBuffering() const;
197
198 void EnableBuffering( bool aEnable = true );
199
200 void Save( bool aSaveDocFile = true );
201
205 bool IsReadOnly() const { return !fileName.IsFileWritable(); }
206
212 void GetSymbolNames( wxArrayString& aNames ) const;
213
219 void GetSymbols( std::vector<LIB_SYMBOL*>& aSymbols ) const;
220
227 LIB_SYMBOL* FindSymbol( const wxString& aName ) const;
228
229 LIB_SYMBOL* FindSymbol( const LIB_ID& aLibId ) const;
230
239 void AddSymbol( LIB_SYMBOL* aSymbol );
240
253
263 LIB_SYMBOL* ReplaceSymbol( LIB_SYMBOL* aOldSymbol, LIB_SYMBOL* aNewSymbol );
264
270 const wxString GetName() const { return fileName.GetName(); }
271
277 wxString GetFullFileName() const { return fileName.GetFullPath(); }
278
284 const wxString GetLogicalName() const
285 {
286 /* for now is the filename without path or extension.
287
288 Technically the library should not know its logical name!
289 This will eventually come out of a pair of lookup tables using a
290 reverse lookup using the full name or library pointer as a key.
291 Search will be by project lookup table and then user lookup table if
292 not found.
293 */
294 return fileName.GetName();
295 }
296
304 static LEGACY_SYMBOL_LIB* LoadSymbolLibrary( const wxString& aFileName );
305
306private:
308 wxFileName fileName;
309 wxDateTime timeStamp;
312 wxString header;
315
316 SCH_IO_MGR::SCH_FILE_T m_pluginType;
317 std::unique_ptr< SCH_IO > m_plugin;
318 std::unique_ptr<std::map<std::string, UTF8>> m_properties;
319};
320
321
325bool operator==( const LEGACY_SYMBOL_LIB& aLibrary, const wxString& aName );
326bool operator!=( const LEGACY_SYMBOL_LIB& aLibrary, const wxString& aName );
327
328#endif // SYMBOL_LIBRARY_H
LEGACY_SYMBOL_LIB * GetCacheLibrary()
wxArrayString GetLibraryNames(bool aSorted=true)
Return the list of symbol library file names without path and extension.
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.
LEGACY_SYMBOL_LIB * FindLibraryByFullFileName(const wxString &aFullFileName)
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
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 void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
LEGACY_SYMBOL_LIB * FindLibrary(const wxString &aName)
Find a symbol library by aName.
LIB_SYMBOL * FindLibSymbol(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Search all libraries in the list for a symbol.
LEGACY_SYMBOL_LIB * AddLibrary(const wxString &aFileName)
Allocate and adds a symbol library to the library list.
bool ReloadLibrary(const wxString &aFileName)
Refreshes the library from the (possibly updated) contents on disk.
PROJECT::ELEM ProjectElementType() override
static const wxString CacheName(const wxString &aFullProjectFilename)
Return the name of the cache library after potentially fixing it from an older naming scheme.
Object used to load, save, search, and otherwise manipulate symbol library files.
static LEGACY_SYMBOL_LIB * LoadSymbolLibrary(const wxString &aFileName)
Allocate and load a symbol library file.
wxFileName fileName
Library file name.
const wxString GetLogicalName() const
Return the logical name of the library.
int versionMajor
Library major version number.
std::unique_ptr< std::map< std::string, UTF8 > > m_properties
Library properties.
void EnableBuffering(bool aEnable=true)
void SetFileName(const wxString &aFileName)
LIB_SYMBOL * ReplaceSymbol(LIB_SYMBOL *aOldSymbol, LIB_SYMBOL *aNewSymbol)
Replace an existing symbol entry in the library.
wxDateTime timeStamp
Library save time and date.
std::unique_ptr< SCH_IO > m_plugin
SCH_IO_MGR::SCH_FILE_T m_pluginType
LIB_SYMBOL * FindSymbol(const wxString &aName) const
Find LIB_SYMBOL by aName.
LIB_SYMBOL * RemoveSymbol(LIB_SYMBOL *aEntry)
Safely remove aEntry from the library and return the next entry.
SCH_IO_MGR::SCH_FILE_T GetPluginType() const
void Create(const wxString &aFileName=wxEmptyString)
int m_mod_hash
incremented each time library is changed.
LEGACY_SYMBOL_LIB(SCH_LIB_TYPE aType, const wxString &aFileName, SCH_IO_MGR::SCH_FILE_T aPluginType=SCH_IO_MGR::SCH_LEGACY)
void GetSymbolNames(wxArrayString &aNames) const
Load a string array with the names of all the entries in this library.
void AddSymbol(LIB_SYMBOL *aSymbol)
Add aSymbol entry to library.
const wxString GetName() const
Return the file name without path or extension.
wxString header
first line of loaded library.
void Save(bool aSaveDocFile=true)
bool isModified
Library modification status.
void GetSymbols(std::vector< LIB_SYMBOL * > &aSymbols) const
Load a vector with all the entries in this library.
wxString GetFullFileName() const
Return the full file library name with path and extension.
int versionMinor
Library minor version number.
void SetPluginType(SCH_IO_MGR::SCH_FILE_T aPluginType)
SCH_LIB_TYPE type
Library type indicator.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
Define a library symbol object.
Definition lib_symbol.h:79
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:62
An interface used to output 8 bit text in a convenient way.
Definition richio.h:291
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition project.h:89
Container for project specific data.
Definition project.h:62
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:68
@ LEGACY_SYMBOL_LIBS
Definition project.h:69
Base class that schematic file and library loading and saving plugins should derive from.
Definition sch_io.h:59
bool operator==(const LEGACY_SYMBOL_LIB &aLibrary, const wxString &aName)
Case insensitive library name comparison.
bool operator!=(const LEGACY_SYMBOL_LIB &aLibrary, const wxString &aName)