pcb: merge RunOnChildren/Descendants into one function with a mode

This commit is contained in:
Mike Williams 2025-03-27 10:43:44 -04:00
parent 7cf699bc9d
commit a90b8ec57a
34 changed files with 195 additions and 194 deletions

View File

@ -85,12 +85,13 @@ void FOOTPRINT_DIFF_WIDGET::DisplayDiff( FOOTPRINT* aBoardFootprint,
m_boardItemCopy->ClearSelected(); m_boardItemCopy->ClearSelected();
m_boardItemCopy->ClearBrightened(); m_boardItemCopy->ClearBrightened();
m_boardItemCopy->RunOnDescendants( m_boardItemCopy->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
item->ClearSelected(); item->ClearSelected();
item->ClearBrightened(); item->ClearBrightened();
} ); },
RECURSE_MODE::RECURSE );
m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() ); m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() );
@ -138,11 +139,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
m_boardItemCopy->SetForcedTransparency( val ); m_boardItemCopy->SetForcedTransparency( val );
m_boardItemCopy->RunOnDescendants( m_boardItemCopy->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
item->SetForcedTransparency( val ); item->SetForcedTransparency( val );
} ); },
RECURSE_MODE::RECURSE );
} }
if( m_libraryItem ) if( m_libraryItem )
@ -156,11 +158,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
m_libraryItem->SetForcedTransparency( val ); m_libraryItem->SetForcedTransparency( val );
m_libraryItem->RunOnDescendants( m_libraryItem->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
item->SetForcedTransparency( val ); item->SetForcedTransparency( val );
} ); },
RECURSE_MODE::RECURSE );
} }
RefreshAll(); RefreshAll();

View File

@ -69,6 +69,11 @@ enum ZONE_LAYER_OVERRIDE
ZLO_FORCE_NO_ZONE_CONNECTION ZLO_FORCE_NO_ZONE_CONNECTION
}; };
enum RECURSE_MODE
{
RECURSE,
NO_RECURSE,
};
/** /**
* A base class for any item which can be embedded within the #BOARD container class, and * A base class for any item which can be embedded within the #BOARD container class, and
@ -207,15 +212,7 @@ public:
* *
* @note This function should not add or remove items to the parent. * @note This function should not add or remove items to the parent.
*/ */
virtual void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const { } virtual void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const {}
/**
* Invoke a function on all descendants.
*
* @note This function should not add or remove items.
*/
virtual void RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction,
int aDepth = 0 ) const { }
BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; } BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; }

View File

@ -523,8 +523,7 @@ void BOARD::Move( const VECTOR2I& aMoveVector ) // overload
} }
void BOARD::RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction, void BOARD::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
int aDepth ) const
{ {
try try
{ {
@ -543,18 +542,22 @@ void BOARD::RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFuncti
for( FOOTPRINT* footprint : m_footprints ) for( FOOTPRINT* footprint : m_footprints )
{ {
aFunction( footprint ); aFunction( footprint );
footprint->RunOnDescendants( aFunction, aDepth + 1 );
if( aMode == RECURSE_MODE::RECURSE )
footprint->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
} }
for( BOARD_ITEM* drawing : m_drawings ) for( BOARD_ITEM* drawing : m_drawings )
{ {
aFunction( drawing ); aFunction( drawing );
drawing->RunOnDescendants( aFunction, aDepth + 1 );
if( aMode == RECURSE_MODE::RECURSE )
drawing->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
} }
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
wxFAIL_MSG( wxT( "Error running BOARD::RunOnDescendants" ) ); wxFAIL_MSG( wxT( "Error running BOARD::RunOnChildren" ) );
} }
} }
@ -1121,7 +1124,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectivity
footprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) footprint->RunOnChildren( [&]( BOARD_ITEM* aChild )
{ {
m_itemByIdCache.insert( { aChild->m_Uuid, aChild } ); m_itemByIdCache.insert( { aChild->m_Uuid, aChild } );
} ); },
RECURSE_MODE::NO_RECURSE );
break; break;
} }
@ -1150,7 +1154,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectivity
table->RunOnChildren( [&]( BOARD_ITEM* aChild ) table->RunOnChildren( [&]( BOARD_ITEM* aChild )
{ {
m_itemByIdCache.insert( { aChild->m_Uuid, aChild } ); m_itemByIdCache.insert( { aChild->m_Uuid, aChild } );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
break; break;
@ -1254,7 +1259,8 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
footprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) footprint->RunOnChildren( [&]( BOARD_ITEM* aChild )
{ {
m_itemByIdCache.erase( aChild->m_Uuid ); m_itemByIdCache.erase( aChild->m_Uuid );
} ); },
RECURSE_MODE::NO_RECURSE );
break; break;
} }
@ -1287,7 +1293,8 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode )
table->RunOnChildren( [&]( BOARD_ITEM* aChild ) table->RunOnChildren( [&]( BOARD_ITEM* aChild )
{ {
m_itemByIdCache.erase( aChild->m_Uuid ); m_itemByIdCache.erase( aChild->m_Uuid );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
break; break;

View File

@ -396,8 +396,7 @@ public:
void Move( const VECTOR2I& aMoveVector ) override; void Move( const VECTOR2I& aMoveVector ) override;
void RunOnDescendants( const std::function<void ( BOARD_ITEM* )>& aFunction, void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
int aDepth = 0 ) const override;
void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; } void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; }
int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; } int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }

