KiCad PCB EDA Suite
pcb_expr_evaluator.cpp File Reference
#include <cstdio>
#include <memory>
#include <board.h>
#include <board_design_settings.h>
#include <drc/drc_rtree.h>
#include <pcb_track.h>
#include <pcb_group.h>
#include <geometry/shape_segment.h>
#include <pcb_expr_evaluator.h>
#include <wx/log.h>
#include <connectivity/connectivity_data.h>
#include <connectivity/connectivity_algo.h>
#include <connectivity/from_to_cache.h>
#include <drc/drc_engine.h>
#include <geometry/shape_circle.h>

Go to the source code of this file.

Classes

class  PCB_LAYER_VALUE
 
class  PCB_UNIT_RESOLVER
 

Functions

bool exprFromTo (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void existsOnLayer (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void isPlated (LIBEVAL::CONTEXT *aCtx, void *self)
 
bool calcIsInsideCourtyard (BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
 
bool isInsideCourtyard (BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
 
static void insideCourtyard (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void insideFrontCourtyard (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void insideBackCourtyard (LIBEVAL::CONTEXT *aCtx, void *self)
 
bool calcIsInsideArea (BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, PCB_EXPR_CONTEXT *aCtx, ZONE *aArea)
 
bool isInsideArea (BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, PCB_EXPR_CONTEXT *aCtx, ZONE *aArea)
 
static void insideArea (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void memberOf (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void isMicroVia (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void isBlindBuriedVia (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void isCoupledDiffPair (LIBEVAL::CONTEXT *aCtx, void *self)
 
static void inDiffPair (LIBEVAL::CONTEXT *aCtx, void *self)
 

Function Documentation

◆ calcIsInsideArea()

bool calcIsInsideArea ( BOARD_ITEM aItem,
const EDA_RECT aItemBBox,
PCB_EXPR_CONTEXT aCtx,
ZONE aArea 
)

Avoid buried vias that don't overlap the zone's layers

Definition at line 447 of file pcb_expr_evaluator.cpp.

449 {
450  BOARD* board = aArea->GetBoard();
451  std::shared_ptr<SHAPE> shape;
452 
453  if( !aArea->GetCachedBoundingBox().Intersects( aItemBBox ) )
454  return false;
455 
456  // Collisions include touching, so we need to deflate outline by enough to
457  // exclude touching. This is particularly important for detecting copper fills
458  // as they will be exactly touching along the entire border.
459  SHAPE_POLY_SET areaOutline = *aArea->Outline();
460  areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(), 0,
462 
463  if( aItem->GetFlags() & HOLE_PROXY )
464  {
465  if( aItem->Type() == PCB_PAD_T )
466  {
467  PAD* pad = static_cast<PAD*>( aItem );
468  const SHAPE_SEGMENT* holeShape = pad->GetEffectiveHoleShape();
469 
470  return areaOutline.Collide( holeShape );
471  }
472  else if( aItem->Type() == PCB_VIA_T )
473  {
474  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
475  const SHAPE_CIRCLE holeShape( via->GetPosition(), via->GetDrillValue() );
476  LSET overlap = via->GetLayerSet() & aArea->GetLayerSet();
477 
479  if( overlap.count() > 0 )
480  {
481  if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
482  return areaOutline.Collide( &holeShape );
483  }
484  }
485 
486  return false;
487  }
488 
489  if( aItem->Type() == PCB_FOOTPRINT_T )
490  {
491  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
492 
493  if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
494  {
495  if( aCtx->HasErrorCallback() )
496  {
497  aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
498  }
499 
500  return false;
501  }
502 
503  if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
504  {
505  SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyard( F_CrtYd );
506 
507  if( courtyard.OutlineCount() == 0 )
508  {
509  if( aCtx->HasErrorCallback() )
510  aCtx->ReportError( _( "Footprint has no front courtyard." ) );
511 
512  return false;
513  }
514  else
515  {
516  return areaOutline.Collide( &courtyard.Outline( 0 ) );
517  }
518  }
519 
520  if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
521  {
522  SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyard( B_CrtYd );
523 
524  if( courtyard.OutlineCount() == 0 )
525  {
526  if( aCtx->HasErrorCallback() )
527  aCtx->ReportError( _( "Footprint has no back courtyard." ) );
528 
529  return false;
530  }
531  else
532  {
533  return areaOutline.Collide( &courtyard.Outline( 0 ) );
534  }
535  }
536 
537  return false;
538  }
539 
540  if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T )
541  {
542  ZONE* zone = static_cast<ZONE*>( aItem );
543 
544  if( !zone->IsFilled() )
545  return false;
546 
547  DRC_RTREE* zoneRTree = board->m_CopperZoneRTrees[ zone ].get();
548 
549  std::vector<SHAPE*> shapes;
550 
551  if( zoneRTree )
552  {
553  for( PCB_LAYER_ID layer : aArea->GetLayerSet().Seq() )
554  {
555  if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
556  {
557  if( zoneRTree->QueryColliding( aItemBBox, &areaOutline, layer ) )
558  return true;
559  }
560  }
561  }
562 
563  return false;
564  }
565  else
566  {
567  if( aCtx->GetLayer() != UNDEFINED_LAYER
568  && !( aArea->GetLayerSet().Contains( aCtx->GetLayer() ) ) )
569  return false;
570 
571  if( !shape )
572  shape = aItem->GetEffectiveShape( aCtx->GetLayer() );
573 
574  return areaOutline.Collide( shape.get() );
575  }
576 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
SHAPE_POLY_SET * Outline()
Definition: zone.h:320
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
Definition: layer_ids.h:575
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:295
class PAD, a pad in a footprint
Definition: typeinfo.h:89
bool IsFilled() const
Definition: zone.h:234
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:411
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:874
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
const EDA_RECT GetCachedBoundingBox() const
ONLY TO BE USED BY CLIENTS WHICH SET UP THE CACHE!
Definition: zone.h:145
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
void Deflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
#define _(s)
const SHAPE_POLY_SET & GetPolyCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.h:695
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:155
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
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,...
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
class ZONE, managed by a footprint
Definition: typeinfo.h:94
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:881
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
std::map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTrees
Definition: board.h:1096
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:167
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Definition: pad.h:57
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition: drc_rtree.h:44
#define MALFORMED_COURTYARDS
just inflate the polygon. Acute angles create spikes
PCB_LAYER_ID GetLayer() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
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:165

References _, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS, B_CrtYd, LSET::BackMask(), SHAPE_POLY_SET::Collide(), LSET::Contains(), SHAPE_POLY_SET::Deflate(), F_CrtYd, LSET::FrontMask(), BOARD_ITEM::GetBoard(), ZONE::GetCachedBoundingBox(), BOARD::GetDesignSettings(), BOARD_DESIGN_SETTINGS::GetDRCEpsilon(), BOARD_ITEM::GetEffectiveShape(), EDA_ITEM::GetFlags(), PCB_EXPR_CONTEXT::GetLayer(), ZONE::GetLayerSet(), FOOTPRINT::GetPolyCourtyard(), LIBEVAL::CONTEXT::HasErrorCallback(), HOLE_PROXY, EDA_RECT::Intersects(), ZONE::IsFilled(), BOARD::m_CopperZoneRTrees, MALFORMED_COURTYARDS, ZONE::Outline(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), pad, PCB_FOOTPRINT_T, PCB_FP_ZONE_T, PCB_PAD_T, PCB_VIA_T, PCB_ZONE_T, DRC_RTREE::QueryColliding(), LIBEVAL::CONTEXT::ReportError(), LSET::Seq(), EDA_ITEM::Type(), UNDEFINED_LAYER, and via.

Referenced by isInsideArea().

◆ calcIsInsideCourtyard()

bool calcIsInsideCourtyard ( BOARD_ITEM aItem,
const EDA_RECT aItemBBox,
std::shared_ptr< SHAPE > &  aItemShape,
PCB_EXPR_CONTEXT aCtx,
FOOTPRINT aFootprint,
PCB_LAYER_ID  aSide 
)

Definition at line 191 of file pcb_expr_evaluator.cpp.

194 {
195  SHAPE_POLY_SET footprintCourtyard;
196 
197  footprintCourtyard = aFootprint->GetPolyCourtyard( aSide );
198 
199  if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T )
200  {
201  // A zone must be entirely inside the courtyard to be considered
202  if( !aFootprint->GetBoundingBox().Contains( aItemBBox ) )
203  return false;
204  }
205  else
206  {
207  if( !aFootprint->GetBoundingBox().Intersects( aItemBBox ) )
208  return false;
209  }
210 
211  if( !aItemShape )
212  aItemShape = aItem->GetEffectiveShape( aCtx->GetLayer() );
213 
214  return footprintCourtyard.Collide( aItemShape.get() );
215 };
bool Contains(const wxPoint &aPoint) const
Definition: eda_rect.cpp:57
Represent a set of closed polygons.
const SHAPE_POLY_SET & GetPolyCourtyard(PCB_LAYER_ID aLayer) const
Used in DRC to test the courtyard area (a complex polygon).
Definition: footprint.h:695
class ZONE, a copper pour area
Definition: typeinfo.h:105
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,...
const EDA_RECT GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: footprint.cpp:718
class ZONE, managed by a footprint
Definition: typeinfo.h:94
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
Definition: board_item.cpp:167
PCB_LAYER_ID GetLayer() const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References SHAPE_POLY_SET::Collide(), EDA_RECT::Contains(), FOOTPRINT::GetBoundingBox(), BOARD_ITEM::GetEffectiveShape(), PCB_EXPR_CONTEXT::GetLayer(), FOOTPRINT::GetPolyCourtyard(), EDA_RECT::Intersects(), PCB_FP_ZONE_T, PCB_ZONE_T, and EDA_ITEM::Type().

Referenced by isInsideCourtyard().

◆ existsOnLayer()

static void existsOnLayer ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 76 of file pcb_expr_evaluator.cpp.

77 {
78  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
79  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
80 
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 )
91  {
92  if( aCtx->HasErrorCallback() )
93  {
94  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
95  wxT( "existsOnLayer()" ) ) );
96  }
97 
98  return;
99  }
100 
101  result->SetDeferredEval(
102  [item, arg, aCtx]() -> double
103  {
104  const wxString& layerName = arg->AsString();
105  wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
106 
107  if( aCtx->HasErrorCallback())
108  {
109  /*
110  * Interpreted version
111  */
112 
113  bool anyMatch = false;
114 
115  for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
116  {
117  wxPGChoiceEntry& entry = layerMap[ ii ];
118 
119  if( entry.GetText().Matches( layerName ))
120  {
121  anyMatch = true;
122 
123  if( item->IsOnLayer( ToLAYER_ID( entry.GetValue())))
124  return 1.0;
125  }
126  }
127 
128  if( !anyMatch )
129  {
130  aCtx->ReportError( wxString::Format( _( "Unrecognized layer '%s'" ),
131  layerName ) );
132  }
133  }
134  else
135  {
136  /*
137  * Compiled version
138  */
139 
140  BOARD* board = item->GetBoard();
141  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
142  auto i = board->m_LayerExpressionCache.find( layerName );
143  LSET mask;
144 
145  if( i == board->m_LayerExpressionCache.end() )
146  {
147  for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
148  {
149  wxPGChoiceEntry& entry = layerMap[ ii ];
150 
151  if( entry.GetText().Matches( layerName ) )
152  mask.set( ToLAYER_ID( entry.GetValue() ) );
153  }
154 
155  board->m_LayerExpressionCache[ layerName ] = mask;
156  }
157  else
158  {
159  mask = i->second;
160  }
161 
162  if( ( item->GetLayerSet() & mask ).any() )
163  return 1.0;
164  }
165 
166  return 0.0;
167  } );
168 }
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
static ENUM_MAP< T > & Instance()
Definition: property.h:510
std::mutex m_CachesMutex
Definition: board.h:1089
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:504
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:198
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
std::map< wxString, LSET > m_LayerExpressionCache
Definition: board.h:1094
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual const wxString & AsString() const
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
void Push(VALUE *v)
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:145

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), Format(), BOARD_ITEM::GetBoard(), BOARD_ITEM::GetLayerSet(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), ENUM_MAP< T >::Instance(), BOARD_ITEM::IsOnLayer(), BOARD::m_CachesMutex, BOARD::m_LayerExpressionCache, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), and ToLAYER_ID().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ exprFromTo()

bool exprFromTo ( LIBEVAL::CONTEXT aCtx,
void *  self 
)

Definition at line 43 of file pcb_expr_evaluator.cpp.

44 {
45  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
46  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
47  LIBEVAL::VALUE* result = aCtx->AllocValue();
48 
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( "Attempting to call fromTo() with non-existent from-to cache, aborting...");
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 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:344
virtual const wxString & AsString() const
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const

References LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), BOARD_ITEM::GetBoard(), BOARD::GetConnectivity(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), and LIBEVAL::VALUE::Set().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ inDiffPair()

static void inDiffPair ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 811 of file pcb_expr_evaluator.cpp.

812 {
813  LIBEVAL::VALUE* arg = aCtx->Pop();
814  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
815  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
816  LIBEVAL::VALUE* result = aCtx->AllocValue();
817 
818  result->Set( 0.0 );
819  aCtx->Push( result );
820 
821  if( !item || !item->GetBoard() )
822  return;
823 
824  if( !arg )
825  {
826  if( aCtx->HasErrorCallback() )
827  {
828  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
829  wxT( "inDiffPair()" ) ) );
830  }
831 
832  return;
833  }
834 
835  result->SetDeferredEval(
836  [item, arg]() -> double
837  {
838  if( item && item->IsConnected() )
839  {
840  NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
841 
842  wxString refName = netinfo->GetNetname();
843  wxString baseName, coupledNet;
844  int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
845 
846  if( polarity != 0
847  && item->GetBoard()->FindNet( coupledNet )
848  && baseName.Matches( arg->AsString() ) )
849  {
850  return 1.0;
851  }
852  }
853 
854  return 0.0;
855  } );
856 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1325
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:365
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
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.
const wxString & GetNetname() const
Definition: netinfo.h:119
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
Handle the data for a net.
Definition: netinfo.h:64
virtual const wxString & AsString() const
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition: board_item.h:103
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), BOARD::FindNet(), Format(), BOARD_ITEM::GetBoard(), NETINFO_ITEM::GetNetname(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), BOARD_ITEM::IsConnected(), DRC_ENGINE::MatchDpSuffix(), EDA_ITEM::Matches(), LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), and LIBEVAL::VALUE::SetDeferredEval().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ insideArea()

static void insideArea ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 600 of file pcb_expr_evaluator.cpp.

601 {
602  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
603  LIBEVAL::VALUE* arg = aCtx->Pop();
604  LIBEVAL::VALUE* result = aCtx->AllocValue();
605 
606  result->Set( 0.0 );
607  aCtx->Push( result );
608 
609  if( !arg )
610  {
611  if( aCtx->HasErrorCallback() )
612  {
613  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
614  wxT( "insideArea()" ) ) );
615  }
616 
617  return;
618  }
619 
620  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
621  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
622 
623  if( !item )
624  return;
625 
626  result->SetDeferredEval(
627  [item, arg, context]() -> double
628  {
629  BOARD* board = item->GetBoard();
630  EDA_RECT itemBBox;
631 
632  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
633  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
634  else
635  itemBBox = item->GetBoundingBox();
636 
637  if( arg->AsString() == "A" )
638  {
639  ZONE* zone = dynamic_cast<ZONE*>( context->GetItem( 0 ) );
640  return isInsideArea( item, itemBBox, context, zone ) ? 1.0 : 0.0;
641  }
642  else if( arg->AsString() == "B" )
643  {
644  ZONE* zone = dynamic_cast<ZONE*>( context->GetItem( 1 ) );
645  return isInsideArea( item, itemBBox, context, zone ) ? 1.0 : 0.0;
646  }
647  else if( KIID::SniffTest( arg->AsString() ) )
648  {
649  KIID target( arg->AsString());
650 
651  for( ZONE* area : board->Zones() )
652  {
653  // Only a single zone can match the UUID; exit once we find a match whether
654  // "inside" or not
655  if( area->m_Uuid == target )
656  return isInsideArea( item, itemBBox, context, area ) ? 1.0 : 0.0;
657  }
658 
659  for( FOOTPRINT* footprint : board->Footprints() )
660  {
661  for( ZONE* area : footprint->Zones() )
662  {
663  // Only a single zone can match the UUID; exit once we find a match
664  // whether "inside" or not
665  if( area->m_Uuid == target )
666  return isInsideArea( item, itemBBox, context, area ) ? 1.0 : 0.0;
667  }
668  }
669 
670  return 0.0;
671  }
672  else // Match on zone name
673  {
674  for( ZONE* area : board->Zones())
675  {
676  if( area->GetZoneName().Matches( arg->AsString() ) )
677  {
678  // Many zones can match the name; exit only when we find an "inside"
679  if( isInsideArea( item, itemBBox, context, area ) )
680  return 1.0;
681  }
682  }
683 
684  for( FOOTPRINT* footprint : board->Footprints() )
685  {
686  for( ZONE* area : footprint->Zones() )
687  {
688  // Many zones can match the name; exit only when we find an "inside"
689  if( area->GetZoneName().Matches( arg->AsString() ) )
690  {
691  if( isInsideArea( item, itemBBox, context, area ) )
692  return 1.0;
693  }
694  }
695  }
696 
697  return 0.0;
698  }
699  } );
700 }
BOARD_ITEM * GetItem(int index) const
ZONES & Zones()
Definition: board.h:239
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
bool isInsideArea(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, PCB_EXPR_CONTEXT *aCtx, ZONE *aArea)
Definition: kiid.h:44
static bool SniffTest(const wxString &aCandidate)
Definition: kiid.cpp:140
FOOTPRINTS & Footprints()
Definition: board.h:233
#define _(s)
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual const wxString & AsString() const
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), BOARD::Footprints(), Format(), BOARD_ITEM::GetBoard(), EDA_ITEM::GetBoundingBox(), PCB_EXPR_CONTEXT::GetItem(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), isInsideArea(), PCB_FP_ZONE_T, PCB_ZONE_T, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), KIID::SniffTest(), EDA_ITEM::Type(), and BOARD::Zones().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ insideBackCourtyard()

