Eeschema: lay the groundwork for symbol library tables.
Create SYM_LIB_TABLE and SYMBOL_LIB_TABLE_ROW objects derived from LIB_TABLE and LIB_TABLE_ROW respectively for supporting symbol library tables. Add FPID member to LIB_PART for associating a symbol to a specific library nickname. Please note, this is not used in any way at this time and will be implemented when the symbol library table is actually implemented. Add sym_lib_table keyword to keywords file. This is a temporary measure until a more elegant method for parsing and formatting library tables can be implemented. Build FPID support in the common library instead of the pcbcommon library for use in Eeschema.
This commit is contained in:
parent
40e93d263d
commit
4d018039aa
|
@ -229,6 +229,8 @@ set( COMMON_SRCS
|
|||
eda_pattern_match.cpp
|
||||
exceptions.cpp
|
||||
filter_reader.cpp
|
||||
fpid.cpp
|
||||
fp_lib_table_keywords.cpp
|
||||
# findkicadhelppath.cpp.notused deprecated, use searchhelpfilefullpath.cpp
|
||||
gbr_metadata.cpp
|
||||
gestfich.cpp
|
||||
|
@ -369,8 +371,6 @@ set( PCB_COMMON_SRCS
|
|||
pcb_plot_params_keywords.cpp
|
||||
pcb_keywords.cpp
|
||||
../pcbnew/pcb_parser.cpp
|
||||
fp_lib_table_keywords.cpp
|
||||
fpid.cpp
|
||||
fp_lib_table.cpp
|
||||
)
|
||||
|
||||
|
@ -468,7 +468,7 @@ add_custom_target(
|
|||
|
||||
add_dependencies( pcbcommon pcb_lexer_source_files )
|
||||
|
||||
# auto-generate pcbnew s-expression footprint library table code.
|
||||
# auto-generate s-expression library table code.
|
||||
make_lexer(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/fp_lib_table.keywords
|
||||
${PROJECT_SOURCE_DIR}/include/fp_lib_table_lexer.h
|
||||
|
@ -483,7 +483,7 @@ add_custom_target(
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/fp_lib_table_keywords.cpp
|
||||
)
|
||||
|
||||
add_dependencies( pcbcommon fp_lib_table_lexer_source_files )
|
||||
add_dependencies( common fp_lib_table_lexer_source_files )
|
||||
|
||||
# auto-generate page layout reader s-expression page_layout_reader_lexer.h
|
||||
# and title_block_reader_keywords.cpp.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
fp_lib_table
|
||||
sym_lib_table
|
||||
lib
|
||||
name
|
||||
type
|
||||
|
|
|
@ -172,6 +172,7 @@ set( EESCHEMA_SRCS
|
|||
sheetlab.cpp
|
||||
symbdraw.cpp
|
||||
symbedit.cpp
|
||||
symbol_lib_table.cpp
|
||||
template_fieldnames_keywords.cpp
|
||||
template_fieldnames.cpp
|
||||
tool_lib.cpp
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2004-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2004-2015 KiCad Developers, see change_log.txt for contributors.
|
||||
* Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2004-2016 KiCad Developers, see change_log.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,6 +31,7 @@
|
|||
#define CLASS_LIBENTRY_H
|
||||
|
||||
#include <general.h>
|
||||
#include <fpid.h>
|
||||
#include <lib_draw_item.h>
|
||||
#include <lib_field.h>
|
||||
#include <vector>
|
||||
|
@ -188,6 +189,7 @@ class LIB_PART : public EDA_ITEM
|
|||
|
||||
PART_SPTR m_me; ///< http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
|
||||
wxString m_name;
|
||||
FPID m_libId;
|
||||
int m_pinNameOffset; ///< The offset in mils to draw the pin name. Set to 0
|
||||
///< to draw the pin name above the pin.
|
||||
bool m_unitsLocked; ///< True if part has multiple units and changing
|
||||
|
@ -237,6 +239,9 @@ public:
|
|||
|
||||
const wxString& GetName() { return m_name; }
|
||||
|
||||
const FPID& GetFPID() const { return m_libId; }
|
||||
void SetFPID( const FPID& aFPID ) { m_libId = aFPID; }
|
||||
|
||||
const wxString GetLibraryName();
|
||||
|
||||
PART_LIB* GetLib() { return m_library; }
|
||||
|
|
|
@ -0,0 +1,412 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 Wayne Stambaugh <stambaughw@gmail.com>
|
||||
* Copyright (C) 2016 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 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
|
||||
*/
|
||||
|
||||
|
||||
#include <fctsys.h>
|
||||
#include <common.h>
|
||||
#include <kiface_i.h>
|
||||
#include <macros.h>
|
||||
#include <fpid.h>
|
||||
#include <fp_lib_table_lexer.h>
|
||||
#include <symbol_lib_table.h>
|
||||
#include <class_libentry.h>
|
||||
|
||||
#define OPT_SEP '|' ///< options separator character
|
||||
|
||||
using namespace FP_LIB_TABLE_T;
|
||||
|
||||
|
||||
static const wxChar global_tbl_name[] = wxT( "sym-lib-table" );
|
||||
|
||||
|
||||
bool SYMBOL_LIB_TABLE_ROW::operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const
|
||||
{
|
||||
return LIB_TABLE_ROW::operator == ( aRow ) && type == aRow.type;
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType )
|
||||
{
|
||||
type = SCH_IO_MGR::EnumFromStr( aType );
|
||||
|
||||
if( SCH_IO_MGR::SCH_FILE_T( -1 ) == type )
|
||||
type = SCH_IO_MGR::SCH_KICAD;
|
||||
}
|
||||
|
||||
|
||||
SYMBOL_LIB_TABLE::SYMBOL_LIB_TABLE( SYMBOL_LIB_TABLE* aFallBackTable ) :
|
||||
LIB_TABLE( aFallBackTable )
|
||||
{
|
||||
// not copying fall back, simply search aFallBackTable separately
|
||||
// if "nickName not found".
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::Parse( FP_LIB_TABLE_LEXER* in ) throw()
|
||||
{
|
||||
T tok;
|
||||
|
||||
// This table may be nested within a larger s-expression, or not.
|
||||
// Allow for parser of that optional containing s-epression to have looked ahead.
|
||||
if( in->CurTok() != T_sym_lib_table )
|
||||
{
|
||||
in->NeedLEFT();
|
||||
if( ( tok = in->NextTok() ) != T_sym_lib_table )
|
||||
in->Expecting( T_sym_lib_table );
|
||||
}
|
||||
|
||||
while( ( tok = in->NextTok() ) != T_RIGHT )
|
||||
{
|
||||
std::unique_ptr< SYMBOL_LIB_TABLE_ROW > row( new SYMBOL_LIB_TABLE_ROW );
|
||||
|
||||
if( tok == T_EOF )
|
||||
in->Expecting( T_RIGHT );
|
||||
|
||||
if( tok != T_LEFT )
|
||||
in->Expecting( T_LEFT );
|
||||
|
||||
// in case there is a "row integrity" error, tell where later.
|
||||
int lineNum = in->CurLineNumber();
|
||||
int offset = in->CurOffset();
|
||||
|
||||
if( ( tok = in->NextTok() ) != T_lib )
|
||||
in->Expecting( T_lib );
|
||||
|
||||
// (name NICKNAME)
|
||||
in->NeedLEFT();
|
||||
|
||||
if( ( tok = in->NextTok() ) != T_name )
|
||||
in->Expecting( T_name );
|
||||
|
||||
in->NeedSYMBOLorNUMBER();
|
||||
|
||||
row->SetNickName( in->FromUTF8() );
|
||||
|
||||
in->NeedRIGHT();
|
||||
|
||||
// After (name), remaining (lib) elements are order independent, and in
|
||||
// some cases optional.
|
||||
bool sawType = false;
|
||||
bool sawOpts = false;
|
||||
bool sawDesc = false;
|
||||
bool sawUri = false;
|
||||
|
||||
while( ( tok = in->NextTok() ) != T_RIGHT )
|
||||
{
|
||||
if( tok == T_EOF )
|
||||
in->Unexpected( T_EOF );
|
||||
|
||||
if( tok != T_LEFT )
|
||||
in->Expecting( T_LEFT );
|
||||
|
||||
tok = in->NeedSYMBOLorNUMBER();
|
||||
|
||||
switch( tok )
|
||||
{
|
||||
case T_uri:
|
||||
if( sawUri )
|
||||
in->Duplicate( tok );
|
||||
sawUri = true;
|
||||
in->NeedSYMBOLorNUMBER();
|
||||
row->SetFullURI( in->FromUTF8() );
|
||||
break;
|
||||
|
||||
case T_type:
|
||||
if( sawType )
|
||||
in->Duplicate( tok );
|
||||
sawType = true;
|
||||
in->NeedSYMBOLorNUMBER();
|
||||
row->SetType( in->FromUTF8() );
|
||||
break;
|
||||
|
||||
case T_options:
|
||||
if( sawOpts )
|
||||
in->Duplicate( tok );
|
||||
sawOpts = true;
|
||||
in->NeedSYMBOLorNUMBER();
|
||||
row->SetOptions( in->FromUTF8() );
|
||||
break;
|
||||
|
||||
case T_descr:
|
||||
if( sawDesc )
|
||||
in->Duplicate( tok );
|
||||
sawDesc = true;
|
||||
in->NeedSYMBOLorNUMBER();
|
||||
row->SetDescr( in->FromUTF8() );
|
||||
break;
|
||||
|
||||
default:
|
||||
in->Unexpected( tok );
|
||||
}
|
||||
|
||||
in->NeedRIGHT();
|
||||
}
|
||||
|
||||
if( !sawType )
|
||||
in->Expecting( T_type );
|
||||
|
||||
if( !sawUri )
|
||||
in->Expecting( T_uri );
|
||||
|
||||
// all nickNames within this table fragment must be unique, so we do not
|
||||
// use doReplace in InsertRow(). (However a fallBack table can have a
|
||||
// conflicting nickName and ours will supercede that one since in
|
||||
// FindLib() we search this table before any fall back.)
|
||||
if( !InsertRow( row.release() ) )
|
||||
{
|
||||
wxString msg = wxString::Format(
|
||||
_( "'%s' is a duplicate symbol library nickname" ),
|
||||
GetChars( row->GetNickName() ) );
|
||||
THROW_PARSE_ERROR( msg, in->CurSource(), in->CurLine(), lineNum, offset );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::Format( OUTPUTFORMATTER* out, int nestLevel ) const
|
||||
throw()
|
||||
{
|
||||
out->Print( nestLevel, "(sym_lib_table\n" );
|
||||
|
||||
for( LIB_TABLE_ROWS_CITER it = rows.begin(); it != rows.end(); ++it )
|
||||
it->Format( out, nestLevel+1 );
|
||||
|
||||
out->Print( nestLevel, ")\n" );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
row->plugin->EnumerateSymbolLib( aAliasNames, row->GetFullURI( true ), row->GetProperties() );
|
||||
}
|
||||
|
||||
|
||||
const SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname )
|
||||
throw( IO_ERROR )
|
||||
{
|
||||
SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) );
|
||||
|
||||
if( !row )
|
||||
{
|
||||
wxString msg = wxString::Format(
|
||||
_( "sym-lib-table files contain no library with nickname '%s'" ),
|
||||
GetChars( aNickname ) );
|
||||
|
||||
THROW_IO_ERROR( msg );
|
||||
}
|
||||
|
||||
// We've been 'lazy' up until now, but it cannot be deferred any longer,
|
||||
// instantiate a PLUGIN of the proper kind if it is not already in this
|
||||
// SYMBOL_LIB_TABLE_ROW.
|
||||
if( !row->plugin )
|
||||
row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) );
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
|
||||
LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxString& aAliasName )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
|
||||
LIB_ALIAS* ret = row->plugin->LoadSymbol( row->GetFullURI( true ), aAliasName,
|
||||
row->GetProperties() );
|
||||
|
||||
// The library cannot know its own name, because it might have been renamed or moved.
|
||||
// Therefore footprints cannot know their own library nickname when residing in
|
||||
// a symbol library.
|
||||
// Only at this API layer can we tell the symbol about its actual library nickname.
|
||||
if( ret )
|
||||
{
|
||||
// remove "const"-ness, I really do want to set nickname without
|
||||
// having to copy the FPID and its two strings, twice each.
|
||||
FPID& fpid = (FPID&) ret->GetPart()->GetFPID();
|
||||
|
||||
// Catch any misbehaving plugin, which should be setting internal alias name properly:
|
||||
wxASSERT( aAliasName == (wxString) fpid.GetFootprintName() );
|
||||
|
||||
// and clearing nickname
|
||||
wxASSERT( !fpid.GetLibNickname().size() );
|
||||
|
||||
fpid.SetLibNickname( row->GetNickName() );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
SYMBOL_LIB_TABLE::SAVE_T SYMBOL_LIB_TABLE::SaveSymbol( const wxString& aNickname,
|
||||
const LIB_PART* aSymbol, bool aOverwrite )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
|
||||
if( !aOverwrite )
|
||||
{
|
||||
// Try loading the footprint to see if it already exists, caller wants overwrite
|
||||
// protection, which is atypical, not the default.
|
||||
|
||||
wxString name = aSymbol->GetFPID().GetFootprintName();
|
||||
|
||||
std::unique_ptr< LIB_ALIAS > symbol( row->plugin->LoadSymbol( row->GetFullURI( true ),
|
||||
name,
|
||||
row->GetProperties() ) );
|
||||
|
||||
if( symbol.get() )
|
||||
return SAVE_SKIPPED;
|
||||
}
|
||||
|
||||
row->plugin->SaveSymbol( row->GetFullURI( true ), aSymbol, row->GetProperties() );
|
||||
|
||||
return SAVE_OK;
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
return row->plugin->DeleteSymbol( row->GetFullURI( true ), aSymbolName,
|
||||
row->GetProperties() );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::DeleteAlias( const wxString& aNickname, const wxString& aAliasName )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
return row->plugin->DeleteAlias( row->GetFullURI( true ), aAliasName,
|
||||
row->GetProperties() );
|
||||
}
|
||||
|
||||
|
||||
bool SYMBOL_LIB_TABLE::IsSymbolLibWritable( const wxString& aNickname )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
return row->plugin->IsSymbolLibWritable( row->GetFullURI( true ) );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::DeleteSymbolLib( const wxString& aNickname )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
row->plugin->DeleteSymbolLib( row->GetFullURI( true ), row->GetProperties() );
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIB_TABLE::CreateSymbolLib( const wxString& aNickname )
|
||||
{
|
||||
const SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname );
|
||||
wxASSERT( (SCH_PLUGIN*) row->plugin );
|
||||
row->plugin->CreateSymbolLib( row->GetFullURI( true ), row->GetProperties() );
|
||||
}
|
||||
|
||||
|
||||
LIB_ALIAS* SYMBOL_LIB_TABLE::LoadSymbolWithOptionalNickname( const FPID& aFootprintId )
|
||||
throw( IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception )
|
||||
{
|
||||
wxString nickname = aFootprintId.GetLibNickname();
|
||||
wxString name = aFootprintId.GetFootprintName();
|
||||
|
||||
if( nickname.size() )
|
||||
{
|
||||
return LoadSymbol( nickname, name );
|
||||
}
|
||||
|
||||
// nickname is empty, sequentially search (alphabetically) all libs/nicks for first match:
|
||||
else
|
||||
{
|
||||
std::vector<wxString> nicks = GetLogicalLibs();
|
||||
|
||||
// Search each library going through libraries alphabetically.
|
||||
for( unsigned i = 0; i < nicks.size(); ++i )
|
||||
{
|
||||
// FootprintLoad() returns NULL on not found, does not throw exception
|
||||
// unless there's an IO_ERROR.
|
||||
LIB_ALIAS* ret = LoadSymbol( nicks[i], name );
|
||||
|
||||
if( ret )
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const wxString SYMBOL_LIB_TABLE::GlobalPathEnvVariableName()
|
||||
{
|
||||
return "KICAD_SYSTEM_SYMBOLS";
|
||||
}
|
||||
|
||||
|
||||
bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable )
|
||||
throw (IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception )
|
||||
{
|
||||
bool tableExists = true;
|
||||
wxFileName fn = GetGlobalTableFileName();
|
||||
|
||||
if( !fn.FileExists() )
|
||||
{
|
||||
tableExists = false;
|
||||
|
||||
if( !fn.DirExists() && !fn.Mkdir( 0x777, wxPATH_MKDIR_FULL ) )
|
||||
{
|
||||
THROW_IO_ERROR( wxString::Format( _( "Cannot create global library table path '%s'." ),
|
||||
GetChars( fn.GetPath() ) ) );
|
||||
}
|
||||
|
||||
// Attempt to copy the default global file table from the KiCad
|
||||
// template folder to the user's home configuration path.
|
||||
wxString fileName = Kiface().KifaceSearch().FindValidPath( global_tbl_name );
|
||||
|
||||
// The fallback is to create an empty global footprint table for the user to populate.
|
||||
if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
|
||||
{
|
||||
SYMBOL_LIB_TABLE emptyTable;
|
||||
|
||||
emptyTable.Save( fn.GetFullPath() );
|
||||
}
|
||||
}
|
||||
|
||||
aTable.Load( fn.GetFullPath() );
|
||||
|
||||
return tableExists;
|
||||
}
|
||||
|
||||
|
||||
wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName()
|
||||
{
|
||||
wxFileName fn;
|
||||
|
||||
fn.SetPath( GetKicadConfigPath() );
|
||||
fn.SetName( global_tbl_name );
|
||||
|
||||
return fn.GetFullPath();
|
||||
}
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 2016 KiCad Developers, see change_log.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 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>
|
||||
|
||||
class LIB_PART;
|
||||
class IO_ERROR;
|
||||
|
||||
/**
|
||||
* Class SYMBOL_LIB_TABLE_ROW
|
||||
*
|
||||
* holds a record identifying a library accessed by the appropriate footprint library #PLUGIN
|
||||
* object in the #SYMBOL_LIB_TABLE.
|
||||
*/
|
||||
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,
|
||||
const wxString& aOptions, const wxString& aDescr = wxEmptyString ) :
|
||||
LIB_TABLE_ROW( aNick, aURI, aOptions, aDescr )
|
||||
{
|
||||
SetType( aType );
|
||||
}
|
||||
|
||||
SYMBOL_LIB_TABLE_ROW() :
|
||||
type( SCH_IO_MGR::SCH_KICAD )
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==( const SYMBOL_LIB_TABLE_ROW& aRow ) const;
|
||||
|
||||
bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
|
||||
|
||||
/**
|
||||
* Function GetType
|
||||
*
|
||||
* returns the type of symbol library table represented by this row.
|
||||
*/
|
||||
const wxString GetType() const override { return SCH_IO_MGR::ShowType( type ); }
|
||||
|
||||
/**
|
||||
* Function SetType
|
||||
*
|
||||
* changes the type represented by this row.
|
||||
*/
|
||||
void SetType( const wxString& aType ) override;
|
||||
|
||||
protected:
|
||||
SYMBOL_LIB_TABLE_ROW( const SYMBOL_LIB_TABLE_ROW& aRow ) :
|
||||
LIB_TABLE_ROW( aRow ),
|
||||
type( aRow.type )
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void Parse( FP_LIB_TABLE_LEXER* aLexer ) throw() override;
|
||||
|
||||
virtual void Format( OUTPUTFORMATTER* out, int nestLevel ) const throw() override;
|
||||
|
||||
/**
|
||||
* Constructor SYMBOL_LIB_TABLE
|
||||
*
|
||||
* builds a footprint library table by pre-pending this table fragment in front of
|
||||
* @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 );
|
||||
|
||||
/**
|
||||
* Function FindRow
|
||||
*
|
||||
* returns an SYMBOL_LIB_TABLE_ROW if \a aNickName is found in this table or in any chained
|
||||
* fallBack table fragment. The #PLUGIN is loaded and attached to the "plugin" field
|
||||
* of the #SYMBOL_LIB_TABLE_ROW if not already loaded.
|
||||
*
|
||||
* @throw IO_ERROR if \a aNickName cannot be found.
|
||||
*/
|
||||
const SYMBOL_LIB_TABLE_ROW* FindRow( const wxString& aNickName ) throw( IO_ERROR );
|
||||
|
||||
//-----<PLUGIN API SUBSET, REBASED ON aNickname>---------------------------
|
||||
|
||||
/**
|
||||
* Function EnumerateSymbolLib
|
||||
*
|
||||
* returns a list of symbol alias names contained within the library given by @a aNickname.
|
||||
*
|
||||
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW.
|
||||
* @param aAliasNames is a reference to an array for the alias names
|
||||
*
|
||||
* @throw IO_ERROR if the library cannot be found or loaded.
|
||||
*/
|
||||
void EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames );
|
||||
|
||||
/**
|
||||
* Function LoadSymbol
|
||||
*
|
||||
* loads a #LIB_ALIAS having @a aAliasName from the library given by @a aNickname.
|
||||
* The actual symbol can be retreaved from the LIB_ALIAS::GetPart() method.
|
||||
*
|
||||
* @param aNickname is a locator for the "library", it is a "name" in #LIB_TABLE_ROW
|
||||
*
|
||||
* @param aAliasName is the name of the #LIB_ALIAS to load.
|
||||
*
|
||||
* @return LIB_ALIAS* - if found we own it, else NULL if not found.
|
||||
*
|
||||
* @throw IO_ERROR if the library cannot be found or read. No exception
|
||||
* is thrown in the case where aAliasName cannot be found.
|
||||
*/
|
||||
LIB_ALIAS* LoadSymbol( const wxString& aNickname, const wxString& aAliasName );
|
||||
|
||||
/**
|
||||
* Enum SAVE_T
|
||||
*
|
||||
* is the set of return values from SaveSymbol() below.
|
||||
*/
|
||||
enum SAVE_T
|
||||
{
|
||||
SAVE_OK,
|
||||
SAVE_SKIPPED,
|
||||
};
|
||||
|
||||
/**
|
||||
* Function SaveSymbol
|
||||
*
|
||||
* will write @a aSymbol to an existing library given by @a aNickname. 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.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @throw IO_ERROR if there is a problem saving.
|
||||
*/
|
||||
SAVE_T SaveSymbol( const wxString& aNickname, const LIB_PART* aSymbol,
|
||||
bool aOverwrite = true );
|
||||
|
||||
/**
|
||||
* Function DeleteSymbol
|
||||
*
|
||||
* deletes the @a aSymbolName from the library given by @a aNickname.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
void DeleteSymbol( const wxString& aNickname, const wxString& aSymboltName );
|
||||
|
||||
/**
|
||||
* Function DeleteAlias
|
||||
*
|
||||
* deletes @a aAliasName from the library at @a aLibraryPath.
|
||||
*
|
||||
* If @a aAliasName refers the the root #LIB_PART object, the part is renamed to
|
||||
* the next or previous #LIB_ALIAS in the #LIB_PART if one exists. If the #LIB_ALIAS
|
||||
* is the last alias referring to the root #LIB_PART, the #LIB_PART is also removed
|
||||
* from the library.
|
||||
*
|
||||
* @param aNickname is a locator for the "library", it is a "name" in LIB_TABLE_ROW
|
||||
*
|
||||
* @param aAliasName is the name of a #LIB_ALIAS to delete from the specified library.
|
||||
*
|
||||
* @throw IO_ERROR if there is a problem finding the alias or the library or deleting it.
|
||||
*/
|
||||
void DeleteAlias( const wxString& aNickname, const wxString& aAliasName );
|
||||
|
||||
/**
|
||||
* Function IsSymbolLibWritable
|
||||
*
|
||||
* returns true if the library given by @a aNickname is writable. (Often
|
||||
* system libraries are read only because of where they are installed.)
|
||||
*
|
||||
* @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>---------------------------
|
||||
|
||||
/**
|
||||
* Function LoadSymboldWithOptionalNickname
|
||||
* loads a #LIB_PART having @a aFootprintId with possibly an empty librarynickname.
|
||||
*
|
||||
* @param aId the library nickname and name of the symbol to load.
|
||||
*
|
||||
* @return LIB_PART* - if found the library owns it, else 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 atId is not parsed OK.
|
||||
*/
|
||||
LIB_ALIAS* LoadSymbolWithOptionalNickname( const FPID& aId )
|
||||
throw( IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception );
|
||||
|
||||
/**
|
||||
* Function LoadGlobalTable
|
||||
*
|
||||
* loads the global symbol library table into \a aTable.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
static bool LoadGlobalTable( SYMBOL_LIB_TABLE& aTable )
|
||||
throw (IO_ERROR, PARSE_ERROR, boost::interprocess::lock_exception );
|
||||
|
||||
/**
|
||||
* Function GetGlobalTableFileName
|
||||
*
|
||||
* @return the platform specific global symbol library path and file name.
|
||||
*/
|
||||
static wxString GetGlobalTableFileName();
|
||||
|
||||
/**
|
||||
* Function GlobalPathEnvVarVariableName
|
||||
*
|
||||
* returns the name of the environment variable used to hold the directory of locally
|
||||
* installed "KiCad sponsored" system symbol libraries. 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.
|
||||
*/
|
||||
static const wxString GlobalPathEnvVariableName();
|
||||
};
|
||||
|
||||
|
||||
#endif // _SYMBOL_LIB_TABLE_H_
|
Loading…
Reference in New Issue