From 2ec1c215cda7c9cd002252630480d2a597fd7edc Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 21 Sep 2021 16:43:53 +0100 Subject: [PATCH] Drop selection after hiding items. Fixes https://gitlab.com/kicad/code/kicad/issues/8605 --- eeschema/tools/sch_edit_tool.cpp | 43 ++++++++++++++++++++++---------- pcbnew/tools/edit_tool.cpp | 15 +++++++++-- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 3fcd3c6bad..7d0759b571 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1149,11 +1149,12 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) if( selection.Size() != 1 ) return 0; - SCH_ITEM* item = (SCH_ITEM*) selection.Front(); + bool clearSelection = selection.IsHover(); + EDA_ITEM* item = selection.Front(); if( item->Type() == SCH_SYMBOL_T ) { - SCH_SYMBOL* symbol = (SCH_SYMBOL*) item; + SCH_SYMBOL* symbol = static_cast( item ); if( aEvent.IsAction( &EE_ACTIONS::editReference ) ) editFieldText( symbol->GetField( REFERENCE_FIELD ) ); @@ -1164,10 +1165,15 @@ int SCH_EDIT_TOOL::EditField( const TOOL_EVENT& aEvent ) } else if( item->Type() == SCH_FIELD_T ) { - editFieldText( (SCH_FIELD*) item ); + SCH_FIELD* field = static_cast( item ); + + editFieldText( field ); + + if( !field->IsVisible() ) + clearSelection = true; } - if( selection.IsHover() ) + if( clearSelection ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); return 0; @@ -1264,6 +1270,7 @@ int SCH_EDIT_TOOL::ConvertDeMorgan( const TOOL_EVENT& aEvent ) int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::EditableItems ); + bool clearSelection = selection.IsHover(); if( selection.Empty() ) { @@ -1279,7 +1286,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) return 0; } - SCH_ITEM* item = (SCH_ITEM*) selection.Front(); + EDA_ITEM* item = selection.Front(); switch( item->Type() ) { @@ -1307,7 +1314,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { case SCH_SYMBOL_T: { - SCH_SYMBOL* symbol = (SCH_SYMBOL*) item; + SCH_SYMBOL* symbol = static_cast( item ); DIALOG_SYMBOL_PROPERTIES symbolPropsDialog( m_frame, symbol ); // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal @@ -1397,7 +1404,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) case SCH_SHEET_PIN_T: { - SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) item; + SCH_SHEET_PIN* pin = static_cast( item ); DIALOG_SHEET_PIN_PROPERTIES dlg( m_frame, pin ); // QuasiModal required for help dialog @@ -1414,7 +1421,8 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) case SCH_GLOBAL_LABEL_T: case SCH_HIER_LABEL_T: { - DIALOG_TEXT_AND_LABEL_PROPERTIES dlg( m_frame, (SCH_TEXT*) item ); + SCH_TEXT* text = static_cast( item ); + DIALOG_TEXT_AND_LABEL_PROPERTIES dlg( m_frame, text ); // Must be quasi modal for syntax help if( dlg.ShowQuasiModal() == wxID_OK ) @@ -1426,12 +1434,19 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) break; case SCH_FIELD_T: - editFieldText( (SCH_FIELD*) item ); + { + SCH_FIELD* field = static_cast( item ); + + editFieldText( field ); + + if( !field->IsVisible() ) + clearSelection = true; + } break; case SCH_BITMAP_T: { - SCH_BITMAP* bitmap = (SCH_BITMAP*) item; + SCH_BITMAP* bitmap = static_cast( item ); DIALOG_IMAGE_EDITOR dlg( m_frame, bitmap->GetImage() ); if( dlg.ShowModal() == wxID_OK ) @@ -1455,7 +1470,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { std::deque strokeItems; - for( auto selItem : selection.Items() ) + for( EDA_ITEM* selItem : selection.Items() ) { SCH_ITEM* schItem = dynamic_cast( selItem ); @@ -1479,7 +1494,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { std::deque junctions; - for( auto selItem : selection.Items() ) + for( EDA_ITEM* selItem : selection.Items() ) { SCH_JUNCTION* junction = dynamic_cast( selItem ); @@ -1508,7 +1523,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) updateItem( item, true ); - if( selection.IsHover() ) + if( clearSelection ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); return 0; @@ -1603,7 +1618,9 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) } } else + { m_frame->TestDanglingEnds(); + } m_frame->OnModify(); } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index b2e68de91d..069aefec29 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1446,9 +1446,20 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) if( selection.IsHover() ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); + } + else + { + // Check for items becoming invisible and drop them from the selection. - // Notify other tools of the changes -- This updates the visual ratsnest - m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified ); + LSET visible = editFrame->GetBoard()->GetVisibleLayers(); + + for( EDA_ITEM* eda_item : selection ) + { + BOARD_ITEM* item = static_cast( eda_item ); + + if( !( item->GetLayerSet() & visible ).any() ) + m_selectionTool->RemoveItemFromSel( item ); + } } return 0;