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 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
733 {
734 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
735
736 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
737 {
738 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
739
740 auto i = board->m_IntersectsAreaCache.find( key );
741
742 if( i != board->m_IntersectsAreaCache.end() && i->second )
743 return true;
744 }
745
746 bool collides = collidesWithArea( item, layer, context, aArea );
747
748 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
749 {
750 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
751 board->m_IntersectsAreaCache[ key ] = collides;
752 }
753
754 if( collides )
755 return true;
756 }
757
758 return false;
759 } ) )
760 {
761 return 1.0;
762 }
763
764 return 0.0;
765 } );
766}
767
768
769static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
770{
771 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
772 LIBEVAL::VALUE* arg = aCtx->Pop();
774
775 result->Set( 0.0 );
776 aCtx->Push( result );
777
778 if( !arg || arg->AsString().IsEmpty() )
779 {
780 if( aCtx->HasErrorCallback() )
781 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
782
783 return;
784 }
785
786 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
787 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
788
789 if( !item )
790 return;
791
792 result->SetDeferredEval(
793 [item, arg, context]() -> double
794 {
795 BOARD* board = item->GetBoard();
796 int maxError = board->GetDesignSettings().m_MaxError;
797 PCB_LAYER_ID layer = context->GetLayer();
798 BOX2I itemBBox = item->GetBoundingBox();
799
800 if( searchAreas( board, arg->AsString(), context,
801 [&]( ZONE* aArea )
802 {
803 if( !aArea || aArea == item || aArea->GetParent() == item )
804 return false;
805
806 if( item->Type() != PCB_FOOTPRINT_T )
807 {
808 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
809 return false;
810 }
811
812 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
813 return false;
814
815 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
816
817 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
818 {
819 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
820
821 auto i = board->m_EnclosedByAreaCache.find( key );
822
823 if( i != board->m_EnclosedByAreaCache.end() )
824 return i->second;
825 }
826
827 SHAPE_POLY_SET itemShape;
828 bool enclosedByArea;
829
830 if( item->Type() == PCB_ZONE_T )
831 {
832 itemShape = *static_cast<ZONE*>( item )->Outline();
833 }
834 else if( item->Type() == PCB_FOOTPRINT_T )
835 {
836 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
837
838 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
839 {
840 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
841 maxError, ERROR_OUTSIDE );
842 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
843 maxError, ERROR_OUTSIDE );
844 }
845 }
846 else
847 {
848 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
850 }
851
852 if( itemShape.IsEmpty() )
853 {
854 // If it's already empty then our test will have no meaning.
855 enclosedByArea = false;
856 }
857 else
858 {
859 itemShape.BooleanSubtract( *aArea->Outline() );
860
861 enclosedByArea = itemShape.IsEmpty();
862 }
863
864 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
865 {
866 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
867 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
868 }
869
870 return enclosedByArea;
871 } ) )
872 {
873 return 1.0;
874 }
875
876 return 0.0;
877 } );
878}
879
880
881#define MISSING_GROUP_ARG( f ) \
882 wxString::Format( _( "Missing group name argument to %s." ), f )
883
884static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
885{
886 LIBEVAL::VALUE* arg = aCtx->Pop();
888
889 result->Set( 0.0 );
890 aCtx->Push( result );
891
892 if( !arg || arg->AsString().IsEmpty() )
893 {
894 if( aCtx->HasErrorCallback() )
895 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
896
897 return;
898 }
899
900 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
901 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
902
903 if( !item )
904 return;
905
906 result->SetDeferredEval(
907 [item, arg]() -> double
908 {
909 EDA_GROUP* group = item->GetParentGroup();
910
911 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
912 group = item->GetParent()->GetParentGroup();
913
914 while( group )
915 {
916 if( group->GetName().Matches( arg->AsString() ) )
917 return 1.0;
918
919 group = group->AsEdaItem()->GetParentGroup();
920 }
921
922 return 0.0;
923 } );
924}
925
926
927#define MISSING_SHEET_ARG( f ) \
928 wxString::Format( _( "Missing sheet name argument to %s." ), f )
929
930static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
931{
932 LIBEVAL::VALUE* arg = aCtx->Pop();
934
935 result->Set( 0.0 );
936 aCtx->Push( result );
937
938 if( !arg || arg->AsString().IsEmpty() )
939 {
940 if( aCtx->HasErrorCallback() )
941 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
942
943 return;
944 }
945
946 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
947 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
948
949 if( !item )
950 return;
951
952 result->SetDeferredEval(
953 [item, arg]() -> double
954 {
955 FOOTPRINT* fp = item->GetParentFootprint();
956
957 if( !fp && item->Type() == PCB_FOOTPRINT_T )
958 fp = static_cast<FOOTPRINT*>( item );
959
960 if( !fp )
961 return 0.0;
962
963 wxString sheetName = fp->GetSheetname();
964 wxString refName = arg->AsString();
965
966 if( sheetName.EndsWith( wxT("/") ) )
967 sheetName.RemoveLast();
968 if( refName.EndsWith( wxT("/") ) )
969 refName.RemoveLast();
970
971 if( sheetName.Matches( refName ) )
972 return 1.0;
973
974 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
975 && sheetName.IsEmpty() )
976 {
977 return 1.0;
978 }
979
980 return 0.0;
981 } );
982}
983
984
985static void memberOfSheetOrChildrenFunc( LIBEVAL::CONTEXT* aCtx, void* self )
986{
987 LIBEVAL::VALUE* arg = aCtx->Pop();
989
990 result->Set( 0.0 );
991 aCtx->Push( result );
992
993 if( !arg || arg->AsString().IsEmpty() )
994 {
995 if( aCtx->HasErrorCallback() )
996 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheetOrChildren()" ) ) );
997
998 return;
999 }
1000
1001 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1002 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1003
1004 if( !item )
1005 return;
1006
1007 result->SetDeferredEval(
1008 [item, arg]() -> double
1009 {
1010 FOOTPRINT* fp = item->GetParentFootprint();
1011
1012 if( !fp && item->Type() == PCB_FOOTPRINT_T )
1013 fp = static_cast<FOOTPRINT*>( item );
1014
1015 if( !fp )
1016 return 0.0;
1017
1018 wxString sheetName = fp->GetSheetname();
1019 wxString refName = arg->AsString();
1020
1021 if( sheetName.EndsWith( wxT( "/" ) ) )
1022 sheetName.RemoveLast();
1023 if( refName.EndsWith( wxT( "/" ) ) )
1024 refName.RemoveLast();
1025
1026 wxArrayString sheetPath = wxSplit( sheetName, '/' );
1027 wxArrayString refPath = wxSplit( refName, '/' );
1028
1029 if( refPath.size() > sheetPath.size() )
1030 return 0.0;
1031
1032 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() ) && sheetName.IsEmpty() )
1033 {
1034 return 1.0;
1035 }
1036
1037 for( size_t i = 0; i < refPath.size(); i++ )
1038 {
1039 if( !sheetPath[i].Matches( refPath[i] ) )
1040 return 0.0;
1041 }
1042
1043 return 1.0;
1044 } );
1045}
1046
1047
1048#define MISSING_REF_ARG( f ) \
1049 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
1050
1051static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1052{
1053 LIBEVAL::VALUE* arg = aCtx->Pop();
1054 LIBEVAL::VALUE* result = aCtx->AllocValue();
1055
1056 result->Set( 0.0 );
1057 aCtx->Push( result );
1058
1059 if( !arg || arg->AsString().IsEmpty() )
1060 {
1061 if( aCtx->HasErrorCallback() )
1062 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1063
1064 return;
1065 }
1066
1067 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1068 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1069
1070 if( !item )
1071 return;
1072
1073 result->SetDeferredEval(
1074 [item, arg]() -> double
1075 {
1076 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1077 {
1078 if( testFootprintSelector( parentFP, arg->AsString() ) )
1079 return 1.0;
1080 }
1081
1082 return 0.0;
1083 } );
1084}
1085
1086
1087static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1088{
1089 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1090 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1091 LIBEVAL::VALUE* result = aCtx->AllocValue();
1092
1093 result->Set( 0.0 );
1094 aCtx->Push( result );
1095
1096 if( item && item->Type() == PCB_VIA_T
1097 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1098 {
1099 result->Set ( 1.0 );
1100 }
1101}
1102
1103
1104static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1105{
1106 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1107 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1108 LIBEVAL::VALUE* result = aCtx->AllocValue();
1109
1110 result->Set( 0.0 );
1111 aCtx->Push( result );
1112
1113 if( item && item->Type() == PCB_VIA_T
1114 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::BLIND_BURIED )
1115 {
1116 result->Set ( 1.0 );
1117 }
1118}
1119
1120
1121static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1122{
1123 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1124 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1125 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1126 LIBEVAL::VALUE* result = aCtx->AllocValue();
1127
1128 result->Set( 0.0 );
1129 aCtx->Push( result );
1130
1131 result->SetDeferredEval(
1132 [a, b, context]() -> double
1133 {
1134 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1135
1136 if( !netinfo )
1137 return 0.0;
1138
1139 wxString coupledNet;
1140 wxString dummy;
1141
1142 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1143 return 0.0;
1144
1148 {
1149 // DRC engine evaluates these only in the context of a diffpair, but doesn't
1150 // always supply the second (B) item.
1151 if( BOARD* board = a->GetBoard() )
1152 {
1153 if( board->FindNet( coupledNet ) )
1154 return 1.0;
1155 }
1156 }
1157
1158 if( b && b->GetNetname() == coupledNet )
1159 return 1.0;
1160
1161 return 0.0;
1162 } );
1163}
1164
1165
1166#define MISSING_DP_ARG( f ) \
1167 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1168
1169static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1170{
1171 LIBEVAL::VALUE* argv = aCtx->Pop();
1172 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1173 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1174 LIBEVAL::VALUE* result = aCtx->AllocValue();
1175
1176 result->Set( 0.0 );
1177 aCtx->Push( result );
1178
1179 if( !argv || argv->AsString().IsEmpty() )
1180 {
1181 if( aCtx->HasErrorCallback() )
1182 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1183
1184 return;
1185 }
1186
1187 if( !item || !item->GetBoard() )
1188 return;
1189
1190 result->SetDeferredEval(
1191 [item, argv]() -> double
1192 {
1193 if( item && item->IsConnected() )
1194 {
1195 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1196
1197 if( !netinfo )
1198 return 0.0;
1199
1200 wxString refName = netinfo->GetNetname();
1201 wxString arg = argv->AsString();
1202 wxString baseName, coupledNet;
1203 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1204
1205 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1206 {
1207 if( baseName.Matches( arg ) )
1208 return 1.0;
1209
1210 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1211 return 1.0;
1212 }
1213 }
1214
1215 return 0.0;
1216 } );
1217}
1218
1219
1220static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1221{
1222 LIBEVAL::VALUE* arg = aCtx->Pop();
1223 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1224 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1225 LIBEVAL::VALUE* result = aCtx->AllocValue();
1226
1227 result->Set( "" );
1228 aCtx->Push( result );
1229
1230 if( !arg )
1231 {
1232 if( aCtx->HasErrorCallback() )
1233 {
1234 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1235 wxT( "getField()" ) ) );
1236 }
1237
1238 return;
1239 }
1240
1241 if( !item || !item->GetBoard() )
1242 return;
1243
1244 result->SetDeferredEval(
1245 [item, arg]() -> wxString
1246 {
1247 if( item && item->Type() == PCB_FOOTPRINT_T )
1248 {
1249 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1250
1251 PCB_FIELD* field = fp->GetField( arg->AsString() );
1252
1253 if( field )
1254 return field->GetText();
1255 }
1256
1257 return "";
1258 } );
1259}
1260
1261
1262static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1263{
1264 LIBEVAL::VALUE* arg = aCtx->Pop();
1265 LIBEVAL::VALUE* result = aCtx->AllocValue();
1266
1267 result->Set( 0.0 );
1268 aCtx->Push( result );
1269
1270 if( !arg || arg->AsString().IsEmpty() )
1271 {
1272 if( aCtx->HasErrorCallback() )
1273 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1274
1275 return;
1276 }
1277
1278 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1279 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1280
1281 if( !item )
1282 return;
1283
1284 result->SetDeferredEval(
1285 [item, arg]() -> double
1286 {
1287 if( !item->IsConnected() )
1288 return 0.0;
1289
1290 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1291 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1292
1293 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1294 return 1.0;
1295
1296 return 0.0;
1297 } );
1298}
1299
1300
1301static void hasExactNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1302{
1303 LIBEVAL::VALUE* arg = aCtx->Pop();
1304 LIBEVAL::VALUE* result = aCtx->AllocValue();
1305
1306 result->Set( 0.0 );
1307 aCtx->Push( result );
1308
1309 if( !arg || arg->AsString().IsEmpty() )
1310 {
1311 if( aCtx->HasErrorCallback() )
1312 aCtx->ReportError( _( "Missing netclass name argument to hasExactNetclass()" ) );
1313
1314 return;
1315 }
1316
1317 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1318 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1319
1320 if( !item )
1321 return;
1322
1323 result->SetDeferredEval(
1324 [item, arg]() -> double
1325 {
1326 if( !item->IsConnected() )
1327 return 0.0;
1328
1329 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1330 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1331
1332 if( netclass->GetName() == arg->AsString() )
1333 return 1.0;
1334
1335 return 0.0;
1336 } );
1337}
1338
1339
1340static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1341{
1342 LIBEVAL::VALUE* arg = aCtx->Pop();
1343 LIBEVAL::VALUE* result = aCtx->AllocValue();
1344
1345 result->Set( 0.0 );
1346 aCtx->Push( result );
1347
1348 if( !arg || arg->AsString().IsEmpty() )
1349 {
1350 if( aCtx->HasErrorCallback() )
1351 aCtx->ReportError(
1352 _( "Missing component class name argument to hasComponentClass()" ) );
1353
1354 return;
1355 }
1356
1357 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1358 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1359
1360 if( !item )
1361 return;
1362
1363 result->SetDeferredEval(
1364 [item, arg]() -> double
1365 {
1366 FOOTPRINT* footprint = nullptr;
1367
1368 if( item->Type() == PCB_FOOTPRINT_T )
1369 footprint = static_cast<FOOTPRINT*>( item );
1370 else
1371 footprint = item->GetParentFootprint();
1372
1373 if( !footprint )
1374 return 0.0;
1375
1376 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1377
1378 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1379 return 1.0;
1380
1381 return 0.0;
1382 } );
1383}
1384
1385
1390
1391
1393{
1394 m_funcs.clear();
1395
1396 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1397
1398 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1399
1400 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1401 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1402 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1403 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1404 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1405 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1406
1407 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1408 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1409 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1410
1411 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1412 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1413
1414 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1415 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1416 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1417 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1418 RegisterFunc( wxT( "memberOfSheetOrChildren('x')" ), memberOfSheetOrChildrenFunc );
1419
1420 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1421 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1422 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1423
1424 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1425
1426 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1427 RegisterFunc( wxT( "hasExactNetclass('x')" ), hasExactNetclassFunc );
1428 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1429}
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:79
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:134
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:314
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:252
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:210
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2152
const ZONES & Zones() const
Definition board.h:362
const FOOTPRINTS & Footprints() const
Definition board.h:358
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition board.h:1373
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition board.h:1374
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1040
std::shared_mutex m_CachesMutex
Definition board.h:1367
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition board.h:521
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: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
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:145
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:97
static ENUM_MAP< T > & Instance()
Definition property.h:699
wxString GetSheetname() const
Definition footprint.h:287
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:275
bool IsFlipped() const
Definition footprint.h:434
const wxString & GetReference() const
Definition footprint.h:661
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:178
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:278
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:322
Handle the data for a net.
Definition netinfo.h:54
const wxString & GetNetname() const
Definition netinfo.h:112
Definition pad.h:54
PAD_ATTRIB GetAttribute() const
Definition pad.h:440
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
VIATYPE GetViaType() const
Definition pcb_track.h:451
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:621
bool IsFilled() const
Definition zone.h:292
SHAPE_POLY_SET * Outline()
Definition zone.h:335
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:82
Class to handle a set of BOARD_ITEMs.
@ BLIND_BURIED
Definition pcb_track.h:68
@ MICROVIA
Definition pcb_track.h:69
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 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 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: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