PCB Editor: make Mirror menu items conditional

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/13230
This commit is contained in:
Mike Williams 2022-12-27 14:18:13 -05:00
parent f1fab140a1
commit 741d1e043a
3 changed files with 50 additions and 26 deletions

View File

@ -684,6 +684,21 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
auto canMirror =
[ this ]( const SELECTION& aSelection )
{
if( !this->IsType( FRAME_FOOTPRINT_EDITOR )
&& SELECTION_CONDITIONS::OnlyTypes( { PCB_PAD_T } )( aSelection ) )
{
return false;
}
return SELECTION_CONDITIONS::HasTypes( EDIT_TOOL::MirrorableItems )( aSelection );
};
mgr->SetConditions( PCB_ACTIONS::mirrorH, ENABLE( canMirror ) );
mgr->SetConditions( PCB_ACTIONS::mirrorV, ENABLE( canMirror ) );
mgr->SetConditions( PCB_ACTIONS::group, ENABLE( SELECTION_CONDITIONS::MoreThan( 1 ) ) );
mgr->SetConditions( PCB_ACTIONS::ungroup, ENABLE( SELECTION_CONDITIONS::HasType( PCB_GROUP_T ) ) );
mgr->SetConditions( PCB_ACTIONS::lock, ENABLE( PCB_SELECTION_CONDITIONS::HasUnlockedItems ) );

View File

@ -144,6 +144,18 @@ bool EDIT_TOOL::Init()
return m_isFootprintEditor;
};
auto canMirror =
[ this ]( const SELECTION& aSelection )
{
if( !m_isFootprintEditor
&& SELECTION_CONDITIONS::OnlyTypes( { PCB_PAD_T } )( aSelection ) )
{
return false;
}
return SELECTION_CONDITIONS::HasTypes( EDIT_TOOL::MirrorableItems )( aSelection );
};
auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyTypes( { PCB_FOOTPRINT_T } )
&& SELECTION_CONDITIONS::Count( 1 );
@ -218,10 +230,8 @@ bool EDIT_TOOL::Init()
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::mirrorH, SELECTION_CONDITIONS::NotEmpty
&& !singleFootprintCondition );
menu.AddItem( PCB_ACTIONS::mirrorV, SELECTION_CONDITIONS::NotEmpty
&& !singleFootprintCondition );
menu.AddItem( PCB_ACTIONS::mirrorH, canMirror );
menu.AddItem( PCB_ACTIONS::mirrorV, canMirror );
menu.AddItem( PCB_ACTIONS::swap, SELECTION_CONDITIONS::MoreThan( 1 ) );
menu.AddItem( PCB_ACTIONS::packAndMoveFootprints, SELECTION_CONDITIONS::MoreThan( 1 )
&& SELECTION_CONDITIONS::HasType( PCB_FOOTPRINT_T ) );
@ -1582,6 +1592,21 @@ static void mirrorPadY( PAD& aPad, const VECTOR2I& aMirrorPoint )
}
const std::vector<KICAD_T> EDIT_TOOL::MirrorableItems = {
PCB_FP_SHAPE_T,
PCB_SHAPE_T,
PCB_FP_TEXT_T,
PCB_TEXT_T,
PCB_FP_TEXTBOX_T,
PCB_TEXTBOX_T,
PCB_FP_ZONE_T,
PCB_ZONE_T,
PCB_PAD_T,
PCB_TRACE_T,
PCB_ARC_T,
PCB_VIA_T,
};
int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
{
if( isRouterActive() )
@ -1623,29 +1648,11 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
for( EDA_ITEM* item : selection )
{
// only modify items we can mirror
switch( item->Type() )
{
case PCB_FP_SHAPE_T:
case PCB_SHAPE_T:
case PCB_FP_TEXT_T:
case PCB_TEXT_T:
case PCB_FP_TEXTBOX_T:
case PCB_TEXTBOX_T:
case PCB_FP_ZONE_T:
case PCB_ZONE_T:
case PCB_PAD_T:
case PCB_TRACE_T:
case PCB_ARC_T:
case PCB_VIA_T:
if( !item->IsNew() && !IsFootprintEditor() )
m_commit->Modify( item );
break;
default:
if( !item->IsType( MirrorableItems ) )
continue;
}
if( !item->IsNew() && !IsFootprintEditor() )
m_commit->Modify( item );
// modify each object as necessary
switch( item->Type() )

View File

@ -111,6 +111,8 @@ public:
*/
int Mirror( const TOOL_EVENT& aEvent );
static const std::vector<KICAD_T> MirrorableItems;
/**
* Swap currently selected items' positions. Changes position of each item to the next.
*/