View File

@ -106,7 +106,8 @@ COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCRE
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
Stage( child, aChangeType ); Stage( child, aChangeType );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
} }
@ -136,8 +137,9 @@ void BOARD_COMMIT::propagateDamage( BOARD_ITEM* aChangedItem, std::vector<ZONE*>
if( aStaleZones && aChangedItem->Type() == PCB_ZONE_T ) if( aStaleZones && aChangedItem->Type() == PCB_ZONE_T )
aStaleZones->push_back( static_cast<ZONE*>( aChangedItem ) ); aStaleZones->push_back( static_cast<ZONE*>( aChangedItem ) );
aChangedItem->RunOnChildren( std::bind( &BOARD_COMMIT::propagateDamage, this, _1, aStaleZones, aChangedItem->RunOnChildren(
aStaleHatchedShapes ) ); std::bind( &BOARD_COMMIT::propagateDamage, this, _1, aStaleZones, aStaleHatchedShapes ),
RECURSE_MODE::NO_RECURSE );
BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() ); BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() );
BOX2I damageBBox = aChangedItem->GetBoundingBox(); BOX2I damageBBox = aChangedItem->GetBoundingBox();
@ -202,11 +204,12 @@ void BOARD_COMMIT::propagateDamage( BOARD_ITEM* aChangedItem, std::vector<ZONE*>
for( FOOTPRINT* footprint : board->Footprints() ) for( FOOTPRINT* footprint : board->Footprints() )
{ {
footprint->RunOnDescendants( footprint->RunOnChildren(
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
checkItem( child ); checkItem( child );
} ); },
RECURSE_MODE::RECURSE );
} }
for( BOARD_ITEM* item : board->Drawings() ) for( BOARD_ITEM* item : board->Drawings() )
@ -542,11 +545,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags )
} }
boardItem->ClearEditFlags(); boardItem->ClearEditFlags();
boardItem->RunOnDescendants( boardItem->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
item->ClearEditFlags(); item->ClearEditFlags();
} ); },
RECURSE_MODE::RECURSE );
} // ... and regenerate them. } // ... and regenerate them.
// Invalidate component classes // Invalidate component classes
@ -813,7 +817,8 @@ void BOARD_COMMIT::Revert()
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->SetParentGroup( group ); child->SetParentGroup( group );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
view->Add( boardItem ); view->Add( boardItem );

View File

@ -2160,7 +2160,7 @@ EDA_ITEM* FOOTPRINT::Clone() const
} }
void FOOTPRINT::RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const void FOOTPRINT::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
{ {
try try
{ {
@ -2177,7 +2177,12 @@ void FOOTPRINT::RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunct
aFunction( group ); aFunction( group );
for( BOARD_ITEM* drawing : m_drawings ) for( BOARD_ITEM* drawing : m_drawings )
{
aFunction( drawing ); aFunction( drawing );
if( aMode == RECURSE_MODE::RECURSE )
drawing->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
}
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
@ -2186,40 +2191,6 @@ void FOOTPRINT::RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunct
} }
void FOOTPRINT::RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
int aDepth ) const
{
// Avoid freezes with infinite recursion
if( aDepth > 20 )
return;
try
{
for( PCB_FIELD* field : m_fields )
aFunction( field );
for( PAD* pad : m_pads )
aFunction( pad );
for( ZONE* zone : m_zones )
aFunction( zone );
for( PCB_GROUP* group : m_groups )
aFunction( group );
for( BOARD_ITEM* drawing : m_drawings )
{
aFunction( drawing );
drawing->RunOnDescendants( aFunction, aDepth + 1 );
}
}
catch( std::bad_function_call& )
{
wxFAIL_MSG( wxT( "Error running FOOTPRINT::RunOnDescendants" ) );
}
}
std::vector<int> FOOTPRINT::ViewGetLayers() const std::vector<int> FOOTPRINT::ViewGetLayers() const
{ {
std::vector<int> layers; std::vector<int> layers;
@ -2575,10 +2546,11 @@ BOARD_ITEM* FOOTPRINT::Duplicate() const
{ {
FOOTPRINT* dupe = static_cast<FOOTPRINT*>( BOARD_ITEM::Duplicate() ); FOOTPRINT* dupe = static_cast<FOOTPRINT*>( BOARD_ITEM::Duplicate() );
dupe->RunOnDescendants( [&]( BOARD_ITEM* child ) dupe->RunOnChildren( [&]( BOARD_ITEM* child )
{ {
const_cast<KIID&>( child->m_Uuid ) = KIID(); const_cast<KIID&>( child->m_Uuid ) = KIID();
}); },
RECURSE_MODE::RECURSE );
return dupe; return dupe;
} }
@ -2683,11 +2655,12 @@ BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootpr
if( aAddToFootprint ) if( aAddToFootprint )
{ {
group->RunOnDescendants( group->RunOnChildren(
[&]( BOARD_ITEM* aCurrItem ) [&]( BOARD_ITEM* aCurrItem )
{ {
Add( aCurrItem ); Add( aCurrItem );
} ); },
RECURSE_MODE::RECURSE );
Add( group ); Add( group );
} }
@ -3390,12 +3363,13 @@ void FOOTPRINT::CheckNetTies( const std::function<void( const BOARD_ITEM* aItem,
if( item->IsOnCopperLayer() ) if( item->IsOnCopperLayer() )
copperItems.push_back( item ); copperItems.push_back( item );
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* descendent ) [&]( BOARD_ITEM* descendent )
{ {
if( descendent->IsOnCopperLayer() ) if( descendent->IsOnCopperLayer() )
copperItems.push_back( descendent ); copperItems.push_back( descendent );
} ); },
RECURSE_MODE::RECURSE );
} }
for( ZONE* zone : m_zones ) for( ZONE* zone : m_zones )
@ -3557,13 +3531,15 @@ void FOOTPRINT::swapData( BOARD_ITEM* aImage )
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->SetParent( this ); child->SetParent( this );
} ); },
RECURSE_MODE::NO_RECURSE );
image->RunOnChildren( image->RunOnChildren(
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->SetParent( image ); child->SetParent( image );
} ); },
RECURSE_MODE::NO_RECURSE );
} }

