From 05ee635420aa007ed4feab45f6bbc28e61e7612e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 10 May 2024 21:44:00 +0100 Subject: [PATCH] Implement mirror for groups. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17644 --- pcbnew/tools/edit_tool.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 34753af2e5..578423138c 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -24,6 +24,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -34,12 +35,9 @@ #include #include #include -#include #include #include -#include #include -#include #include #include #include @@ -58,11 +56,9 @@ #include #include #include -#include #include #include #include -#include #include using namespace std::placeholders; #include "kicad_clipboard.h" @@ -73,8 +69,6 @@ using namespace std::placeholders; #include #include #include -#include -#include #include const unsigned int EDIT_TOOL::COORDS_PADDING = pcbIUScale.mmToIU( 20 ); @@ -250,6 +244,9 @@ bool EDIT_TOOL::Init() return false; } + if( SELECTION_CONDITIONS::HasTypes( { PCB_GROUP_T } )( aSelection ) ) + return true; + return SELECTION_CONDITIONS::HasTypes( EDIT_TOOL::MirrorableItems )( aSelection ); }; @@ -2069,7 +2066,25 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) mirrorAroundXaxis = true; } + std::vector items; + for( EDA_ITEM* item : selection ) + { + if( item->Type() == PCB_GROUP_T ) + { + static_cast( item )->RunOnDescendants( + [&]( BOARD_ITEM* descendant ) + { + items.push_back( descendant ); + } ); + } + else + { + items.push_back( item ); + } + } + + for( EDA_ITEM* item : items ) { if( !item->IsType( MirrorableItems ) ) continue; @@ -2117,9 +2132,7 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) default: // it's likely the commit object is wrong if you get here - // Unsure if PCB_GROUP_T needs special attention here. - assert( false ); - break; + UNIMPLEMENTED_FOR( item->GetClass() ); } }