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 The 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 testFootprintSelector( FOOTPRINT* aFp, const wxString& aSelector )
213{
214 // NOTE: This code may want to be somewhat more generalized, but for now it's implemented
215 // here to support functions like insersectsCourtyard where we want multiple ways to search
216 // for the footprints in question.
217 // If support for text variable replacement is added, it should happen before any other
218 // logic here, so that people can use text variables to contain references or LIBIDs.
219 // (see: https://gitlab.com/kicad/code/kicad/-/issues/11231)
220
221 // First check if we have a known directive
222 if( aSelector.Upper().StartsWith( wxT( "${CLASS:" ) ) && aSelector.EndsWith( '}' ) )
223 {
224 wxString name = aSelector.Mid( 8, aSelector.Length() - 9 );
225
226 const COMPONENT_CLASS* compClass = aFp->GetComponentClass();
227
228 if( compClass && compClass->ContainsClassName( name ) )
229 return true;
230 }
231 else if( aFp->GetReference().Matches( aSelector ) )
232 {
233 return true;
234 }
235 else if( aSelector.Contains( ':' ) && aFp->GetFPIDAsString().Matches( aSelector ) )
236 {
237 return true;
238 }
239
240 return false;
241}
242
243
244static bool searchFootprints( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
245 const std::function<bool( FOOTPRINT* )>& aFunc )
246{
247 if( aArg == wxT( "A" ) )
248 {
249 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 0 ) );
250
251 if( fp && aFunc( fp ) )
252 return true;
253 }
254 else if( aArg == wxT( "B" ) )
255 {
256 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 1 ) );
257
258 if( fp && aFunc( fp ) )
259 return true;
260 }
261 else for( FOOTPRINT* fp : aBoard->Footprints() )
262 {
263 if( testFootprintSelector( fp, aArg ) && aFunc( fp ) )
264 return true;
265 }
266
267 return false;
268}
269
270
271#define MISSING_FP_ARG( f ) \
272 wxString::Format( _( "Missing footprint argument (A, B, or reference designator) to %s." ), f )
273
274static void intersectsCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
275{
276 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
277 LIBEVAL::VALUE* arg = context->Pop();
278 LIBEVAL::VALUE* result = context->AllocValue();
279
280 result->Set( 0.0 );
281 context->Push( result );
282
283 if( !arg || arg->AsString().IsEmpty() )
284 {
285 if( context->HasErrorCallback() )
286 context->ReportError( MISSING_FP_ARG( wxT( "intersectsCourtyard()" ) ) );
287
288 return;
289 }
290
291 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
292 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
293
294 if( !item )
295 return;
296
297 result->SetDeferredEval(
298 [item, arg, context]() -> double
299 {
300 BOARD* board = item->GetBoard();
301 std::shared_ptr<SHAPE> itemShape;
302
303 if( searchFootprints( board, arg->AsString(), context,
304 [&]( FOOTPRINT* fp )
305 {
306 PTR_PTR_CACHE_KEY key = { fp, item };
307
308 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
309 {
310 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
311
312 auto i = board->m_IntersectsCourtyardCache.find( key );
313
314 if( i != board->m_IntersectsCourtyardCache.end() )
315 return i->second;
316 }
317
318 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu )
319 || collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
320
321 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
322 {
323 std::unique_lock<std::shared_mutex> cacheLock( board->m_CachesMutex );
324 board->m_IntersectsCourtyardCache[ key ] = res;
325 }
326
327 return res;
328 } ) )
329 {
330 return 1.0;
331 }
332
333 return 0.0;
334 } );
335}
336
337
338static void intersectsFrontCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
339{
340 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
341 LIBEVAL::VALUE* arg = context->Pop();
342 LIBEVAL::VALUE* result = context->AllocValue();
343
344 result->Set( 0.0 );
345 context->Push( result );
346
347 if( !arg || arg->AsString().IsEmpty() )
348 {
349 if( context->HasErrorCallback() )
350 context->ReportError( MISSING_FP_ARG( wxT( "intersectsFrontCourtyard()" ) ) );
351
352 return;
353 }
354
355 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
356 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
357
358 if( !item )
359 return;
360
361 result->SetDeferredEval(
362 [item, arg, context]() -> double
363 {
364 BOARD* board = item->GetBoard();
365 std::shared_ptr<SHAPE> itemShape;
366
367 if( searchFootprints( board, arg->AsString(), context,
368 [&]( FOOTPRINT* fp )
369 {
370 PTR_PTR_CACHE_KEY key = { fp, item };
371
372 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
373 {
374 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
375
376 auto i = board->m_IntersectsFCourtyardCache.find( key );
377
378 if( i != board->m_IntersectsFCourtyardCache.end() )
379 return i->second;
380 }
381
382 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu );
383
384 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
385 {
386 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
387 board->m_IntersectsFCourtyardCache[ key ] = res;
388 }
389
390 return res;
391 } ) )
392 {
393 return 1.0;
394 }
395
396 return 0.0;
397 } );
398}
399
400
401static void intersectsBackCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
402{
403 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
404 LIBEVAL::VALUE* arg = context->Pop();
405 LIBEVAL::VALUE* result = context->AllocValue();
406
407 result->Set( 0.0 );
408 context->Push( result );
409
410 if( !arg || arg->AsString().IsEmpty() )
411 {
412 if( context->HasErrorCallback() )
413 context->ReportError( MISSING_FP_ARG( wxT( "intersectsBackCourtyard()" ) ) );
414
415 return;
416 }
417
418 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
419 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
420
421 if( !item )
422 return;
423
424 result->SetDeferredEval(
425 [item, arg, context]() -> double
426 {
427 BOARD* board = item->GetBoard();
428 std::shared_ptr<SHAPE> itemShape;
429
430 if( searchFootprints( board, arg->AsString(), context,
431 [&]( FOOTPRINT* fp )
432 {
433 PTR_PTR_CACHE_KEY key = { fp, item };
434
435 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
436 {
437 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
438
439 auto i = board->m_IntersectsBCourtyardCache.find( key );
440
441 if( i != board->m_IntersectsBCourtyardCache.end() )
442 return i->second;
443 }
444
445 bool res = collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
446
447 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
448 {
449 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
450 board->m_IntersectsBCourtyardCache[ key ] = res;
451 }
452
453 return res;
454 } ) )
455 {
456 return 1.0;
457 }
458
459 return 0.0;
460 } );
461}
462
463
464bool collidesWithArea( BOARD_ITEM* aItem, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
465{
466 BOARD* board = aArea->GetBoard();
467 BOX2I areaBBox = aArea->GetBoundingBox();
468 std::shared_ptr<SHAPE> shape;
469
470 // Collisions include touching, so we need to deflate outline by enough to exclude it.
471 // This is particularly important for detecting copper fills as they will be exactly
472 // touching along the entire exclusion border.
473 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
474 areaOutline.ClearArcs();
475 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
477
478 if( aItem->GetFlags() & HOLE_PROXY )
479 {
480 if( aItem->Type() == PCB_PAD_T )
481 {
482 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
483 }
484 else if( aItem->Type() == PCB_VIA_T )
485 {
486 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
487
489 if( overlap.any() )
490 {
491 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
492 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
493 }
494 }
495
496 return false;
497 }
498
499 if( aItem->Type() == PCB_FOOTPRINT_T )
500 {
501 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
502
503 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
504 {
505 if( aCtx->HasErrorCallback() )
506 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
507
508 return false;
509 }
510
511 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
512 {
513 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
514
515 if( courtyard.OutlineCount() == 0 )
516 {
517 if( aCtx->HasErrorCallback() )
518 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
519 }
520 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
521 {
522 return true;
523 }
524 }
525
526 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
527 {
528 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
529
530 if( courtyard.OutlineCount() == 0 )
531 {
532 if( aCtx->HasErrorCallback() )
533 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
534 }
535 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
536 {
537 return true;
538 }
539 }
540
541 return false;
542 }
543
544 if( aItem->Type() == PCB_ZONE_T )
545 {
546 ZONE* zone = static_cast<ZONE*>( aItem );
547
548 if( !zone->IsFilled() )
549 return false;
550
551 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
552
553 if( zoneRTree )
554 {
555 for( size_t ii = 0; ii < aArea->GetLayerSet().size(); ++ii )
556 {
557 if( aArea->GetLayerSet().test( ii ) )
558 {
559 PCB_LAYER_ID layer = PCB_LAYER_ID( ii );
560
561 if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
562 {
563 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, layer ) )
564 return true;
565 }
566 }
567 }
568 }
569
570 return false;
571 }
572 else
573 {
574 PCB_LAYER_ID layer = aCtx->GetLayer();
575
576 if( layer != UNDEFINED_LAYER && !( aArea->GetLayerSet().Contains( layer ) ) )
577 return false;
578
579 if( !shape )
580 shape = aItem->GetEffectiveShape( layer );
581
582 return areaOutline.Collide( shape.get() );
583 }
584}
585
586
587bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
588 const std::function<bool( ZONE* )>& aFunc )
589{
590 if( aArg == wxT( "A" ) )
591 {
592 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
593 }
594 else if( aArg == wxT( "B" ) )
595 {
596 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
597 }
598 else if( KIID::SniffTest( aArg ) )
599 {
600 KIID target( aArg );
601
602 for( ZONE* area : aBoard->Zones() )
603 {
604 // Only a single zone can match the UUID; exit once we find a match whether
605 // "inside" or not
606 if( area->m_Uuid == target )
607 return aFunc( area );
608 }
609
610 for( FOOTPRINT* footprint : aBoard->Footprints() )
611 {
612 for( ZONE* area : footprint->Zones() )
613 {
614 // Only a single zone can match the UUID; exit once we find a match
615 // whether "inside" or not
616 if( area->m_Uuid == target )
617 return aFunc( area );
618 }
619 }
620
621 return false;
622 }
623 else // Match on zone name
624 {
625 for( ZONE* area : aBoard->Zones() )
626 {
627 if( area->GetZoneName().Matches( aArg ) )
628 {
629 // Many zones can match the name; exit only when we find an "inside"
630 if( aFunc( area ) )
631 return true;
632 }
633 }
634
635 for( FOOTPRINT* footprint : aBoard->Footprints() )
636 {
637 for( ZONE* area : footprint->Zones() )
638 {
639 // Many zones can match the name; exit only when we find an "inside"
640 if( area->GetZoneName().Matches( aArg ) )
641 {
642 if( aFunc( area ) )
643 return true;
644 }
645 }
646 }
647
648 return false;
649 }
650}
651
652
654{
655public:
657 {
658 m_item = aItem;
659 m_layers = aItem->GetLayerSet();
660 }
661
663 {
665 }
666
667 void Add( PCB_LAYER_ID aLayer )
668 {
669 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
670 }
671
672private:
675};
676
677
678#define MISSING_AREA_ARG( f ) \
679 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
680
681static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
682{
683 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
684 LIBEVAL::VALUE* arg = aCtx->Pop();
685 LIBEVAL::VALUE* result = aCtx->AllocValue();
686
687 result->Set( 0.0 );
688 aCtx->Push( result );
689
690 if( !arg || arg->AsString().IsEmpty() )
691 {
692 if( aCtx->HasErrorCallback() )
693 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
694
695 return;
696 }
697
698 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
699 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
700
701 if( !item )
702 return;
703
704 result->SetDeferredEval(
705 [item, arg, context]() -> double
706 {
707 BOARD* board = item->GetBoard();
708 PCB_LAYER_ID aLayer = context->GetLayer();
709 BOX2I itemBBox = item->GetBoundingBox();
710
711 if( searchAreas( board, arg->AsString(), context,
712 [&]( ZONE* aArea )
713 {
714 if( !aArea || aArea == item || aArea->GetParent() == item )
715 return false;
716
717 SCOPED_LAYERSET scopedLayerSet( aArea );
718
719 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
720 {
721 // Silk clearance tests are run across layer pairs
722 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
723 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
724 {
725 scopedLayerSet.Add( aLayer );
726 }
727 }
728
729 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
730
731 if( !commonLayers.any() )
732 return false;
733
734 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
735 return false;
736
737 LSET testLayers;
738
739 if( aLayer != UNDEFINED_LAYER )
740 testLayers.set( aLayer );
741 else
742 testLayers = commonLayers;
743
744 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
745 {
746 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
747
748 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
749 {
750 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
751
752 auto i = board->m_IntersectsAreaCache.find( key );
753
754 if( i != board->m_IntersectsAreaCache.end() && i->second )
755 return true;
756 }
757
758 bool collides = collidesWithArea( item, context, aArea );
759
760 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
761 {
762 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
763 board->m_IntersectsAreaCache[ key ] = collides;
764 }
765
766 if( collides )
767 return true;
768 }
769
770 return false;
771 } ) )
772 {
773 return 1.0;
774 }
775
776 return 0.0;
777 } );
778}
779
780
781static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
782{
783 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
784 LIBEVAL::VALUE* arg = aCtx->Pop();
785 LIBEVAL::VALUE* result = aCtx->AllocValue();
786
787 result->Set( 0.0 );
788 aCtx->Push( result );
789
790 if( !arg || arg->AsString().IsEmpty() )
791 {
792 if( aCtx->HasErrorCallback() )
793 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
794
795 return;
796 }
797
798 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
799 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
800
801 if( !item )
802 return;
803
804 result->SetDeferredEval(
805 [item, arg, context]() -> double
806 {
807 BOARD* board = item->GetBoard();
808 int maxError = board->GetDesignSettings().m_MaxError;
809 PCB_LAYER_ID layer = context->GetLayer();
810 BOX2I itemBBox = item->GetBoundingBox();
811
812 if( searchAreas( board, arg->AsString(), context,
813 [&]( ZONE* aArea )
814 {
815 if( !aArea || aArea == item || aArea->GetParent() == item )
816 return false;
817
818 if( item->Type() != PCB_FOOTPRINT_T )
819 {
820 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
821 return false;
822 }
823
824 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
825 return false;
826
827 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
828
829 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
830 {
831 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
832
833 auto i = board->m_EnclosedByAreaCache.find( key );
834
835 if( i != board->m_EnclosedByAreaCache.end() )
836 return i->second;
837 }
838
839 SHAPE_POLY_SET itemShape;
840 bool enclosedByArea;
841
842 if( item->Type() == PCB_ZONE_T )
843 {
844 itemShape = *static_cast<ZONE*>( item )->Outline();
845 }
846 else if( item->Type() == PCB_FOOTPRINT_T )
847 {
848 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
849
850 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
851 {
852 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
853 maxError, ERROR_OUTSIDE );
854 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
855 maxError, ERROR_OUTSIDE );
856 }
857 }
858 else
859 {
860 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
862 }
863
864 if( itemShape.IsEmpty() )
865 {
866 // If it's already empty then our test will have no meaning.
867 enclosedByArea = false;
868 }
869 else
870 {
871 itemShape.BooleanSubtract( *aArea->Outline() );
872
873 enclosedByArea = itemShape.IsEmpty();
874 }
875
876 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
877 {
878 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
879 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
880 }
881
882 return enclosedByArea;
883 } ) )
884 {
885 return 1.0;
886 }
887
888 return 0.0;
889 } );
890}
891
892
893#define MISSING_GROUP_ARG( f ) \
894 wxString::Format( _( "Missing group name argument to %s." ), f )
895
896static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
897{
898 LIBEVAL::VALUE* arg = aCtx->Pop();
899 LIBEVAL::VALUE* result = aCtx->AllocValue();
900
901 result->Set( 0.0 );
902 aCtx->Push( result );
903
904 if( !arg || arg->AsString().IsEmpty() )
905 {
906 if( aCtx->HasErrorCallback() )
907 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
908
909 return;
910 }
911
912 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
913 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
914
915 if( !item )
916 return;
917
918 result->SetDeferredEval(
919 [item, arg]() -> double
920 {
921 PCB_GROUP* group = item->GetParentGroup();
922
923 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
924 group = item->GetParent()->GetParentGroup();
925
926 while( group )
927 {
928 if( group->GetName().Matches( arg->AsString() ) )
929 return 1.0;
930
931 group = group->GetParentGroup();
932 }
933
934 return 0.0;
935 } );
936}
937
938
939#define MISSING_SHEET_ARG( f ) \
940 wxString::Format( _( "Missing sheet name argument to %s." ), f )
941
942static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
943{
944 LIBEVAL::VALUE* arg = aCtx->Pop();
945 LIBEVAL::VALUE* result = aCtx->AllocValue();
946
947 result->Set( 0.0 );
948 aCtx->Push( result );
949
950 if( !arg || arg->AsString().IsEmpty() )
951 {
952 if( aCtx->HasErrorCallback() )
953 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
954
955 return;
956 }
957
958 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
959 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
960
961 if( !item )
962 return;
963
964 result->SetDeferredEval(
965 [item, arg]() -> double
966 {
967 FOOTPRINT* fp = item->GetParentFootprint();
968
969 if( !fp && item->Type() == PCB_FOOTPRINT_T )
970 fp = static_cast<FOOTPRINT*>( item );
971
972 if( !fp )
973 return 0.0;
974
975 wxString sheetName = fp->GetSheetname();
976 wxString refName = arg->AsString();
977
978 if( sheetName.EndsWith( wxT("/") ) )
979 sheetName.RemoveLast();
980 if( refName.EndsWith( wxT("/") ) )
981 refName.RemoveLast();
982
983 if( sheetName.Matches( refName ) )
984 return 1.0;
985
986 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
987 && sheetName.IsEmpty() )
988 {
989 return 1.0;
990 }
991
992 return 0.0;
993 } );
994}
995
996
997#define MISSING_REF_ARG( f ) \
998 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
999
1000static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1001{
1002 LIBEVAL::VALUE* arg = aCtx->Pop();
1003 LIBEVAL::VALUE* result = aCtx->AllocValue();
1004
1005 result->Set( 0.0 );
1006 aCtx->Push( result );
1007
1008 if( !arg || arg->AsString().IsEmpty() )
1009 {
1010 if( aCtx->HasErrorCallback() )
1011 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1012
1013 return;
1014 }
1015
1016 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1017 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1018
1019 if( !item )
1020 return;
1021
1022 result->SetDeferredEval(
1023 [item, arg]() -> double
1024 {
1025 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1026 {
1027 if( testFootprintSelector( parentFP, arg->AsString() ) )
1028 return 1.0;
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->GetField( 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:59
@ 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:116
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.
int GetDRCEpsilon() const
Return an epsilon which accounts for rounding errors, etc.
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:267
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:321
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:259
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:217
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:288
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:296
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2005
const ZONES & Zones() const
Definition: board.h:341
const FOOTPRINTS & Footprints() const
Definition: board.h:337
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1327
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1328
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:948
std::shared_mutex m_CachesMutex
Definition: board.h:1321
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:495
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:214
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:78
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:128
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
wxString GetSheetname() const
Definition: footprint.h:265
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
Definition: footprint.cpp:580
const COMPONENT_CLASS * GetComponentClass() const
Returns the component class for this footprint.
Definition: footprint.h:1011
wxString GetFPIDAsString() const
Definition: footprint.h:253
const wxString & GetReference() const
Definition: footprint.h:621
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2976
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:37
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:683
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:690
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:63
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:45
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition: netclass.cpp:276
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:74
const BOX2I GetBoundingBox() const override
Definition: zone.cpp:641
bool IsFilled() const
Definition: zone.h:290
SHAPE_POLY_SET * Outline()
Definition: zone.h:366
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:134
@ 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:722
@ 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 bool testFootprintSelector(FOOTPRINT *aFp, const wxString &aSelector)
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