From 21728106000c7181b29456570d5c2aed65310a22 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 15 Feb 2022 17:34:38 +0000 Subject: [PATCH] Performance: better sharing of zone fills. --- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 2 +- pcbnew/connectivity/connectivity_algo.cpp | 8 +-- pcbnew/connectivity/connectivity_items.cpp | 10 +-- pcbnew/connectivity/connectivity_items.h | 10 ++- ...drc_test_provider_mechanical_clearance.cpp | 2 +- .../drc/drc_test_provider_sliver_checker.cpp | 2 +- pcbnew/drc/drc_test_provider_solder_mask.cpp | 2 +- .../drc_test_provider_zone_connections.cpp | 10 +-- pcbnew/exporters/export_hyperlynx.cpp | 2 +- pcbnew/footprint.cpp | 2 +- pcbnew/pcb_painter.cpp | 6 +- pcbnew/plot_board_layers.cpp | 2 +- .../cadstar/cadstar_pcb_archive_loader.cpp | 13 ++-- pcbnew/plugins/kicad/pcb_plugin.cpp | 6 +- pcbnew/zone.cpp | 63 ++++++++++--------- pcbnew/zone.h | 8 +-- pcbnew/zone_filler.cpp | 22 +++---- qa/pcbnew/test_zone_filler.cpp | 4 +- .../polygon_triangulation.cpp | 2 +- 19 files changed, 87 insertions(+), 89 deletions(-) diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index 781188de03..55e3cbb048 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -644,7 +644,7 @@ void BOARD_ADAPTER::addSolidAreasShapes( const ZONE* aZone, CONTAINER_2D_BASE* a PCB_LAYER_ID aLayerId ) { // Copy the polys list because we have to simplify it - SHAPE_POLY_SET polyList = SHAPE_POLY_SET( aZone->GetFilledPolysList( aLayerId ) ); + SHAPE_POLY_SET polyList = SHAPE_POLY_SET( *aZone->GetFilledPolysList( aLayerId ) ); // This convert the poly in outline and holes ConvertPolygonToTriangles( polyList, *aContainer, m_biuTo3Dunits, *aZone ); diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index c3dae75dd3..39b5f67a05 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -592,7 +592,7 @@ void CN_CONNECTIVITY_ALGO::PropagateNets( BOARD_COMMIT* aCommit, PROPAGATE_MODE void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands( ZONE* aZone, PCB_LAYER_ID aLayer, std::vector& aIslands ) { - if( aZone->GetFilledPolysList( aLayer ).IsEmpty() ) + if( aZone->GetFilledPolysList( aLayer )->IsEmpty() ) return; aIslands.clear(); @@ -644,7 +644,7 @@ void CN_CONNECTIVITY_ALGO::FindIsolatedCopperIslands( std::vectorGetLayerSet().Seq() ) { - if( zone.m_zone->GetFilledPolysList( layer ).IsEmpty() ) + if( zone.m_zone->GetFilledPolysList( layer )->IsEmpty() ) continue; for( const std::shared_ptr& cluster : m_connClusters ) @@ -732,7 +732,7 @@ void CN_VISITOR::checkZoneZoneConnection( CN_ZONE_LAYER* aZoneLayerA, CN_ZONE_LA return; const SHAPE_LINE_CHAIN& outline = - zoneA->GetFilledPolysList( layer ).COutline( aZoneLayerA->SubpolyIndex() ); + zoneA->GetFilledPolysList( layer )->COutline( aZoneLayerA->SubpolyIndex() ); for( int i = 0; i < outline.PointCount(); i++ ) { @@ -748,7 +748,7 @@ void CN_VISITOR::checkZoneZoneConnection( CN_ZONE_LAYER* aZoneLayerA, CN_ZONE_LA } const SHAPE_LINE_CHAIN& outline2 = - zoneB->GetFilledPolysList( layer ).COutline( aZoneLayerB->SubpolyIndex() ); + zoneB->GetFilledPolysList( layer )->COutline( aZoneLayerB->SubpolyIndex() ); for( int i = 0; i < outline2.PointCount(); i++ ) { diff --git a/pcbnew/connectivity/connectivity_items.cpp b/pcbnew/connectivity/connectivity_items.cpp index 3b0c263c50..20cd5655c2 100644 --- a/pcbnew/connectivity/connectivity_items.cpp +++ b/pcbnew/connectivity/connectivity_items.cpp @@ -93,7 +93,7 @@ int CN_ZONE_LAYER::AnchorCount() const return 0; const ZONE* zone = static_cast( Parent() ); - const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer ).COutline( m_subpolyIndex ); + const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer )->COutline( m_subpolyIndex ); return outline.PointCount() ? 1 : 0; } @@ -105,7 +105,7 @@ const VECTOR2I CN_ZONE_LAYER::GetAnchor( int n ) const return VECTOR2I(); const ZONE* zone = static_cast( Parent() ); - const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer ).COutline( m_subpolyIndex ); + const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( m_layer )->COutline( m_subpolyIndex ); return outline.CPoint( 0 ); } @@ -199,14 +199,14 @@ CN_ITEM* CN_LIST::Add( PCB_ARC* aArc ) const std::vector CN_LIST::Add( ZONE* zone, PCB_LAYER_ID aLayer ) { - const auto& polys = zone->GetFilledPolysList( aLayer ); + const std::shared_ptr& polys = zone->GetFilledPolysList( aLayer ); std::vector rv; - for( int j = 0; j < polys.OutlineCount(); j++ ) + for( int j = 0; j < polys->OutlineCount(); j++ ) { CN_ZONE_LAYER* zitem = new CN_ZONE_LAYER( zone, aLayer, false, j ); - const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( aLayer ).COutline( j ); + const SHAPE_LINE_CHAIN& outline = zone->GetFilledPolysList( aLayer )->COutline( j ); for( int k = 0; k < outline.PointCount(); k++ ) zitem->AddAnchor( outline.CPoint( k ) ); diff --git a/pcbnew/connectivity/connectivity_items.h b/pcbnew/connectivity/connectivity_items.h index d884d49858..d5d3d53eb9 100644 --- a/pcbnew/connectivity/connectivity_items.h +++ b/pcbnew/connectivity/connectivity_items.h @@ -290,13 +290,11 @@ public: m_subpolyIndex( aSubpolyIndex ), m_layer( aLayer ) { - const SHAPE_POLY_SET& fill = aParent->GetFilledPolysList( aLayer ); + m_triangulatedPoly = aParent->GetFilledPolysList( aLayer ); - m_triangulatedPoly = fill; - - for( unsigned int ii = 0; ii < m_triangulatedPoly.TriangulatedPolyCount(); ++ii ) + for( unsigned int ii = 0; ii < m_triangulatedPoly->TriangulatedPolyCount(); ++ii ) { - const auto* triangleSet = m_triangulatedPoly.TriangulatedPolygon( ii ); + const auto* triangleSet = m_triangulatedPoly->TriangulatedPolygon( ii ); if( triangleSet->GetSourceOutlineIndex() != aSubpolyIndex ) continue; @@ -373,7 +371,7 @@ private: std::vector m_testOutlinePoints; int m_subpolyIndex; PCB_LAYER_ID m_layer; - SHAPE_POLY_SET m_triangulatedPoly; + std::shared_ptr m_triangulatedPoly; RTree m_rTree; }; diff --git a/pcbnew/drc/drc_test_provider_mechanical_clearance.cpp b/pcbnew/drc/drc_test_provider_mechanical_clearance.cpp index cd936c916c..3466c78da8 100644 --- a/pcbnew/drc/drc_test_provider_mechanical_clearance.cpp +++ b/pcbnew/drc/drc_test_provider_mechanical_clearance.cpp @@ -519,7 +519,7 @@ void DRC_TEST_PROVIDER_MECHANICAL_CLEARANCE::testZoneLayer( ZONE* aZone, PCB_LAY { int epsilon = m_board->GetDesignSettings().GetDRCEpsilon(); int clearance = aConstraint.GetValue().Min(); - SHAPE_POLY_SET fill = aZone->GetFilledPolysList( aLayer ); + SHAPE_POLY_SET fill = *aZone->GetFilledPolysList( aLayer ); if( aConstraint.GetSeverity() == RPT_SEVERITY_IGNORE || clearance - epsilon <= 0 ) return; diff --git a/pcbnew/drc/drc_test_provider_sliver_checker.cpp b/pcbnew/drc/drc_test_provider_sliver_checker.cpp index 94e7129783..d18ef14d28 100644 --- a/pcbnew/drc/drc_test_provider_sliver_checker.cpp +++ b/pcbnew/drc/drc_test_provider_sliver_checker.cpp @@ -115,7 +115,7 @@ bool DRC_TEST_PROVIDER_SLIVER_CHECKER::Run() { ZONE* zone = static_cast( item ); - poly.BooleanAdd( zone->GetFilledPolysList( layer ), + poly.BooleanAdd( *zone->GetFilledPolysList( layer ), SHAPE_POLY_SET::PM_FAST ); } else diff --git a/pcbnew/drc/drc_test_provider_solder_mask.cpp b/pcbnew/drc/drc_test_provider_solder_mask.cpp index 9428d863a9..acaaf7e00c 100644 --- a/pcbnew/drc/drc_test_provider_solder_mask.cpp +++ b/pcbnew/drc/drc_test_provider_solder_mask.cpp @@ -117,7 +117,7 @@ void DRC_TEST_PROVIDER_SOLDER_MASK::addItemToRTrees( BOARD_ITEM* item ) { if( zone->IsOnLayer( layer ) ) { - solderMask->GetFill( layer )->BooleanAdd( zone->GetFilledPolysList( layer ), + solderMask->GetFill( layer )->BooleanAdd( *zone->GetFilledPolysList( layer ), SHAPE_POLY_SET::PM_FAST ); } } diff --git a/pcbnew/drc/drc_test_provider_zone_connections.cpp b/pcbnew/drc/drc_test_provider_zone_connections.cpp index 2601e2fb5d..aebb43660a 100644 --- a/pcbnew/drc/drc_test_provider_zone_connections.cpp +++ b/pcbnew/drc/drc_test_provider_zone_connections.cpp @@ -97,7 +97,7 @@ bool DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run() for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { - const SHAPE_POLY_SET& zoneFill = zone->GetFilledPolysList( layer ); + const std::shared_ptr& zoneFill = zone->GetFilledPolysList( layer ); for( FOOTPRINT* footprint : board->Footprints() ) { @@ -142,8 +142,8 @@ bool DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run() std::vector intersections; int spokes = 0; - for( int jj = 0; jj < zoneFill.OutlineCount(); ++jj ) - padOutline.Intersect( zoneFill.Outline( jj ), intersections, true ); + for( int jj = 0; jj < zoneFill->OutlineCount(); ++jj ) + padOutline.Intersect( zoneFill->Outline( jj ), intersections, true ); spokes += intersections.size() / 2; @@ -157,12 +157,12 @@ bool DRC_TEST_PROVIDER_ZONE_CONNECTIONS::Run() { if( padOutline.PointInside( track->GetStart() ) ) { - if( zone->GetFilledPolysList( layer ).Collide( track->GetEnd() ) ) + if( zone->GetFilledPolysList( layer )->Collide( track->GetEnd() ) ) spokes++; } else if( padOutline.PointInside( track->GetEnd() ) ) { - if( zone->GetFilledPolysList( layer ).Collide( track->GetStart() ) ) + if( zone->GetFilledPolysList( layer )->Collide( track->GetStart() ) ) spokes++; } } diff --git a/pcbnew/exporters/export_hyperlynx.cpp b/pcbnew/exporters/export_hyperlynx.cpp index b2b80aff17..f407f7f17d 100644 --- a/pcbnew/exporters/export_hyperlynx.cpp +++ b/pcbnew/exporters/export_hyperlynx.cpp @@ -485,7 +485,7 @@ bool HYPERLYNX_EXPORTER::writeNetObjects( const std::vector& aObjec for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { const wxString layerName = m_board->GetLayerName( layer ); - SHAPE_POLY_SET filledShape = zone->GetFilledPolysList( layer ); + SHAPE_POLY_SET filledShape = *zone->GetFilledPolysList( layer ); filledShape.Simplify( SHAPE_POLY_SET::PM_FAST ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index bb9bfd104b..bb732896da 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -894,7 +894,7 @@ SHAPE_POLY_SET FOOTPRINT::GetBoundingHull() const { for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { - SHAPE_POLY_SET layerPoly = zone->GetFilledPolysList( layer ); + SHAPE_POLY_SET layerPoly = *zone->GetFilledPolysList( layer ); for( int ii = 0; ii < layerPoly.OutlineCount(); ii++ ) { diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 7dd623bf67..302def28a4 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1916,9 +1916,9 @@ void PCB_PAINTER::draw( const ZONE* aZone, int aLayer ) || displayMode == ZONE_DISPLAY_MODE::SHOW_FRACTURE_BORDERS || displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ) { - const SHAPE_POLY_SET& polySet = aZone->GetFilledPolysList( layer ); + const std::shared_ptr& polySet = aZone->GetFilledPolysList( layer ); - if( polySet.OutlineCount() == 0 ) // Nothing to draw + if( polySet->OutlineCount() == 0 ) // Nothing to draw return; m_gal->SetStrokeColor( color ); @@ -1936,7 +1936,7 @@ void PCB_PAINTER::draw( const ZONE* aZone, int aLayer ) m_gal->SetIsStroke( true ); } - m_gal->DrawPolygon( polySet, displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ); + m_gal->DrawPolygon( *polySet, displayMode == ZONE_DISPLAY_MODE::SHOW_TRIANGULATION ); } } diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index f3a3eaf625..868890f74c 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -608,7 +608,7 @@ void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask, if( !aLayerMask[layer] ) continue; - SHAPE_POLY_SET mainArea = zone->GetFilledPolysList( layer ); + SHAPE_POLY_SET mainArea = *zone->GetFilledPolysList( layer ); SHAPE_POLY_SET islands; for( int i = mainArea.OutlineCount() - 1; i >= 0; i-- ) diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index b4525ea5a5..6bbe0a15fc 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -3692,15 +3692,12 @@ bool CADSTAR_PCB_ARCHIVE_LOADER::calculateZonePriorities( PCB_LAYER_ID& aLayer ) SHAPE_POLY_SET intersectShape( *aHigherZone->Outline() ); intersectShape.Inflate( inflateValue( aLowerZone, aHigherZone ) , 32 ); - SHAPE_POLY_SET lowerZoneFill( aLowerZone->GetFilledPolysList( aLayer ) ); - + SHAPE_POLY_SET lowerZoneFill( *aLowerZone->GetFilledPolysList( aLayer ) ); SHAPE_POLY_SET lowerZoneOutline( *aLowerZone->Outline() ); - lowerZoneOutline.BooleanSubtract( intersectShape, - SHAPE_POLY_SET::PM_FAST ); + lowerZoneOutline.BooleanSubtract( intersectShape, SHAPE_POLY_SET::PM_FAST ); - lowerZoneFill.BooleanSubtract( lowerZoneOutline, - SHAPE_POLY_SET::PM_FAST ); + lowerZoneFill.BooleanSubtract( lowerZoneOutline, SHAPE_POLY_SET::PM_FAST ); double leftOverArea = lowerZoneFill.Area(); @@ -3758,8 +3755,8 @@ bool CADSTAR_PCB_ARCHIVE_LOADER::calculateZonePriorities( PCB_LAYER_ID& aLayer ) continue; // The zones do not interact in any way } - SHAPE_POLY_SET thisZonePolyFill = thisZone->GetFilledPolysList( aLayer ); - SHAPE_POLY_SET otherZonePolyFill = otherZone->GetFilledPolysList( aLayer ); + SHAPE_POLY_SET thisZonePolyFill = *thisZone->GetFilledPolysList( aLayer ); + SHAPE_POLY_SET otherZonePolyFill = *otherZone->GetFilledPolysList( aLayer ); if( thisZonePolyFill.Area() > 0.0 && otherZonePolyFill.Area() > 0.0 ) { diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 73cc861eff..5fb475e1f9 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -2215,9 +2215,9 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const // Save the PolysList (filled areas) for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() ) { - const SHAPE_POLY_SET& fv = aZone->GetFilledPolysList( layer ); + const std::shared_ptr& fv = aZone->GetFilledPolysList( layer ); - for( int ii = 0; ii < fv.OutlineCount(); ++ii ) + for( int ii = 0; ii < fv->OutlineCount(); ++ii ) { m_out->Print( aNestLevel + 1, "(filled_polygon\n" ); m_out->Print( aNestLevel + 2, "(layer %s)\n", @@ -2226,7 +2226,7 @@ void PCB_PLUGIN::format( const ZONE* aZone, int aNestLevel ) const if( aZone->IsIsland( layer, ii ) ) m_out->Print( aNestLevel + 2, "(island)\n" ); - const SHAPE_LINE_CHAIN& chain = fv.COutline( ii ); + const SHAPE_LINE_CHAIN& chain = fv->COutline( ii ); formatPolyPts( chain, aNestLevel + 1, ADVANCED_CFG::GetCfg().m_CompactSave ); m_out->Print( aNestLevel + 1, ")\n" ); diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index c1c231a477..94982a5d09 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -149,7 +149,13 @@ void ZONE::InitDataFromSrcInCopyCtor( const ZONE& aZone ) for( PCB_LAYER_ID layer : aZone.GetLayerSet().Seq() ) { - m_FilledPolysList[layer] = aZone.m_FilledPolysList.at( layer ); + std::shared_ptr fill = aZone.m_FilledPolysList.at( layer ); + + if( fill ) + m_FilledPolysList[layer] = std::make_shared( *fill ); + else + m_FilledPolysList[layer] = std::make_shared(); + m_RawPolysList[layer] = aZone.m_RawPolysList.at( layer ); m_filledPolysHash[layer] = aZone.m_filledPolysHash.at( layer ); m_insulatedIslands[layer] = aZone.m_insulatedIslands.at( layer ); @@ -178,11 +184,11 @@ bool ZONE::UnFill() { bool change = false; - for( std::pair& pair : m_FilledPolysList ) + for( std::pair>& pair : m_FilledPolysList ) { - change |= !pair.second.IsEmpty(); + change |= !pair.second->IsEmpty(); m_insulatedIslands[pair.first].clear(); - pair.second.RemoveAllContours(); + pair.second->RemoveAllContours(); } m_isFilled = false; @@ -250,7 +256,7 @@ void ZONE::SetLayerSet( LSET aLayerSet ) for( PCB_LAYER_ID layer : aLayerSet.Seq() ) { - m_FilledPolysList[layer] = {}; + m_FilledPolysList[layer] = std::make_shared(); m_RawPolysList[layer] = {}; m_filledPolysHash[layer] = {}; m_insulatedIslands[layer] = {}; @@ -351,7 +357,7 @@ void ZONE::BuildHashValue( PCB_LAYER_ID aLayer ) if( !m_FilledPolysList.count( aLayer ) ) m_filledPolysHash[aLayer] = g_nullPoly.GetHash(); else - m_filledPolysHash[aLayer] = m_FilledPolysList.at( aLayer ).GetHash(); + m_filledPolysHash[aLayer] = m_FilledPolysList.at( aLayer )->GetHash(); } @@ -466,13 +472,12 @@ bool ZONE::HitTestFilledArea( PCB_LAYER_ID aLayer, const VECTOR2I& aRefPos, int // Rule areas have no filled area, but it's generally nice to treat their interior as if it were // filled so that people don't have to select them by their outline (which is min-width) if( GetIsRuleArea() ) - return m_Poly->Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1, aAccuracy ); + return m_Poly->Contains( aRefPos, -1, aAccuracy ); if( !m_FilledPolysList.count( aLayer ) ) return false; - return m_FilledPolysList.at( aLayer ).Contains( VECTOR2I( aRefPos.x, aRefPos.y ), -1, - aAccuracy ); + return m_FilledPolysList.at( aLayer )->Contains( aRefPos, -1, aAccuracy ); } @@ -622,7 +627,7 @@ void ZONE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector& if( layer_it != m_FilledPolysList.end() ) { - msg.Printf( wxT( "%d" ), layer_it->second.TotalVertices() ); + msg.Printf( wxT( "%d" ), layer_it->second->TotalVertices() ); aList.emplace_back( MSG_PANEL_ITEM( _( "Corner Count" ), msg ) ); } } @@ -636,8 +641,8 @@ void ZONE::Move( const VECTOR2I& offset ) HatchBorder(); - for( std::pair& pair : m_FilledPolysList ) - pair.second.Move( offset ); + for( std::pair>& pair : m_FilledPolysList ) + pair.second->Move( offset ); } @@ -662,8 +667,8 @@ void ZONE::Rotate( const VECTOR2I& aCentre, const EDA_ANGLE& aAngle ) HatchBorder(); /* rotate filled areas: */ - for( std::pair& pair : m_FilledPolysList ) - pair.second.Rotate( aAngle, aCentre ); + for( std::pair>& pair : m_FilledPolysList ) + pair.second->Rotate( aAngle, aCentre ); } @@ -686,8 +691,8 @@ void ZONE::Mirror( const VECTOR2I& aMirrorRef, bool aMirrorLeftRight ) HatchBorder(); - for( std::pair& pair : m_FilledPolysList ) - pair.second.Mirror( aMirrorLeftRight, !aMirrorLeftRight, aMirrorRef ); + for( std::pair>& pair : m_FilledPolysList ) + pair.second->Mirror( aMirrorLeftRight, !aMirrorLeftRight, aMirrorRef ); } @@ -1018,13 +1023,13 @@ void ZONE::CacheTriangulation( PCB_LAYER_ID aLayer ) { if( aLayer == UNDEFINED_LAYER ) { - for( std::pair& pair : m_FilledPolysList ) - pair.second.CacheTriangulation(); + for( std::pair>& pair : m_FilledPolysList ) + pair.second->CacheTriangulation(); } else { if( m_FilledPolysList.count( aLayer ) ) - m_FilledPolysList[ aLayer ].CacheTriangulation(); + m_FilledPolysList[ aLayer ]->CacheTriangulation(); } } @@ -1175,16 +1180,16 @@ double ZONE::CalculateFilledArea() // Iterate over each outline polygon in the zone and then iterate over // each hole it has to compute the total area. - for( std::pair& pair : m_FilledPolysList ) + for( std::pair>& pair : m_FilledPolysList ) { - SHAPE_POLY_SET& poly = pair.second; + std::shared_ptr& poly = pair.second; - for( int i = 0; i < poly.OutlineCount(); i++ ) + for( int i = 0; i < poly->OutlineCount(); i++ ) { - m_area += poly.Outline( i ).Area(); + m_area += poly->Outline( i ).Area(); - for( int j = 0; j < poly.HoleCount( i ); j++ ) - m_area -= poly.Hole( i, j ).Area(); + for( int j = 0; j < poly->HoleCount( i ); j++ ) + m_area -= poly->Hole( i, j ).Area(); } } @@ -1302,7 +1307,7 @@ std::shared_ptr ZONE::GetEffectiveShape( PCB_LAYER_ID aLayer ) const } else { - shape.reset( m_FilledPolysList.at( aLayer ).Clone() ); + shape.reset( m_FilledPolysList.at( aLayer )->Clone() ); } return shape; @@ -1318,7 +1323,7 @@ void ZONE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, if( !m_FilledPolysList.count( aLayer ) ) return; - aCornerBuffer = m_FilledPolysList.at( aLayer ); + aCornerBuffer = *m_FilledPolysList.at( aLayer ); // Rebuild filled areas only if clearance is not 0 if( aClearance ) @@ -1332,8 +1337,8 @@ void ZONE::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, void ZONE::TransformSolidAreasShapesToPolygon( PCB_LAYER_ID aLayer, SHAPE_POLY_SET& aCornerBuffer, int aError ) const { - if( m_FilledPolysList.count( aLayer ) && !m_FilledPolysList.at( aLayer ).IsEmpty() ) - aCornerBuffer.Append( m_FilledPolysList.at( aLayer ) ); + if( m_FilledPolysList.count( aLayer ) && !m_FilledPolysList.at( aLayer )->IsEmpty() ) + aCornerBuffer.Append( *m_FilledPolysList.at( aLayer ) ); } diff --git a/pcbnew/zone.h b/pcbnew/zone.h index c6f1d504ab..b7338bc6bc 100644 --- a/pcbnew/zone.h +++ b/pcbnew/zone.h @@ -639,7 +639,7 @@ public: /** * @return a reference to the list of filled polygons. */ - const SHAPE_POLY_SET& GetFilledPolysList( PCB_LAYER_ID aLayer ) const + const std::shared_ptr& GetFilledPolysList( PCB_LAYER_ID aLayer ) const { wxASSERT( m_FilledPolysList.count( aLayer ) ); return m_FilledPolysList.at( aLayer ); @@ -648,7 +648,7 @@ public: SHAPE_POLY_SET* GetFill( PCB_LAYER_ID aLayer ) { wxASSERT( m_FilledPolysList.count( aLayer ) ); - return &m_FilledPolysList.at( aLayer ); + return m_FilledPolysList.at( aLayer ).get(); } /** @@ -662,7 +662,7 @@ public: */ void SetFilledPolysList( PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList ) { - m_FilledPolysList[aLayer] = aPolysList; + m_FilledPolysList[aLayer] = std::make_shared( aPolysList ); } /** @@ -931,7 +931,7 @@ protected: * connecting "holes" with external main outline. In complex cases an outline * described by m_Poly can have many filled areas */ - std::map m_FilledPolysList; + std::map> m_FilledPolysList; std::map m_RawPolysList; /// Temp variables used while filling diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index 628b211c49..b5203517ec 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -339,23 +339,22 @@ bool ZONE_FILLER::Fill( std::vector& aZones, bool aCheck, wxWindow* aPare // to allow deleting a polygon from list without breaking the remaining of the list std::sort( islands.begin(), islands.end(), std::greater() ); - SHAPE_POLY_SET poly = zone.m_zone->GetFilledPolysList( layer ); - long long int minArea = zone.m_zone->GetMinIslandArea(); - ISLAND_REMOVAL_MODE mode = zone.m_zone->GetIslandRemovalMode(); + std::shared_ptr poly = zone.m_zone->GetFilledPolysList( layer ); + long long int minArea = zone.m_zone->GetMinIslandArea(); + ISLAND_REMOVAL_MODE mode = zone.m_zone->GetIslandRemovalMode(); for( int idx : islands ) { - SHAPE_LINE_CHAIN& outline = poly.Outline( idx ); + SHAPE_LINE_CHAIN& outline = poly->Outline( idx ); if( mode == ISLAND_REMOVAL_MODE::ALWAYS ) - poly.DeletePolygon( idx ); + poly->DeletePolygon( idx ); else if ( mode == ISLAND_REMOVAL_MODE::AREA && outline.Area() < minArea ) - poly.DeletePolygon( idx ); + poly->DeletePolygon( idx ); else zone.m_zone->SetIsIsland( layer, idx ); } - zone.m_zone->SetFilledPolysList( layer, poly ); zone.m_zone->CalculateFilledArea(); if( m_progressReporter && m_progressReporter->IsCancelled() ) @@ -373,17 +372,16 @@ bool ZONE_FILLER::Fill( std::vector& aZones, bool aCheck, wxWindow* aPare if( m_debugZoneFiller && LSET::InternalCuMask().Contains( layer ) ) continue; - SHAPE_POLY_SET poly = zone->GetFilledPolysList( layer ); + std::shared_ptr poly = zone->GetFilledPolysList( layer ); - for( int ii = poly.OutlineCount() - 1; ii >= 0; ii-- ) + for( int ii = poly->OutlineCount() - 1; ii >= 0; ii-- ) { - std::vector& island = poly.Polygon( ii ); + std::vector& island = poly->Polygon( ii ); if( island.empty() || !m_boardOutline.Contains( island.front().CPoint( 0 ) ) ) - poly.DeletePolygon( ii ); + poly->DeletePolygon( ii ); } - zone->SetFilledPolysList( layer, poly ); zone->CalculateFilledArea(); if( m_progressReporter && m_progressReporter->IsCancelled() ) diff --git a/qa/pcbnew/test_zone_filler.cpp b/qa/pcbnew/test_zone_filler.cpp index c17659637c..d4a6744742 100644 --- a/qa/pcbnew/test_zone_filler.cpp +++ b/qa/pcbnew/test_zone_filler.cpp @@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_CASE( NotchedZones, ZONE_FILL_TEST_FIXTURE ) { if( zone->GetLayerSet().Contains( F_Cu ) ) { - frontCopper.BooleanAdd( zone->GetFilledPolysList( F_Cu ), + frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } } @@ -167,7 +167,7 @@ BOOST_FIXTURE_TEST_CASE( NotchedZones, ZONE_FILL_TEST_FIXTURE ) { if( zone->GetLayerSet().Contains( F_Cu ) ) { - frontCopper.BooleanAdd( zone->GetFilledPolysList( F_Cu ), + frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ), SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } } diff --git a/qa/pcbnew_tools/tools/polygon_triangulation/polygon_triangulation.cpp b/qa/pcbnew_tools/tools/polygon_triangulation/polygon_triangulation.cpp index 4472680c33..ac577ffe7d 100644 --- a/qa/pcbnew_tools/tools/polygon_triangulation/polygon_triangulation.cpp +++ b/qa/pcbnew_tools/tools/polygon_triangulation/polygon_triangulation.cpp @@ -239,7 +239,7 @@ int polygon_triangulation_main( int argc, char *argv[] ) // to do that right now. for( PCB_LAYER_ID layer : zone->GetLayerSet().Seq() ) { - SHAPE_POLY_SET poly = zone->GetFilledPolysList( layer ); + SHAPE_POLY_SET poly = *zone->GetFilledPolysList( layer ); poly.CacheTriangulation();