From 80dd3f8635c667edec0fe5672ff60e580ef7d208 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 25 Aug 2019 21:50:33 +0100 Subject: [PATCH] Draw datasheet field with the value from the dfm file. Fixes: lp:1841369 * https://bugs.launchpad.net/kicad/+bug/1841369 --- eeschema/class_libentry.cpp | 22 ++++++++++++++----- eeschema/class_libentry.h | 5 +++-- .../dialogs/dialog_edit_component_in_lib.cpp | 1 - eeschema/libedit/lib_edit_frame.cpp | 3 +++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 66e355e294..6edcfbb12b 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -1112,22 +1112,34 @@ void LIB_PART::RemoveAllAliases() } -LIB_ALIAS* LIB_PART::GetAlias( const wxString& aName ) +LIB_ALIAS* LIB_PART::GetAlias( const wxString& aName ) const { wxCHECK2_MSG( !aName.IsEmpty(), return NULL, wxT( "Cannot get alias with an empty name. Bad programmer!" ) ); - for( size_t i = 0; i < m_aliases.size(); i++ ) + for( LIB_ALIAS* alias : m_aliases) { - if( aName == m_aliases[i]->GetName() ) - return m_aliases[i]; + if( alias->GetName() == aName ) + return alias; } return NULL; } -LIB_ALIAS* LIB_PART::GetAlias( size_t aIndex ) +LIB_ALIAS* LIB_PART::GetRootAlias() const +{ + for( LIB_ALIAS* alias : m_aliases ) + { + if( alias->IsRoot() ) + return alias; + } + + return NULL; +} + + +LIB_ALIAS* LIB_PART::GetAlias( size_t aIndex ) const { wxCHECK2_MSG( aIndex < m_aliases.size(), return NULL, wxT( "Illegal alias list index, bad programmer." ) ); diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index e20fc14c7a..1d8816cf28 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -281,8 +281,9 @@ public: size_t GetAliasCount() const { return m_aliases.size(); } - LIB_ALIAS* GetAlias( size_t aIndex ); - LIB_ALIAS* GetAlias( const wxString& aName ); + LIB_ALIAS* GetAlias( size_t aIndex ) const; + LIB_ALIAS* GetAlias( const wxString& aName ) const; + LIB_ALIAS* GetRootAlias() const; timestamp_t GetDateLastEdition() const { return m_dateLastEdition; } diff --git a/eeschema/dialogs/dialog_edit_component_in_lib.cpp b/eeschema/dialogs/dialog_edit_component_in_lib.cpp index b23b460da9..ea00e10118 100644 --- a/eeschema/dialogs/dialog_edit_component_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_lib.cpp @@ -330,7 +330,6 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::TransferDataFromWindow() // Datasheet field is special; copy it to the root alias docfilename rootAlias->SetDocFileName( m_fields->at( DATASHEET ).GetText() ); - m_fields->at( DATASHEET ).SetText( wxEmptyString ); m_libEntry->SetFields( *m_fields ); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 5a7506190b..ca1f1fd956 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -406,6 +406,9 @@ void LIB_EDIT_FRAME::SetCurPart( LIB_PART* aPart ) { delete m_my_part; m_my_part = aPart; + + // Datasheet field is special; copy it to the root alias docfilename + m_my_part->GetField( DATASHEET )->SetText( aPart->GetRootAlias()->GetDocFileName() ); } // select the current component in the tree widget