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>
32#include <drc/drc_rtree.h>
33#include <drc/drc_engine.h>
34#include <lset.h>
35#include <pcb_track.h>
36#include <pcb_group.h>
38#include <pcbexpr_evaluator.h>
42
43
44bool fromToFunc( LIBEVAL::CONTEXT* aCtx, void* self )
45{
46 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
47 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
49 LIBEVAL::VALUE* argTo = aCtx->Pop();
50 LIBEVAL::VALUE* argFrom = aCtx->Pop();
51
52 result->Set(0.0);
53 aCtx->Push( result );
54
55 if(!item)
56 return false;
57
58 auto ftCache = item->GetBoard()->GetConnectivity()->GetFromToCache();
59
60 if( !ftCache )
61 {
62 wxLogWarning( wxT( "Attempting to call fromTo() with non-existent from-to cache." ) );
63 return true;
64 }
65
66 if( ftCache->IsOnFromToPath( static_cast<BOARD_CONNECTED_ITEM*>( item ),
67 argFrom->AsString(), argTo->AsString() ) )
68 {
69 result->Set(1.0);
70 }
71
72 return true;
73}
74
75
76#define MISSING_LAYER_ARG( f ) wxString::Format( _( "Missing layer name argument to %s." ), f )
77
78static void existsOnLayerFunc( LIBEVAL::CONTEXT* aCtx, void *self )
79{
80 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
81 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
82 LIBEVAL::VALUE* arg = aCtx->Pop();
84
85 result->Set( 0.0 );
86 aCtx->Push( result );
87
88 if( !item )
89 return;
90
91 if( !arg || arg->AsString().IsEmpty() )
92 {
93 if( aCtx->HasErrorCallback() )
94 aCtx->ReportError( MISSING_LAYER_ARG( wxT( "existsOnLayer()" ) ) );
95
96 return;
97 }
98
99 result->SetDeferredEval(
100 [item, arg, aCtx]() -> double
101 {
102 const wxString& layerName = arg->AsString();
103 wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
104
105 if( aCtx->HasErrorCallback())
106 {
107 /*
108 * Interpreted version
109 */
110
111 bool anyMatch = false;
112
113 for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
114 {
115 wxPGChoiceEntry& entry = layerMap[ ii ];
116
117 if( entry.GetText().Matches( layerName ))
118 {
119 anyMatch = true;
120
121 if( item->IsOnLayer( ToLAYER_ID( entry.GetValue() ) ) )
122 return 1.0;
123 }
124 }
125
126 if( !anyMatch )
127 {
128 aCtx->ReportError( wxString::Format( _( "Unrecognized layer '%s'" ),
129 layerName ) );
130 }
131
132 return 0.0;
133 }
134 else
135 {
136 /*
137 * Compiled version
138 */
139
140 BOARD* board = item->GetBoard();
141
142 {
143 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
144
145 auto i = board->m_LayerExpressionCache.find( layerName );
146
147 if( i != board->m_LayerExpressionCache.end() )
148 return ( item->GetLayerSet() & i->second ).any() ? 1.0 : 0.0;
149 }
150
151 LSET mask;
152
153 for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
154 {
155 wxPGChoiceEntry& entry = layerMap[ ii ];
156
157 if( entry.GetText().Matches( layerName ) )
158 mask.set( ToLAYER_ID( entry.GetValue() ) );
159 }
160
161 {
162 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
163 board->m_LayerExpressionCache[ layerName ] = mask;
164 }
165
166 return ( item->GetLayerSet() & mask ).any() ? 1.0 : 0.0;
167 }
168 } );
169}
170
171
172static void isPlatedFunc( LIBEVAL::CONTEXT* aCtx, void* self )
173{
175
176 result->Set( 0.0 );
177 aCtx->Push( result );
178
179 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
180 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
181
182 if( !item )
183 return;
184
185 if( item->Type() == PCB_PAD_T && static_cast<PAD*>( item )->GetAttribute() == PAD_ATTRIB::PTH )
186 result->Set( 1.0 );
187 else if( item->Type() == PCB_VIA_T )
188 result->Set( 1.0 );
189}
190
191
192bool collidesWithCourtyard( BOARD_ITEM* aItem, std::shared_ptr<SHAPE>& aItemShape,
193 PCBEXPR_CONTEXT* aCtx, FOOTPRINT* aFootprint, PCB_LAYER_ID aSide )
194{
195 SHAPE_POLY_SET footprintCourtyard;
196
197 footprintCourtyard = aFootprint->GetCourtyard( aSide );
198
199 if( !aItemShape )
200 {
201 // Since rules are used for zone filling we can't rely on the filled shapes.
202 // Use the zone outline instead.
203 if( ZONE* zone = dynamic_cast<ZONE*>( aItem ) )
204 aItemShape.reset( zone->Outline()->Clone() );
205 else
206 aItemShape = aItem->GetEffectiveShape( aCtx->GetLayer() );
207 }
208
209 return footprintCourtyard.Collide( aItemShape.get() );
210};
211
212
213static bool testFootprintSelector( FOOTPRINT* aFp, const wxString& aSelector )
214{
215 // NOTE: This code may want to be somewhat more generalized, but for now it's implemented
216 // here to support functions like insersectsCourtyard where we want multiple ways to search
217 // for the footprints in question.
218 // If support for text variable replacement is added, it should happen before any other
219 // logic here, so that people can use text variables to contain references or LIBIDs.
220 // (see: https://gitlab.com/kicad/code/kicad/-/issues/11231)
221
222 // First check if we have a known directive
223 if( aSelector.Upper().StartsWith( wxT( "${CLASS:" ) ) && aSelector.EndsWith( '}' ) )
224 {
225 wxString name = aSelector.Mid( 8, aSelector.Length() - 9 );
226
227 const COMPONENT_CLASS* compClass = aFp->GetComponentClass();
228
229 if( compClass && compClass->ContainsClassName( name ) )
230 return true;
231 }
232 else if( aFp->GetReference().Matches( aSelector ) )
233 {
234 return true;
235 }
236 else if( aSelector.Contains( ':' ) && aFp->GetFPIDAsString().Matches( aSelector ) )
237 {
238 return true;
239 }
240
241 return false;
242}
243
244
245static bool searchFootprints( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
246 const std::function<bool( FOOTPRINT* )>& aFunc )
247{
248 if( aArg == wxT( "A" ) )
249 {
250 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 0 ) );
251
252 if( fp && aFunc( fp ) )
253 return true;
254 }
255 else if( aArg == wxT( "B" ) )
256 {
257 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 1 ) );
258
259 if( fp && aFunc( fp ) )
260 return true;
261 }
262 else for( FOOTPRINT* fp : aBoard->Footprints() )
263 {
264 if( testFootprintSelector( fp, aArg ) && aFunc( fp ) )
265 return true;
266 }
267
268 return false;
269}
270
271
272#define MISSING_FP_ARG( f ) \
273 wxString::Format( _( "Missing footprint argument (A, B, or reference designator) to %s." ), f )
274
275static void intersectsCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
276{
277 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
278 LIBEVAL::VALUE* arg = context->Pop();
279 LIBEVAL::VALUE* result = context->AllocValue();
280
281 result->Set( 0.0 );
282 context->Push( result );
283
284 if( !arg || arg->AsString().IsEmpty() )
285 {
286 if( context->HasErrorCallback() )
287 context->ReportError( MISSING_FP_ARG( wxT( "intersectsCourtyard()" ) ) );
288
289 return;
290 }
291
292 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
293 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
294
295 if( !item )
296 return;
297
298 result->SetDeferredEval(
299 [item, arg, context]() -> double
300 {
301 BOARD* board = item->GetBoard();
302 std::shared_ptr<SHAPE> itemShape;
303
304 if( searchFootprints( board, arg->AsString(), context,
305 [&]( FOOTPRINT* fp )
306 {
307 PTR_PTR_CACHE_KEY key = { fp, item };
308
309 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
310 {
311 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
312
313 auto i = board->m_IntersectsCourtyardCache.find( key );
314
315 if( i != board->m_IntersectsCourtyardCache.end() )
316 return i->second;
317 }
318
319 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu )
320 || collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
321
322 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
323 {
324 std::unique_lock<std::shared_mutex> cacheLock( board->m_CachesMutex );
325 board->m_IntersectsCourtyardCache[ key ] = res;
326 }
327
328 return res;
329 } ) )
330 {
331 return 1.0;
332 }
333
334 return 0.0;
335 } );
336}
337
338
339static void intersectsFrontCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
340{
341 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
342 LIBEVAL::VALUE* arg = context->Pop();
343 LIBEVAL::VALUE* result = context->AllocValue();
344
345 result->Set( 0.0 );
346 context->Push( result );
347
348 if( !arg || arg->AsString().IsEmpty() )
349 {
350 if( context->HasErrorCallback() )
351 context->ReportError( MISSING_FP_ARG( wxT( "intersectsFrontCourtyard()" ) ) );
352
353 return;
354 }
355
356 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
357 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
358
359 if( !item )
360 return;
361
362 result->SetDeferredEval(
363 [item, arg, context]() -> double
364 {
365 BOARD* board = item->GetBoard();
366 std::shared_ptr<SHAPE> itemShape;
367
368 if( searchFootprints( board, arg->AsString(), context,
369 [&]( FOOTPRINT* fp )
370 {
371 PTR_PTR_CACHE_KEY key = { fp, item };
372
373 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
374 {
375 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
376
377 auto i = board->m_IntersectsFCourtyardCache.find( key );
378
379 if( i != board->m_IntersectsFCourtyardCache.end() )
380 return i->second;
381 }
382
383 PCB_LAYER_ID layerId = fp->IsFlipped() ? B_Cu : F_Cu;
384
385 bool res = collidesWithCourtyard( item, itemShape, context, fp, layerId );
386
387 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
388 {
389 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
390 board->m_IntersectsFCourtyardCache[ key ] = res;
391 }
392
393 return res;
394 } ) )
395 {
396 return 1.0;
397 }
398
399 return 0.0;
400 } );
401}
402
403
404static void intersectsBackCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
405{
406 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
407 LIBEVAL::VALUE* arg = context->Pop();
408 LIBEVAL::VALUE* result = context->AllocValue();
409
410 result->Set( 0.0 );
411 context->Push( result );
412
413 if( !arg || arg->AsString().IsEmpty() )
414 {
415 if( context->HasErrorCallback() )
416 context->ReportError( MISSING_FP_ARG( wxT( "intersectsBackCourtyard()" ) ) );
417
418 return;
419 }
420
421 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
422 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
423
424 if( !item )
425 return;
426
427 result->SetDeferredEval(
428 [item, arg, context]() -> double
429 {
430 BOARD* board = item->GetBoard();
431 std::shared_ptr<SHAPE> itemShape;
432
433 if( searchFootprints( board, arg->AsString(), context,
434 [&]( FOOTPRINT* fp )
435 {
436 PTR_PTR_CACHE_KEY key = { fp, item };
437
438 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
439 {
440 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
441
442 auto i = board->m_IntersectsBCourtyardCache.find( key );
443
444 if( i != board->m_IntersectsBCourtyardCache.end() )
445 return i->second;
446 }
447
448 PCB_LAYER_ID layerId = fp->IsFlipped() ? F_Cu : B_Cu;
449
450 bool res = collidesWithCourtyard( item, itemShape, context, fp, layerId );
451
452 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
453 {
454 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
455 board->m_IntersectsBCourtyardCache[ key ] = res;
456 }
457
458 return res;
459 } ) )
460 {
461 return 1.0;
462 }
463
464 return 0.0;
465 } );
466}
467
468
469bool collidesWithArea( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
470{
471 BOARD* board = aArea->GetBoard();
472 BOX2I areaBBox = aArea->GetBoundingBox();
473
474 // Collisions include touching, so we need to deflate outline by enough to exclude it.
475 // This is particularly important for detecting copper fills as they will be exactly
476 // touching along the entire exclusion border.
477 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
478 areaOutline.ClearArcs();
479 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
481
482 if( aItem->GetFlags() & HOLE_PROXY )
483 {
484 if( aItem->Type() == PCB_PAD_T )
485 {
486 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
487 }
488 else if( aItem->Type() == PCB_VIA_T )
489 {
490 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
491
493 if( overlap.any() )
494 {
495 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
496 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
497 }
498 }
499
500 return false;
501 }
502
503 if( aItem->Type() == PCB_FOOTPRINT_T )
504 {
505 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
506
507 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
508 {
509 if( aCtx->HasErrorCallback() )
510 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
511
512 return false;
513 }
514
515 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
516 {
517 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
518
519 if( courtyard.OutlineCount() == 0 )
520 {
521 if( aCtx->HasErrorCallback() )
522 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
523 }
524 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
525 {
526 return true;
527 }
528 }
529
530 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
531 {
532 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
533
534 if( courtyard.OutlineCount() == 0 )
535 {
536 if( aCtx->HasErrorCallback() )
537 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
538 }
539 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
540 {
541 return true;
542 }
543 }
544
545 return false;
546 }
547
548 if( aItem->Type() == PCB_ZONE_T )
549 {
550 ZONE* zone = static_cast<ZONE*>( aItem );
551
552 if( !zone->IsFilled() )
553 return false;
554
555 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
556
557 if( zoneRTree )
558 {
559 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, aLayer ) )
560 return true;
561 }
562
563 return false;
564 }
565 else
566 {
567 if( !aArea->GetLayerSet().Contains( aLayer ) )
568 return false;
569
570 return areaOutline.Collide( aItem->GetEffectiveShape( aLayer ).get() );
571 }
572}
573
574
575bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
576 const std::function<bool( ZONE* )>& aFunc )
577{
578 if( aArg == wxT( "A" ) )
579 {
580 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
581 }
582 else if( aArg == wxT( "B" ) )
583 {
584 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
585 }
586 else if( KIID::SniffTest( aArg ) )
587 {
588 KIID target( aArg );
589
590 for( ZONE* area : aBoard->Zones() )
591 {
592 // Only a single zone can match the UUID; exit once we find a match whether
593 // "inside" or not
594 if( area->m_Uuid == target )
595 return aFunc( area );
596 }
597
598 for( FOOTPRINT* footprint : aBoard->Footprints() )
599 {
600 for( ZONE* area : footprint->Zones() )
601 {
602 // Only a single zone can match the UUID; exit once we find a match
603 // whether "inside" or not
604 if( area->m_Uuid == target )
605 return aFunc( area );
606 }
607 }
608
609 return false;
610 }
611 else // Match on zone name
612 {
613 for( ZONE* area : aBoard->Zones() )
614 {
615 if( area->GetZoneName().Matches( aArg ) )
616 {
617 // Many zones can match the name; exit only when we find an "inside"
618 if( aFunc( area ) )
619 return true;
620 }
621 }
622
623 for( FOOTPRINT* footprint : aBoard->Footprints() )
624 {
625 for( ZONE* area : footprint->Zones() )
626 {
627 // Many zones can match the name; exit only when we find an "inside"
628 if( area->GetZoneName().Matches( aArg ) )
629 {
630 if( aFunc( area ) )
631 return true;
632 }
633 }
634 }
635
636 return false;
637 }
638}
639
640
642{
643public:
645 {
646 m_item = aItem;
647 m_layers = aItem->GetLayerSet();
648 }
649
651 {
652 m_item->SetLayerSet( m_layers );
653 }
654
655 void Add( PCB_LAYER_ID aLayer )
656 {
657 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
658 }
659
660private:
663};
664
665
666#define MISSING_AREA_ARG( f ) \
667 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
668
669static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
670{
671 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
672 LIBEVAL::VALUE* arg = aCtx->Pop();
674
675 result->Set( 0.0 );
676 aCtx->Push( result );
677
678 if( !arg || arg->AsString().IsEmpty() )
679 {
680 if( aCtx->HasErrorCallback() )
681 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
682
683 return;
684 }
685
686 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
687 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
688
689 if( !item )
690 return;
691
692 result->SetDeferredEval(
693 [item, arg, context]() -> double
694 {
695 BOARD* board = item->GetBoard();
696 PCB_LAYER_ID aLayer = context->GetLayer();
697 BOX2I itemBBox = item->GetBoundingBox();
698
699 if( searchAreas( board, arg->AsString(), context,
700 [&]( ZONE* aArea )
701 {
702 if( !aArea || aArea == item || aArea->GetParent() == item )
703 return false;
704
705 SCOPED_LAYERSET scopedLayerSet( aArea );
706
707 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
708 {
709 // Silk clearance tests are run across layer pairs
710 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
711 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
712 {
713 scopedLayerSet.Add( aLayer );
714 }
715 }
716
717 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
718
719 if( !commonLayers.any() )
720 return false;
721
722 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
723 return false;
724
725 LSET testLayers;
726
727 if( aLayer != UNDEFINED_LAYER )
728 testLayers.set( aLayer );
729 else
730 testLayers = commonLayers;
731
732 bool isTransient = ( item->GetFlags() & ROUTER_TRANSIENT ) != 0;
733 std::vector<PCB_LAYER_ID> layersToCompute;
734
735 if( !isTransient )
736 {
737 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
738
739 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
740 {
741 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
742 auto i = board->m_IntersectsAreaCache.find( key );
743
744 if( i != board->m_IntersectsAreaCache.end() )
745 {
746 if( i->second )
747 return true;
748 }
749 else
750 {
751 layersToCompute.push_back( layer );
752 }
753 }
754 }
755 else
756 {
757 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
758 layersToCompute.push_back( layer );
759 }
760
761 std::vector<std::pair<PTR_PTR_LAYER_CACHE_KEY, bool>> results;
762 bool anyCollision = false;
763
764 for( PCB_LAYER_ID layer : layersToCompute )
765 {
766 bool collides = collidesWithArea( item, layer, context, aArea );
767
768 if( !isTransient )
769 results.push_back( { { aArea, item, layer }, collides } );
770
771 if( collides )
772 anyCollision = true;
773 }
774
775 if( !isTransient && !results.empty() )
776 {
777 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
778
779 for( const auto& [key, collides] : results )
780 board->m_IntersectsAreaCache[key] = collides;
781 }
782
783 return anyCollision;
784 } ) )
785 {
786 return 1.0;
787 }
788
789 return 0.0;
790 } );
791}
792
793
794static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
795{
796 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
797 LIBEVAL::VALUE* arg = aCtx->Pop();
799
800 result->Set( 0.0 );
801 aCtx->Push( result );
802
803 if( !arg || arg->AsString().IsEmpty() )
804 {
805 if( aCtx->HasErrorCallback() )
806 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
807
808 return;
809 }
810
811 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
812 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
813
814 if( !item )
815 return;
816
817 result->SetDeferredEval(
818 [item, arg, context]() -> double
819 {
820 BOARD* board = item->GetBoard();
821 int maxError = board->GetDesignSettings().m_MaxError;
822 PCB_LAYER_ID layer = context->GetLayer();
823 BOX2I itemBBox = item->GetBoundingBox();
824
825 if( searchAreas( board, arg->AsString(), context,
826 [&]( ZONE* aArea )
827 {
828 if( !aArea || aArea == item || aArea->GetParent() == item )
829 return false;
830
831 if( item->Type() != PCB_FOOTPRINT_T )
832 {
833 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
834 return false;
835 }
836
837 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
838 return false;
839
840 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
841
842 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
843 {
844 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
845
846 auto i = board->m_EnclosedByAreaCache.find( key );
847
848 if( i != board->m_EnclosedByAreaCache.end() )
849 return i->second;
850 }
851
852 SHAPE_POLY_SET itemShape;
853 bool enclosedByArea;
854
855 if( item->Type() == PCB_ZONE_T )
856 {
857 itemShape = *static_cast<ZONE*>( item )->Outline();
858 }
859 else if( item->Type() == PCB_FOOTPRINT_T )
860 {
861 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
862
863 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
864 {
865 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
866 maxError, ERROR_OUTSIDE );
867 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
868 maxError, ERROR_OUTSIDE );
869 }
870 }
871 else
872 {
873 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
875 }
876
877 if( itemShape.IsEmpty() )
878 {
879 // If it's already empty then our test will have no meaning.
880 enclosedByArea = false;
881 }
882 else
883 {
884 itemShape.BooleanSubtract( *aArea->Outline() );
885
886 enclosedByArea = itemShape.IsEmpty();
887 }
888
889 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
890 {
891 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
892 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
893 }
894
895 return enclosedByArea;
896 } ) )
897 {
898 return 1.0;
899 }
900
901 return 0.0;
902 } );
903}
904
905
906#define MISSING_GROUP_ARG( f ) \
907 wxString::Format( _( "Missing group name argument to %s." ), f )
908
909static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
910{
911 LIBEVAL::VALUE* arg = aCtx->Pop();
913
914 result->Set( 0.0 );
915 aCtx->Push( result );
916
917 if( !arg || arg->AsString().IsEmpty() )
918 {
919 if( aCtx->HasErrorCallback() )
920 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
921
922 return;
923 }
924
925 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
926 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
927
928 if( !item )
929 return;
930
931 result->SetDeferredEval(
932 [item, arg]() -> double
933 {
934 EDA_GROUP* group = item->GetParentGroup();
935
936 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
937 group = item->GetParent()->GetParentGroup();
938
939 while( group )
940 {
941 if( group->GetName().Matches( arg->AsString() ) )
942 return 1.0;
943
944 group = group->AsEdaItem()->GetParentGroup();
945 }
946
947 return 0.0;
948 } );
949}
950
951
952#define MISSING_SHEET_ARG( f ) \
953 wxString::Format( _( "Missing sheet name argument to %s." ), f )
954
955static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
956{
957 LIBEVAL::VALUE* arg = aCtx->Pop();
959
960 result->Set( 0.0 );
961 aCtx->Push( result );
962
963 if( !arg || arg->AsString().IsEmpty() )
964 {
965 if( aCtx->HasErrorCallback() )
966 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
967
968 return;
969 }
970
971 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
972 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
973
974 if( !item )
975 return;
976
977 result->SetDeferredEval(
978 [item, arg]() -> double
979 {
980 FOOTPRINT* fp = item->GetParentFootprint();
981
982 if( !fp && item->Type() == PCB_FOOTPRINT_T )
983 fp = static_cast<FOOTPRINT*>( item );
984
985 if( !fp )
986 return 0.0;
987
988 wxString sheetName = fp->GetSheetname();
989 wxString refName = arg->AsString();
990
991 if( sheetName.EndsWith( wxT( "/" ) ) )
992 sheetName.RemoveLast();
993 if( refName.EndsWith( wxT( "/" ) ) )
994 refName.RemoveLast();
995
996 if( sheetName.Matches( refName ) )
997 return 1.0;
998
999 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
1000 && sheetName.IsEmpty() )
1001 {
1002 return 1.0;
1003 }
1004
1005 return 0.0;
1006 } );
1007}
1008
1009
1010static void memberOfSheetOrChildrenFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1011{
1012 LIBEVAL::VALUE* arg = aCtx->Pop();
1013 LIBEVAL::VALUE* result = aCtx->AllocValue();
1014
1015 result->Set( 0.0 );
1016 aCtx->Push( result );
1017
1018 if( !arg || arg->AsString().IsEmpty() )
1019 {
1020 if( aCtx->HasErrorCallback() )
1021 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheetOrChildren()" ) ) );
1022
1023 return;
1024 }
1025
1026 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1027 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1028
1029 if( !item )
1030 return;
1031
1032 result->SetDeferredEval(
1033 [item, arg]() -> double
1034 {
1035 FOOTPRINT* fp = item->GetParentFootprint();
1036
1037 if( !fp && item->Type() == PCB_FOOTPRINT_T )
1038 fp = static_cast<FOOTPRINT*>( item );
1039
1040 if( !fp )
1041 return 0.0;
1042
1043 wxString sheetName = fp->GetSheetname();
1044 wxString refName = arg->AsString();
1045
1046 if( sheetName.EndsWith( wxT( "/" ) ) )
1047 sheetName.RemoveLast();
1048 if( refName.EndsWith( wxT( "/" ) ) )
1049 refName.RemoveLast();
1050
1051 wxArrayString sheetPath = wxSplit( sheetName, '/' );
1052 wxArrayString refPath = wxSplit( refName, '/' );
1053
1054 if( refPath.size() > sheetPath.size() )
1055 return 0.0;
1056
1057 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() ) && sheetName.IsEmpty() )
1058 {
1059 return 1.0;
1060 }
1061
1062 for( size_t i = 0; i < refPath.size(); i++ )
1063 {
1064 if( !sheetPath[i].Matches( refPath[i] ) )
1065 return 0.0;
1066 }
1067
1068 return 1.0;
1069 } );
1070}
1071
1072
1073#define MISSING_REF_ARG( f ) \
1074 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
1075
1076static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1077{
1078 LIBEVAL::VALUE* arg = aCtx->Pop();
1079 LIBEVAL::VALUE* result = aCtx->AllocValue();
1080
1081 result->Set( 0.0 );
1082 aCtx->Push( result );
1083
1084 if( !arg || arg->AsString().IsEmpty() )
1085 {
1086 if( aCtx->HasErrorCallback() )
1087 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1088
1089 return;
1090 }
1091
1092 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1093 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1094
1095 if( !item )
1096 return;
1097
1098 result->SetDeferredEval(
1099 [item, arg]() -> double
1100 {
1101 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1102 {
1103 if( testFootprintSelector( parentFP, arg->AsString() ) )
1104 return 1.0;
1105 }
1106
1107 return 0.0;
1108 } );
1109}
1110
1111
1112static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1113{
1114 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1115 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1116 LIBEVAL::VALUE* result = aCtx->AllocValue();
1117
1118 result->Set( 0.0 );
1119 aCtx->Push( result );
1120
1121 if( item && item->Type() == PCB_VIA_T && static_cast<PCB_VIA*>( item )->IsMicroVia() )
1122 result->Set( 1.0 );
1123}
1124
1125static void isBlindVia( LIBEVAL::CONTEXT* aCtx, void* self )
1126{
1127 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1128 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1129 LIBEVAL::VALUE* result = aCtx->AllocValue();
1130
1131 result->Set( 0.0 );
1132 aCtx->Push( result );
1133
1134 if( item && item->Type() == PCB_VIA_T && static_cast<PCB_VIA*>( item )->IsBlindVia() )
1135 result->Set( 1.0 );
1136}
1137
1138static void isBuriedVia( LIBEVAL::CONTEXT* aCtx, void* self )
1139{
1140 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1141 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1142 LIBEVAL::VALUE* result = aCtx->AllocValue();
1143
1144 result->Set( 0.0 );
1145 aCtx->Push( result );
1146
1147 if( item && item->Type() == PCB_VIA_T && static_cast<PCB_VIA*>( item )->IsBuriedVia() )
1148 result->Set( 1.0 );
1149}
1150
1151static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1152{
1153 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1154 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1155 LIBEVAL::VALUE* result = aCtx->AllocValue();
1156
1157 result->Set( 0.0 );
1158 aCtx->Push( result );
1159
1160 if( item && item->Type() == PCB_VIA_T )
1161 {
1162 PCB_VIA* via = static_cast<PCB_VIA*>( item );
1163
1164 if( via->IsBlindVia() || via->IsBuriedVia() )
1165 result->Set( 1.0 );
1166 }
1167}
1168
1169
1170static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1171{
1172 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1173 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1174 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1175 LIBEVAL::VALUE* result = aCtx->AllocValue();
1176
1177 result->Set( 0.0 );
1178 aCtx->Push( result );
1179
1180 result->SetDeferredEval(
1181 [a, b, context]() -> double
1182 {
1183 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1184
1185 if( !netinfo )
1186 return 0.0;
1187
1188 wxString coupledNet;
1189 wxString dummy;
1190
1191 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1192 return 0.0;
1193
1197 {
1198 // DRC engine evaluates these only in the context of a diffpair, but doesn't
1199 // always supply the second (B) item.
1200 if( BOARD* board = a->GetBoard() )
1201 {
1202 if( board->FindNet( coupledNet ) )
1203 return 1.0;
1204 }
1205 }
1206
1207 if( b && b->GetNetname() == coupledNet )
1208 return 1.0;
1209
1210 return 0.0;
1211 } );
1212}
1213
1214
1215#define MISSING_DP_ARG( f ) \
1216 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1217
1218static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1219{
1220 LIBEVAL::VALUE* argv = aCtx->Pop();
1221 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1222 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1223 LIBEVAL::VALUE* result = aCtx->AllocValue();
1224
1225 result->Set( 0.0 );
1226 aCtx->Push( result );
1227
1228 if( !argv || argv->AsString().IsEmpty() )
1229 {
1230 if( aCtx->HasErrorCallback() )
1231 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1232
1233 return;
1234 }
1235
1236 if( !item || !item->GetBoard() )
1237 return;
1238
1239 result->SetDeferredEval(
1240 [item, argv]() -> double
1241 {
1242 if( item && item->IsConnected() )
1243 {
1244 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1245
1246 if( !netinfo )
1247 return 0.0;
1248
1249 wxString refName = netinfo->GetNetname();
1250 wxString arg = argv->AsString();
1251 wxString baseName, coupledNet;
1252 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1253
1254 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1255 {
1256 if( baseName.Matches( arg ) )
1257 return 1.0;
1258
1259 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1260 return 1.0;
1261 }
1262 }
1263
1264 return 0.0;
1265 } );
1266}
1267
1268
1269static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1270{
1271 LIBEVAL::VALUE* arg = aCtx->Pop();
1272 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1273 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1274 LIBEVAL::VALUE* result = aCtx->AllocValue();
1275
1276 result->Set( "" );
1277 aCtx->Push( result );
1278
1279 if( !arg )
1280 {
1281 if( aCtx->HasErrorCallback() )
1282 {
1283 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1284 wxT( "getField()" ) ) );
1285 }
1286
1287 return;
1288 }
1289
1290 if( !item || !item->GetBoard() )
1291 return;
1292
1293 result->SetDeferredEval(
1294 [item, arg]() -> wxString
1295 {
1296 if( item && item->Type() == PCB_FOOTPRINT_T )
1297 {
1298 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1299
1300 PCB_FIELD* field = fp->GetField( arg->AsString() );
1301
1302 if( field )
1303 return field->GetText();
1304 }
1305
1306 return "";
1307 } );
1308}
1309
1310
1311static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1312{
1313 LIBEVAL::VALUE* arg = aCtx->Pop();
1314 LIBEVAL::VALUE* result = aCtx->AllocValue();
1315
1316 result->Set( 0.0 );
1317 aCtx->Push( result );
1318
1319 if( !arg || arg->AsString().IsEmpty() )
1320 {
1321 if( aCtx->HasErrorCallback() )
1322 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1323
1324 return;
1325 }
1326
1327 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1328 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1329
1330 if( !item )
1331 return;
1332
1333 result->SetDeferredEval(
1334 [item, arg]() -> double
1335 {
1336 if( !item->IsConnected() )
1337 return 0.0;
1338
1339 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1340 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1341
1342 if( netclass && netclass->ContainsNetclassWithName( arg->AsString() ) )
1343 return 1.0;
1344
1345 return 0.0;
1346 } );
1347}
1348
1349
1350static void hasExactNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1351{
1352 LIBEVAL::VALUE* arg = aCtx->Pop();
1353 LIBEVAL::VALUE* result = aCtx->AllocValue();
1354
1355 result->Set( 0.0 );
1356 aCtx->Push( result );
1357
1358 if( !arg || arg->AsString().IsEmpty() )
1359 {
1360 if( aCtx->HasErrorCallback() )
1361 aCtx->ReportError( _( "Missing netclass name argument to hasExactNetclass()" ) );
1362
1363 return;
1364 }
1365
1366 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1367 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1368
1369 if( !item )
1370 return;
1371
1372 result->SetDeferredEval(
1373 [item, arg]() -> double
1374 {
1375 if( !item->IsConnected() )
1376 return 0.0;
1377
1378 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1379 BOARD* board = bcItem->GetBoard();
1380 wxString netclassName;
1381
1382 if( board && ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
1383 {
1384 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
1385
1386 auto it = board->m_ItemNetclassCache.find( item );
1387
1388 if( it != board->m_ItemNetclassCache.end() )
1389 netclassName = it->second;
1390 }
1391
1392 if( netclassName.empty() )
1393 {
1394 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1395
1396 if( netclass )
1397 netclassName = netclass->GetName();
1398
1399 if( board && !netclassName.empty() && ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
1400 {
1401 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
1402 board->m_ItemNetclassCache[item] = netclassName;
1403 }
1404 }
1405
1406 return ( netclassName == arg->AsString() ) ? 1.0 : 0.0;
1407 } );
1408}
1409
1410
1411static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1412{
1413 LIBEVAL::VALUE* arg = aCtx->Pop();
1414 LIBEVAL::VALUE* result = aCtx->AllocValue();
1415
1416 result->Set( 0.0 );
1417 aCtx->Push( result );
1418
1419 if( !arg || arg->AsString().IsEmpty() )
1420 {
1421 if( aCtx->HasErrorCallback() )
1422 aCtx->ReportError( _( "Missing component class name argument to hasComponentClass()" ) );
1423
1424 return;
1425 }
1426
1427 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1428 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1429
1430 if( !item )
1431 return;
1432
1433 result->SetDeferredEval(
1434 [item, arg]() -> double
1435 {
1436 FOOTPRINT* footprint = nullptr;
1437
1438 if( item->Type() == PCB_FOOTPRINT_T )
1439 footprint = static_cast<FOOTPRINT*>( item );
1440 else
1441 footprint = item->GetParentFootprint();
1442
1443 if( !footprint )
1444 return 0.0;
1445
1446 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1447
1448 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1449 return 1.0;
1450
1451 return 0.0;
1452 } );
1453}
1454
1455
1460
1461
1463{
1464 m_funcs.clear();
1465
1466 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1467
1468 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1469
1470 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1471 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1472 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1473 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1474 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1475 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1476
1477 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1478 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1479 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1480
1481 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1482 RegisterFunc( wxT( "isBlindVia()" ), isBlindVia );
1483 RegisterFunc( wxT( "isBuriedVia()" ), isBuriedVia );
1484 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1485
1486 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1487 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1488 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1489 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1490 RegisterFunc( wxT( "memberOfSheetOrChildren('x')" ), memberOfSheetOrChildrenFunc );
1491
1492 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1493 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1494 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1495
1496 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1497
1498 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1499 RegisterFunc( wxT( "hasExactNetclass('x')" ), hasExactNetclassFunc );
1500 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1501}
const char * name
@ ERROR_OUTSIDE
constexpr int ARC_LOW_DEF
Definition base_units.h:128
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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:83
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:138
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.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:318
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.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:256
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:214
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
std::unordered_map< const BOARD_ITEM *, wxString > m_ItemNetclassCache
Definition board.h:1452
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2359
const ZONES & Zones() const
Definition board.h:367
const FOOTPRINTS & Footprints() const
Definition board.h:363
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition board.h:1446
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition board.h:1447
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1081
std::shared_mutex m_CachesMutex
Definition board.h:1440
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:563
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
A lightweight representation of a component class.
bool ContainsClassName(const wxString &className) const
Determines if this (effective) component class contains a specific constituent class.
std::shared_ptr< FROM_TO_CACHE > GetFromToCache()
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:50
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
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:46
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:110
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:151
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:721
wxString GetSheetname() const
Definition footprint.h:367
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
const COMPONENT_CLASS * GetComponentClass() const
Returns the component class for this footprint.
wxString GetFPIDAsString() const
Definition footprint.h:355
bool IsFlipped() const
Definition footprint.h:514
const wxString & GetReference() const
Definition footprint.h:741
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
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:179
void ReportError(const wxString &aErrorMsg)
void Push(VALUE *v)
virtual const wxString & AsString() const
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:705
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:712
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:284
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition netclass.cpp:328
Handle the data for a net.
Definition netinfo.h:54
const wxString & GetNetname() const
Definition netinfo.h:112
Definition pad.h:55
PAD_ATTRIB GetAttribute() const
Definition pad.h:563
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
bool IsBlindVia() const
bool IsBuriedVia() const
bool IsMicroVia() const
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:613
bool IsFilled() const
Definition zone.h:288
SHAPE_POLY_SET * Outline()
Definition zone.h:331
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:136
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
@ DIFF_PAIR_GAP_CONSTRAINT
Definition drc_rule.h:73
@ LENGTH_CONSTRAINT
Definition drc_rule.h:71
@ SKEW_CONSTRAINT
Definition drc_rule.h:72
#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:737
@ PTH
Plated through hole pad.
Definition padstack.h:98
Class to handle a set of BOARD_ITEMs.
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)
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 isBuriedVia(LIBEVAL::CONTEXT *aCtx, void *self)
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)
static void isBlindVia(LIBEVAL::CONTEXT *aCtx, void *self)
static void hasExactNetclassFunc(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 memberOfSheetOrChildrenFunc(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)
bool collidesWithArea(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, PCBEXPR_CONTEXT *aCtx, ZONE *aArea)
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
wxString result
Test unit parsing edge cases and error handling.
@ 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:108
@ 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