2017-11-12 17:55:20 +00:00
|
|
|
/*
|
2021-06-15 12:31:28 +00:00
|
|
|
* This program source code file is symbol of KiCad, a free EDA CAD application.
|
2017-11-12 17:55:20 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2022-04-21 10:57:15 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2017-11-12 17:55:20 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2021-06-15 12:31:28 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A SYMBOLICULAR PURPOSE. See the
|
2017-11-12 17:55:20 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
#ifndef SYMBOL_LIBRARY_MANAGER_H
|
|
|
|
#define SYMBOL_LIBRARY_MANAGER_H
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <list>
|
|
|
|
#include <deque>
|
|
|
|
#include <set>
|
|
|
|
#include <memory>
|
|
|
|
#include <wx/arrstr.h>
|
2020-02-13 13:39:52 +00:00
|
|
|
#include <sch_io_mgr.h>
|
2018-01-30 08:56:43 +00:00
|
|
|
#include <sch_screen.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
class LIB_SYMBOL;
|
2021-06-15 12:31:28 +00:00
|
|
|
class SYMBOL_LIB;
|
2021-03-20 00:23:54 +00:00
|
|
|
class PROGRESS_REPORTER;
|
2017-11-13 13:58:39 +00:00
|
|
|
class SCH_PLUGIN;
|
2022-09-16 03:06:23 +00:00
|
|
|
class SCH_BASE_FRAME;
|
2017-11-12 17:55:20 +00:00
|
|
|
class SYMBOL_LIB_TABLE;
|
2018-02-06 15:14:01 +00:00
|
|
|
class SYMBOL_LIB_TABLE_ROW;
|
2021-06-01 05:17:57 +00:00
|
|
|
class LIB_LOGGER;
|
2019-07-10 17:59:39 +00:00
|
|
|
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
|
|
|
* Class to handle modifications to the symbol libraries.
|
|
|
|
*/
|
2020-10-31 01:27:16 +00:00
|
|
|
class SYMBOL_LIBRARY_MANAGER
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-09-16 03:06:23 +00:00
|
|
|
SYMBOL_LIBRARY_MANAGER( SCH_BASE_FRAME& aFrame );
|
2022-09-24 01:44:15 +00:00
|
|
|
virtual ~SYMBOL_LIBRARY_MANAGER();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-03-20 00:23:54 +00:00
|
|
|
/**
|
|
|
|
* Preloads all symbol libraries in the symbol library table using SYMBOL_ASYNC_LOADER.
|
|
|
|
* Call before the first call to Sync() to get better performance.
|
|
|
|
* @param aReporter is used to report progress of the load
|
|
|
|
*/
|
|
|
|
void Preload( PROGRESS_REPORTER& aReporter );
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
int GetHash() const;
|
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
bool HasModifications() const;
|
|
|
|
|
2017-11-12 13:24:55 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return a library hash value to determine if it has changed.
|
2017-11-12 13:24:55 +00:00
|
|
|
*
|
2019-07-18 23:37:04 +00:00
|
|
|
* For buffered libraries, it returns a number corresponding to the number of modifications.
|
|
|
|
* For original libraries, hash is computed basing on the library URI. Returns -1 when the
|
|
|
|
* requested library does not exist.
|
2017-11-12 13:24:55 +00:00
|
|
|
*/
|
2017-11-12 17:55:20 +00:00
|
|
|
int GetLibraryHash( const wxString& aLibrary ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return the array of library names.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
|
|
|
wxArrayString GetLibraryNames() const;
|
|
|
|
|
2018-02-06 15:14:01 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Find a single library within the (aggregate) library table.
|
2018-02-06 15:14:01 +00:00
|
|
|
*/
|
2018-02-16 10:59:22 +00:00
|
|
|
SYMBOL_LIB_TABLE_ROW* GetLibrary( const wxString& aLibrary ) const;
|
2018-02-06 15:14:01 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
std::list<LIB_SYMBOL*> GetAliases( const wxString& aLibrary ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Create an empty library and adds it to the library table. The library file is created.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2017-11-22 13:02:45 +00:00
|
|
|
bool CreateLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2017-11-22 13:02:45 +00:00
|
|
|
return addLibrary( aFilePath, true, aTable );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Add an existing library. The library is added to the library table as well.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2017-11-22 13:02:45 +00:00
|
|
|
bool AddLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2017-11-22 13:02:45 +00:00
|
|
|
return addLibrary( aFilePath, false, aTable );
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Update the symbol buffer with a new version of the symbol.
|
|
|
|
* The library buffer creates a copy of the symbol.
|
|
|
|
* It is required to save the library to use the updated symbol in the schematic editor.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool UpdateSymbol( LIB_SYMBOL* aSymbol, const wxString& aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2018-01-19 18:56:01 +00:00
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Update the symbol buffer with a new version of the symbol when the name has changed.
|
2018-01-19 18:56:01 +00:00
|
|
|
* The old library buffer will be deleted and a new one created with the new name.
|
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool UpdateSymbolAfterRename( LIB_SYMBOL* aSymbol, const wxString& oldAlias,
|
|
|
|
const wxString& aLibrary );
|
2018-01-19 18:56:01 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Remove the symbol from the symbol buffer.
|
|
|
|
* It is required to save the library to have the symbol removed in the schematic editor.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool RemoveSymbol( const wxString& aName, const wxString& aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Return either an alias of a working LIB_SYMBOL copy, or alias of the original symbol if there
|
2017-11-12 17:55:20 +00:00
|
|
|
* is no working copy.
|
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* GetAlias( const wxString& aAlias, const wxString& aLibrary ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Return the symbol copy from the buffer. In case it does not exist yet, the copy is created.
|
2021-01-26 15:23:37 +00:00
|
|
|
* #SYMBOL_LIBRARY_MANAGER retains the ownership.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* GetBufferedSymbol( const wxString& aAlias, const wxString& aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Return the screen used to edit a specific symbol. #SYMBOL_LIBRARY_MANAGER retains the
|
2021-01-26 15:23:37 +00:00
|
|
|
* ownership.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
|
|
|
SCH_SCREEN* GetScreen( const wxString& aAlias, const wxString& aLibrary );
|
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Return true if symbol with a specific alias exists in library (either original one or
|
2019-11-06 19:15:42 +00:00
|
|
|
* buffered).
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool SymbolExists( const wxString& aAlias, const wxString& aLibrary ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return true if library exists. If \a aCheckEnabled is set, then the library must
|
2018-04-28 09:43:41 +00:00
|
|
|
* also be enabled in the library table.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2018-04-28 09:43:41 +00:00
|
|
|
bool LibraryExists( const wxString& aLibrary, bool aCheckEnabled = false ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2020-08-29 23:19:05 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return true if the library was successfully loaded.
|
2020-08-29 23:19:05 +00:00
|
|
|
*/
|
|
|
|
bool IsLibraryLoaded( const wxString& aLibrary ) const;
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return true if library has unsaved modifications.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
|
|
|
bool IsLibraryModified( const wxString& aLibrary ) const;
|
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Return true if symbol has unsaved modifications.
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool IsSymbolModified( const wxString& aAlias, const wxString& aLibrary ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2022-04-21 10:57:15 +00:00
|
|
|
void SetSymbolModified( const wxString& aAlias, const wxString& aLibrary );
|
|
|
|
|
2017-11-13 22:13:10 +00:00
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Clear the modified flag for all symbols in a library.
|
2017-11-13 22:13:10 +00:00
|
|
|
*/
|
|
|
|
bool ClearLibraryModified( const wxString& aLibrary ) const;
|
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Clear the modified flag for a symbol.
|
2017-11-13 22:13:10 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool ClearSymbolModified( const wxString& aAlias, const wxString& aLibrary ) const;
|
2017-11-13 22:13:10 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return true if the library is stored in a read-only file.
|
|
|
|
*
|
2017-11-12 17:55:20 +00:00
|
|
|
* @return True on success, false otherwise.
|
|
|
|
*/
|
|
|
|
bool IsLibraryReadOnly( const wxString& aLibrary ) const;
|
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Save symbol changes to the library copy used by the schematic editor. Not it is not
|
2017-11-12 17:55:20 +00:00
|
|
|
* necessarily saved to the file.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2017-11-12 17:55:20 +00:00
|
|
|
* @return True on success, false otherwise.
|
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
bool FlushSymbol( const wxString& aAlias, const wxString& aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-13 13:58:39 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Save library to a file, including unsaved changes.
|
|
|
|
*
|
2017-11-13 13:58:39 +00:00
|
|
|
* @param aLibrary is the library name.
|
|
|
|
* @param aFileName is the target file name.
|
|
|
|
* @return True on success, false otherwise.
|
|
|
|
*/
|
2020-02-13 13:39:52 +00:00
|
|
|
bool SaveLibrary( const wxString& aLibrary, const wxString& aFileName,
|
|
|
|
SCH_IO_MGR::SCH_FILE_T aFileType = SCH_IO_MGR::SCH_FILE_T::SCH_LEGACY );
|
2017-11-13 13:58:39 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Revert unsaved changes for a symbolicular symbol.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2021-06-15 12:31:28 +00:00
|
|
|
* @return The LIB_ID of the reverted symbol (which may be different in the case
|
2018-01-19 18:56:01 +00:00
|
|
|
* of a rename)
|
2017-11-12 17:55:20 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_ID RevertSymbol( const wxString& aAlias, const wxString& aLibrary );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Revert unsaved changes for a symbolicular library.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2017-11-12 17:55:20 +00:00
|
|
|
* @return True on success, false otherwise.
|
|
|
|
*/
|
|
|
|
bool RevertLibrary( const wxString& aLibrary );
|
|
|
|
|
2019-06-13 11:44:12 +00:00
|
|
|
/**
|
|
|
|
* Revert all pending changes.
|
|
|
|
*
|
|
|
|
* @return True if all changes successfully reverted.
|
|
|
|
*/
|
|
|
|
bool RevertAll();
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return a library name that is not currently in use.
|
2017-11-12 17:55:20 +00:00
|
|
|
* Used for generating names for new libraries.
|
|
|
|
*/
|
|
|
|
wxString GetUniqueLibraryName() const;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void GetRootSymbolNames( const wxString& aLibName, wxArrayString& aRootSymbolNames );
|
|
|
|
|
2019-12-12 15:44:53 +00:00
|
|
|
/**
|
|
|
|
* Check if symbol \a aSymbolName in library \a aLibraryName is a root symbol that
|
|
|
|
* has derived symbols.
|
|
|
|
*
|
|
|
|
* @return true if \aSymbolName in \a aLibraryName has derived symbols.
|
|
|
|
*/
|
|
|
|
bool HasDerivedSymbols( const wxString& aSymbolName, const wxString& aLibraryName );
|
|
|
|
|
2021-03-20 00:23:54 +00:00
|
|
|
size_t GetLibraryCount() const;
|
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
protected:
|
|
|
|
virtual void OnDataChanged() const {}
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Extract library name basing on the file name.
|
2017-11-12 17:55:20 +00:00
|
|
|
static wxString getLibraryName( const wxString& aFilePath );
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Helper function to add either existing or create new library
|
2017-11-22 13:02:45 +00:00
|
|
|
bool addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LIB_TABLE* aTable );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Return the current Symbol Library Table.
|
2018-01-08 14:18:08 +00:00
|
|
|
SYMBOL_LIB_TABLE* symTable() const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
///< Class to store a working copy of a LIB_SYMBOL object and editor context.
|
2021-06-15 12:31:28 +00:00
|
|
|
class SYMBOL_BUFFER
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-06-15 12:31:28 +00:00
|
|
|
SYMBOL_BUFFER( LIB_SYMBOL* aSymbol = nullptr,
|
|
|
|
std::unique_ptr<SCH_SCREEN> aScreen = nullptr );
|
|
|
|
~SYMBOL_BUFFER();
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* GetSymbol() const { return m_symbol; }
|
|
|
|
void SetSymbol( LIB_SYMBOL* aSymbol );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* GetOriginal() const { return m_original; }
|
|
|
|
void SetOriginal( LIB_SYMBOL* aSymbol );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
bool IsModified() const;
|
2018-01-22 16:46:28 +00:00
|
|
|
SCH_SCREEN* GetScreen() const { return m_screen.get(); }
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Transfer the screen ownership
|
2018-01-22 16:46:28 +00:00
|
|
|
std::unique_ptr<SCH_SCREEN> RemoveScreen()
|
|
|
|
{
|
|
|
|
return std::move( m_screen );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetScreen( std::unique_ptr<SCH_SCREEN> aScreen )
|
|
|
|
{
|
|
|
|
bool ret = !!m_screen;
|
|
|
|
m_screen = std::move( aScreen );
|
|
|
|
return ret;
|
|
|
|
}
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-22 16:46:28 +00:00
|
|
|
std::unique_ptr<SCH_SCREEN> m_screen;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* m_symbol; // Working copy
|
|
|
|
LIB_SYMBOL* m_original; // Initial state of the symbol
|
2017-11-12 17:55:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Store a working copy of a library.
|
2017-11-12 17:55:20 +00:00
|
|
|
class LIB_BUFFER
|
|
|
|
{
|
|
|
|
public:
|
2019-07-18 23:37:04 +00:00
|
|
|
LIB_BUFFER( const wxString& aLibrary ) :
|
|
|
|
m_libName( aLibrary ),
|
|
|
|
m_hash( 1 )
|
|
|
|
{ }
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
bool IsModified() const
|
|
|
|
{
|
|
|
|
if( !m_deleted.empty() )
|
|
|
|
return true;
|
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
for( const std::shared_ptr<SYMBOL_BUFFER>& symbolBuf : m_symbols )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
if( symbolBuf->IsModified() )
|
2017-11-12 17:55:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-18 23:37:04 +00:00
|
|
|
int GetHash() const { return m_hash; }
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
///< Return the working copy of a LIB_SYMBOL root object with specified alias.
|
2021-06-15 12:31:28 +00:00
|
|
|
LIB_SYMBOL* GetSymbol( const wxString& aAlias ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
///< Create a new buffer to store a symbol. LIB_BUFFER takes ownership of aCopy.
|
2021-06-10 18:51:46 +00:00
|
|
|
bool CreateBuffer( LIB_SYMBOL* aCopy, SCH_SCREEN* aScreen );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
///< Update the buffered symbol with the contents of \a aCopy.
|
2021-07-28 20:04:53 +00:00
|
|
|
bool UpdateBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf, LIB_SYMBOL* aCopy );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
bool DeleteBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
void ClearDeletedBuffer()
|
|
|
|
{
|
|
|
|
m_deleted.clear();
|
|
|
|
}
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Save stored modifications to Symbol Lib Table. It may result in saving the symbol
|
|
|
|
///< to disk as well, depending on the row properties.
|
2021-07-28 20:04:53 +00:00
|
|
|
bool SaveBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf, SYMBOL_LIB_TABLE* aLibTable );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Save stored modifications using a plugin. aBuffer decides whether the changes
|
|
|
|
///< should be cached or stored directly to the disk (for SCH_LEGACY_PLUGIN).
|
2021-07-28 20:04:53 +00:00
|
|
|
bool SaveBuffer( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf, const wxString& aFileName,
|
2021-03-13 13:28:52 +00:00
|
|
|
SCH_PLUGIN* aPlugin, bool aBuffer );
|
2017-11-13 13:58:39 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
///< Return a symbol buffer with LIB_SYMBOL holding a symbolicular alias
|
2021-07-28 20:04:53 +00:00
|
|
|
std::shared_ptr<SYMBOL_BUFFER> GetBuffer( const wxString& aAlias ) const;
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
///< Return all buffered symbols
|
2021-07-28 20:04:53 +00:00
|
|
|
const std::deque< std::shared_ptr<SYMBOL_BUFFER> >& GetBuffers() const { return m_symbols; }
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
/**
|
2021-06-15 12:31:28 +00:00
|
|
|
* Check to see any symbols in the buffer are derived from a parent named \a aParentName.
|
2019-11-06 19:15:42 +00:00
|
|
|
*
|
|
|
|
* @param aParentName is the name of the parent to test.
|
|
|
|
* @return true if any symbols are found derived from a symbol named \a aParent, otherwise
|
|
|
|
* false.
|
|
|
|
*/
|
|
|
|
bool HasDerivedSymbols( const wxString& aParentName ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Fetch a list of root symbols names from the library buffer.
|
2019-11-06 19:15:42 +00:00
|
|
|
*
|
|
|
|
* @param aRootSymbolNames is a reference to a list to populate with root symbol names.
|
|
|
|
*/
|
|
|
|
void GetRootSymbolNames( wxArrayString& aRootSymbolNames );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2020-01-09 16:23:46 +00:00
|
|
|
/**
|
|
|
|
* Fetch all of the symbols derived from a \a aSymbolName into \a aList.
|
|
|
|
*
|
2021-06-15 12:31:28 +00:00
|
|
|
* @param aSymbolName is the name of the symbol to search for derived symbols in this
|
2020-01-09 16:23:46 +00:00
|
|
|
* buffer.
|
|
|
|
* @param aList is the list of symbols names derived from \a aSymbolName.
|
|
|
|
* @return a size_t count of the number of symbols derived from \a aSymbolName.
|
|
|
|
*/
|
|
|
|
size_t GetDerivedSymbolNames( const wxString& aSymbolName, wxArrayString& aList );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Remove all symbols derived from \a aParent from the library buffer.
|
|
|
|
*
|
2021-06-15 12:31:28 +00:00
|
|
|
* @param aParent is the #SYMBOL_BUFFER to check against.
|
|
|
|
* @return the count of #SYMBOL_BUFFER objects removed from the library.
|
2019-11-06 19:15:42 +00:00
|
|
|
*/
|
2021-07-28 20:04:53 +00:00
|
|
|
int removeChildSymbols( std::shared_ptr<SYMBOL_BUFFER> aSymbolBuf );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2021-07-28 20:04:53 +00:00
|
|
|
std::deque< std::shared_ptr<SYMBOL_BUFFER> > m_symbols;
|
2021-06-15 12:31:28 +00:00
|
|
|
|
|
|
|
///< Buffer for deleted symbols until library is saved.
|
2021-07-28 20:04:53 +00:00
|
|
|
std::deque< std::shared_ptr<SYMBOL_BUFFER> > m_deleted;
|
|
|
|
const wxString m_libName; // Buffered library name
|
|
|
|
int m_hash;
|
2017-11-12 17:55:20 +00:00
|
|
|
};
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Return a set of #LIB_SYMBOL objects belonging to the original library.
|
2020-11-07 14:31:50 +00:00
|
|
|
*/
|
2021-06-15 12:31:28 +00:00
|
|
|
std::set<LIB_SYMBOL*> getOriginalSymbols( const wxString& aLibrary );
|
2017-11-13 13:58:39 +00:00
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return an existing library buffer or creates one to using Symbol Library Table to get
|
2020-11-07 14:31:50 +00:00
|
|
|
* the original data.
|
|
|
|
*/
|
2017-11-12 17:55:20 +00:00
|
|
|
LIB_BUFFER& getLibraryBuffer( const wxString& aLibrary );
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< The library buffers
|
2017-11-12 17:55:20 +00:00
|
|
|
std::map<wxString, LIB_BUFFER> m_libs;
|
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
SCH_BASE_FRAME& m_frame; ///< Parent frame
|
2021-06-01 05:17:57 +00:00
|
|
|
LIB_LOGGER* m_logger;
|
2017-11-12 17:55:20 +00:00
|
|
|
};
|
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
#endif /* SYMBOL_LIBRARY_MANAGER_H */
|