static void insideBackCourtyard ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 382 of file pcb_expr_evaluator.cpp.

383 {
384  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
385  LIBEVAL::VALUE* arg = aCtx->Pop();
386  LIBEVAL::VALUE* result = aCtx->AllocValue();
387 
388  result->Set( 0.0 );
389  aCtx->Push( result );
390 
391  if( !arg )
392  {
393  if( aCtx->HasErrorCallback() )
394  {
395  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
396  wxT( "insideBackCourtyard()" ) ) );
397  }
398  return;
399  }
400 
401  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
402  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
403 
404  if( !item )
405  return;
406 
407  result->SetDeferredEval(
408  [item, arg, context]() -> double
409  {
410  BOARD* board = item->GetBoard();
411  EDA_RECT itemBBox;
412  std::shared_ptr<SHAPE> itemShape;
413 
414  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
415  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
416  else
417  itemBBox = item->GetBoundingBox();
418 
419  if( arg->AsString() == "A" )
420  {
421  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
422 
423  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
424  return 1.0;
425  }
426  else if( arg->AsString() == "B" )
427  {
428  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
429 
430  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
431  return 1.0;
432  }
433  else for( FOOTPRINT* fp : board->Footprints() )
434  {
435  if( fp->GetReference().Matches( arg->AsString() ) )
436  {
437  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
438  return 1.0;
439  }
440  }
441 
442  return 0.0;
443  } );
444 }
BOARD_ITEM * GetItem(int index) const
bool isInsideCourtyard(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
FOOTPRINTS & Footprints()
Definition: board.h:233
const wxString & GetReference() const
Definition: footprint.h:463
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual const wxString & AsString() const
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), B_Cu, BOARD::Footprints(), Format(), BOARD_ITEM::GetBoard(), EDA_ITEM::GetBoundingBox(), PCB_EXPR_CONTEXT::GetItem(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), isInsideCourtyard(), PCB_FP_ZONE_T, PCB_ZONE_T, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), and EDA_ITEM::Type().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ insideCourtyard()