View File

@ -870,11 +870,7 @@ public:
EDA_ITEM* Clone() const override; EDA_ITEM* Clone() const override;
///< @copydoc BOARD_ITEM::RunOnChildren ///< @copydoc BOARD_ITEM::RunOnChildren
void RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction ) const override; void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
///< @copydoc BOARD_ITEM::RunOnDescendants
void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
int aDepth = 0 ) const override;
virtual std::vector<int> ViewGetLayers() const override; virtual std::vector<int> ViewGetLayers() const override;

View File

@ -539,14 +539,15 @@ void FOOTPRINT_EDIT_FRAME::updateEnabledLayers()
// Don't drop pre-existing user layers // Don't drop pre-existing user layers
LSET enabledLayers = GetBoard()->GetEnabledLayers(); LSET enabledLayers = GetBoard()->GetEnabledLayers();
m_originalFootprintCopy->RunOnDescendants( m_originalFootprintCopy->RunOnChildren(
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
LSET childLayers = child->GetLayerSet() & LSET::UserDefinedLayersMask(); LSET childLayers = child->GetLayerSet() & LSET::UserDefinedLayersMask();
for( PCB_LAYER_ID layer : childLayers ) for( PCB_LAYER_ID layer : childLayers )
enabledLayers.set( layer ); enabledLayers.set( layer );
} ); },
RECURSE_MODE::RECURSE );
// Enable any layers that the user has gone to the trouble to name // Enable any layers that the user has gone to the trouble to name
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();

View File

@ -928,16 +928,17 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
fixUuid( const_cast<KIID&>( newFootprint->m_Uuid ) ); fixUuid( const_cast<KIID&>( newFootprint->m_Uuid ) );
newFootprint->RunOnDescendants( newFootprint->RunOnChildren(
[&]( BOARD_ITEM* aChild ) [&]( BOARD_ITEM* aChild )
{ {
fixUuid( const_cast<KIID&>( aChild->m_Uuid ) ); fixUuid( const_cast<KIID&>( aChild->m_Uuid ) );
} ); },
RECURSE_MODE::RECURSE );
// Right now, we only show the "Unconnected" net in the footprint editor, but this is still // Right now, we only show the "Unconnected" net in the footprint editor, but this is still
// referenced in the footprint. So we need to update the net pointers in the footprint to // referenced in the footprint. So we need to update the net pointers in the footprint to
// point to the nets in the main board. // point to the nets in the main board.
newFootprint->RunOnDescendants( newFootprint->RunOnChildren(
[&]( BOARD_ITEM* aChild ) [&]( BOARD_ITEM* aChild )
{ {
if( BOARD_CONNECTED_ITEM* conn = dynamic_cast<BOARD_CONNECTED_ITEM*>( aChild ) ) if( BOARD_CONNECTED_ITEM* conn = dynamic_cast<BOARD_CONNECTED_ITEM*>( aChild ) )
@ -954,7 +955,8 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
} }
} }
} ); },
RECURSE_MODE::RECURSE );
BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings(); BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings();
@ -1314,7 +1316,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx
if( footprint->GetValue().IsEmpty() ) if( footprint->GetValue().IsEmpty() )
footprint->SetValue( aFootprintName ); footprint->SetValue( aFootprintName );
footprint->RunOnDescendants( footprint->RunOnChildren(
[&]( BOARD_ITEM* aChild ) [&]( BOARD_ITEM* aChild )
{ {
if( aChild->Type() == PCB_FIELD_T || aChild->Type() == PCB_TEXT_T ) if( aChild->Type() == PCB_FIELD_T || aChild->Type() == PCB_TEXT_T )
@ -1327,7 +1329,8 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx
textItem->SetItalic( settings.GetTextItalic( layer ) ); textItem->SetItalic( settings.GetTextItalic( layer ) );
textItem->SetKeepUpright( settings.GetTextUpright( layer ) ); textItem->SetKeepUpright( settings.GetTextUpright( layer ) );
} }
} ); },
RECURSE_MODE::RECURSE );
SetMsgPanel( footprint ); SetMsgPanel( footprint );
return footprint; return footprint;

View File

