3D viewer: fix a minor issue, clean code and and a few comments.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21629
This commit is contained in:
jean-pierre charras 2025-09-03 18:24:40 +02:00
parent 9f06d1f66b
commit 622ddd3a37
4 changed files with 25 additions and 24 deletions

View File

@ -368,11 +368,12 @@ private:
void createTrackWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer, void createTrackWithMargin( const PCB_TRACK* aTrack, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, int aMargin = 0 ); 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, void createPadWithMargin( const PAD *aPad, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const; PCB_LAYER_ID aLayer, const VECTOR2I& aMargin ) const;
void createPadWithHole( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, // Generate the hole shape of aPad, stored in aDstContainer
int aInflateValue ); void createPadHoleShape( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer, int aInflateValue );
void addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer, void addPads( const FOOTPRINT* aFootprint, CONTAINER_2D_BASE* aDstContainer,
PCB_LAYER_ID aLayerId ); PCB_LAYER_ID aLayerId );

View File

@ -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, void BOARD_ADAPTER::createPadHoleShape( const PAD* aPad, CONTAINER_2D_BASE* aDstContainer,
int aInflateValue ) int aInflateValue )
{ {
if( !aPad->HasHole() ) 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; return;
} }

View File

@ -507,27 +507,32 @@ void BOARD_ADAPTER::createLayers( REPORTER* aStatusReporter )
{ {
for( PAD* pad : footprint->Pads() ) for( PAD* pad : footprint->Pads() )
{ {
const VECTOR2I padHole = pad->GetDrillSize(); // Note: holes of NPTH are already built by GetBoardPolygonOutlines
if( !pad->HasHole() )
if( !padHole.x ) // Not drilled pad like SMD pad
continue; 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++; m_holeCount++;
double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0; double holeDiameter = ( pad->GetDrillSize().x + pad->GetDrillSize().y ) / 2.0;
m_averageHoleDiameter += static_cast<float>( holeDiameter * m_biuTo3Dunits ); m_averageHoleDiameter += static_cast<float>( 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 ) 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() ) for( PAD* pad : footprint->Pads() )
{ {
const VECTOR2I padHole = pad->GetDrillSize(); if( !pad->HasHole() )
if( !padHole.x ) // Not drilled pad like SMD pad
continue; continue;
// The hole in the body is inflated by copper thickness. // The hole in the body is inflated by copper thickness.

View File

@ -819,10 +819,7 @@ void RENDER_3D_OPENGL::generateViasAndPads()
{ {
if( pad->GetAttribute() != PAD_ATTRIB::NPTH ) if( pad->GetAttribute() != PAD_ATTRIB::NPTH )
{ {
const VECTOR2I drillsize = pad->GetDrillSize(); if( !pad->HasHole() )
const bool hasHole = drillsize.x && drillsize.y;
if( !hasHole )
continue; continue;
pad->TransformHoleToPolygon( tht_outer_holes_poly, platingThickness, pad->TransformHoleToPolygon( tht_outer_holes_poly, platingThickness,