KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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;
48 LIBEVAL::VALUE* result = aCtx->AllocValue();
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();
83 LIBEVAL::VALUE* result = aCtx->AllocValue();
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{
174 LIBEVAL::VALUE* result = aCtx->AllocValue();
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 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu );
384
385 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
386 {
387 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
388 board->m_IntersectsFCourtyardCache[ key ] = res;
389 }
390
391 return res;
392 } ) )
393 {
394 return 1.0;
395 }
396
397 return 0.0;
398 } );
399}
400
401
402static void intersectsBackCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
403{
404 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
405 LIBEVAL::VALUE* arg = context->Pop();
406 LIBEVAL::VALUE* result = context->AllocValue();
407
408 result->Set( 0.0 );
409 context->Push( result );
410
411 if( !arg || arg->AsString().IsEmpty() )
412 {
413 if( context->HasErrorCallback() )
414 context->ReportError( MISSING_FP_ARG( wxT( "intersectsBackCourtyard()" ) ) );
415
416 return;
417 }
418
419 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
420 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
421
422 if( !item )
423 return;
424
425 result->SetDeferredEval(
426 [item, arg, context]() -> double
427 {
428 BOARD* board = item->GetBoard();
429 std::shared_ptr<SHAPE> itemShape;
430
431 if( searchFootprints( board, arg->AsString(), context,
432 [&]( FOOTPRINT* fp )
433 {
434 PTR_PTR_CACHE_KEY key = { fp, item };
435
436 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
437 {
438 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
439
440 auto i = board->m_IntersectsBCourtyardCache.find( key );
441
442 if( i != board->m_IntersectsBCourtyardCache.end() )
443 return i->second;
444 }
445
446 bool res = collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
447
448 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
449 {
450 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
451 board->m_IntersectsBCourtyardCache[ key ] = res;
452 }
453
454 return res;
455 } ) )
456 {
457 return 1.0;
458 }
459
460 return 0.0;
461 } );
462}
463
464
465bool collidesWithArea( BOARD_ITEM* aItem, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
466{
467 BOARD* board = aArea->GetBoard();
468 BOX2I areaBBox = aArea->GetBoundingBox();
469 std::shared_ptr<SHAPE> shape;
470
471 // Collisions include touching, so we need to deflate outline by enough to exclude it.
472 // This is particularly important for detecting copper fills as they will be exactly
473 // touching along the entire exclusion border.
474 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
475 areaOutline.ClearArcs();
476 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
478
479 if( aItem->GetFlags() & HOLE_PROXY )
480 {
481 if( aItem->Type() == PCB_PAD_T )
482 {
483 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
484 }
485 else if( aItem->Type() == PCB_VIA_T )
486 {
487 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
488
490 if( overlap.any() )
491 {
492 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
493 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
494 }
495 }
496
497 return false;
498 }
499
500 if( aItem->Type() == PCB_FOOTPRINT_T )
501 {
502 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
503
504 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
505 {
506 if( aCtx->HasErrorCallback() )
507 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
508
509 return false;
510 }
511
512 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
513 {
514 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
515
516 if( courtyard.OutlineCount() == 0 )
517 {
518 if( aCtx->HasErrorCallback() )
519 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
520 }
521 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
522 {
523 return true;
524 }
525 }
526
527 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
528 {
529 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
530
531 if( courtyard.OutlineCount() == 0 )
532 {
533 if( aCtx->HasErrorCallback() )
534 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
535 }
536 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
537 {
538 return true;
539 }
540 }
541
542 return false;
543 }
544
545 if( aItem->Type() == PCB_ZONE_T )
546 {
547 ZONE* zone = static_cast<ZONE*>( aItem );
548
549 if( !zone->IsFilled() )
550 return false;
551
552 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
553
554 if( zoneRTree )
555 {
556 for( size_t ii = 0; ii < aArea->GetLayerSet().size(); ++ii )
557 {
558 if( aArea->GetLayerSet().test( ii ) )
559 {
560 PCB_LAYER_ID layer = PCB_LAYER_ID( ii );
561
562 if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
563 {
564 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, layer ) )
565 return true;
566 }
567 }
568 }
569 }
570
571 return false;
572 }
573 else
574 {
575 PCB_LAYER_ID layer = aCtx->GetLayer();
576
577 if( layer != UNDEFINED_LAYER && !( aArea->GetLayerSet().Contains( layer ) ) )
578 return false;
579
580 if( !shape )
581 shape = aItem->GetEffectiveShape( layer );
582
583 return areaOutline.Collide( shape.get() );
584 }
585}
586
587
588bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
589 const std::function<bool( ZONE* )>& aFunc )
590{
591 if( aArg == wxT( "A" ) )
592 {
593 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
594 }
595 else if( aArg == wxT( "B" ) )
596 {
597 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
598 }
599 else if( KIID::SniffTest( aArg ) )
600 {
601 KIID target( aArg );
602
603 for( ZONE* area : aBoard->Zones() )
604 {
605 // Only a single zone can match the UUID; exit once we find a match whether
606 // "inside" or not
607 if( area->m_Uuid == target )
608 return aFunc( area );
609 }
610
611 for( FOOTPRINT* footprint : aBoard->Footprints() )
612 {
613 for( ZONE* area : footprint->Zones() )
614 {
615 // Only a single zone can match the UUID; exit once we find a match
616 // whether "inside" or not
617 if( area->m_Uuid == target )
618 return aFunc( area );
619 }
620 }
621
622 return false;
623 }
624 else // Match on zone name
625 {
626 for( ZONE* area : aBoard->Zones() )
627 {
628 if( area->GetZoneName().Matches( aArg ) )
629 {
630 // Many zones can match the name; exit only when we find an "inside"
631 if( aFunc( area ) )
632 return true;
633 }
634 }
635
636 for( FOOTPRINT* footprint : aBoard->Footprints() )
637 {
638 for( ZONE* area : footprint->Zones() )
639 {
640 // Many zones can match the name; exit only when we find an "inside"
641 if( area->GetZoneName().Matches( aArg ) )
642 {
643 if( aFunc( area ) )
644 return true;
645 }
646 }
647 }
648
649 return false;
650 }
651}
652
653
655{
656public:
658 {
659 m_item = aItem;
660 m_layers = aItem->GetLayerSet();
661 }
662
664 {
666 }
667
668 void Add( PCB_LAYER_ID aLayer )
669 {
670 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
671 }
672
673private:
676};
677
678
679#define MISSING_AREA_ARG( f ) \
680 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
681
682static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
683{
684 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
685 LIBEVAL::VALUE* arg = aCtx->Pop();
686 LIBEVAL::VALUE* result = aCtx->AllocValue();
687
688 result->Set( 0.0 );
689 aCtx->Push( result );
690
691 if( !arg || arg->AsString().IsEmpty() )
692 {
693 if( aCtx->HasErrorCallback() )
694 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
695
696 return;
697 }
698
699 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
700 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
701
702 if( !item )
703 return;
704
705 result->SetDeferredEval(
706 [item, arg, context]() -> double
707 {
708 BOARD* board = item->GetBoard();
709 PCB_LAYER_ID aLayer = context->GetLayer();
710 BOX2I itemBBox = item->GetBoundingBox();
711
712 if( searchAreas( board, arg->AsString(), context,
713 [&]( ZONE* aArea )
714 {
715 if( !aArea || aArea == item || aArea->GetParent() == item )
716 return false;
717
718 SCOPED_LAYERSET scopedLayerSet( aArea );
719
720 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
721 {
722 // Silk clearance tests are run across layer pairs
723 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
724 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
725 {
726 scopedLayerSet.Add( aLayer );
727 }
728 }
729
730 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
731
732 if( !commonLayers.any() )
733 return false;
734
735 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
736 return false;
737
738 LSET testLayers;
739
740 if( aLayer != UNDEFINED_LAYER )
741 testLayers.set( aLayer );
742 else
743 testLayers = commonLayers;
744
745 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
746 {
747 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
748
749 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
750 {
751 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
752
753 auto i = board->m_IntersectsAreaCache.find( key );
754
755 if( i != board->m_IntersectsAreaCache.end() && i->second )
756 return true;
757 }
758
759 bool collides = collidesWithArea( item, context, aArea );
760
761 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
762 {
763 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
764 board->m_IntersectsAreaCache[ key ] = collides;
765 }
766
767 if( collides )
768 return true;
769 }
770
771 return false;
772 } ) )
773 {
774 return 1.0;
775 }
776
777 return 0.0;
778 } );
779}
780
781
782static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
783{
784 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
785 LIBEVAL::VALUE* arg = aCtx->Pop();
786 LIBEVAL::VALUE* result = aCtx->AllocValue();
787
788 result->Set( 0.0 );
789 aCtx->Push( result );
790
791 if( !arg || arg->AsString().IsEmpty() )
792 {
793 if( aCtx->HasErrorCallback() )
794 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
795
796 return;
797 }
798
799 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
800 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
801
802 if( !item )
803 return;
804
805 result->SetDeferredEval(
806 [item, arg, context]() -> double
807 {
808 BOARD* board = item->GetBoard();
809 int maxError = board->GetDesignSettings().m_MaxError;
810 PCB_LAYER_ID layer = context->GetLayer();
811 BOX2I itemBBox = item->GetBoundingBox();
812
813 if( searchAreas( board, arg->AsString(), context,
814 [&]( ZONE* aArea )
815 {
816 if( !aArea || aArea == item || aArea->GetParent() == item )
817 return false;
818
819 if( item->Type() != PCB_FOOTPRINT_T )
820 {
821 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
822 return false;
823 }
824
825 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
826 return false;
827
828 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
829
830 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
831 {
832 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
833
834 auto i = board->m_EnclosedByAreaCache.find( key );
835
836 if( i != board->m_EnclosedByAreaCache.end() )
837 return i->second;
838 }
839
840 SHAPE_POLY_SET itemShape;
841 bool enclosedByArea;
842
843 if( item->Type() == PCB_ZONE_T )
844 {
845 itemShape = *static_cast<ZONE*>( item )->Outline();
846 }
847 else if( item->Type() == PCB_FOOTPRINT_T )
848 {
849 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
850
851 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
852 {
853 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
854 maxError, ERROR_OUTSIDE );
855 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
856 maxError, ERROR_OUTSIDE );
857 }
858 }
859 else
860 {
861 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
863 }
864
865 if( itemShape.IsEmpty() )
866 {
867 // If it's already empty then our test will have no meaning.
868 enclosedByArea = false;
869 }
870 else
871 {
872 itemShape.BooleanSubtract( *aArea->Outline() );
873
874 enclosedByArea = itemShape.IsEmpty();
875 }
876
877 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
878 {
879 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
880 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
881 }
882
883 return enclosedByArea;
884 } ) )
885 {
886 return 1.0;
887 }
888
889 return 0.0;
890 } );
891}
892
893
894#define MISSING_GROUP_ARG( f ) \
895 wxString::Format( _( "Missing group name argument to %s." ), f )
896
897static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
898{
899 LIBEVAL::VALUE* arg = aCtx->Pop();
900 LIBEVAL::VALUE* result = aCtx->AllocValue();
901
902 result->Set( 0.0 );
903 aCtx->Push( result );
904
905 if( !arg || arg->AsString().IsEmpty() )
906 {
907 if( aCtx->HasErrorCallback() )
908 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
909
910 return;
911 }
912
913 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
914 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
915
916 if( !item )
917 return;
918
919 result->SetDeferredEval(
920 [item, arg]() -> double
921 {
922 EDA_GROUP* group = item->GetParentGroup();
923
924 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
925 group = item->GetParent()->GetParentGroup();
926
927 while( group )
928 {
929 if( group->GetName().Matches( arg->AsString() ) )
930 return 1.0;
931
932 group = group->AsEdaItem()->GetParentGroup();
933 }
934
935 return 0.0;
936 } );
937}
938
939
940#define MISSING_SHEET_ARG( f ) \
941 wxString::Format( _( "Missing sheet name argument to %s." ), f )
942
943static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
944{
945 LIBEVAL::VALUE* arg = aCtx->Pop();
946 LIBEVAL::VALUE* result = aCtx->AllocValue();
947
948 result->Set( 0.0 );
949 aCtx->Push( result );
950
951 if( !arg || arg->AsString().IsEmpty() )
952 {
953 if( aCtx->HasErrorCallback() )
954 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
955
956 return;
957 }
958
959 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
960 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
961
962 if( !item )
963 return;
964
965 result->SetDeferredEval(
966 [item, arg]() -> double
967 {
968 FOOTPRINT* fp = item->GetParentFootprint();
969
970 if( !fp && item->Type() == PCB_FOOTPRINT_T )
971 fp = static_cast<FOOTPRINT*>( item );
972
973 if( !fp )
974 return 0.0;
975
976 wxString sheetName = fp->GetSheetname();
977 wxString refName = arg->AsString();
978
979 if( sheetName.EndsWith( wxT("/") ) )
980 sheetName.RemoveLast();
981 if( refName.EndsWith( wxT("/") ) )
982 refName.RemoveLast();
983
984 if( sheetName.Matches( refName ) )
985 return 1.0;
986
987 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
988 && sheetName.IsEmpty() )
989 {
990 return 1.0;
991 }
992
993 return 0.0;
994 } );
995}
996
997
998static void memberOfSheetOrChildrenFunc( 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_SHEET_ARG( wxT( "memberOfSheetOrChildren()" ) ) );
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 FOOTPRINT* fp = item->GetParentFootprint();
1024
1025 if( !fp && item->Type() == PCB_FOOTPRINT_T )
1026 fp = static_cast<FOOTPRINT*>( item );
1027
1028 if( !fp )
1029 return 0.0;
1030
1031 wxString sheetName = fp->GetSheetname();
1032 wxString refName = arg->AsString();
1033
1034 if( sheetName.EndsWith( wxT( "/" ) ) )
1035 sheetName.RemoveLast();
1036 if( refName.EndsWith( wxT( "/" ) ) )
1037 refName.RemoveLast();
1038
1039 wxArrayString sheetPath = wxSplit( sheetName, '/' );
1040 wxArrayString refPath = wxSplit( refName, '/' );
1041
1042 if( refPath.size() > sheetPath.size() )
1043 return 0.0;
1044
1045 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() ) && sheetName.IsEmpty() )
1046 {
1047 return 1.0;
1048 }
1049
1050 for( size_t i = 0; i < refPath.size(); i++ )
1051 {
1052 if( !sheetPath[i].Matches( refPath[i] ) )
1053 return 0.0;
1054 }
1055
1056 return 1.0;
1057 } );
1058}
1059
1060
1061#define MISSING_REF_ARG( f ) \
1062 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
1063
1064static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1065{
1066 LIBEVAL::VALUE* arg = aCtx->Pop();
1067 LIBEVAL::VALUE* result = aCtx->AllocValue();
1068
1069 result->Set( 0.0 );
1070 aCtx->Push( result );
1071
1072 if( !arg || arg->AsString().IsEmpty() )
1073 {
1074 if( aCtx->HasErrorCallback() )
1075 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1076
1077 return;
1078 }
1079
1080 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1081 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1082
1083 if( !item )
1084 return;
1085
1086 result->SetDeferredEval(
1087 [item, arg]() -> double
1088 {
1089 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1090 {
1091 if( testFootprintSelector( parentFP, arg->AsString() ) )
1092 return 1.0;
1093 }
1094
1095 return 0.0;
1096 } );
1097}
1098
1099
1100static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1101{
1102 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1103 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1104 LIBEVAL::VALUE* result = aCtx->AllocValue();
1105
1106 result->Set( 0.0 );
1107 aCtx->Push( result );
1108
1109 if( item && item->Type() == PCB_VIA_T
1110 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1111 {
1112 result->Set ( 1.0 );
1113 }
1114}
1115
1116
1117static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1118{
1119 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1120 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1121 LIBEVAL::VALUE* result = aCtx->AllocValue();
1122
1123 result->Set( 0.0 );
1124 aCtx->Push( result );
1125
1126 if( item && item->Type() == PCB_VIA_T
1127 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::BLIND_BURIED )
1128 {
1129 result->Set ( 1.0 );
1130 }
1131}
1132
1133
1134static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1135{
1136 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1137 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1138 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1139 LIBEVAL::VALUE* result = aCtx->AllocValue();
1140
1141 result->Set( 0.0 );
1142 aCtx->Push( result );
1143
1144 result->SetDeferredEval(
1145 [a, b, context]() -> double
1146 {
1147 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1148
1149 if( !netinfo )
1150 return 0.0;
1151
1152 wxString coupledNet;
1153 wxString dummy;
1154
1155 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1156 return 0.0;
1157
1160 {
1161 // DRC engine evaluates these singly, so we won't have a B item
1162 return 1.0;
1163 }
1164
1165 return b && b->GetNetname() == coupledNet;
1166 } );
1167}
1168
1169
1170#define MISSING_DP_ARG( f ) \
1171 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1172
1173static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1174{
1175 LIBEVAL::VALUE* argv = aCtx->Pop();
1176 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1177 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1178 LIBEVAL::VALUE* result = aCtx->AllocValue();
1179
1180 result->Set( 0.0 );
1181 aCtx->Push( result );
1182
1183 if( !argv || argv->AsString().IsEmpty() )
1184 {
1185 if( aCtx->HasErrorCallback() )
1186 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1187
1188 return;
1189 }
1190
1191 if( !item || !item->GetBoard() )
1192 return;
1193
1194 result->SetDeferredEval(
1195 [item, argv]() -> double
1196 {
1197 if( item && item->IsConnected() )
1198 {
1199 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1200
1201 if( !netinfo )
1202 return 0.0;
1203
1204 wxString refName = netinfo->GetNetname();
1205 wxString arg = argv->AsString();
1206 wxString baseName, coupledNet;
1207 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1208
1209 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1210 {
1211 if( baseName.Matches( arg ) )
1212 return 1.0;
1213
1214 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1215 return 1.0;
1216 }
1217 }
1218
1219 return 0.0;
1220 } );
1221}
1222
1223
1224static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1225{
1226 LIBEVAL::VALUE* arg = aCtx->Pop();
1227 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1228 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1229 LIBEVAL::VALUE* result = aCtx->AllocValue();
1230
1231 result->Set( "" );
1232 aCtx->Push( result );
1233
1234 if( !arg )
1235 {
1236 if( aCtx->HasErrorCallback() )
1237 {
1238 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1239 wxT( "getField()" ) ) );
1240 }
1241
1242 return;
1243 }
1244
1245 if( !item || !item->GetBoard() )
1246 return;
1247
1248 result->SetDeferredEval(
1249 [item, arg]() -> wxString
1250 {
1251 if( item && item->Type() == PCB_FOOTPRINT_T )
1252 {
1253 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1254
1255 PCB_FIELD* field = fp->GetField( arg->AsString() );
1256
1257 if( field )
1258 return field->GetText();
1259 }
1260
1261 return "";
1262 } );
1263}
1264
1265
1266static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1267{
1268 LIBEVAL::VALUE* arg = aCtx->Pop();
1269 LIBEVAL::VALUE* result = aCtx->AllocValue();
1270
1271 result->Set( 0.0 );
1272 aCtx->Push( result );
1273
1274 if( !arg || arg->AsString().IsEmpty() )
1275 {
1276 if( aCtx->HasErrorCallback() )
1277 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1278
1279 return;
1280 }
1281
1282 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1283 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1284
1285 if( !item )
1286 return;
1287
1288 result->SetDeferredEval(
1289 [item, arg]() -> double
1290 {
1291 if( !item->IsConnected() )
1292 return 0.0;
1293
1294 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1295 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1296
1297 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1298 return 1.0;
1299
1300 return 0.0;
1301 } );
1302}
1303
1304static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1305{
1306 LIBEVAL::VALUE* arg = aCtx->Pop();
1307 LIBEVAL::VALUE* result = aCtx->AllocValue();
1308
1309 result->Set( 0.0 );
1310 aCtx->Push( result );
1311
1312 if( !arg || arg->AsString().IsEmpty() )
1313 {
1314 if( aCtx->HasErrorCallback() )
1315 aCtx->ReportError(
1316 _( "Missing component class name argument to hasComponentClass()" ) );
1317
1318 return;
1319 }
1320
1321 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1322 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1323
1324 if( !item )
1325 return;
1326
1327 result->SetDeferredEval(
1328 [item, arg]() -> double
1329 {
1330 FOOTPRINT* footprint = nullptr;
1331
1332 if( item->Type() == PCB_FOOTPRINT_T )
1333 footprint = static_cast<FOOTPRINT*>( item );
1334 else
1335 footprint = item->GetParentFootprint();
1336
1337 if( !footprint )
1338 return 0.0;
1339
1340 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1341
1342 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1343 return 1.0;
1344
1345 return 0.0;
1346 } );
1347}
1348
1349
1351{
1353}
1354
1355
1357{
1358 m_funcs.clear();
1359
1360 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1361
1362 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1363
1364 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1365 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1366 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1367 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1368 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1369 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1370
1371 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1372 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1373 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1374
1375 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1376 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1377
1378 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1379 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1380 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1381 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1382 RegisterFunc( wxT( "memberOfSheetOrChildren('x')" ), memberOfSheetOrChildrenFunc );
1383
1384 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1385 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1386 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1387
1388 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1389
1390 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1391 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1392}
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:78
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:131
virtual void SetLayerSet(const LSET &aLayers)
Definition: board_item.h:257
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:256
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:311
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:279
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:48
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:299
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:249
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:207
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:289
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2011
const ZONES & Zones() const
Definition: board.h:342
const FOOTPRINTS & Footprints() const
Definition: board.h:338
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1329
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1330
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:946
std::shared_mutex m_CachesMutex
Definition: board.h:1323
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:495
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:311
A lightweight representation of a component class.
bool ContainsClassName(const wxString &className) const
Determines if this (effective) component class contains a specific constituent class.
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Check if the given net is a diff pair, returning its polarity and complement if so.
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:48
int QueryColliding(BOARD_ITEM *aRefItem, PCB_LAYER_ID aRefLayer, PCB_LAYER_ID aTargetLayer, std::function< bool(BOARD_ITEM *)> aFilter=nullptr, std::function< bool(BOARD_ITEM *)> aVisitor=nullptr, int aClearance=0) const
This is a fast test which essentially does bounding-box overlap given a worst-case clearance.
Definition: drc_rtree.h:214
A set of EDA_ITEMs (i.e., without duplicates).
Definition: eda_group.h:45
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:84
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:108
EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:114
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:138
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
static ENUM_MAP< T > & Instance()
Definition: property.h:680
wxString GetSheetname() const
Definition: footprint.h:271
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
Definition: footprint.cpp:582
const COMPONENT_CLASS * GetComponentClass() const
Returns the component class for this footprint.
Definition: footprint.cpp:4059
wxString GetFPIDAsString() const
Definition: footprint.h:259
const wxString & GetReference() const
Definition: footprint.h:621
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2990
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 const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:708
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:715
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
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:648
bool IsFilled() const
Definition: zone.h:292
SHAPE_POLY_SET * Outline()
Definition: zone.h:368
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
@ 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:747
@ 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 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)
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