static void insideCourtyard ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 250 of file pcb_expr_evaluator.cpp.

251 {
252  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
253  LIBEVAL::VALUE* arg = aCtx->Pop();
254  LIBEVAL::VALUE* result = aCtx->AllocValue();
255 
256  result->Set( 0.0 );
257  aCtx->Push( result );
258 
259  if( !arg )
260  {
261  if( aCtx->HasErrorCallback() )
262  {
263  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
264  wxT( "insideCourtyard()" ) ) );
265  }
266 
267  return;
268  }
269 
270  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
271  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
272 
273  if( !item )
274  return;
275 
276  result->SetDeferredEval(
277  [item, arg, context]() -> double
278  {
279  BOARD* board = item->GetBoard();
280  EDA_RECT itemBBox;
281  std::shared_ptr<SHAPE> itemShape;
282 
283  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
284  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
285  else
286  itemBBox = item->GetBoundingBox();
287 
288  if( arg->AsString() == "A" )
289  {
290  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
291 
292  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
293  return 1.0;
294  }
295  else if( arg->AsString() == "B" )
296  {
297  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
298 
299  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
300  return 1.0;
301  }
302  else for( FOOTPRINT* fp : board->Footprints() )
303  {
304  if( fp->GetReference().Matches( arg->AsString() ) )
305  {
306  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
307  return 1.0;
308  }
309  }
310 
311  return 0.0;
312  } );
313 }
BOARD_ITEM * GetItem(int index) const
bool isInsideCourtyard(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
FOOTPRINTS & Footprints()
Definition: board.h:233
const wxString & GetReference() const
Definition: footprint.h:463
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual const wxString & AsString() const
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), BOARD::Footprints(), Format(), BOARD_ITEM::GetBoard(), EDA_ITEM::GetBoundingBox(), PCB_EXPR_CONTEXT::GetItem(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), In1_Cu, isInsideCourtyard(), PCB_FP_ZONE_T, PCB_ZONE_T, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), and EDA_ITEM::Type().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ insideFrontCourtyard()

