Store group id rather than group
We only need the group storage id for lookup. Storing the KIID instead of a copy of the group avoids unneeded overhead Fixes https://gitlab.com/kicad/code/kicad/-/issues/17175
This commit is contained in:
parent
38df918993
commit
7d1adff071
|
@ -213,6 +213,27 @@ EDA_ITEM_FLAGS PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx ) const
|
|||
}
|
||||
|
||||
|
||||
KIID PICKED_ITEMS_LIST::GetPickedItemGroupId( unsigned aIdx ) const
|
||||
{
|
||||
if( aIdx < m_ItemsList.size() )
|
||||
return m_ItemsList[aIdx].GetGroupId();
|
||||
|
||||
return KIID();
|
||||
}
|
||||
|
||||
|
||||
bool PICKED_ITEMS_LIST::SetPickedItemGroupId( KIID aGroupId, unsigned aIdx )
|
||||
{
|
||||
if( aIdx < m_ItemsList.size() )
|
||||
{
|
||||
m_ItemsList[aIdx].SetGroupId( aGroupId );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx )
|
||||
{
|
||||
if( aIdx < m_ItemsList.size() )
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <core/typeinfo.h>
|
||||
#include <eda_item_flags.h>
|
||||
#include <functional>
|
||||
#include <kiid.h>
|
||||
#include <vector>
|
||||
#include <wx/string.h>
|
||||
|
||||
|
@ -99,6 +100,10 @@ public:
|
|||
|
||||
EDA_ITEM* GetLink() const { return m_link; }
|
||||
|
||||
KIID GetGroupId() const { return m_groupId; }
|
||||
|
||||
void SetGroupId( KIID aId ) { m_groupId = aId; }
|
||||
|
||||
BASE_SCREEN* GetScreen() const { return m_screen; }
|
||||
|
||||
private:
|
||||
|
@ -116,6 +121,7 @@ private:
|
|||
* duplicate) m_Item points the duplicate (i.e the old
|
||||
* copy of an active item) and m_Link points the active
|
||||
* item in schematic */
|
||||
KIID m_groupId; /* Id of the group of items in case this is a group/ungroup command */
|
||||
|
||||
BASE_SCREEN* m_screen; /* For new and deleted items the screen the item should
|
||||
* be added to/removed from. */
|
||||
|
@ -225,6 +231,12 @@ public:
|
|||
*/
|
||||
UNDO_REDO GetPickedItemStatus( unsigned int aIdx ) const;
|
||||
|
||||
/**
|
||||
* @return The group id of the picked item, or null KIID if does not exist.
|
||||
* @param aIdx Index of the picked item in the picked list.
|
||||
*/
|
||||
KIID GetPickedItemGroupId( unsigned int aIdx ) const;
|
||||
|
||||
/**
|
||||
* Return the value of the picker flag.
|
||||
*
|
||||
|
@ -257,6 +269,15 @@ public:
|
|||
*/
|
||||
bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
|
||||
|
||||
/**
|
||||
* Set the group id associated to a given picked item.
|
||||
*
|
||||
* @param aId is the group id to associate to the picked item.
|
||||
* @param aIdx is index of the picker in the picked list.
|
||||
* @return true if the picker exists, or false if does not exist.
|
||||
*/
|
||||
bool SetPickedItemGroupId( KIID aId, unsigned aIdx );
|
||||
|
||||
/**
|
||||
* Set the type of undo/redo operation for a given picked item.
|
||||
*
|
||||
|
|
|
@ -411,7 +411,7 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
|
|||
if( !( aCommitFlags & SKIP_UNDO ) )
|
||||
{
|
||||
ITEM_PICKER itemWrapper( nullptr, boardItem, UNDO_REDO::UNGROUP );
|
||||
itemWrapper.SetLink( MakeImage( group ) );
|
||||
itemWrapper.SetGroupId( group->m_Uuid );
|
||||
undoList.PushItem( itemWrapper );
|
||||
}
|
||||
|
||||
|
|
|
@ -2235,7 +2235,7 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
|
|||
break;
|
||||
|
||||
default:
|
||||
wxASSERT_MSG( parentFP == nullptr, wxT( "Try to delete an item living in a footrprint" ) );
|
||||
wxASSERT_MSG( parentFP == nullptr, wxT( "Try to delete an item living in a footprint" ) );
|
||||
commit.Remove( board_item );
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -418,8 +418,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
|
|||
{
|
||||
if( PCB_GROUP* group = boardItem->GetParentGroup() )
|
||||
{
|
||||
if( !aList->GetPickedItemLink( ii ) )
|
||||
aList->SetPickedItemLink( BOARD_COMMIT::MakeImage( group ), ii );
|
||||
aList->SetPickedItemGroupId( group->m_Uuid, ii );
|
||||
|
||||
group->RemoveItem( boardItem );
|
||||
}
|
||||
|
@ -432,12 +431,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
|
|||
|
||||
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( eda_item ) )
|
||||
{
|
||||
PCB_GROUP* group = nullptr;
|
||||
|
||||
// The link is just a clone of the original parent group; we need to look up
|
||||
// the UUID in the document to find the real parent.
|
||||
if( EDA_ITEM* link = aList->GetPickedItemLink( ii ) )
|
||||
group = dynamic_cast<PCB_GROUP*>( GetBoard()->GetItem( link->m_Uuid ) );
|
||||
PCB_GROUP* group = dynamic_cast<PCB_GROUP*>(
|
||||
GetBoard()->GetItem( aList->GetPickedItemGroupId( ii ) ) );
|
||||
|
||||
if( group )
|
||||
group->AddItem( boardItem );
|
||||
|
|
Loading…
Reference in New Issue