diff --git a/pcbnew/board_stackup_manager/board_stackup.cpp b/pcbnew/board_stackup_manager/board_stackup.cpp index b24555cc1b..007bd240e9 100644 --- a/pcbnew/board_stackup_manager/board_stackup.cpp +++ b/pcbnew/board_stackup_manager/board_stackup.cpp @@ -712,6 +712,7 @@ int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSec int total = 0; bool start = false; + bool half = false; for( BOARD_STACKUP_ITEM* item : m_list ) { @@ -725,17 +726,25 @@ int BOARD_STACKUP::GetLayerDistance( PCB_LAYER_ID aFirstLayer, PCB_LAYER_ID aSec if( !start && ( layer != UNDEFINED_LAYER && layer >= aFirstLayer ) ) { start = true; - continue; + half = true; } else if( !start ) continue; // Reached the stop copper layer? we're done if( start && ( layer != UNDEFINED_LAYER && layer >= aSecondLayer ) ) - break; + half = true; for( int sublayer = 0; sublayer < item->GetSublayersCount(); sublayer++ ) - total += item->GetThickness( sublayer ); + { + int subThickness = item->GetThickness( sublayer ); + total += half ? ( subThickness / 2 ) : subThickness; + } + + half = false; + + if( layer != UNDEFINED_LAYER && layer >= aSecondLayer ) + break; } return total; diff --git a/pcbnew/board_stackup_manager/board_stackup.h b/pcbnew/board_stackup_manager/board_stackup.h index 3f78a23597..e378923be3 100644 --- a/pcbnew/board_stackup_manager/board_stackup.h +++ b/pcbnew/board_stackup_manager/board_stackup.h @@ -277,7 +277,12 @@ public: * Calculate the distance (height) between the two given copper layers. * * This factors in the thickness of any dielectric and copper layers between the two given - * layers, but not the height of the given copper layers. + * layers, and half the height of the given start and end layers. This half-height calculation + * allows this to be used for consistent length measurements when calculating net length through + * a series of vias. A more advanced algorithm would be possible once we have a good concept of + * the start and end for a length measurment, but for now this will do. + * See https://gitlab.com/kicad/code/kicad/-/issues/8384 for more background. + * * @param aFirstLayer is a copper layer * @param aSecondLayer is a different copper layer * @return the height (in IU) between the two layers