static void insideFrontCourtyard ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 316 of file pcb_expr_evaluator.cpp.

317 {
318  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
319  LIBEVAL::VALUE* arg = aCtx->Pop();
320  LIBEVAL::VALUE* result = aCtx->AllocValue();
321 
322  result->Set( 0.0 );
323  aCtx->Push( result );
324 
325  if( !arg )
326  {
327  if( aCtx->HasErrorCallback() )
328  {
329  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
330  wxT( "insideFrontCourtyard()" ) ) );
331  }
332 
333  return;
334  }
335 
336  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
337  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
338 
339  if( !item )
340  return;
341 
342  result->SetDeferredEval(
343  [item, arg, context]() -> double
344  {
345  BOARD* board = item->GetBoard();
346  EDA_RECT itemBBox;
347  std::shared_ptr<SHAPE> itemShape;
348 
349  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
350  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
351  else
352  itemBBox = item->GetBoundingBox();
353 
354  if( arg->AsString() == "A" )
355  {
356  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
357 
358  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
359  return 1.0;
360  }
361  else if( arg->AsString() == "B" )
362  {
363  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
364 
365  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
366  return 1.0;
367  }
368  else for( FOOTPRINT* fp : board->Footprints() )
369  {
370  if( fp->GetReference().Matches( arg->AsString() ) )
371  {
372  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
373  return 1.0;
374  }
375  }
376 
377  return 0.0;
378  } );
379 }
BOARD_ITEM * GetItem(int index) const
bool isInsideCourtyard(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
FOOTPRINTS & Footprints()
Definition: board.h:233
const wxString & GetReference() const
Definition: footprint.h:463
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
Definition: layer_ids.h:71
virtual const wxString & AsString() const
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:75
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), F_Cu, BOARD::Footprints(), Format(), BOARD_ITEM::GetBoard(), EDA_ITEM::GetBoundingBox(), PCB_EXPR_CONTEXT::GetItem(), PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::HasErrorCallback(), isInsideCourtyard(), PCB_FP_ZONE_T, PCB_ZONE_T, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), and EDA_ITEM::Type().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ isBlindBuriedVia()

