Move group/ungroup to COMMIT infrastructure.

This commit is contained in:
Jeff Young 2023-12-16 14:14:47 +00:00
parent 27f5ecf716
commit ea3c87f243
9 changed files with 86 additions and 80 deletions

View File

@ -80,6 +80,11 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCREEN* aS
break;
}
case CHT_GROUP:
case CHT_UNGROUP:
makeEntry( aItem, aChangeType, nullptr, aScreen );
return *this;
default:
wxFAIL;
}
@ -182,18 +187,12 @@ CHANGE_TYPE COMMIT::convert( UNDO_REDO aType ) const
{
switch( aType )
{
case UNDO_REDO::NEWITEM:
return CHT_ADD;
case UNDO_REDO::DELETED:
return CHT_REMOVE;
default:
wxASSERT( false );
KI_FALLTHROUGH;
case UNDO_REDO::CHANGED:
return CHT_MODIFY;
case UNDO_REDO::NEWITEM: return CHT_ADD;
case UNDO_REDO::DELETED: return CHT_REMOVE;
case UNDO_REDO::GROUP: return CHT_GROUP;
case UNDO_REDO::UNGROUP: return CHT_UNGROUP;
case UNDO_REDO::CHANGED: return CHT_MODIFY;
default: wxASSERT( false ); return CHT_MODIFY;
}
}
@ -202,18 +201,12 @@ UNDO_REDO COMMIT::convert( CHANGE_TYPE aType ) const
{
switch( aType )
{
case CHT_ADD:
return UNDO_REDO::NEWITEM;
case CHT_REMOVE:
return UNDO_REDO::DELETED;
default:
wxASSERT( false );
KI_FALLTHROUGH;
case CHT_MODIFY:
return UNDO_REDO::CHANGED;
case CHT_ADD: return UNDO_REDO::NEWITEM;
case CHT_REMOVE: return UNDO_REDO::DELETED;
case CHT_GROUP: return UNDO_REDO::GROUP;
case CHT_UNGROUP: return UNDO_REDO::UNGROUP;
case CHT_MODIFY: return UNDO_REDO::CHANGED;
default: wxASSERT( false ); return UNDO_REDO::CHANGED;
}
}

View File

@ -42,9 +42,11 @@ enum CHANGE_TYPE {
CHT_ADD = 1,
CHT_REMOVE = 2,
CHT_MODIFY = 4,
CHT_TYPE = CHT_ADD | CHT_REMOVE | CHT_MODIFY,
CHT_GROUP = 8,
CHT_UNGROUP = 16,
CHT_TYPE = CHT_ADD | CHT_REMOVE | CHT_MODIFY | CHT_GROUP | CHT_UNGROUP,
CHT_DONE = 8, ///< Flag to indicate the change is already applied
CHT_DONE = 32, ///< Flag to indicate the change is already applied
CHT_FLAGS = CHT_DONE
};

View File

@ -67,7 +67,7 @@ enum class UNDO_REDO {
DRILLORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
GRIDORIGIN, // origin changed (like CHANGED, contains the origin and a copy)
PAGESETTINGS, // page settings or title block changes
REGROUP, // new group of items created (do not use GROUP to avoid collision
GROUP, // new group of items created (do not use GROUP to avoid collision
// with an header on msys2)
UNGROUP // existing group destroyed (items not destroyed)
};

View File

