diff --git a/include/pcb_group.h b/include/pcb_group.h index 80c7b50ba8..d658f31985 100644 --- a/include/pcb_group.h +++ b/include/pcb_group.h @@ -130,6 +130,8 @@ public: */ void SetLayerRecursive( PCB_LAYER_ID aLayer, int aDepth ); + void SetLocked( bool aLocked ) override; + ///< @copydoc EDA_ITEM::Clone EDA_ITEM* Clone() const override; diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 3a054b41a5..2bdb5725bc 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -142,6 +142,18 @@ void PCB_GROUP::SetLayerRecursive( PCB_LAYER_ID aLayer, int aDepth ) } +void PCB_GROUP::SetLocked( bool aLockState ) +{ + BOARD_ITEM::SetLocked( aLockState ); + + RunOnChildren( + [&]( BOARD_ITEM* child ) + { + child->SetLocked( aLockState ); + } ); +} + + EDA_ITEM* PCB_GROUP::Clone() const { // Use copy constructor to get the same uuid and other fields diff --git a/pcbnew/tools/group_tool.cpp b/pcbnew/tools/group_tool.cpp index 8aee0ba404..a3e086c18d 100644 --- a/pcbnew/tools/group_tool.cpp +++ b/pcbnew/tools/group_tool.cpp @@ -254,6 +254,7 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent ) BOARD* board = getModel(); PCB_GROUP* group = nullptr; + bool lockGroup = false; if( m_isFootprintEditor ) { @@ -264,8 +265,15 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent ) group = new PCB_GROUP( parentFootprint ); parentFootprint->Add( group ); - for( EDA_ITEM* item : selection ) - group->AddItem( static_cast( item ) ); + for( EDA_ITEM* eda_item : selection ) + { + BOARD_ITEM* item = static_cast( eda_item ); + + if( item->IsLocked() ) + lockGroup = true; + + group->AddItem( item ); + } } else { @@ -276,15 +284,24 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent ) undoList.PushItem( ITEM_PICKER( nullptr, group, UNDO_REDO::NEWITEM ) ); - for( EDA_ITEM* item : selection ) + for( EDA_ITEM* eda_item : selection ) { + BOARD_ITEM* item = static_cast( eda_item ); + + if( item->IsLocked() ) + lockGroup = true; + group->AddItem( static_cast( item ) ); + undoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) ); } m_frame->SaveCopyInUndoList( undoList, UNDO_REDO::REGROUP ); } + if( lockGroup ) + group->SetLocked( true ); + selTool->ClearSelection(); selTool->select( group ); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 8eed99bd31..30181f724f 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -687,11 +687,11 @@ bool PCB_SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, if( aClientFilter ) aClientFilter( aWhere, collector, this ); + FilterCollectorForHierarchy( collector, false ); + // Apply the stateful filter FilterCollectedItems( collector, false ); - FilterCollectorForHierarchy( collector, false ); - // Apply some ugly heuristics to avoid disambiguation menus whenever possible if( collector.GetCount() > 1 && !m_skip_heuristics ) GuessSelectionCandidates( collector, aWhere );