static void isBlindBuriedVia ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 764 of file pcb_expr_evaluator.cpp.

765 {
766  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
767  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
768  LIBEVAL::VALUE* result = aCtx->AllocValue();
769 
770  result->Set( 0.0 );
771  aCtx->Push( result );
772 
773  PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
774 
775  if( via && via->GetViaType() == VIATYPE::BLIND_BURIED )
776  result->Set ( 1.0 );
777 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const

References LIBEVAL::CONTEXT::AllocValue(), BLIND_BURIED, PCB_EXPR_VAR_REF::GetObject(), LIBEVAL::CONTEXT::Push(), LIBEVAL::VALUE::Set(), and via.

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ isCoupledDiffPair()

static void isCoupledDiffPair ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 780 of file pcb_expr_evaluator.cpp.

781 {
782  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
783  BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
784  BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
785  LIBEVAL::VALUE* result = aCtx->AllocValue();
786 
787  result->Set( 0.0 );
788  aCtx->Push( result );
789 
790  result->SetDeferredEval(
791  [a, b]() -> double
792  {
793  if( a && b )
794  {
795  NETINFO_ITEM* netinfo = a->GetNet();
796  wxString coupledNet, dummy;
797 
798  if( netinfo
799  && DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy )
800  && b->GetNetname() == coupledNet )
801  {
802  return 1.0;
803  }
804  }
805 
806  return 0.0;
807  } );
808 }
BOARD_ITEM * GetItem(int index) const
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
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.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
const wxString & GetNetname() const
Definition: netinfo.h:119
Handle the data for a net.
Definition: netinfo.h:64
void Push(VALUE *v)
void Set(double aValue)