@ -159,6 +159,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
bool autofillZones = false;
std::vector<BOARD_ITEM*> staleTeardropPadsAndVias;
std::set<PCB_TRACK*> staleTeardropTracks;
PCB_GROUP* addedGroup = nullptr;
if( Empty() )
return;
@ -269,6 +270,9 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
}
}
if( boardItem->Type() == PCB_GROUP_T )
addedGroup = static_cast<PCB_GROUP*>( boardItem );
if( autofillZones && boardItem->Type() != PCB_MARKER_T )
dirtyIntersectingZones( boardItem, changeType );
@ -377,6 +381,23 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
break;
}
case CHT_UNGROUP:
boardItem->SetParentGroup( nullptr );
if( !( aCommitFlags & SKIP_UNDO ) )
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::UNGROUP ) );
break;
case CHT_GROUP:
if( addedGroup )
addedGroup->AddItem( boardItem );
if( !( aCommitFlags & SKIP_UNDO ) )
undoList.PushItem( ITEM_PICKER( nullptr, boardItem, UNDO_REDO::GROUP ) );
break;
case CHT_MODIFY:
{
BOARD_ITEM* boardItemCopy = dynamic_cast<BOARD_ITEM*>( ent.m_copy );

View File

@ -1343,10 +1343,11 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
&& bounds.PointInside( track->GetEnd(), epsilon ) )
{
AddItem( item );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::GROUP ) );
}
}
aCommit->Stage( groupUndoList );
aCommit->Add( item );
}
@ -1357,8 +1358,6 @@ void PCB_TUNING_PATTERN::EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard,
aCommitFlags |= APPEND_UNDO;
}
aFrame->AppendCopyToUndoList( groupUndoList, UNDO_REDO::REGROUP );
}

View File

@ -1550,7 +1550,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
selectedItems.push_back( item );
}
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::GROUP ) );
layer = item->GetLayer();
@ -1562,10 +1562,10 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
for( BOARD_ITEM* item : newItems )
commit.Add( item );
commit.Push( _( "Import Graphics" ) );
if( groupUndoList.GetCount() > 0 )
m_frame->AppendCopyToUndoList( groupUndoList, UNDO_REDO::REGROUP );
commit.Stage( groupUndoList );
commit.Push( _( "Import Graphics" ) );
return 0;
}
@ -1651,10 +1651,10 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
for( BOARD_ITEM* item : newItems )
commit.Add( item );
commit.Push( _( "Import Graphics" ) );
if( groupUndoList.GetCount() > 0 )
m_frame->AppendCopyToUndoList( groupUndoList, UNDO_REDO::REGROUP );
commit.Stage( groupUndoList );
commit.Push( _( "Import Graphics" ) );
break; // This is a one-shot command, not a tool
}

View File

@ -249,40 +249,37 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent )
if( selection.Empty() )
return 0;
BOARD* board = getModel<BOARD>();
PCB_GROUP* group = nullptr;
bool lockGroup = false;
BOARD* board = getModel<BOARD>();
BOARD_COMMIT commit( m_toolMgr );
PCB_GROUP* group = nullptr;
if( m_isFootprintEditor )
{
group = new PCB_GROUP( board->GetFirstFootprint() );
board->GetFirstFootprint()->Add( group );
}
else
{
group = new PCB_GROUP( board );
board->Add( group );
}
PICKED_ITEMS_LIST undoList;
undoList.PushItem( ITEM_PICKER( nullptr, group, UNDO_REDO::NEWITEM ) );
for( EDA_ITEM* eda_item : selection )
{
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( eda_item ) )
{
if( item->IsLocked() )
lockGroup = true;
group->AddItem( item );
undoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
group->SetLocked( true );
}
}
m_frame->SaveCopyInUndoList( undoList, UNDO_REDO::REGROUP );
commit.Add( group );
if( lockGroup )
group->SetLocked( true );
PICKED_ITEMS_LIST groupList;
for( EDA_ITEM* eda_item : selection )
{
if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( eda_item ) )
groupList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::GROUP ) );
}
commit.Stage( groupList );
commit.Push( _( "Group Items" ) );
selTool->ClearSelection();
selTool->select( group );
@ -296,9 +293,9 @@ int GROUP_TOOL::Group( const TOOL_EVENT& aEvent )
int GROUP_TOOL::Ungroup( const TOOL_EVENT& aEvent )
{
const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
BOARD* board = getModel<BOARD>();
std::vector<BOARD_ITEM*> members;
const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
BOARD_COMMIT commit( m_toolMgr );
EDA_ITEMS toSelect;
if( selection.Empty() )
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor );
@ -312,31 +309,25 @@ int GROUP_TOOL::Ungroup( const TOOL_EVENT& aEvent )
if( group )
{
PICKED_ITEMS_LIST undoList;
PICKED_ITEMS_LIST ungroupList;
for( BOARD_ITEM* member : group->GetItems() )
{
undoList.PushItem( ITEM_PICKER( nullptr, member, UNDO_REDO::UNGROUP ) );
members.push_back( member );
ungroupList.PushItem( ITEM_PICKER( nullptr, member, UNDO_REDO::UNGROUP ) );
toSelect.push_back( member );
}
group->RemoveAll();
commit.Stage( ungroupList );
if( m_isFootprintEditor )
board->GetFirstFootprint()->Remove( group );
else
board->Remove( group );
canvas()->GetView()->Remove( group );
undoList.PushItem( ITEM_PICKER( nullptr, group, UNDO_REDO::DELETED ) );
m_frame->SaveCopyInUndoList( undoList, UNDO_REDO::UNGROUP );
group->GetItems().clear();
group->SetSelected();
commit.Remove( group );
}
}
EDA_ITEMS mem( members.begin(), members.end() );
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &mem );
commit.Push( _( "Ungroup Items" ) );
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &toSelect );
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
m_frame->OnModify();

