Show dragging tools in context selection menu for components

Show the dragging tools in the context selection menu when a single
component is selected. Prevent the dragging tools from appearing when
more than one object is selected, as they will not activate anyway.

Fixes https://gitlab.com/kicad/code/kicad/issues/7258
This commit is contained in:
Mikołaj Wielgus 2021-01-27 19:55:42 +00:00 committed by Seth Hillbrand
parent 7d6a749285
commit 3e42ba18a9
5 changed files with 31 additions and 10 deletions

View File

@ -145,6 +145,13 @@ const KICAD_T GENERAL_COLLECTOR::Dimensions[] = {
}; };
const KICAD_T GENERAL_COLLECTOR::DraggableItems[] = {
PCB_TRACE_T,
PCB_VIA_T,
PCB_FOOTPRINT_T,
PCB_ARC_T,
EOT
};
SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData ) SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, void* testData )

View File

@ -308,6 +308,11 @@ public:
*/ */
static const KICAD_T Dimensions[]; static const KICAD_T Dimensions[];
/**
* A scan list for items that can be dragged
*/
static const KICAD_T DraggableItems[];
/** /**
* Constructor GENERALCOLLECTOR * Constructor GENERALCOLLECTOR
*/ */

View File

@ -1459,7 +1459,7 @@ void ROUTER_TOOL::NeighboringSegmentFilter( const VECTOR2I& aPt, GENERAL_COLLECT
} }
bool ROUTER_TOOL::CanInlineDrag() bool ROUTER_TOOL::CanInlineDrag( int aDragMode )
{ {
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, NeighboringSegmentFilter ); m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, NeighboringSegmentFilter );
const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection(); const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
@ -1468,10 +1468,16 @@ bool ROUTER_TOOL::CanInlineDrag()
{ {
const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( selection.Front() ); const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( selection.Front() );
if( item->Type() == PCB_TRACE_T // Note: EDIT_TOOL::Drag temporarily handles items of type PCB_ARC_T on its own using
|| item->Type() == PCB_VIA_T // DragArcTrack(), so PCB_ARC_T should never occur here.
|| item->Type() == PCB_FOOTPRINT_T ) if( item->IsType( GENERAL_COLLECTOR::DraggableItems ) )
{ {
static const KICAD_T footprints[] = { PCB_FOOTPRINT_T, EOT };
// Footprints cannot be dragged freely.
if( item->IsType( footprints ) )
return !( aDragMode & PNS::DM_FREE_ANGLE );
else
return true; return true;
} }
} }

View File

@ -37,7 +37,7 @@ public:
int MainLoop( const TOOL_EVENT& aEvent ); int MainLoop( const TOOL_EVENT& aEvent );
int InlineBreakTrack( const TOOL_EVENT& aEvent ); int InlineBreakTrack( const TOOL_EVENT& aEvent );
bool CanInlineDrag(); bool CanInlineDrag( int aDragMode );
int InlineDrag( const TOOL_EVENT& aEvent ); int InlineDrag( const TOOL_EVENT& aEvent );
int SelectCopperLayerPair( const TOOL_EVENT& aEvent ); int SelectCopperLayerPair( const TOOL_EVENT& aEvent );

View File

@ -136,8 +136,11 @@ bool EDIT_TOOL::Init()
menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition ); menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 ) menu.AddItem( PCB_ACTIONS::inlineBreakTrack, SELECTION_CONDITIONS::Count( 1 )
&& SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); && SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); menu.AddItem( PCB_ACTIONS::drag45Degree, SELECTION_CONDITIONS::Count( 1 )
menu.AddItem( PCB_ACTIONS::dragFreeAngle, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) ); && 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::filletTracks, SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::Tracks ) );
menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::rotateCcw, SELECTION_CONDITIONS::NotEmpty );
menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty ); menu.AddItem( PCB_ACTIONS::rotateCw, SELECTION_CONDITIONS::NotEmpty );
@ -211,7 +214,7 @@ bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
if( theRouter->IsToolActive() ) if( theRouter->IsToolActive() )
return false; return false;
if( theRouter->CanInlineDrag() ) if( theRouter->CanInlineDrag( aDragMode ) )
{ {
m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, true, aDragMode ); m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, true, aDragMode );
return true; return true;