References LIBEVAL::CONTEXT::AllocValue(), dummy(), PCB_EXPR_CONTEXT::GetItem(), BOARD_CONNECTED_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), DRC_ENGINE::MatchDpSuffix(), LIBEVAL::CONTEXT::Push(), and LIBEVAL::VALUE::Set().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ isInsideArea()

bool isInsideArea ( BOARD_ITEM aItem,
const EDA_RECT aItemBBox,
PCB_EXPR_CONTEXT aCtx,
ZONE aArea 
)

Definition at line 579 of file pcb_expr_evaluator.cpp.

581 {
582  if( !aArea || aArea == aItem || aArea->GetParent() == aItem )
583  return false;
584 
585  BOARD* board = aArea->GetBoard();
586  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
587  std::pair<BOARD_ITEM*, BOARD_ITEM*> key( aArea, aItem );
588  auto i = board->m_InsideAreaCache.find( key );
589 
590  if( i != board->m_InsideAreaCache.end() )
591  return i->second;
592 
593  bool isInside = calcIsInsideArea( aItem, aItemBBox, aCtx, aArea );
594 
595  board->m_InsideAreaCache[ key ] = isInside;
596  return isInside;
597 }
bool calcIsInsideArea(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, PCB_EXPR_CONTEXT *aCtx, ZONE *aArea)
std::mutex m_CachesMutex
Definition: board.h:1089
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideAreaCache
Definition: board.h:1093