@ -275,7 +275,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
if( copy->Type() == PCB_GROUP_T || copy->Type() == PCB_GENERATOR_T ) if( copy->Type() == PCB_GROUP_T || copy->Type() == PCB_GENERATOR_T )
{ {
copy->RunOnDescendants( copy->RunOnChildren(
[&]( BOARD_ITEM* descendant ) [&]( BOARD_ITEM* descendant )
{ {
// One cannot add an additional mandatory field to a given footprint: // One cannot add an additional mandatory field to a given footprint:
@ -292,7 +292,8 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
partialFootprint.Add( descendant ); partialFootprint.Add( descendant );
else else
skipped_items.push_back( descendant ); skipped_items.push_back( descendant );
} ); },
RECURSE_MODE::RECURSE );
} }
// locate the reference point at (0, 0) in the copied items // locate the reference point at (0, 0) in the copied items
@ -432,12 +433,13 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
if( copy->Type() == PCB_GROUP_T || copy->Type() == PCB_GENERATOR_T ) if( copy->Type() == PCB_GROUP_T || copy->Type() == PCB_GENERATOR_T )
{ {
copy->RunOnDescendants( copy->RunOnChildren(
[&]( BOARD_ITEM* descendant ) [&]( BOARD_ITEM* descendant )
{ {
descendant->SetLocked( false ); descendant->SetLocked( false );
Format( descendant ); Format( descendant );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
copy->SetParentGroup( nullptr ); copy->SetParentGroup( nullptr );

View File

@ -123,7 +123,7 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint )
newFootprint->ClearFlags(); newFootprint->ClearFlags();
recordAndUpdateUuid( newFootprint ); recordAndUpdateUuid( newFootprint );
newFootprint->RunOnDescendants( newFootprint->RunOnChildren(
[&]( BOARD_ITEM* aItem ) [&]( BOARD_ITEM* aItem )
{ {
if( aItem->Type() == PCB_PAD_T ) if( aItem->Type() == PCB_PAD_T )
@ -131,7 +131,8 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint )
aItem->ClearFlags(); aItem->ClearFlags();
recordAndUpdateUuid( aItem ); recordAndUpdateUuid( aItem );
} ); },
RECURSE_MODE::RECURSE );
AddFootprintToBoard( newFootprint ); AddFootprintToBoard( newFootprint );

View File

@ -287,11 +287,12 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID
{ {
lastItem->ClearBrightened(); lastItem->ClearBrightened();
lastItem->RunOnDescendants( lastItem->RunOnChildren(
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->ClearBrightened(); child->ClearBrightened();
} ); },
RECURSE_MODE::RECURSE );
GetCanvas()->GetView()->Update( lastItem ); GetCanvas()->GetView()->Update( lastItem );
lastBrightenedItemID = niluuid; lastBrightenedItemID = niluuid;
@ -332,11 +333,12 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector<BOARD_ITEM*> aItems, PCB_LAYER_ID
{ {
item->SetBrightened(); item->SetBrightened();
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->SetBrightened(); child->SetBrightened();
}); },
RECURSE_MODE::RECURSE );
GetCanvas()->GetView()->Update( item ); GetCanvas()->GetView()->Update( item );
lastBrightenedItemIDs.push_back( item->m_Uuid ); lastBrightenedItemIDs.push_back( item->m_Uuid );

View File

@ -269,7 +269,7 @@ bool PCB_EDIT_FRAME::saveSelectionToDesignBlock( const wxString& aNickname, PCB_
tempBoard->Add( static_cast<BOARD_ITEM*>( copy ), ADD_MODE::APPEND, false ); tempBoard->Add( static_cast<BOARD_ITEM*>( copy ), ADD_MODE::APPEND, false );
if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( item ) ) if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( item ) )
fp->RunOnChildren( addNetIfNeeded ); fp->RunOnChildren( addNetIfNeeded, RECURSE_MODE::NO_RECURSE );
else else
addNetIfNeeded( copy ); addNetIfNeeded( copy );
} }

View File

