diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index c1993f19fe..cd62223475 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -646,10 +646,8 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) std::vector> zones; - for( int i = 0; i < m_board->GetAreaCount(); i++ ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - const ZONE_CONTAINER* zone = m_board->GetArea( i ); - for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) zones.emplace_back( std::make_pair( zone, layer ) ); } @@ -938,24 +936,16 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) // Draw non copper zones if( GetFlag( FL_ZONE ) ) { - for( int ii = 0; ii < m_board->GetAreaCount(); ++ii ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - ZONE_CONTAINER* zone = m_board->GetArea( ii ); - - if( !zone->IsOnLayer( curr_layer_id ) ) - continue; - - AddSolidAreasShapesToContainer( zone, layerContainer, curr_layer_id ); + if( zone->IsOnLayer( curr_layer_id ) ) + AddSolidAreasShapesToContainer( zone, layerContainer, curr_layer_id ); } - for( int ii = 0; ii < m_board->GetAreaCount(); ++ii ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - ZONE_CONTAINER* zone = m_board->GetArea( ii ); - - if( !zone->IsOnLayer( curr_layer_id ) ) - continue; - - zone->TransformSolidAreasShapesToPolygon( curr_layer_id, *layerPoly ); + if( zone->IsOnLayer( curr_layer_id ) ) + zone->TransformSolidAreasShapesToPolygon( curr_layer_id, *layerPoly ); } } diff --git a/pcbnew/board_connected_item.cpp b/pcbnew/board_connected_item.cpp index 59d7ec4fd1..dbbebbd46f 100644 --- a/pcbnew/board_connected_item.cpp +++ b/pcbnew/board_connected_item.cpp @@ -24,11 +24,8 @@ */ #include -#include - #include #include - #include using namespace std::placeholders; @@ -50,11 +47,6 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) // set the m_netinfo to the dummy NETINFO_LIST::ORPHANED BOARD* board = GetBoard(); - //auto connectivity = board ? board->GetConnectivity() : nullptr; - //bool addRatsnest = false; - - //if( connectivity ) - //addRatsnest = connectivity->Remove( this ); if( ( aNetCode >= 0 ) && board ) m_netinfo = board->FindNet( aNetCode ); @@ -64,10 +56,6 @@ bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) if( !aNoAssert ) wxASSERT( m_netinfo ); - // Add only if it was previously added to the ratsnest - //if( addRatsnest ) - // connectivity->Add( this ); - return ( m_netinfo != NULL ); } diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index b4a97bb42f..b1b0014459 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -86,10 +86,8 @@ void BOARD::ConvertBrdLayerToPolygonalContours( PCB_LAYER_ID aLayer, SHAPE_POLY_ } // convert copper zones - for( int ii = 0; ii < GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : Zones() ) { - ZONE_CONTAINER* zone = GetArea( ii ); - if( zone->GetLayerSet().test( aLayer ) ) zone->TransformSolidAreasShapesToPolygon( aLayer, aOutlines ); } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 5db4de5861..3678d4e1f9 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -102,30 +102,25 @@ BOARD::BOARD() : BOARD::~BOARD() { - while( m_ZoneDescriptorList.size() ) - { - ZONE_CONTAINER* area_to_remove = m_ZoneDescriptorList[0]; - Delete( area_to_remove ); - } - // Clean up the owned elements DeleteMARKERs(); - DeleteZONEOutlines(); - // Delete the modules - for( auto m : m_modules ) + for( ZONE_CONTAINER* zone : m_zones ) + delete zone; + + m_zones.clear(); + + for( MODULE* m : m_modules ) delete m; m_modules.clear(); - // Delete the tracks - for( auto t : m_tracks ) + for( TRACK* t : m_tracks ) delete t; m_tracks.clear(); - // Delete the drawings - for (auto d : m_drawings ) + for ( BOARD_ITEM* d : m_drawings ) delete d; m_drawings.clear(); @@ -246,19 +241,19 @@ TRACKS BOARD::TracksInNet( int aNetCode ) { TRACKS ret; - INSPECTOR_FUNC inspector = [aNetCode,&ret] ( EDA_ITEM* item, void* testData ) - { - TRACK* t = (TRACK*) item; + INSPECTOR_FUNC inspector = [aNetCode, &ret]( EDA_ITEM* item, void* testData ) + { + TRACK* t = (TRACK*) item; - if( t->GetNetCode() == aNetCode ) - ret.push_back( t ); + if( t->GetNetCode() == aNetCode ) + ret.push_back( t ); - return SEARCH_RESULT::CONTINUE; - }; + return SEARCH_RESULT::CONTINUE; + }; // visit this BOARD's TRACKs and VIAs with above TRACK INSPECTOR which // appends all in aNetCode to ret. - Visit( inspector, NULL, GENERAL_COLLECTOR::Tracks ); + Visit( inspector, NULL, GENERAL_COLLECTOR::Tracks ); return ret; } @@ -283,18 +278,14 @@ const PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer ) { if ( IsCopperLayer( layer ) && ( m_Layer[ layer ].m_name == aLayerName ) ) - { return ToLAYER_ID( layer ); - } } // Otherwise fall back to the system standard layer names for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer ) { if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName ) - { return ToLAYER_ID( layer ); - } } return UNDEFINED_LAYER; @@ -376,29 +367,14 @@ bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType ) const char* LAYER::ShowType( LAYER_T aType ) { - const char* cp; - switch( aType ) { default: - case LT_SIGNAL: - cp = "signal"; - break; - - case LT_POWER: - cp = "power"; - break; - - case LT_MIXED: - cp = "mixed"; - break; - - case LT_JUMPER: - cp = "jumper"; - break; + case LT_SIGNAL: return "signal"; + case LT_POWER: return "power"; + case LT_MIXED: return "mixed"; + case LT_JUMPER: return "jumper"; } - - return cp; } @@ -507,20 +483,17 @@ void BOARD::SetElementVisibility( GAL_LAYER_ID aLayer, bool isEnabled ) // because we have a tool to show/hide ratsnest relative to a pad or a module // so the hide/show option is a per item selection - for( auto track : Tracks() ) + for( TRACK* track : Tracks() ) track->SetLocalRatsnestVisible( isEnabled ); - for( auto mod : Modules() ) + for( MODULE* mod : Modules() ) { - for( auto pad : mod->Pads() ) + for( D_PAD* pad : mod->Pads() ) pad->SetLocalRatsnestVisible( isEnabled ); } - for( int i = 0; iSetLocalRatsnestVisible( isEnabled ); - } break; } @@ -574,7 +547,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode ) // this one uses a vector case PCB_ZONE_AREA_T: - m_ZoneDescriptorList.push_back( (ZONE_CONTAINER*) aBoardItem ); + m_zones.push_back( (ZONE_CONTAINER*) aBoardItem ); break; case PCB_TRACE_T: @@ -649,35 +622,27 @@ void BOARD::Remove( BOARD_ITEM* aBoardItem ) } case PCB_MARKER_T: - - // find the item in the vector, then remove it - for( unsigned i = 0; im_Uuid == aID ) return track; + } for( MODULE* module : Modules() ) { @@ -783,8 +740,10 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) return module; for( D_PAD* pad : module->Pads() ) + { if( pad->m_Uuid == aID ) return pad; + } if( module->Reference().m_Uuid == aID ) return &module->Reference(); @@ -793,25 +752,35 @@ BOARD_ITEM* BOARD::GetItem( const KIID& aID ) return &module->Value(); for( BOARD_ITEM* drawing : module->GraphicalItems() ) + { if( drawing->m_Uuid == aID ) return drawing; + } } for( ZONE_CONTAINER* zone : Zones() ) + { if( zone->m_Uuid == aID ) return zone; + } for( BOARD_ITEM* drawing : Drawings() ) + { if( drawing->m_Uuid == aID ) return drawing; + } for( MARKER_PCB* marker : m_markers ) + { if( marker->m_Uuid == aID ) return marker; + } for( PCB_GROUP* group : m_groups ) + { if( group->m_Uuid == aID ) return group; + } if( m_Uuid == aID ) return this; @@ -857,9 +826,10 @@ void BOARD::FillItemMap( std::map& aMap ) unsigned BOARD::GetNodesCount( int aNet ) { unsigned retval = 0; - for( auto mod : Modules() ) + + for( MODULE* mod : Modules() ) { - for( auto pad : mod->Pads() ) + for( D_PAD* pad : mod->Pads() ) { if( ( aNet == -1 && pad->GetNetCode() > 0 ) || aNet == pad->GetNetCode() ) retval++; @@ -884,7 +854,7 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const && PgmOrNull() && !PgmOrNull()->m_Printing; // Check segments, dimensions, texts, and fiducials - for( auto item : m_drawings ) + for( BOARD_ITEM* item : m_drawings ) { if( aBoardEdgesOnly && ( item->GetLayer() != Edge_Cuts ) ) continue; @@ -894,14 +864,14 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const } // Check modules - for( auto module : m_modules ) + for( MODULE* module : m_modules ) { if( !( module->GetLayerSet() & visible ).any() ) continue; if( aBoardEdgesOnly ) { - for( const auto edge : module->GraphicalItems() ) + for( const BOARD_ITEM* edge : module->GraphicalItems() ) { if( edge->GetLayer() == Edge_Cuts ) area.Merge( edge->GetBoundingBox() ); @@ -916,14 +886,14 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const if( !aBoardEdgesOnly ) { // Check tracks - for( auto track : m_tracks ) + for( TRACK* track : m_tracks ) { if( ( track->GetLayerSet() & visible ).any() ) area.Merge( track->GetBoundingBox() ); } // Check zones - for( auto aZone : m_ZoneDescriptorList ) + for( ZONE_CONTAINER* aZone : m_zones ) { if( ( aZone->GetLayerSet() & visible ).any() ) area.Merge( aZone->GetBoundingBox() ); @@ -940,7 +910,7 @@ void BOARD::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector int viasCount = 0; int trackSegmentsCount = 0; - for( auto item : m_tracks ) + for( TRACK* item : m_tracks ) { if( item->Type() == PCB_VIA_T ) viasCount++; @@ -972,8 +942,8 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s { KICAD_T stype; SEARCH_RESULT result = SEARCH_RESULT::CONTINUE; - const KICAD_T* p = scanTypes; - bool done = false; + const KICAD_T* p = scanTypes; + bool done = false; #if 0 && defined(DEBUG) std::cout << GetClass().mb_str() << ' '; @@ -1052,51 +1022,8 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s break; } - ; break; -#if 0 // both these are on same list, so we must scan it twice in order - // to get VIA priority, using new #else code below. - // But we are not using separate lists for TRACKs and VIA, because - // items are ordered (sorted) in the linked - // list by netcode AND by physical distance: - // when created, if a track or via is connected to an existing track or - // via, it is put in linked list after this existing track or via - // So usually, connected tracks or vias are grouped in this list - // So the algorithm (used in ratsnest computations) which computes the - // track connectivity is faster (more than 100 time regarding to - // a non ordered list) because when it searches for a connection, first - // it tests the near (near in term of linked list) 50 items - // from the current item (track or via) in test. - // Usually, because of this sort, a connected item (if exists) is - // found. - // If not found (and only in this case) an exhaustive (and time - // consuming) search is made, but this case is statistically rare. - case PCB_VIA_T: - case PCB_TRACE_T: - case PCB_ARC_T: - result = IterateForward( m_Track, inspector, testData, p ); - - // skip over any types handled in the above call. - for( ; ; ) - { - switch( stype = *++p ) - { - case PCB_VIA_T: - case PCB_TRACE_T: - case PCB_ARC_T: - continue; - - default: - ; - } - - break; - } - - break; - -#else case PCB_VIA_T: result = IterateForward( m_tracks, inspector, testData, p ); ++p; @@ -1107,14 +1034,11 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s result = IterateForward( m_tracks, inspector, testData, p ); ++p; break; -#endif case PCB_MARKER_T: - - // MARKER_PCBS are in the m_markers std::vector - for( unsigned i = 0; iVisit( inspector, testData, p ); + result = marker->Visit( inspector, testData, p ); if( result == SEARCH_RESULT::QUIT ) break; @@ -1124,11 +1048,9 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T s break; case PCB_ZONE_AREA_T: - - // PCB_ZONE_AREA_T are in the m_ZoneDescriptorList std::vector - for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i ) + for( ZONE_CONTAINER* zone : m_zones) { - result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p ); + result = zone->Visit( inspector, testData, p ); if( result == SEARCH_RESULT::QUIT ) break; @@ -1183,18 +1105,18 @@ MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const // search only for MODULES static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT }; - INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData ) - { - MODULE* module = (MODULE*) item; + INSPECTOR_FUNC inspector = [&]( EDA_ITEM* item, void* testData ) + { + MODULE* module = (MODULE*) item; - if( aReference == module->GetReference() ) - { - found = module; - return SEARCH_RESULT::QUIT; - } + if( aReference == module->GetReference() ) + { + found = module; + return SEARCH_RESULT::QUIT; + } - return SEARCH_RESULT::CONTINUE; - }; + return SEARCH_RESULT::CONTINUE; + }; // visit this BOARD with the above inspector BOARD* nonconstMe = (BOARD*) this; @@ -1356,30 +1278,28 @@ int BOARD::SetAreasNetCodesFromNetNames() { int error_count = 0; - for( int ii = 0; ii < GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : Zones() ) { - ZONE_CONTAINER* it = GetArea( ii ); - - if( !it->IsOnCopperLayer() ) + if( !zone->IsOnCopperLayer() ) { - it->SetNetCode( NETINFO_LIST::UNCONNECTED ); + zone->SetNetCode( NETINFO_LIST::UNCONNECTED ); continue; } - if( it->GetNetCode() != 0 ) // i.e. if this zone is connected to a net + if( zone->GetNetCode() != 0 ) // i.e. if this zone is connected to a net { - const NETINFO_ITEM* net = it->GetNet(); + const NETINFO_ITEM* net = zone->GetNet(); if( net ) { - it->SetNetCode( net->GetNet() ); + zone->SetNetCode( net->GetNet() ); } else { error_count++; // keep Net Name and set m_NetCode to -1 : error flag. - it->SetNetCode( -1 ); + zone->SetNetCode( -1 ); } } } @@ -1683,19 +1603,15 @@ std::list BOARD::GetZoneList( bool aIncludeZonesInFootprints ) { std::list zones; - for( int ii = 0; ii < GetAreaCount(); ii++ ) - { - zones.push_back( GetArea( ii ) ); - } + for( ZONE_CONTAINER* zone : Zones() ) + zones.push_back( zone ); if( aIncludeZonesInFootprints ) { for( MODULE* mod : m_modules ) { for( MODULE_ZONE_CONTAINER* zone : mod->Zones() ) - { zones.push_back( zone ); - } } } @@ -1706,10 +1622,17 @@ std::list BOARD::GetZoneList( bool aIncludeZonesInFootprints ) ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch ) { - ZONE_CONTAINER* new_area = InsertArea( aNetcode, - m_ZoneDescriptorList.size( ) - 1, - aLayer, aStartPointPosition.x, - aStartPointPosition.y, aHatch ); + ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this ); + + new_area->SetNetCode( aNetcode ); + new_area->SetLayer( aLayer ); + + m_zones.push_back( new_area ); + + new_area->SetHatchStyle( (ZONE_BORDER_DISPLAY_STYLE) aHatch ); + + // Add the first corner to the new zone + new_area->AppendCorner( aStartPointPosition, -1 ); if( aNewZonesList ) { @@ -1739,32 +1662,10 @@ void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to } -ZONE_CONTAINER* BOARD::InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer, int aCornerX, - int aCornerY, ZONE_BORDER_DISPLAY_STYLE aHatch ) -{ - ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this ); - - new_area->SetNetCode( aNetcode ); - new_area->SetLayer( aLayer ); - - if( aAreaIdx < (int) ( m_ZoneDescriptorList.size() - 1 ) ) - m_ZoneDescriptorList.insert( m_ZoneDescriptorList.begin() + aAreaIdx + 1, new_area ); - else - m_ZoneDescriptorList.push_back( new_area ); - - new_area->SetHatchStyle( (ZONE_BORDER_DISPLAY_STYLE) aHatch ); - - // Add the first corner to the new zone - new_area->AppendCorner( wxPoint( aCornerX, aCornerY ), -1 ); - - return new_area; -} - - bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAINER* aCurrArea ) { // mark all areas as unmodified except this one, if modified - for( ZONE_CONTAINER* zone : m_ZoneDescriptorList ) + for( ZONE_CONTAINER* zone : m_zones ) zone->SetLocalFlags( 0 ); aCurrArea->SetLocalFlags( 1 ); @@ -1816,8 +1717,8 @@ bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAI * return true if success, false if a contour is not valid */ extern bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, - wxString* aErrorText, unsigned int aTolerance, - wxPoint* aErrorLocation = nullptr ); + wxString* aErrorText, unsigned int aTolerance, + wxPoint* aErrorLocation = nullptr ); bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, wxString* aErrorText, @@ -1851,58 +1752,28 @@ unsigned BOARD::GetPadCount() { unsigned retval = 0; - for( auto mod : Modules() ) + for( MODULE* mod : Modules() ) retval += mod->Pads().size(); return retval; } -/** - * Function GetPad - * @return D_PAD* - at the \a aIndex - */ -D_PAD* BOARD::GetPad( unsigned aIndex ) const -{ - unsigned count = 0; - - for( auto mod : m_modules ) - { - for( auto pad : mod->Pads() ) - { - if( count == aIndex ) - return pad; - - count++; - } - } - - return nullptr; -} - - const std::vector BOARD::AllConnectedItems() { std::vector items; - for( auto track : Tracks() ) - { + for( TRACK* track : Tracks() ) items.push_back( track ); - } - for( auto mod : Modules() ) + for( MODULE* mod : Modules() ) { - for( auto pad : mod->Pads() ) - { + for( D_PAD* pad : mod->Pads() ) items.push_back( pad ); - } } - for( int i = 0; iGetItems().find( toFind ) != group->GetItems().end() ) { if( scope == group && candidate != NULL ) diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index b59fe4a904..2a9d08f3d1 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -186,7 +186,7 @@ private: MODULES m_modules; TRACKS m_tracks; GROUPS m_groups; - ZONE_CONTAINERS m_ZoneDescriptorList; + ZONE_CONTAINERS m_zones; LAYER m_Layer[PCB_LAYER_ID_COUNT]; @@ -251,7 +251,8 @@ public: DRAWINGS& Drawings() { return m_drawings; } - ZONE_CONTAINERS& Zones() { return m_ZoneDescriptorList; } + ZONE_CONTAINERS& Zones() { return m_zones; } + const ZONE_CONTAINERS& Zones() const { return m_zones; } MARKERS& Markers() { return m_markers; } @@ -290,8 +291,7 @@ public: bool IsEmpty() const { - return m_drawings.empty() && m_modules.empty() && m_tracks.empty() && - m_ZoneDescriptorList.empty(); + return m_drawings.empty() && m_modules.empty() && m_tracks.empty() && m_zones.empty(); } void Move( const wxPoint& aMoveVector ) override; @@ -353,13 +353,7 @@ public: void DeleteMARKERs( bool aWarningsAndErrors, bool aExclusions ); - /** - * Function DeleteZONEOutlines - * deletes ALL zone outlines from the board. - */ - void DeleteZONEOutlines(); - - PROJECT* GetProject() const { return m_project; } + PROJECT* GetProject() const { return m_project; } /** * Links a board to a given project. Should be called immediately after loading board in @@ -681,12 +675,6 @@ public: */ unsigned GetPadCount(); - /** - * Function GetPad - * @return D_PAD* - at the \a aIndex - */ - D_PAD* GetPad( unsigned aIndex ) const; - /** * Function GetPads * returns a reference to a list of all the pads. The returned list is not @@ -870,7 +858,7 @@ public: * @return : error count * For non copper areas, netcode is set to 0 */ - int SetAreasNetCodesFromNetNames( void ); + int SetAreasNetCodesFromNetNames(); /** * Function GetArea @@ -880,29 +868,12 @@ public: */ ZONE_CONTAINER* GetArea( int index ) const { - if( (unsigned) index < m_ZoneDescriptorList.size() ) - return m_ZoneDescriptorList[index]; + if( (unsigned) index < m_zones.size() ) + return m_zones[index]; return NULL; } - /** - * Function GetAreaIndex - * returns the Area Index for the given Zone Container. - * @param aArea :The ZONE_CONTAINER to find. - * @return an Area Index in m_ZoneDescriptorList or -1 if non found. - */ - int GetAreaIndex( const ZONE_CONTAINER* aArea ) const - { - for( int ii = 0; ii < GetAreaCount(); ii++ ) // Search for aArea in list - { - if( aArea == GetArea( ii ) ) // Found ! - return ii; - } - - return -1; - } - /** * Function GetZoneList * @return a std::list of pointers to all board zones (possibly including zones in footprints) @@ -915,7 +886,7 @@ public: */ int GetAreaCount() const { - return static_cast( m_ZoneDescriptorList.size() ); + return static_cast( m_zones.size() ); } /* Functions used in test, merge and cut outlines */ @@ -934,19 +905,6 @@ public: ZONE_CONTAINER* AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, ZONE_BORDER_DISPLAY_STYLE aHatch ); - /** - * Add a copper area to net, inserting after m_ZoneDescriptorList[aAreaIdx] - * @param aNetcode is the netcode of the new copper zone - * @param aAreaIdx is the netcode of the new copper zone - * @param aLayer is the copper layer id of the new copper zone - * @param aCornerX,aCornerY is the coordinate of the first corner - * (a zone cannot have a empty outline) - * @param aHatch is the hatch option - * @return pointer to the new area - */ - ZONE_CONTAINER* InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer, int aCornerX, - int aCornerY, ZONE_BORDER_DISPLAY_STYLE aHatch ); - /** * Function NormalizeAreaPolygon * Process an area that has been modified, by normalizing its polygon against itself. @@ -1004,7 +962,6 @@ public: /** * Function TestAreaIntersection * Test for intersection of 2 copper areas - * area_to_test must be after area_ref in m_ZoneDescriptorList * @param area_ref = area reference * @param area_to_test = area to compare for intersection calculations * @return : false if no intersection, true if intersection diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index a113ad3555..c1656aecd5 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -47,18 +47,18 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = { // all items in m_Drawings for instance should be contiguous. // *** all items in a same list (shown here) must be contiguous **** PCB_MARKER_T, // in m_markers - PCB_TEXT_T, // in m_Drawings - PCB_LINE_T, // in m_Drawings - PCB_DIMENSION_T, // in m_Drawings - PCB_TARGET_T, // in m_Drawings - PCB_VIA_T, // in m_Tracks - PCB_TRACE_T, // in m_Tracks - PCB_ARC_T, // in m_Tracks + PCB_TEXT_T, // in m_drawings + PCB_LINE_T, // in m_drawings + PCB_DIMENSION_T, // in m_drawings + PCB_TARGET_T, // in m_drawings + PCB_VIA_T, // in m_tracks + PCB_TRACE_T, // in m_tracks + PCB_ARC_T, // in m_tracks PCB_PAD_T, // in modules PCB_MODULE_TEXT_T, // in modules - PCB_MODULE_T, // in m_Modules - PCB_GROUP_T, // in m_Groups ? - PCB_ZONE_AREA_T, // in m_ZoneDescriptorList + PCB_MODULE_T, // in m_modules + PCB_GROUP_T, // in m_groups + PCB_ZONE_AREA_T, // in m_zones EOT }; diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index 69621b990d..20342dab7d 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -394,24 +394,17 @@ const CN_CONNECTIVITY_ALGO::CLUSTERS CN_CONNECTIVITY_ALGO::SearchClusters( CLUST void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard ) { - for( int i = 0; iGetAreaCount(); i++ ) - { - auto zone = aBoard->GetArea( i ); + for( ZONE_CONTAINER* zone : aBoard->Zones() ) Add( zone ); - } - for( auto tv : aBoard->Tracks() ) + for( TRACK* tv : aBoard->Tracks() ) Add( tv ); - for( auto mod : aBoard->Modules() ) + for( MODULE* mod : aBoard->Modules() ) { - for( auto pad : mod->Pads() ) + for( D_PAD* pad : mod->Pads() ) Add( pad ); } - - /*wxLogTrace( "CN", "zones : %lu, pads : %lu vias : %lu tracks : %lu\n", - m_zoneList.Size(), m_padList.Size(), - m_viaList.Size(), m_trackList.Size() );*/ } diff --git a/pcbnew/dialogs/dialog_copper_zones.cpp b/pcbnew/dialogs/dialog_copper_zones.cpp index 11aac57532..0b548664ee 100644 --- a/pcbnew/dialogs/dialog_copper_zones.cpp +++ b/pcbnew/dialogs/dialog_copper_zones.cpp @@ -503,10 +503,8 @@ void DIALOG_COPPER_ZONE::ExportSetupToOtherCopperZones( wxCommandEvent& event ) // Export settings ( but layer and netcode ) to others copper zones BOARD* pcb = m_Parent->GetBoard(); - for( int ii = 0; ii < pcb->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : pcb->Zones() ) { - ZONE_CONTAINER* zone = pcb->GetArea( ii ); - // Cannot export settings from a copper zone // to a zone keepout: if( zone->GetIsKeepout() ) diff --git a/pcbnew/exporters/export_hyperlynx.cpp b/pcbnew/exporters/export_hyperlynx.cpp index c4b7991063..03923037da 100644 --- a/pcbnew/exporters/export_hyperlynx.cpp +++ b/pcbnew/exporters/export_hyperlynx.cpp @@ -563,10 +563,8 @@ const std::vector HYPERLYNX_EXPORTER::collectNetObjects( int netcod rv.push_back( item ); } - for( int i = 0; i < m_board->GetAreaCount(); i++ ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - ZONE_CONTAINER* zone = m_board->GetArea( i ); - if( check( zone ) ) rv.push_back( zone ); } diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp index df71f4baf0..915cc43971 100644 --- a/pcbnew/exporters/export_vrml.cpp +++ b/pcbnew/exporters/export_vrml.cpp @@ -1024,10 +1024,8 @@ static void export_vrml_tracks( MODEL_VRML& aModel, BOARD* pcb ) static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb, COMMIT* aCommit ) { - for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : aPcb->Zones() ) { - ZONE_CONTAINER* zone = aPcb->GetArea( ii ); - for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { VRML_LAYER* vl; diff --git a/pcbnew/exporters/gerber_jobfile_writer.cpp b/pcbnew/exporters/gerber_jobfile_writer.cpp index 424b040a8c..e2f2b962ac 100644 --- a/pcbnew/exporters/gerber_jobfile_writer.cpp +++ b/pcbnew/exporters/gerber_jobfile_writer.cpp @@ -516,10 +516,8 @@ void GERBER_JOBFILE_WRITER::addJSONDesignRules() minclearanceOuter = INT_MAX; minclearanceInner = INT_MAX; - for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : m_pcb->Zones() ) { - ZONE_CONTAINER* zone = m_pcb->GetArea( ii ); - if( zone->GetIsKeepout() || !zone->IsOnCopperLayer() ) continue; diff --git a/pcbnew/netinfo_list.cpp b/pcbnew/netinfo_list.cpp index 820ddaf0a2..6d08f00856 100644 --- a/pcbnew/netinfo_list.cpp +++ b/pcbnew/netinfo_list.cpp @@ -22,10 +22,10 @@ */ #include -#include -#include -#include -#include +//#include +//#include +//#include +//#include #include #include #include @@ -170,6 +170,7 @@ void NETINFO_LIST::Show() const { int i = 0; NETNAMES_MAP::const_iterator it, itEnd; + for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it ) { wxLogDebug( "[%d]: netcode:%d netname:<%s>\n", @@ -183,7 +184,8 @@ void NETINFO_LIST::Show() const int NETINFO_LIST::getFreeNetCode() { - do { + do + { if( m_newNetCode < 0 ) m_newNetCode = 0; } while( m_netCodes.count( ++m_newNetCode ) != 0 ); @@ -213,20 +215,18 @@ void NETINFO_MAPPING::Update() nets.insert( 0 ); // Zones - for( int i = 0; i < m_board->GetAreaCount(); ++i ) - nets.insert( m_board->GetArea( i )->GetNetCode() ); + for( ZONE_CONTAINER* zone : m_board->Zones() ) + nets.insert( zone->GetNetCode() ); // Tracks - for( auto track : m_board->Tracks() ) + for( TRACK* track : m_board->Tracks() ) nets.insert( track->GetNetCode() ); // Modules/pads - for( auto module : m_board->Modules() ) + for( MODULE* module : m_board->Modules() ) { - for( auto pad : module->Pads() ) - { + for( D_PAD* pad : module->Pads() ) nets.insert( pad->GetNetCode() ); - } } // Prepare the new mapping @@ -235,8 +235,9 @@ void NETINFO_MAPPING::Update() // Now the nets variable stores all the used net codes (not only for pads) and we are ready to // assign new consecutive net numbers int newNetCode = 0; - for( std::set::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it ) - m_netMapping[*it] = newNetCode++; + + for( auto net : nets ) + m_netMapping[net] = newNetCode++; } diff --git a/pcbnew/netlist_reader/board_netlist_updater.cpp b/pcbnew/netlist_reader/board_netlist_updater.cpp index 6e27754097..15fbc5f801 100644 --- a/pcbnew/netlist_reader/board_netlist_updater.cpp +++ b/pcbnew/netlist_reader/board_netlist_updater.cpp @@ -481,10 +481,8 @@ bool BOARD_NETLIST_UPDATER::updateComponentPadConnections( MODULE* aPcbComponent void BOARD_NETLIST_UPDATER::cacheCopperZoneConnections() { - for( int ii = 0; ii < m_board->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - ZONE_CONTAINER* zone = m_board->GetArea( ii ); - if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() ) continue; @@ -556,10 +554,8 @@ bool BOARD_NETLIST_UPDATER::updateCopperZoneNets( NETLIST& aNetlist ) } // Test copper zones to detect "dead" nets (nets without any pad): - for( int i = 0; i < m_board->GetAreaCount(); i++ ) + for( ZONE_CONTAINER* zone : m_board->Zones() ) { - ZONE_CONTAINER* zone = m_board->GetArea( i ); - if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() ) continue; diff --git a/pcbnew/swig/pcbnew_action_plugins.cpp b/pcbnew/swig/pcbnew_action_plugins.cpp index b8f7e54c1a..1f889d4079 100644 --- a/pcbnew/swig/pcbnew_action_plugins.cpp +++ b/pcbnew/swig/pcbnew_action_plugins.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,22 +21,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file pcbnew_action_plugins.cpp - * @brief Class PCBNEW_PYTHON_ACTION_PLUGINS - */ - #include "pcbnew_action_plugins.h" -#include #include -#include #include #include #include -#include -#include #include -#include #include #include #include @@ -220,30 +210,30 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) itemsList.m_Status = UNDO_REDO::CHANGED; // Append tracks: - for( auto item : currentPcb->Tracks() ) + for( TRACK* item : currentPcb->Tracks() ) { ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED ); itemsList.PushItem( picker ); } // Append modules: - for( auto item : currentPcb->Modules() ) + for( MODULE* item : currentPcb->Modules() ) { ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED ); itemsList.PushItem( picker ); } // Append drawings - for( auto item : currentPcb->Drawings() ) + for( BOARD_ITEM* item : currentPcb->Drawings() ) { ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED ); itemsList.PushItem( picker ); } // Append zones outlines - for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : currentPcb->Zones() ) { - ITEM_PICKER picker( nullptr, (EDA_ITEM*) currentPcb->GetArea( ii ), UNDO_REDO::CHANGED ); + ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED ); itemsList.PushItem( picker ); } @@ -278,6 +268,7 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) // The list of existing items after running the action script std::set currItemList; + // Append tracks: for( TRACK* item : currentPcb->Tracks() ) currItemList.insert( item ); @@ -291,8 +282,8 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) currItemList.insert( item ); // Append zones outlines - for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ ) - currItemList.insert( currentPcb->GetArea( ii ) ); + for( ZONE_CONTAINER* zone : currentPcb->Zones() ) + currItemList.insert( zone ); // Found deleted modules for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ ) @@ -340,11 +331,11 @@ void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin ) } } - for( int ii = 0; ii < currentPcb->GetAreaCount(); ii++ ) + for( ZONE_CONTAINER* zone : currentPcb->Zones() ) { - if( !oldBuffer->ContainsItem( (EDA_ITEM*) currentPcb->GetArea( ii ) ) ) + if( !oldBuffer->ContainsItem( zone ) ) { - ITEM_PICKER picker( nullptr, (EDA_ITEM*) currentPcb->GetArea( ii ), UNDO_REDO::NEWITEM ); + ITEM_PICKER picker( nullptr, zone, UNDO_REDO::NEWITEM ); oldBuffer->PushItem( picker ); } } @@ -387,13 +378,12 @@ void PCB_EDIT_FRAME::buildActionPluginMenus( ACTION_MENU* actionMenu ) void PCB_EDIT_FRAME::AddActionPluginTools() { bool need_separator = true; - const auto& orderedPlugins = GetOrderedActionPlugins(); + const std::vector& orderedPlugins = GetOrderedActionPlugins(); - for( const auto& ap : orderedPlugins ) + for( ACTION_PLUGIN* ap : orderedPlugins ) { if( GetActionPluginButtonVisible( ap->GetPluginPath(), ap->GetShowToolbarButton() ) ) { - if( need_separator ) { m_mainToolBar->AddScaledSeparator( this ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 11756caca1..ff15bef4b2 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -199,8 +199,8 @@ int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent ) m_frame->SetDisplayOptions( opts ); - for( int i = 0; i < board()->GetAreaCount(); ++i ) - view()->Update( board()->GetArea( i ), KIGFX::GEOMETRY ); + for( ZONE_CONTAINER* zone : board()->Zones() ) + view()->Update( zone, KIGFX::GEOMETRY ); canvas()->Refresh(); diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 70dbe619dd..cf97b62856 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -98,11 +98,8 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE_CONTAINER* aZone ) wxBusyCursor dummy; // Undraw old zone outlines - for( int ii = 0; ii < GetBoard()->GetAreaCount(); ii++ ) - { - ZONE_CONTAINER* edge_zone = GetBoard()->GetArea( ii ); - GetCanvas()->GetView()->Update( edge_zone ); - } + for( ZONE_CONTAINER* zone : GetBoard()->Zones() ) + GetCanvas()->GetView()->Update( zone ); zoneInfo.ExportSetting( *aZone ); diff --git a/pcbnew/zones_test_and_combine_areas.cpp b/pcbnew/zones_test_and_combine_areas.cpp index decc1e3a5b..dbf1a818e7 100644 --- a/pcbnew/zones_test_and_combine_areas.cpp +++ b/pcbnew/zones_test_and_combine_areas.cpp @@ -31,17 +31,8 @@ */ #include -#include -#include -#include - #include #include -#include - -#include -#include -#include bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList, @@ -59,13 +50,9 @@ bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList, // Test for bad areas: all zones must have more than 2 corners: // Note: should not happen, but just in case. - for( unsigned ii = 0; ii < m_ZoneDescriptorList.size(); ) + for( ZONE_CONTAINER* zone : m_zones ) { - ZONE_CONTAINER* zone = m_ZoneDescriptorList[ii]; - - if( zone->GetNumCorners() >= 3 ) - ii++; - else // Remove zone because it is incorrect: + if( zone->GetNumCorners() < 3 ) RemoveArea( aModifiedZonesList, zone ); } @@ -76,15 +63,15 @@ bool BOARD::OnAreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList, bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, bool aUseLocalFlags ) { - if( m_ZoneDescriptorList.size() <= 1 ) + if( m_zones.size() <= 1 ) return false; bool modified = false; // Loop through all combinations - for( unsigned ia1 = 0; ia1 < m_ZoneDescriptorList.size() - 1; ia1++ ) + for( unsigned ia1 = 0; ia1 < m_zones.size() - 1; ia1++ ) { - ZONE_CONTAINER* curr_area = m_ZoneDescriptorList[ia1]; + ZONE_CONTAINER* curr_area = m_zones[ia1]; if( curr_area->GetNetCode() != aNetCode ) continue; @@ -93,9 +80,9 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, BOX2I b1 = curr_area->Outline()->BBox(); bool mod_ia1 = false; - for( unsigned ia2 = m_ZoneDescriptorList.size() - 1; ia2 > ia1; ia2-- ) + for( unsigned ia2 = m_zones.size() - 1; ia2 > ia1; ia2-- ) { - ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2]; + ZONE_CONTAINER* area2 = m_zones[ia2]; if( area2->GetNetCode() != aNetCode ) continue; @@ -141,10 +128,8 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test ) { - for( unsigned ia2 = 0; ia2 < m_ZoneDescriptorList.size(); ia2++ ) + for( ZONE_CONTAINER* area2 : m_zones) { - ZONE_CONTAINER* area2 = m_ZoneDescriptorList[ia2]; - if( area_to_test->GetNetCode() != area2->GetNetCode() ) continue; @@ -289,7 +274,7 @@ bool BOARD::CombineAreas( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_ // but we should never have more than 2 polys if( mergedOutlines.OutlineCount() > 2 ) { - wxLogMessage(wxT("BOARD::CombineAreas error: more than 2 polys after merging") ); + wxLogMessage( "BOARD::CombineAreas error: more than 2 polys after merging" ); return false; } diff --git a/qa/drc_proto/drc_test_provider_copper_clearance.cpp b/qa/drc_proto/drc_test_provider_copper_clearance.cpp index fd272b3045..d8f95337cd 100644 --- a/qa/drc_proto/drc_test_provider_copper_clearance.cpp +++ b/qa/drc_proto/drc_test_provider_copper_clearance.cpp @@ -668,7 +668,6 @@ void test::DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones() for( int ii = 0; ii < m_board->GetAreaCount(); ii++ ) { - ZONE_CONTAINER* zone = m_board->GetArea( ii ); ZONE_CONTAINER* zoneRef = m_board->GetArea( ii ); zoneRef->BuildSmoothedPoly( smoothed_polys[ii], zoneRef->GetLayer() );