From b36e31c49fa605bc1566ba8fbce023db286d05a0 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 29 Jan 2022 14:07:07 -0500 Subject: [PATCH] Factor out common and remove dead legacy symbol library code. --- eeschema/getpart.cpp | 9 +- eeschema/sch_base_frame.h | 10 +- .../sch_plugins/legacy/sch_legacy_plugin.cpp | 24 ++- eeschema/symbol_library.h | 154 ++---------------- eeschema/symbol_library_common.h | 135 +++++++++++++++ eeschema/symbol_viewer_frame.cpp | 6 +- eeschema/symbol_viewer_frame.h | 6 +- eeschema/tools/sch_drawing_tools.cpp | 6 +- eeschema/tools/sch_drawing_tools.h | 3 +- 9 files changed, 186 insertions(+), 167 deletions(-) create mode 100644 eeschema/symbol_library_common.h diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 73427fcbf2..25a8f54976 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ #include PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibBrowser( wxTopLevelWindow* aParent, - const SCHLIB_FILTER* aFilter, + const SYMBOL_LIBRARY_FILTER* aFilter, const LIB_ID& aPreselectedLibId, int aUnit, int aConvert ) { @@ -88,7 +89,7 @@ PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibBrowser( wxTopLevelWindow* aParen } -PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SCHLIB_FILTER* aFilter, +PICKED_SYMBOL SCH_BASE_FRAME::PickSymbolFromLibTree( const SYMBOL_LIBRARY_FILTER* aFilter, std::vector& aHistoryList, bool aUseLibBrowser, int aUnit, int aConvert, bool aShowFootprints, const LIB_ID* aHighlight, diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index bf22c1ab6f..30b0fe5082 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -52,7 +52,7 @@ class SYMBOL_VIEWER_FRAME; class SYMBOL_EDIT_FRAME; class LIB_SYMBOL; class SYMBOL_LIB; -class SCHLIB_FILTER; +class SYMBOL_LIBRARY_FILTER; class LIB_ID; class SYMBOL_LIB_TABLE; class EESCHEMA_SETTINGS; @@ -141,7 +141,7 @@ public: * (e.g. footprint selection) should be enabled. This should be false when they would * have no effect, for example loading a part into symbol_editor. * - * @param aFilter is an optional #SCHLIB_FILTER filter to pass the allowed library names + * @param aFilter is an optional #SYMBOL_LIBRARY_FILTER filter to pass the allowed library names * and/or the library name to load the symbol from and/or some other filter * @param aHistoryList is the list of previously loaded symbols - will be edited * @param aUseLibBrowser is the flag to call the library viewer to select the symbol @@ -154,7 +154,7 @@ public: * * @return the selected symbol */ - PICKED_SYMBOL PickSymbolFromLibTree( const SCHLIB_FILTER* aFilter, + PICKED_SYMBOL PickSymbolFromLibTree( const SYMBOL_LIBRARY_FILTER* aFilter, std::vector& aHistoryList, bool aUseLibBrowser, int aUnit, @@ -188,7 +188,7 @@ public: * @return the selected symbol. */ PICKED_SYMBOL PickSymbolFromLibBrowser( wxTopLevelWindow* aParent, - const SCHLIB_FILTER* aFilter, + const SYMBOL_LIBRARY_FILTER* aFilter, const LIB_ID& aPreselectedLibId, int aUnit, int aConvert ); diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index 16069506cf..4303360234 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -63,14 +63,32 @@ #include #include // for MAX_UNIT_COUNT_PER_PACKAGE definition #include +#include #define Mils2Iu( x ) Mils2iu( x ) +#define LIB_VERSION_MAJOR 2 ///< Legacy symbol library major version. +#define LIB_VERSION_MINOR 4 ///< Legacy symbol library minor version. -// Must be the first line of symbol library document (.dcm) files. +#define LIB_VERSION( major, minor ) ( major * 100 + minor ) + +/** Legacy symbol library (.lib) file header. */ +#define LIBFILE_IDENT "EESchema-LIBRARY Version" + +/** Legacy symbol library document (.dcm) file header. */ #define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0" +/** + * Library versions 2.4 and lower use the old separate library (.lib) and + * document (.dcm) files. Symbol libraries after 2.4 merged the library + * and document files into a single library file. This macro checks if the + * library version supports the old format. + */ +#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \ + ( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 4 ) ) + + #define SCH_PARSE_ERROR( text, reader, pos ) \ THROW_PARSE_ERROR( text, reader.GetSource(), reader.Line(), \ reader.LineNumber(), pos - reader.Line() ) @@ -2693,7 +2711,7 @@ void SCH_LEGACY_PLUGIN_CACHE::loadDocs() wxFileName fn = m_libFileName; LIB_SYMBOL* symbol = nullptr;; - fn.SetExt( DOC_EXT ); + fn.SetExt( LegacySymbolDocumentFileExtension ); // Not all libraries will have a document file. if( !fn.FileExists() ) @@ -4248,7 +4266,7 @@ void SCH_LEGACY_PLUGIN_CACHE::saveDocFile() wxFileName fileName = m_libFileName; - fileName.SetExt( DOC_EXT ); + fileName.SetExt( LegacySymbolDocumentFileExtension ); FILE_OUTPUTFORMATTER formatter( fileName.GetFullPath() ); formatter.Print( 0, "%s\n", DOCFILE_IDENT ); diff --git a/eeschema/symbol_library.h b/eeschema/symbol_library.h index 699c31bedf..12ad51008a 100644 --- a/eeschema/symbol_library.h +++ b/eeschema/symbol_library.h @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,158 +31,25 @@ #ifndef SYMBOL_LIBRARY_H #define SYMBOL_LIBRARY_H -#include #include #include #include -#include #include +#include +#include + class LIB_SYMBOL; class LIB_ID; class LINE_READER; class OUTPUTFORMATTER; -class SCH_LEGACY_PLUGIN; +class PROPERTIES; class SCH_PLUGIN; - - -#define DOC_EXT "dcm" - -/* - * Symbol Library version and file header macros. - */ -#define LIB_VERSION_MAJOR 2 -#define LIB_VERSION_MINOR 4 - -/* Must be the first line of symbol library (.lib) files. */ -#define LIBFILE_IDENT "EESchema-LIBRARY Version" - -#define LIB_VERSION( major, minor ) ( major * 100 + minor ) - -#define IS_LIB_CURRENT_VERSION( major, minor ) \ - ( \ - LIB_VERSION( major1, minor1 ) == \ - LIB_VERSION( LIB_VERSION_MAJOR, LIB_VERSION_MINOR) \ - ) - -/* - * Library versions 2.4 and lower use the old separate library (.lib) and - * document (.dcm) files. Symbol libraries after 2.4 merged the library - * and document files into a single library file. This macro checks if the - * library version supports the old format - */ -#define USE_OLD_DOC_FILE_FORMAT( major, minor ) \ - ( LIB_VERSION( major, minor ) <= LIB_VERSION( 2, 4 ) ) - -enum class SCH_LIB_TYPE -{ - LT_EESCHEMA, - LT_SYMBOL -}; - -// Helper class to filter a list of libraries, and/or a list of SYMBOL_LIB -// in dialogs -class SCHLIB_FILTER -{ -public: - SCHLIB_FILTER() - { - m_filterPowerSymbols = false; - m_forceLoad = false; - } - - /** - * add a lib name to the allowed libraries - */ - void AddLib( const wxString& aLibName ) - { - m_allowedLibs.Add( aLibName ); - m_forceLoad = false; - } - - - /** - * add a lib name to the allowed libraries - */ - void LoadFrom( const wxString& aLibName ) - { - m_allowedLibs.Clear(); - m_allowedLibs.Add( aLibName ); - m_forceLoad = true; - } - - /** - * Clear the allowed libraries list (allows all libs) - */ - void ClearLibList() - { - m_allowedLibs.Clear(); - m_forceLoad = false; - } - - /** - * Set the filtering of power symbols - */ - void FilterPowerSymbols( bool aFilterEnable ) - { - m_filterPowerSymbols = aFilterEnable; - } - - // Accessors - - /** - * @return true if the filtering of power symbols is on - */ - bool GetFilterPowerSymbols() const { return m_filterPowerSymbols; } - - - /** - * @return am wxArrayString of the names of allowed libs - */ - const wxArrayString& GetAllowedLibList() const { return m_allowedLibs; } - - /** - * @return the name of the lib to use to load a symbol, or an a empty string - * Useful to load (in lib editor or lib viewer) a symbol from a given library - */ - const wxString& GetLibSource() const - { - static wxString dummy; - - if( m_forceLoad && m_allowedLibs.GetCount() > 0 ) - return m_allowedLibs[0]; - else - return dummy; - } - -private: - wxArrayString m_allowedLibs; ///< a list of lib names to list some libraries - ///< if empty: no filter - bool m_filterPowerSymbols; ///< true to filter (show only) power symbols - bool m_forceLoad; // When true, load a symbol lib from the lib - // which is given in m_allowedLibs[0] -}; +class SYMBOL_LIB; /* Helpers for creating a list of symbol libraries. */ -class SYMBOL_LIB; -class wxRegEx; - -/** - * LIB_SYMBOL map sorting. - */ -struct LibSymbolMapSort -{ - bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const - { - return aItem1 < aItem2; - } -}; - -/// Symbol map used by symbol library object. - -typedef std::map< wxString, LIB_SYMBOL*, LibSymbolMapSort > LIB_SYMBOL_MAP; typedef boost::ptr_vector< SYMBOL_LIB > SYMBOL_LIBS_BASE; @@ -197,9 +64,6 @@ class SYMBOL_LIBS : public SYMBOL_LIBS_BASE, public PROJECT::_ELEM public: KICAD_T Type() override { return SYMBOL_LIBS_T; } - static int s_modify_generation; ///< helper for GetModifyHash() - static std::mutex s_generationMutex; - SYMBOL_LIBS() { IncrementModifyGeneration(); @@ -311,6 +175,9 @@ public: const wxString& aLibraryName = wxEmptyString ); int GetLibraryCount() { return size(); } + + static int s_modify_generation; ///< helper for GetModifyHash() + static std::mutex s_generationMutex; }; @@ -324,7 +191,7 @@ class SYMBOL_LIB { public: SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName, - SCH_IO_MGR::SCH_FILE_T aPluginType = SCH_IO_MGR::SCH_LEGACY ); + SCH_IO_MGR::SCH_FILE_T aPluginType = SCH_IO_MGR::SCH_LEGACY ); ~SYMBOL_LIB(); /** @@ -450,7 +317,6 @@ public: return fileName.GetName(); } - /** * Allocate and load a symbol library file. * diff --git a/eeschema/symbol_library_common.h b/eeschema/symbol_library_common.h new file mode 100644 index 0000000000..09c44fc6dc --- /dev/null +++ b/eeschema/symbol_library_common.h @@ -0,0 +1,135 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 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, see . + */ + +#ifndef _SYMBOL_LIBRARY_COMMON_H_ +#define _SYMBOL_LIBRARY_COMMON_H_ + +#include + +#include + + +class LIB_SYMBOL; + + +enum class SCH_LIB_TYPE +{ + LT_EESCHEMA, + LT_SYMBOL +}; + + +/** + * Symbol library map sorting helper. + */ +struct LibSymbolMapSort +{ + bool operator() ( const wxString& aItem1, const wxString& aItem2 ) const + { + return aItem1 < aItem2; + } +}; + + +///< Symbol library map sorted by the symbol name. +typedef std::map< wxString, LIB_SYMBOL*, LibSymbolMapSort > LIB_SYMBOL_MAP; + + +/** + * Helper object to filter a list of libraries. + */ +class SYMBOL_LIBRARY_FILTER +{ +public: + SYMBOL_LIBRARY_FILTER() + { + m_filterPowerSymbols = false; + m_forceLoad = false; + } + + /** + * Add \a aLibName to the allowed libraries list. + */ + void AddLib( const wxString& aLibName ) + { + m_allowedLibs.Add( aLibName ); + m_forceLoad = false; + } + + + /** + * Add \a aLibName to the allowed libraries list. + */ + void LoadFrom( const wxString& aLibName ) + { + m_allowedLibs.Clear(); + m_allowedLibs.Add( aLibName ); + m_forceLoad = true; + } + + /** + * Clear the allowed libraries list (allows all libraries). + */ + void ClearLibList() + { + m_allowedLibs.Clear(); + m_forceLoad = false; + } + + /** + * Enable or disable the filtering of power symbols. + */ + void FilterPowerSymbols( bool aFilterEnable ) + { + m_filterPowerSymbols = aFilterEnable; + } + + /** + * @return true if the filtering of power symbols is on. + */ + bool GetFilterPowerSymbols() const { return m_filterPowerSymbols; } + + + /** + * @return the list of the names of allowed libraries. + */ + const wxArrayString& GetAllowedLibList() const { return m_allowedLibs; } + + /** + * @return the name of the library to use to load a symbol or an a empty string if no + * library source available. + */ + const wxString& GetLibSource() const + { + static wxString dummy; + + if( m_forceLoad && m_allowedLibs.GetCount() > 0 ) + return m_allowedLibs[0]; + else + return dummy; + } + +private: + wxArrayString m_allowedLibs; ///< List of filtered library names. + bool m_filterPowerSymbols; ///< Enable or disable power symbol filtering. + bool m_forceLoad; ///< Force loading symbol from library m_allowedLibs[0]. +}; + + +#endif // _SYMBOL_LIBRARY_COMMON_H_ diff --git a/eeschema/symbol_viewer_frame.cpp b/eeschema/symbol_viewer_frame.cpp index 5e510027cb..75e9f5a319 100644 --- a/eeschema/symbol_viewer_frame.cpp +++ b/eeschema/symbol_viewer_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,7 +24,7 @@ */ #include -#include +#include #include #include #include @@ -774,7 +774,7 @@ void SYMBOL_VIEWER_FRAME::CloseLibraryViewer( wxCommandEvent& event ) } -void SYMBOL_VIEWER_FRAME::SetFilter( const SCHLIB_FILTER* aFilter ) +void SYMBOL_VIEWER_FRAME::SetFilter( const SYMBOL_LIBRARY_FILTER* aFilter ) { m_listPowerOnly = false; m_allowedLibs.Clear(); diff --git a/eeschema/symbol_viewer_frame.h b/eeschema/symbol_viewer_frame.h index f2ae1618a4..02a8eceb89 100644 --- a/eeschema/symbol_viewer_frame.h +++ b/eeschema/symbol_viewer_frame.h @@ -3,7 +3,7 @@ * * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,7 @@ #include class wxListBox; -class SCHLIB_FILTER; +class SYMBOL_LIBRARY_FILTER; class LIB_SYMBOL; class SYMBOL_LIB_TABLE_ROW; @@ -112,7 +112,7 @@ public: * see SCH_BASE_FRAME::SelectSymbolFromLibrary() for details. * if aFilter == NULL, remove all filtering. */ - void SetFilter( const SCHLIB_FILTER* aFilter ); + void SetFilter( const SYMBOL_LIBRARY_FILTER* aFilter ); /** * Set the selected library in the library window. diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index b9aa47559f..d9f44c8a37 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include @@ -114,7 +114,7 @@ EDA_RECT SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels() int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) { SCH_SYMBOL* symbol = aEvent.Parameter(); - SCHLIB_FILTER filter; + SYMBOL_LIBRARY_FILTER filter; std::vector* historyList = nullptr; if( m_inPlaceSymbol ) diff --git a/eeschema/tools/sch_drawing_tools.h b/eeschema/tools/sch_drawing_tools.h index 05a183e8c3..53feac9191 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,6 @@ class SCH_SYMBOL; class SCH_BUS_WIRE_ENTRY; -class SCHLIB_FILTER; class SCH_EDIT_FRAME; class EE_SELECTION_TOOL;