diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index 36f4e5be57..42c91e78e7 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -521,6 +521,45 @@ void BOARD::Move( const VECTOR2I& aMoveVector ) // overload } +void BOARD::RunOnDescendants( const std::function& aFunction, + int aDepth ) const +{ + try + { + for( PCB_TRACK* track : m_tracks ) + aFunction( track ); + + for( ZONE* zone : m_zones ) + aFunction( zone ); + + for( PCB_MARKER* marker : m_markers ) + aFunction( marker ); + + for( FOOTPRINT* footprint : m_footprints ) + { + aFunction( footprint ); + footprint->RunOnDescendants( aFunction, aDepth + 1 ); + } + + for( PCB_GROUP* group : m_groups ) + { + aFunction( group ); + group->RunOnDescendants( aFunction, aDepth + 1 ); + } + + 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" ) ); + } +} + + TRACKS BOARD::TracksInNet( int aNetCode ) { TRACKS ret; diff --git a/pcbnew/board.h b/pcbnew/board.h index 82ced675b5..d7863af583 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -390,6 +390,9 @@ public: void Move( const VECTOR2I& aMoveVector ) override; + void RunOnDescendants( const std::function& aFunction, + int aDepth = 0 ) const override; + void SetFileFormatVersionAtLoad( int aVersion ) { m_fileFormatVersionAtLoad = aVersion; } int GetFileFormatVersionAtLoad() const { return m_fileFormatVersionAtLoad; }