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 439 of file pcb_expr_evaluator.cpp.

441 {
442  BOARD* board = aArea->GetBoard();
443  EDA_RECT areaBBox = aArea->GetBoundingBox();
444  std::shared_ptr<SHAPE> shape;
445 
446  if( !areaBBox.Intersects( aItemBBox ) )
447  return false;
448 
449  // Collisions include touching, so we need to deflate outline by enough to exclude it.
450  // This is particularly important for detecting copper fills as they will be exactly
451  // touching along the entire exclusion border.
452  SHAPE_POLY_SET areaOutline = *aArea->Outline();
453  areaOutline.Deflate( board->GetDesignSettings().GetDRCEpsilon(), 0,
455 
456  if( aItem->GetFlags() & HOLE_PROXY )
457  {
458  if( aItem->Type() == PCB_PAD_T )
459  {
460  PAD* pad = static_cast<PAD*>( aItem );
461  const SHAPE_SEGMENT* holeShape = pad->GetEffectiveHoleShape();
462 
463  return areaOutline.Collide( holeShape );
464  }
465  else if( aItem->Type() == PCB_VIA_T )
466  {
467  PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
468  const SHAPE_CIRCLE holeShape( via->GetPosition(), via->GetDrillValue() );
469  LSET overlap = via->GetLayerSet() & aArea->GetLayerSet();
470 
472  if( overlap.count() > 0 )
473  {
474  if( aCtx->GetLayer() == UNDEFINED_LAYER || overlap.Contains( aCtx->GetLayer() ) )
475  return areaOutline.Collide( &holeShape );
476  }
477  }
478 
479  return false;
480  }
481 
482  if( aItem->Type() == PCB_FOOTPRINT_T )
483  {
484  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
485 
486  if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
487  {
488  if( aCtx->HasErrorCallback() )
489  {
490  aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
491  }
492 
493  return false;
494  }
495 
496  if( ( aArea->GetLayerSet() & LSET::FrontMask() ).any() )
497  {
498  SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyard( F_CrtYd );
499 
500  if( courtyard.OutlineCount() == 0 )
501  {
502  if( aCtx->HasErrorCallback() )
503  aCtx->ReportError( _( "Footprint has no front courtyard." ) );
504 
505  return false;
506  }
507  else
508  {
509  return areaOutline.Collide( &courtyard.Outline( 0 ) );
510  }
511  }
512 
513  if( ( aArea->GetLayerSet() & LSET::BackMask() ).any() )
514  {
515  SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyard( B_CrtYd );
516 
517  if( courtyard.OutlineCount() == 0 )
518  {
519  if( aCtx->HasErrorCallback() )
520  aCtx->ReportError( _( "Footprint has no back courtyard." ) );
521 
522  return false;
523  }
524  else
525  {
526  return areaOutline.Collide( &courtyard.Outline( 0 ) );
527  }
528  }
529 
530  return false;
531  }
532 
533  if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T )
534  {
535  ZONE* zone = static_cast<ZONE*>( aItem );
536 
537  if( !zone->IsFilled() )
538  return false;
539 
540  DRC_RTREE* zoneRTree = board->m_CopperZoneRTrees[ zone ].get();
541 
542  std::vector<SHAPE*> shapes;
543 
544  if( zoneRTree )
545  {
546  for( PCB_LAYER_ID layer : aArea->GetLayerSet().Seq() )
547  {
548  if( aCtx->GetLayer() == layer || aCtx->GetLayer() == UNDEFINED_LAYER )
549  {
550  if( zoneRTree->QueryColliding( areaBBox, &areaOutline, layer ) )
551  return true;
552  }
553  }
554  }
555 
556  return false;
557  }
558  else
559  {
560  PCB_LAYER_ID layer = aCtx->GetLayer();
561 
562  if( layer != UNDEFINED_LAYER && !( aArea->GetLayerSet().Contains( layer ) ) )
563  return false;
564 
565  if( !shape )
566  shape = aItem->GetEffectiveShape( layer );
567 
568  return areaOutline.Collide( shape.get() );
569  }
570 }
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:587
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:289
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:883
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:181
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
const EDA_RECT GetBoundingBox() const override
Definition: zone.cpp:320
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:154
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:191
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
class ZONE, managed by a footprint
Definition: typeinfo.h:94
Handle the component boundary box.
Definition: eda_rect.h:42
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:890
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:1072
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:46
#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:112
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:183

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::GetBoundingBox(), 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 192 of file pcb_expr_evaluator.cpp.

