From d1877d7c1b531dee2f4e35304a1d6b33a34c5fff Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 30 May 2019 17:15:57 -0700 Subject: [PATCH] Moving modules from DLIST to std::deque --- 3d-viewer/3d_canvas/create_layer_items.cpp | 12 ++-- .../c3d_render_createscene_ogl_legacy.cpp | 7 +-- .../c3d_render_ogl_legacy.cpp | 17 ++---- .../c3d_render_createscene.cpp | 8 +-- cvpcb/display_footprints_frame.cpp | 16 +++-- pcbnew/board_commit.cpp | 4 +- ...board_items_to_polygon_shape_transform.cpp | 2 +- pcbnew/board_netlist_updater.cpp | 8 +-- pcbnew/build_BOM_from_board.cpp | 8 +-- pcbnew/class_board.cpp | 24 ++++---- pcbnew/class_board.h | 59 ++++++++++++++----- pcbnew/class_module.h | 3 - pcbnew/dialogs/dialog_exchange_footprints.cpp | 19 +++--- pcbnew/dialogs/dialog_find.cpp | 2 +- pcbnew/dialogs/dialog_gendrill.cpp | 2 +- pcbnew/dialogs/dialog_global_deletion.cpp | 5 +- pcbnew/dialogs/dialog_netlist.cpp | 2 +- pcbnew/drc.cpp | 31 +++++----- pcbnew/drc/courtyard_overlap.cpp | 18 ++++-- pcbnew/exporters/export_d356.cpp | 3 +- .../export_footprint_associations.cpp | 2 +- pcbnew/exporters/export_gencad.cpp | 13 ++-- pcbnew/exporters/export_idf.cpp | 2 +- pcbnew/exporters/export_vrml.cpp | 4 +- pcbnew/exporters/gen_footprints_placefile.cpp | 6 +- .../exporters/gendrill_file_writer_base.cpp | 2 +- pcbnew/footprint_edit_frame.cpp | 39 ++++++------ pcbnew/footprint_editor_utils.cpp | 45 +++++++------- pcbnew/footprint_libraries_utils.cpp | 15 +++-- pcbnew/footprint_viewer_frame.cpp | 11 ++-- pcbnew/footprint_wizard_frame.cpp | 2 +- pcbnew/footprint_wizard_frame_functions.cpp | 3 +- pcbnew/fp_tree_synchronizing_adapter.cpp | 12 +++- pcbnew/import_gfx/dialog_import_gfx.cpp | 2 +- pcbnew/initpcb.cpp | 5 +- pcbnew/kicad_clipboard.cpp | 2 +- pcbnew/kicad_plugin.cpp | 4 +- pcbnew/load_select_footprint.cpp | 30 ++++------ pcbnew/menubar_footprint_editor.cpp | 4 +- pcbnew/netinfo_list.cpp | 2 +- pcbnew/netlist.cpp | 14 ++--- pcbnew/pcb_base_frame.cpp | 2 +- pcbnew/pcb_draw_panel_gal.cpp | 2 +- pcbnew/pcb_edit_frame.cpp | 8 +-- pcbnew/pcb_legacy_draw_utils.cpp | 2 +- pcbnew/plot_board_layers.cpp | 16 ++--- pcbnew/plot_brditems_plotter.cpp | 4 +- pcbnew/router/pns_kicad_iface.cpp | 2 +- .../specctra_export.cpp | 4 +- pcbnew/swig/pcbnew_action_plugins.cpp | 4 +- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/footprint_editor_tools.cpp | 12 ++-- pcbnew/tools/pad_tool.cpp | 4 +- pcbnew/tools/pcb_tool_base.h | 5 +- pcbnew/tools/pcbnew_control.cpp | 4 +- pcbnew/tools/selection_tool.cpp | 3 +- pcbnew/undo_redo.cpp | 21 +++---- pcbnew/zone_filler.cpp | 2 +- 58 files changed, 292 insertions(+), 274 deletions(-) diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index ac29b8273d..6ded7deb2e 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -488,7 +488,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) // Add holes of modules // ///////////////////////////////////////////////////////////////////////// - for( const MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { const D_PAD* pad = module->PadsList(); @@ -522,7 +522,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) // Add contours of the pad holes (pads can be Circle or Segment holes) // ///////////////////////////////////////////////////////////////////////// - for( const MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { const D_PAD* pad = module->PadsList(); @@ -566,7 +566,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) CBVHCONTAINER2D *layerContainer = m_layers_container2D[curr_layer_id]; // ADD PADS - for( const MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { // Note: NPTH pads are not drawn on copper layers when the pad // has same shape as its hole @@ -603,7 +603,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) SHAPE_POLY_SET *layerPoly = m_layers_poly[curr_layer_id]; // ADD PADS - for( const MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { // Construct polys // ///////////////////////////////////////////////////////////// @@ -993,7 +993,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) // Add modules tech layers - objects // ///////////////////////////////////////////////////////////////////// - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) ) { @@ -1020,7 +1020,7 @@ void CINFO3D_VISU::createLayers( REPORTER *aStatusTextReporter ) // Add modules tech layers - contours // ///////////////////////////////////////////////////////////////////// - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { if( (curr_layer_id == F_SilkS) || (curr_layer_id == B_SilkS) ) { diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp index 239b8ae004..a83c9c51d3 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp @@ -800,9 +800,7 @@ void C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads() tht_inner_holes_poly.RemoveAllContours(); // Insert pads holes (vertical cylinders) - for( const MODULE* module = m_settings.GetBoard()->m_Modules; - module; - module = module->Next() ) + for( const auto module : m_settings.GetBoard()->Modules() ) { for( const D_PAD* pad = module->PadsList(); pad; pad = pad->Next() ) { @@ -907,8 +905,7 @@ void C3D_RENDER_OGL_LEGACY::load_3D_models( REPORTER *aStatusTextReporter ) return; // Go for all modules - for( const MODULE* module = m_settings.GetBoard()->m_Modules; - module; module = module->Next() ) + for( auto module : m_settings.GetBoard()->Modules() ) { if( !module->Models().empty() ) { diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp index 6f427841c1..5678e47074 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_ogl_legacy.cpp @@ -980,18 +980,13 @@ void C3D_RENDER_OGL_LEGACY::render_3D_models( bool aRenderTopOrBot, bool aRenderTransparentOnly ) { // Go for all modules - if( m_settings.GetBoard()->m_Modules.GetCount() ) + for( auto module : m_settings.GetBoard()->Modules() ) { - for( const MODULE* module = m_settings.GetBoard()->m_Modules; - module; - module = module->Next() ) - { - if( !module->Models().empty() ) - if( m_settings.ShouldModuleBeDisplayed( (MODULE_ATTR_T)module->GetAttributes() ) ) - if( ( aRenderTopOrBot && !module->IsFlipped()) || - (!aRenderTopOrBot && module->IsFlipped()) ) - render_3D_module( module, aRenderTransparentOnly ); - } + if( !module->Models().empty() ) + if( m_settings.ShouldModuleBeDisplayed( (MODULE_ATTR_T) module->GetAttributes() ) ) + if( ( aRenderTopOrBot && !module->IsFlipped() ) + || ( !aRenderTopOrBot && module->IsFlipped() ) ) + render_3D_module( module, aRenderTransparentOnly ); } } diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp index 2910ccdf7e..f008aedd9b 100644 --- a/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp +++ b/3d-viewer/3d_rendering/3d_render_raytracing/c3d_render_createscene.cpp @@ -1183,9 +1183,7 @@ void C3D_RENDER_RAYTRACING::add_3D_vias_and_pads_to_container() } // Insert pads holes (vertical cylinders) - for( const MODULE* module = m_settings.GetBoard()->m_Modules; - module; - module = module->Next() ) + for( auto module : m_settings.GetBoard()->Modules() ) { for( const D_PAD* pad = module->PadsList(); pad; pad = pad->Next() ) if( pad->GetAttribute () != PAD_ATTRIB_HOLE_NOT_PLATED ) @@ -1199,9 +1197,7 @@ void C3D_RENDER_RAYTRACING::add_3D_vias_and_pads_to_container() void C3D_RENDER_RAYTRACING::load_3D_models() { // Go for all modules - for( const MODULE* module = m_settings.GetBoard()->m_Modules; - module; - module = module->Next() ) + for( auto module : m_settings.GetBoard()->Modules() ) { if( (!module->Models().empty() ) && m_settings.ShouldModuleBeDisplayed( (MODULE_ATTR_T)module->GetAttributes() ) ) diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 6b977b62c9..0a696331e3 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -413,8 +413,10 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() MODULE* module = nullptr; const FOOTPRINT_INFO* module_info = nullptr; - if( GetBoard()->m_Modules.GetCount() ) - GetBoard()->m_Modules.DeleteAll(); + for( auto it = GetBoard()->Modules().begin(); it != GetBoard()->Modules().end(); it++ ) + delete *it; + + GetBoard()->Modules().clear(); wxString footprintName = parentframe->GetSelectedFootprint(); @@ -436,7 +438,7 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() } if( module ) - GetBoard()->m_Modules.PushBack( module ); + GetBoard()->Modules().push_back( module ); if( module_info ) SetStatusText( wxString::Format( _( "Lib: %s" ), module_info->GetLibNickname() ), 0 ); @@ -471,7 +473,7 @@ void DISPLAY_FOOTPRINTS_FRAME::updateView() void DISPLAY_FOOTPRINTS_FRAME::UpdateMsgPanel() { - MODULE* footprint = GetBoard()->m_Modules; + MODULE* footprint = GetBoard()->GetFirstModule(); MSG_PANEL_ITEMS items; if( footprint ) @@ -515,7 +517,9 @@ void DISPLAY_FOOTPRINTS_FRAME::SyncMenusAndToolbars() */ void BOARD::Print( PCB_BASE_FRAME* aFrame, wxDC* aDC, const wxPoint& aOffset ) { - if( m_Modules ) - m_Modules->Print( aFrame, aDC ); + if( !m_modules.empty() ) + { + GetFirstModule()->Print( aFrame, aDC ); + } } diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 15db206493..54954693a6 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -129,10 +129,10 @@ void BOARD_COMMIT::Push( const wxString& aMessage, bool aCreateUndoEntry, bool a // modules inside modules are not supported yet wxASSERT( boardItem->Type() != PCB_MODULE_T ); - boardItem->SetParent( board->m_Modules.GetFirst() ); + boardItem->SetParent( board->Modules().front() ); if( !( changeFlags & CHT_DONE ) ) - board->m_Modules->Add( boardItem ); + board->Modules().front()->Add( boardItem ); } view->Add( boardItem ); diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 8c819ff97f..e07cfec434 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -83,7 +83,7 @@ void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_ } // convert pads - for( MODULE* module = m_Modules; module != NULL; module = module->Next() ) + for( auto module : m_modules ) { module->TransformPadsShapesWithClearanceToPolygon( aLayer, aOutlines, 0 ); diff --git a/pcbnew/board_netlist_updater.cpp b/pcbnew/board_netlist_updater.cpp index bb4d344aff..1675dd8971 100644 --- a/pcbnew/board_netlist_updater.cpp +++ b/pcbnew/board_netlist_updater.cpp @@ -530,12 +530,10 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist ) bool BOARD_NETLIST_UPDATER::deleteUnusedComponents( NETLIST& aNetlist ) { wxString msg; - MODULE* nextModule; const COMPONENT* component; - for( MODULE* module = m_board->m_Modules; module != NULL; module = nextModule ) + for( auto module : m_board->Modules() ) { - nextModule = module->Next(); if( m_lookupByTimestamp ) component = aNetlist.GetComponentByTimeStamp( module->GetPath() ); @@ -691,7 +689,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) m_errorCount = 0; m_warningCount = 0; m_newFootprintsCount = 0; - MODULE* lastPreexistingFootprint = m_board->m_Modules.GetLast(); + MODULE* lastPreexistingFootprint = m_board->Modules().back(); cacheCopperZoneConnections(); @@ -717,7 +715,7 @@ bool BOARD_NETLIST_UPDATER::UpdateNetlist( NETLIST& aNetlist ) component->GetFPID().Format().wx_str() ); m_reporter->Report( msg, REPORTER::RPT_INFO ); - for( MODULE* footprint = m_board->m_Modules; footprint; footprint = footprint->Next() ) + for( auto footprint : m_board->Modules() ) { bool match = false; diff --git a/pcbnew/build_BOM_from_board.cpp b/pcbnew/build_BOM_from_board.cpp index 99f11c80a2..b2e101814b 100644 --- a/pcbnew/build_BOM_from_board.cpp +++ b/pcbnew/build_BOM_from_board.cpp @@ -77,10 +77,9 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent ) { wxFileName fn; FILE* fp_bom; - MODULE* module = GetBoard()->m_Modules; wxString msg; - if( module == NULL ) + if( GetBoard()->Modules().empty() ) { DisplayError( this, _( "Cannot export BOM: there are no footprints in the PCB" ) ); return; @@ -126,7 +125,7 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent ) CmpList::iterator iter; int i = 1; - while( module != NULL ) + for( auto module : GetBoard()->Modules() ) { bool valExist = false; @@ -157,9 +156,6 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent ) comp->m_CmpCount = 1; list.Append( comp ); } - - // increment module - module = module->Next(); } // Print list. Also delete temporary created objects. diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index b8ef1e105d..27ef2d57c0 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -902,9 +902,9 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) case PCB_MODULE_T: if( aMode == ADD_APPEND ) - m_Modules.PushBack( (MODULE*) aBoardItem ); + m_modules.push_back( (MODULE*) aBoardItem ); else - m_Modules.PushFront( (MODULE*) aBoardItem ); + m_modules.push_front( (MODULE*) aBoardItem ); break; @@ -977,7 +977,8 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem ) break; case PCB_MODULE_T: - m_Modules.Remove( (MODULE*) aBoardItem ); + m_modules.erase( std::remove_if( m_modules.begin(), m_modules.end(), + [aBoardItem]( BOARD_ITEM* aItem ) { return aItem == aBoardItem; } ) ); break; case PCB_TRACE_T: @@ -1123,7 +1124,7 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const if( !aBoardEdgesOnly ) { // Check modules - for( MODULE* module = m_Modules; module; module = module->Next() ) + for( auto module : m_modules ) { if( !( module->GetLayerSet() & visible ).any() ) continue; @@ -1240,7 +1241,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s case PCB_MODULE_EDGE_T: // this calls MODULE::Visit() on each module. - result = IterateForward( m_Modules, inspector, testData, p ); + result = IterateForward( m_modules, inspector, testData, p ); // skip over any types handled in the above call. for( ; ; ) @@ -1434,7 +1435,7 @@ MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeSt { if( aSearchByTimeStamp ) { - for( MODULE* module = m_Modules; module; module = module->Next() ) + for( auto module : m_modules ) { if( aRefOrTimeStamp.CmpNoCase( module->GetPath() ) == 0 ) return module; @@ -1605,7 +1606,7 @@ D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerSet ) if( !aLayerSet.any() ) aLayerSet = LSET::AllCuMask(); - for( MODULE* module = m_Modules; module; module = module->Next() ) + for( auto module : m_modules ) { D_PAD* pad = NULL; @@ -2137,14 +2138,13 @@ TRACK* BOARD::MarkTrace( TRACK* aTrackList, TRACK* aTrace, int* aCount, MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer, bool aVisibleOnly, bool aIgnoreLocked ) { - MODULE* pt_module; MODULE* module = NULL; MODULE* alt_module = NULL; int min_dim = 0x7FFFFFFF; int alt_min_dim = 0x7FFFFFFF; bool current_layer_back = IsBackLayer( aActiveLayer ); - for( pt_module = m_Modules; pt_module; pt_module = pt_module->Next() ) + for( auto pt_module : m_modules ) { // is the ref point within the module's bounds? if( !pt_module->HitTest( aPosition ) ) @@ -2205,7 +2205,7 @@ MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer BOARD_CONNECTED_ITEM* BOARD::GetLockPoint( const wxPoint& aPosition, LSET aLayerSet ) { - for( MODULE* module = m_Modules; module; module = module->Next() ) + for( auto module : m_modules ) { D_PAD* pad = module->GetPad( aPosition, aLayerSet ); @@ -2497,9 +2497,9 @@ D_PAD* BOARD::GetPad( unsigned aIndex ) const { unsigned count = 0; - for( MODULE* mod = m_Modules; mod ; mod = mod->Next() ) // FIXME: const DLIST_ITERATOR + for( auto mod : m_modules ) { - for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() ) + for( auto pad : mod->Pads() ) { if( count == aIndex ) return pad; diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 5e3ee965c3..394ed151a6 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -34,17 +34,18 @@ #include #include -#include // PAGE_INFO -#include -#include +#include +#include +#include #include #include -#include +#include // PAGE_INFO +#include +#include +#include +#include #include #include -#include -#include -#include #include @@ -158,10 +159,11 @@ protected: }; -DECL_VEC_FOR_SWIG(MARKERS, MARKER_PCB*) -DECL_VEC_FOR_SWIG(ZONE_CONTAINERS, ZONE_CONTAINER*) -DECL_VEC_FOR_SWIG(TRACKS, TRACK*) -DECL_DEQ_FOR_SWIG(DRAWINGS, BOARD_ITEM*) +DECL_VEC_FOR_SWIG( MARKERS, MARKER_PCB* ) +DECL_VEC_FOR_SWIG( ZONE_CONTAINERS, ZONE_CONTAINER* ) +DECL_VEC_FOR_SWIG( TRACKS, TRACK* ) +DECL_DEQ_FOR_SWIG( DRAWINGS, BOARD_ITEM* ) +DECL_DEQ_FOR_SWIG( MODULES, MODULE* ) /** @@ -182,6 +184,9 @@ private: /// BOARD_ITEMs for drawings on the board, owned by pointer. DRAWINGS m_drawings; + /// MODULES for components on the board, owned by pointer. + MODULES m_modules; + /// edge zone descriptors, owned by pointer. ZONE_CONTAINERS m_ZoneDescriptorList; @@ -245,11 +250,17 @@ public: public: - DLIST m_Modules; // linked list of MODULEs DLIST m_Track; // linked list of TRACKs and VIAs DLIST_ITERATOR_WRAPPER Tracks() { return DLIST_ITERATOR_WRAPPER(m_Track); } - DLIST_ITERATOR_WRAPPER Modules() { return DLIST_ITERATOR_WRAPPER(m_Modules); } + MODULES& Modules() + { + return m_modules; + } + const MODULES& Modules() const + { + return m_modules; + } DRAWINGS& Drawings() { return m_drawings; } ZONE_CONTAINERS& Zones() { return m_ZoneDescriptorList; } const std::vector AllConnectedItems(); @@ -265,7 +276,7 @@ public: bool IsEmpty() const { - return m_drawings.empty() && m_Modules.GetCount() == 0 && m_Track.GetCount() == 0; + return m_drawings.empty() && m_modules.empty() && m_Track.GetCount() == 0; } void Move( const wxPoint& aMoveVector ) override; @@ -277,6 +288,26 @@ public: void Remove( BOARD_ITEM* aBoardItem ) override; + /** + * Gets the first module in the list (used in footprint viewer/editor) or NULL if none + * @return first module or null pointer + */ + MODULE* GetFirstModule() const + { + return m_modules.empty() ? nullptr : m_modules.front(); + } + + /** + * Removes all modules from the deque and frees the memory associated with them + */ + void DeleteAllModules() + { + for( MODULE* mod : m_modules ) + delete mod; + + m_modules.clear(); + } + BOARD_ITEM* GetItem( void* aWeakReference ); BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard = false ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 599b7ee014..e8bbca9981 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -119,9 +119,6 @@ public: return aItem && PCB_MODULE_T == aItem->Type(); } - MODULE* Next() const { return static_cast( Pnext ); } - MODULE* Back() const { return static_cast( Pback ); } - ///> @copydoc BOARD_ITEM_CONTAINER::Add() void Add( BOARD_ITEM* aItem, ADD_MODE aMode = ADD_INSERT ) override; diff --git a/pcbnew/dialogs/dialog_exchange_footprints.cpp b/pcbnew/dialogs/dialog_exchange_footprints.cpp index 0038c5eb2f..3f638de2f8 100644 --- a/pcbnew/dialogs/dialog_exchange_footprints.cpp +++ b/pcbnew/dialogs/dialog_exchange_footprints.cpp @@ -284,13 +284,11 @@ void DIALOG_EXCHANGE_FOOTPRINTS::OnApplyClicked( wxCommandEvent& event ) bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules() { - MODULE* Module; - MODULE* PtBack; bool change = false; LIB_ID newFPID; wxString value; - if( !m_parent->GetBoard()->m_Modules ) + if( m_parent->GetBoard()->Modules().empty() ) return false; if( !m_updateMode ) @@ -303,26 +301,23 @@ bool DIALOG_EXCHANGE_FOOTPRINTS::processMatchingModules() /* The change is done from the last module because processModule() modifies the last item * in the list. - * Note: for the first module in chain (the last here), Module->Back() points to the board - * or is NULL. */ - Module = m_parent->GetBoard()->m_Modules.GetLast(); - - for( ; Module && Module->Type() == PCB_MODULE_T; Module = PtBack ) + for( auto it = m_parent->GetBoard()->Modules().rbegin(); + it != m_parent->GetBoard()->Modules().rend(); it++ ) { - PtBack = Module->Back(); + auto mod = *it; - if( !isMatch( Module ) ) + if( !isMatch( mod ) ) continue; if( m_updateMode ) { - if( processModule( Module, Module->GetFPID()) ) + if( processModule( mod, mod->GetFPID() ) ) change = true; } else { - if( processModule( Module, newFPID ) ) + if( processModule( mod, newFPID ) ) change = true; } } diff --git a/pcbnew/dialogs/dialog_find.cpp b/pcbnew/dialogs/dialog_find.cpp index d56f7e33b2..1446d682a6 100644 --- a/pcbnew/dialogs/dialog_find.cpp +++ b/pcbnew/dialogs/dialog_find.cpp @@ -99,7 +99,7 @@ void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent ) int count = 0; - for( MODULE* module = parent->GetBoard()->m_Modules; module; module = module->Next() ) + for( auto module : parent->GetBoard()->Modules() ) { if( WildCompareString( searchString, module->GetReference().GetData(), false ) ) { diff --git a/pcbnew/dialogs/dialog_gendrill.cpp b/pcbnew/dialogs/dialog_gendrill.cpp index a431bface8..8364320e1c 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -153,7 +153,7 @@ void DIALOG_GENDRILL::InitDisplayParams() m_microViasCount = 0; m_blindOrBuriedViasCount = 0; - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { for( D_PAD* pad = module->PadsList(); pad != NULL; pad = pad->Next() ) { diff --git a/pcbnew/dialogs/dialog_global_deletion.cpp b/pcbnew/dialogs/dialog_global_deletion.cpp index 4195f40ba3..5321fee26a 100644 --- a/pcbnew/dialogs/dialog_global_deletion.cpp +++ b/pcbnew/dialogs/dialog_global_deletion.cpp @@ -110,7 +110,6 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() BOARD* pcb = m_Parent->GetBoard(); BOARD_COMMIT commit( m_Parent ); - BOARD_ITEM* item; LSET layers_filter = LSET().set(); @@ -120,7 +119,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() if( delAll || m_DelZones->GetValue() ) { int area_index = 0; - item = pcb->GetArea( area_index ); + auto item = pcb->GetArea( area_index ); while( item ) { @@ -170,7 +169,7 @@ void DIALOG_GLOBAL_DELETION::AcceptPcbDelete() if( delAll || m_DelModules->GetValue() ) { - for( item = pcb->m_Modules; item; item = item->Next() ) + for( auto item : pcb->Modules() ) { bool del_fp = delAll; diff --git a/pcbnew/dialogs/dialog_netlist.cpp b/pcbnew/dialogs/dialog_netlist.cpp index 63c132791c..fc1cffbc4b 100644 --- a/pcbnew/dialogs/dialog_netlist.cpp +++ b/pcbnew/dialogs/dialog_netlist.cpp @@ -178,7 +178,7 @@ void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event ) void DIALOG_NETLIST::OnTestFootprintsClick( wxCommandEvent& event ) { - if( m_parent->GetBoard()->m_Modules == nullptr ) + if( m_parent->GetBoard()->GetFirstModule() == nullptr ) { DisplayInfoMessage( this, _( "No footprints." ) ); return; diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index e89465fa80..7380d452dc 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -1478,23 +1478,25 @@ void DRC::doFootprintOverlappingDrc() void DRC::TestFootprints( NETLIST& aNetlist, BOARD* aPCB, EDA_UNITS_T aUnits, DRC_LIST& aDRCList ) { - MODULE* module; - MODULE* nextModule; + auto mods = aPCB->Modules(); + + std::sort( mods.begin(), mods.end(), []( const MODULE* a, const MODULE* b ) { + return a->GetReference().CmpNoCase( b->GetReference() ); + } ); // Search for duplicate footprints. - for( module = aPCB->m_Modules; module != NULL; module = module->Next() ) + for( auto it = mods.begin(); it != mods.end(); it++ ) { - nextModule = module->Next(); + auto next_it = it + 1; - for( ; nextModule != NULL; nextModule = nextModule->Next() ) + if( next_it == mods.end() ) + break; + + if( ( *it )->GetReference().CmpNoCase( ( *next_it )->GetReference() ) == 0 ) { - if( module->GetReference().CmpNoCase( nextModule->GetReference() ) == 0 ) - { - aDRCList.emplace_back( new DRC_ITEM( aUnits, DRCE_DUPLICATE_FOOTPRINT, - module, module->GetPosition(), - nextModule, nextModule->GetPosition() ) ); - break; - } + aDRCList.emplace_back( new DRC_ITEM( aUnits, DRCE_DUPLICATE_FOOTPRINT, *it, + ( *it )->GetPosition(), *next_it, ( *next_it )->GetPosition() ) ); + break; } } @@ -1503,7 +1505,7 @@ void DRC::TestFootprints( NETLIST& aNetlist, BOARD* aPCB, EDA_UNITS_T aUnits, { COMPONENT* component = aNetlist.GetComponent( ii ); - module = aPCB->FindModuleByReference( component->GetReference() ); + auto module = aPCB->FindModuleByReference( component->GetReference() ); if( module == NULL ) { @@ -1516,9 +1518,8 @@ void DRC::TestFootprints( NETLIST& aNetlist, BOARD* aPCB, EDA_UNITS_T aUnits, } // Search for component footprints found on board but not in netlist. - for( module = aPCB->m_Modules; module != NULL; module = module->Next() ) + for( auto module : mods ) { - COMPONENT* component = aNetlist.GetComponentByReference( module->GetReference() ); if( component == NULL ) diff --git a/pcbnew/drc/courtyard_overlap.cpp b/pcbnew/drc/courtyard_overlap.cpp index 4b383cb171..addc13acfb 100644 --- a/pcbnew/drc/courtyard_overlap.cpp +++ b/pcbnew/drc/courtyard_overlap.cpp @@ -65,7 +65,7 @@ bool DRC_COURTYARD_OVERLAP::RunDRC( BOARD& aBoard ) const const DRC_MARKER_FACTORY& marker_factory = GetMarkerFactory(); // Update courtyard polygons, and test for missing courtyard definition: - for( MODULE* footprint = aBoard.m_Modules; footprint; footprint = footprint->Next() ) + for( auto footprint : aBoard.Modules() ) { wxPoint pos = footprint->GetPosition(); bool is_ok = footprint->BuildPolyCourtyard(); @@ -99,13 +99,17 @@ bool DRC_COURTYARD_OVERLAP::RunDRC( BOARD& aBoard ) const // Now test for overlapping on top layer: SHAPE_POLY_SET courtyard; // temporary storage of the courtyard of current footprint - for( MODULE* footprint = aBoard.m_Modules; footprint; footprint = footprint->Next() ) + for( auto it1 = aBoard.Modules().begin(); it1 != aBoard.Modules().end(); it1++ ) { + auto footprint = *it1; + if( footprint->GetPolyCourtyardFront().OutlineCount() == 0 ) continue; // No courtyard defined - for( MODULE* candidate = footprint->Next(); candidate; candidate = candidate->Next() ) + for( auto it2 = it1 + 1; it2 != aBoard.Modules().end(); it2++ ) { + auto candidate = *it2; + if( candidate->GetPolyCourtyardFront().OutlineCount() == 0 ) continue; // No courtyard defined @@ -132,13 +136,17 @@ bool DRC_COURTYARD_OVERLAP::RunDRC( BOARD& aBoard ) const } // Test for overlapping on bottom layer: - for( MODULE* footprint = aBoard.m_Modules; footprint; footprint = footprint->Next() ) + for( auto it1 = aBoard.Modules().begin(); it1 != aBoard.Modules().end(); it1++ ) { + auto footprint = *it1; + if( footprint->GetPolyCourtyardBack().OutlineCount() == 0 ) continue; // No courtyard defined - for( MODULE* candidate = footprint->Next(); candidate; candidate = candidate->Next() ) + for( auto it2 = it1 + 1; it2 != aBoard.Modules().end(); it2++ ) { + auto candidate = *it2; + if( candidate->GetPolyCourtyardBack().OutlineCount() == 0 ) continue; // No courtyard defined diff --git a/pcbnew/exporters/export_d356.cpp b/pcbnew/exporters/export_d356.cpp index 0788ca6586..2dc1c5188c 100644 --- a/pcbnew/exporters/export_d356.cpp +++ b/pcbnew/exporters/export_d356.cpp @@ -114,8 +114,7 @@ static void build_pad_testpoints( BOARD *aPcb, { wxPoint origin = aPcb->GetAuxOrigin(); - for( MODULE* module = aPcb->m_Modules; - module; module = module->Next() ) + for( auto module : aPcb->Modules() ) { for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() ) { diff --git a/pcbnew/exporters/export_footprint_associations.cpp b/pcbnew/exporters/export_footprint_associations.cpp index 576e7cae61..c8215d808f 100644 --- a/pcbnew/exporters/export_footprint_associations.cpp +++ b/pcbnew/exporters/export_footprint_associations.cpp @@ -40,7 +40,7 @@ bool RecreateCmpFile( BOARD * aBrd, const wxString& aFullCmpFileName ) fprintf( cmpFile, "Cmp-Mod V01 Created by PcbNew date = %s\n", TO_UTF8( DateAndTime() ) ); - for( MODULE* module = aBrd->m_Modules; module != NULL; module = module->Next() ) + for( auto module : aBrd->Modules() ) { fprintf( cmpFile, "\nBeginCmp\n" ); fprintf( cmpFile, "TimeStamp = %8.8lX\n", (unsigned long)module->GetTimeStamp() ); diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp index 637b26a0a8..1d42a6e8e3 100644 --- a/pcbnew/exporters/export_gencad.cpp +++ b/pcbnew/exporters/export_gencad.cpp @@ -311,9 +311,8 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent ) * these changes will be undone later */ BOARD* pcb = GetBoard(); - MODULE* module; - for( module = pcb->m_Modules; module; module = module->Next() ) + for( auto module : pcb->Modules() ) { module->SetFlag( 0 ); @@ -349,7 +348,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& aEvent ) fclose( file ); // Undo the footprints modifications (flipped footprints) - for( module = pcb->m_Modules; module; module = module->Next() ) + for( auto module : pcb->Modules() ) { if( module->GetFlag() ) { @@ -732,7 +731,6 @@ static size_t hashModule( const MODULE* aModule ) */ static void CreateShapesSection( FILE* aFile, BOARD* aPcb ) { - MODULE* module; D_PAD* pad; const char* layer; wxString pinname; @@ -741,7 +739,7 @@ static void CreateShapesSection( FILE* aFile, BOARD* aPcb ) fputs( "$SHAPES\n", aFile ); - for( module = aPcb->m_Modules; module; module = module->Next() ) + for( auto module : aPcb->Modules() ) { if( !individualShapes ) { @@ -854,7 +852,7 @@ static void CreateComponentsSection( FILE* aFile, BOARD* aPcb ) int cu_count = aPcb->GetCopperLayerCount(); - for( MODULE* module = aPcb->m_Modules; module; module = module->Next() ) + for( auto module : aPcb->Modules() ) { const char* mirror; const char* flip; @@ -929,7 +927,6 @@ static void CreateSignalsSection( FILE* aFile, BOARD* aPcb ) wxString msg; NETINFO_ITEM* net; D_PAD* pad; - MODULE* module; int NbNoConn = 1; fputs( "$SIGNALS\n", aFile ); @@ -951,7 +948,7 @@ static void CreateSignalsSection( FILE* aFile, BOARD* aPcb ) fputs( TO_UTF8( msg ), aFile ); fputs( "\n", aFile ); - for( module = aPcb->m_Modules; module; module = module->Next() ) + for( auto module : aPcb->Modules() ) { for( pad = module->PadsList(); pad; pad = pad->Next() ) { diff --git a/pcbnew/exporters/export_idf.cpp b/pcbnew/exporters/export_idf.cpp index 144313b0b8..c12fe822fa 100644 --- a/pcbnew/exporters/export_idf.cpp +++ b/pcbnew/exporters/export_idf.cpp @@ -596,7 +596,7 @@ bool PCB_EDIT_FRAME::Export_IDF3( BOARD* aPcb, const wxString& aFullFileName, idf_export_outline( aPcb, idfBoard ); // Output the drill holes and module (library) data. - for( MODULE* module = aPcb->m_Modules; module != 0; module = module->Next() ) + for( auto module : aPcb->Modules() ) idf_export_module( aPcb, module, idfBoard ); if( !idfBoard.WriteFile( aFullFileName, idfUnit, false ) ) diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp index df0609977d..ac056e94d7 100644 --- a/pcbnew/exporters/export_vrml.cpp +++ b/pcbnew/exporters/export_vrml.cpp @@ -1622,7 +1622,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt output_file << " children [\n"; // Export footprints - for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() ) + for( auto module : pcb->Modules() ) export_vrml_module( model3d, pcb, module, &output_file ); // write out the board and all layers @@ -1636,7 +1636,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt else { // Export footprints - for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() ) + for( auto module : pcb->Modules() ) export_vrml_module( model3d, pcb, module, NULL ); // write out the board and all layers diff --git a/pcbnew/exporters/gen_footprints_placefile.cpp b/pcbnew/exporters/gen_footprints_placefile.cpp index 4f6e495036..e8a3108a4a 100644 --- a/pcbnew/exporters/gen_footprints_placefile.cpp +++ b/pcbnew/exporters/gen_footprints_placefile.cpp @@ -431,8 +431,6 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName, bool aForceSmdItems, int aSide, bool aFormatCSV ) { - MODULE* footprint; - // Minimal text lengths: int lenRefText = 8; int lenValText = 8; @@ -451,7 +449,7 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName, std::vector list; list.reserve( footprintCount ); - for( footprint = GetBoard()->m_Modules; footprint; footprint = footprint->Next() ) + for( auto footprint : GetBoard()->Modules() ) { if( aSide != PCB_BOTH_SIDES ) { @@ -696,7 +694,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool fputs( "$EndBOARD\n\n", rptfile ); - for( MODULE* Module = GetBoard()->m_Modules; Module; Module = Module->Next() ) + for( auto Module : GetBoard()->Modules() ) { fprintf( rptfile, "$MODULE %s\n", EscapedUTF8( Module->GetReference() ).c_str() ); diff --git a/pcbnew/exporters/gendrill_file_writer_base.cpp b/pcbnew/exporters/gendrill_file_writer_base.cpp index ee71bf2c51..dbdfe98316 100644 --- a/pcbnew/exporters/gendrill_file_writer_base.cpp +++ b/pcbnew/exporters/gendrill_file_writer_base.cpp @@ -115,7 +115,7 @@ void GENDRILL_WRITER_BASE::buildHolesList( DRILL_LAYER_PAIR aLayerPair, if( aLayerPair == DRILL_LAYER_PAIR( F_Cu, B_Cu ) ) { // add holes for thru hole pads - for( MODULE* module = m_pcb->m_Modules; module; module = module->Next() ) + for( auto module : m_pcb->Modules() ) { for( auto& pad : module->Pads() ) { diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index be378ab90c..5fe1b7f722 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -327,7 +327,7 @@ bool FOOTPRINT_EDIT_FRAME::IsSearchTreeShown() BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const { - return GetBoard()->m_Modules; + return GetBoard()->GetFirstModule(); } @@ -345,7 +345,7 @@ LIB_ID FOOTPRINT_EDIT_FRAME::getTargetFPID() const LIB_ID FOOTPRINT_EDIT_FRAME::GetLoadedFPID() const { - MODULE* module = GetBoard()->m_Modules; + MODULE* module = GetBoard()->GetFirstModule(); if( module ) return LIB_ID( module->GetFPID().GetLibNickname(), m_footprintNameWhenLoaded ); @@ -356,7 +356,7 @@ LIB_ID FOOTPRINT_EDIT_FRAME::GetLoadedFPID() const bool FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard() const { - MODULE* module = GetBoard()->m_Modules; + MODULE* module = GetBoard()->GetFirstModule(); return ( module && module->GetLink() > 0 ); } @@ -498,10 +498,10 @@ double FOOTPRINT_EDIT_FRAME::BestZoom() void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { - if( GetScreen()->IsModify() && GetBoard()->m_Modules ) + if( GetScreen()->IsModify() && GetBoard()->GetFirstModule() ) { if( !HandleUnsavedChanges( this, _( "Save changes to footprint before closing?" ), - [&]()->bool { return SaveFootprint( GetBoard()->m_Modules ); } ) ) + [&]() -> bool { return SaveFootprint( GetBoard()->GetFirstModule() ); } ) ) { Event.Veto(); return; @@ -531,7 +531,7 @@ void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event ) void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ) { - aEvent.Enable( GetBoard()->m_Modules != NULL ); + aEvent.Enable( GetBoard()->GetFirstModule() != NULL ); if( aEvent.GetEventObject() == m_drawToolBar ) aEvent.Check( GetToolId() == aEvent.GetId() ); @@ -540,7 +540,7 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent ) void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent ) { - aEvent.Enable( GetBoard()->m_Modules != NULL ); + aEvent.Enable( GetBoard()->GetFirstModule() != NULL ); } @@ -554,7 +554,7 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent { PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); - aEvent.Enable( frame && frame->GetBoard()->m_Modules != NULL ); + aEvent.Enable( frame && frame->GetBoard()->GetFirstModule() != NULL ); } @@ -562,23 +562,24 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent { PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); - MODULE* module_in_edit = GetBoard()->m_Modules; + MODULE* module_in_edit = GetBoard()->GetFirstModule(); bool canInsert = frame && module_in_edit && !module_in_edit->GetLink(); // If the source was deleted, the module can inserted but not updated in the board. if( frame && module_in_edit && module_in_edit->GetLink() ) // this is not a new module { BOARD* mainpcb = frame->GetBoard(); - MODULE* source_module = mainpcb->m_Modules; + canInsert = true; // search if the source module was not deleted: - for( ; source_module != NULL; source_module = source_module->Next() ) + for( auto source_module : mainpcb->Modules() ) { if( module_in_edit->GetLink() == source_module->GetTimeStamp() ) + { + canInsert = false; break; + } } - - canInsert = ( source_module == NULL ); } aEvent.Enable( canInsert ); @@ -658,8 +659,8 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() if( IsCurrentFPFromBoard() ) { title += wxString::Format( wxT( " \u2014 %s [from %s.%s]" ), - GetBoard()->m_Modules->GetReference(), - Prj().GetProjectName(), PcbFileExtension ); + GetBoard()->GetFirstModule()->GetReference(), Prj().GetProjectName(), + PcbFileExtension ); } else if( fpid.IsValid() ) { @@ -674,15 +675,15 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() // Note: don't used GetLoadedFPID(); footprint name may have been edited title += wxString::Format( wxT( " \u2014 %s %s" ), - FROM_UTF8( GetBoard()->m_Modules->GetFPID().Format().c_str() ), - writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) ); + FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().Format().c_str() ), + writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) ); } else if( !fpid.GetLibItemName().empty() ) { // Note: don't used GetLoadedFPID(); footprint name may have been edited title += wxString::Format( wxT( " \u2014 %s %s" ), - FROM_UTF8( GetBoard()->m_Modules->GetFPID().GetLibItemName().c_str() ), - _( "[Unsaved]" ) ); + FROM_UTF8( GetBoard()->GetFirstModule()->GetFPID().GetLibItemName().c_str() ), + _( "[Unsaved]" ) ); } SetTitle( title ); diff --git a/pcbnew/footprint_editor_utils.cpp b/pcbnew/footprint_editor_utils.cpp index cfa8812d23..bf50860c72 100644 --- a/pcbnew/footprint_editor_utils.cpp +++ b/pcbnew/footprint_editor_utils.cpp @@ -89,14 +89,16 @@ void FOOTPRINT_EDIT_FRAME::LoadModuleFromLibrary( LIB_ID aFPID) SetCrossHairPosition( wxPoint( 0, 0 ) ); AddModuleToBoard( module ); - if( GetBoard()->m_Modules ) + auto fp = GetBoard()->GetFirstModule(); + + if( fp ) { - GetBoard()->m_Modules->ClearFlags(); + fp->ClearFlags(); // if either m_Reference or m_Value are gone, reinstall them - // otherwise you cannot see what you are doing on board - TEXTE_MODULE* ref = &GetBoard()->m_Modules->Reference(); - TEXTE_MODULE* val = &GetBoard()->m_Modules->Value(); + TEXTE_MODULE* ref = &fp->Reference(); + TEXTE_MODULE* val = &fp->Value(); if( val && ref ) { @@ -210,8 +212,8 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) GetBoard()->BuildListOfNets(); module->SetPosition( wxPoint( 0, 0 ) ); - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); + if( GetBoard()->GetFirstModule() ) + GetBoard()->GetFirstModule()->ClearFlags(); Zoom_Automatique( false ); GetScreen()->SetModify(); @@ -240,8 +242,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) if( GetScreen()->IsModify() && !GetBoard()->IsEmpty() ) { - if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. Save changes?" ), - [&]()->bool { return SaveFootprint( GetBoard()->m_Modules ); } ) ) + if( !HandleUnsavedChanges( this, + _( "The current footprint has been modified. Save changes?" ), + [&]() -> bool { + return SaveFootprint( GetBoard()->GetFirstModule() ); + } ) ) { break; } @@ -299,9 +304,9 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_SAVE: if( getTargetFPID() == GetLoadedFPID() ) { - if( SaveFootprint( GetBoard()->m_Modules ) ) + if( SaveFootprint( GetBoard()->GetFirstModule() ) ) { - m_toolManager->GetView()->Update( GetBoard()->m_Modules ); + m_toolManager->GetView()->Update( GetBoard()->GetFirstModule() ); GetGalCanvas()->ForceRefresh(); GetScreen()->ClrModify(); @@ -324,12 +329,12 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) else if( getTargetFPID() == GetLoadedFPID() ) { // Save Board Footprint As - MODULE* footprint = GetBoard()->m_Modules; + MODULE* footprint = GetBoard()->GetFirstModule(); if( footprint && SaveFootprintAs( footprint ) ) { m_footprintNameWhenLoaded = footprint->GetFPID().GetLibItemName(); - m_toolManager->GetView()->Update( GetBoard()->m_Modules ); + m_toolManager->GetView()->Update( footprint ); GetScreen()->ClrModify(); GetGalCanvas()->ForceRefresh(); @@ -359,7 +364,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) LIB_ID fpID = getTargetFPID(); if( fpID == GetLoadedFPID() ) - m_copiedModule.reset( new MODULE( *GetBoard()->m_Modules.GetFirst() ) ); + m_copiedModule.reset( new MODULE( *GetBoard()->GetFirstModule() ) ); else m_copiedModule.reset( LoadFootprint( fpID ) ); @@ -404,8 +409,8 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) SetCrossHairPosition( wxPoint( 0, 0 ) ); Import_Module(); - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); + if( GetBoard()->GetFirstModule() ) + GetBoard()->GetFirstModule()->ClearFlags(); GetScreen()->SetModify(); Zoom_Automatique( false ); @@ -416,7 +421,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_EXPORT_PART: if( getTargetFPID() == GetLoadedFPID() ) - Export_Module( GetBoard()->m_Modules ); + Export_Module( GetBoard()->GetFirstModule() ); else Export_Module( LoadFootprint( getTargetFPID() ) ); break; @@ -453,9 +458,9 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_MODEDIT_EDIT_MODULE_PROPERTIES: - if( GetBoard()->m_Modules ) + if( GetBoard()->GetFirstModule() ) { - editFootprintProperties( GetBoard()->m_Modules ); + editFootprintProperties( GetBoard()->GetFirstModule() ); GetGalCanvas()->Refresh(); } break; @@ -530,8 +535,8 @@ bool FOOTPRINT_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileS SetCrossHairPosition( wxPoint( 0, 0 ) ); Import_Module( aFileSet[0] ); - if( GetBoard()->m_Modules ) - GetBoard()->m_Modules->ClearFlags(); + if( GetBoard()->GetFirstModule() ) + GetBoard()->GetFirstModule()->ClearFlags(); GetScreen()->ClrModify(); Zoom_Automatique( false ); diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 95471841cc..e64b1ef37e 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -634,7 +634,7 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aC void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& aLibName, wxString* aLibPath ) { - if( GetBoard()->m_Modules == NULL ) + if( GetBoard()->GetFirstModule() == NULL ) { DisplayInfoMessage( this, _( "No footprints to archive!" ) ); return; @@ -658,7 +658,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& { FP_LIB_TABLE* tbl = prj.PcbFootprintLibs(); - for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() ) + for( auto curr_fp : GetBoard()->Modules() ) { if( !curr_fp->GetFPID().GetLibItemName().empty() ) // Can happen with old boards. tbl->FootprintSave( nickname, curr_fp, false ); @@ -684,7 +684,7 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aStoreInNewLib, const wxString& IO_MGR::PCB_FILE_T piType = IO_MGR::KICAD_SEXP; PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) ); - for( MODULE* curr_fp = GetBoard()->m_Modules; curr_fp; curr_fp = curr_fp->Next() ) + for( auto curr_fp : GetBoard()->Modules() ) { try { @@ -794,18 +794,21 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) BOARD* mainpcb = pcbframe->GetBoard(); MODULE* source_module = NULL; - MODULE* module_in_edit = GetBoard()->m_Modules; + MODULE* module_in_edit = GetBoard()->GetFirstModule(); // Search the old module (source) if exists // Because this source could be deleted when editing the main board... if( module_in_edit->GetLink() ) // this is not a new module ... { - source_module = mainpcb->m_Modules; + source_module = nullptr; - for( ; source_module != NULL; source_module = source_module->Next() ) + for( auto mod : mainpcb->Modules() ) { if( module_in_edit->GetLink() == source_module->GetTimeStamp() ) + { + source_module = mod; break; + } } } diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 846ba2393d..4d4acdd77d 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -406,7 +406,8 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) // Delete the current footprint (MUST reset tools first) GetToolManager()->ResetTools( TOOL_BASE::MODEL_RELOAD ); - GetBoard()->m_Modules.DeleteAll(); + + GetBoard()->DeleteAllModules(); LIB_ID id; id.SetLibNickname( getCurNickname() ); @@ -459,7 +460,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& event ) Close( true ); } - else if( GetBoard()->m_Modules ) + else if( GetBoard()->GetFirstModule() ) { PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false ); @@ -473,7 +474,7 @@ void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& event ) BOARD_COMMIT commit( pcbframe ); // Create the "new" module - MODULE* newmodule = new MODULE( *GetBoard()->m_Modules ); + MODULE* newmodule = new MODULE( *GetBoard()->GetFirstModule() ); newmodule->SetParent( pcbframe->GetBoard() ); newmodule->SetLink( 0 ); @@ -584,7 +585,7 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event ) void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent ) { - aEvent.Enable( GetBoard()->m_Modules != nullptr ); + aEvent.Enable( GetBoard()->GetFirstModule() != nullptr ); } @@ -765,7 +766,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) setCurFootprintName( m_footprintList->GetString( (unsigned) selection ) ); // Delete the current footprint - GetBoard()->m_Modules.DeleteAll(); + GetBoard()->DeleteAllModules(); MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad( getCurNickname(), getCurFootprintName() ); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 3758823060..34b6a8dc6a 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -324,7 +324,7 @@ void FOOTPRINT_WIZARD_FRAME::updateView() void FOOTPRINT_WIZARD_FRAME::UpdateMsgPanel() { - BOARD_ITEM* footprint = GetBoard()->m_Modules; + BOARD_ITEM* footprint = GetBoard()->GetFirstModule(); if( footprint ) { diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp index 5601a19337..019c89a31e 100644 --- a/pcbnew/footprint_wizard_frame_functions.cpp +++ b/pcbnew/footprint_wizard_frame_functions.cpp @@ -100,7 +100,7 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint() m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); // Delete the current footprint - GetBoard()->m_Modules.DeleteAll(); + GetBoard()->DeleteAllModules(); // Creates the module wxString msg; @@ -254,4 +254,3 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event ) } } - diff --git a/pcbnew/fp_tree_synchronizing_adapter.cpp b/pcbnew/fp_tree_synchronizing_adapter.cpp index f8620da905..048b52d23c 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.cpp +++ b/pcbnew/fp_tree_synchronizing_adapter.cpp @@ -162,7 +162,11 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte case 0: if( node->LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() ) { - wxString currentFPName = m_frame->GetBoard()->m_Modules->GetFPID().GetLibItemName(); + auto mod = m_frame->GetBoard()->GetFirstModule(); + + wxASSERT( mod ); + + wxString currentFPName = mod->GetFPID().GetLibItemName(); // mark modified part with an asterix if( m_frame->GetScreen()->IsModify() ) @@ -176,7 +180,11 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewIte case 1: if( node->LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() ) - aVariant = m_frame->GetBoard()->m_Modules->GetDescription(); + { + auto mod = m_frame->GetBoard()->GetFirstModule(); + wxASSERT( mod ); + aVariant = mod->GetDescription(); + } else aVariant = node->Desc; break; diff --git a/pcbnew/import_gfx/dialog_import_gfx.cpp b/pcbnew/import_gfx/dialog_import_gfx.cpp index 5c950efdd5..eafa3d6ec4 100644 --- a/pcbnew/import_gfx/dialog_import_gfx.cpp +++ b/pcbnew/import_gfx/dialog_import_gfx.cpp @@ -70,7 +70,7 @@ DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aImportAsFoo m_parent = aParent; if( aImportAsFootprintGraphic ) - m_importer.reset( new GRAPHICS_IMPORTER_MODULE( m_parent->GetBoard()->m_Modules ) ); + m_importer.reset( new GRAPHICS_IMPORTER_MODULE( m_parent->GetBoard()->GetFirstModule() ) ); else m_importer.reset( new GRAPHICS_IMPORTER_BOARD( m_parent->GetBoard() ) ); diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index db9f8c7c53..799bf92e00 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -101,8 +101,9 @@ bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery ) { wxSafeYield( this, true ); // Allow frame to come to front before showing warning. - if( !HandleUnsavedChanges( this, _( "The current footprint has been modified. Save changes?" ), - [&]()->bool { return SaveFootprint( GetBoard()->m_Modules ); } ) ) + if( !HandleUnsavedChanges( this, + _( "The current footprint has been modified. Save changes?" ), + [&]() -> bool { return SaveFootprint( GetBoard()->Modules().front() ); } ) ) { return false; } diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index d24f2db5ee..2316ac1137 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -135,7 +135,7 @@ void CLIPBOARD_IO::SaveSelection( const SELECTION& aSelected ) } // Set the new relative internal local coordinates of copied items - MODULE* editedModule = m_board->m_Modules; + MODULE* editedModule = m_board->Modules().front(); wxPoint moveVector = partialModule.GetPosition() + editedModule->GetPosition(); partialModule.MoveAnchorPosition( moveVector ); diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index b463bd700d..495241994b 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -603,7 +603,7 @@ void PCB_IO::formatGeneral( BOARD* aBoard, int aNestLevel ) const m_out->Print( aNestLevel+1, "(drawings %zu)\n", aBoard->Drawings().size() ); m_out->Print( aNestLevel+1, "(tracks %d)\n", aBoard->GetNumSegmTrack() ); - m_out->Print( aNestLevel+1, "(modules %d)\n", aBoard->m_Modules.GetCount() ); + m_out->Print( aNestLevel + 1, "(modules %zu)\n", aBoard->Modules().size() ); m_out->Print( aNestLevel+1, "(nets %d)\n", m_mapping->GetSize() ); m_out->Print( aNestLevel, ")\n\n" ); @@ -717,7 +717,7 @@ void PCB_IO::format( BOARD* aBoard, int aNestLevel ) const formatHeader( aBoard, aNestLevel ); // Save the modules. - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { Format( module, aNestLevel ); m_out->Print( 0, "\n" ); diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index 7bf4f40203..f193fb59a4 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -98,7 +98,7 @@ bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule ) if( aModule == NULL ) { - if( ! frame->GetBoard() || ! frame->GetBoard()->m_Modules ) + if( !frame->GetBoard() || !frame->GetBoard()->GetFirstModule() ) return false; aModule = SelectFootprintFromBoard( frame->GetBoard() ); @@ -336,9 +336,8 @@ MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprintFromBoard( BOARD* aPcb ) wxString fpname; wxString msg; wxArrayString listnames; - MODULE* module = aPcb->m_Modules; - for( ; module; module = module->Next() ) + for( auto module : aPcb->Modules() ) listnames.Add( module->GetReference() ); msg.Printf( _( "Footprints [%u items]" ), (unsigned) listnames.GetCount() ); @@ -367,15 +366,13 @@ MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprintFromBoard( BOARD* aPcb ) oldName = fpname; - module = aPcb->m_Modules; - - for( ; module; module = module->Next() ) + for( auto mod : aPcb->Modules() ) { - if( fpname == module->GetReference() ) - break; + if( fpname == mod->GetReference() ) + return mod; } - return module; + return nullptr; } @@ -437,11 +434,10 @@ static PICKED_ITEMS_LIST s_PickedList; // a pick-list to save in MODULE* PCB_BASE_FRAME::GetFootprintFromBoardByReference() { wxString moduleName; - MODULE* module = NULL; wxArrayString fplist; // Build list of available fp references, to display them in dialog - for( MODULE* fp = GetBoard()->m_Modules; fp; fp = fp->Next() ) + for( auto fp : GetBoard()->Modules() ) fplist.Add( fp->GetReference() + wxT(" ( ") + fp->GetValue() + wxT(" )") ); fplist.Sort(); @@ -457,18 +453,14 @@ MODULE* PCB_BASE_FRAME::GetFootprintFromBoardByReference() if( !moduleName.IsEmpty() ) { - module = GetBoard()->m_Modules; - - while( module ) + for( auto mod : GetBoard()->Modules() ) { - if( module->GetReference().CmpNoCase( moduleName ) == 0 ) - break; - - module = module->Next(); + if( mod->GetReference().CmpNoCase( moduleName ) == 0 ) + return mod; } } - return module; + return nullptr; } diff --git a/pcbnew/menubar_footprint_editor.cpp b/pcbnew/menubar_footprint_editor.cpp index e1f91afe23..7bcf3f8995 100644 --- a/pcbnew/menubar_footprint_editor.cpp +++ b/pcbnew/menubar_footprint_editor.cpp @@ -48,8 +48,8 @@ void FOOTPRINT_EDIT_FRAME::ReCreateMenuBar() wxMenuBar* oldMenuBar = GetMenuBar(); wxMenuBar* menuBar = new wxMenuBar(); - auto modifiedDocumentCondition = [ this ] ( const SELECTION& sel ) { - return GetBoard()->m_Modules && GetScreen()->IsModify(); + auto modifiedDocumentCondition = [this]( const SELECTION& sel ) { + return !GetBoard()->Modules().empty() && GetScreen()->IsModify(); }; auto libraryPartCondition = [ this ] ( const SELECTION& sel ) { LIB_ID libId = getTargetFPID(); diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp index 6552b11397..1b659cb784 100644 --- a/pcbnew/netinfo_list.cpp +++ b/pcbnew/netinfo_list.cpp @@ -212,7 +212,7 @@ void NETINFO_MAPPING::Update() nets.insert( track->GetNetCode() ); // Modules/pads - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { for( D_PAD* pad = module->PadsList().GetFirst(); pad; pad = pad->Next() ) { diff --git a/pcbnew/netlist.cpp b/pcbnew/netlist.cpp index e072da44a6..d18824cf8a 100644 --- a/pcbnew/netlist.cpp +++ b/pcbnew/netlist.cpp @@ -135,7 +135,7 @@ void PCB_EDIT_FRAME::OnNetlistChanged( BOARD_NETLIST_UPDATER& aUpdater, MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName() { - if( GetBoard()->m_Modules == NULL ) + if( GetBoard()->Modules().empty() ) { DisplayError( this, _( "No footprints" ) ); return 0; @@ -143,9 +143,7 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName() wxArrayString listnames; - MODULE* module; - - for( module = GetBoard()->m_Modules; module; module = module->Next() ) + for( auto module : GetBoard()->Modules() ) listnames.Add( module->GetReference() ); wxArrayString headers; @@ -163,17 +161,17 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName() EDA_LIST_DIALOG dlg( this, _( "Components" ), headers, itemsToDisplay, wxEmptyString ); if( dlg.ShowModal() != wxID_OK ) - return NULL; + return nullptr; wxString ref = dlg.GetTextSelection(); - for( module = GetBoard()->m_Modules; module; module = module->Next() ) + for( auto module : GetBoard()->Modules() ) { if( module->GetReference() == ref ) - break; + return module; } - return module; + return nullptr; } diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index b19216a709..6f6e81eae1 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -511,7 +511,7 @@ void PCB_BASE_FRAME::OnTogglePadDrawMode( wxCommandEvent& aEvent ) // Update pads BOARD* board = GetBoard(); - for( MODULE* module = board->m_Modules; module; module = module->Next() ) + for( auto module : board->Modules() ) { for( auto pad : module->Pads() ) view->Update( pad, KIGFX::GEOMETRY ); diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 1f01caf435..ae4e66724a 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -174,7 +174,7 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard ) m_view->Add( track ); // Load modules and its additional elements - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) m_view->Add( module ); // DRC markers diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 0f2d0e0fa2..d27eeda049 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -639,7 +639,7 @@ void PCB_EDIT_FRAME::DoShowBoardSetupDialog( const wxString& aInitialPage, UpdateUserInterface(); ReCreateAuxiliaryToolbar(); - for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) + for( auto module : GetBoard()->Modules() ) GetGalCanvas()->GetView()->Update( module ); GetGalCanvas()->Refresh(); @@ -1303,11 +1303,11 @@ void PCB_EDIT_FRAME::LockModule( MODULE* aModule, bool aLocked ) } else { - for( aModule = GetBoard()->m_Modules; aModule != NULL; aModule = aModule->Next() ) + for( auto mod : GetBoard()->Modules() ) { - if( WildCompareString( ModulesMaskSelection, aModule->GetReference() ) ) + if( WildCompareString( ModulesMaskSelection, mod->GetReference() ) ) { - aModule->SetLocked( aLocked ); + mod->SetLocked( aLocked ); OnModify(); } } diff --git a/pcbnew/pcb_legacy_draw_utils.cpp b/pcbnew/pcb_legacy_draw_utils.cpp index 8bccffe0c9..123511f8f3 100644 --- a/pcbnew/pcb_legacy_draw_utils.cpp +++ b/pcbnew/pcb_legacy_draw_utils.cpp @@ -110,7 +110,7 @@ void BOARD::Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& offset ) LSET all_cu = LSET::AllCuMask(); - for( MODULE* module = m_Modules; module; module = module->Next() ) + for( auto module : m_modules ) { bool display = true; LSET layerMask = all_cu; diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 7499e1a6c7..9e365305be 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -88,7 +88,7 @@ void PlotSilkScreen( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask, if( layersmask_plotpads.any() ) { - for( MODULE* Module = aBoard->m_Modules; Module; Module = Module->Next() ) + for( auto Module : aBoard->Modules() ) { aPlotter->StartBlock( NULL ); @@ -115,7 +115,7 @@ void PlotSilkScreen( BOARD *aBoard, PLOTTER* aPlotter, LSET aLayerMask, } // Plot footprints fields (ref, value ...) - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { if( ! itemplotter.PlotAllTextsModule( module ) ) { @@ -299,7 +299,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, // We plot here module texts, but they are usually on silkscreen layer, // so they are not plot here but plot by PlotSilkScreen() // Plot footprints fields (ref, value ...) - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { if( ! itemplotter.PlotAllTextsModule( module ) ) { @@ -308,7 +308,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, } } - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() ) { @@ -328,7 +328,7 @@ void PlotStandardLayer( BOARD *aBoard, PLOTTER* aPlotter, } // Plot footprint pads - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { aPlotter->StartBlock( NULL ); @@ -695,7 +695,7 @@ void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, int smallDrill = (aPlotOpt.GetDrillMarksType() == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE) ? SMALL_DRILL : INT_MAX; - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { for( D_PAD* pad = module->PadsList(); pad; pad = pad->Next() ) { @@ -773,7 +773,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, // on this layer (like logos), not actually areas around pads. itemplotter.PlotBoardGraphicItems(); - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { for( BOARD_ITEM* item = module->GraphicalItemsList(); item; item = item->Next() ) { @@ -804,7 +804,7 @@ void PlotSolderMaskLayer( BOARD *aBoard, PLOTTER* aPlotter, SHAPE_POLY_SET initialPolys; // Contains exact shapes to plot // Plot pads - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { // add shapes with exact size module->TransformPadsShapesWithClearanceToPolygon( layer, initialPolys, 0 ); diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 4431683f97..16bfac364d 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -430,7 +430,7 @@ void BRDITEMS_PLOTTER::PlotPcbTarget( PCB_TARGET* aMire ) // Plot footprints graphic items (outlines) void BRDITEMS_PLOTTER::Plot_Edges_Modules() { - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { for( BOARD_ITEM* item = module->GraphicalItemsList().GetFirst(); item; item = item->Next() ) { @@ -843,7 +843,7 @@ void BRDITEMS_PLOTTER::PlotDrillMarks() } } - for( MODULE* Module = m_board->m_Modules; Module != NULL; Module = Module->Next() ) + for( auto Module : m_board->Modules() ) { for( D_PAD* pad = Module->PadsList(); pad != NULL; pad = pad->Next() ) { diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 7d9ead406b..f6d023c44a 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -132,7 +132,7 @@ PNS_PCBNEW_RULE_RESOLVER::PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* } // Build clearance cache for pads - for( MODULE* mod = m_board->m_Modules; mod ; mod = mod->Next() ) + for( auto mod : m_board->Modules() ) { auto moduleClearance = mod->GetLocalClearance(); diff --git a/pcbnew/specctra_import_export/specctra_export.cpp b/pcbnew/specctra_import_export/specctra_export.cpp index 1a44ff8057..bb5e98f4da 100644 --- a/pcbnew/specctra_import_export/specctra_export.cpp +++ b/pcbnew/specctra_import_export/specctra_export.cpp @@ -1758,7 +1758,7 @@ void SPECCTRA_DB::exportNETCLASS( const NETCLASSPTR& aNetClass, BOARD* aBoard ) void SPECCTRA_DB::FlipMODULEs( BOARD* aBoard ) { - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { module->SetFlag( 0 ); if( module->GetLayer() == B_Cu ) @@ -1779,7 +1779,7 @@ void SPECCTRA_DB::RevertMODULEs( BOARD* aBoard ) // DSN Images (=KiCad MODULES and pads) must be presented from the // top view. Restore those that were flipped. - for( MODULE* module = aBoard->m_Modules; module; module = module->Next() ) + for( auto module : aBoard->Modules() ) { if( module->GetFlag() ) { diff --git a/pcbnew/swig/pcbnew_action_plugins.cpp b/pcbnew/swig/pcbnew_action_plugins.cpp index 8053274a32..e774487d47 100644 --- a/pcbnew/swig/pcbnew_action_plugins.cpp +++ b/pcbnew/swig/pcbnew_action_plugins.cpp @@ -225,7 +225,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) } // Append modules: - for( BOARD_ITEM* item = currentPcb->m_Modules; item != NULL; item = item->Next() ) + for( auto item : currentPcb->Modules() ) { ITEM_PICKER picker( item, UR_CHANGED ); itemsList.PushItem( picker ); @@ -336,7 +336,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) } // Find new modules - for( BOARD_ITEM* item = currentPcb->m_Modules; item != NULL; item = item->Next() ) + for( auto item : currentPcb->Modules() ) { if( !oldBuffer->ContainsItem( item ) ) { diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 08c07d4fc7..8c2cf8a44b 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1085,7 +1085,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) if( m_editModules ) { - dupe_item = editFrame->GetBoard()->m_Modules->Duplicate( orig_item, increment ); + dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment ); } else { diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index 4beabb1561..e9cbb13fee 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -104,7 +104,7 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) { std::unique_ptr CreateItem() override { - D_PAD* pad = new D_PAD ( m_board->m_Modules ); + D_PAD* pad = new D_PAD( m_board->GetFirstModule() ); m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad pad->IncrementPadName( true, true ); return std::unique_ptr( pad ); @@ -130,7 +130,7 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) ); - wxASSERT( board()->m_Modules ); + wxASSERT( board()->GetFirstModule() ); doInteractiveItemPlacement( &placer, _( "Place pad" ), IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP ); @@ -142,7 +142,7 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) { - if( !board()->m_Modules || !board()->m_Modules->PadsList() ) + if( !board()->GetFirstModule() || !board()->GetFirstModule()->PadsList() ) return 0; DIALOG_ENUM_PADS settingsDlg( frame() ); @@ -318,7 +318,7 @@ int MODULE_EDITOR_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent ) statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) ); } - for( auto p : board()->m_Modules->Pads() ) + for( auto p : board()->GetFirstModule()->Pads() ) { p->ClearSelected(); view->Update( p ); @@ -354,7 +354,7 @@ int MODULE_EDITOR_TOOLS::ExplodePadToShapes( const TOOL_EVENT& aEvent ) for( auto prim : pad->GetPrimitives() ) { - auto ds = new EDGE_MODULE( board()->m_Modules ); + auto ds = new EDGE_MODULE( board()->GetFirstModule() ); prim.ExportTo( ds ); // ExportTo exports to a DRAWSEGMENT // Fix an arbitray draw layer for this EDGE_MODULE @@ -385,7 +385,7 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent ) { SELECTION& selection = m_toolMgr->GetTool()->GetSelection(); - std::unique_ptr pad ( new D_PAD ( board()->m_Modules ) ); + std::unique_ptr pad( new D_PAD( board()->GetFirstModule() ) ); D_PAD *refPad = nullptr; bool multipleRefPadsFound = false; bool illegalItemsFound = false; diff --git a/pcbnew/tools/pad_tool.cpp b/pcbnew/tools/pad_tool.cpp index 39723b7877..9a3aa73b97 100644 --- a/pcbnew/tools/pad_tool.cpp +++ b/pcbnew/tools/pad_tool.cpp @@ -161,7 +161,7 @@ void PAD_TOOL::Reset( RESET_REASON aReason ) bool PAD_TOOL::haveFootprints() { auto& board = *getModel(); - return board.m_Modules.GetCount() > 0; + return board.Modules().size() > 0; } @@ -267,7 +267,7 @@ static void doPushPadProperties( BOARD& board, const D_PAD& aSrcPad, BOARD_COMMI double pad_orient = aSrcPad.GetOrientation() - moduleRef->GetOrientation(); - for( const MODULE* module = board.m_Modules; module; module = module->Next() ) + for( auto module : board.Modules() ) { if( !aSameFootprints && ( module != moduleRef ) ) continue; diff --git a/pcbnew/tools/pcb_tool_base.h b/pcbnew/tools/pcb_tool_base.h index 8975d761c0..8615d6f1bd 100644 --- a/pcbnew/tools/pcb_tool_base.h +++ b/pcbnew/tools/pcb_tool_base.h @@ -138,7 +138,10 @@ protected: KIGFX::VIEW_CONTROLS* controls() const { return getViewControls(); } PCB_EDIT_FRAME* frame() const { return getEditFrame(); } BOARD* board() const { return getModel(); } - MODULE* module() const { return board()->m_Modules; } + MODULE* module() const + { + return board()->Modules().front(); + } PCB_DISPLAY_OPTIONS* displayOptions() const; PCB_DRAW_PANEL_GAL* canvas() const; const SELECTION& selection() const; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 0e69d8729e..39289bc067 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -705,7 +705,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) if( editModules ) { auto oldModule = static_cast( clipItem ); - auto newModule = board()->m_Modules.GetFirst(); + auto newModule = board()->GetFirstModule(); for( D_PAD* pad = oldModule->PadsList(), *next = nullptr; pad; pad = next ) { @@ -839,7 +839,7 @@ int PCBNEW_CONTROL::placeBoardItems( BOARD* aBoard ) std::vector items; moveNoFlagToVector( aBoard->m_Track, items, isNew ); - moveNoFlagToVector( aBoard->m_Modules, items, isNew ); + moveNoFlagToVector( aBoard->Modules(), items, isNew ); moveNoFlagToVector( aBoard->Drawings(), items, isNew ); moveNoFlagToVector( aBoard->Zones(), items, isNew ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index ffdcc6b568..a2e9f81668 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -992,11 +992,10 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent ) void SELECTION_TOOL::selectAllItemsOnSheet( wxString& aSheetpath ) { - auto modules = board()->m_Modules.GetFirst(); std::list modList; // store all modules that are on that sheet - for( MODULE* mitem = modules; mitem; mitem = mitem->Next() ) + for( auto mitem : board()->Modules() ) { if( mitem != NULL && mitem->GetPath().Contains( aSheetpath ) ) { diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index 72fee88af0..ac1be90a99 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -119,7 +119,7 @@ using namespace std::placeholders; static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) { - static std::list itemsList; + static std::set itemsList; if( aItem == NULL ) // Build list { @@ -130,33 +130,30 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) // Store items in list: // Append tracks: for( item = aPcb->m_Track; item != NULL; item = item->Next() ) - itemsList.push_back( item ); + itemsList.insert( item ); // Append modules: - for( item = aPcb->m_Modules; item != NULL; item = item->Next() ) - itemsList.push_back( item ); + std::copy( aPcb->Modules().begin(), aPcb->Modules().end(), + std::inserter( itemsList, itemsList.end() ) ); // Append drawings for( auto ditem : aPcb->Drawings() ) - itemsList.push_back( ditem ); + itemsList.insert( ditem ); // Append zones outlines for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ ) - itemsList.push_back( aPcb->GetArea( ii ) ); + itemsList.insert( aPcb->GetArea( ii ) ); NETINFO_LIST& netInfo = aPcb->GetNetInfo(); for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i ) - itemsList.push_back( *i ); - - // Sort list - itemsList.sort(); + itemsList.insert( *i ); return false; } // search in list: - return std::binary_search( itemsList.begin(), itemsList.end(), aItem ); + return itemsList.count( aItem ); } static void SwapItemData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) @@ -625,4 +622,4 @@ void PCB_BASE_EDIT_FRAME::RollbackFromUndo() delete undo; GetGalCanvas()->Refresh(); -} \ No newline at end of file +} diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index 2e3a842c5c..5ee0588f96 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -377,7 +377,7 @@ void ZONE_FILLER::buildZoneFeatureHoleList( const ZONE_CONTAINER* aZone, MODULE dummymodule( m_board ); // Creates a dummy parent D_PAD dummypad( &dummymodule ); - for( MODULE* module = m_board->m_Modules; module; module = module->Next() ) + for( auto module : m_board->Modules() ) { D_PAD* nextpad;