KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcbexpr_functions.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <algorithm>
25#include <cstdio>
26#include <memory>
27#include <mutex>
28#include <wx/log.h>
29#include <board.h>
31#include <drc/drc_rtree.h>
32#include <drc/drc_engine.h>
33#include <lset.h>
34#include <pcb_track.h>
35#include <pcb_group.h>
37#include <pcbexpr_evaluator.h>
41
42
43bool fromToFunc( LIBEVAL::CONTEXT* aCtx, void* self )
44{
45 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
46 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
47 LIBEVAL::VALUE* result = aCtx->AllocValue();
48 LIBEVAL::VALUE* argTo = aCtx->Pop();
49 LIBEVAL::VALUE* argFrom = aCtx->Pop();
50
51 result->Set(0.0);
52 aCtx->Push( result );
53
54 if(!item)
55 return false;
56
57 auto ftCache = item->GetBoard()->GetConnectivity()->GetFromToCache();
58
59 if( !ftCache )
60 {
61 wxLogWarning( wxT( "Attempting to call fromTo() with non-existent from-to cache." ) );
62 return true;
63 }
64
65 if( ftCache->IsOnFromToPath( static_cast<BOARD_CONNECTED_ITEM*>( item ),
66 argFrom->AsString(), argTo->AsString() ) )
67 {
68 result->Set(1.0);
69 }
70
71 return true;
72}
73
74
75#define MISSING_LAYER_ARG( f ) wxString::Format( _( "Missing layer name argument to %s." ), f )
76
77static void existsOnLayerFunc( LIBEVAL::CONTEXT* aCtx, void *self )
78{
79 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
80 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
81 LIBEVAL::VALUE* arg = aCtx->Pop();
82 LIBEVAL::VALUE* result = aCtx->AllocValue();
83
84 result->Set( 0.0 );
85 aCtx->Push( result );
86
87 if( !item )
88 return;
89
90 if( !arg || arg->AsString().IsEmpty() )
91 {
92 if( aCtx->HasErrorCallback() )
93 aCtx->ReportError( MISSING_LAYER_ARG( wxT( "existsOnLayer()" ) ) );
94
95 return;
96 }
97
98 result->SetDeferredEval(
99 [item, arg, aCtx]() -> double
100 {
101 const wxString& layerName = arg->AsString();
102 wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
103
104 if( aCtx->HasErrorCallback())
105 {
106 /*
107 * Interpreted version
108 */
109
110 bool anyMatch = false;
111
112 for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
113 {
114 wxPGChoiceEntry& entry = layerMap[ ii ];
115
116 if( entry.GetText().Matches( layerName ))
117 {
118 anyMatch = true;
119
120 if( item->IsOnLayer( ToLAYER_ID( entry.GetValue() ) ) )
121 return 1.0;
122 }
123 }
124
125 if( !anyMatch )
126 {
127 aCtx->ReportError( wxString::Format( _( "Unrecognized layer '%s'" ),
128 layerName ) );
129 }
130
131 return 0.0;
132 }
133 else
134 {
135 /*
136 * Compiled version
137 */
138
139 BOARD* board = item->GetBoard();
140
141 {
142 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
143
144 auto i = board->m_LayerExpressionCache.find( layerName );
145
146 if( i != board->m_LayerExpressionCache.end() )
147 return ( item->GetLayerSet() & i->second ).any() ? 1.0 : 0.0;
148 }
149
150 LSET mask;
151
152 for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
153 {
154 wxPGChoiceEntry& entry = layerMap[ ii ];
155
156 if( entry.GetText().Matches( layerName ) )
157 mask.set( ToLAYER_ID( entry.GetValue() ) );
158 }
159
160 {
161 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
162 board->m_LayerExpressionCache[ layerName ] = mask;
163 }
164
165 return ( item->GetLayerSet() & mask ).any() ? 1.0 : 0.0;
166 }
167 } );
168}
169
170
171static void isPlatedFunc( LIBEVAL::CONTEXT* aCtx, void* self )
172{
173 LIBEVAL::VALUE* result = aCtx->AllocValue();
174
175 result->Set( 0.0 );
176 aCtx->Push( result );
177
178 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
179 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
180
181 if( !item )
182 return;
183
184 if( item->Type() == PCB_PAD_T && static_cast<PAD*>( item )->GetAttribute() == PAD_ATTRIB::PTH )
185 result->Set( 1.0 );
186 else if( item->Type() == PCB_VIA_T )
187 result->Set( 1.0 );
188}
189
190
191bool collidesWithCourtyard( BOARD_ITEM* aItem, std::shared_ptr<SHAPE>& aItemShape,
192 PCBEXPR_CONTEXT* aCtx, FOOTPRINT* aFootprint, PCB_LAYER_ID aSide )
193{
194 SHAPE_POLY_SET footprintCourtyard;
195
196 footprintCourtyard = aFootprint->GetCourtyard( aSide );
197
198 if( !aItemShape )
199 {
200 // Since rules are used for zone filling we can't rely on the filled shapes.
201 // Use the zone outline instead.
202 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
203 aItemShape.reset( zone->Outline()->Clone() );
204 else
205 aItemShape = aItem->GetEffectiveShape( aCtx->GetLayer() );
206 }
207
208 return footprintCourtyard.Collide( aItemShape.get() );
209};
210
211
212static bool searchFootprints( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
213 const std::function<bool( FOOTPRINT* )>& aFunc )
214{
215 if( aArg == wxT( "A" ) )
216 {
217 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 0 ) );
218
219 if( fp && aFunc( fp ) )
220 return true;
221 }
222 else if( aArg == wxT( "B" ) )
223 {
224 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 1 ) );
225
226 if( fp && aFunc( fp ) )
227 return true;
228 }
229 else for( FOOTPRINT* fp : aBoard->Footprints() )
230 {
231 // NOTE: This code may want to be somewhat more generalized, but for now it's implemented
232 // here to support functions like insersectsCourtyard where we want multiple ways to search
233 // for the footprints in question.
234 // If support for text variable replacement is added, it should happen before any other
235 // logic here, so that people can use text variables to contain references or LIBIDs.
236 // (see: https://gitlab.com/kicad/code/kicad/-/issues/11231)
237
238 // First check if we have a known directive
239 if( aArg.Upper().StartsWith( wxT( "${CLASS:" ) ) && aArg.EndsWith( '}' ) )
240 {
241 wxString name = aArg.Mid( 8, aArg.Length() - 9 );
242
243 if( fp->GetComponentClass()->ContainsClassName( name ) && aFunc( fp ) )
244 return true;
245 }
246 else if( fp->GetReference().Matches( aArg ) )
247 {
248 if( aFunc( fp ) )
249 return true;
250 }
251 else if( aArg.Contains( ':' )
252 && fp->GetFPIDAsString().Matches( aArg ) )
253 {
254 if( aFunc( fp ) )
255 return true;
256 }
257 }
258
259 return false;
260}
261
262
263#define MISSING_FP_ARG( f ) \
264 wxString::Format( _( "Missing footprint argument (A, B, or reference designator) to %s." ), f )
265
266static void intersectsCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
267{
268 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
269 LIBEVAL::VALUE* arg = context->Pop();
270 LIBEVAL::VALUE* result = context->AllocValue();
271
272 result->Set( 0.0 );
273 context->Push( result );
274
275 if( !arg || arg->AsString().IsEmpty() )
276 {
277 if( context->HasErrorCallback() )
278 context->ReportError( MISSING_FP_ARG( wxT( "intersectsCourtyard()" ) ) );
279
280 return;
281 }
282
283 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
284 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
285
286 if( !item )
287 return;
288
289 result->SetDeferredEval(
290 [item, arg, context]() -> double
291 {
292 BOARD* board = item->GetBoard();
293 std::shared_ptr<SHAPE> itemShape;
294
295 if( searchFootprints( board, arg->AsString(), context,
296 [&]( FOOTPRINT* fp )
297 {
298 PTR_PTR_CACHE_KEY key = { fp, item };
299
300 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
301 {
302 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
303
304 auto i = board->m_IntersectsCourtyardCache.find( key );
305
306 if( i != board->m_IntersectsCourtyardCache.end() )
307 return i->second;
308 }
309
310 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu )
311 || collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
312
313 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
314 {
315 std::unique_lock<std::shared_mutex> cacheLock( board->m_CachesMutex );
316 board->m_IntersectsCourtyardCache[ key ] = res;
317 }
318
319 return res;
320 } ) )
321 {
322 return 1.0;
323 }
324
325 return 0.0;
326 } );
327}
328
329
330static void intersectsFrontCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
331{
332 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
333 LIBEVAL::VALUE* arg = context->Pop();
334 LIBEVAL::VALUE* result = context->AllocValue();
335
336 result->Set( 0.0 );
337 context->Push( result );
338
339 if( !arg || arg->AsString().IsEmpty() )
340 {
341 if( context->HasErrorCallback() )
342 context->ReportError( MISSING_FP_ARG( wxT( "intersectsFrontCourtyard()" ) ) );
343
344 return;
345 }
346
347 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
348 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
349
350 if( !item )
351 return;
352
353 result->SetDeferredEval(
354 [item, arg, context]() -> double
355 {
356 BOARD* board = item->GetBoard();
357 std::shared_ptr<SHAPE> itemShape;
358
359 if( searchFootprints( board, arg->AsString(), context,
360 [&]( FOOTPRINT* fp )
361 {
362 PTR_PTR_CACHE_KEY key = { fp, item };
363
364 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
365 {
366 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
367
368 auto i = board->m_IntersectsFCourtyardCache.find( key );
369
370 if( i != board->m_IntersectsFCourtyardCache.end() )
371 return i->second;
372 }
373
374 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu );
375
376 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
377 {
378 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
379 board->m_IntersectsFCourtyardCache[ key ] = res;
380 }
381
382 return res;
383 } ) )
384 {
385 return 1.0;
386 }
387
388 return 0.0;
389 } );
390}
391
392
393static void intersectsBackCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
394{
395 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
396 LIBEVAL::VALUE* arg = context->Pop();
397 LIBEVAL::VALUE* result = context->AllocValue();
398
399 result->Set( 0.0 );
400 context->Push( result );
401
402 if( !arg || arg->AsString().IsEmpty() )
403 {
404 if( context->HasErrorCallback() )
405 context->ReportError( MISSING_FP_ARG( wxT( "intersectsBackCourtyard()" ) ) );
406
407 return;
408 }
409
410 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
411 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
412
413 if( !item )
414 return;
415
416 result->SetDeferredEval(
417 [item, arg, context]() -> double
418 {
419 BOARD* board = item->GetBoard();
420 std::shared_ptr<SHAPE> itemShape;
421
422 if( searchFootprints( board, arg->AsString(), context,
423 [&]( FOOTPRINT* fp )
424 {
425 PTR_PTR_CACHE_KEY key = { fp, item };
426
427 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
428 {
429 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
430
431 auto i = board->m_IntersectsBCourtyardCache.find( key );
432
433 if( i != board->m_IntersectsBCourtyardCache.end() )
434 return i->second;
435 }
436
437 bool res = collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
438
439 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
440 {
441 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
442 board->m_IntersectsBCourtyardCache[ key ] = res;
443 }
444
445 return res;
446 } ) )
447 {
448 return 1.0;
449 }
450
451 return 0.0;
452 } );
453}
454
455
456bool collidesWithArea( BOARD_ITEM* aItem, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
457{
458 BOARD* board = aArea->GetBoard();
459 BOX2I areaBBox = aArea->GetBoundingBox();
460 std::shared_ptr<SHAPE> shape;
461
462 // Collisions include touching, so we need to deflate outline by enough to exclude it.
463 // This is particularly important for detecting copper fills as they will be exactly
464 // touching along the entire exclusion border.
465 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
466 areaOutline.ClearArcs();
467 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
469
470 if( aItem->GetFlags() & HOLE_PROXY )
471 {
472 if( aItem->Type() == PCB_PAD_T )
473 {
474 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
475 }
476 else if( aItem->Type() == PCB_VIA_T )
477 {
478 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
479
481 if( overlap.any() )
482 {
483 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
484 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
485 }
486 }
487
488 return false;
489 }
490
491 if( aItem->Type() == PCB_FOOTPRINT_T )
492 {
493 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
494
495 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
496 {
497 if( aCtx->HasErrorCallback() )
498 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
499
500 return false;
501 }
502
503 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
504 {
505 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
506
507 if( courtyard.OutlineCount() == 0 )
508 {
509 if( aCtx->HasErrorCallback() )
510 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
511 }
512 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
513 {
514 return true;
515 }
516 }
517
518 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
519 {
520 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
521
522 if( courtyard.OutlineCount() == 0 )
523 {
524 if( aCtx->HasErrorCallback() )
525 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
526 }
527 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
528 {
529 return true;
530 }
531 }
532
533 return false;
534 }
535
536 if( aItem->Type() == PCB_ZONE_T )
537 {
538 ZONE* zone = static_cast<ZONE*>( aItem );
539
540 if( !zone->IsFilled() )
541 return false;
542
543 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
544
545 if( zoneRTree )
546 {
547 for( size_t ii = 0; ii < aArea->GetLayerSet().size(); ++ii )
548 {
549 if( aArea->GetLayerSet().test( ii ) )
550 {
551 PCB_LAYER_ID layer = PCB_LAYER_ID( ii );
552
553 if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
554 {
555 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, layer ) )
556 return true;
557 }
558 }
559 }
560 }
561
562 return false;
563 }
564 else
565 {
566 PCB_LAYER_ID layer = aCtx->GetLayer();
567
568 if( layer != UNDEFINED_LAYER && !( aArea->GetLayerSet().Contains( layer ) ) )
569 return false;
570
571 if( !shape )
572 shape = aItem->GetEffectiveShape( layer );
573
574 return areaOutline.Collide( shape.get() );
575 }
576}
577
578
579bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
580 const std::function<bool( ZONE* )>& aFunc )
581{
582 if( aArg == wxT( "A" ) )
583 {
584 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
585 }
586 else if( aArg == wxT( "B" ) )
587 {
588 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
589 }
590 else if( KIID::SniffTest( aArg ) )
591 {
592 KIID target( aArg );
593
594 for( ZONE* area : aBoard->Zones() )
595 {
596 // Only a single zone can match the UUID; exit once we find a match whether
597 // "inside" or not
598 if( area->m_Uuid == target )
599 return aFunc( area );
600 }
601
602 for( FOOTPRINT* footprint : aBoard->Footprints() )
603 {
604 for( ZONE* area : footprint->Zones() )
605 {
606 // Only a single zone can match the UUID; exit once we find a match
607 // whether "inside" or not
608 if( area->m_Uuid == target )
609 return aFunc( area );
610 }
611 }
612
613 return false;
614 }
615 else // Match on zone name
616 {
617 for( ZONE* area : aBoard->Zones() )
618 {
619 if( area->GetZoneName().Matches( aArg ) )
620 {
621 // Many zones can match the name; exit only when we find an "inside"
622 if( aFunc( area ) )
623 return true;
624 }
625 }
626
627 for( FOOTPRINT* footprint : aBoard->Footprints() )
628 {
629 for( ZONE* area : footprint->Zones() )
630 {
631 // Many zones can match the name; exit only when we find an "inside"
632 if( area->GetZoneName().Matches( aArg ) )
633 {
634 if( aFunc( area ) )
635 return true;
636 }
637 }
638 }
639
640 return false;
641 }
642}
643
644
646{
647public:
649 {
650 m_item = aItem;
651 m_layers = aItem->GetLayerSet();
652 }
653
655 {
657 }
658
659 void Add( PCB_LAYER_ID aLayer )
660 {
661 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
662 }
663
664private:
667};
668
669
670#define MISSING_AREA_ARG( f ) \
671 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
672
673static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
674{
675 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
676 LIBEVAL::VALUE* arg = aCtx->Pop();
677 LIBEVAL::VALUE* result = aCtx->AllocValue();
678
679 result->Set( 0.0 );
680 aCtx->Push( result );
681
682 if( !arg || arg->AsString().IsEmpty() )
683 {
684 if( aCtx->HasErrorCallback() )
685 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
686
687 return;
688 }
689
690 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
691 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
692
693 if( !item )
694 return;
695
696 result->SetDeferredEval(
697 [item, arg, context]() -> double
698 {
699 BOARD* board = item->GetBoard();
700 PCB_LAYER_ID aLayer = context->GetLayer();
701 BOX2I itemBBox = item->GetBoundingBox();
702
703 if( searchAreas( board, arg->AsString(), context,
704 [&]( ZONE* aArea )
705 {
706 if( !aArea || aArea == item || aArea->GetParent() == item )
707 return false;
708
709 SCOPED_LAYERSET scopedLayerSet( aArea );
710
711 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
712 {
713 // Silk clearance tests are run across layer pairs
714 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
715 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
716 {
717 scopedLayerSet.Add( aLayer );
718 }
719 }
720
721 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
722
723 if( !commonLayers.any() )
724 return false;
725
726 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
727 return false;
728
729 LSET testLayers;
730
731 if( aLayer != UNDEFINED_LAYER )
732 testLayers.set( aLayer );
733 else
734 testLayers = commonLayers;
735
736 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
737 {
738 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
739
740 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
741 {
742 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
743
744 auto i = board->m_IntersectsAreaCache.find( key );
745
746 if( i != board->m_IntersectsAreaCache.end() && i->second )
747 return true;
748 }
749
750 bool collides = collidesWithArea( item, context, aArea );
751
752 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
753 {
754 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
755 board->m_IntersectsAreaCache[ key ] = collides;
756 }
757
758 if( collides )
759 return true;
760 }
761
762 return false;
763 } ) )
764 {
765 return 1.0;
766 }
767
768 return 0.0;
769 } );
770}
771
772
773static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
774{
775 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
776 LIBEVAL::VALUE* arg = aCtx->Pop();
777 LIBEVAL::VALUE* result = aCtx->AllocValue();
778
779 result->Set( 0.0 );
780 aCtx->Push( result );
781
782 if( !arg || arg->AsString().IsEmpty() )
783 {
784 if( aCtx->HasErrorCallback() )
785 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
786
787 return;
788 }
789
790 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
791 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
792
793 if( !item )
794 return;
795
796 result->SetDeferredEval(
797 [item, arg, context]() -> double
798 {
799 BOARD* board = item->GetBoard();
800 int maxError = board->GetDesignSettings().m_MaxError;
801 PCB_LAYER_ID layer = context->GetLayer();
802 BOX2I itemBBox = item->GetBoundingBox();
803
804 if( searchAreas( board, arg->AsString(), context,
805 [&]( ZONE* aArea )
806 {
807 if( !aArea || aArea == item || aArea->GetParent() == item )
808 return false;
809
810 if( item->Type() != PCB_FOOTPRINT_T )
811 {
812 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
813 return false;
814 }
815
816 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
817 return false;
818
819 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
820
821 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
822 {
823 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
824
825 auto i = board->m_EnclosedByAreaCache.find( key );
826
827 if( i != board->m_EnclosedByAreaCache.end() )
828 return i->second;
829 }
830
831 SHAPE_POLY_SET itemShape;
832 bool enclosedByArea;
833
834 if( item->Type() == PCB_ZONE_T )
835 {
836 itemShape = *static_cast<ZONE*>( item )->Outline();
837 }
838 else if( item->Type() == PCB_FOOTPRINT_T )
839 {
840 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
841
842 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
843 {
844 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
845 maxError, ERROR_OUTSIDE );
846 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
847 maxError, ERROR_OUTSIDE );
848 }
849 }
850 else
851 {
852 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
854 }
855
856 if( itemShape.IsEmpty() )
857 {
858 // If it's already empty then our test will have no meaning.
859 enclosedByArea = false;
860 }
861 else
862 {
863 itemShape.BooleanSubtract( *aArea->Outline() );
864
865 enclosedByArea = itemShape.IsEmpty();
866 }
867
868 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
869 {
870 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
871 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
872 }
873
874 return enclosedByArea;
875 } ) )
876 {
877 return 1.0;
878 }
879
880 return 0.0;
881 } );
882}
883
884
885#define MISSING_GROUP_ARG( f ) \
886 wxString::Format( _( "Missing group name argument to %s." ), f )
887
888static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
889{
890 LIBEVAL::VALUE* arg = aCtx->Pop();
891 LIBEVAL::VALUE* result = aCtx->AllocValue();
892
893 result->Set( 0.0 );
894 aCtx->Push( result );
895
896 if( !arg || arg->AsString().IsEmpty() )
897 {
898 if( aCtx->HasErrorCallback() )
899 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
900
901 return;
902 }
903
904 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
905 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
906
907 if( !item )
908 return;
909
910 result->SetDeferredEval(
911 [item, arg]() -> double
912 {
913 PCB_GROUP* group = item->GetParentGroup();
914
915 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
916 group = item->GetParent()->GetParentGroup();
917
918 while( group )
919 {
920 if( group->GetName().Matches( arg->AsString() ) )
921 return 1.0;
922
923 group = group->GetParentGroup();
924 }
925
926 return 0.0;
927 } );
928}
929
930
931#define MISSING_SHEET_ARG( f ) \
932 wxString::Format( _( "Missing sheet name argument to %s." ), f )
933
934static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
935{
936 LIBEVAL::VALUE* arg = aCtx->Pop();
937 LIBEVAL::VALUE* result = aCtx->AllocValue();
938
939 result->Set( 0.0 );
940 aCtx->Push( result );
941
942 if( !arg || arg->AsString().IsEmpty() )
943 {
944 if( aCtx->HasErrorCallback() )
945 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
946
947 return;
948 }
949
950 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
951 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
952
953 if( !item )
954 return;
955
956 result->SetDeferredEval(
957 [item, arg]() -> double
958 {
959 FOOTPRINT* fp = item->GetParentFootprint();
960
961 if( !fp && item->Type() == PCB_FOOTPRINT_T )
962 fp = static_cast<FOOTPRINT*>( item );
963
964 if( !fp )
965 return 0.0;
966
967 wxString sheetName = fp->GetSheetname();
968 wxString refName = arg->AsString();
969
970 if( sheetName.EndsWith( wxT("/") ) )
971 sheetName.RemoveLast();
972 if( refName.EndsWith( wxT("/") ) )
973 refName.RemoveLast();
974
975 if( sheetName.Matches( refName ) )
976 return 1.0;
977
978 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
979 && sheetName.IsEmpty() )
980 {
981 return 1.0;
982 }
983
984 return 0.0;
985 } );
986}
987
988
989#define MISSING_REF_ARG( f ) \
990 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
991
992static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
993{
994 LIBEVAL::VALUE* arg = aCtx->Pop();
995 LIBEVAL::VALUE* result = aCtx->AllocValue();
996
997 result->Set( 0.0 );
998 aCtx->Push( result );
999
1000 if( !arg || arg->AsString().IsEmpty() )
1001 {
1002 if( aCtx->HasErrorCallback() )
1003 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1004
1005 return;
1006 }
1007
1008 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1009 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1010
1011 if( !item )
1012 return;
1013
1014 result->SetDeferredEval(
1015 [item, arg]() -> double
1016 {
1017 ;
1018
1019 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1020 {
1021 if( parentFP->GetReference().Matches( arg->AsString() ) )
1022 return 1.0;
1023
1024 if( arg->AsString().Contains( ':' )
1025 && parentFP->GetFPIDAsString().Matches( arg->AsString() ) )
1026 {
1027 return 1.0;
1028 }
1029 }
1030
1031 return 0.0;
1032 } );
1033}
1034
1035
1036static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1037{
1038 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1039 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1040 LIBEVAL::VALUE* result = aCtx->AllocValue();
1041
1042 result->Set( 0.0 );
1043 aCtx->Push( result );
1044
1045 if( item && item->Type() == PCB_VIA_T
1046 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1047 {
1048 result->Set ( 1.0 );
1049 }
1050}
1051
1052
1053static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1054{
1055 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1056 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1057 LIBEVAL::VALUE* result = aCtx->AllocValue();
1058
1059 result->Set( 0.0 );
1060 aCtx->Push( result );
1061
1062 if( item && item->Type() == PCB_VIA_T
1063 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::BLIND_BURIED )
1064 {
1065 result->Set ( 1.0 );
1066 }
1067}
1068
1069
1070static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1071{
1072 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1073 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1074 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1075 LIBEVAL::VALUE* result = aCtx->AllocValue();
1076
1077 result->Set( 0.0 );
1078 aCtx->Push( result );
1079
1080 result->SetDeferredEval(
1081 [a, b, context]() -> double
1082 {
1083 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1084
1085 if( !netinfo )
1086 return 0.0;
1087
1088 wxString coupledNet;
1089 wxString dummy;
1090
1091 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1092 return 0.0;
1093
1096 {
1097 // DRC engine evaluates these singly, so we won't have a B item
1098 return 1.0;
1099 }
1100
1101 return b && b->GetNetname() == coupledNet;
1102 } );
1103}
1104
1105
1106#define MISSING_DP_ARG( f ) \
1107 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1108
1109static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1110{
1111 LIBEVAL::VALUE* argv = aCtx->Pop();
1112 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1113 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1114 LIBEVAL::VALUE* result = aCtx->AllocValue();
1115
1116 result->Set( 0.0 );
1117 aCtx->Push( result );
1118
1119 if( !argv || argv->AsString().IsEmpty() )
1120 {
1121 if( aCtx->HasErrorCallback() )
1122 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1123
1124 return;
1125 }
1126
1127 if( !item || !item->GetBoard() )
1128 return;
1129
1130 result->SetDeferredEval(
1131 [item, argv]() -> double
1132 {
1133 if( item && item->IsConnected() )
1134 {
1135 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1136
1137 if( !netinfo )
1138 return 0.0;
1139
1140 wxString refName = netinfo->GetNetname();
1141 wxString arg = argv->AsString();
1142 wxString baseName, coupledNet;
1143 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1144
1145 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1146 {
1147 if( baseName.Matches( arg ) )
1148 return 1.0;
1149
1150 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1151 return 1.0;
1152 }
1153 }
1154
1155 return 0.0;
1156 } );
1157}
1158
1159
1160static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1161{
1162 LIBEVAL::VALUE* arg = aCtx->Pop();
1163 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1164 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1165 LIBEVAL::VALUE* result = aCtx->AllocValue();
1166
1167 result->Set( "" );
1168 aCtx->Push( result );
1169
1170 if( !arg )
1171 {
1172 if( aCtx->HasErrorCallback() )
1173 {
1174 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1175 wxT( "getField()" ) ) );
1176 }
1177
1178 return;
1179 }
1180
1181 if( !item || !item->GetBoard() )
1182 return;
1183
1184 result->SetDeferredEval(
1185 [item, arg]() -> wxString
1186 {
1187 if( item && item->Type() == PCB_FOOTPRINT_T )
1188 {
1189 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1190
1191 PCB_FIELD* field = fp->GetFieldByName( arg->AsString() );
1192
1193 if( field )
1194 return field->GetText();
1195 }
1196
1197 return "";
1198 } );
1199}
1200
1201
1202static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1203{
1204 LIBEVAL::VALUE* arg = aCtx->Pop();
1205 LIBEVAL::VALUE* result = aCtx->AllocValue();
1206
1207 result->Set( 0.0 );
1208 aCtx->Push( result );
1209
1210 if( !arg || arg->AsString().IsEmpty() )
1211 {
1212 if( aCtx->HasErrorCallback() )
1213 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1214
1215 return;
1216 }
1217
1218 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1219 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1220
1221 if( !item )
1222 return;
1223
1224 result->SetDeferredEval(
1225 [item, arg]() -> double
1226 {
1227 if( !item->IsConnected() )
1228 return 0.0;
1229
1230 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1231 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1232
1233 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1234 return 1.0;
1235
1236 return 0.0;
1237 } );
1238}
1239
1240static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1241{
1242 LIBEVAL::VALUE* arg = aCtx->Pop();
1243 LIBEVAL::VALUE* result = aCtx->AllocValue();
1244
1245 result->Set( 0.0 );
1246 aCtx->Push( result );
1247
1248 if( !arg || arg->AsString().IsEmpty() )
1249 {
1250 if( aCtx->HasErrorCallback() )
1251 aCtx->ReportError(
1252 _( "Missing component class name argument to hasComponentClass()" ) );
1253
1254 return;
1255 }
1256
1257 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1258 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1259
1260 if( !item )
1261 return;
1262
1263 result->SetDeferredEval(
1264 [item, arg]() -> double
1265 {
1266 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
1267
1268 if( !footprint )
1269 return 0.0;
1270
1271 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1272
1273 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1274 return 1.0;
1275
1276 return 0.0;
1277 } );
1278}
1279
1280
1282{
1284}
1285
1286
1288{
1289 m_funcs.clear();
1290
1291 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1292
1293 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1294
1295 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1296 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1297 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1298 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1299 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1300 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1301
1302 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1303 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1304 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1305
1306 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1307 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1308
1309 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1310 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1311 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1312 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1313
1314 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1315 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1316 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1317
1318 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1319
1320 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1321 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1322}
const char * name
Definition: DXF_plotter.cpp:57
@ ERROR_OUTSIDE
Definition: approximation.h:33
constexpr int ARC_LOW_DEF
Definition: base_units.h:119
BASE_SET & set(size_t pos)
Definition: base_set.h:115
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:133
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:90
virtual void SetLayerSet(const LSET &aLayers)
Definition: board_item.h:265
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
Definition: board_item.cpp:255
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:319
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:278
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:298
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:257
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:215
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:288
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1922
const ZONES & Zones() const
Definition: board.h:335
const FOOTPRINTS & Footprints() const
Definition: board.h:331
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1297
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1298
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
std::shared_mutex m_CachesMutex
Definition: board.h:1291
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:475
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
bool ContainsClassName(const wxString &className) const
Determines if this (effective) component class contains a specific sub-class.
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Check if the given net is a diff pair, returning its polarity and complement if so.
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:48
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
Definition: drc_rtree.h:217
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:130
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
static ENUM_MAP< T > & Instance()
Definition: property.h:680
PCB_FIELD * GetFieldByName(const wxString &aFieldName)
Return a field in this symbol.
Definition: footprint.cpp:615
wxString GetSheetname() const
Definition: footprint.h:260
const COMPONENT_CLASS * GetComponentClass() const
Definition: footprint.h:1017
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2967
Definition: kiid.h:49
static bool SniffTest(const wxString &aCandidate)
Returns true if a string has the correct formatting to be a KIID.
Definition: kiid.cpp:178
void ReportError(const wxString &aErrorMsg)
void Push(VALUE *v)
void Set(double aValue)
virtual const wxString & AsString() const
void SetDeferredEval(std::function< double()> aLambda)
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:782
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:789
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:62
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition: netclass.cpp:141
Handle the data for a net.
Definition: netinfo.h:56
const wxString & GetNetname() const
Definition: netinfo.h:114
Definition: pad.h:54
void RegisterFunc(const wxString &funcSignature, LIBEVAL::FUNC_CALL_REF funcPtr)
std::map< wxString, LIBEVAL::FUNC_CALL_REF > m_funcs
int GetConstraint() const
PCB_LAYER_ID GetLayer() const
BOARD_ITEM * GetItem(int index) const
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
void Add(PCB_LAYER_ID aLayer)
SCOPED_LAYERSET(BOARD_ITEM *aItem)
Represent a set of closed polygons.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void Deflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError)
int OutlineCount() const
Return the number of outlines in the set.
SHAPE_POLY_SET CloneDropTriangulation() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:572
bool IsFilled() const
Definition: zone.h:264
SHAPE_POLY_SET * Outline()
Definition: zone.h:340
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
@ LENGTH_CONSTRAINT
Definition: drc_rule.h:68
@ SKEW_CONSTRAINT
Definition: drc_rule.h:69
#define _(s)
#define ROUTER_TRANSIENT
transient items that should NOT be cached
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
#define MALFORMED_COURTYARDS
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Cu
Definition: layer_ids.h:65
@ B_CrtYd
Definition: layer_ids.h:115
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:820
@ PTH
Plated through hole pad.
Class to handle a set of BOARD_ITEMs.
@ BLIND_BURIED
static void intersectsFrontCourtyardFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_SHEET_ARG(f)
bool collidesWithCourtyard(BOARD_ITEM *aItem, std::shared_ptr< SHAPE > &aItemShape, PCBEXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
#define MISSING_LAYER_ARG(f)
static void intersectsBackCourtyardFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool collidesWithArea(BOARD_ITEM *aItem, PCBEXPR_CONTEXT *aCtx, ZONE *aArea)
static void memberOfGroupFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_AREA_ARG(f)
static void isCoupledDiffPairFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void isPlatedFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool searchAreas(BOARD *aBoard, const wxString &aArg, PCBEXPR_CONTEXT *aCtx, const std::function< bool(ZONE *)> &aFunc)
static void existsOnLayerFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_GROUP_ARG(f)
static void isBlindBuriedViaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void memberOfSheetFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void hasComponentClassFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_REF_ARG(f)
#define MISSING_DP_ARG(f)
static void enclosedByAreaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void memberOfFootprintFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void isMicroVia(LIBEVAL::CONTEXT *aCtx, void *self)
static void getFieldFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void hasNetclassFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool fromToFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void intersectsCourtyardFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static bool searchFootprints(BOARD *aBoard, const wxString &aArg, PCBEXPR_CONTEXT *aCtx, const std::function< bool(FOOTPRINT *)> &aFunc)
static void inDiffPairFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void intersectsAreaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_FP_ARG(f)
std::vector< FAB_LAYER_COLOR > dummy
VECTOR3I res
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:107
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87