References calcIsInsideArea(), BOARD_ITEM::GetBoard(), BOARD_ITEM::GetParent(), BOARD::m_CachesMutex, and BOARD::m_InsideAreaCache.

Referenced by insideArea().

◆ isInsideCourtyard()

bool isInsideCourtyard ( BOARD_ITEM aItem,
const EDA_RECT aItemBBox,
std::shared_ptr< SHAPE > &  aItemShape,
PCB_EXPR_CONTEXT aCtx,
FOOTPRINT aFootprint,
PCB_LAYER_ID  aSide 
)

Definition at line 218 of file pcb_expr_evaluator.cpp.

221 {
222  if( !aFootprint )
223  return false;
224 
225  BOARD* board = aItem->GetBoard();
226  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
227  std::pair<BOARD_ITEM*, BOARD_ITEM*> key( aFootprint, aItem );
228 
229  std::map< std::pair<BOARD_ITEM*, BOARD_ITEM*>, bool >* cache;
230 
231  switch( aSide )
232  {
233  case F_Cu: cache = &board->m_InsideFCourtyardCache; break;
234  case B_Cu: cache = &board->m_InsideBCourtyardCache; break;
235  default: cache = &board->m_InsideCourtyardCache; break;
236  }
237 
238  auto i = cache->find( key );
239 
240  if( i != cache->end() )
241  return i->second;
242 
243  bool res = calcIsInsideCourtyard( aItem, aItemBBox, aItemShape, aCtx, aFootprint, aSide );
244 
245  (*cache)[ key ] = res;
246  return res;
247 };
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideCourtyardCache
Definition: board.h:1090
std::mutex m_CachesMutex
Definition: board.h:1089
bool calcIsInsideCourtyard(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, std::shared_ptr< SHAPE > &aItemShape, PCB_EXPR_CONTEXT *aCtx, FOOTPRINT *aFootprint, PCB_LAYER_ID aSide)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
Definition: layer_ids.h:71
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:36
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideBCourtyardCache
Definition: board.h:1092
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideFCourtyardCache
Definition: board.h:1091

