KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 SHAPE_POLY_SET::PM_FAST );
865
866 enclosedByArea = itemShape.IsEmpty();
867 }
868
869 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
870 {
871 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
872 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
873 }
874
875 return enclosedByArea;
876 } ) )
877 {
878 return 1.0;
879 }
880
881 return 0.0;
882 } );
883}
884
885
886#define MISSING_GROUP_ARG( f ) \
887 wxString::Format( _( "Missing group name argument to %s." ), f )
888
889static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
890{
891 LIBEVAL::VALUE* arg = aCtx->Pop();
892 LIBEVAL::VALUE* result = aCtx->AllocValue();
893
894 result->Set( 0.0 );
895 aCtx->Push( result );
896
897 if( !arg || arg->AsString().IsEmpty() )
898 {
899 if( aCtx->HasErrorCallback() )
900 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
901
902 return;
903 }
904
905 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
906 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
907
908 if( !item )
909 return;
910
911 result->SetDeferredEval(
912 [item, arg]() -> double
913 {
914 PCB_GROUP* group = item->GetParentGroup();
915
916 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
917 group = item->GetParent()->GetParentGroup();
918
919 while( group )
920 {
921 if( group->GetName().Matches( arg->AsString() ) )
922 return 1.0;
923
924 group = group->GetParentGroup();
925 }
926
927 return 0.0;
928 } );
929}
930
931
932#define MISSING_SHEET_ARG( f ) \
933 wxString::Format( _( "Missing sheet name argument to %s." ), f )
934
935static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
936{
937 LIBEVAL::VALUE* arg = aCtx->Pop();
938 LIBEVAL::VALUE* result = aCtx->AllocValue();
939
940 result->Set( 0.0 );
941 aCtx->Push( result );
942
943 if( !arg || arg->AsString().IsEmpty() )
944 {
945 if( aCtx->HasErrorCallback() )
946 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
947
948 return;
949 }
950
951 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
952 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
953
954 if( !item )
955 return;
956
957 result->SetDeferredEval(
958 [item, arg]() -> double
959 {
960 FOOTPRINT* fp = item->GetParentFootprint();
961
962 if( !fp && item->Type() == PCB_FOOTPRINT_T )
963 fp = static_cast<FOOTPRINT*>( item );
964
965 if( !fp )
966 return 0.0;
967
968 wxString sheetName = fp->GetSheetname();
969 wxString refName = arg->AsString();
970
971 if( sheetName.EndsWith( wxT("/") ) )
972 sheetName.RemoveLast();
973 if( refName.EndsWith( wxT("/") ) )
974 refName.RemoveLast();
975
976 if( sheetName.Matches( refName ) )
977 return 1.0;
978
979 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
980 && sheetName.IsEmpty() )
981 {
982 return 1.0;
983 }
984
985 return 0.0;
986 } );
987}
988
989
990#define MISSING_REF_ARG( f ) \
991 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
992
993static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
994{
995 LIBEVAL::VALUE* arg = aCtx->Pop();
996 LIBEVAL::VALUE* result = aCtx->AllocValue();
997
998 result->Set( 0.0 );
999 aCtx->Push( result );
1000
1001 if( !arg || arg->AsString().IsEmpty() )
1002 {
1003 if( aCtx->HasErrorCallback() )
1004 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1005
1006 return;
1007 }
1008
1009 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1010 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1011
1012 if( !item )
1013 return;
1014
1015 result->SetDeferredEval(
1016 [item, arg]() -> double
1017 {
1018 ;
1019
1020 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1021 {
1022 if( parentFP->GetReference().Matches( arg->AsString() ) )
1023 return 1.0;
1024
1025 if( arg->AsString().Contains( ':' )
1026 && parentFP->GetFPIDAsString().Matches( arg->AsString() ) )
1027 {
1028 return 1.0;
1029 }
1030 }
1031
1032 return 0.0;
1033 } );
1034}
1035
1036
1037static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1038{
1039 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1040 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1041 LIBEVAL::VALUE* result = aCtx->AllocValue();
1042
1043 result->Set( 0.0 );
1044 aCtx->Push( result );
1045
1046 if( item && item->Type() == PCB_VIA_T
1047 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1048 {
1049 result->Set ( 1.0 );
1050 }
1051}
1052
1053
1054static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1055{
1056 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1057 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1058 LIBEVAL::VALUE* result = aCtx->AllocValue();
1059
1060 result->Set( 0.0 );
1061 aCtx->Push( result );
1062
1063 if( item && item->Type() == PCB_VIA_T
1064 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::BLIND_BURIED )
1065 {
1066 result->Set ( 1.0 );
1067 }
1068}
1069
1070
1071static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1072{
1073 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1074 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1075 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1076 LIBEVAL::VALUE* result = aCtx->AllocValue();
1077
1078 result->Set( 0.0 );
1079 aCtx->Push( result );
1080
1081 result->SetDeferredEval(
1082 [a, b, context]() -> double
1083 {
1084 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1085
1086 if( !netinfo )
1087 return 0.0;
1088
1089 wxString coupledNet;
1090 wxString dummy;
1091
1092 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1093 return 0.0;
1094
1097 {
1098 // DRC engine evaluates these singly, so we won't have a B item
1099 return 1.0;
1100 }
1101
1102 return b && b->GetNetname() == coupledNet;
1103 } );
1104}
1105
1106
1107#define MISSING_DP_ARG( f ) \
1108 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1109
1110static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1111{
1112 LIBEVAL::VALUE* argv = aCtx->Pop();
1113 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1114 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1115 LIBEVAL::VALUE* result = aCtx->AllocValue();
1116
1117 result->Set( 0.0 );
1118 aCtx->Push( result );
1119
1120 if( !argv || argv->AsString().IsEmpty() )
1121 {
1122 if( aCtx->HasErrorCallback() )
1123 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1124
1125 return;
1126 }
1127
1128 if( !item || !item->GetBoard() )
1129 return;
1130
1131 result->SetDeferredEval(
1132 [item, argv]() -> double
1133 {
1134 if( item && item->IsConnected() )
1135 {
1136 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1137
1138 if( !netinfo )
1139 return 0.0;
1140
1141 wxString refName = netinfo->GetNetname();
1142 wxString arg = argv->AsString();
1143 wxString baseName, coupledNet;
1144 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1145
1146 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1147 {
1148 if( baseName.Matches( arg ) )
1149 return 1.0;
1150
1151 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1152 return 1.0;
1153 }
1154 }
1155
1156 return 0.0;
1157 } );
1158}
1159
1160
1161static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1162{
1163 LIBEVAL::VALUE* arg = aCtx->Pop();
1164 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1165 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1166 LIBEVAL::VALUE* result = aCtx->AllocValue();
1167
1168 result->Set( "" );
1169 aCtx->Push( result );
1170
1171 if( !arg )
1172 {
1173 if( aCtx->HasErrorCallback() )
1174 {
1175 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1176 wxT( "getField()" ) ) );
1177 }
1178
1179 return;
1180 }
1181
1182 if( !item || !item->GetBoard() )
1183 return;
1184
1185 result->SetDeferredEval(
1186 [item, arg]() -> wxString
1187 {
1188 if( item && item->Type() == PCB_FOOTPRINT_T )
1189 {
1190 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1191
1192 PCB_FIELD* field = fp->GetFieldByName( arg->AsString() );
1193
1194 if( field )
1195 return field->GetText();
1196 }
1197
1198 return "";
1199 } );
1200}
1201
1202
1203static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1204{
1205 LIBEVAL::VALUE* arg = aCtx->Pop();
1206 LIBEVAL::VALUE* result = aCtx->AllocValue();
1207
1208 result->Set( 0.0 );
1209 aCtx->Push( result );
1210
1211 if( !arg || arg->AsString().IsEmpty() )
1212 {
1213 if( aCtx->HasErrorCallback() )
1214 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1215
1216 return;
1217 }
1218
1219 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1220 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1221
1222 if( !item )
1223 return;
1224
1225 result->SetDeferredEval(
1226 [item, arg]() -> double
1227 {
1228 if( !item->IsConnected() )
1229 return 0.0;
1230
1231 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1232 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1233
1234 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1235 return 1.0;
1236
1237 return 0.0;
1238 } );
1239}
1240
1241static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1242{
1243 LIBEVAL::VALUE* arg = aCtx->Pop();
1244 LIBEVAL::VALUE* result = aCtx->AllocValue();
1245
1246 result->Set( 0.0 );
1247 aCtx->Push( result );
1248
1249 if( !arg || arg->AsString().IsEmpty() )
1250 {
1251 if( aCtx->HasErrorCallback() )
1252 aCtx->ReportError(
1253 _( "Missing component class name argument to hasComponentClass()" ) );
1254
1255 return;
1256 }
1257
1258 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1259 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1260
1261 if( !item )
1262 return;
1263
1264 result->SetDeferredEval(
1265 [item, arg]() -> double
1266 {
1267 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
1268
1269 if( !footprint )
1270 return 0.0;
1271
1272 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1273
1274 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1275 return 1.0;
1276
1277 return 0.0;
1278 } );
1279}
1280
1281
1283{
1285}
1286
1287
1289{
1290 m_funcs.clear();
1291
1292 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1293
1294 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1295
1296 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1297 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1298 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1299 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1300 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1301 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1302
1303 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1304 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1305 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1306
1307 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1308 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1309
1310 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1311 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1312 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1313 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1314
1315 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1316 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1317 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1318
1319 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1320
1321 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1322 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1323}
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:1921
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:663
PCB_FIELD * GetFieldByName(const wxString &aFieldName)
Return a field in this symbol.
Definition: footprint.cpp:588
wxString GetSheetname() const
Definition: footprint.h:266
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:2891
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:170
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:772
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:779
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:60
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:567
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:810
@ 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