From e4efe212d6f9f017107a97a0d536e0612f2bedc6 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Dec 2013 13:39:11 +0100 Subject: [PATCH] Added MODULE::RunOnChildren(). --- pcbnew/basepcbframe.cpp | 29 +++-------------------------- pcbnew/class_module.cpp | 13 +++++++++++++ pcbnew/class_module.h | 9 +++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 22983f9063..95b356d915 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -200,46 +200,25 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const KIGFX::VIEW* view = m_galCanvas->GetView(); view->Clear(); - // All of PCB drawing elements should be added to the VIEW - // in order to be displayed + // All the PCB drawable items should be added to the VIEW in order to be displayed // Load zones for( int i = 0; i < aBoard->GetAreaCount(); ++i ) - { view->Add( (KIGFX::VIEW_ITEM*) ( aBoard->GetArea( i ) ) ); - } // Load drawings for( BOARD_ITEM* drawing = aBoard->m_Drawings; drawing; drawing = drawing->Next() ) - { view->Add( drawing ); - } // Load tracks for( TRACK* track = aBoard->m_Track; track; track = track->Next() ) - { view->Add( track ); - } // Load modules and its additional elements for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) { - // Load module's pads - for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() ) - { - view->Add( pad ); - } - - // Load module's drawing (mostly silkscreen) - for( BOARD_ITEM* drawing = module->GraphicalItems().GetFirst(); drawing; - drawing = drawing->Next() ) - { - view->Add( drawing ); - } - - // Load module's texts (name and value) - view->Add( &module->Reference() ); - view->Add( &module->Value() ); + // Load items that belong to a module + module->RunOnChildren( std::bind1st( std::mem_fun( &KIGFX::VIEW::Add ), view ) ); // Add the module itself view->Add( module ); @@ -247,9 +226,7 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const // Segzones (equivalent of ZONE_CONTAINER for legacy boards) for( SEGZONE* zone = aBoard->m_Zone; zone; zone = zone->Next() ) - { view->Add( zone ); - } // Add an entry for the worksheet layout KIGFX::WORKSHEET_VIEWITEM* worksheet = new KIGFX::WORKSHEET_VIEWITEM( diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 9694607a39..1885eb16c9 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -728,6 +728,19 @@ EDA_ITEM* MODULE::Clone() const } +void MODULE::RunOnChildren( boost::function aFunction ) +{ + for( D_PAD* pad = m_Pads.GetFirst(); pad; pad = pad->Next() ) + aFunction( static_cast( pad ) ); + + for( BOARD_ITEM* drawing = m_Drawings.GetFirst(); drawing; drawing = drawing->Next() ) + aFunction( drawing ); + + aFunction( static_cast( m_Reference ) ); + aFunction( static_cast( m_Value ) ); +} + + void MODULE::ViewUpdate( int aUpdateFlags ) { if( !m_view ) diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index a1564db05e..dbea0179d9 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -41,6 +41,7 @@ #include #include "zones.h" +#include class LINE_READER; class EDA_3D_CANVAS; @@ -447,6 +448,14 @@ public: EDA_ITEM* Clone() const; + /** + * Function RunOnChildren + * + * Invokes a function on all BOARD_ITEMs that belong to the module (pads, drawings, texts). + * @param aFunction is the function to be invoked. + */ + void RunOnChildren( boost::function aFunction ); + /// @copydoc VIEW_ITEM::ViewUpdate() void ViewUpdate( int aUpdateFlags );