195 {
196  SHAPE_POLY_SET footprintCourtyard;
197 
198  footprintCourtyard = aFootprint->GetPolyCourtyard( aSide );
199 
200  if( !aFootprint->GetBoundingBox().Intersects( aItemBBox ) )
201  return false;
202 
203  if( !aItemShape )
204  aItemShape = aItem->GetEffectiveShape( aCtx->GetLayer() );
205 
206  return footprintCourtyard.Collide( aItemShape.get() );
207 };
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:181
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
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:736
bool Intersects(const EDA_RECT &aRect) const
Test for a common area between rectangles.
Definition: eda_rect.cpp:150
PCB_LAYER_ID GetLayer() const

References SHAPE_POLY_SET::Collide(), FOOTPRINT::GetBoundingBox(), BOARD_ITEM::GetEffectiveShape(), PCB_EXPR_CONTEXT::GetLayer(), FOOTPRINT::GetPolyCourtyard(), and EDA_RECT::Intersects().

Referenced by isInsideCourtyard().

◆ existsOnLayer()

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

Definition at line 77 of file pcb_expr_evaluator.cpp.

78 {
79  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
80  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
81 
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 )
92  {
93  if( aCtx->HasErrorCallback() )
94  {
95  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
96  wxT( "existsOnLayer()" ) ) );
97  }
98 
99  return;
100  }
101 
102  result->SetDeferredEval(
103  [item, arg, aCtx]() -> double
104  {
105  const wxString& layerName = arg->AsString();
106  wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
107 
108  if( aCtx->HasErrorCallback())
109  {
110  /*
111  * Interpreted version
112  */
113 
114  bool anyMatch = false;
115 
116  for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
117  {
118  wxPGChoiceEntry& entry = layerMap[ ii ];
119 
120  if( entry.GetText().Matches( layerName ))
121  {
122  anyMatch = true;
123 
124  if( item->IsOnLayer( ToLAYER_ID( entry.GetValue())))
125  return 1.0;
126  }
127  }
128 
129  if( !anyMatch )
130  {
131  aCtx->ReportError( wxString::Format( _( "Unrecognized layer '%s'" ),
132  layerName ) );
133  }
134  }
135  else
136  {
137  /*
138  * Compiled version
139  */
140 
141  BOARD* board = item->GetBoard();
142  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
143  auto i = board->m_LayerExpressionCache.find( layerName );
144  LSET mask;
145 
146  if( i == board->m_LayerExpressionCache.end() )
147  {
148  for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
149  {
150  wxPGChoiceEntry& entry = layerMap[ ii ];
151 
152  if( entry.GetText().Matches( layerName ) )
153  mask.set( ToLAYER_ID( entry.GetValue() ) );
154  }
155 
156  board->m_LayerExpressionCache[ layerName ] = mask;
157  }
158  else
159  {
160  mask = i->second;
161  }
162 
163  if( ( item->GetLayerSet() & mask ).any() )
164  return 1.0;
165  }
166 
167  return 0.0;
168  } );
169 }
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:1065
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition: board_item.h:195
#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:1070
void ReportError(const wxString &aErrorMsg)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
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:914
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:148

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( wxT( "Attempting to call fromTo() with non-existent from-to cache, "
63  "aborting..." ));
64  return true;
65  }
66 
67  if( ftCache->IsOnFromToPath( static_cast<BOARD_CONNECTED_ITEM*>( item ),
68  argFrom->AsString(), argTo->AsString() ) )
69  {
70  result->Set(1.0);
71  }
72 
73  return true;
74 }
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:345
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 810 of file pcb_expr_evaluator.cpp.

811 {
812  LIBEVAL::VALUE* argv = aCtx->Pop();
813  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
814  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
815  LIBEVAL::VALUE* result = aCtx->AllocValue();
816 
817  result->Set( 0.0 );
818  aCtx->Push( result );
819 
820  if( !argv )
821  {
822  if( aCtx->HasErrorCallback() )
823  {
824  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
825  wxT( "inDiffPair()" ) ) );
826  }
827 
828  return;
829  }
830 
831  if( !item || !item->GetBoard() )
832  return;
833 
834  result->SetDeferredEval(
835  [item, argv]() -> double
836  {
837  if( item && item->IsConnected() )
838  {
839  NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
840 
841  wxString refName = netinfo->GetNetname();
842  wxString arg = argv->AsString();
843  wxString baseName, coupledNet;
844  int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
845 
846  if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) )
847  {
848  if( baseName.Matches( arg ) )
849  return 1.0;
850 
851  if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) )
852  return 1.0;
853  }
854  }
855 
856  return 0.0;
857  } );
858 }
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1328
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:126
#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:66
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(), 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 594 of file pcb_expr_evaluator.cpp.

