Hook up AutoplaceFields for sheets.

Fixes https://gitlab.com/kicad/code/kicad/issues/6197
This commit is contained in:
Jeff Young 2020-10-28 22:32:08 +00:00
parent bc23fd0530
commit c9d7bdc340
5 changed files with 27 additions and 11 deletions

View File

@ -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 )

View File

@ -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 ),

View File

@ -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 );

View File

@ -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",

View File

@ -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<SYMBOL_UNIT_MENU> symUnitMenu3 = std::make_shared<SYMBOL_UNIT_MENU>();
@ -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<SCH_ITEM*>( selection.Front() );
if( !component->IsNew() )
saveCopyInUndoList( component, UNDO_REDO::CHANGED );
if( !item->IsNew() )
saveCopyInUndoList( item, UNDO_REDO::CHANGED );
if( item->Type() == SCH_COMPONENT_T )
{
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
component->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true );
}
else if( item->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( 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() )