From ec201211147c72ae116fa0cd46b97d90b52c9ad8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 14 Feb 2021 18:29:27 +0000 Subject: [PATCH] Make sure schematic symbol fields get transferred to symbol editor. Fixes https://gitlab.com/kicad/code/kicad/issues/7501 --- eeschema/dialogs/dialog_change_symbols.cpp | 8 +++-- .../dialogs/dialog_update_symbol_fields.cpp | 11 +++--- eeschema/sch_edit_frame.cpp | 2 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 36 ++++++++++++++----- eeschema/symbol_editor/symbol_edit_frame.h | 6 +--- eeschema/tools/sch_edit_tool.cpp | 4 +-- eeschema/tools/sch_editor_control.cpp | 7 ++-- eeschema/tools/sch_editor_control.h | 2 +- 8 files changed, 47 insertions(+), 29 deletions(-) diff --git a/eeschema/dialogs/dialog_change_symbols.cpp b/eeschema/dialogs/dialog_change_symbols.cpp index 1a6ec54dac..d74a279cbf 100644 --- a/eeschema/dialogs/dialog_change_symbols.cpp +++ b/eeschema/dialogs/dialog_change_symbols.cpp @@ -593,10 +593,14 @@ bool DIALOG_CHANGE_SYMBOLS::processSymbol( SCH_COMPONENT* aSymbol, const SCH_SHE if( resetEffects ) { - // Careful: the visible bit is also in Effects - bool visible = field->IsVisible(); + // Careful: the visible bit and position are also in Effects + bool visible = field->IsVisible(); + wxPoint pos = field->GetPosition(); + field->SetEffects( *libField ); + field->SetVisible( visible ); + field->SetPosition( pos ); } if( resetPositions ) diff --git a/eeschema/dialogs/dialog_update_symbol_fields.cpp b/eeschema/dialogs/dialog_update_symbol_fields.cpp index ed2120ed24..1ec212af0a 100644 --- a/eeschema/dialogs/dialog_update_symbol_fields.cpp +++ b/eeschema/dialogs/dialog_update_symbol_fields.cpp @@ -163,10 +163,14 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent ) if( resetEffects ) { - // Careful: the visible bit is also in Effects - bool visible = field.IsVisible(); + // Careful: the visible bit and position are also in Effects + bool visible = field.IsVisible(); + wxPoint pos = field.GetPosition(); + field.SetEffects( *parentField ); + field.SetVisible( visible ); + field.SetPosition( pos ); } if( resetPositions ) @@ -198,9 +202,8 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent ) LIB_FIELD* newField = &result.back(); newField->SetName( parentField->GetCanonicalName() ); - newField->SetEffects( *parentField ); newField->SetText( parentField->GetText() ); - newField->SetTextPos( parentField->GetTextPos() ); + newField->SetEffects( *parentField ); // Includes visible bit and position } } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index f634da017e..dfd6f90137 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -1631,7 +1631,7 @@ void SCH_EDIT_FRAME::UpdateSymbolFromEditor( const LIB_PART& aSymbol ) // This should work for multiple selections of the same symbol even though the editor // only works for a single symbol selection. - for( auto item : selection ) + for( EDA_ITEM* item : selection ) { SCH_COMPONENT* symbol = dynamic_cast( item ); diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d262449a4d..854c560509 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -1284,26 +1284,44 @@ SELECTION& SYMBOL_EDIT_FRAME::GetCurrentSelection() } -void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( const std::unique_ptr& aSymbol, - const wxString& aReference, int aUnit, - int aConvert ) +void SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol ) { - std::unique_ptr symbol = aSymbol->Flatten(); - wxCHECK( symbol, /* void */ ); + std::unique_ptr part = aSymbol->GetPartRef()->Flatten(); + wxCHECK( part, /* void */ ); + + std::vector fullSetOfFields; + + for( int i = 0; i < (int) aSymbol->GetFields().size(); ++i ) + { + SCH_FIELD* field = aSymbol->GetField( i ); + wxPoint pos = field->GetPosition() - aSymbol->GetPosition(); + LIB_FIELD libField( part.get(), field->GetId() ); + + if( i >= MANDATORY_FIELDS && !field->GetName( false ).IsEmpty() ) + libField.SetName( field->GetName( false ) ); + + libField.SetText( field->GetText() ); + libField.SetEffects( *field ); + libField.SetPosition( wxPoint( pos.x, -pos.y ) ); + + fullSetOfFields.emplace_back( std::move( libField ) ); + } + + part->SetFields( fullSetOfFields ); if( m_my_part ) SetCurPart( nullptr, false ); m_isSymbolFromSchematic = true; - m_reference = aReference; - m_unit = aUnit > 0 ? aUnit : 1; - m_convert = aConvert > 0 ? aConvert : 1; + m_reference = part->GetField( REFERENCE_FIELD )->GetText(); + m_unit = std::max( 1, aSymbol->GetUnit() ); + m_convert = std::max( 1, aSymbol->GetConvert() ); // The buffered screen for the part SCH_SCREEN* tmpScreen = new SCH_SCREEN(); SetScreen( tmpScreen ); - SetCurPart( symbol.release(), true ); + SetCurPart( part.release(), true ); ReCreateMenuBar(); ReCreateHToolbar(); diff --git a/eeschema/symbol_editor/symbol_edit_frame.h b/eeschema/symbol_editor/symbol_edit_frame.h index 566a502b47..a115df3924 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.h +++ b/eeschema/symbol_editor/symbol_edit_frame.h @@ -330,12 +330,8 @@ public: * Load a symbol from the schematic to edit in place. * * @param aSymbol the symbol to edit. - * @param aReference the reference of the symbol to edit. - * @param aUnit the unit of the symbol to edit. - * @param aConvert the alternate body style of the symbol to edit. */ - void LoadSymbolFromSchematic( const std::unique_ptr& aSymbol, - const wxString& aReference, int aUnit, int aConvert ); + void LoadSymbolFromSchematic( SCH_COMPONENT* aSymbol ); /** * Test if a symbol is loaded and can be edited. diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 302b054f67..1d8214c330 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1396,9 +1396,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { auto editor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, true ); - editor->LoadSymbolFromSchematic( component->GetPartRef(), - component->GetRef( &m_frame->GetCurrentSheet() ), - component->GetUnit(), component->GetConvert() ); + editor->LoadSymbolFromSchematic( component ); editor->Show( true ); editor->Raise(); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index e7bfe7cf8a..7726f48c3d 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1569,7 +1569,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) } -int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent ) +int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent ) { EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); @@ -1588,8 +1588,7 @@ int SCH_EDITOR_CONTROL::EditWithLibEdit( const TOOL_EVENT& aEvent ) if( symbolEditor ) { - symbolEditor->LoadSymbolFromSchematic( sym->GetPartRef(), sym->GetRef( ¤tSheet ), - sym->GetUnit(), sym->GetConvert() ); + symbolEditor->LoadSymbolFromSchematic( sym ); } return 0; @@ -1817,7 +1816,7 @@ void SCH_EDITOR_CONTROL::setTransitions() Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() ); - Go( &SCH_EDITOR_CONTROL::EditWithLibEdit, EE_ACTIONS::editWithLibEdit.MakeEvent() ); + Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, EE_ACTIONS::editWithLibEdit.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ShowCvpcb, EE_ACTIONS::assignFootprints.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::ImportFPAssignments, EE_ACTIONS::importFPAssignments.MakeEvent() ); Go( &SCH_EDITOR_CONTROL::Annotate, EE_ACTIONS::annotate.MakeEvent() ); diff --git a/eeschema/tools/sch_editor_control.h b/eeschema/tools/sch_editor_control.h index a54fcd81ed..ba6d5af51f 100644 --- a/eeschema/tools/sch_editor_control.h +++ b/eeschema/tools/sch_editor_control.h @@ -112,7 +112,7 @@ public: int Copy( const TOOL_EVENT& aEvent ); int Paste( const TOOL_EVENT& aEvent ); - int EditWithLibEdit( const TOOL_EVENT& aEvent ); + int EditWithSymbolEditor( const TOOL_EVENT& aEvent ); int ShowCvpcb( const TOOL_EVENT& aEvent ); int Annotate( const TOOL_EVENT& aEvent ); int EditSymbolFields( const TOOL_EVENT& aEvent );