From 622ddd3a3763c07a28a1e711fd07441bbfa7963c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 3 Sep 2025 18:24:40 +0200 Subject: [PATCH] 3D viewer: fix a minor issue, clean code and and a few comments. Fixes https://gitlab.com/kicad/code/kicad/-/issues/21629 --- 3d-viewer/3d_canvas/board_adapter.h | 5 +-- .../3d_canvas/create_3Dgraphic_brd_items.cpp | 6 ++-- 3d-viewer/3d_canvas/create_layer_items.cpp | 33 ++++++++++--------- .../3d_rendering/opengl/create_scene.cpp | 5 +-- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/3d-viewer/3d_canvas/board_adapter.h b/3d-viewer/3d_canvas/board_adapter.h index 2fc15d9123..a572e35291 100644 --- a/3d-viewer/3d_canvas/board_adapter.h +++ b/3d-viewer/3d_canvas/board_adapter.h @@ -368,11 +368,12 @@ private: void createTrackWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer, PCB_LAYER_ID aLayer, int aMargin = 0 ); + // Generate the pad shape on board layers. The pad hole is not generated by createPadWithMargin void createPadWithMargin( const PAD *aPad, CONTAINER_2D_BASE* aDstContainer, PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const; - void createPadWithHole( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, - int aInflateValue ); + // Generate the hole shape of aPad, stored in aDstContainer + void createPadHoleShape( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aInflateValue ); void addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer, PCB_LAYER_ID aLayerId ); diff --git a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp index c55fa7d7ac..f626870fc1 100644 --- a/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp +++ b/3d-viewer/3d_canvas/create_3Dgraphic_brd_items.cpp @@ -474,12 +474,12 @@ void BOARD_ADAPTER::createPadWithMargin( const PAD* aPad, CONTAINER_2D_BASE* aCo } -void BOARD_ADAPTER::createPadWithHole( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, - int aInflateValue ) +void BOARD_ADAPTER::createPadHoleShape( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, + int aInflateValue ) { if( !aPad->HasHole() ) { - wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createPadWithHole - found an invalid pad" ) ); + wxLogTrace( m_logTrace, wxT( "BOARD_ADAPTER::createPadHole pad has no hole" ) ); return; } diff --git a/3d-viewer/3d_canvas/create_layer_items.cpp b/3d-viewer/3d_canvas/create_layer_items.cpp index 2d62f4b467..aaf99089d6 100644 --- a/3d-viewer/3d_canvas/create_layer_items.cpp +++ b/3d-viewer/3d_canvas/create_layer_items.cpp @@ -507,27 +507,32 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) { for( PAD* pad : footprint->Pads() ) { - const VECTOR2I padHole = pad->GetDrillSize(); - - if( !padHole.x ) // Not drilled pad like SMD pad + // Note: holes of NPTH are already built by GetBoardPolygonOutlines + if( !pad->HasHole() ) continue; - // The hole in the body is inflated by copper thickness, if not plated, no copper - int inflate = 0; - - if( pad->GetAttribute() != PAD_ATTRIB::NPTH ) - inflate = KiROUND( GetHolePlatingThickness() / 2.0 ); - m_holeCount++; double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0; m_averageHoleDiameter += static_cast( holeDiameter * m_biuTo3Dunits ); - createPadWithHole( pad, &m_TH_ODs, inflate ); + if( pad->GetAttribute() == PAD_ATTRIB::NPTH ) + { + // Ensure the silk drawings are clipped to the NPTH hole, like other pad/via holes + // even if the clip to board body is not activated (remember NPTH holes are part of + // the board body) + createPadHoleShape( pad, &m_TH_ODs, 0 ); + continue; + } + + // The hole in the body is inflated by copper thickness + int inflate = KiROUND( GetHolePlatingThickness() / 2.0 ); + + createPadHoleShape( pad, &m_TH_ODs, inflate ); if( cfg.clip_silk_on_via_annuli ) - createPadWithHole( pad, &m_viaAnnuli, inflate ); + createPadHoleShape( pad, &m_viaAnnuli, inflate ); - createPadWithHole( pad, &m_TH_IDs, 0 ); + createPadHoleShape( pad, &m_TH_IDs, 0 ); } } @@ -539,9 +544,7 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter ) { for( PAD* pad : footprint->Pads() ) { - const VECTOR2I padHole = pad->GetDrillSize(); - - if( !padHole.x ) // Not drilled pad like SMD pad + if( !pad->HasHole() ) continue; // The hole in the body is inflated by copper thickness. diff --git a/3d-viewer/3d_rendering/opengl/create_scene.cpp b/3d-viewer/3d_rendering/opengl/create_scene.cpp index 4b4bd6504c..2ef677d718 100644 --- a/3d-viewer/3d_rendering/opengl/create_scene.cpp +++ b/3d-viewer/3d_rendering/opengl/create_scene.cpp @@ -819,10 +819,7 @@ void RENDER_3D_OPENGL::generateViasAndPads() { if( pad->GetAttribute() != PAD_ATTRIB::NPTH ) { - const VECTOR2I drillsize = pad->GetDrillSize(); - const bool hasHole = drillsize.x && drillsize.y; - - if( !hasHole ) + if( !pad->HasHole() ) continue; pad->TransformHoleToPolygon( tht_outer_holes_poly, platingThickness,