KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcbexpr_functions.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <algorithm>
25#include <cstdio>
26#include <memory>
27#include <mutex>
28#include <wx/log.h>
29#include <board.h>
32#include <drc/drc_rtree.h>
33#include <drc/drc_engine.h>
34#include <lset.h>
35#include <pcb_track.h>
36#include <pcb_group.h>
38#include <pcbexpr_evaluator.h>
42
43
44bool fromToFunc( LIBEVAL::CONTEXT* aCtx, void* self )
45{
46 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
47 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
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, PCB_LAYER_ID aLayer, PCBEXPR_CONTEXT* aCtx, ZONE* aArea )
466{
467 BOARD* board = aArea->GetBoard();
468 BOX2I areaBBox = aArea->GetBoundingBox();
469
470 // Collisions include touching, so we need to deflate outline by enough to exclude it.
471 // This is particularly important for detecting copper fills as they will be exactly
472 // touching along the entire exclusion border.
473 SHAPE_POLY_SET areaOutline = aArea->Outline()->CloneDropTriangulation();
474 areaOutline.ClearArcs();
475 areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(),
477
478 if( aItem->GetFlags() & HOLE_PROXY )
479 {
480 if( aItem->Type() == PCB_PAD_T )
481 {
482 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
483 }
484 else if( aItem->Type() == PCB_VIA_T )
485 {
486 LSET overlap = aItem->GetLayerSet() & aArea->GetLayerSet();
487
489 if( overlap.any() )
490 {
491 if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
492 return areaOutline.Collide( aItem->GetEffectiveHoleShape().get() );
493 }
494 }
495
496 return false;
497 }
498
499 if( aItem->Type() == PCB_FOOTPRINT_T )
500 {
501 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
502
503 if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
504 {
505 if( aCtx->HasErrorCallback() )
506 aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
507
508 return false;
509 }
510
511 if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
512 {
513 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( F_CrtYd );
514
515 if( courtyard.OutlineCount() == 0 )
516 {
517 if( aCtx->HasErrorCallback() )
518 aCtx->ReportError( _( "Footprint has no front courtyard." ) );
519 }
520 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
521 {
522 return true;
523 }
524 }
525
526 if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
527 {
528 const SHAPE_POLY_SET& courtyard = footprint->GetCourtyard( B_CrtYd );
529
530 if( courtyard.OutlineCount() == 0 )
531 {
532 if( aCtx->HasErrorCallback() )
533 aCtx->ReportError( _( "Footprint has no back courtyard." ) );
534 }
535 else if( areaOutline.Collide( &courtyard.Outline( 0 ) ) )
536 {
537 return true;
538 }
539 }
540
541 return false;
542 }
543
544 if( aItem->Type() == PCB_ZONE_T )
545 {
546 ZONE* zone = static_cast<ZONE*>( aItem );
547
548 if( !zone->IsFilled() )
549 return false;
550
551 DRC_RTREE* zoneRTree = board->m_CopperZoneRTreeCache[ zone ].get();
552
553 if( zoneRTree )
554 {
555 if( zoneRTree->QueryColliding( areaBBox, &areaOutline, aLayer ) )
556 return true;
557 }
558
559 return false;
560 }
561 else
562 {
563 if( !aArea->GetLayerSet().Contains( aLayer ) )
564 return false;
565
566 return areaOutline.Collide( aItem->GetEffectiveShape( aLayer ).get() );
567 }
568}
569
570
571bool searchAreas( BOARD* aBoard, const wxString& aArg, PCBEXPR_CONTEXT* aCtx,
572 const std::function<bool( ZONE* )>& aFunc )
573{
574 if( aArg == wxT( "A" ) )
575 {
576 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 0 ) ) );
577 }
578 else if( aArg == wxT( "B" ) )
579 {
580 return aFunc( dynamic_cast<ZONE*>( aCtx->GetItem( 1 ) ) );
581 }
582 else if( KIID::SniffTest( aArg ) )
583 {
584 KIID target( aArg );
585
586 for( ZONE* area : aBoard->Zones() )
587 {
588 // Only a single zone can match the UUID; exit once we find a match whether
589 // "inside" or not
590 if( area->m_Uuid == target )
591 return aFunc( area );
592 }
593
594 for( FOOTPRINT* footprint : aBoard->Footprints() )
595 {
596 for( ZONE* area : footprint->Zones() )
597 {
598 // Only a single zone can match the UUID; exit once we find a match
599 // whether "inside" or not
600 if( area->m_Uuid == target )
601 return aFunc( area );
602 }
603 }
604
605 return false;
606 }
607 else // Match on zone name
608 {
609 for( ZONE* area : aBoard->Zones() )
610 {
611 if( area->GetZoneName().Matches( aArg ) )
612 {
613 // Many zones can match the name; exit only when we find an "inside"
614 if( aFunc( area ) )
615 return true;
616 }
617 }
618
619 for( FOOTPRINT* footprint : aBoard->Footprints() )
620 {
621 for( ZONE* area : footprint->Zones() )
622 {
623 // Many zones can match the name; exit only when we find an "inside"
624 if( area->GetZoneName().Matches( aArg ) )
625 {
626 if( aFunc( area ) )
627 return true;
628 }
629 }
630 }
631
632 return false;
633 }
634}
635
636
638{
639public:
641 {
642 m_item = aItem;
643 m_layers = aItem->GetLayerSet();
644 }
645
647 {
649 }
650
651 void Add( PCB_LAYER_ID aLayer )
652 {
653 m_item->SetLayerSet( m_item->GetLayerSet().set( aLayer ) );
654 }
655
656private:
659};
660
661
662#define MISSING_AREA_ARG( f ) \
663 wxString::Format( _( "Missing rule-area argument (A, B, or rule-area name) to %s." ), f )
664
665static void intersectsAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
666{
667 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
668 LIBEVAL::VALUE* arg = aCtx->Pop();
669 LIBEVAL::VALUE* result = aCtx->AllocValue();
670
671 result->Set( 0.0 );
672 aCtx->Push( result );
673
674 if( !arg || arg->AsString().IsEmpty() )
675 {
676 if( aCtx->HasErrorCallback() )
677 aCtx->ReportError( MISSING_AREA_ARG( wxT( "intersectsArea()" ) ) );
678
679 return;
680 }
681
682 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
683 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
684
685 if( !item )
686 return;
687
688 result->SetDeferredEval(
689 [item, arg, context]() -> double
690 {
691 BOARD* board = item->GetBoard();
692 PCB_LAYER_ID aLayer = context->GetLayer();
693 BOX2I itemBBox = item->GetBoundingBox();
694
695 if( searchAreas( board, arg->AsString(), context,
696 [&]( ZONE* aArea )
697 {
698 if( !aArea || aArea == item || aArea->GetParent() == item )
699 return false;
700
701 SCOPED_LAYERSET scopedLayerSet( aArea );
702
703 if( context->GetConstraint() == SILK_CLEARANCE_CONSTRAINT )
704 {
705 // Silk clearance tests are run across layer pairs
706 if( ( aArea->IsOnLayer( F_SilkS ) && IsFrontLayer( aLayer ) )
707 || ( aArea->IsOnLayer( B_SilkS ) && IsBackLayer( aLayer ) ) )
708 {
709 scopedLayerSet.Add( aLayer );
710 }
711 }
712
713 LSET commonLayers = aArea->GetLayerSet() & item->GetLayerSet();
714
715 if( !commonLayers.any() )
716 return false;
717
718 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
719 return false;
720
721 LSET testLayers;
722
723 if( aLayer != UNDEFINED_LAYER )
724 testLayers.set( aLayer );
725 else
726 testLayers = commonLayers;
727
728 for( PCB_LAYER_ID layer : testLayers.UIOrder() )
729 {
730 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
731
732 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
733 {
734 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
735
736 auto i = board->m_IntersectsAreaCache.find( key );
737
738 if( i != board->m_IntersectsAreaCache.end() && i->second )
739 return true;
740 }
741
742 bool collides = collidesWithArea( item, layer, context, aArea );
743
744 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
745 {
746 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
747 board->m_IntersectsAreaCache[ key ] = collides;
748 }
749
750 if( collides )
751 return true;
752 }
753
754 return false;
755 } ) )
756 {
757 return 1.0;
758 }
759
760 return 0.0;
761 } );
762}
763
764
765static void enclosedByAreaFunc( LIBEVAL::CONTEXT* aCtx, void* self )
766{
767 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
768 LIBEVAL::VALUE* arg = aCtx->Pop();
769 LIBEVAL::VALUE* result = aCtx->AllocValue();
770
771 result->Set( 0.0 );
772 aCtx->Push( result );
773
774 if( !arg || arg->AsString().IsEmpty() )
775 {
776 if( aCtx->HasErrorCallback() )
777 aCtx->ReportError( MISSING_AREA_ARG( wxT( "enclosedByArea()" ) ) );
778
779 return;
780 }
781
782 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
783 BOARD_ITEM* item = vref ? vref->GetObject( context ) : nullptr;
784
785 if( !item )
786 return;
787
788 result->SetDeferredEval(
789 [item, arg, context]() -> double
790 {
791 BOARD* board = item->GetBoard();
792 int maxError = board->GetDesignSettings().m_MaxError;
793 PCB_LAYER_ID layer = context->GetLayer();
794 BOX2I itemBBox = item->GetBoundingBox();
795
796 if( searchAreas( board, arg->AsString(), context,
797 [&]( ZONE* aArea )
798 {
799 if( !aArea || aArea == item || aArea->GetParent() == item )
800 return false;
801
802 if( item->Type() != PCB_FOOTPRINT_T )
803 {
804 if( !( aArea->GetLayerSet() & item->GetLayerSet() ).any() )
805 return false;
806 }
807
808 if( !aArea->GetBoundingBox().Intersects( itemBBox ) )
809 return false;
810
811 PTR_PTR_LAYER_CACHE_KEY key = { aArea, item, layer };
812
813 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
814 {
815 std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
816
817 auto i = board->m_EnclosedByAreaCache.find( key );
818
819 if( i != board->m_EnclosedByAreaCache.end() )
820 return i->second;
821 }
822
823 SHAPE_POLY_SET itemShape;
824 bool enclosedByArea;
825
826 if( item->Type() == PCB_ZONE_T )
827 {
828 itemShape = *static_cast<ZONE*>( item )->Outline();
829 }
830 else if( item->Type() == PCB_FOOTPRINT_T )
831 {
832 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
833
834 for( PCB_LAYER_ID testLayer : aArea->GetLayerSet() )
835 {
836 fp->TransformPadsToPolySet( itemShape, testLayer, 0,
837 maxError, ERROR_OUTSIDE );
838 fp->TransformFPShapesToPolySet( itemShape, testLayer, 0,
839 maxError, ERROR_OUTSIDE );
840 }
841 }
842 else
843 {
844 item->TransformShapeToPolygon( itemShape, layer, 0, maxError,
846 }
847
848 if( itemShape.IsEmpty() )
849 {
850 // If it's already empty then our test will have no meaning.
851 enclosedByArea = false;
852 }
853 else
854 {
855 itemShape.BooleanSubtract( *aArea->Outline() );
856
857 enclosedByArea = itemShape.IsEmpty();
858 }
859
860 if( ( item->GetFlags() & ROUTER_TRANSIENT ) == 0 )
861 {
862 std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
863 board->m_EnclosedByAreaCache[ key ] = enclosedByArea;
864 }
865
866 return enclosedByArea;
867 } ) )
868 {
869 return 1.0;
870 }
871
872 return 0.0;
873 } );
874}
875
876
877#define MISSING_GROUP_ARG( f ) \
878 wxString::Format( _( "Missing group name argument to %s." ), f )
879
880static void memberOfGroupFunc( LIBEVAL::CONTEXT* aCtx, void* self )
881{
882 LIBEVAL::VALUE* arg = aCtx->Pop();
883 LIBEVAL::VALUE* result = aCtx->AllocValue();
884
885 result->Set( 0.0 );
886 aCtx->Push( result );
887
888 if( !arg || arg->AsString().IsEmpty() )
889 {
890 if( aCtx->HasErrorCallback() )
891 aCtx->ReportError( MISSING_GROUP_ARG( wxT( "memberOfGroup()" ) ) );
892
893 return;
894 }
895
896 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
897 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
898
899 if( !item )
900 return;
901
902 result->SetDeferredEval(
903 [item, arg]() -> double
904 {
905 EDA_GROUP* group = item->GetParentGroup();
906
907 if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
908 group = item->GetParent()->GetParentGroup();
909
910 while( group )
911 {
912 if( group->GetName().Matches( arg->AsString() ) )
913 return 1.0;
914
915 group = group->AsEdaItem()->GetParentGroup();
916 }
917
918 return 0.0;
919 } );
920}
921
922
923#define MISSING_SHEET_ARG( f ) \
924 wxString::Format( _( "Missing sheet name argument to %s." ), f )
925
926static void memberOfSheetFunc( LIBEVAL::CONTEXT* aCtx, void* self )
927{
928 LIBEVAL::VALUE* arg = aCtx->Pop();
929 LIBEVAL::VALUE* result = aCtx->AllocValue();
930
931 result->Set( 0.0 );
932 aCtx->Push( result );
933
934 if( !arg || arg->AsString().IsEmpty() )
935 {
936 if( aCtx->HasErrorCallback() )
937 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheet()" ) ) );
938
939 return;
940 }
941
942 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
943 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
944
945 if( !item )
946 return;
947
948 result->SetDeferredEval(
949 [item, arg]() -> double
950 {
951 FOOTPRINT* fp = item->GetParentFootprint();
952
953 if( !fp && item->Type() == PCB_FOOTPRINT_T )
954 fp = static_cast<FOOTPRINT*>( item );
955
956 if( !fp )
957 return 0.0;
958
959 wxString sheetName = fp->GetSheetname();
960 wxString refName = arg->AsString();
961
962 if( sheetName.EndsWith( wxT("/") ) )
963 sheetName.RemoveLast();
964 if( refName.EndsWith( wxT("/") ) )
965 refName.RemoveLast();
966
967 if( sheetName.Matches( refName ) )
968 return 1.0;
969
970 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() )
971 && sheetName.IsEmpty() )
972 {
973 return 1.0;
974 }
975
976 return 0.0;
977 } );
978}
979
980
981static void memberOfSheetOrChildrenFunc( LIBEVAL::CONTEXT* aCtx, void* self )
982{
983 LIBEVAL::VALUE* arg = aCtx->Pop();
984 LIBEVAL::VALUE* result = aCtx->AllocValue();
985
986 result->Set( 0.0 );
987 aCtx->Push( result );
988
989 if( !arg || arg->AsString().IsEmpty() )
990 {
991 if( aCtx->HasErrorCallback() )
992 aCtx->ReportError( MISSING_SHEET_ARG( wxT( "memberOfSheetOrChildren()" ) ) );
993
994 return;
995 }
996
997 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
998 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
999
1000 if( !item )
1001 return;
1002
1003 result->SetDeferredEval(
1004 [item, arg]() -> double
1005 {
1006 FOOTPRINT* fp = item->GetParentFootprint();
1007
1008 if( !fp && item->Type() == PCB_FOOTPRINT_T )
1009 fp = static_cast<FOOTPRINT*>( item );
1010
1011 if( !fp )
1012 return 0.0;
1013
1014 wxString sheetName = fp->GetSheetname();
1015 wxString refName = arg->AsString();
1016
1017 if( sheetName.EndsWith( wxT( "/" ) ) )
1018 sheetName.RemoveLast();
1019 if( refName.EndsWith( wxT( "/" ) ) )
1020 refName.RemoveLast();
1021
1022 wxArrayString sheetPath = wxSplit( sheetName, '/' );
1023 wxArrayString refPath = wxSplit( refName, '/' );
1024
1025 if( refPath.size() > sheetPath.size() )
1026 return 0.0;
1027
1028 if( ( refName.Matches( wxT( "/" ) ) || refName.IsEmpty() ) && sheetName.IsEmpty() )
1029 {
1030 return 1.0;
1031 }
1032
1033 for( size_t i = 0; i < refPath.size(); i++ )
1034 {
1035 if( !sheetPath[i].Matches( refPath[i] ) )
1036 return 0.0;
1037 }
1038
1039 return 1.0;
1040 } );
1041}
1042
1043
1044#define MISSING_REF_ARG( f ) \
1045 wxString::Format( _( "Missing footprint argument (reference designator) to %s." ), f )
1046
1047static void memberOfFootprintFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1048{
1049 LIBEVAL::VALUE* arg = aCtx->Pop();
1050 LIBEVAL::VALUE* result = aCtx->AllocValue();
1051
1052 result->Set( 0.0 );
1053 aCtx->Push( result );
1054
1055 if( !arg || arg->AsString().IsEmpty() )
1056 {
1057 if( aCtx->HasErrorCallback() )
1058 aCtx->ReportError( MISSING_REF_ARG( wxT( "memberOfFootprint()" ) ) );
1059
1060 return;
1061 }
1062
1063 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1064 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1065
1066 if( !item )
1067 return;
1068
1069 result->SetDeferredEval(
1070 [item, arg]() -> double
1071 {
1072 if( FOOTPRINT* parentFP = item->GetParentFootprint() )
1073 {
1074 if( testFootprintSelector( parentFP, arg->AsString() ) )
1075 return 1.0;
1076 }
1077
1078 return 0.0;
1079 } );
1080}
1081
1082
1083static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
1084{
1085 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1086 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1087 LIBEVAL::VALUE* result = aCtx->AllocValue();
1088
1089 result->Set( 0.0 );
1090 aCtx->Push( result );
1091
1092 if( item && item->Type() == PCB_VIA_T
1093 && static_cast<PCB_VIA*>( item )->GetViaType() == VIATYPE::MICROVIA )
1094 {
1095 result->Set ( 1.0 );
1096 }
1097}
1098
1099
1100static void isBlindBuriedViaFunc( 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::BLIND_BURIED )
1111 {
1112 result->Set ( 1.0 );
1113 }
1114}
1115
1116
1117static void isCoupledDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1118{
1119 PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
1120 BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
1121 BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
1122 LIBEVAL::VALUE* result = aCtx->AllocValue();
1123
1124 result->Set( 0.0 );
1125 aCtx->Push( result );
1126
1127 result->SetDeferredEval(
1128 [a, b, context]() -> double
1129 {
1130 NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
1131
1132 if( !netinfo )
1133 return 0.0;
1134
1135 wxString coupledNet;
1136 wxString dummy;
1137
1138 if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
1139 return 0.0;
1140
1144 {
1145 // DRC engine evaluates these only in the context of a diffpair, but doesn't
1146 // always supply the second (B) item.
1147 if( BOARD* board = a->GetBoard() )
1148 {
1149 if( board->FindNet( coupledNet ) )
1150 return 1.0;
1151 }
1152 }
1153
1154 if( b && b->GetNetname() == coupledNet )
1155 return 1.0;
1156
1157 return 0.0;
1158 } );
1159}
1160
1161
1162#define MISSING_DP_ARG( f ) \
1163 wxString::Format( _( "Missing diff-pair name argument to %s." ), f )
1164
1165static void inDiffPairFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1166{
1167 LIBEVAL::VALUE* argv = aCtx->Pop();
1168 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1169 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1170 LIBEVAL::VALUE* result = aCtx->AllocValue();
1171
1172 result->Set( 0.0 );
1173 aCtx->Push( result );
1174
1175 if( !argv || argv->AsString().IsEmpty() )
1176 {
1177 if( aCtx->HasErrorCallback() )
1178 aCtx->ReportError( MISSING_DP_ARG( wxT( "inDiffPair()" ) ) );
1179
1180 return;
1181 }
1182
1183 if( !item || !item->GetBoard() )
1184 return;
1185
1186 result->SetDeferredEval(
1187 [item, argv]() -> double
1188 {
1189 if( item && item->IsConnected() )
1190 {
1191 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
1192
1193 if( !netinfo )
1194 return 0.0;
1195
1196 wxString refName = netinfo->GetNetname();
1197 wxString arg = argv->AsString();
1198 wxString baseName, coupledNet;
1199 int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
1200
1201 if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
1202 {
1203 if( baseName.Matches( arg ) )
1204 return 1.0;
1205
1206 if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
1207 return 1.0;
1208 }
1209 }
1210
1211 return 0.0;
1212 } );
1213}
1214
1215
1216static void getFieldFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1217{
1218 LIBEVAL::VALUE* arg = aCtx->Pop();
1219 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1220 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1221 LIBEVAL::VALUE* result = aCtx->AllocValue();
1222
1223 result->Set( "" );
1224 aCtx->Push( result );
1225
1226 if( !arg )
1227 {
1228 if( aCtx->HasErrorCallback() )
1229 {
1230 aCtx->ReportError( wxString::Format( _( "Missing field name argument to %s." ),
1231 wxT( "getField()" ) ) );
1232 }
1233
1234 return;
1235 }
1236
1237 if( !item || !item->GetBoard() )
1238 return;
1239
1240 result->SetDeferredEval(
1241 [item, arg]() -> wxString
1242 {
1243 if( item && item->Type() == PCB_FOOTPRINT_T )
1244 {
1245 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1246
1247 PCB_FIELD* field = fp->GetField( arg->AsString() );
1248
1249 if( field )
1250 return field->GetText();
1251 }
1252
1253 return "";
1254 } );
1255}
1256
1257
1258static void hasNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1259{
1260 LIBEVAL::VALUE* arg = aCtx->Pop();
1261 LIBEVAL::VALUE* result = aCtx->AllocValue();
1262
1263 result->Set( 0.0 );
1264 aCtx->Push( result );
1265
1266 if( !arg || arg->AsString().IsEmpty() )
1267 {
1268 if( aCtx->HasErrorCallback() )
1269 aCtx->ReportError( _( "Missing netclass name argument to hasNetclass()" ) );
1270
1271 return;
1272 }
1273
1274 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1275 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1276
1277 if( !item )
1278 return;
1279
1280 result->SetDeferredEval(
1281 [item, arg]() -> double
1282 {
1283 if( !item->IsConnected() )
1284 return 0.0;
1285
1286 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1287 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1288
1289 if( netclass->ContainsNetclassWithName( arg->AsString() ) )
1290 return 1.0;
1291
1292 return 0.0;
1293 } );
1294}
1295
1296
1297static void hasExactNetclassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1298{
1299 LIBEVAL::VALUE* arg = aCtx->Pop();
1300 LIBEVAL::VALUE* result = aCtx->AllocValue();
1301
1302 result->Set( 0.0 );
1303 aCtx->Push( result );
1304
1305 if( !arg || arg->AsString().IsEmpty() )
1306 {
1307 if( aCtx->HasErrorCallback() )
1308 aCtx->ReportError( _( "Missing netclass name argument to hasExactNetclass()" ) );
1309
1310 return;
1311 }
1312
1313 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1314 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1315
1316 if( !item )
1317 return;
1318
1319 result->SetDeferredEval(
1320 [item, arg]() -> double
1321 {
1322 if( !item->IsConnected() )
1323 return 0.0;
1324
1325 BOARD_CONNECTED_ITEM* bcItem = static_cast<BOARD_CONNECTED_ITEM*>( item );
1326 NETCLASS* netclass = bcItem->GetEffectiveNetClass();
1327
1328 if( netclass->GetName() == arg->AsString() )
1329 return 1.0;
1330
1331 return 0.0;
1332 } );
1333}
1334
1335
1336static void hasComponentClassFunc( LIBEVAL::CONTEXT* aCtx, void* self )
1337{
1338 LIBEVAL::VALUE* arg = aCtx->Pop();
1339 LIBEVAL::VALUE* result = aCtx->AllocValue();
1340
1341 result->Set( 0.0 );
1342 aCtx->Push( result );
1343
1344 if( !arg || arg->AsString().IsEmpty() )
1345 {
1346 if( aCtx->HasErrorCallback() )
1347 aCtx->ReportError(
1348 _( "Missing component class name argument to hasComponentClass()" ) );
1349
1350 return;
1351 }
1352
1353 PCBEXPR_VAR_REF* vref = static_cast<PCBEXPR_VAR_REF*>( self );
1354 BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
1355
1356 if( !item )
1357 return;
1358
1359 result->SetDeferredEval(
1360 [item, arg]() -> double
1361 {
1362 FOOTPRINT* footprint = nullptr;
1363
1364 if( item->Type() == PCB_FOOTPRINT_T )
1365 footprint = static_cast<FOOTPRINT*>( item );
1366 else
1367 footprint = item->GetParentFootprint();
1368
1369 if( !footprint )
1370 return 0.0;
1371
1372 const COMPONENT_CLASS* compClass = footprint->GetComponentClass();
1373
1374 if( compClass && compClass->ContainsClassName( arg->AsString() ) )
1375 return 1.0;
1376
1377 return 0.0;
1378 } );
1379}
1380
1381
1383{
1385}
1386
1387
1389{
1390 m_funcs.clear();
1391
1392 RegisterFunc( wxT( "existsOnLayer('x')" ), existsOnLayerFunc );
1393
1394 RegisterFunc( wxT( "isPlated()" ), isPlatedFunc );
1395
1396 RegisterFunc( wxT( "insideCourtyard('x') DEPRECATED" ), intersectsCourtyardFunc );
1397 RegisterFunc( wxT( "insideFrontCourtyard('x') DEPRECATED" ), intersectsFrontCourtyardFunc );
1398 RegisterFunc( wxT( "insideBackCourtyard('x') DEPRECATED" ), intersectsBackCourtyardFunc );
1399 RegisterFunc( wxT( "intersectsCourtyard('x')" ), intersectsCourtyardFunc );
1400 RegisterFunc( wxT( "intersectsFrontCourtyard('x')" ), intersectsFrontCourtyardFunc );
1401 RegisterFunc( wxT( "intersectsBackCourtyard('x')" ), intersectsBackCourtyardFunc );
1402
1403 RegisterFunc( wxT( "insideArea('x') DEPRECATED" ), intersectsAreaFunc );
1404 RegisterFunc( wxT( "intersectsArea('x')" ), intersectsAreaFunc );
1405 RegisterFunc( wxT( "enclosedByArea('x')" ), enclosedByAreaFunc );
1406
1407 RegisterFunc( wxT( "isMicroVia()" ), isMicroVia );
1408 RegisterFunc( wxT( "isBlindBuriedVia()" ), isBlindBuriedViaFunc );
1409
1410 RegisterFunc( wxT( "memberOf('x') DEPRECATED" ), memberOfGroupFunc );
1411 RegisterFunc( wxT( "memberOfGroup('x')" ), memberOfGroupFunc );
1412 RegisterFunc( wxT( "memberOfFootprint('x')" ), memberOfFootprintFunc );
1413 RegisterFunc( wxT( "memberOfSheet('x')" ), memberOfSheetFunc );
1414 RegisterFunc( wxT( "memberOfSheetOrChildren('x')" ), memberOfSheetOrChildrenFunc );
1415
1416 RegisterFunc( wxT( "fromTo('x','y')" ), fromToFunc );
1417 RegisterFunc( wxT( "isCoupledDiffPair()" ), isCoupledDiffPairFunc );
1418 RegisterFunc( wxT( "inDiffPair('x')" ), inDiffPairFunc );
1419
1420 RegisterFunc( wxT( "getField('x')" ), getFieldFunc );
1421
1422 RegisterFunc( wxT( "hasNetclass('x')" ), hasNetclassFunc );
1423 RegisterFunc( wxT( "hasExactNetclass('x')" ), hasExactNetclassFunc );
1424 RegisterFunc( wxT( "hasComponentClass('x')" ), hasComponentClassFunc );
1425}
const char * name
Definition: DXF_plotter.cpp:62
@ ERROR_OUTSIDE
Definition: approximation.h:33
constexpr int ARC_LOW_DEF
Definition: base_units.h:128
BASE_SET & set(size_t pos)
Definition: base_set.h:116
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
int GetDRCEpsilon() const
Return an epsilon which accounts for rounding errors, etc.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:134
virtual void SetLayerSet(const LSET &aLayers)
Definition: board_item.h:260
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:303
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:314
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:326
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:79
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:97
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:252
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:210
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const
Definition: board_item.cpp:336
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:2099
const ZONES & Zones() const
Definition: board.h:362
const FOOTPRINTS & Footprints() const
Definition: board.h:358
std::unordered_map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1374
std::unordered_map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTreeCache
Definition: board.h:1375
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:1024
std::shared_mutex m_CachesMutex
Definition: board.h:1368
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:522
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:46
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:110
virtual EDA_GROUP * GetParentGroup() const
Definition: eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:145
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:97
static ENUM_MAP< T > & Instance()
Definition: property.h:697
wxString GetSheetname() const
Definition: footprint.h:269
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
Definition: footprint.cpp:593
const COMPONENT_CLASS * GetComponentClass() const
Returns the component class for this footprint.
Definition: footprint.cpp:4122
wxString GetFPIDAsString() const
Definition: footprint.h:257
const wxString & GetReference() const
Definition: footprint.h:627
const SHAPE_POLY_SET & GetCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.cpp:3058
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:705
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:712
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:63
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:45
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition: netclass.cpp:278
const wxString GetName() const
Gets the name of this (maybe aggregate) netclass in a format for internal usage or for export to exte...
Definition: netclass.cpp:322
Handle the data for a net.
Definition: netinfo.h: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:621
bool IsFilled() const
Definition: zone.h:292
SHAPE_POLY_SET * Outline()
Definition: zone.h:335
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:136
@ ALLOW_ACUTE_CORNERS
just inflate the polygon. Acute angles create spikes
@ DIFF_PAIR_GAP_CONSTRAINT
Definition: drc_rule.h:73
@ LENGTH_CONSTRAINT
Definition: drc_rule.h:71
@ SKEW_CONSTRAINT
Definition: drc_rule.h:72
#define _(s)
#define ROUTER_TRANSIENT
transient items that should NOT be cached
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
#define MALFORMED_COURTYARDS
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Cu
Definition: layer_ids.h:65
@ B_CrtYd
Definition: layer_ids.h:115
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:744
@ 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)
static void memberOfGroupFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_AREA_ARG(f)
static void isCoupledDiffPairFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void isPlatedFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool searchAreas(BOARD *aBoard, const wxString &aArg, PCBEXPR_CONTEXT *aCtx, const std::function< bool(ZONE *)> &aFunc)
static void existsOnLayerFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_GROUP_ARG(f)
static bool testFootprintSelector(FOOTPRINT *aFp, const wxString &aSelector)
static void isBlindBuriedViaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void memberOfSheetFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void hasComponentClassFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void hasExactNetclassFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_REF_ARG(f)
#define MISSING_DP_ARG(f)
static void enclosedByAreaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void memberOfSheetOrChildrenFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void memberOfFootprintFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void isMicroVia(LIBEVAL::CONTEXT *aCtx, void *self)
static void getFieldFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool collidesWithArea(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer, PCBEXPR_CONTEXT *aCtx, ZONE *aArea)
static void hasNetclassFunc(LIBEVAL::CONTEXT *aCtx, void *self)
bool fromToFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void intersectsCourtyardFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static bool searchFootprints(BOARD *aBoard, const wxString &aArg, PCBEXPR_CONTEXT *aCtx, const std::function< bool(FOOTPRINT *)> &aFunc)
static void inDiffPairFunc(LIBEVAL::CONTEXT *aCtx, void *self)
static void intersectsAreaFunc(LIBEVAL::CONTEXT *aCtx, void *self)
#define MISSING_FP_ARG(f)
std::vector< FAB_LAYER_COLOR > dummy
VECTOR3I res
@ 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