Test for group in footprint was snagging all footprint children.

Fixes https://gitlab.com/kicad/code/kicad/issues/8121
This commit is contained in:
Jeff Young 2021-04-06 18:26:56 +01:00
parent 9f957d3e08
commit 09b2db3139
3 changed files with 35 additions and 36 deletions

View File

@ -95,12 +95,12 @@ public:
* Search for highest level group containing item. * Search for highest level group containing item.
* *
* @param aScope restricts the search to groups within the group scope. * @param aScope restricts the search to groups within the group scope.
* @param aFootprintEditor true if we should stop promoting at the footprint level * @param isFootprintEditor true if we should stop promoting at the footprint level
* @return group containing item, if it exists, otherwise, NULL * @return group containing item, if it exists, otherwise, NULL
*/ */
static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool aFootprintEditor ); static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
static bool WithinScope( BOARD_ITEM* item, PCB_GROUP* scope ); static bool WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor );
#if defined( DEBUG ) #if defined( DEBUG )
void Show( int nestLevel, std::ostream& os ) const override void Show( int nestLevel, std::ostream& os ) const override

View File

@ -69,45 +69,46 @@ void PCB_GROUP::RemoveAll()
} }
PCB_GROUP* PCB_GROUP::TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool aFootprintEditor ) PCB_GROUP* getTopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
{ {
PCB_GROUP* candidate = aItem->GetParentGroup(); PCB_GROUP* group = nullptr;
// Don't get the footprint's group if we are in the footprint editor if( isFootprintEditor )
if( !candidate && aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T
&& !aFootprintEditor )
candidate = aItem->GetParent()->GetParentGroup();
while( candidate && candidate->GetParentGroup() && candidate->GetParentGroup() != aScope )
{ {
if( candidate->GetParent()->Type() == PCB_FOOTPRINT_T && aFootprintEditor ) group = aItem->GetParentGroup();
}
else
{
if( aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T )
group = aItem->GetParent()->GetParentGroup();
else
group = aItem->GetParentGroup();
}
while( group && group->GetParentGroup() && group->GetParentGroup() != aScope )
{
if( group->GetParent()->Type() == PCB_FOOTPRINT_T && isFootprintEditor )
break; break;
candidate = candidate->GetParentGroup(); group = group->GetParentGroup();
} }
return group;
}
PCB_GROUP* PCB_GROUP::TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
{
PCB_GROUP* candidate = getTopLevelGroup( aItem, aScope, isFootprintEditor );
return candidate == aScope ? nullptr : candidate; return candidate == aScope ? nullptr : candidate;
} }
bool PCB_GROUP::WithinScope( BOARD_ITEM* item, PCB_GROUP* scope ) bool PCB_GROUP::WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor )
{ {
for( PCB_GROUP* parent = item->GetParentGroup(); parent; parent = parent->GetParentGroup() ) PCB_GROUP* candidate = getTopLevelGroup( aItem, aScope, isFootprintEditor );
{
if( parent == scope )
return true;
}
if( item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T ) return candidate == aScope;
item = item->GetParent();
for( PCB_GROUP* parent = item->GetParentGroup(); parent; parent = parent->GetParentGroup() )
{
if( parent == scope )
return true;
}
return false;
} }

View File

@ -2509,15 +2509,12 @@ void PCB_SELECTION_TOOL::FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector
{ {
BOARD_ITEM* item = aCollector[j]; BOARD_ITEM* item = aCollector[j];
BOARD_ITEM* parent = item->GetParent(); BOARD_ITEM* parent = item->GetParent();
BOARD_ITEM* start = item;
// Ignore footprint groups in board editor
if( !m_isFootprintEditor && parent && parent->Type() == PCB_FOOTPRINT_T ) if( !m_isFootprintEditor && parent && parent->Type() == PCB_FOOTPRINT_T )
{ start = parent;
++j;
continue;
}
PCB_GROUP* aTop = PCB_GROUP::TopLevelGroup( item, m_enteredGroup, m_isFootprintEditor ); PCB_GROUP* aTop = PCB_GROUP::TopLevelGroup( start, m_enteredGroup, m_isFootprintEditor );
if( aTop ) if( aTop )
{ {
@ -2528,7 +2525,8 @@ void PCB_SELECTION_TOOL::FilterCollectorForGroups( GENERAL_COLLECTOR& aCollector
continue; continue;
} }
} }
else if( m_enteredGroup && !PCB_GROUP::WithinScope( item, m_enteredGroup ) ) else if( m_enteredGroup
&& !PCB_GROUP::WithinScope( item, m_enteredGroup, m_isFootprintEditor ) )
{ {
// If a group is entered, disallow selections of objects outside the group. // If a group is entered, disallow selections of objects outside the group.
aCollector.Remove( item ); aCollector.Remove( item );