595 {
596  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
597  LIBEVAL::VALUE* arg = aCtx->Pop();
598  LIBEVAL::VALUE* result = aCtx->AllocValue();
599 
600  result->Set( 0.0 );
601  aCtx->Push( result );
602 
603  if( !arg )
604  {
605  if( aCtx->HasErrorCallback() )
606  {
607  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
608  wxT( "insideArea()" ) ) );
609  }
610 
611  return;
612  }
613 
614  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
615  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
616 
617  if( !item )
618  return;
619 
620  result->SetDeferredEval(
621  [item, arg, context]() -> double
622  {
623  BOARD* board = item->GetBoard();
624  EDA_RECT itemBBox;
625 
626  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
627  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
628  else
629  itemBBox = item->GetBoundingBox();
630 
631  if( arg->AsString() == wxT( "A" ) )
632  {
633  ZONE* zone = dynamic_cast<ZONE*>( context->GetItem( 0 ) );
634  return isInsideArea( item, itemBBox, context, zone ) ? 1.0 : 0.0;
635  }
636  else if( arg->AsString() == wxT( "B" ) )
637  {
638  ZONE* zone = dynamic_cast<ZONE*>( context->GetItem( 1 ) );
639  return isInsideArea( item, itemBBox, context, zone ) ? 1.0 : 0.0;
640  }
641  else if( KIID::SniffTest( arg->AsString() ) )
642  {
643  KIID target( arg->AsString());
644 
645  for( ZONE* area : board->Zones() )
646  {
647  // Only a single zone can match the UUID; exit once we find a match whether
648  // "inside" or not
649  if( area->m_Uuid == target )
650  return isInsideArea( item, itemBBox, context, area ) ? 1.0 : 0.0;
651  }
652 
653  for( FOOTPRINT* footprint : board->Footprints() )
654  {
655  for( ZONE* area : footprint->Zones() )
656  {
657  // Only a single zone can match the UUID; exit once we find a match
658  // whether "inside" or not
659  if( area->m_Uuid == target )
660  return isInsideArea( item, itemBBox, context, area ) ? 1.0 : 0.0;
661  }
662  }
663 
664  return 0.0;
665  }
666  else // Match on zone name
667  {
668  for( ZONE* area : board->Zones())
669  {
670  if( area->GetZoneName().Matches( arg->AsString() ) )
671  {
672  // Many zones can match the name; exit only when we find an "inside"
673  if( isInsideArea( item, itemBBox, context, area ) )
674  return 1.0;
675  }
676  }
677 
678  for( FOOTPRINT* footprint : board->Footprints() )
679  {
680  for( ZONE* area : footprint->Zones() )
681  {
682  // Many zones can match the name; exit only when we find an "inside"
683  if( area->GetZoneName().Matches( arg->AsString() ) )
684  {
685  if( isInsideArea( item, itemBBox, context, area ) )
686  return 1.0;
687  }
688  }
689  }
690 
691  return 0.0;
692  }
693  } );
694 }
BOARD_ITEM * GetItem(int index) const
ZONES & Zones()
Definition: board.h:240
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)
Returns true if a string has the correct formatting to be a KIID.
Definition: kiid.cpp:158
FOOTPRINTS & Footprints()
Definition: board.h:234
#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:191
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:112

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 374 of file pcb_expr_evaluator.cpp.

375 {
376  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
377  LIBEVAL::VALUE* arg = aCtx->Pop();
378  LIBEVAL::VALUE* result = aCtx->AllocValue();
379 
380  result->Set( 0.0 );
381  aCtx->Push( result );
382 
383  if( !arg )
384  {
385  if( aCtx->HasErrorCallback() )
386  {
387  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
388  wxT( "insideBackCourtyard()" ) ) );
389  }
390  return;
391  }
392 
393  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
394  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
395 
396  if( !item )
397  return;
398 
399  result->SetDeferredEval(
400  [item, arg, context]() -> double
401  {
402  BOARD* board = item->GetBoard();
403  EDA_RECT itemBBox;
404  std::shared_ptr<SHAPE> itemShape;
405 
406  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
407  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
408  else
409  itemBBox = item->GetBoundingBox();
410 
411  if( arg->AsString() == wxT( "A" ) )
412  {
413  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
414 
415  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
416  return 1.0;
417  }
418  else if( arg->AsString() == wxT( "B" ) )
419  {
420  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
421 
422  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
423  return 1.0;
424  }
425  else for( FOOTPRINT* fp : board->Footprints() )
426  {
427  if( fp->GetReference().Matches( arg->AsString() ) )
428  {
429  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, B_Cu ) )
430  return 1.0;
431  }
432  }
433 
434  return 0.0;
435  } );
436 }
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:234
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:191
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:112

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 242 of file pcb_expr_evaluator.cpp.

