58 wxLogWarning(
"Attempting to call fromTo() with non-existent from-to cache, aborting...");
62 if( ftCache->IsOnFromToPath( static_cast<BOARD_CONNECTED_ITEM*>( item ),
89 wxT(
"existsOnLayer()" ) ) );
93 wxString layerName = arg->
AsString();
95 bool anyMatch =
false;
97 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
99 wxPGChoiceEntry& entry = layerMap[ii];
101 if( entry.GetText().Matches( layerName ) )
123 aCtx->
Push( result );
145 aCtx->
Push( result );
150 wxT(
"insideCourtyard()" ) ) );
162 std::shared_ptr<SHAPE> shape;
165 itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
169 auto realInsideFootprint =
174 if( footprint->IsFlipped() )
175 footprintCourtyard = footprint->GetPolyCourtyardBack();
177 footprintCourtyard = footprint->GetPolyCourtyardFront();
182 if( !footprint->GetBoundingBox().Contains( itemBBox ) )
187 if( !footprint->GetBoundingBox().Intersects( itemBBox ) )
194 return footprintCourtyard.
Collide( shape.get() );
197 auto insideFootprint =
203 std::unique_lock<std::mutex> cacheLock( board->
m_CachesMutex );
204 std::pair<BOARD_ITEM*, BOARD_ITEM*> key( footprint, item );
210 bool isInside = realInsideFootprint( footprint );
218 if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->
GetItem( 0 ) ) ) )
223 if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->
GetItem( 1 ) ) ) )
230 if( candidate->GetReference().Matches( arg->
AsString() ) )
232 if( insideFootprint( candidate ) )
250 aCtx->
Push( result );
255 wxT(
"insideArea()" ) ) );
267 std::shared_ptr<SHAPE> shape;
270 itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
274 auto realInsideZone =
275 [&](
ZONE* zone ) ->
bool 277 if( !zone->GetCachedBoundingBox().Intersects( itemBBox ) )
290 PAD* pad = static_cast<PAD*>( item );
293 return zoneOutline.
Collide( holeShape );
297 VIA* via = static_cast<VIA*>( item );
300 return zoneOutline.
Collide( &holeShape );
308 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
312 aCtx->
ReportError(
_(
"Footprint's courtyard is not a single, closed shape." ) );
322 aCtx->
ReportError(
_(
"Footprint has no front courtyard." ) );
337 aCtx->
ReportError(
_(
"Footprint has no back courtyard." ) );
351 ZONE* itemZone = static_cast<ZONE*>( item );
360 if( itemRTree->
QueryColliding( zone->GetCachedBoundingBox(), &zoneOutline,
361 layer, 0,
nullptr, nullptr ) )
374 return zoneOutline.
Collide( shape.get() );
379 [&](
ZONE* zone ) ->
bool 381 if( !zone || zone == item || zone->
GetParent() == item )
384 std::unique_lock<std::mutex> cacheLock( board->
m_CachesMutex );
385 std::pair<BOARD_ITEM*, BOARD_ITEM*> key( zone, item );
391 bool isInside = realInsideZone( zone );
399 if( insideZone( dynamic_cast<ZONE*>( context->
GetItem( 0 ) ) ) )
404 if( insideZone( dynamic_cast<ZONE*>( context->
GetItem( 1 ) ) ) )
415 if( candidate->m_Uuid == target )
417 if( insideZone( candidate ) )
426 for(
ZONE* candidate : footprint->Zones() )
430 if( candidate->m_Uuid == target )
432 if( insideZone( candidate ) )
444 if( candidate->GetZoneName().Matches( arg->
AsString() ) )
447 if( insideZone( candidate ) )
457 for(
ZONE* candidate : footprint->Zones() )
460 if( candidate->GetZoneName().Matches( arg->
AsString() ) )
462 if( insideZone( candidate ) )
480 aCtx->
Push( result );
485 wxT(
"memberOf()" ) ) );
520 aCtx->
Push( result );
522 auto via = dyn_cast<VIA*>( item );
538 aCtx->
Push( result );
540 auto via = dyn_cast<VIA*>( item );
556 aCtx->
Push( result );
560 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
561 int dummy_p, dummy_n;
577 aCtx->
Push( result );
582 wxT(
"inDiffPair()" ) ) );
588 NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
591 wxString baseName, coupledNet;
598 if( baseName.Matches( arg->
AsString() ) )
628 wxASSERT( dynamic_cast<const PCB_EXPR_CONTEXT*>( aCtx ) );
652 for(
unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
654 wxPGChoiceEntry& entry = layerMap[ii];
656 if( entry.GetValue() == layerId && entry.GetText().Matches( b->AsString() ) )
698 str = item->
Get<wxString>( it->second );
702 const wxAny& any = item->
Get( it->second );
703 any.GetAs<wxString>( &str );
706 if( str ==
"UNDEFINED" )
723 return LIBEVAL::VALUE( static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNetClassName() );
737 return LIBEVAL::VALUE( static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNetname() );
747 return registry.
Get( aName.Lower() );
752 const wxString& aField )
755 std::unique_ptr<PCB_EXPR_VAR_REF> vref;
759 if( aField.CmpNoCase(
"NetClass" ) == 0 )
762 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 0 );
763 else if( aVar ==
"B" )
764 return std::make_unique<PCB_EXPR_NETCLASS_REF>( 1 );
768 else if( aField.CmpNoCase(
"NetName" ) == 0 )
771 return std::make_unique<PCB_EXPR_NETNAME_REF>( 0 );
772 else if( aVar ==
"B" )
773 return std::make_unique<PCB_EXPR_NETNAME_REF>( 1 );
779 vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
780 else if( aVar ==
"B" )
781 vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
782 else if( aVar ==
"L" )
783 vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 );
787 if( aField.length() == 0 )
789 return std::move( vref );
792 wxString field( aField );
793 field.Replace(
"_",
" " );
803 vref->AddAllowedClass( cls.type, prop );
816 vref->SetIsEnum (
true );
820 wxFAIL_MSG(
"PCB_EXPR_UCODE::createVarRef: Unknown property type." );
829 return std::move( vref );
842 static const std::vector<wxString> pcbUnits = {
"mil",
"mm",
"in" };
849 return _(
"must be mm, in, or mil" );
852 virtual double Convert(
const wxString& aString,
int unitId )
const override 854 double v = wxAtof( aString );
PCB_GROUP * GetParentGroup() const
BOARD_ITEM * GetItem(int index) const
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
static PROPERTY_MANAGER & Instance()
int OutlineCount() const
Return the number of vertices in a given outline/hole.
std::unique_ptr< UNIT_RESOLVER > m_unitResolver
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideCourtyardCache
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual LIBEVAL::FUNC_CALL_REF CreateFuncCall(const wxString &aName) override
static bool IsNetADiffPair(BOARD *aBoard, NETINFO_ITEM *aNet, int &aNetP, int &aNetN)
A set of BOARD_ITEMs (i.e., without duplicates).
virtual ~PCB_UNIT_RESOLVER()
void RegisterFunc(const wxString &funcSignature, LIBEVAL::FUNC_CALL_REF funcPtr)
static void isDiffPair(LIBEVAL::CONTEXT *aCtx, void *self)
LIBEVAL::FUNC_CALL_REF Get(const wxString &name)
virtual size_t TypeHash() const =0
Return type-id of the property type.
static ENUM_MAP< T > & Instance()
static void isPlated(LIBEVAL::CONTEXT *aCtx, void *self)
bool exprFromTo(LIBEVAL::CONTEXT *aCtx, void *self)
const SHAPE_SEGMENT * GetEffectiveHoleShape() const
Return a SHAPE object representing the pad's hole.
class PAD, a pad in a footprint
static void inDiffPair(LIBEVAL::CONTEXT *aCtx, void *self)
static int MatchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
Checks if the given net is a diff pair, returning its polarity and complement if so.
virtual wxString GetSupportedUnitsMessage() const override
static LSET FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
std::map< wxString, LIBEVAL::FUNC_CALL_REF > m_funcs
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
void RegisterAllFunctions()
PCB_LAYER_ID
A quick note on layer IDs:
PCB_EXPR_COMPILER m_compiler
VAR_TYPE_T GetType() const
std::function< void(CONTEXT *, void *)> FUNC_CALL_REF
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
static void isBlindBuriedVia(LIBEVAL::CONTEXT *aCtx, void *self)
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
LIBEVAL::VAR_TYPE_T m_type
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
static bool SniffTest(const wxString &aCandidate)
static void existsOnLayer(LIBEVAL::CONTEXT *aCtx, void *self)
FOOTPRINTS & Footprints()
wxAny Get(PROPERTY_BASE *aProperty)
virtual std::unique_ptr< LIBEVAL::VAR_REF > CreateVarRef(const wxString &aVar, const wxString &aField) override
virtual BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
void Deflate(int aAmount, int aCircleSegmentsCount, CORNER_STRATEGY aCornerStrategy=ROUND_ALL_CORNERS)
const wxString & GetNetname() const
#define MALFORMED_COURTYARDS
ZONE handles a list of polygons defining a copper zone.
class ZONE, a copper pour area
PCB_LAYER_VALUE(PCB_LAYER_ID aLayer)
static void insideArea(LIBEVAL::CONTEXT *aCtx, void *self)
class FOOTPRINT, a footprint
LIBEVAL::VALUE GetValue(LIBEVAL::CONTEXT *aCtx) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define HOLE_PROXY
Indicates the BOARD_ITEM is a proxy for its hole.
PCB_EXPR_BUILTIN_FUNCTIONS()
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,...
virtual LIBEVAL::VALUE GetValue(LIBEVAL::CONTEXT *aCtx) override
void ReportError(const wxString &aErrorMsg)
Handle the data for a net.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
virtual double AsDouble() const
Information pertinent to a Pcbnew printed circuit board.
static void memberOf(LIBEVAL::CONTEXT *aCtx, void *self)
virtual const wxString & AsString() const
class ZONE, managed by a footprint
static void insideCourtyard(LIBEVAL::CONTEXT *aCtx, void *self)
Handle the component boundary box.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
bool Evaluate(const wxString &aExpr)
static void isMicroVia(LIBEVAL::CONTEXT *aCtx, void *self)
virtual double Convert(const wxString &aString, int unitId) const override
static LSET BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
std::map< ZONE *, std::unique_ptr< DRC_RTREE > > m_CopperZoneRTrees
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.
virtual const std::vector< wxString > & GetSupportedUnits() const override
CLASSES_INFO GetAllClasses()
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Provide class metadata.Helper macro to map type hashes to names.
virtual bool EqualTo(const VALUE *b) const override
class VIA, a via (like a track segment on a copper layer)
VALUE * Run(CONTEXT *ctx)
virtual const EDA_RECT GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
double DoubleValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function DoubleValueFromString converts aTextValue to a double.
DRC_RTREE - Implements an R-tree for fast spatial and layer indexing of connectable items.
wxPoint GetPosition() const override
STATUS_FLAGS GetFlags() const
BOARD_ITEM_CONTAINER * GetParent() const
LIBEVAL::VALUE GetValue(LIBEVAL::CONTEXT *aCtx) override
static constexpr int Millimeter2iu(double mm)
std::map< std::pair< BOARD_ITEM *, BOARD_ITEM * >, bool > m_InsideAreaCache
PCB_LAYER_ID ToLAYER_ID(int aLayer)
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
PCB_LAYER_ID GetLayer() const
std::unordered_map< TYPE_ID, PROPERTY_BASE * > m_matchingTypes
KICAD_T Type() const
Returns the type of object.
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.
static PCB_EXPR_BUILTIN_FUNCTIONS & Instance()