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 (C) 2019-2023 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 searchFootprints( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
213 const std::function<bool( FOOTPRINT* )>& aFunc )
214{
215 if( aArg == wxT( "A" ) )
216 {
217 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 0 ) );
218
219 if( fp && aFunc( fp ) )
220 return true;
221 }
222 else if( aArg == wxT( "B" ) )
223 {
224 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aCtx->GetItem( 1 ) );
225
226 if( fp && aFunc( fp ) )
227 return true;
228 }
229 else for( FOOTPRINT* fp : aBoard->Footprints() )
230 {
231 // NOTE: This code may want to be somewhat more generalized, but for now it's implemented
232 // here to support functions like insersectsCourtyard where we want multiple ways to search
233 // for the footprints in question.
234 // If support for text variable replacement is added, it should happen before any other
235 // logic here, so that people can use text variables to contain references or LIBIDs.
236 // (see: https://gitlab.com/kicad/code/kicad/-/issues/11231)
237
238 // First check if we have a known directive
239 if( aArg.Upper().StartsWith( wxT( "${CLASS:" ) ) && aArg.EndsWith( '}' ) )
240 {
241 wxString name = aArg.Mid( 8, aArg.Length() - 9 );
242
243 if( fp->GetComponentClass()->ContainsClassName( name ) && aFunc( fp ) )
244 return true;
245 }
246 else if( fp->GetReference().Matches( aArg ) )
247 {
248 if( aFunc( fp ) )
249 return true;
250 }
251 else if( aArg.Contains( ':' )
252 && fp->GetFPIDAsString().Matches( aArg ) )
253 {
254 if( aFunc( fp ) )
255 return true;
256 }
257 }
258
259 return false;
260}
261
262
263#define MISSING_FP_ARG( f ) \
264 wxString::Format( _( "Missing footprint argument (A, B, or reference designator) to %s." ), f )
265
266static void intersectsCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
267{
268 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
269 LIBEVAL::VALUE* arg = context->Pop();
270 LIBEVAL::VALUE* result = context->AllocValue();
271
272 result->Set( 0.0 );
273 context->Push( result );
274
275 if( !arg || arg->AsString().IsEmpty() )
276 {
277 if( context->HasErrorCallback() )
278 context->ReportError( MISSING_FP_ARG( wxT( "intersectsCourtyard()" ) ) );
279
280 return;
281 }
282
283 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
284 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
285
286 if( !item )
287 return;
288
289 result->SetDeferredEval(
290 [item, arg, context]() -> double
291 {
292 BOARD* board = item->GetBoard();
293 std::shared_ptr<SHAPE> itemShape;
294
295 if( searchFootprints( board, arg->AsString(), context,
296 [&]( FOOTPRINT* fp )
297 {
298 PTR_PTR_CACHE_KEY key = { fp, item };
299
300 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
301 {
302 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
303
304 auto i = board->m_IntersectsCourtyardCache.find( key );
305
306 if( i != board->m_IntersectsCourtyardCache.end() )
307 return i->second;
308 }
309
310 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu )
311 || collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
312
313 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
314 {
315 std::unique_lock<std::shared_mutex> cacheLock( board->m_CachesMutex );
316 board->m_IntersectsCourtyardCache[ key ] = res;
317 }
318
319 return res;
320 } ) )
321 {
322 return 1.0;
323 }
324
325 return 0.0;
326 } );
327}
328
329
330static void intersectsFrontCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
331{
332 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
333 LIBEVAL::VALUE* arg = context->Pop();
334 LIBEVAL::VALUE* result = context->AllocValue();
335
336 result->Set( 0.0 );
337 context->Push( result );
338
339 if( !arg || arg->AsString().IsEmpty() )
340 {
341 if( context->HasErrorCallback() )
342 context->ReportError( MISSING_FP_ARG( wxT( "intersectsFrontCourtyard()" ) ) );
343
344 return;
345 }
346
347 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
348 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
349
350 if( !item )
351 return;
352
353 result->SetDeferredEval(
354 [item, arg, context]() -> double
355 {
356 BOARD* board = item->GetBoard();
357 std::shared_ptr<SHAPE> itemShape;
358
359 if( searchFootprints( board, arg->AsString(), context,
360 [&]( FOOTPRINT* fp )
361 {
362 PTR_PTR_CACHE_KEY key = { fp, item };
363
364 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
365 {
366 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
367
368 auto i = board->m_IntersectsFCourtyardCache.find( key );
369
370 if( i != board->m_IntersectsFCourtyardCache.end() )
371 return i->second;
372 }
373
374 bool res = collidesWithCourtyard( item, itemShape, context, fp, F_Cu );
375
376 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
377 {
378 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
379 board->m_IntersectsFCourtyardCache[ key ] = res;
380 }
381
382 return res;
383 } ) )
384 {
385 return 1.0;
386 }
387
388 return 0.0;
389 } );
390}
391
392
393static void intersectsBackCourtyardFunc( LIBEVAL::CONTEXT* aCtx, void* self )
394{
395 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
396 LIBEVAL::VALUE* arg = context->Pop();
397 LIBEVAL::VALUE* result = context->AllocValue();
398
399 result->Set( 0.0 );
400 context->Push( result );
401
402 if( !arg || arg->AsString().IsEmpty() )
403 {
404 if( context->HasErrorCallback() )
405 context->ReportError( MISSING_FP_ARG( wxT( "intersectsBackCourtyard()" ) ) );
406
407 return;
408 }
409
410 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
411 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
412
413 if( !item )
414 return;
415
416 result->SetDeferredEval(
417 [item, arg, context]() -> double
418 {
419 BOARD* board = item->GetBoard();
420 std::shared_ptr<SHAPE> itemShape;
421
422 if( searchFootprints( board, arg->AsString(), context,
423 [&]( FOOTPRINT* fp )
424 {
425 PTR_PTR_CACHE_KEY key = { fp, item };
426
427 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
428 {
429 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
430
431 auto i = board->m_IntersectsBCourtyardCache.find( key );
432
433 if( i != board->m_IntersectsBCourtyardCache.end() )
434 return i->second;
435 }
436
437 bool res = collidesWithCourtyard( item, itemShape, context, fp, B_Cu );
438
439 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
440 {
441 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
442 board->m_IntersectsBCourtyardCache[ key ] = res;
443 }
444
445 return res;
446 } ) )
447 {
448 return 1.0;
449 }
450
451 return 0.0;
452 } );
453}
454
455
456bool collidesWithArea( BOARD_ITEM* aItem, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
457{
458 BOARD* board = aArea->GetBoard();
459 BOX2I areaBBox = aArea->GetBoundingBox();
460 std::shared_ptr<SHAPE> shape;
461
462 // Collisions include touching, so we need to deflate outline by enough to exclude it.
463 // This is particularly important for detecting copper fills as they will be exactly
464 // touching along the entire exclusion border.
465 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
466 areaOutline.ClearArcs();
467 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
469
470 if( aItem->GetFlags() & HOLE_PROXY )
471 {
472 if( aItem->Type() == PCB_PAD_T )
473 {
474 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
475 }
476 else if( aItem->Type() == PCB_VIA_T )
477 {
478 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
479
481 if( overlap.any() )
482 {
483 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
484 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
485 }
486 }
487
488 return false;
489 }
490
491 if( aItem->Type() == PCB_FOOTPRINT_T )
492 {
493 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
494
495 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
496 {
497 if( aCtx->HasErrorCallback() )
498 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
499
500 return false;
501 }
502
503 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
504 {
505 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
506
507 if( courtyard.OutlineCount() == 0 )
508 {
509 if( aCtx->HasErrorCallback() )
510 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
511 }
512 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
513 {
514 return true;
515 }
516 }
517
518 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
519 {
520 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
521
522 if( courtyard.OutlineCount() == 0 )
523 {
524 if( aCtx->HasErrorCallback() )
525 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
526 }
527 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
528 {
529 return true;
530 }
531 }
532
533 return false;
534 }
535
536 if( aItem->Type() == PCB_ZONE_T )
537 {
538 ZONE* zone = static_cast<ZONE*>( aItem );
539
540 if( !zone->IsFilled() )
541 return false;
542
543 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
544
545 if( zoneRTree )
546 {
547 for( size_t ii = 0; ii < aArea->GetLayerSet().size(); ++ii )
548 {
549 if( aArea->GetLayerSet().test( ii ) )
550 {
551 PCB_LAYER_ID layer = PCB_LAYER_ID( ii );
552
553 if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
554 {
555 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, layer ) )
556 return true;
557 }
558 }
559 }
560 }
561
562 return false;
563 }
564 else
565 {
566 PCB_LAYER_ID layer = aCtx->GetLayer();
567
568 if( layer != UNDEFINED_LAYER && !( aArea->GetLayerSet().Contains( layer ) ) )
569 return false;
570
571 if( !shape )
572 shape = aItem->GetEffectiveShape( layer );
573
574 return areaOutline.Collide( shape.get() );
575 }
576}
577
578
579bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
580 const std::function<bool( ZONE* )>& aFunc )
581{
582 if( aArg == wxT( "A" ) )
583 {
584 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
585 }
586 else if( aArg == wxT( "B" ) )
587 {
588 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
589 }
590 else if( KIID::SniffTest( aArg ) )
591 {
592 KIID target( aArg );
593
594 for( ZONE* area : aBoard->Zones() )
595 {
596 // Only a single zone can match the UUID; exit once we find a match whether
597 // "inside" or not
598 if( area->m_Uuid == target )
599 return aFunc( area );
600 }
601
602 for( FOOTPRINT* footprint : aBoard->Footprints() )
603 {
604 for( ZONE* area : footprint->Zones() )
605 {
606 // Only a single zone can match the UUID; exit once we find a match
607 // whether "inside" or not
608 if( area->m_Uuid == target )
609 return aFunc( area );
610 }
611 }
612
613 return false;
614 }
615 else // Match on zone name
616 {
617 for( ZONE* area : aBoard->Zones() )
618 {
619 if( area->GetZoneName().Matches( aArg ) )
620 {
621 // Many zones can match the name; exit only when we find an "inside"
622 if( aFunc( area ) )
623 return true;
624 }
625 }
626
627 for( FOOTPRINT* footprint : aBoard->Footprints() )
628 {
629 for( ZONE* area : footprint->Zones() )
630 {
631 // Many zones can match the name; exit only when we find an "inside"
632 if( area->GetZoneName().Matches( aArg ) )
633 {
634 if( aFunc( area ) )
635 return true;
636 }
637 }
638 }
639
640 return false;
641 }
642}
643
644
646{
647public:
649 {
650 m_item = aItem;
651 m_layers = aItem->GetLayerSet();
652 }
653
655 {
657 }
658
659 void Add( PCB_LAYER_ID aLayer )
660 {
661 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
662 }
663
664private:
667};
668
669
670#define MISSING_AREA_ARG( f ) \
671 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
672
673static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
674{
675 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
676 LIBEVAL::VALUE* arg = aCtx->Pop();
677 LIBEVAL::VALUE* result = aCtx->AllocValue();
678
679 result->Set( 0.0 );
680 aCtx->Push( result );
681
682 if( !arg || arg->AsString().IsEmpty() )
683 {
684 if( aCtx->HasErrorCallback() )
685 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
686
687 return;
688 }
689
690 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
691 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
692
693 if( !item )
694 return;
695
696 result->SetDeferredEval(
697 [item, arg, context]() -> double
698 {
699 BOARD* board = item->GetBoard();
700 PCB_LAYER_ID aLayer = context->GetLayer();
701 BOX2I itemBBox = item->GetBoundingBox();
702
703 if( searchAreas( board, arg->AsString(), context,
704 [&]( ZONE* aArea )
705 {
706 if( !aArea || aArea == item || aArea->GetParent() == item )
707 return false;
708
709 SCOPED_LAYERSET scopedLayerSet( aArea );
710
711 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
712 {
713 // Silk clearance tests are run across layer pairs
714 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
715 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
716 {
717 scopedLayerSet.Add( aLayer );
718 }
719 }
720
721 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
722
723 if( !commonLayers.any() )
724 return false;
725
726 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
727 return false;
728
729 LSET testLayers;
730
731 if( aLayer != UNDEFINED_LAYER )
732 testLayers.set( aLayer );
733 else
734 testLayers = commonLayers;
735
736 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
737 {
738 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
739
740 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
741 {
742 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
743
744 auto i = board->m_IntersectsAreaCache.find( key );
745
746 if( i != board->m_IntersectsAreaCache.end() && i->second )
747 return true;
748 }
749
750 bool collides = collidesWithArea( item, context, aArea );
751
752 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
753 {
754 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
755 board->m_IntersectsAreaCache[ key ] = collides;
756 }
757
758 if( collides )
759 return true;
760 }
761
762 return false;
763 } ) )
764 {
765 return 1.0;
766 }
767
768 return 0.0;
769 } );
770}
771
772
773static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
774{
775 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
776 LIBEVAL::VALUE* arg = aCtx->Pop();
777 LIBEVAL::VALUE* result = aCtx->AllocValue();
778
779 result->Set( 0.0 );
780 aCtx->Push( result );
781
782 if( !arg || arg->AsString().IsEmpty() )
783 {
784 if( aCtx->HasErrorCallback() )
785 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
786
787 return;
788 }
789
790 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
791 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
792
793 if( !item )
794 return;
795
796 result->SetDeferredEval(
797 [item, arg, context]() -> double
798 {
799 BOARD* board = item->GetBoard();
800 int maxError = board->GetDesignSettings().m_MaxError;
801 PCB_LAYER_ID layer = context->GetLayer();
802 BOX2I itemBBox = item->GetBoundingBox();
803
804 if( searchAreas( board, arg->AsString(), context,
805 [&]( ZONE* aArea )
806 {
807 if( !aArea || aArea == item || aArea->GetParent() == item )
808 return false;
809
810 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
811 return false;
812
813 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
814 return false;
815
816 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
817
818 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
819 {
820 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
821
822 auto i = board->m_EnclosedByAreaCache.find( key );
823
824 if( i != board->m_EnclosedByAreaCache.end() )
825 return i->second;
826 }
827
828 SHAPE_POLY_SET itemShape;
829 bool enclosedByArea;
830
831 if( item->Type() == PCB_ZONE_T )
832 {
833 itemShape = *static_cast<ZONE*>( item )->Outline();
834 }
835 else
836 {
837 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
838 ERROR_OUTSIDE );
839 }
840
841 if( itemShape.IsEmpty() )
842 {
843 // If it's already empty then our test will have no meaning.
844 enclosedByArea = false;
845 }
846 else
847 {
848 itemShape.BooleanSubtract( *aArea->Outline(),
849 SHAPE_POLY_SET::PM_FAST );
850
851 enclosedByArea = itemShape.IsEmpty();
852 }
853
854 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
855 {
856 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
857 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
858 }
859
860 return enclosedByArea;
861 } ) )
862 {
863 return 1.0;
864 }
865
866 return 0.0;
867 } );
868}
869
870
871#define MISSING_GROUP_ARG( f ) \
872 wxString::Format( _( "Missing group name argument to %s." ), f )
873
874static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
875{
876 LIBEVAL::VALUE* arg = aCtx->Pop();
877 LIBEVAL::VALUE* result = aCtx->AllocValue();
878
879 result->Set( 0.0 );
880 aCtx->Push( result );
881
882 if( !arg || arg->AsString().IsEmpty() )
883 {
884 if( aCtx->HasErrorCallback() )
885 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
886
887 return;
888 }
889
890 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
891 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
892
893 if( !item )
894 return;
895
896 result->SetDeferredEval(
897 [item, arg]() -> double
898 {
899 PCB_GROUP* group = item->GetParentGroup();
900
901 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
902 group = item->GetParent()->GetParentGroup();
903
904 while( group )
905 {
906 if( group->GetName().Matches( arg->AsString() ) )
907 return 1.0;
908
909 group = group->GetParentGroup();
910 }
911
912 return 0.0;
913 } );
914}
915
916
917#define MISSING_SHEET_ARG( f ) \
918 wxString::Format( _( "Missing sheet name argument to %s." ), f )
919
920static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
921{
922 LIBEVAL::VALUE* arg = aCtx->Pop();
923 LIBEVAL::VALUE* result = aCtx->AllocValue();
924
925 result->Set( 0.0 );
926 aCtx->Push( result );
927
928 if( !arg || arg->AsString().IsEmpty() )
929 {
930 if( aCtx->HasErrorCallback() )
931 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
932
933 return;
934 }
935
936 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
937 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
938
939 if( !item )
940 return;
941
942 result->SetDeferredEval(
943 [item, arg]() -> double
944 {
945 FOOTPRINT* fp = item->GetParentFootprint();
946
947 if( !fp && item->Type() == PCB_FOOTPRINT_T )
948 fp = static_cast<FOOTPRINT*>( item );
949
950 if( !fp )
951 return 0.0;
952
953 wxString sheetName = fp->GetSheetname();
954 wxString refName = arg->AsString();
955
956 if( sheetName.EndsWith( wxT("/") ) )
957 sheetName.RemoveLast();
958 if( refName.EndsWith( wxT("/") ) )
959 refName.RemoveLast();
960
961 if( sheetName.Matches( refName ) )
962 return 1.0;
963
964 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
965 && sheetName.IsEmpty() )
966 {
967 return 1.0;
968 }
969
970 return 0.0;
971 } );
972}
973
974
975#define MISSING_REF_ARG( f ) \
976 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
977
978static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
979{
980 LIBEVAL::VALUE* arg = aCtx->Pop();
981 LIBEVAL::VALUE* result = aCtx->AllocValue();
982
983 result->Set( 0.0 );
984 aCtx->Push( result );
985
986 if( !arg || arg->AsString().IsEmpty() )
987 {
988 if( aCtx->HasErrorCallback() )
989 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
990
991 return;
992 }
993
994 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
995 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
996
997 if( !item )
998 return;
999
1000 result->SetDeferredEval(
1001 [item, arg]() -> double
1002 {
1003 ;
1004
1005 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1006 {
1007 if( parentFP->GetReference().Matches( arg->AsString() ) )
1008 return 1.0;
1009
1010 if( arg->AsString().Contains( ':' )
1011 && parentFP->GetFPIDAsString().Matches( arg->AsString() ) )
1012 {
1013 return 1.0;
1014 }
1015 }
1016
1017 return 0.0;
1018 } );
1019}
1020
1021
1022static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1023{
1024 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1025 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1026 LIBEVAL::VALUE* result = aCtx->AllocValue();
1027
1028 result->Set( 0.0 );
1029 aCtx->Push( result );
1030
1031 if( item && item->Type() == PCB_VIA_T
1032 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1033 {
1034 result->Set ( 1.0 );
1035 }
1036}
1037
1038
1039static void isBlindBuriedViaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1040{
1041 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1042 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1043 LIBEVAL::VALUE* result = aCtx->AllocValue();
1044
1045 result->Set( 0.0 );
1046 aCtx->Push( result );
1047
1048 if( item && item->Type() == PCB_VIA_T
1049 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::BLIND_BURIED )
1050 {
1051 result->Set ( 1.0 );
1052 }
1053}
1054
1055
1056static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1057{
1058 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1059 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1060 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1061 LIBEVAL::VALUE* result = aCtx->AllocValue();
1062
1063 result->Set( 0.0 );
1064 aCtx->Push( result );
1065
1066 result->SetDeferredEval(
1067 [a, b, context]() -> double
1068 {
1069 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1070
1071 if( !netinfo )
1072 return 0.0;
1073
1074 wxString coupledNet;
1075 wxString dummy;
1076
1077 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1078 return 0.0;
1079
1082 {
1083 // DRC engine evaluates these singly, so we won't have a B item
1084 return 1.0;
1085 }
1086
1087 return b && b->GetNetname() == coupledNet;
1088 } );
1089}
1090
1091
1092#define MISSING_DP_ARG( f ) \
1093 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1094
1095static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1096{
1097 LIBEVAL::VALUE* argv = aCtx->Pop();
1098 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1099 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1100 LIBEVAL::VALUE* result = aCtx->AllocValue();
1101
1102 result->Set( 0.0 );
1103 aCtx->Push( result );
1104
1105 if( !argv || argv->AsString().IsEmpty() )
1106 {
1107 if( aCtx->HasErrorCallback() )
1108 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1109
1110 return;
1111 }
1112
1113 if( !item || !item->GetBoard() )
1114 return;
1115
1116 result->SetDeferredEval(
1117 [item, argv]() -> double
1118 {
1119 if( item && item->IsConnected() )
1120 {
1121 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1122
1123 if( !netinfo )
1124 return 0.0;
1125
1126 wxString refName = netinfo->GetNetname();
1127 wxString arg = argv->AsString();
1128 wxString baseName, coupledNet;
1129 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1130
1131 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1132 {
1133 if( baseName.Matches( arg ) )
1134 return 1.0;
1135
1136 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1137 return 1.0;
1138 }
1139 }
1140
1141 return 0.0;
1142 } );
1143}
1144
1145
1146static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1147{
1148 LIBEVAL::VALUE* arg = aCtx->Pop();
1149 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1150 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1151 LIBEVAL::VALUE* result = aCtx->AllocValue();
1152
1153 result->Set( "" );
1154 aCtx->Push( result );
1155
1156 if( !arg )
1157 {
1158 if( aCtx->HasErrorCallback() )
1159 {
1160 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1161 wxT( "getField()" ) ) );
1162 }
1163
1164 return;
1165 }
1166
1167 if( !item || !item->GetBoard() )
1168 return;
1169
1170 result->SetDeferredEval(
1171 [item, arg]() -> wxString
1172 {
1173 if( item && item->Type() == PCB_FOOTPRINT_T )
1174 {
1175 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1176
1177 PCB_FIELD* field = fp->GetFieldByName( arg->AsString() );
1178
1179 if( field )
1180 return field->GetText();
1181 }
1182
1183 return "";
1184 } );
1185}
1186
1187
1188static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1189{
1190 LIBEVAL::VALUE* arg = aCtx->Pop();
1191 LIBEVAL::VALUE* result = aCtx->AllocValue();
1192
1193 result->Set( 0.0 );
1194 aCtx->Push( result );
1195
1196 if( !arg || arg->AsString().IsEmpty() )
1197 {
1198 if( aCtx->HasErrorCallback() )
1199 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1200
1201 return;
1202 }
1203
1204 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1205 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1206
1207 if( !item )
1208 return;
1209
1210 result->SetDeferredEval(
1211 [item, arg]() -> double
1212 {
1213 if( !item->IsConnected() )
1214 return 0.0;
1215
1216 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1217 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1218
1219 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1220 return 1.0;
1221
1222 return 0.0;
1223 } );
1224}
1225
1226static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1227{
1228 LIBEVAL::VALUE* arg = aCtx->Pop();
1229 LIBEVAL::VALUE* result = aCtx->AllocValue();
1230
1231 result->Set( 0.0 );
1232 aCtx->Push( result );
1233
1234 if( !arg || arg->AsString().IsEmpty() )
1235 {
1236 if( aCtx->HasErrorCallback() )
1237 aCtx->ReportError(
1238 _( "Missing component class name argument to hasComponentClass()" ) );
1239
1240 return;
1241 }
1242
1243 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1244 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1245
1246 if( !item )
1247 return;
1248
1249 result->SetDeferredEval(
1250 [item, arg]() -> double
1251 {
1252 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
1253
1254 if( !footprint )
1255 return 0.0;
1256
1257 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1258
1259 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1260 return 1.0;
1261
1262 return 0.0;
1263 } );
1264}
1265
1266
1268{
1270}
1271
1272
1274{
1275 m_funcs.clear();
1276
1277 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1278
1279 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1280
1281 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1282 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1283 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1284 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1285 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1286 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1287
1288 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1289 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1290 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1291
1292 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1293 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1294
1295 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1296 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1297 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1298 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1299
1300 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1301 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1302 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1303
1304 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1305
1306 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1307 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1308}
const char * name
Definition: DXF_plotter.cpp:57
constexpr int ARC_LOW_DEF
Definition: base_units.h:119
BASE_SET & set(size_t pos)
Definition: base_set.h:115
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.
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:265
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:319
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:47
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:257
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:215
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:289
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1918
const ZONES & Zones() const
Definition: board.h:335
const FOOTPRINTS & Footprints() const
Definition: board.h:331
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1297
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1298
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:892
std::shared_mutex m_CachesMutex
Definition: board.h:1291
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:475
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:215
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:94
static ENUM_MAP< T > & Instance()
Definition: property.h:663
PCB_FIELD * GetFieldByName(const wxString &aFieldName)
Return a field in this symbol.
Definition: footprint.cpp:552
wxString GetSheetname() const
Definition: footprint.h:266
const COMPONENT_CLASS * GetComponentClass() const
Definition: footprint.h:999
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:2847
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:170
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:36
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:772
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:779
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:60
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition: netclass.cpp:141
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:381
bool IsFilled() const
Definition: zone.h:261
SHAPE_POLY_SET * Outline()
Definition: zone.h:337
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:130
@ 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:810
@ 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 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