From 371c5a9259dddcbbdf90aafdc12d4c39f1d4d6fa Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Tue, 31 Dec 2019 08:05:52 -0500 Subject: [PATCH] Eeschema: fix symbol properties dialog bug. Derived symbols were causing the symbol properties grid to assume that the reference could not be edited because derived symbols inherit the reference from the parent symbol. The flattened symbols in the schematic still have the parent set which cause the issue. Clearing the parent of the flattened symbol resolves the issue. Fix a minor bug in the symbol information of derived symbols show in the symbol chooser dialog. Fixes #3723 https://gitlab.com/kicad/code/kicad/issues/3723 --- .../dialog_edit_component_in_schematic.cpp | 2 +- eeschema/generate_alias_info.cpp | 9 +++++-- eeschema/sch_component.cpp | 27 ++++++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 941a9d97dd..c2e4bf4964 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -58,7 +58,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( SCH_EDIT m_config = Kiface().KifaceSettings(); m_cmp = aComponent; - m_part = GetParent()->GetLibPart( m_cmp->GetLibId(), true ); + m_part = m_cmp->GetPartRef().get(); m_fields = new FIELDS_GRID_TABLE( this, aParent, m_part ); m_width = 0; diff --git a/eeschema/generate_alias_info.cpp b/eeschema/generate_alias_info.cpp index 90079d3335..e34d7c0f5f 100644 --- a/eeschema/generate_alias_info.cpp +++ b/eeschema/generate_alias_info.cpp @@ -122,8 +122,13 @@ protected: wxString root_name = _( "Unknown" ); wxString root_desc = ""; - root_name = m_symbol->SharedPtr()->GetName(); - root_desc = m_symbol->SharedPtr()->GetDescription(); + std::shared_ptr< LIB_PART > parent = m_symbol->GetParent().lock(); + + if( parent ) + { + root_name = parent->GetName(); + root_desc = parent->GetDescription(); + } m_html.Replace( "__ALIASOF__", wxString::Format( diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index ae86a337c9..84c6d7e1f3 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -130,7 +130,12 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_PART& aPart, LIB_ID aLibId, SCH_SHEET_PATH* sh m_unit = unit; m_convert = convert; m_lib_id = aLibId; - m_part.reset( new LIB_PART( aPart ) ); + + std::unique_ptr< LIB_PART > part; + + part = aPart.Flatten(); + part->SetParent(); + m_part.reset( part.release() ); m_fieldsAutoplaced = AUTOPLACED_NO; SetTimeStamp( GetNewTimeStamp() ); @@ -274,7 +279,10 @@ void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aSymLibTab LIB_PART* tmp = aSymLibTable->LoadSymbol( m_lib_id ); if( tmp ) + { symbol = tmp->Flatten(); + symbol->SetParent(); + } } if( !symbol && aCacheLib ) @@ -282,7 +290,10 @@ void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, SYMBOL_LIB_TABLE* aSymLibTab LIB_PART* tmp = aCacheLib->FindPart( m_lib_id.Format().wx_str() ); if( tmp ) - symbol.reset( new LIB_PART( *tmp ) ); + { + symbol = tmp->Flatten(); + symbol->SetParent(); + } } m_part.reset( symbol.release() ); @@ -318,7 +329,9 @@ bool SCH_COMPONENT::Resolve( PART_LIBS* aLibs ) // flimsy search path ordering. None-the-less find a part based on that design: if( LIB_PART* part = aLibs->FindLibPart( m_lib_id ) ) { - m_part.reset( new LIB_PART( *part ) ); + std::unique_ptr< LIB_PART > flattenedPart = part->Flatten(); + flattenedPart->SetParent(); + m_part.reset( flattenedPart.release() ); UpdatePins(); return true; } @@ -346,7 +359,10 @@ bool SCH_COMPONENT::Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib ) LIB_PART* tmp = aLibTable.LoadSymbol( m_lib_id ); if( tmp ) + { part = tmp->Flatten(); + part->SetParent(); + } } // Fall back to cache library. This is temporary until the new schematic file @@ -361,7 +377,10 @@ bool SCH_COMPONENT::Resolve( SYMBOL_LIB_TABLE& aLibTable, PART_LIB* aCacheLib ) LIB_PART* tmp = aCacheLib->FindPart( libId ); if( tmp ) - part.reset( new LIB_PART( *tmp ) ); + { + part = tmp->Flatten(); + part->SetParent(); + } } if( part )