@ -189,7 +189,8 @@ void PCB_GROUP::SetLocked( bool aLockState )
[&]( BOARD_ITEM* child ) [&]( BOARD_ITEM* child )
{ {
child->SetLocked( aLockState ); child->SetLocked( aLockState );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
@ -397,12 +398,19 @@ void PCB_GROUP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_I
} }
void PCB_GROUP::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const void PCB_GROUP::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
{ {
try try
{ {
for( BOARD_ITEM* item : m_items ) for( BOARD_ITEM* item : m_items )
{
aFunction( item ); aFunction( item );
if( aMode == RECURSE_MODE::RECURSE && ( item->Type() == PCB_GROUP_T || item->Type() == PCB_GENERATOR_T ) )
{
item->RunOnChildren( aFunction, RECURSE_MODE::RECURSE );
}
}
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
@ -411,30 +419,6 @@ void PCB_GROUP::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFuncti
} }
void PCB_GROUP::RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
int aDepth ) const
{
// Avoid freezes with infinite recursion
if( aDepth > 20 )
return;
try
{
for( BOARD_ITEM* item : m_items )
{
aFunction( item );
if( item->Type() == PCB_GROUP_T || item->Type() == PCB_GENERATOR_T )
item->RunOnDescendants( aFunction, aDepth + 1 );
}
}
catch( std::bad_function_call& )
{
wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnDescendants" ) );
}
}
bool PCB_GROUP::operator==( const BOARD_ITEM& aBoardItem ) const bool PCB_GROUP::operator==( const BOARD_ITEM& aBoardItem ) const
{ {
if( aBoardItem.Type() != Type() ) if( aBoardItem.Type() != Type() )

View File

@ -199,11 +199,7 @@ public:
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override; void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
///< @copydoc BOARD_ITEM::RunOnChildren ///< @copydoc BOARD_ITEM::RunOnChildren
void RunOnChildren( const std::function<void ( BOARD_ITEM* )>& aFunction ) const override; void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
///< @copydoc BOARD_ITEM::RunOnDescendants
void RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFunction,
int aDepth = 0 ) const override;
/** /**
* Check if the proposed type can be added to a group * Check if the proposed type can be added to a group

View File

@ -895,12 +895,13 @@ BOARD_ITEM* PCB_IO_KICAD_SEXPR_PARSER::Parse()
const std::vector<wxString>* embeddedFonts = item->GetEmbeddedFiles()->UpdateFontFiles(); const std::vector<wxString>* embeddedFonts = item->GetEmbeddedFiles()->UpdateFontFiles();
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* aChild ) [&]( BOARD_ITEM* aChild )
{ {
if( EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aChild ) ) if( EDA_TEXT* textItem = dynamic_cast<EDA_TEXT*>( aChild ) )
textItem->ResolveFont( embeddedFonts ); textItem->ResolveFont( embeddedFonts );
} ); },
RECURSE_MODE::RECURSE );
resolveGroups( item ); resolveGroups( item );
@ -1285,7 +1286,8 @@ void PCB_IO_KICAD_SEXPR_PARSER::resolveGroups( BOARD_ITEM* aParent )
{ {
if( child->m_Uuid == aId ) if( child->m_Uuid == aId )
aItem = child; aItem = child;
} ); },
RECURSE_MODE::NO_RECURSE );
} }
return aItem; return aItem;

View File

@ -346,7 +346,7 @@ void PCB_SHAPE::updateHatching() const
holes.Append( footprint->GetCourtyard( layer ) ); holes.Append( footprint->GetCourtyard( layer ) );
// Knockout footprint fields // Knockout footprint fields
footprint->RunOnDescendants( footprint->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
if( item->Type() == PCB_FIELD_T if( item->Type() == PCB_FIELD_T
@ -355,7 +355,8 @@ void PCB_SHAPE::updateHatching() const
{ {
knockoutItem( item ); knockoutItem( item );
} }
} ); },
RECURSE_MODE::RECURSE );
} }
m_hatching.BooleanSubtract( holes ); m_hatching.BooleanSubtract( holes );

View File

@ -218,7 +218,7 @@ void PCB_TABLE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
} }
void PCB_TABLE::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const void PCB_TABLE::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
{ {
for( PCB_TABLECELL* cell : m_cells ) for( PCB_TABLECELL* cell : m_cells )
aFunction( cell ); aFunction( cell );

View File

@ -97,7 +97,7 @@ public:
void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; } void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; }
bool StrokeRows() const { return m_strokeRows; } bool StrokeRows() const { return m_strokeRows; }
void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction ) const override; void RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const override;
void SetPosition( const VECTOR2I& aPos ) override; void SetPosition( const VECTOR2I& aPos ) override;
VECTOR2I GetPosition() const override; VECTOR2I GetPosition() const override;

View File

@ -62,8 +62,8 @@ void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
if( boardItem->Type() == PCB_FOOTPRINT_T ) if( boardItem->Type() == PCB_FOOTPRINT_T )
{ {
static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Add, this, static_cast<FOOTPRINT*>( boardItem )
_1, aDrawPriority ) ); ->RunOnChildren( std::bind( &PCB_VIEW::Add, this, _1, aDrawPriority ), RECURSE_MODE::NO_RECURSE );
} }
} }
@ -79,8 +79,8 @@ void PCB_VIEW::Remove( KIGFX::VIEW_ITEM* aItem )
if( boardItem->Type() == PCB_FOOTPRINT_T ) if( boardItem->Type() == PCB_FOOTPRINT_T )
{ {
static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Remove, static_cast<FOOTPRINT*>( boardItem )
this, _1 ) ); ->RunOnChildren( std::bind( &PCB_VIEW::Remove, this, _1 ), RECURSE_MODE::NO_RECURSE );
} }
} }
@ -104,7 +104,8 @@ void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
[this, aUpdateFlags]( BOARD_ITEM* child ) [this, aUpdateFlags]( BOARD_ITEM* child )
{ {
VIEW::Update( child, aUpdateFlags ); VIEW::Update( child, aUpdateFlags );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
} }

View File

@ -306,11 +306,12 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent )
// it this state, reset the selected stated of aItem: // it this state, reset the selected stated of aItem:
this_item->ClearSelected(); this_item->ClearSelected();
this_item->RunOnDescendants( this_item->RunOnChildren(
[]( BOARD_ITEM* aItem ) []( BOARD_ITEM* aItem )
{ {
aItem->ClearSelected(); aItem->ClearSelected();
} ); },
RECURSE_MODE::RECURSE );
// We're iterating backwards, so the first item is the last in the array // We're iterating backwards, so the first item is the last in the array
TransformItem( *m_array_opts, arraySize - ptN - 1, *this_item ); TransformItem( *m_array_opts, arraySize - ptN - 1, *this_item );
@ -318,11 +319,12 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent )
// If a group is duplicated, add also created members to the board // If a group is duplicated, add also created members to the board
if( this_item->Type() == PCB_GROUP_T ) if( this_item->Type() == PCB_GROUP_T )
{ {
this_item->RunOnDescendants( this_item->RunOnChildren(
[&]( BOARD_ITEM* aItem ) [&]( BOARD_ITEM* aItem )
{ {
commit.Add( aItem ); commit.Add( aItem );
} ); },
RECURSE_MODE::RECURSE );
} }
commit.Add( this_item ); commit.Add( this_item );

View File

@ -2050,10 +2050,11 @@ void BOARD_INSPECTION_TOOL::calculateSelectionRatsnest( const VECTOR2I& aDelta )
} }
else if( item->Type() == PCB_GROUP_T || item->Type() == PCB_GENERATOR_T ) else if( item->Type() == PCB_GROUP_T || item->Type() == PCB_GENERATOR_T )
{ {
item->RunOnDescendants( [ &queued_items ]( BOARD_ITEM *aItem ) item->RunOnChildren( [ &queued_items ]( BOARD_ITEM *aItem )
{ {
queued_items.push_back( aItem ); queued_items.push_back( aItem );
} ); },
RECURSE_MODE::RECURSE );
} }
else if( BOARD_CONNECTED_ITEM* boardItem = dyn_cast<BOARD_CONNECTED_ITEM*>( item ) ) else if( BOARD_CONNECTED_ITEM* boardItem = dyn_cast<BOARD_CONNECTED_ITEM*>( item ) )
{ {

View File

@ -91,12 +91,13 @@ int BOARD_REANNOTATE_TOOL::ReannotateDuplicates( const PCB_SELECTION& aSelection
{ {
PCB_GROUP* group = static_cast<PCB_GROUP*>( item ); PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
group->RunOnDescendants( group->RunOnChildren(
[&]( BOARD_ITEM* aGroupItem ) [&]( BOARD_ITEM* aGroupItem )
{ {
if( aGroupItem->Type() == PCB_FOOTPRINT_T ) if( aGroupItem->Type() == PCB_FOOTPRINT_T )
fpOnBoard.push_back( static_cast<FOOTPRINT*>( aGroupItem ) ); fpOnBoard.push_back( static_cast<FOOTPRINT*>( aGroupItem ) );
} ); },
RECURSE_MODE::RECURSE );
} }
} }
@ -115,12 +116,13 @@ int BOARD_REANNOTATE_TOOL::ReannotateDuplicates( const PCB_SELECTION& aSelection
{ {
PCB_GROUP* group = static_cast<PCB_GROUP*>( item ); PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
group->RunOnDescendants( group->RunOnChildren(
[&]( BOARD_ITEM* aGroupItem ) [&]( BOARD_ITEM* aGroupItem )
{ {
if( aGroupItem->Type() == PCB_FOOTPRINT_T ) if( aGroupItem->Type() == PCB_FOOTPRINT_T )
fpInSelection.push_back( static_cast<FOOTPRINT*>( aGroupItem ) ); fpInSelection.push_back( static_cast<FOOTPRINT*>( aGroupItem ) );
} ); },
RECURSE_MODE::RECURSE );
} }
} }

View File

@ -641,11 +641,12 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
{ {
item->SetLayer( destLayer ); item->SetLayer( destLayer );
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* descendant ) [&]( BOARD_ITEM* descendant )
{ {
descendant->SetLayer( destLayer ); descendant->SetLayer( destLayer );
} ); },
RECURSE_MODE::RECURSE );
} }
} }
@ -654,11 +655,12 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent,
item->Move( cursorPosition ); item->Move( cursorPosition );
commit.Add( item ); commit.Add( item );
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* descendant ) [&]( BOARD_ITEM* descendant )
{ {
commit.Add( descendant ); commit.Add( descendant );
} ); },
RECURSE_MODE::RECURSE );
} }
commit.Push( _( "Place Items" ) ); commit.Push( _( "Place Items" ) );

View File

@ -2168,11 +2168,12 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
{ {
if( item->Type() == PCB_GROUP_T ) if( item->Type() == PCB_GROUP_T )
{ {
static_cast<PCB_GROUP*>( item )->RunOnDescendants( static_cast<PCB_GROUP*>( item )->RunOnChildren(
[&]( BOARD_ITEM* descendant ) [&]( BOARD_ITEM* descendant )
{ {
items.push_back( descendant ); items.push_back( descendant );
} ); },
RECURSE_MODE::RECURSE );
} }
else else
{ {
@ -2557,17 +2558,19 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
break; break;
case PCB_GROUP_T: case PCB_GROUP_T:
board_item->RunOnDescendants( board_item->RunOnChildren(
[&commit]( BOARD_ITEM* aItem ) [&commit]( BOARD_ITEM* aItem )
{ {
commit.Stage( aItem, CHT_UNGROUP ); commit.Stage( aItem, CHT_UNGROUP );
} ); },
RECURSE_MODE::RECURSE );
board_item->RunOnDescendants( board_item->RunOnChildren(
[&commit]( BOARD_ITEM* aItem ) [&commit]( BOARD_ITEM* aItem )
{ {
commit.Remove( aItem ); commit.Remove( aItem );
} ); },
RECURSE_MODE::RECURSE );
commit.Remove( board_item ); commit.Remove( board_item );
itemsDeleted++; itemsDeleted++;
@ -2967,13 +2970,14 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
case PCB_GROUP_T: case PCB_GROUP_T:
dupe_item = static_cast<PCB_GROUP*>( orig_item )->DeepDuplicate(); dupe_item = static_cast<PCB_GROUP*>( orig_item )->DeepDuplicate();
dupe_item->RunOnDescendants( dupe_item->RunOnChildren(
[&]( BOARD_ITEM* aItem ) [&]( BOARD_ITEM* aItem )
{ {
aItem->ClearSelected(); aItem->ClearSelected();
new_items.push_back( aItem ); new_items.push_back( aItem );
commit.Add( aItem ); commit.Add( aItem );
} ); },
RECURSE_MODE::RECURSE );
dupe_item->ClearSelected(); dupe_item->ClearSelected();
new_items.push_back( dupe_item ); new_items.push_back( dupe_item );

View File

@ -585,11 +585,12 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
item->SetFlags( IS_MOVING ); item->SetFlags( IS_MOVING );
static_cast<BOARD_ITEM*>( item )->RunOnDescendants( static_cast<BOARD_ITEM*>( item )->RunOnChildren(
[&]( BOARD_ITEM* bItem ) [&]( BOARD_ITEM* bItem )
{ {
item->SetFlags( IS_MOVING ); item->SetFlags( IS_MOVING );
} ); },
RECURSE_MODE::RECURSE );
} }
} }
@ -631,12 +632,13 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
if( item->Type() == PCB_FOOTPRINT_T ) if( item->Type() == PCB_FOOTPRINT_T )
FPs.push_back( static_cast<FOOTPRINT*>( item ) ); FPs.push_back( static_cast<FOOTPRINT*>( item ) );
item->RunOnDescendants( item->RunOnChildren(
[&]( BOARD_ITEM* descendent ) [&]( BOARD_ITEM* descendent )
{ {
if( descendent->Type() == PCB_FOOTPRINT_T ) if( descendent->Type() == PCB_FOOTPRINT_T )
FPs.push_back( static_cast<FOOTPRINT*>( descendent ) ); FPs.push_back( static_cast<FOOTPRINT*>( descendent ) );
} ); },
RECURSE_MODE::RECURSE );
} }
} }

View File

@ -194,7 +194,7 @@ bool MULTICHANNEL_TOOL::findOtherItemsInRuleArea( ZONE* aRuleArea, std::set<BOAR
// A group is cloned in its entirety if *all* children are contained // A group is cloned in its entirety if *all* children are contained
bool addGroup = true; bool addGroup = true;
group->RunOnDescendants( group->RunOnChildren(
[&]( BOARD_ITEM* aItem ) [&]( BOARD_ITEM* aItem )
{ {
if( aItem->IsType( { PCB_ZONE_T, PCB_SHAPE_T, PCB_DIMENSION_T } ) ) if( aItem->IsType( { PCB_ZONE_T, PCB_SHAPE_T, PCB_DIMENSION_T } ) )
@ -205,7 +205,8 @@ bool MULTICHANNEL_TOOL::findOtherItemsInRuleArea( ZONE* aRuleArea, std::set<BOAR
if( val->AsDouble() == 0.0 ) if( val->AsDouble() == 0.0 )
addGroup = false; addGroup = false;
} }
} ); },
RECURSE_MODE::RECURSE );
if( addGroup ) if( addGroup )
aItems.insert( group ); aItems.insert( group );

View File

@ -1439,11 +1439,12 @@ bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, std::vector<BOARD_ITEM
{ {
const_cast<KIID&>( item->m_Uuid ) = KIID(); const_cast<KIID&>( item->m_Uuid ) = KIID();
item->RunOnDescendants( item->RunOnChildren(
[]( BOARD_ITEM* aChild ) []( BOARD_ITEM* aChild )
{ {
const_cast<KIID&>( aChild->m_Uuid ) = KIID(); const_cast<KIID&>( aChild->m_Uuid ) = KIID();
} ); },
RECURSE_MODE::RECURSE );
// Even though BOARD_COMMIT::Push() will add any new items to the group, we're // Even though BOARD_COMMIT::Push() will add any new items to the group, we're
// going to run PCB_ACTIONS::move first, and the move tool will throw out any // going to run PCB_ACTIONS::move first, and the move tool will throw out any
@ -2046,7 +2047,7 @@ int PCB_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
// Use dynamic_cast to include PCB_GENERATORs. // Use dynamic_cast to include PCB_GENERATORs.
else if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( aItem ) ) else if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( aItem ) )
{ {
group->RunOnChildren( accumulateTrackLength ); group->RunOnChildren( accumulateTrackLength, RECURSE_MODE::NO_RECURSE );
} }
else else
{ {
@ -2088,7 +2089,7 @@ int PCB_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) ) if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
{ {
boardItem->RunOnChildren( accumulateArea ); boardItem->RunOnChildren( accumulateArea, RECURSE_MODE::NO_RECURSE );
for( PCB_LAYER_ID layer : LSET( boardItem->GetLayerSet() & enabledCopper ) ) for( PCB_LAYER_ID layer : LSET( boardItem->GetLayerSet() & enabledCopper ) )
{ {

View File

@ -911,11 +911,12 @@ PCB_GRID_HELPER::queryVisible( const BOX2I& aArea, const std::vector<BOARD_ITEM*
{ {
items.erase( aItem ); items.erase( aItem );
aItem->RunOnDescendants( aItem->RunOnChildren(
[&]( BOARD_ITEM* aChild ) [&]( BOARD_ITEM* aChild )
{ {
skipItem( aChild ); skipItem( aChild );
} ); },
RECURSE_MODE::RECURSE );
}; };
for( BOARD_ITEM* item : aSkip ) for( BOARD_ITEM* item : aSkip )

View File

@ -98,7 +98,8 @@ const std::vector<KIGFX::VIEW_ITEM*> PCB_SELECTION::updateDrawList() const
boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem ) boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem )
{ {
addItem( childItem ); addItem( childItem );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
}; };

View File

@ -614,7 +614,8 @@ void PCB_SELECTION_TOOL::EnterGroup()
m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem ) m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem )
{ {
select( titem ); select( titem );
} ); },
RECURSE_MODE::NO_RECURSE );
m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
@ -727,12 +728,13 @@ PCB_SELECTION& PCB_SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aCl
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item ); BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
bool lockedDescendant = false; bool lockedDescendant = false;
boardItem->RunOnDescendants( boardItem->RunOnChildren(
[&]( BOARD_ITEM* curr_item ) [&]( BOARD_ITEM* curr_item )
{ {
if( curr_item->IsLocked() ) if( curr_item->IsLocked() )
lockedDescendant = true; lockedDescendant = true;
} ); },
RECURSE_MODE::RECURSE );
if( boardItem->IsLocked() || lockedDescendant ) if( boardItem->IsLocked() || lockedDescendant )
lockedItems.push_back( boardItem ); lockedItems.push_back( boardItem );
@ -3161,8 +3163,8 @@ void PCB_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUs
if( aItem->IsBOARD_ITEM() ) if( aItem->IsBOARD_ITEM() )
{ {
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem ); BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
boardItem->RunOnDescendants( std::bind( &PCB_SELECTION_TOOL::highlightInternal, this, _1, boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::highlightInternal, this, _1, aMode, aUsingOverlay ),
aMode, aUsingOverlay ) ); RECURSE_MODE::RECURSE );
} }
} }
@ -3197,8 +3199,8 @@ void PCB_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, bool a
if( aItem->IsBOARD_ITEM() ) if( aItem->IsBOARD_ITEM() )
{ {
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem ); BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
boardItem->RunOnDescendants( std::bind( &PCB_SELECTION_TOOL::unhighlightInternal, this, _1, boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::unhighlightInternal, this, _1, aMode, aUsingOverlay ),
aMode, aUsingOverlay ) ); RECURSE_MODE::RECURSE );
} }
} }
@ -3223,12 +3225,13 @@ bool PCB_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const
if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( item ) ) if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( item ) )
{ {
group->RunOnDescendants( group->RunOnChildren(
[&]( BOARD_ITEM* aItem ) [&]( BOARD_ITEM* aItem )
{ {
if( aItem->HitTest( aPoint, margin ) ) if( aItem->HitTest( aPoint, margin ) )
found = true; found = true;
} ); },
RECURSE_MODE::RECURSE );
} }
if( found ) if( found )

View File

@ -82,7 +82,8 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool,
// footprints have more drawable parts // footprints have more drawable parts
if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( newItem.get() ) ) if( FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( newItem.get() ) )
fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) ); fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ),
RECURSE_MODE::NO_RECURSE );
} }
}; };

View File

@ -465,7 +465,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
group->RunOnChildren( [&]( BOARD_ITEM* child ) group->RunOnChildren( [&]( BOARD_ITEM* child )
{ {
child->SetParentGroup( group ); child->SetParentGroup( group );
} ); },
RECURSE_MODE::NO_RECURSE );
} }
view->Add( item ); view->Add( item );
@ -642,11 +643,12 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
for( FOOTPRINT* footprint : GetBoard()->Footprints() ) for( FOOTPRINT* footprint : GetBoard()->Footprints() )
{ {
footprint->RunOnDescendants( footprint->RunOnChildren(
[&]( BOARD_ITEM* item ) [&]( BOARD_ITEM* item )
{ {
checkHatching( item ); checkHatching( item );
} ); },
RECURSE_MODE::RECURSE );
} }
if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 ) if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 )

View File

@ -126,8 +126,9 @@ void PCB_TEST_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, boo
if( aItem->IsBOARD_ITEM() ) if( aItem->IsBOARD_ITEM() )
{ {
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem ); BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, std::placeholders::_1,
std::placeholders::_1, aMode, aUsingOverlay ) ); aMode, aUsingOverlay ),
RECURSE_MODE::RECURSE );
} }
} }
@ -162,8 +163,9 @@ void PCB_TEST_SELECTION_TOOL::unhighlightInternal( EDA_ITEM* aItem, int aMode, b
if( aItem->IsBOARD_ITEM() ) if( aItem->IsBOARD_ITEM() )
{ {
BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem ); BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, std::placeholders::_1,
std::placeholders::_1, aMode, aUsingOverlay ) ); aMode, aUsingOverlay ),
RECURSE_MODE::RECURSE );
} }
} }