From 86ec36d183e1e5dc56750b2accede1f7643c7805 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Sun, 10 Sep 2023 17:30:48 +0300 Subject: [PATCH] Fix reading/writing thermal spoke angles for custom pads. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15518 --- pcbnew/plugins/kicad/pcb_parser.cpp | 43 ++++++++++++++++++----------- pcbnew/plugins/kicad/pcb_plugin.cpp | 11 ++++++-- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index 1ce0b3bc86..2370088c09 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -4641,21 +4641,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent ) Expecting( "circle, rectangle, roundrect, oval, trapezoid or custom" ); } - if( pad->GetShape() == PAD_SHAPE::CIRCLE ) - { - pad->SetThermalSpokeAngle( ANGLE_45 ); - } - else if( pad->GetShape() == PAD_SHAPE::CUSTOM && pad->GetAnchorPadShape() == PAD_SHAPE::CIRCLE ) - { - if( m_requiredVersion < 20211226 ) - pad->SetThermalSpokeAngle( ANGLE_90 ); - else - pad->SetThermalSpokeAngle( ANGLE_45 ); - } - else - { - pad->SetThermalSpokeAngle( ANGLE_90 ); - } + std::optional thermalBrAngleOverride; for( token = NextTok(); token != T_RIGHT; token = NextTok() ) { @@ -4851,7 +4837,7 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent ) break; case T_thermal_bridge_angle: - pad->SetThermalSpokeAngle( EDA_ANGLE( parseDouble( "thermal spoke angle" ), DEGREES_T ) ); + thermalBrAngleOverride = EDA_ANGLE( parseDouble( "thermal spoke angle" ), DEGREES_T ); NeedRIGHT(); break; @@ -5066,6 +5052,31 @@ PAD* PCB_PARSER::parsePAD( FOOTPRINT* aParent ) } } + if( thermalBrAngleOverride ) + { + pad->SetThermalSpokeAngle( *thermalBrAngleOverride ); + } + else + { + // This is here because custom pad anchor shape isn't known before reading (options + if( pad->GetShape() == PAD_SHAPE::CIRCLE ) + { + pad->SetThermalSpokeAngle( ANGLE_45 ); + } + else if( pad->GetShape() == PAD_SHAPE::CUSTOM + && pad->GetAnchorPadShape() == PAD_SHAPE::CIRCLE ) + { + if( m_requiredVersion <= 20211014 ) // 6.0 + pad->SetThermalSpokeAngle( ANGLE_90 ); + else + pad->SetThermalSpokeAngle( ANGLE_45 ); + } + else + { + pad->SetThermalSpokeAngle( ANGLE_90 ); + } + } + if( !pad->CanHaveNumber() ) { // At some point it was possible to assign a number to aperture pads so we need to clean diff --git a/pcbnew/plugins/kicad/pcb_plugin.cpp b/pcbnew/plugins/kicad/pcb_plugin.cpp index 6755b62f8f..a1617d1b6b 100644 --- a/pcbnew/plugins/kicad/pcb_plugin.cpp +++ b/pcbnew/plugins/kicad/pcb_plugin.cpp @@ -1679,8 +1679,15 @@ void PCB_PLUGIN::format( const PAD* aPad, int aNestLevel ) const EDA_UNIT_UTILS::FormatInternalUnits( pcbIUScale, aPad->GetThermalSpokeWidth() ).c_str() ); } - if( ( aPad->GetShape() == PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_45 ) - || ( aPad->GetShape() != PAD_SHAPE::CIRCLE && aPad->GetThermalSpokeAngle() != ANGLE_90 ) ) + EDA_ANGLE defaultThermalSpokeAngle = ANGLE_90; + + if( aPad->GetShape() == PAD_SHAPE::CIRCLE || + ( aPad->GetShape() == PAD_SHAPE::CUSTOM && aPad->GetAnchorPadShape() == PAD_SHAPE::CIRCLE ) ) + { + defaultThermalSpokeAngle = ANGLE_45; + } + + if( aPad->GetThermalSpokeAngle() != defaultThermalSpokeAngle ) { StrPrintf( &output, " (thermal_bridge_angle %s)", EDA_UNIT_UTILS::FormatAngle( aPad->GetThermalSpokeAngle() ).c_str() );