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