Factor out common and remove dead legacy symbol library code.

This commit is contained in:
Wayne Stambaugh 2022-01-29 14:07:07 -05:00
parent aef665b1e2
commit b36e31c49f
9 changed files with 186 additions and 167 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <pgm_base.h>
#include <settings/settings_manager.h>
#include <core/kicad_algo.h>
#include <symbol_library.h>
#include <symbol_library_common.h>
#include <confirm.h>
#include <eeschema_id.h>
#include <general.h>
@ -35,6 +35,7 @@
#include <symbol_tree_model_adapter.h>
#include <symbol_editor/symbol_editor_settings.h>
#include <sch_symbol.h>
#include <symbol_library_common.h>
#include <sch_edit_frame.h>
#include <symbol_lib_table.h>
#include <tool/tool_manager.h>
@ -43,7 +44,7 @@
#include <dialog_choose_symbol.h>
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<PICKED_SYMBOL>& aHistoryList,
bool aUseLibBrowser, int aUnit, int aConvert,
bool aShowFootprints, const LIB_ID* aHighlight,

View File

@ -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 <dick@softplc.com>
* 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<PICKED_SYMBOL>& 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 );

View File

@ -63,14 +63,32 @@
#include <lib_text.h>
#include <eeschema_id.h> // for MAX_UNIT_COUNT_PER_PACKAGE definition
#include <tool/selection.h>
#include <wildcards_and_files_ext.h>
#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 );

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <map>
#include <mutex>
#include <boost/ptr_container/ptr_vector.hpp>
#include <wx/filename.h>
#include <sch_io_mgr.h>
#include <project.h>
#include <sch_io_mgr.h>
#include <symbol_library_common.h>
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;
};
@ -450,7 +317,6 @@ public:
return fileName.GetName();
}
/**
* Allocate and load a symbol library file.
*

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef _SYMBOL_LIBRARY_COMMON_H_
#define _SYMBOL_LIBRARY_COMMON_H_
#include <map>
#include <wx/arrstr.h>
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_

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <bitmaps.h>
#include <symbol_library.h>
#include <symbol_library_common.h>
#include <confirm.h>
#include <dialog_choose_symbol.h>
#include <eeschema_id.h>
@ -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();

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* 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 <tool/selection.h>
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.

View File

@ -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 <sch_sheet_pin.h>
#include <sch_bitmap.h>
#include <schematic.h>
#include <symbol_library.h>
#include <symbol_library_common.h>
#include <eeschema_settings.h>
#include <dialogs/dialog_label_properties.h>
#include <dialogs/dialog_text_properties.h>
@ -114,7 +114,7 @@ EDA_RECT SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels()
int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent )
{
SCH_SYMBOL* symbol = aEvent.Parameter<SCH_SYMBOL*>();
SCHLIB_FILTER filter;
SYMBOL_LIBRARY_FILTER filter;
std::vector<PICKED_SYMBOL>* historyList = nullptr;
if( m_inPlaceSymbol )

View File

@ -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;