From c9d7bdc3403bbd6ac5c7fe451780996faae9bae8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 28 Oct 2020 22:32:08 +0000 Subject: [PATCH] Hook up AutoplaceFields for sheets. Fixes https://gitlab.com/kicad/code/kicad/issues/6197 --- eeschema/ee_collectors.cpp | 7 +++++++ eeschema/ee_collectors.h | 1 + eeschema/sch_sheet.cpp | 2 -- eeschema/tools/ee_actions.cpp | 2 +- eeschema/tools/sch_edit_tool.cpp | 26 ++++++++++++++++++-------- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/eeschema/ee_collectors.cpp b/eeschema/ee_collectors.cpp index 3a4e76db05..7c60617460 100644 --- a/eeschema/ee_collectors.cpp +++ b/eeschema/ee_collectors.cpp @@ -71,6 +71,13 @@ const KICAD_T EE_COLLECTOR::SheetsOnly[] = { }; +const KICAD_T EE_COLLECTOR::ComponentsOrSheets[] = { + SCH_COMPONENT_T, + SCH_SHEET_T, + EOT +}; + + SEARCH_RESULT EE_COLLECTOR::Inspect( EDA_ITEM* aItem, void* aTestData ) { if( aItem->Type() == LIB_PIN_T ) diff --git a/eeschema/ee_collectors.h b/eeschema/ee_collectors.h index ac272fa134..d085e50f03 100644 --- a/eeschema/ee_collectors.h +++ b/eeschema/ee_collectors.h @@ -46,6 +46,7 @@ public: static const KICAD_T EditableItems[]; static const KICAD_T ComponentsOnly[]; static const KICAD_T SheetsOnly[]; + static const KICAD_T ComponentsOrSheets[]; EE_COLLECTOR( const KICAD_T* aScanTypes = EE_COLLECTOR::AllItems ) : m_Unit( 0 ), diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 6518a4db02..fdba18f365 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -497,8 +497,6 @@ int SCH_SHEET::GetPenWidth() const void SCH_SHEET::AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) { - wxASSERT_MSG( !aManual, "manual autoplacement not currently supported for sheets" ); - wxSize textSize = m_fields[ SHEETNAME ].GetTextSize(); int borderMargin = KiROUND( GetPenWidth() / 2.0 ) + 4; int margin = borderMargin + KiROUND( std::max( textSize.x, textSize.y ) * 0.5 ); diff --git a/eeschema/tools/ee_actions.cpp b/eeschema/tools/ee_actions.cpp index 5b6810a087..5ff2f27be5 100644 --- a/eeschema/tools/ee_actions.cpp +++ b/eeschema/tools/ee_actions.cpp @@ -393,7 +393,7 @@ TOOL_ACTION EE_ACTIONS::editFootprint( "eeschema.InteractiveEdit.editFootprint", TOOL_ACTION EE_ACTIONS::autoplaceFields( "eeschema.InteractiveEdit.autoplaceFields", AS_GLOBAL, 'O', LEGACY_HK_NAME( "Autoplace Fields" ), - _( "Autoplace Fields" ), _( "Runs the automatic placement algorithm on the symbol's fields" ), + _( "Autoplace Fields" ), _( "Runs the automatic placement algorithm on the symbol or sheet's fields" ), autoplace_fields_xpm ); TOOL_ACTION EE_ACTIONS::changeSymbols( "eeschema.InteractiveEdit.changeSymbols", diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 2bb40c00e3..d314321b63 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -359,7 +359,8 @@ bool SCH_EDIT_TOOL::Init() selToolMenu.AddItem( EE_ACTIONS::editReference, E_C::SingleSymbol, 200 ); selToolMenu.AddItem( EE_ACTIONS::editValue, E_C::SingleSymbol, 200 ); selToolMenu.AddItem( EE_ACTIONS::editFootprint, E_C::SingleSymbol, 200 ); - selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 ); + selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition + || singleSheetCondition, 200 ); selToolMenu.AddItem( EE_ACTIONS::toggleDeMorgan, E_C::SingleSymbol, 200 ); std::shared_ptr symUnitMenu3 = std::make_shared(); @@ -1260,20 +1261,29 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::AutoplaceFields( const TOOL_EVENT& aEvent ) { - EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOnly ); + EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::ComponentsOrSheets ); if( selection.Empty() ) return 0; - SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front(); + SCH_ITEM* item = static_cast( selection.Front() ); - if( !component->IsNew() ) - saveCopyInUndoList( component, UNDO_REDO::CHANGED ); + if( !item->IsNew() ) + saveCopyInUndoList( item, UNDO_REDO::CHANGED ); - component->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); + if( item->Type() == SCH_COMPONENT_T ) + { + SCH_COMPONENT* component = static_cast( item ); + component->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); + } + else if( item->Type() == SCH_SHEET_T ) + { + SCH_SHEET* sheet = static_cast( item ); + sheet->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true ); + } - m_frame->GetScreen()->Update( component ); - updateView( component ); + m_frame->GetScreen()->Update( item ); + updateView( item ); m_frame->OnModify(); if( selection.IsHover() )