243 {
244  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
245  LIBEVAL::VALUE* arg = aCtx->Pop();
246  LIBEVAL::VALUE* result = aCtx->AllocValue();
247 
248  result->Set( 0.0 );
249  aCtx->Push( result );
250 
251  if( !arg )
252  {
253  if( aCtx->HasErrorCallback() )
254  {
255  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
256  wxT( "insideCourtyard()" ) ) );
257  }
258 
259  return;
260  }
261 
262  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
263  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
264 
265  if( !item )
266  return;
267 
268  result->SetDeferredEval(
269  [item, arg, context]() -> double
270  {
271  BOARD* board = item->GetBoard();
272  EDA_RECT itemBBox;
273  std::shared_ptr<SHAPE> itemShape;
274 
275  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
276  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
277  else
278  itemBBox = item->GetBoundingBox();
279 
280  if( arg->AsString() == wxT( "A" ) )
281  {
282  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
283 
284  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
285  return 1.0;
286  }
287  else if( arg->AsString() == wxT( "B" ) )
288  {
289  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
290 
291  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
292  return 1.0;
293  }
294  else for( FOOTPRINT* fp : board->Footprints() )
295  {
296  if( fp->GetReference().Matches( arg->AsString() ) )
297  {
298  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, In1_Cu ) )
299  return 1.0;
300  }
301  }
302 
303  return 0.0;
304  } );
305 }
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:234
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:191
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:112

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 308 of file pcb_expr_evaluator.cpp.

309 {
310  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
311  LIBEVAL::VALUE* arg = aCtx->Pop();
312  LIBEVAL::VALUE* result = aCtx->AllocValue();
313 
314  result->Set( 0.0 );
315  aCtx->Push( result );
316 
317  if( !arg )
318  {
319  if( aCtx->HasErrorCallback() )
320  {
321  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
322  wxT( "insideFrontCourtyard()" ) ) );
323  }
324 
325  return;
326  }
327 
328  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
329  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
330 
331  if( !item )
332  return;
333 
334  result->SetDeferredEval(
335  [item, arg, context]() -> double
336  {
337  BOARD* board = item->GetBoard();
338  EDA_RECT itemBBox;
339  std::shared_ptr<SHAPE> itemShape;
340 
341  if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
342  itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
343  else
344  itemBBox = item->GetBoundingBox();
345 
346  if( arg->AsString() == wxT( "A" ) )
347  {
348  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) );
349 
350  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
351  return 1.0;
352  }
353  else if( arg->AsString() == wxT( "B" ) )
354  {
355  FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) );
356 
357  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
358  return 1.0;
359  }
360  else for( FOOTPRINT* fp : board->Footprints() )
361  {
362  if( fp->GetReference().Matches( arg->AsString() ) )
363  {
364  if( isInsideCourtyard( item, itemBBox, itemShape, context, fp, F_Cu ) )
365  return 1.0;
366  }
367  }
368 
369  return 0.0;
370  } );
371 }
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:234
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:191
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:112

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 758 of file pcb_expr_evaluator.cpp.

759 {
760  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
761  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
762  LIBEVAL::VALUE* result = aCtx->AllocValue();
763 
764  result->Set( 0.0 );
765  aCtx->Push( result );
766 
767  PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
768 
769  if( via && via->GetViaType() == VIATYPE::BLIND_BURIED )
770  result->Set ( 1.0 );
771 }
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 774 of file pcb_expr_evaluator.cpp.