References B_Cu, calcIsInsideCourtyard(), F_Cu, BOARD_ITEM::GetBoard(), BOARD::m_CachesMutex, BOARD::m_InsideBCourtyardCache, BOARD::m_InsideCourtyardCache, and BOARD::m_InsideFCourtyardCache.

Referenced by insideBackCourtyard(), insideCourtyard(), and insideFrontCourtyard().

◆ isMicroVia()

static void isMicroVia ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 748 of file pcb_expr_evaluator.cpp.

749 {
750  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
751  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
752  LIBEVAL::VALUE* result = aCtx->AllocValue();
753 
754  result->Set( 0.0 );
755  aCtx->Push( result );
756 
757  PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
758 
759  if( via && via->GetViaType() == VIATYPE::MICROVIA )
760  result->Set ( 1.0 );
761 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const

References LIBEVAL::CONTEXT::AllocValue(), PCB_EXPR_VAR_REF::GetObject(), MICROVIA, LIBEVAL::CONTEXT::Push(), LIBEVAL::VALUE::Set(), and via.

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ isPlated()

static void isPlated ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 171 of file pcb_expr_evaluator.cpp.

172 {
173  LIBEVAL::VALUE* result = aCtx->AllocValue();
174 
175  result->Set( 0.0 );
176  aCtx->Push( result );
177 
178  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_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 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PAD, a pad in a footprint
Definition: typeinfo.h:89
Plated through hole pad.
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References LIBEVAL::CONTEXT::AllocValue(), PCB_EXPR_VAR_REF::GetObject(), PCB_PAD_T, PCB_VIA_T, PTH, LIBEVAL::CONTEXT::Push(), LIBEVAL::VALUE::Set(), and EDA_ITEM::Type().

Referenced by BOARD_ADAPTER::addPadsWithClearance(), PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions(), and FOOTPRINT::TransformPadsWithClearanceToPolygon().

◆ memberOf()

static void memberOf ( LIBEVAL::CONTEXT aCtx,
void *  self 
)
static

Definition at line 703 of file pcb_expr_evaluator.cpp.

704 {
705  LIBEVAL::VALUE* arg = aCtx->Pop();
706  LIBEVAL::VALUE* result = aCtx->AllocValue();
707 
708  result->Set( 0.0 );
709  aCtx->Push( result );
710 
711  if( !arg )
712  {
713  if( aCtx->HasErrorCallback() )
714  {
715  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
716  wxT( "memberOf()" ) ) );
717  }
718  return;
719  }
720 
721  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
722  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
723 
724  if( !item )
725  return;
726 
727  result->SetDeferredEval(
728  [item, arg]() -> double
729  {
730  PCB_GROUP* group = item->GetParentGroup();
731 
732  if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
733  group = item->GetParent()->GetParentGroup();
734 
735  while( group )
736  {
737  if( group->GetName().Matches( arg->AsString() ) )
738  return 1.0;
739 
740  group = group->GetParentGroup();
741  }
742 
743  return 0.0;
744  } );
745 }
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:60
void SetDeferredEval(std::function< double()> aLambda)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
#define _(s)
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ReportError(const wxString &aErrorMsg)
virtual const wxString & AsString() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:135
void Push(VALUE *v)
void Set(double aValue)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

References _, LIBEVAL::CONTEXT::AllocValue(), LIBEVAL::VALUE::AsString(), Format(), PCB_EXPR_VAR_REF::GetObject(), BOARD_ITEM::GetParent(), BOARD_ITEM::GetParentGroup(), group, LIBEVAL::CONTEXT::HasErrorCallback(), PCB_FOOTPRINT_T, LIBEVAL::CONTEXT::Pop(), LIBEVAL::CONTEXT::Push(), LIBEVAL::CONTEXT::ReportError(), LIBEVAL::VALUE::Set(), LIBEVAL::VALUE::SetDeferredEval(), and EDA_ITEM::Type().

Referenced by PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().