From b88473e41fc75fce2355a396c7bd1f36e53e27a5 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 15 Oct 2021 08:43:31 -0700 Subject: [PATCH] Respect context layer in eval When testing for a specific layer context, we should only return true if the item either exists on that layer or if the context layer is UNDEFINED_LAYER, meaning the layer value is not material to the test Relates to https://gitlab.com/kicad/code/kicad/-/issues/9366 --- pcbnew/pcb_expr_evaluator.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 424a53e8bc..fe93223420 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -473,10 +473,14 @@ bool calcIsInsideArea( BOARD_ITEM* aItem, const EDA_RECT& aItemBBox, PCB_EXPR_CO { PCB_VIA* via = static_cast( aItem ); const SHAPE_CIRCLE holeShape( via->GetPosition(), via->GetDrillValue() ); + LSET overlap = via->GetLayerSet() & aArea->GetLayerSet(); /// Avoid buried vias that don't overlap the zone's layers - if( ( via->GetLayerSet() & aArea->GetLayerSet() ).any() ) + if( overlap.count() > 0 ) + { + if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) ) return areaOutline.Collide( &holeShape ); + } } return false; @@ -548,8 +552,11 @@ bool calcIsInsideArea( BOARD_ITEM* aItem, const EDA_RECT& aItemBBox, PCB_EXPR_CO { for( PCB_LAYER_ID layer : aArea->GetLayerSet().Seq() ) { - if( zoneRTree->QueryColliding( aItemBBox, &areaOutline, layer ) ) - return true; + if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER ) + { + if( zoneRTree->QueryColliding( aItemBBox, &areaOutline, layer ) ) + return true; + } } } @@ -557,7 +564,8 @@ bool calcIsInsideArea( BOARD_ITEM* aItem, const EDA_RECT& aItemBBox, PCB_EXPR_CO } else { - if( !( aArea->GetLayerSet().Contains( aCtx->GetLayer() ) ) ) + if( aCtx->GetLayer() != UNDEFINED_LAYER + && !( aArea->GetLayerSet().Contains( aCtx->GetLayer() ) ) ) return false; if( !shape ) @@ -921,7 +929,7 @@ public: PCB_LAYER_ID layerId = ToLAYER_ID( (int) AsDouble() ); - return mask.test( layerId ); + return mask.Contains( layerId ); } };