775 {
776  PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
777  BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
778  BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
779  LIBEVAL::VALUE* result = aCtx->AllocValue();
780 
781  result->Set( 0.0 );
782  aCtx->Push( result );
783 
784  result->SetDeferredEval(
785  [a, b, context]() -> double
786  {
787  NETINFO_ITEM* netinfo = a ? a->GetNet() : nullptr;
788 
789  if( !netinfo )
790  return 0.0;
791 
792  wxString coupledNet;
793  wxString dummy;
794 
795  if( !DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) )
796  return 0.0;
797 
800  {
801  // DRC engine evaluates these singly, so we won't have a B item
802  return 1.0;
803  }
804 
805  return b && b->GetNetname() == coupledNet;
806  } );
807 }
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:126
Handle the data for a net.
Definition: netinfo.h:66
int GetConstraint() const
void Push(VALUE *v)
void Set(double aValue)

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

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 573 of file pcb_expr_evaluator.cpp.

575 {
576  if( !aArea || aArea == aItem || aArea->GetParent() == aItem )
577  return false;
578 
579  BOARD* board = aArea->GetBoard();
580  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
581  std::pair<BOARD_ITEM*, BOARD_ITEM*> key( aArea, aItem );
582  auto i = board->m_InsideAreaCache.find( key );
583 
584  if( i != board->m_InsideAreaCache.end() )
585  return i->second;
586 
587  bool isInside = calcIsInsideArea( aItem, aItemBBox, aCtx, aArea );
588 
589  board->m_InsideAreaCache[ key ] = isInside;
590  return isInside;
591 }
bool calcIsInsideArea(BOARD_ITEM *aItem, const EDA_RECT &aItemBBox, PCB_EXPR_CONTEXT *aCtx, ZONE *aArea)
std::mutex m_CachesMutex
Definition: board.h:1065
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
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:136
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideAreaCache
Definition: board.h:1069

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 210 of file pcb_expr_evaluator.cpp.

213 {
214  if( !aFootprint )
215  return false;
216 
217  BOARD* board = aItem->GetBoard();
218  std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
219  std::pair<BOARD_ITEM*, BOARD_ITEM*> key( aFootprint, aItem );
220 
221  std::map< std::pair<BOARD_ITEM*, BOARD_ITEM*>, bool >* cache;
222 
223  switch( aSide )
224  {
225  case F_Cu: cache = &board->m_InsideFCourtyardCache; break;
226  case B_Cu: cache = &board->m_InsideBCourtyardCache; break;
227  default: cache = &board->m_InsideCourtyardCache; break;
228  }
229 
230  auto i = cache->find( key );
231 
232  if( i != cache->end() )
233  return i->second;
234 
235  bool res = calcIsInsideCourtyard( aItem, aItemBBox, aItemShape, aCtx, aFootprint, aSide );
236 
237  (*cache)[ key ] = res;
238  return res;
239 };
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideCourtyardCache
Definition: board.h:1066
std::mutex m_CachesMutex
Definition: board.h:1065
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:191
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:1068
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideFCourtyardCache
Definition: board.h:1067

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 742 of file pcb_expr_evaluator.cpp.

743 {
744  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
745  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
746  LIBEVAL::VALUE* result = aCtx->AllocValue();
747 
748  result->Set( 0.0 );
749  aCtx->Push( result );
750 
751  PCB_VIA* via = dyn_cast<PCB_VIA*>( item );
752 
753  if( via && via->GetViaType() == VIATYPE::MICROVIA )
754  result->Set ( 1.0 );
755 }
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 172 of file pcb_expr_evaluator.cpp.

173 {
174  LIBEVAL::VALUE* result = aCtx->AllocValue();
175 
176  result->Set( 0.0 );
177  aCtx->Push( result );
178 
179  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_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 }
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:112

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 PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions().

◆ memberOf()

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

Definition at line 697 of file pcb_expr_evaluator.cpp.

698 {
699  LIBEVAL::VALUE* arg = aCtx->Pop();
700  LIBEVAL::VALUE* result = aCtx->AllocValue();
701 
702  result->Set( 0.0 );
703  aCtx->Push( result );
704 
705  if( !arg )
706  {
707  if( aCtx->HasErrorCallback() )
708  {
709  aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
710  wxT( "memberOf()" ) ) );
711  }
712  return;
713  }
714 
715  PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
716  BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
717 
718  if( !item )
719  return;
720 
721  result->SetDeferredEval(
722  [item, arg]() -> double
723  {
724  PCB_GROUP* group = item->GetParentGroup();
725 
726  if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
727  group = item->GetParent()->GetParentGroup();
728 
729  while( group )
730  {
731  if( group->GetName().Matches( arg->AsString() ) )
732  return 1.0;
733 
734  group = group->GetParentGroup();
735  }
736 
737  return 0.0;
738  } );
739 }
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:136
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:112

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().