KiCad PCB EDA Suite
PCB_EXPR_VAR_REF Class Reference

#include <pcb_expr_evaluator.h>

Inheritance diagram for PCB_EXPR_VAR_REF:
LIBEVAL::VAR_REF PCB_EXPR_NETCLASS_REF PCB_EXPR_NETNAME_REF PCB_EXPR_TYPE_REF

Public Member Functions

 PCB_EXPR_VAR_REF (int aItemIndex)
 
 ~PCB_EXPR_VAR_REF ()
 
void SetIsEnum (bool s)
 
bool IsEnum () const
 
void SetType (LIBEVAL::VAR_TYPE_T type)
 
LIBEVAL::VAR_TYPE_T GetType () const override
 
void AddAllowedClass (TYPE_ID type_hash, PROPERTY_BASE *prop)
 
LIBEVAL::VALUEGetValue (LIBEVAL::CONTEXT *aCtx) override
 
BOARD_ITEMGetObject (const LIBEVAL::CONTEXT *aCtx) const
 

Private Attributes

std::unordered_map< TYPE_ID, PROPERTY_BASE * > m_matchingTypes
 
int m_itemIndex
 
LIBEVAL::VAR_TYPE_T m_type
 
bool m_isEnum
 

Detailed Description

Definition at line 82 of file pcb_expr_evaluator.h.

Constructor & Destructor Documentation

◆ PCB_EXPR_VAR_REF()

PCB_EXPR_VAR_REF::PCB_EXPR_VAR_REF ( int  aItemIndex)
inline

Definition at line 85 of file pcb_expr_evaluator.h.

85 :
86 m_itemIndex( aItemIndex ),
88 m_isEnum( false )
89 {
90 //printf("*** CreateVarRef %p %d\n", this, aItemIndex );
91 }
LIBEVAL::VAR_TYPE_T m_type

◆ ~PCB_EXPR_VAR_REF()

PCB_EXPR_VAR_REF::~PCB_EXPR_VAR_REF ( )
inline

Definition at line 93 of file pcb_expr_evaluator.h.

93{};

Member Function Documentation

◆ AddAllowedClass()

void PCB_EXPR_VAR_REF::AddAllowedClass ( TYPE_ID  type_hash,
PROPERTY_BASE prop 
)
inline

Definition at line 101 of file pcb_expr_evaluator.h.

102 {
103 m_matchingTypes[type_hash] = prop;
104 }
std::unordered_map< TYPE_ID, PROPERTY_BASE * > m_matchingTypes

References m_matchingTypes.

◆ GetObject()

BOARD_ITEM * PCB_EXPR_VAR_REF::GetObject ( const LIBEVAL::CONTEXT aCtx) const

Definition at line 36 of file pcb_expr_evaluator.cpp.

37{
38 wxASSERT( dynamic_cast<const PCB_EXPR_CONTEXT*>( aCtx ) );
39
40 const PCB_EXPR_CONTEXT* ctx = static_cast<const PCB_EXPR_CONTEXT*>( aCtx );
41 BOARD_ITEM* item = ctx->GetItem( m_itemIndex );
42 return item;
43}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:70
BOARD_ITEM * GetItem(int index) const

References PCB_EXPR_CONTEXT::GetItem(), and m_itemIndex.

Referenced by enclosedByAreaFunc(), existsOnLayerFunc(), fromToFunc(), getFieldFunc(), GetValue(), PCB_EXPR_NETCLASS_REF::GetValue(), PCB_EXPR_NETNAME_REF::GetValue(), PCB_EXPR_TYPE_REF::GetValue(), inDiffPairFunc(), intersectsAreaFunc(), intersectsBackCourtyardFunc(), intersectsCourtyardFunc(), intersectsFrontCourtyardFunc(), isBlindBuriedViaFunc(), isMicroVia(), isPlatedFunc(), and memberOfFunc().

◆ GetType()

LIBEVAL::VAR_TYPE_T PCB_EXPR_VAR_REF::GetType ( ) const
inlineoverridevirtual

Implements LIBEVAL::VAR_REF.

Definition at line 99 of file pcb_expr_evaluator.h.

99{ return m_type; }

References m_type.

◆ GetValue()

