DbLib: Load source symbol in editor when edit action is taken

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12840
This commit is contained in:
Jon Evans 2023-01-19 22:45:46 -05:00
parent 6cce99e0d0
commit dee4f80680
4 changed files with 39 additions and 6 deletions

View File

@ -141,6 +141,9 @@ public:
LIB_ID GetLibId() const override { return m_libId; }
void SetLibId( const LIB_ID& aLibId ) { m_libId = aLibId; }
LIB_ID GetSourceLibId() const { return m_sourceLibId; }
void SetSourceLibId( const LIB_ID& aLibId ) { m_sourceLibId = aLibId; }
wxString GetLibNickname() const override { return GetLibraryName(); }
void SetDescription( const wxString& aDescription ) { m_description = aDescription; }
@ -747,6 +750,7 @@ private:
LIB_SYMBOL_SPTR m_me;
LIB_SYMBOL_REF m_parent; ///< Use for inherited symbols.
LIB_ID m_libId;
LIB_ID m_sourceLibId; ///< For database library symbols; the original symbol
timestamp_t m_lastModDate;
int m_unitCount; ///< Number of units (parts) per package.

View File

@ -312,6 +312,7 @@ LIB_SYMBOL* SCH_DATABASE_PLUGIN::loadSymbolFromRow( const wxString& aSymbolName,
wxLogTrace( traceDatabase, wxT( "loadSymbolFromRow: found original symbol '%s'" ),
symbolIdStr );
symbol = originalSymbol->Duplicate();
symbol->SetSourceLibId( symbolId );
}
else
{

View File

@ -142,8 +142,34 @@ bool SYMBOL_EDIT_FRAME::saveCurrentSymbol()
bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConvert )
{
LIB_ID libId = aLibId;
// Database library symbols can't be edited, so load the underlying chosen symbol
if( SYMBOL_LIB_TABLE_ROW* lib = m_libMgr->GetLibrary( aLibId.GetLibNickname() ) )
{
if( lib->SchLibType() == SCH_IO_MGR::SCH_DATABASE )
{
try
{
LIB_SYMBOL* dbSym = Prj().SchSymbolLibTable()->LoadSymbol( aLibId );
if( dbSym && dbSym->GetSourceLibId().IsValid() )
libId = dbSym->GetSourceLibId();
}
catch( const IO_ERROR& ioe )
{
wxString msg;
msg.Printf( _( "Error loading symbol %s from library '%s'." ),
aLibId.GetUniStringLibId(), aLibId.GetUniStringLibItemName() );
DisplayErrorMessage( this, msg, ioe.What() );
return false;
}
}
}
if( GetCurSymbol() && !IsSymbolFromSchematic()
&& GetCurSymbol()->GetLibId() == aLibId
&& GetCurSymbol()->GetLibId() == libId
&& GetUnit() == aUnit
&& GetConvert() == aConvert )
{
@ -162,14 +188,14 @@ bool SYMBOL_EDIT_FRAME::LoadSymbol( const LIB_ID& aLibId, int aUnit, int aConver
}
}
SelectActiveLibrary( aLibId.GetLibNickname() );
SelectActiveLibrary( libId.GetLibNickname() );
if( LoadSymbolFromCurrentLib( aLibId.GetLibItemName(), aUnit, aConvert ) )
if( LoadSymbolFromCurrentLib( libId.GetLibItemName(), aUnit, aConvert ) )
{
m_treePane->GetLibTree()->SelectLibId( aLibId );
m_treePane->GetLibTree()->ExpandLibId( aLibId );
m_treePane->GetLibTree()->SelectLibId( libId );
m_treePane->GetLibTree()->ExpandLibId( libId );
m_centerItemOnIdle = aLibId;
m_centerItemOnIdle = libId;
Bind( wxEVT_IDLE, &SYMBOL_EDIT_FRAME::centerItemIdleHandler, this );
return true;

View File

@ -62,6 +62,8 @@ public:
bool operator!=( const SYMBOL_LIB_TABLE_ROW& aRow ) const { return !( *this == aRow ); }
LIB_T SchLibType() const { return type; }
/**
* Return the type of symbol library table represented by this row.
*/