Browse Source

Handle wildcards and "other" item for insideCourtyard DRC function.

Fixes https://gitlab.com/kicad/code/kicad/issues/4519
pull/16/head
Jeff Young 5 years ago
parent
commit
e88dda2c01
  1. 54
      pcbnew/pcb_expr_evaluator.cpp

54
pcbnew/pcb_expr_evaluator.cpp

@ -80,8 +80,9 @@ static void isPlated( LIBEVAL::CONTEXT* aCtx, void* self )
static void insideCourtyard( LIBEVAL::CONTEXT* aCtx, void* self )
{
LIBEVAL::VALUE* arg = aCtx->Pop();
LIBEVAL::VALUE* result = aCtx->AllocValue();
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
LIBEVAL::VALUE* arg = aCtx->Pop();
LIBEVAL::VALUE* result = aCtx->AllocValue();
result->Set( 0.0 );
aCtx->Push( result );
@ -93,34 +94,49 @@ static void insideCourtyard( LIBEVAL::CONTEXT* aCtx, void* self )
return;
}
wxString footprintRef = arg->AsString();
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
MODULE* footprint = nullptr;
if( item )
if( !item )
return;
if( arg->AsString() == "A" )
{
footprint = dynamic_cast<MODULE*>( context->GetItem( 0 ) );
}
else if( arg->AsString() == "B" )
{
for( MODULE* footprint : item->GetBoard()->Modules() )
footprint = dynamic_cast<MODULE*>( context->GetItem( 1 ) );
}
else
{
for( MODULE* candidate : item->GetBoard()->Modules() )
{
if( footprint->GetReference() == footprintRef )
if( candidate->GetReference().Matches( arg->AsString() ) )
{
SHAPE_POLY_SET footprintCourtyard;
footprint = candidate;
break;
}
}
}
if( footprint->IsFlipped() )
footprintCourtyard = footprint->GetPolyCourtyardBack();
else
footprintCourtyard = footprint->GetPolyCourtyardFront();
if( footprint )
{
SHAPE_POLY_SET footprintCourtyard;
SHAPE_POLY_SET testPoly;
if( footprint->IsFlipped() )
footprintCourtyard = footprint->GetPolyCourtyardBack();
else
footprintCourtyard = footprint->GetPolyCourtyardFront();
item->TransformShapeWithClearanceToPolygon( testPoly, 0 );
testPoly.BooleanIntersection( footprintCourtyard, SHAPE_POLY_SET::PM_FAST );
SHAPE_POLY_SET testPoly;
if( testPoly.OutlineCount() )
result->Set( 1.0 );
item->TransformShapeWithClearanceToPolygon( testPoly, 0 );
testPoly.BooleanIntersection( footprintCourtyard, SHAPE_POLY_SET::PM_FAST );
break;
}
}
if( testPoly.OutlineCount() )
result->Set( 1.0 );
}
}

Loading…
Cancel
Save