LIBEVAL::VALUE * PCB_EXPR_VAR_REF::GetValue ( LIBEVAL::CONTEXT aCtx)
overridevirtual

Implements LIBEVAL::VAR_REF.

Reimplemented in PCB_EXPR_NETCLASS_REF, PCB_EXPR_NETNAME_REF, and PCB_EXPR_TYPE_REF.

Definition at line 92 of file pcb_expr_evaluator.cpp.

93{
94 PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
95
96 if( m_itemIndex == 2 )
97 return new PCB_LAYER_VALUE( context->GetLayer() );
98
99 BOARD_ITEM* item = GetObject( aCtx );
100
101 if( !item )
102 return new LIBEVAL::VALUE();
103
104 auto it = m_matchingTypes.find( TYPE_HASH( *item ) );
105
106 if( it == m_matchingTypes.end() )
107 {
108 // Don't force user to type "A.Type == 'via' && A.Via_Type == 'buried'" when the
109 // simpler "A.Via_Type == 'buried'" is perfectly clear. Instead, return an undefined
110 // value when the property doesn't appear on a particular object.
111
112 return new LIBEVAL::VALUE();
113 }
114 else
115 {
117 return new LIBEVAL::VALUE( (double) item->Get<int>( it->second ) );
118 else
119 {
120 wxString str;
121
122 if( !m_isEnum )
123 {
124 str = item->Get<wxString>( it->second );
125 return new LIBEVAL::VALUE( str );
126 }
127 else
128 {
129 const wxAny& any = item->Get( it->second );
130 bool valid = any.GetAs<wxString>( &str );
131
132 if( valid )
133 {
134 if( it->second->Name() == wxT( "Layer" ) )
135 return new PCB_LAYER_VALUE( context->GetBoard()->GetLayerID( str ) );
136 else
137 return new LIBEVAL::VALUE( str );
138 }
139 }
140
141 return new LIBEVAL::VALUE();
142 }
143 }
144}
const PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Return the ID of a layer.
Definition: board.cpp:454
wxAny Get(PROPERTY_BASE *aProperty) const
Definition: inspectable.h:84
BOARD * GetBoard() const
PCB_LAYER_ID GetLayer() const
BOARD_ITEM * GetObject(const LIBEVAL::CONTEXT *aCtx) const
#define TYPE_HASH(x)
Definition: property.h:63

References INSPECTABLE::Get(), PCB_EXPR_CONTEXT::GetBoard(), PCB_EXPR_CONTEXT::GetLayer(), BOARD::GetLayerID(), GetObject(), m_isEnum, m_itemIndex, m_matchingTypes, m_type, TYPE_HASH, and LIBEVAL::VT_NUMERIC.

◆ IsEnum()

bool PCB_EXPR_VAR_REF::IsEnum ( ) const
inline

Definition at line 96 of file pcb_expr_evaluator.h.

96{ return m_isEnum; }

References m_isEnum.

◆ SetIsEnum()

void PCB_EXPR_VAR_REF::SetIsEnum ( bool  s)
inline

Definition at line 95 of file pcb_expr_evaluator.h.

95{ m_isEnum = s; }

References m_isEnum.

◆ SetType()

void PCB_EXPR_VAR_REF::SetType ( LIBEVAL::VAR_TYPE_T  type)
inline

Member Data Documentation

◆ m_isEnum

bool PCB_EXPR_VAR_REF::m_isEnum
private

Definition at line 114 of file pcb_expr_evaluator.h.

Referenced by GetValue(), IsEnum(), and SetIsEnum().

◆ m_itemIndex

int PCB_EXPR_VAR_REF::m_itemIndex
private

Definition at line 112 of file pcb_expr_evaluator.h.

Referenced by GetObject(), and GetValue().

◆ m_matchingTypes

std::unordered_map<TYPE_ID, PROPERTY_BASE*> PCB_EXPR_VAR_REF::m_matchingTypes
private

Definition at line 111 of file pcb_expr_evaluator.h.

Referenced by AddAllowedClass(), and GetValue().

◆ m_type

LIBEVAL::VAR_TYPE_T PCB_EXPR_VAR_REF::m_type
private

Definition at line 113 of file pcb_expr_evaluator.h.

Referenced by GetType(), GetValue(), and SetType().


The documentation for this class was generated from the following files: