diff --git a/common/widgets/footprint_diff_widget.cpp b/common/widgets/footprint_diff_widget.cpp index cfffc9d920..c6873fbcf9 100644 --- a/common/widgets/footprint_diff_widget.cpp +++ b/common/widgets/footprint_diff_widget.cpp @@ -85,12 +85,13 @@ void FOOTPRINT_DIFF_WIDGET::DisplayDiff( FOOTPRINT* aBoardFootprint, m_boardItemCopy->ClearSelected(); m_boardItemCopy->ClearBrightened(); - m_boardItemCopy->RunOnDescendants( + m_boardItemCopy->RunOnChildren( [&]( BOARD_ITEM* item ) { item->ClearSelected(); item->ClearBrightened(); - } ); + }, + RECURSE_MODE::RECURSE ); m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() ); @@ -138,11 +139,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent ) m_boardItemCopy->SetForcedTransparency( val ); - m_boardItemCopy->RunOnDescendants( + m_boardItemCopy->RunOnChildren( [&]( BOARD_ITEM* item ) { item->SetForcedTransparency( val ); - } ); + }, + RECURSE_MODE::RECURSE ); } if( m_libraryItem ) @@ -156,11 +158,12 @@ void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent ) m_libraryItem->SetForcedTransparency( val ); - m_libraryItem->RunOnDescendants( + m_libraryItem->RunOnChildren( [&]( BOARD_ITEM* item ) { item->SetForcedTransparency( val ); - } ); + }, + RECURSE_MODE::RECURSE ); } RefreshAll(); diff --git a/include/board_item.h b/include/board_item.h index 11f3a31520..9cbbd95f69 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -69,6 +69,11 @@ enum ZONE_LAYER_OVERRIDE 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 @@ -207,15 +212,7 @@ public: * * @note This function should not add or remove items to the parent. */ - virtual void RunOnChildren( const std::function& aFunction ) const { } - - /** - * Invoke a function on all descendants. - * - * @note This function should not add or remove items. - */ - virtual void RunOnDescendants( const std::function& aFunction, - int aDepth = 0 ) const { } + virtual void RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const {} BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; } diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 60506729f2..4bdf36175f 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -523,8 +523,7 @@ void BOARD::Move( const VECTOR2I& aMoveVector ) // overload } -void BOARD::RunOnDescendants( const std::function& aFunction, - int aDepth ) const +void BOARD::RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const { try { @@ -543,18 +542,22 @@ void BOARD::RunOnDescendants( const std::function& aFuncti for( FOOTPRINT* footprint : m_footprints ) { aFunction( footprint ); - footprint->RunOnDescendants( aFunction, aDepth + 1 ); + + if( aMode == RECURSE_MODE::RECURSE ) + footprint->RunOnChildren( aFunction, RECURSE_MODE::RECURSE ); } for( BOARD_ITEM* drawing : m_drawings ) { aFunction( drawing ); - drawing->RunOnDescendants( aFunction, aDepth + 1 ); + + if( aMode == RECURSE_MODE::RECURSE ) + drawing->RunOnChildren( aFunction, RECURSE_MODE::RECURSE ); } } 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 ) { m_itemByIdCache.insert( { aChild->m_Uuid, aChild } ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); break; } @@ -1150,7 +1154,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode, bool aSkipConnectivity table->RunOnChildren( [&]( BOARD_ITEM* aChild ) { m_itemByIdCache.insert( { aChild->m_Uuid, aChild } ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } break; @@ -1254,7 +1259,8 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode ) footprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) { m_itemByIdCache.erase( aChild->m_Uuid ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); break; } @@ -1287,7 +1293,8 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aRemoveMode ) table->RunOnChildren( [&]( BOARD_ITEM* aChild ) { m_itemByIdCache.erase( aChild->m_Uuid ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } break; diff --git a/pcbnew/board.h b/pcbnew/board.h index b01bf85e6a..b610934df2 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -396,8 +396,7 @@ public: void Move( const VECTOR2I& aMoveVector ) override; - void RunOnDescendants( const std::function& aFunction, - int aDepth = 0 ) const override; + void RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const override; void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; } int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; } diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index ac09ebde17..42f6b037c9 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -106,7 +106,8 @@ COMMIT& BOARD_COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType, BASE_SCRE [&]( BOARD_ITEM* child ) { Stage( child, aChangeType ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } } @@ -136,8 +137,9 @@ void BOARD_COMMIT::propagateDamage( BOARD_ITEM* aChangedItem, std::vector if( aStaleZones && aChangedItem->Type() == PCB_ZONE_T ) aStaleZones->push_back( static_cast( aChangedItem ) ); - aChangedItem->RunOnChildren( std::bind( &BOARD_COMMIT::propagateDamage, this, _1, aStaleZones, - aStaleHatchedShapes ) ); + aChangedItem->RunOnChildren( + std::bind( &BOARD_COMMIT::propagateDamage, this, _1, aStaleZones, aStaleHatchedShapes ), + RECURSE_MODE::NO_RECURSE ); BOARD* board = static_cast( m_toolMgr->GetModel() ); BOX2I damageBBox = aChangedItem->GetBoundingBox(); @@ -202,11 +204,12 @@ void BOARD_COMMIT::propagateDamage( BOARD_ITEM* aChangedItem, std::vector for( FOOTPRINT* footprint : board->Footprints() ) { - footprint->RunOnDescendants( + footprint->RunOnChildren( [&]( BOARD_ITEM* child ) { checkItem( child ); - } ); + }, + RECURSE_MODE::RECURSE ); } for( BOARD_ITEM* item : board->Drawings() ) @@ -542,11 +545,12 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) } boardItem->ClearEditFlags(); - boardItem->RunOnDescendants( + boardItem->RunOnChildren( [&]( BOARD_ITEM* item ) { item->ClearEditFlags(); - } ); + }, + RECURSE_MODE::RECURSE ); } // ... and regenerate them. // Invalidate component classes @@ -813,7 +817,8 @@ void BOARD_COMMIT::Revert() [&]( BOARD_ITEM* child ) { child->SetParentGroup( group ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } view->Add( boardItem ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 4dbdc4c91a..d0cc29799d 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -2160,39 +2160,8 @@ EDA_ITEM* FOOTPRINT::Clone() const } -void FOOTPRINT::RunOnChildren( const std::function& aFunction ) const +void FOOTPRINT::RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const { - 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 ); - } - catch( std::bad_function_call& ) - { - wxFAIL_MSG( wxT( "Error running FOOTPRINT::RunOnChildren" ) ); - } -} - - -void FOOTPRINT::RunOnDescendants( const std::function& aFunction, - int aDepth ) const -{ - // Avoid freezes with infinite recursion - if( aDepth > 20 ) - return; - try { for( PCB_FIELD* field : m_fields ) @@ -2210,12 +2179,14 @@ void FOOTPRINT::RunOnDescendants( const std::function& aFun for( BOARD_ITEM* drawing : m_drawings ) { aFunction( drawing ); - drawing->RunOnDescendants( aFunction, aDepth + 1 ); + + if( aMode == RECURSE_MODE::RECURSE ) + drawing->RunOnChildren( aFunction, RECURSE_MODE::RECURSE ); } } catch( std::bad_function_call& ) { - wxFAIL_MSG( wxT( "Error running FOOTPRINT::RunOnDescendants" ) ); + wxFAIL_MSG( wxT( "Error running FOOTPRINT::RunOnChildren" ) ); } } @@ -2575,10 +2546,11 @@ BOARD_ITEM* FOOTPRINT::Duplicate() const { FOOTPRINT* dupe = static_cast( BOARD_ITEM::Duplicate() ); - dupe->RunOnDescendants( [&]( BOARD_ITEM* child ) + dupe->RunOnChildren( [&]( BOARD_ITEM* child ) { const_cast( child->m_Uuid ) = KIID(); - }); + }, + RECURSE_MODE::RECURSE ); return dupe; } @@ -2683,11 +2655,12 @@ BOARD_ITEM* FOOTPRINT::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToFootpr if( aAddToFootprint ) { - group->RunOnDescendants( + group->RunOnChildren( [&]( BOARD_ITEM* aCurrItem ) { Add( aCurrItem ); - } ); + }, + RECURSE_MODE::RECURSE ); Add( group ); } @@ -3390,12 +3363,13 @@ void FOOTPRINT::CheckNetTies( const std::functionIsOnCopperLayer() ) copperItems.push_back( item ); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* descendent ) { if( descendent->IsOnCopperLayer() ) copperItems.push_back( descendent ); - } ); + }, + RECURSE_MODE::RECURSE ); } for( ZONE* zone : m_zones ) @@ -3557,13 +3531,15 @@ void FOOTPRINT::swapData( BOARD_ITEM* aImage ) [&]( BOARD_ITEM* child ) { child->SetParent( this ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); image->RunOnChildren( [&]( BOARD_ITEM* child ) { child->SetParent( image ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index b5851f8b7d..0b5d0cf4da 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -870,11 +870,7 @@ public: EDA_ITEM* Clone() const override; ///< @copydoc BOARD_ITEM::RunOnChildren - void RunOnChildren( const std::function& aFunction ) const override; - - ///< @copydoc BOARD_ITEM::RunOnDescendants - void RunOnDescendants( const std::function& aFunction, - int aDepth = 0 ) const override; + void RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const override; virtual std::vector ViewGetLayers() const override; diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index 17d04c359f..de16eb7ac5 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -539,14 +539,15 @@ void FOOTPRINT_EDIT_FRAME::updateEnabledLayers() // Don't drop pre-existing user layers LSET enabledLayers = GetBoard()->GetEnabledLayers(); - m_originalFootprintCopy->RunOnDescendants( + m_originalFootprintCopy->RunOnChildren( [&]( BOARD_ITEM* child ) { LSET childLayers = child->GetLayerSet() & LSET::UserDefinedLayersMask(); for( PCB_LAYER_ID layer : childLayers ) enabledLayers.set( layer ); - } ); + }, + RECURSE_MODE::RECURSE ); // Enable any layers that the user has gone to the trouble to name SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 699373ddd5..105635614f 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -928,16 +928,17 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) fixUuid( const_cast( newFootprint->m_Uuid ) ); - newFootprint->RunOnDescendants( + newFootprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) { fixUuid( const_cast( aChild->m_Uuid ) ); - } ); + }, + RECURSE_MODE::RECURSE ); // 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 // point to the nets in the main board. - newFootprint->RunOnDescendants( + newFootprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) { if( BOARD_CONNECTED_ITEM* conn = dynamic_cast( aChild ) ) @@ -954,7 +955,8 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) } } - } ); + }, + RECURSE_MODE::RECURSE ); BOARD_DESIGN_SETTINGS& bds = m_pcb->GetDesignSettings(); @@ -1314,7 +1316,7 @@ FOOTPRINT* PCB_BASE_FRAME::CreateNewFootprint( wxString aFootprintName, const wx if( footprint->GetValue().IsEmpty() ) footprint->SetValue( aFootprintName ); - footprint->RunOnDescendants( + footprint->RunOnChildren( [&]( BOARD_ITEM* aChild ) { 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->SetKeepUpright( settings.GetTextUpright( layer ) ); } - } ); + }, + RECURSE_MODE::RECURSE ); SetMsgPanel( footprint ); return footprint; diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index 25b4e604a9..46b500b391 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -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 ) { - copy->RunOnDescendants( + copy->RunOnChildren( [&]( BOARD_ITEM* descendant ) { // 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 ); else skipped_items.push_back( descendant ); - } ); + }, + RECURSE_MODE::RECURSE ); } // 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 ) { - copy->RunOnDescendants( + copy->RunOnChildren( [&]( BOARD_ITEM* descendant ) { descendant->SetLocked( false ); Format( descendant ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } copy->SetParentGroup( nullptr ); diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index a17bb154c3..b9321713a8 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -123,7 +123,7 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint ) newFootprint->ClearFlags(); recordAndUpdateUuid( newFootprint ); - newFootprint->RunOnDescendants( + newFootprint->RunOnChildren( [&]( BOARD_ITEM* aItem ) { if( aItem->Type() == PCB_PAD_T ) @@ -131,7 +131,8 @@ bool FOOTPRINT_EDIT_FRAME::LoadFootprintFromBoard( FOOTPRINT* aFootprint ) aItem->ClearFlags(); recordAndUpdateUuid( aItem ); - } ); + }, + RECURSE_MODE::RECURSE ); AddFootprintToBoard( newFootprint ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index a9271872eb..70558b9bdb 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -287,11 +287,12 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { lastItem->ClearBrightened(); - lastItem->RunOnDescendants( + lastItem->RunOnChildren( [&]( BOARD_ITEM* child ) { child->ClearBrightened(); - } ); + }, + RECURSE_MODE::RECURSE ); GetCanvas()->GetView()->Update( lastItem ); lastBrightenedItemID = niluuid; @@ -332,11 +333,12 @@ void PCB_BASE_FRAME::FocusOnItems( std::vector aItems, PCB_LAYER_ID { item->SetBrightened(); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* child ) { child->SetBrightened(); - }); + }, + RECURSE_MODE::RECURSE ); GetCanvas()->GetView()->Update( item ); lastBrightenedItemIDs.push_back( item->m_Uuid ); diff --git a/pcbnew/pcb_design_block_utils.cpp b/pcbnew/pcb_design_block_utils.cpp index 22f1db90d4..e6af96092b 100644 --- a/pcbnew/pcb_design_block_utils.cpp +++ b/pcbnew/pcb_design_block_utils.cpp @@ -269,7 +269,7 @@ bool PCB_EDIT_FRAME::saveSelectionToDesignBlock( const wxString& aNickname, PCB_ tempBoard->Add( static_cast( copy ), ADD_MODE::APPEND, false ); if( FOOTPRINT* fp = dynamic_cast( item ) ) - fp->RunOnChildren( addNetIfNeeded ); + fp->RunOnChildren( addNetIfNeeded, RECURSE_MODE::NO_RECURSE ); else addNetIfNeeded( copy ); } diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 67d83f5b8d..45c520d61d 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -189,7 +189,8 @@ void PCB_GROUP::SetLocked( bool aLockState ) [&]( BOARD_ITEM* child ) { child->SetLocked( aLockState ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } @@ -397,40 +398,23 @@ void PCB_GROUP::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aFunction ) const +void PCB_GROUP::RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const { - try - { - for( BOARD_ITEM* item : m_items ) - aFunction( item ); - } - catch( std::bad_function_call& ) - { - wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnChildren" ) ); - } -} - - -void PCB_GROUP::RunOnDescendants( const std::function& 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 ); + 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& ) { - wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnDescendants" ) ); + wxFAIL_MSG( wxT( "Error calling function in PCB_GROUP::RunOnChildren" ) ); } } diff --git a/pcbnew/pcb_group.h b/pcbnew/pcb_group.h index 1956613c52..e160d75acf 100644 --- a/pcbnew/pcb_group.h +++ b/pcbnew/pcb_group.h @@ -199,11 +199,7 @@ public: void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& aList ) override; ///< @copydoc BOARD_ITEM::RunOnChildren - void RunOnChildren( const std::function& aFunction ) const override; - - ///< @copydoc BOARD_ITEM::RunOnDescendants - void RunOnDescendants( const std::function& aFunction, - int aDepth = 0 ) const override; + void RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const override; /** * Check if the proposed type can be added to a group diff --git a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp index 4b847efa47..fa607c8b22 100644 --- a/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp +++ b/pcbnew/pcb_io/kicad_sexpr/pcb_io_kicad_sexpr_parser.cpp @@ -895,12 +895,13 @@ BOARD_ITEM* PCB_IO_KICAD_SEXPR_PARSER::Parse() const std::vector* embeddedFonts = item->GetEmbeddedFiles()->UpdateFontFiles(); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* aChild ) { if( EDA_TEXT* textItem = dynamic_cast( aChild ) ) textItem->ResolveFont( embeddedFonts ); - } ); + }, + RECURSE_MODE::RECURSE ); resolveGroups( item ); @@ -1285,7 +1286,8 @@ void PCB_IO_KICAD_SEXPR_PARSER::resolveGroups( BOARD_ITEM* aParent ) { if( child->m_Uuid == aId ) aItem = child; - } ); + }, + RECURSE_MODE::NO_RECURSE ); } return aItem; diff --git a/pcbnew/pcb_shape.cpp b/pcbnew/pcb_shape.cpp index 09802dab76..c29a02bc97 100644 --- a/pcbnew/pcb_shape.cpp +++ b/pcbnew/pcb_shape.cpp @@ -346,7 +346,7 @@ void PCB_SHAPE::updateHatching() const holes.Append( footprint->GetCourtyard( layer ) ); // Knockout footprint fields - footprint->RunOnDescendants( + footprint->RunOnChildren( [&]( BOARD_ITEM* item ) { if( item->Type() == PCB_FIELD_T @@ -355,7 +355,8 @@ void PCB_SHAPE::updateHatching() const { knockoutItem( item ); } - } ); + }, + RECURSE_MODE::RECURSE ); } m_hatching.BooleanSubtract( holes ); diff --git a/pcbnew/pcb_table.cpp b/pcbnew/pcb_table.cpp index 7ddbda392c..5bf2448281 100644 --- a/pcbnew/pcb_table.cpp +++ b/pcbnew/pcb_table.cpp @@ -218,7 +218,7 @@ void PCB_TABLE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection ) } -void PCB_TABLE::RunOnChildren( const std::function& aFunction ) const +void PCB_TABLE::RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const { for( PCB_TABLECELL* cell : m_cells ) aFunction( cell ); diff --git a/pcbnew/pcb_table.h b/pcbnew/pcb_table.h index 34c6cefdaa..8f43e4f9be 100644 --- a/pcbnew/pcb_table.h +++ b/pcbnew/pcb_table.h @@ -97,7 +97,7 @@ public: void SetStrokeRows( bool aDoStroke ) { m_strokeRows = aDoStroke; } bool StrokeRows() const { return m_strokeRows; } - void RunOnChildren( const std::function& aFunction ) const override; + void RunOnChildren( const std::function& aFunction, RECURSE_MODE aMode ) const override; void SetPosition( const VECTOR2I& aPos ) override; VECTOR2I GetPosition() const override; diff --git a/pcbnew/pcb_view.cpp b/pcbnew/pcb_view.cpp index 381e906094..f014174226 100644 --- a/pcbnew/pcb_view.cpp +++ b/pcbnew/pcb_view.cpp @@ -62,8 +62,8 @@ void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority ) if( boardItem->Type() == PCB_FOOTPRINT_T ) { - static_cast( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Add, this, - _1, aDrawPriority ) ); + static_cast( boardItem ) + ->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 ) { - static_cast( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Remove, - this, _1 ) ); + static_cast( boardItem ) + ->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 ) { VIEW::Update( child, aUpdateFlags ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } } diff --git a/pcbnew/tools/array_tool.cpp b/pcbnew/tools/array_tool.cpp index 6c1c19ddba..e49f9f3ea2 100644 --- a/pcbnew/tools/array_tool.cpp +++ b/pcbnew/tools/array_tool.cpp @@ -306,11 +306,12 @@ void ARRAY_TOOL::onDialogClosed( wxCloseEvent& aEvent ) // it this state, reset the selected stated of aItem: this_item->ClearSelected(); - this_item->RunOnDescendants( + this_item->RunOnChildren( []( BOARD_ITEM* aItem ) { aItem->ClearSelected(); - } ); + }, + RECURSE_MODE::RECURSE ); // We're iterating backwards, so the first item is the last in the array 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( this_item->Type() == PCB_GROUP_T ) { - this_item->RunOnDescendants( + this_item->RunOnChildren( [&]( BOARD_ITEM* aItem ) { commit.Add( aItem ); - } ); + }, + RECURSE_MODE::RECURSE ); } commit.Add( this_item ); diff --git a/pcbnew/tools/board_inspection_tool.cpp b/pcbnew/tools/board_inspection_tool.cpp index 03a7a51cac..2d6c566cdc 100644 --- a/pcbnew/tools/board_inspection_tool.cpp +++ b/pcbnew/tools/board_inspection_tool.cpp @@ -2050,10 +2050,11 @@ void BOARD_INSPECTION_TOOL::calculateSelectionRatsnest( const VECTOR2I& aDelta ) } 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 ); - } ); + }, + RECURSE_MODE::RECURSE ); } else if( BOARD_CONNECTED_ITEM* boardItem = dyn_cast( item ) ) { diff --git a/pcbnew/tools/board_reannotate_tool.cpp b/pcbnew/tools/board_reannotate_tool.cpp index 97285b0805..e912627ea3 100644 --- a/pcbnew/tools/board_reannotate_tool.cpp +++ b/pcbnew/tools/board_reannotate_tool.cpp @@ -91,12 +91,13 @@ int BOARD_REANNOTATE_TOOL::ReannotateDuplicates( const PCB_SELECTION& aSelection { PCB_GROUP* group = static_cast( item ); - group->RunOnDescendants( + group->RunOnChildren( [&]( BOARD_ITEM* aGroupItem ) { if( aGroupItem->Type() == PCB_FOOTPRINT_T ) fpOnBoard.push_back( static_cast( aGroupItem ) ); - } ); + }, + RECURSE_MODE::RECURSE ); } } @@ -115,12 +116,13 @@ int BOARD_REANNOTATE_TOOL::ReannotateDuplicates( const PCB_SELECTION& aSelection { PCB_GROUP* group = static_cast( item ); - group->RunOnDescendants( + group->RunOnChildren( [&]( BOARD_ITEM* aGroupItem ) { if( aGroupItem->Type() == PCB_FOOTPRINT_T ) fpInSelection.push_back( static_cast( aGroupItem ) ); - } ); + }, + RECURSE_MODE::RECURSE ); } } diff --git a/pcbnew/tools/drawing_stackup_table_tool.cpp b/pcbnew/tools/drawing_stackup_table_tool.cpp index ead6120bd1..c2c6f1ded8 100644 --- a/pcbnew/tools/drawing_stackup_table_tool.cpp +++ b/pcbnew/tools/drawing_stackup_table_tool.cpp @@ -641,11 +641,12 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, { item->SetLayer( destLayer ); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* descendant ) { descendant->SetLayer( destLayer ); - } ); + }, + RECURSE_MODE::RECURSE ); } } @@ -654,11 +655,12 @@ int DRAWING_TOOL::InteractivePlaceWithPreview( const TOOL_EVENT& aEvent, item->Move( cursorPosition ); commit.Add( item ); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* descendant ) { commit.Add( descendant ); - } ); + }, + RECURSE_MODE::RECURSE ); } commit.Push( _( "Place Items" ) ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 18d6172f4f..a265cc1c68 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -2168,11 +2168,12 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) { if( item->Type() == PCB_GROUP_T ) { - static_cast( item )->RunOnDescendants( + static_cast( item )->RunOnChildren( [&]( BOARD_ITEM* descendant ) { items.push_back( descendant ); - } ); + }, + RECURSE_MODE::RECURSE ); } else { @@ -2557,17 +2558,19 @@ void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut ) break; case PCB_GROUP_T: - board_item->RunOnDescendants( + board_item->RunOnChildren( [&commit]( BOARD_ITEM* aItem ) { commit.Stage( aItem, CHT_UNGROUP ); - } ); + }, + RECURSE_MODE::RECURSE ); - board_item->RunOnDescendants( + board_item->RunOnChildren( [&commit]( BOARD_ITEM* aItem ) { commit.Remove( aItem ); - } ); + }, + RECURSE_MODE::RECURSE ); commit.Remove( board_item ); itemsDeleted++; @@ -2967,13 +2970,14 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) case PCB_GROUP_T: dupe_item = static_cast( orig_item )->DeepDuplicate(); - dupe_item->RunOnDescendants( + dupe_item->RunOnChildren( [&]( BOARD_ITEM* aItem ) { aItem->ClearSelected(); new_items.push_back( aItem ); commit.Add( aItem ); - } ); + }, + RECURSE_MODE::RECURSE ); dupe_item->ClearSelected(); new_items.push_back( dupe_item ); diff --git a/pcbnew/tools/edit_tool_move_fct.cpp b/pcbnew/tools/edit_tool_move_fct.cpp index a3bbcd1bac..998636d7b9 100644 --- a/pcbnew/tools/edit_tool_move_fct.cpp +++ b/pcbnew/tools/edit_tool_move_fct.cpp @@ -585,11 +585,12 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit item->SetFlags( IS_MOVING ); - static_cast( item )->RunOnDescendants( + static_cast( item )->RunOnChildren( [&]( BOARD_ITEM* bItem ) { 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 ) FPs.push_back( static_cast( item ) ); - item->RunOnDescendants( + item->RunOnChildren( [&]( BOARD_ITEM* descendent ) { if( descendent->Type() == PCB_FOOTPRINT_T ) FPs.push_back( static_cast( descendent ) ); - } ); + }, + RECURSE_MODE::RECURSE ); } } diff --git a/pcbnew/tools/multichannel_tool.cpp b/pcbnew/tools/multichannel_tool.cpp index f88b405037..2d27079952 100644 --- a/pcbnew/tools/multichannel_tool.cpp +++ b/pcbnew/tools/multichannel_tool.cpp @@ -194,7 +194,7 @@ bool MULTICHANNEL_TOOL::findOtherItemsInRuleArea( ZONE* aRuleArea, std::setRunOnDescendants( + group->RunOnChildren( [&]( BOARD_ITEM* aItem ) { if( aItem->IsType( { PCB_ZONE_T, PCB_SHAPE_T, PCB_DIMENSION_T } ) ) @@ -205,7 +205,8 @@ bool MULTICHANNEL_TOOL::findOtherItemsInRuleArea( ZONE* aRuleArea, std::setAsDouble() == 0.0 ) addGroup = false; } - } ); + }, + RECURSE_MODE::RECURSE ); if( addGroup ) aItems.insert( group ); @@ -1019,7 +1020,7 @@ bool MULTICHANNEL_TOOL::pruneExistingGroups( COMMIT& aCommit, if( refItem->Type() == PCB_GROUP_T ) pending.push_back( static_cast(refItem) ); - + for( BOARD_ITEM* testItem : aItemsToRemove ) { if( refItem->m_Uuid == testItem->m_Uuid ) diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 43bd5230f7..1e6b94f0a4 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -1439,11 +1439,12 @@ bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, std::vector( item->m_Uuid ) = KIID(); - item->RunOnDescendants( + item->RunOnChildren( []( BOARD_ITEM* aChild ) { const_cast( aChild->m_Uuid ) = KIID(); - } ); + }, + RECURSE_MODE::RECURSE ); // 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 @@ -2046,7 +2047,7 @@ int PCB_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) // Use dynamic_cast to include PCB_GENERATORs. else if( PCB_GROUP* group = dynamic_cast( aItem ) ) { - group->RunOnChildren( accumulateTrackLength ); + group->RunOnChildren( accumulateTrackLength, RECURSE_MODE::NO_RECURSE ); } else { @@ -2088,7 +2089,7 @@ int PCB_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) if( BOARD_ITEM* boardItem = dynamic_cast( aItem ) ) { - boardItem->RunOnChildren( accumulateArea ); + boardItem->RunOnChildren( accumulateArea, RECURSE_MODE::NO_RECURSE ); for( PCB_LAYER_ID layer : LSET( boardItem->GetLayerSet() & enabledCopper ) ) { diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index 5dea32b21c..7218f9e75a 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -911,11 +911,12 @@ PCB_GRID_HELPER::queryVisible( const BOX2I& aArea, const std::vectorRunOnDescendants( + aItem->RunOnChildren( [&]( BOARD_ITEM* aChild ) { skipItem( aChild ); - } ); + }, + RECURSE_MODE::RECURSE ); }; for( BOARD_ITEM* item : aSkip ) diff --git a/pcbnew/tools/pcb_selection.cpp b/pcbnew/tools/pcb_selection.cpp index 8958d1e8c0..7733a8d13f 100644 --- a/pcbnew/tools/pcb_selection.cpp +++ b/pcbnew/tools/pcb_selection.cpp @@ -98,7 +98,8 @@ const std::vector PCB_SELECTION::updateDrawList() const boardItem->RunOnChildren( [&]( BOARD_ITEM* childItem ) { addItem( childItem ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } }; diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 69bb4454bd..8f885d8272 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -614,7 +614,8 @@ void PCB_SELECTION_TOOL::EnterGroup() m_enteredGroup->RunOnChildren( [&]( BOARD_ITEM* titem ) { select( titem ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); @@ -727,12 +728,13 @@ PCB_SELECTION& PCB_SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aCl BOARD_ITEM* boardItem = static_cast( item ); bool lockedDescendant = false; - boardItem->RunOnDescendants( + boardItem->RunOnChildren( [&]( BOARD_ITEM* curr_item ) { if( curr_item->IsLocked() ) lockedDescendant = true; - } ); + }, + RECURSE_MODE::RECURSE ); if( boardItem->IsLocked() || lockedDescendant ) lockedItems.push_back( boardItem ); @@ -3161,8 +3163,8 @@ void PCB_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, bool aUs if( aItem->IsBOARD_ITEM() ) { BOARD_ITEM* boardItem = static_cast( aItem ); - boardItem->RunOnDescendants( std::bind( &PCB_SELECTION_TOOL::highlightInternal, this, _1, - aMode, aUsingOverlay ) ); + boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::highlightInternal, this, _1, 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() ) { BOARD_ITEM* boardItem = static_cast( aItem ); - boardItem->RunOnDescendants( std::bind( &PCB_SELECTION_TOOL::unhighlightInternal, this, _1, - aMode, aUsingOverlay ) ); + boardItem->RunOnChildren( std::bind( &PCB_SELECTION_TOOL::unhighlightInternal, this, _1, aMode, aUsingOverlay ), + RECURSE_MODE::RECURSE ); } } @@ -3223,12 +3225,13 @@ bool PCB_SELECTION_TOOL::selectionContains( const VECTOR2I& aPoint ) const if( PCB_GROUP* group = dynamic_cast( item ) ) { - group->RunOnDescendants( + group->RunOnChildren( [&]( BOARD_ITEM* aItem ) { if( aItem->HitTest( aPoint, margin ) ) found = true; - } ); + }, + RECURSE_MODE::RECURSE ); } if( found ) diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 8a328b72df..2abe5dfa74 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -82,7 +82,8 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool, // footprints have more drawable parts if( FOOTPRINT* fp = dynamic_cast( 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 ); } }; diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index c89b13c49d..6269c9800a 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -465,7 +465,8 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) group->RunOnChildren( [&]( BOARD_ITEM* child ) { child->SetParentGroup( group ); - } ); + }, + RECURSE_MODE::NO_RECURSE ); } view->Add( item ); @@ -642,11 +643,12 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) for( FOOTPRINT* footprint : GetBoard()->Footprints() ) { - footprint->RunOnDescendants( + footprint->RunOnChildren( [&]( BOARD_ITEM* item ) { checkHatching( item ); - } ); + }, + RECURSE_MODE::RECURSE ); } if( added_items.size() > 0 || deleted_items.size() > 0 || changed_items.size() > 0 ) diff --git a/qa/qa_utils/pcb_test_selection_tool.cpp b/qa/qa_utils/pcb_test_selection_tool.cpp index 7f4739f6f7..095edb6646 100644 --- a/qa/qa_utils/pcb_test_selection_tool.cpp +++ b/qa/qa_utils/pcb_test_selection_tool.cpp @@ -126,8 +126,9 @@ void PCB_TEST_SELECTION_TOOL::highlightInternal( EDA_ITEM* aItem, int aMode, boo if( aItem->IsBOARD_ITEM() ) { BOARD_ITEM* boardItem = static_cast( aItem ); - boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, - std::placeholders::_1, aMode, aUsingOverlay ) ); + boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::highlightInternal, this, std::placeholders::_1, + 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() ) { BOARD_ITEM* boardItem = static_cast( aItem ); - boardItem->RunOnDescendants( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, - std::placeholders::_1, aMode, aUsingOverlay ) ); + boardItem->RunOnChildren( std::bind( &PCB_TEST_SELECTION_TOOL::unhighlightInternal, this, std::placeholders::_1, + aMode, aUsingOverlay ), + RECURSE_MODE::RECURSE ); } }