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>
|
2020-05-15 13:25:11 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see change_log.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>
|
2019-11-06 19:15:42 +00:00
|
|
|
#include <class_libentry.h>
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
//class LIB_PART;
|
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
|
|
|
|
{
|
|
|
|
friend class SYMBOL_LIB_TABLE;
|
|
|
|
|
|
|
|
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 ); }
|
|
|
|
|
|
|
|
/**
|
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;
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
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
|
|
|
friend class SYMBOL_LIB_TABLE_GRID;
|
2018-07-20 17:46:56 +00:00
|
|
|
friend class PANEL_SYM_LIB_TABLE;
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2017-09-01 20:42:20 +00:00
|
|
|
static int m_modifyHash; ///< helper for GetModifyHash()
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable = NULL );
|
|
|
|
|
|
|
|
/**
|
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.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
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
|
|
|
*
|
|
|
|
* @throw IO_ERROR if \a aNickName cannot be found.
|
|
|
|
*/
|
2017-10-06 18:07:43 +00:00
|
|
|
SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName );
|
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
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
void LoadSymbolLib( std::vector<LIB_PART*>& aAliasList, const wxString& aNickname,
|
2018-01-24 23:29:45 +00:00
|
|
|
bool aPowerSymbolsOnly = false );
|
|
|
|
|
2016-11-20 18:33:07 +00:00
|
|
|
/**
|
2019-11-06 19:15:42 +00:00
|
|
|
* Load a #LIB_PART 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
|
2019-11-06 19:15:42 +00:00
|
|
|
* @param aName is the name of the #LIB_PART to load.
|
|
|
|
* @param aFlatten set to true to flatten derived parts.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* @return the symbol alias if found or NULL if not found.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* @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
|
|
|
*/
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* LoadSymbol( const wxString& aNickname, const wxString& aName );
|
2016-11-20 18:33:07 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* 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
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* If a #LIB_PART by the same name already exists or there are any conflicting alias
|
|
|
|
* names, the new #LIB_PART will silently overwrite any existing aliases and/or part
|
|
|
|
* becaue libraries cannot have duplicate alias names. It is the responsibility of
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
SAVE_T SaveSymbol( const wxString& aNickname, const LIB_PART* aSymbol,
|
|
|
|
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 );
|
|
|
|
|
|
|
|
void DeleteSymbolLib( const wxString& aNickname );
|
|
|
|
|
|
|
|
void CreateSymbolLib( const wxString& aNickname );
|
|
|
|
|
|
|
|
//-----</PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
|
|
|
|
|
|
|
|
/**
|
2017-06-27 15:22:25 +00:00
|
|
|
* Load a #LIB_PART 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.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* @return the library symbol if found (the library owns it) or NULL if not found.
|
2016-11-20 18:33:07 +00:00
|
|
|
*
|
2017-06-27 15:22:25 +00:00
|
|
|
* @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
|
|
|
*/
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* 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.
|
2017-06-27 15:22:25 +00:00
|
|
|
*
|
2016-11-20 18:33:07 +00:00
|
|
|
* @return true if the global library table exists and is loaded properly.
|
2017-06-27 15:22:25 +00:00
|
|
|
*
|
2016-11-20 18:33:07 +00:00
|
|
|
* @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();
|
2016-11-20 18:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _SYMBOL_LIB_TABLE_H_
|