From cc956695ae17ac2e56b01d6284c66e3eb3924014 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 11 Apr 2021 14:18:08 +0100 Subject: [PATCH] Hit test for worksheet before adding Properties to menu. Fixes https://gitlab.com/kicad/code/kicad/issues/8171 --- eeschema/tools/sch_edit_tool.cpp | 15 ++++++- pcbnew/tools/edit_tool.cpp | 77 ++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 26 deletions(-) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 92f23f5960..5ac7501e55 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -205,10 +205,21 @@ bool SCH_EDIT_TOOL::Init() }; auto propertiesCondition = - []( const SELECTION& aSel ) + [&]( const SELECTION& aSel ) { if( aSel.GetSize() == 0 ) - return true; // Show drawing-sheet properties + { + if( getView()->IsLayerVisible( LAYER_SCHEMATIC_DRAWINGSHEET ) ) + { + DS_PROXY_VIEW_ITEM* ds = m_frame->GetCanvas()->GetView()->GetDrawingSheet(); + VECTOR2D cursor = getViewControls()->GetCursorPosition( false ); + + if( ds && ds->HitTestDrawingSheetItems( getView(), (wxPoint) cursor ) ) + return true; + } + + return false; + } SCH_ITEM* firstItem = dynamic_cast( aSel.Front() ); const EE_SELECTION* eeSelection = dynamic_cast( &aSel ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 738edfb37d..43df206ba4 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -103,6 +103,35 @@ bool EDIT_TOOL::Init() // Find the selection tool, so they can cooperate m_selectionTool = m_toolMgr->GetTool(); + auto propertiesCondition = + [&]( const SELECTION& aSel ) + { + if( aSel.GetSize() == 0 ) + { + if( getView()->IsLayerVisible( LAYER_SCHEMATIC_DRAWINGSHEET ) ) + { + DS_PROXY_VIEW_ITEM* ds = frame()->GetCanvas()->GetDrawingSheet(); + VECTOR2D cursor = getViewControls()->GetCursorPosition( false ); + + if( ds && ds->HitTestDrawingSheetItems( getView(), (wxPoint) cursor ) ) + return true; + } + + return false; + } + + if( aSel.GetSize() == 1 ) + return true; + + for( EDA_ITEM* item : aSel ) + { + if( !dynamic_cast( item ) ) + return false; + } + + return true; + }; + auto inFootprintEditor = [ this ]( const SELECTION& aSelection ) { @@ -134,43 +163,43 @@ bool EDIT_TOOL::Init() // Add context menu entries that are displayed when selection tool is active CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu(); - menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition ); - menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); - menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) ); - menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::Count( 1 ) - && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) - && !SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) ); - menu.AddItem( PCB_ACTIONS::filletTracks, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); - menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty ); - menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); - menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); - menu.AddItem( PCB_ACTIONS::mirror, inFootprintEditor && SELECTION_CONDITIONS::NotEmpty ); + menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty + && notMovingCondition ); + menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 ) + && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::Count( 1 ) + && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) ); + menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::Count( 1 ) + && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::DraggableItems ) + && !SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T ) ); + menu.AddItem( PCB_ACTIONS::filletTracks, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty ); + menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); + menu.AddItem( PCB_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty ); + menu.AddItem( PCB_ACTIONS::mirror, inFootprintEditor && SELECTION_CONDITIONS::NotEmpty ); - menu.AddItem( PCB_ACTIONS::properties, SELECTION_CONDITIONS::Count( 1 ) - || SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); + menu.AddItem( PCB_ACTIONS::properties, propertiesCondition ); // Footprint actions menu.AddSeparator(); - menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleFootprintCondition ); - menu.AddItem( PCB_ACTIONS::updateFootprint, singleFootprintCondition ); - menu.AddItem( PCB_ACTIONS::changeFootprint, singleFootprintCondition ); + menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleFootprintCondition ); + menu.AddItem( PCB_ACTIONS::updateFootprint, singleFootprintCondition ); + menu.AddItem( PCB_ACTIONS::changeFootprint, singleFootprintCondition ); // Add the submenu for create array and special move auto specialToolsSubMenu = std::make_shared( this ); menu.AddSeparator(); m_selectionTool->GetToolMenu().AddSubMenu( specialToolsSubMenu ); - menu.AddMenu( specialToolsSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); + menu.AddMenu( specialToolsSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 ); menu.AddSeparator( 150 ); - menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 150 ); - menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 150 ); + menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 150 ); + menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 150 ); // Selection tool handles the context menu for some other tools, such as the Picker. // Don't add things like Paste when another tool is active. - menu.AddItem( ACTIONS::paste, noActiveToolCondition, 150 ); - menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty, 150 ); - menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 150 ); + menu.AddItem( ACTIONS::paste, noActiveToolCondition, 150 ); + menu.AddItem( ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty, 150 ); + menu.AddItem( ACTIONS::doDelete, SELECTION_CONDITIONS::NotEmpty, 150 ); menu.AddSeparator( 150 ); menu.AddItem( ACTIONS::selectAll, noItemsCondition, 150 );