From e288218c4fe12ce340a8ee81b2d181672ef08ae0 Mon Sep 17 00:00:00 2001 From: Mario Luzeiro Date: Mon, 7 Sep 2020 13:29:40 +0100 Subject: [PATCH] 3D-Viewer: subtract pads poly to F_Cu and B_Cu poly layers --- 3d-viewer/3d_canvas/create_layer_items.cpp | 82 ++++++++++++++-------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index abdfb6d60f..e9bf334eb6 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -758,41 +758,65 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) if( GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS ) && ( m_render_engine == RENDER_ENGINE::OPENGL_LEGACY ) ) { - std::atomic nextItem( 0 ); - std::atomic threadsFinished( 0 ); - - size_t parallelThreadCount = std::min( - std::max( std::thread::hardware_concurrency(), 2 ), - layer_id.size() ); - for( size_t ii = 0; ii < parallelThreadCount; ++ii ) + if( m_F_Cu_PlatedPads_poly && ( m_layers_poly.find( F_Cu ) != m_layers_poly.end() ) ) { - std::thread t = std::thread( [&nextItem, &threadsFinished, &layer_id, this]() - { - for( size_t i = nextItem.fetch_add( 1 ); - i < layer_id.size(); - i = nextItem.fetch_add( 1 ) ) - { - auto layerPoly = m_layers_poly.find( layer_id[i] ); + SHAPE_POLY_SET *layerPoly_F_Cu = m_layers_poly[F_Cu]; + layerPoly_F_Cu->BooleanSubtract( *m_F_Cu_PlatedPads_poly, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST ); - if( layerPoly != m_layers_poly.end() ) - // This will make a union of all added contours - layerPoly->second->Simplify( SHAPE_POLY_SET::PM_FAST ); - } - - threadsFinished++; - } ); - - t.detach(); + m_F_Cu_PlatedPads_poly->Simplify( SHAPE_POLY_SET::PM_FAST ); } - while( threadsFinished < parallelThreadCount ) - std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + if( m_B_Cu_PlatedPads_poly && ( m_layers_poly.find( B_Cu ) != m_layers_poly.end() ) ) + { + SHAPE_POLY_SET *layerPoly_B_Cu = m_layers_poly[B_Cu]; + layerPoly_B_Cu->BooleanSubtract( *m_B_Cu_PlatedPads_poly, SHAPE_POLY_SET::POLYGON_MODE::PM_FAST ); - if( m_F_Cu_PlatedPads_poly ) - m_F_Cu_PlatedPads_poly->Simplify( SHAPE_POLY_SET::PM_FAST ); - - if( m_B_Cu_PlatedPads_poly ) m_B_Cu_PlatedPads_poly->Simplify( SHAPE_POLY_SET::PM_FAST ); + } + + std::vector< PCB_LAYER_ID > layer_id_without_F_and_B; + layer_id_without_F_and_B.clear(); + layer_id_without_F_and_B.reserve( layer_id.size() ); + + for( size_t i = 0; i < layer_id.size(); ++i ) + { + if( ( layer_id[i] != F_Cu ) && + ( layer_id[i] != B_Cu ) ) + layer_id_without_F_and_B.push_back( layer_id[i] ); + } + + if( layer_id_without_F_and_B.size() > 0 ) + { + std::atomic nextItem( 0 ); + std::atomic threadsFinished( 0 ); + + size_t parallelThreadCount = std::min( + std::max( std::thread::hardware_concurrency(), 2 ), + layer_id_without_F_and_B.size() ); + for( size_t ii = 0; ii < parallelThreadCount; ++ii ) + { + std::thread t = std::thread( [&nextItem, &threadsFinished, &layer_id_without_F_and_B, this]() + { + for( size_t i = nextItem.fetch_add( 1 ); + i < layer_id_without_F_and_B.size(); + i = nextItem.fetch_add( 1 ) ) + { + auto layerPoly = m_layers_poly.find( layer_id_without_F_and_B[i] ); + + if( layerPoly != m_layers_poly.end() ) + // This will make a union of all added contours + layerPoly->second->Simplify( SHAPE_POLY_SET::PM_FAST ); + } + + threadsFinished++; + } ); + + t.detach(); + } + + while( threadsFinished < parallelThreadCount ) + std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) ); + } } // Simplify holes polygon contours