2016-11-20 18:33:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-09-02 18:12:50 +00:00
|
|
|
* Copyright (C) 2016 Wayne Stambaugh <stambaughw@gmail.com>
|
2023-04-27 10:54:18 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYMBOL_LIB_TABLE_H_
|
|
|
|
#define _SYMBOL_LIB_TABLE_H_
|
|
|
|
|
|
|
|
#include <lib_table_base.h>
|
|
|
|
#include <sch_io_mgr.h>
|
2017-08-04 18:46:28 +00:00
|
|
|
#include <lib_id.h>
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
//class LIB_SYMBOL;
|
2017-08-04 18:46:28 +00:00
|
|
|
class SYMBOL_LIB_TABLE_GRID;
|
2017-08-12 12:09:39 +00:00
|
|
|
class DIALOG_SYMBOL_LIB_TABLE;
|
2017-08-04 18:46:28 +00:00
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Hold a record identifying a symbol library accessed by the appropriate symbol library
|
|
|
|
* #SCH_PLUGIN object in the #SYMBOL_LIB_TABLE.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
|
|
|
class SYMBOL_LIB_TABLE_ROW : public LIB_TABLE_ROW
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef SCH_IO_MGR::SCH_FILE_T LIB_T;
|
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE_ROW( const wxString& aNick, const wxString& aURI, const wxString& aType,
|
2017-03-05 22:31:31 +00:00
|
|
|
const wxString& aOptions = wxEmptyString,
|
|
|
|
const wxString& aDescr = wxEmptyString ) :
|
2016-11-20 18:33:07 +00:00
|
|
|
LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
|
|
|
|
{
|
|
|
|
SetType( aType );
|
2017-11-15 05:48:31 +00:00
|
|
|
SetEnabled( true );
|
2016-11-20 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE_ROW() :
|
2020-05-15 13:25:11 +00:00
|
|
|
type( SCH_IO_MGR::SCH_KICAD )
|
2016-11-20 18:33:07 +00:00
|
|
|
{
|
2017-11-15 05:48:31 +00:00
|
|
|
SetEnabled( true );
|
2016-11-20 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const;
|
|
|
|
|
|
|
|
bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
|
|
|
|
|
2023-01-20 03:45:46 +00:00
|
|
|
LIB_T SchLibType() const { return type; }
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Return the type of symbol library table represented by this row.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
|
|
|
const wxString GetType() const override { return SCH_IO_MGR::ShowType( type ); }
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Change the schematic plugin type represented by this row.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
|
|
|
void SetType( const wxString& aType ) override;
|
|
|
|
|
2020-07-17 17:32:16 +00:00
|
|
|
/**
|
|
|
|
* Attempt to reload the library.
|
2021-03-25 21:13:01 +00:00
|
|
|
*
|
2020-07-17 17:32:16 +00:00
|
|
|
* @return true if a reload was required.
|
2021-03-25 21:13:01 +00:00
|
|
|
* @throw IO_ERROR if the reload was unsuccessful.
|
2020-07-17 17:32:16 +00:00
|
|
|
*/
|
2023-02-26 23:39:31 +00:00
|
|
|
bool Refresh() override;
|
2020-07-17 17:32:16 +00:00
|
|
|
|
2022-08-27 03:52:56 +00:00
|
|
|
bool SupportsSubLibraries() const { return plugin ? plugin->SupportsSubLibraries() : false; }
|
|
|
|
|
2023-02-26 23:39:31 +00:00
|
|
|
bool SupportsSettingsDialog() const override
|
|
|
|
{
|
|
|
|
// Only database libraries have dialog-configurable options at the moment
|
|
|
|
return type == SCH_IO_MGR::SCH_FILE_T::SCH_DATABASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowSettingsDialog( wxWindow* aWindow ) const override;
|
|
|
|
|
2022-08-27 03:52:56 +00:00
|
|
|
void GetSubLibraryNames( std::vector<wxString>& aNames ) const;
|
|
|
|
|
2022-08-28 23:02:12 +00:00
|
|
|
/**
|
|
|
|
* @see SCH_PLUGIN::GetAvailableSymbolFields
|
|
|
|
*/
|
|
|
|
void GetAvailableSymbolFields( std::vector<wxString>& aNames ) const
|
|
|
|
{
|
|
|
|
if( plugin )
|
|
|
|
plugin->GetAvailableSymbolFields( aNames );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see SCH_PLUGIN::GetDefaultSymbolFields
|
|
|
|
*/
|
|
|
|
void GetDefaultSymbolFields( std::vector<wxString>& aNames ) const
|
|
|
|
{
|
|
|
|
if( plugin )
|
|
|
|
plugin->GetDefaultSymbolFields( aNames );
|
|
|
|
}
|
|
|
|
|
2023-12-07 11:14:10 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T GetFileType() { return type; }
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
protected:
|
|
|
|
SYMBOL_LIB_TABLE_ROW( const SYMBOL_LIB_TABLE_ROW& aRow ) :
|
|
|
|
LIB_TABLE_ROW( aRow ),
|
|
|
|
type( aRow.type )
|
|
|
|
{
|
2017-11-15 05:48:31 +00:00
|
|
|
SetEnabled( aRow.GetIsEnabled() );
|
2016-11-20 18:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-03-25 21:13:01 +00:00
|
|
|
friend class SYMBOL_LIB_TABLE;
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
virtual LIB_TABLE_ROW* do_clone() const override
|
|
|
|
{
|
|
|
|
return new SYMBOL_LIB_TABLE_ROW( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPlugin( SCH_PLUGIN* aPlugin )
|
|
|
|
{
|
|
|
|
plugin.set( aPlugin );
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER plugin;
|
|
|
|
LIB_T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SYMBOL_LIB_TABLE : public LIB_TABLE
|
|
|
|
{
|
2017-08-04 18:46:28 +00:00
|
|
|
public:
|
2018-09-15 11:05:54 +00:00
|
|
|
KICAD_T Type() override { return SYMBOL_LIB_TABLE_T; }
|
|
|
|
|
2017-09-02 18:12:50 +00:00
|
|
|
static const char* PropPowerSymsOnly;
|
|
|
|
static const char* PropNonPowerSymsOnly;
|
|
|
|
|
2017-03-14 22:54:40 +00:00
|
|
|
virtual void Parse( LIB_TABLE_LEXER* aLexer ) override;
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2017-03-14 22:54:40 +00:00
|
|
|
virtual void Format( OUTPUTFORMATTER* aOutput, int aIndentLevel ) const override;
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Build a symbol library table by pre-pending this table fragment in front of
|
2016-11-20 18:33:07 +00:00
|
|
|
* @a aFallBackTable. Loading of this table fragment is done by using Parse().
|
|
|
|
*
|
|
|
|
* @param aFallBackTable is another SYMBOL_LIB_TABLE which is searched only when
|
|
|
|
* a row is not found in this table. No ownership is
|
|
|
|
* taken of aFallBackTable.
|
|
|
|
*/
|
2021-07-16 20:13:26 +00:00
|
|
|
SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = nullptr );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Return an SYMBOL_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
|
|
|
|
* fallBack table fragment.
|
|
|
|
*
|
|
|
|
* The #SCH_PLUGIN is loaded and attached to the "plugin" fieldf the #SYMBOL_LIB_TABLE_ROW if
|
|
|
|
* not already loaded.
|
|
|
|
*
|
|
|
|
* @param aNickName is the name of the row to find.
|
2021-01-10 22:55:30 +00:00
|
|
|
* @param aCheckIfEnabled is a flag to verify if the table entry is enabled or disabled.
|
2017-06-27 15:22:25 +00:00
|
|
|
* @return the row found or NULL if \a aNickName was not found.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
2021-01-10 22:55:30 +00:00
|
|
|
SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName, bool aCheckIfEnabled = false );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
int GetModifyHash();
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
//-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Return a list of symbol alias names contained within the library given by @a aNickname.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
|
2017-09-02 18:12:50 +00:00
|
|
|
* @param aAliasNames is a reference to an array for the alias names.
|
|
|
|
* @param aPowerSymbolsOnly is a flag to enumerate only power symbols.
|
2016-11-20 18:33:07 +00:00
|
|
|
* @throw IO_ERROR if the library cannot be found or loaded.
|
|
|
|
*/
|
2017-09-02 18:12:50 +00:00
|
|
|
void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames,
|
|
|
|
bool aPowerSymbolsOnly = false );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void LoadSymbolLib( std::vector<LIB_SYMBOL*>& aAliasList, const wxString& aNickname,
|
2018-01-24 23:29:45 +00:00
|
|
|
bool aPowerSymbolsOnly = false );
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Load a #LIB_SYMBOL having @a aName from the library given by @a aNickname.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* @param aNickname is a locator for the "library", it is a "name" in #LIB_TABLE_ROW
|
2021-06-10 18:51:46 +00:00
|
|
|
* @param aName is the name of the #LIB_SYMBOL to load.
|
2019-11-06 19:15:42 +00:00
|
|
|
* @param aFlatten set to true to flatten derived parts.
|
2017-06-27 15:22:25 +00:00
|
|
|
* @return the symbol alias if found or NULL if not found.
|
|
|
|
* @throw IO_ERROR if the library cannot be found or read. No exception
|
2019-11-06 19:15:42 +00:00
|
|
|
* is thrown in the case where \a aNickname cannot be found.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
|
2017-06-27 15:22:25 +00:00
|
|
|
{
|
|
|
|
return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
|
|
|
|
}
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* The set of return values from SaveSymbol() below.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
|
|
|
enum SAVE_T
|
|
|
|
{
|
|
|
|
SAVE_OK,
|
|
|
|
SAVE_SKIPPED,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Write @a aSymbol to an existing library given by @a aNickname.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2021-06-10 18:51:46 +00:00
|
|
|
* If a #LIB_SYMBOL by the same name already exists or there are any conflicting alias
|
|
|
|
* names, the new #LIB_SYMBOL will silently overwrite any existing aliases and/or part
|
2021-03-25 21:13:01 +00:00
|
|
|
* because libraries cannot have duplicate alias names. It is the responsibility of
|
2017-06-27 15:22:25 +00:00
|
|
|
* the caller to check the library for conflicts before saving.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW
|
|
|
|
* @param aSymbol is what to store in the library. The library owns the symbol after this
|
|
|
|
* call.
|
|
|
|
* @param aOverwrite when true means overwrite any existing symbol by the same name,
|
|
|
|
* else if false means skip the write and return SAVE_SKIPPED.
|
|
|
|
* @return SAVE_T - SAVE_OK or SAVE_SKIPPED. If error saving, then IO_ERROR is thrown.
|
2017-06-27 15:22:25 +00:00
|
|
|
* @throw IO_ERROR if there is a problem saving the symbol.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
|
2016-11-20 18:33:07 +00:00
|
|
|
bool aOverwrite = true );
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Deletes the @a aSymbolName from the library given by @a aNickname.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
|
|
|
|
* @param aSymbolName is the name of a symbol to delete from the specified library.
|
|
|
|
* @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
|
|
|
|
*/
|
2017-06-21 07:32:19 +00:00
|
|
|
void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Return true if the library given by @a aNickname is writable.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* It is possible that some symbols libraries are read only because of where they are
|
|
|
|
* installed.
|
|
|
|
*
|
|
|
|
* @param aNickname is the library nickname in the symbol library table.
|
2016-11-20 18:33:07 +00:00
|
|
|
* @throw IO_ERROR if no library at @a aNickname exists.
|
|
|
|
*/
|
|
|
|
bool IsSymbolLibWritable( const wxString& aNickname );
|
|
|
|
|
2020-08-29 23:19:05 +00:00
|
|
|
/**
|
|
|
|
* Return true if the library given by @a aNickname was successfully loaded.
|
|
|
|
*
|
|
|
|
* @param aNickname is the library nickname in the symbol library table.
|
|
|
|
* @throw IO_ERROR if no library at @a aNickname exists.
|
|
|
|
*/
|
|
|
|
bool IsSymbolLibLoaded( const wxString& aNickname );
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
void DeleteSymbolLib( const wxString& aNickname );
|
|
|
|
|
|
|
|
void CreateSymbolLib( const wxString& aNickname );
|
|
|
|
|
|
|
|
//-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
|
|
|
|
|
|
|
|
/**
|
2021-06-10 18:51:46 +00:00
|
|
|
* Load a #LIB_SYMBOL having @a aFootprintId with possibly an empty library nickname.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* @param aId the library nickname and name of the symbol to load.
|
|
|
|
* @return the library symbol if found (the library owns it) or NULL if not found.
|
|
|
|
* @throw IO_ERROR if the library cannot be found or read. No exception
|
|
|
|
* is thrown in the case where aId cannot be found.
|
|
|
|
* @throw PARSE_ERROR if @a aId is not parsed OK.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* LoadSymbolWithOptionalNickname( const LIB_ID& aId );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Load the global symbol library table into \a aTable.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* This probably should be move into the application object when KiCad is changed
|
|
|
|
* to a single process application. This is the least painful solution for the
|
|
|
|
* time being.
|
|
|
|
*
|
|
|
|
* @param aTable the #SYMBOL_LIB_TABLE object to load.
|
|
|
|
* @return true if the global library table exists and is loaded properly.
|
|
|
|
* @throw IO_ERROR if an error occurs attempting to load the symbol library table.
|
|
|
|
*/
|
2017-06-08 21:47:21 +00:00
|
|
|
static bool LoadGlobalTable( SYMBOL_LIB_TABLE& aTable );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
*
|
|
|
|
* Fetch the global symbol library table file name.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
|
|
|
* @return the platform specific global symbol library path and file name.
|
|
|
|
*/
|
|
|
|
static wxString GetGlobalTableFileName();
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Return the name of the environment variable used to hold the directory of locally
|
|
|
|
* installed "KiCad sponsored" system symbol libraries.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* These can be either legacy or sweet format. The only thing special about this
|
|
|
|
* particular environment variable is that it is set automatically by KiCad on
|
|
|
|
* program start up, <b>if</b> it is not set already in the environment.
|
2016-11-20 18:33:07 +00:00
|
|
|
*/
|
|
|
|
static const wxString GlobalPathEnvVariableName();
|
2016-11-24 17:57:53 +00:00
|
|
|
|
2017-03-05 22:31:31 +00:00
|
|
|
static SYMBOL_LIB_TABLE& GetGlobalLibTable();
|
2016-11-24 17:57:53 +00:00
|
|
|
|
2017-03-05 22:31:31 +00:00
|
|
|
static const wxString& GetSymbolLibTableFileName();
|
2021-03-25 21:13:01 +00:00
|
|
|
|
2023-04-27 10:54:18 +00:00
|
|
|
/**
|
|
|
|
* Compares this table against another.
|
|
|
|
* This compares the row *contents* against each other.
|
|
|
|
*/
|
|
|
|
bool operator==( const SYMBOL_LIB_TABLE& aOther ) const;
|
|
|
|
|
|
|
|
bool operator!=( const SYMBOL_LIB_TABLE& aOther ) const { return !( *this == aOther ); }
|
|
|
|
|
|
|
|
|
2021-03-25 21:13:01 +00:00
|
|
|
private:
|
|
|
|
friend class SYMBOL_LIB_TABLE_GRID;
|
|
|
|
friend class PANEL_SYM_LIB_TABLE;
|
|
|
|
|
|
|
|
static int m_modifyHash; ///< helper for GetModifyHash()
|
2016-11-20 18:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _SYMBOL_LIB_TABLE_H_
|