View File

@ -1194,14 +1194,14 @@ TOOL_ACTION PCB_ACTIONS::unlock( TOOL_ACTION_ARGS()
TOOL_ACTION PCB_ACTIONS::group( TOOL_ACTION_ARGS()
.Name( "pcbnew.EditorControl.group" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Group" ) )
.FriendlyName( _( "Group Items" ) )
.Tooltip( _( "Group the selected items so that they are treated as a single item" ) )
.Icon( BITMAPS::group ) );
TOOL_ACTION PCB_ACTIONS::ungroup( TOOL_ACTION_ARGS()
.Name( "pcbnew.EditorControl.ungroup" )
.Scope( AS_GLOBAL )
.FriendlyName( _( "Ungroup" ) )
.FriendlyName( _( "Ungroup Items" ) )
.Tooltip( _( "Ungroup any selected groups" ) )
.Icon( BITMAPS::group_ungroup ) );

View File

@ -141,7 +141,7 @@ void PCB_BASE_EDIT_FRAME::saveCopyInUndoList( PICKED_ITEMS_LIST* commandToUndo,
case UNDO_REDO::NEWITEM:
case UNDO_REDO::DELETED:
case UNDO_REDO::PAGESETTINGS:
case UNDO_REDO::REGROUP:
case UNDO_REDO::GROUP:
case UNDO_REDO::UNGROUP:
break;
@ -295,8 +295,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
UNDO_REDO status = aList->GetPickedItemStatus( ii );
if( status != UNDO_REDO::DELETED
&& status != UNDO_REDO::GROUP
&& status != UNDO_REDO::UNGROUP
&& status != UNDO_REDO::REGROUP
&& status != UNDO_REDO::DRILLORIGIN // origin markers never on board
&& status != UNDO_REDO::GRIDORIGIN // origin markers never on board
&& status != UNDO_REDO::PAGESETTINGS ) // nor are page settings proxy items
@ -419,7 +419,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
break;
case UNDO_REDO::REGROUP:
case UNDO_REDO::GROUP:
aList->SetPickedItemStatus( UNDO_REDO::UNGROUP, ii );
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( eda_item ) )
@ -428,7 +428,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
break;
case UNDO_REDO::UNGROUP:
aList->SetPickedItemStatus( UNDO_REDO::REGROUP, ii );
aList->SetPickedItemStatus( UNDO_REDO::GROUP, ii );
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( eda_item ) )
{