2020-07-03 18:36:33 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2025-01-01 13:30:11 -08:00
|
|
|
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
2020-07-03 18:36:33 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-06-14 01:22:08 +02:00
|
|
|
#include <cstdio>
|
2020-07-21 16:49:55 +01:00
|
|
|
#include <memory>
|
2024-03-06 19:24:50 +01:00
|
|
|
#include <mutex>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2024-10-24 20:11:35 +01:00
|
|
|
#include <footprint.h>
|
2024-07-08 20:58:47 -07:00
|
|
|
#include <lset.h>
|
2022-11-29 14:18:44 +00:00
|
|
|
#include <board_connected_item.h>
|
2023-08-21 15:26:03 +01:00
|
|
|
#include <pcbexpr_evaluator.h>
|
2020-10-08 23:59:40 +02:00
|
|
|
#include <drc/drc_engine.h>
|
2025-03-09 20:46:34 +00:00
|
|
|
#include <component_classes/component_class.h>
|
2020-09-25 20:26:58 +02:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Specialized Expression References
|
|
|
|
*/
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
BOARD_ITEM* PCBEXPR_VAR_REF::GetObject( const LIBEVAL::CONTEXT* aCtx ) const
|
2020-07-22 09:02:30 +02:00
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
wxASSERT( dynamic_cast<const PCBEXPR_CONTEXT*>( aCtx ) );
|
2020-08-12 16:26:10 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
const PCBEXPR_CONTEXT* ctx = static_cast<const PCBEXPR_CONTEXT*>( aCtx );
|
|
|
|
BOARD_ITEM* item = ctx->GetItem( m_itemIndex );
|
2020-06-16 21:49:09 +02:00
|
|
|
return item;
|
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
class PCBEXPR_LAYER_VALUE : public LIBEVAL::VALUE
|
2020-09-27 19:43:44 +01:00
|
|
|
{
|
|
|
|
public:
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_LAYER_VALUE( PCB_LAYER_ID aLayer ) :
|
2022-09-16 14:13:34 +01:00
|
|
|
LIBEVAL::VALUE( LayerName( aLayer ) ),
|
|
|
|
m_layer( aLayer )
|
2020-09-27 19:43:44 +01:00
|
|
|
{};
|
|
|
|
|
2021-08-16 10:53:27 +01:00
|
|
|
virtual bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
2020-09-27 19:43:44 +01:00
|
|
|
{
|
|
|
|
// For boards with user-defined layer names there will be 2 entries for each layer
|
|
|
|
// in the ENUM_MAP: one for the canonical layer name and one for the user layer name.
|
|
|
|
// We need to check against both.
|
|
|
|
|
2024-03-07 13:02:16 +00:00
|
|
|
wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
|
|
|
|
const wxString& layerName = b->AsString();
|
|
|
|
BOARD* board = static_cast<PCBEXPR_CONTEXT*>( aCtx )->GetBoard();
|
|
|
|
|
2020-09-27 19:43:44 +01:00
|
|
|
{
|
2024-03-07 13:02:16 +00:00
|
|
|
std::shared_lock<std::shared_mutex> readLock( board->m_CachesMutex );
|
2020-09-27 19:43:44 +01:00
|
|
|
|
2024-03-07 13:02:16 +00:00
|
|
|
auto i = board->m_LayerExpressionCache.find( layerName );
|
2021-08-16 10:53:27 +01:00
|
|
|
|
2024-03-07 13:02:16 +00:00
|
|
|
if( i != board->m_LayerExpressionCache.end() )
|
|
|
|
return i->second.Contains( m_layer );
|
2021-08-16 10:53:27 +01:00
|
|
|
}
|
2024-03-07 13:02:16 +00:00
|
|
|
|
|
|
|
LSET mask;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
|
2021-08-16 10:53:27 +01:00
|
|
|
{
|
2024-03-07 13:02:16 +00:00
|
|
|
wxPGChoiceEntry& entry = layerMap[ii];
|
|
|
|
|
|
|
|
if( entry.GetText().Matches( layerName ) )
|
|
|
|
mask.set( ToLAYER_ID( entry.GetValue() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_lock<std::shared_mutex> writeLock( board->m_CachesMutex );
|
|
|
|
board->m_LayerExpressionCache[ layerName ] = mask;
|
2020-09-27 19:43:44 +01:00
|
|
|
}
|
|
|
|
|
2022-09-16 14:13:34 +01:00
|
|
|
return mask.Contains( m_layer );
|
2020-09-27 19:43:44 +01:00
|
|
|
}
|
2022-09-16 14:13:34 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PCB_LAYER_ID m_layer;
|
2020-09-27 19:43:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-12-27 21:14:04 +00:00
|
|
|
class PCBEXPR_PINTYPE_VALUE : public LIBEVAL::VALUE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PCBEXPR_PINTYPE_VALUE( const wxString& aPinTypeName ) :
|
|
|
|
LIBEVAL::VALUE( aPinTypeName )
|
|
|
|
{};
|
|
|
|
|
|
|
|
bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
|
|
|
{
|
|
|
|
const wxString& thisStr = AsString();
|
|
|
|
const wxString& otherStr = b->AsString();
|
|
|
|
|
2025-01-06 20:04:10 +00:00
|
|
|
// Case insensitive
|
2023-12-27 21:14:04 +00:00
|
|
|
if( thisStr.IsSameAs( otherStr, false ) )
|
|
|
|
return true;
|
|
|
|
|
2025-01-06 20:04:10 +00:00
|
|
|
// Wildcards
|
|
|
|
if( thisStr.Matches( otherStr ) )
|
|
|
|
return true;
|
2023-12-27 21:14:04 +00:00
|
|
|
|
2025-01-06 20:04:10 +00:00
|
|
|
// Handle cases where the netlist token is different from the EEschema token
|
|
|
|
wxString altStr;
|
2023-12-27 21:14:04 +00:00
|
|
|
|
2025-01-06 20:04:10 +00:00
|
|
|
if( thisStr == wxT( "tri_state" ) )
|
|
|
|
altStr = wxT( "Tri-state" );
|
|
|
|
else if( thisStr == wxT( "power_in" ) )
|
|
|
|
altStr = wxT( "Power input" );
|
|
|
|
else if( thisStr == wxT( "power_out" ) )
|
|
|
|
altStr = wxT( "Power output" );
|
|
|
|
else if( thisStr == wxT( "no_connect" ) )
|
|
|
|
altStr = wxT( "Unconnected" );
|
|
|
|
|
|
|
|
if( !altStr.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Case insensitive
|
|
|
|
if( altStr.IsSameAs( otherStr, false ) )
|
|
|
|
return true;
|
2023-12-27 21:14:04 +00:00
|
|
|
|
2025-01-06 20:04:10 +00:00
|
|
|
// Wildcards
|
|
|
|
if( altStr.Matches( otherStr ) )
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-27 21:14:04 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
class PCBEXPR_NETCLASS_VALUE : public LIBEVAL::VALUE
|
2023-08-21 14:51:10 +01:00
|
|
|
{
|
|
|
|
public:
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_NETCLASS_VALUE( BOARD_CONNECTED_ITEM* aItem ) :
|
2023-08-21 14:51:10 +01:00
|
|
|
LIBEVAL::VALUE( wxEmptyString ),
|
|
|
|
m_item( aItem )
|
|
|
|
{};
|
|
|
|
|
|
|
|
const wxString& AsString() const override
|
|
|
|
{
|
2024-07-26 20:49:29 +00:00
|
|
|
const_cast<PCBEXPR_NETCLASS_VALUE*>( this )->Set(
|
2025-01-14 20:00:43 +00:00
|
|
|
m_item->GetEffectiveNetClass()->GetName() );
|
2023-08-21 14:51:10 +01:00
|
|
|
return LIBEVAL::VALUE::AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
if( const PCBEXPR_NETCLASS_VALUE* bValue = dynamic_cast<const PCBEXPR_NETCLASS_VALUE*>( b ) )
|
2025-01-06 19:50:38 +00:00
|
|
|
{
|
2024-07-26 20:49:29 +00:00
|
|
|
return *( m_item->GetEffectiveNetClass() )
|
|
|
|
== *( bValue->m_item->GetEffectiveNetClass() );
|
2025-01-06 19:50:38 +00:00
|
|
|
}
|
2025-03-05 19:54:04 +00:00
|
|
|
|
|
|
|
if( b->GetType() == LIBEVAL::VT_STRING )
|
2025-01-06 19:50:38 +00:00
|
|
|
{
|
2025-03-05 19:54:04 +00:00
|
|
|
if( m_item->GetEffectiveNetClass()->ContainsNetclassWithName( b->AsString() ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return m_item->GetEffectiveNetClass()->GetName() == b->AsString();
|
2025-01-06 19:50:38 +00:00
|
|
|
}
|
2025-03-05 19:54:04 +00:00
|
|
|
|
|
|
|
return LIBEVAL::VALUE::EqualTo( aCtx, b );
|
2023-08-21 14:51:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NotEqualTo( LIBEVAL::CONTEXT* aCtx, const LIBEVAL::VALUE* b ) const override
|
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
if( const PCBEXPR_NETCLASS_VALUE* bValue = dynamic_cast<const PCBEXPR_NETCLASS_VALUE*>( b ) )
|
2025-03-05 19:54:04 +00:00
|
|
|
{
|
|
|
|
return *( m_item->GetEffectiveNetClass() )
|
|
|
|
!= *( bValue->m_item->GetEffectiveNetClass() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b->GetType() == LIBEVAL::VT_STRING )
|
|
|
|
{
|
|
|
|
const bool isInConstituents =
|
|
|
|
m_item->GetEffectiveNetClass()->ContainsNetclassWithName( b->AsString() );
|
|
|
|
const bool isFullName = m_item->GetEffectiveNetClass()->GetName() == b->AsString();
|
|
|
|
|
|
|
|
return !isInConstituents && !isFullName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LIBEVAL::VALUE::NotEqualTo( aCtx, b );
|
2023-08-21 14:51:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BOARD_CONNECTED_ITEM* m_item;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
class PCBEXPR_COMPONENT_CLASS_VALUE : public LIBEVAL::VALUE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PCBEXPR_COMPONENT_CLASS_VALUE( BOARD_ITEM* aItem ) :
|
2024-10-24 20:11:35 +01:00
|
|
|
LIBEVAL::VALUE( wxEmptyString ), m_item( dynamic_cast<FOOTPRINT*>( aItem ) )
|
|
|
|
{};
|
2024-09-27 20:48:12 +01:00
|
|
|
|
|
|
|
const wxString& AsString() const override
|
|
|
|
{
|
2024-10-24 20:11:35 +01:00
|
|
|
if( !m_item )
|
|
|
|
return LIBEVAL::VALUE::AsString();
|
2024-09-27 20:48:12 +01:00
|
|
|
|
2024-10-24 20:11:35 +01:00
|
|
|
if( const COMPONENT_CLASS* compClass = m_item->GetComponentClass() )
|
2025-03-09 20:46:34 +00:00
|
|
|
const_cast<PCBEXPR_COMPONENT_CLASS_VALUE*>( this )->Set( compClass->GetName() );
|
2024-09-27 20:48:12 +01:00
|
|
|
|
|
|
|
return LIBEVAL::VALUE::AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
|
|
|
{
|
|
|
|
if( const PCBEXPR_COMPONENT_CLASS_VALUE* bValue =
|
|
|
|
dynamic_cast<const PCBEXPR_COMPONENT_CLASS_VALUE*>( b ) )
|
|
|
|
{
|
2024-10-24 20:11:35 +01:00
|
|
|
if( !m_item || !bValue->m_item )
|
|
|
|
return LIBEVAL::VALUE::EqualTo( aCtx, b );
|
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
const COMPONENT_CLASS* aClass = m_item->GetComponentClass();
|
|
|
|
const COMPONENT_CLASS* bClass = bValue->m_item->GetComponentClass();
|
|
|
|
|
2025-03-09 20:46:34 +00:00
|
|
|
return *aClass == *bClass;
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
2025-03-08 22:18:22 +00:00
|
|
|
|
|
|
|
if( b->GetType() == LIBEVAL::VT_STRING )
|
2024-09-27 20:48:12 +01:00
|
|
|
{
|
2025-03-08 22:18:22 +00:00
|
|
|
if( m_item->GetComponentClass()->ContainsClassName( b->AsString() ) )
|
|
|
|
return true;
|
|
|
|
|
2025-03-09 20:46:34 +00:00
|
|
|
return m_item->GetComponentClass()->GetName() == b->AsString();
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
2025-03-08 22:18:22 +00:00
|
|
|
|
|
|
|
return LIBEVAL::VALUE::EqualTo( aCtx, b );
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NotEqualTo( LIBEVAL::CONTEXT* aCtx, const LIBEVAL::VALUE* b ) const override
|
|
|
|
{
|
|
|
|
if( const PCBEXPR_COMPONENT_CLASS_VALUE* bValue =
|
|
|
|
dynamic_cast<const PCBEXPR_COMPONENT_CLASS_VALUE*>( b ) )
|
|
|
|
{
|
2024-10-24 20:11:35 +01:00
|
|
|
if( !m_item || !bValue->m_item )
|
2025-03-05 19:10:30 +00:00
|
|
|
return LIBEVAL::VALUE::NotEqualTo( aCtx, b );
|
2024-10-24 20:11:35 +01:00
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
const COMPONENT_CLASS* aClass = m_item->GetComponentClass();
|
|
|
|
const COMPONENT_CLASS* bClass = bValue->m_item->GetComponentClass();
|
|
|
|
|
2025-03-09 20:46:34 +00:00
|
|
|
return *aClass != *bClass;
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
2025-03-08 22:18:22 +00:00
|
|
|
|
|
|
|
if( b->GetType() == LIBEVAL::VT_STRING )
|
2024-09-27 20:48:12 +01:00
|
|
|
{
|
2025-03-08 22:18:22 +00:00
|
|
|
const bool isInConstituents =
|
|
|
|
m_item->GetComponentClass()->ContainsClassName( b->AsString() );
|
2025-03-09 20:46:34 +00:00
|
|
|
const bool isFullName = m_item->GetComponentClass()->GetName() == b->AsString();
|
2025-03-08 22:18:22 +00:00
|
|
|
|
|
|
|
return !isInConstituents && !isFullName;
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
2025-03-08 22:18:22 +00:00
|
|
|
|
|
|
|
return LIBEVAL::VALUE::NotEqualTo( aCtx, b );
|
2024-09-27 20:48:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2024-10-24 20:11:35 +01:00
|
|
|
FOOTPRINT* m_item;
|
2024-09-27 20:48:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
class PCBEXPR_NET_VALUE : public LIBEVAL::VALUE
|
2023-08-21 14:51:10 +01:00
|
|
|
{
|
|
|
|
public:
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_NET_VALUE( BOARD_CONNECTED_ITEM* aItem ) :
|
2023-08-21 14:51:10 +01:00
|
|
|
LIBEVAL::VALUE( wxEmptyString ),
|
|
|
|
m_item( aItem )
|
|
|
|
{};
|
|
|
|
|
|
|
|
const wxString& AsString() const override
|
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
const_cast<PCBEXPR_NET_VALUE*>( this )->Set( m_item->GetNetname() );
|
2023-08-21 14:51:10 +01:00
|
|
|
return LIBEVAL::VALUE::AsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
if( const PCBEXPR_NET_VALUE* bValue = dynamic_cast<const PCBEXPR_NET_VALUE*>( b ) )
|
2023-08-21 14:51:10 +01:00
|
|
|
return m_item->GetNetCode() == bValue->m_item->GetNetCode();
|
|
|
|
else
|
|
|
|
return LIBEVAL::VALUE::EqualTo( aCtx, b );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NotEqualTo( LIBEVAL::CONTEXT* aCtx, const LIBEVAL::VALUE* b ) const override
|
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
if( const PCBEXPR_NET_VALUE* bValue = dynamic_cast<const PCBEXPR_NET_VALUE*>( b ) )
|
2023-08-21 14:51:10 +01:00
|
|
|
return m_item->GetNetCode() != bValue->m_item->GetNetCode();
|
|
|
|
else
|
|
|
|
return LIBEVAL::VALUE::NotEqualTo( aCtx, b );
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BOARD_CONNECTED_ITEM* m_item;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
LIBEVAL::VALUE* PCBEXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2020-06-16 21:49:09 +02:00
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_CONTEXT* context = static_cast<PCBEXPR_CONTEXT*>( aCtx );
|
2022-09-16 14:13:34 +01:00
|
|
|
|
2024-12-02 16:29:41 -05:00
|
|
|
if( m_type == LIBEVAL::VT_NULL )
|
|
|
|
return LIBEVAL::VALUE::MakeNullValue();
|
|
|
|
|
2020-09-27 19:43:44 +01:00
|
|
|
if( m_itemIndex == 2 )
|
2023-08-21 15:26:03 +01:00
|
|
|
return new PCBEXPR_LAYER_VALUE( context->GetLayer() );
|
2020-09-27 19:43:44 +01:00
|
|
|
|
2021-01-02 22:25:28 +00:00
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-02 22:25:28 +00:00
|
|
|
|
|
|
|
auto it = m_matchingTypes.find( TYPE_HASH( *item ) );
|
2020-06-14 01:22:08 +02:00
|
|
|
|
|
|
|
if( it == m_matchingTypes.end() )
|
|
|
|
{
|
2020-07-23 11:35:05 +01:00
|
|
|
// Don't force user to type "A.Type == 'via' && A.Via_Type == 'buried'" when the
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 18:37:31 -04:00
|
|
|
// simpler "A.Via_Type == 'buried'" is perfectly clear. Instead, return an undefined
|
2020-07-23 11:35:05 +01:00
|
|
|
// value when the property doesn't appear on a particular object.
|
|
|
|
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2020-06-14 01:22:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_type == LIBEVAL::VT_NUMERIC )
|
2023-12-27 21:14:04 +00:00
|
|
|
{
|
2024-12-02 16:29:41 -05:00
|
|
|
if( m_isOptional )
|
|
|
|
{
|
|
|
|
auto val = item->Get<std::optional<int>>( it->second );
|
|
|
|
|
|
|
|
if( val.has_value() )
|
|
|
|
return new LIBEVAL::VALUE( static_cast<double>( val.value() ) );
|
|
|
|
|
|
|
|
return LIBEVAL::VALUE::MakeNullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new LIBEVAL::VALUE( static_cast<double>( item->Get<int>( it->second ) ) );
|
2023-12-27 21:14:04 +00:00
|
|
|
}
|
2025-03-06 14:02:37 +00:00
|
|
|
else if( m_type == LIBEVAL::VT_NUMERIC_DOUBLE )
|
|
|
|
{
|
|
|
|
if( m_isOptional )
|
|
|
|
{
|
|
|
|
auto val = item->Get<std::optional<double>>( it->second );
|
|
|
|
|
|
|
|
if( val.has_value() )
|
|
|
|
return new LIBEVAL::VALUE( val.value() );
|
|
|
|
|
|
|
|
return LIBEVAL::VALUE::MakeNullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new LIBEVAL::VALUE( item->Get<double>( it->second ) );
|
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
else
|
|
|
|
{
|
2020-06-16 21:49:09 +02:00
|
|
|
wxString str;
|
2020-07-23 11:35:05 +01:00
|
|
|
|
2020-06-16 21:49:09 +02:00
|
|
|
if( !m_isEnum )
|
|
|
|
{
|
2020-08-18 13:34:48 -04:00
|
|
|
str = item->Get<wxString>( it->second );
|
2023-12-27 21:14:04 +00:00
|
|
|
|
|
|
|
if( it->second->Name() == wxT( "Pin Type" ) )
|
|
|
|
return new PCBEXPR_PINTYPE_VALUE( str );
|
|
|
|
else
|
|
|
|
return new LIBEVAL::VALUE( str );
|
2020-07-19 22:22:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 11:35:05 +01:00
|
|
|
const wxAny& any = item->Get( it->second );
|
2023-04-29 20:51:32 +01:00
|
|
|
PCB_LAYER_ID layer;
|
2021-05-03 14:04:15 +02:00
|
|
|
|
2023-10-06 21:55:47 +01:00
|
|
|
if( it->second->Name() == wxT( "Layer" )
|
|
|
|
|| it->second->Name() == wxT( "Layer Top" )
|
|
|
|
|| it->second->Name() == wxT( "Layer Bottom" ) )
|
2022-09-16 14:13:34 +01:00
|
|
|
{
|
2023-04-29 20:51:32 +01:00
|
|
|
if( any.GetAs<PCB_LAYER_ID>( &layer ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return new PCBEXPR_LAYER_VALUE( layer );
|
2023-04-29 20:51:32 +01:00
|
|
|
else if( any.GetAs<wxString>( &str ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return new PCBEXPR_LAYER_VALUE( context->GetBoard()->GetLayerID( str ) );
|
2023-04-29 20:51:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( any.GetAs<wxString>( &str ) )
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE( str );
|
|
|
|
}
|
2020-06-16 21:49:09 +02:00
|
|
|
}
|
2020-07-23 11:35:05 +01:00
|
|
|
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2020-06-14 01:22:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
LIBEVAL::VALUE* PCBEXPR_NETCLASS_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-08-14 12:03:18 +01:00
|
|
|
BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( GetObject( aCtx ) );
|
2021-01-11 22:08:07 +00:00
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-11 22:08:07 +00:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
return new PCBEXPR_NETCLASS_VALUE( item );
|
2021-01-11 22:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-09-27 20:48:12 +01:00
|
|
|
LIBEVAL::VALUE* PCBEXPR_COMPONENT_CLASS_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( GetObject( aCtx ) );
|
|
|
|
|
|
|
|
if( !item || item->Type() != PCB_FOOTPRINT_T )
|
|
|
|
return new LIBEVAL::VALUE();
|
|
|
|
|
|
|
|
return new PCBEXPR_COMPONENT_CLASS_VALUE( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
LIBEVAL::VALUE* PCBEXPR_NETNAME_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-08-14 12:03:18 +01:00
|
|
|
BOARD_CONNECTED_ITEM* item = dynamic_cast<BOARD_CONNECTED_ITEM*>( GetObject( aCtx ) );
|
2021-01-11 22:08:07 +00:00
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-11 22:08:07 +00:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
return new PCBEXPR_NET_VALUE( item );
|
2021-01-11 22:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
LIBEVAL::VALUE* PCBEXPR_TYPE_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-08-16 10:53:27 +01:00
|
|
|
{
|
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-08-16 10:53:27 +01:00
|
|
|
|
2022-09-16 14:13:34 +01:00
|
|
|
return new LIBEVAL::VALUE( ENUM_MAP<KICAD_T>::Instance().ToString( item->Type() ) );
|
2021-08-16 10:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
LIBEVAL::FUNC_CALL_REF PCBEXPR_UCODE::CreateFuncCall( const wxString& aName )
|
2020-06-16 21:49:09 +02:00
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_BUILTIN_FUNCTIONS& registry = PCBEXPR_BUILTIN_FUNCTIONS::Instance();
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2020-08-14 14:36:27 +02:00
|
|
|
return registry.Get( aName.Lower() );
|
2020-06-16 21:49:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
std::unique_ptr<LIBEVAL::VAR_REF> PCBEXPR_UCODE::CreateVarRef( const wxString& aVar,
|
2020-09-24 14:39:59 +01:00
|
|
|
const wxString& aField )
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2023-08-21 15:26:03 +01:00
|
|
|
std::unique_ptr<PCBEXPR_VAR_REF> vref;
|
2020-06-14 01:22:08 +02:00
|
|
|
|
2024-12-02 16:29:41 -05:00
|
|
|
if( aVar.IsSameAs( wxT( "null" ), false ) )
|
|
|
|
{
|
|
|
|
vref = std::make_unique<PCBEXPR_VAR_REF>( 0 );
|
|
|
|
vref->SetType( LIBEVAL::VT_NULL );
|
|
|
|
return vref;
|
|
|
|
}
|
|
|
|
|
2021-01-11 22:08:07 +00:00
|
|
|
// Check for a couple of very common cases and compile them straight to "object code".
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aField.CmpNoCase( wxT( "NetClass" ) ) == 0 )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aVar == wxT( "A" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_NETCLASS_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_NETCLASS_REF>( 1 );
|
2021-01-11 22:08:07 +00:00
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2024-09-27 20:48:12 +01:00
|
|
|
else if( aField.CmpNoCase( wxT( "ComponentClass" ) ) == 0 )
|
|
|
|
{
|
|
|
|
if( aVar == wxT( "A" ) )
|
|
|
|
return std::make_unique<PCBEXPR_COMPONENT_CLASS_REF>( 0 );
|
|
|
|
else if( aVar == wxT( "B" ) )
|
|
|
|
return std::make_unique<PCBEXPR_COMPONENT_CLASS_REF>( 1 );
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aField.CmpNoCase( wxT( "NetName" ) ) == 0 )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aVar == wxT( "A" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_NETNAME_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_NETNAME_REF>( 1 );
|
2021-01-11 22:08:07 +00:00
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aField.CmpNoCase( wxT( "Type" ) ) == 0 )
|
2021-08-16 10:53:27 +01:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aVar == wxT( "A" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_TYPE_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
return std::make_unique<PCBEXPR_TYPE_REF>( 1 );
|
2021-08-16 10:53:27 +01:00
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-01-11 22:08:07 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aVar == wxT( "A" ) || aVar == wxT( "AB" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
vref = std::make_unique<PCBEXPR_VAR_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
vref = std::make_unique<PCBEXPR_VAR_REF>( 1 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "L" ) )
|
2023-08-21 15:26:03 +01:00
|
|
|
vref = std::make_unique<PCBEXPR_VAR_REF>( 2 );
|
2020-07-19 22:22:49 +01:00
|
|
|
else
|
2020-08-11 15:33:16 +02:00
|
|
|
return nullptr;
|
2020-06-14 01:22:08 +02:00
|
|
|
|
2020-08-11 15:33:16 +02:00
|
|
|
if( aField.length() == 0 ) // return reference to base object
|
2023-12-19 22:38:34 -05:00
|
|
|
return vref;
|
2020-06-16 21:49:09 +02:00
|
|
|
|
2020-08-11 15:33:16 +02:00
|
|
|
wxString field( aField );
|
2022-02-04 22:44:59 +00:00
|
|
|
field.Replace( wxT( "_" ), wxT( " " ) );
|
2020-07-21 23:42:40 +01:00
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
|
|
|
if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
|
|
|
|
{
|
|
|
|
PROPERTY_BASE* prop = propMgr.GetProperty( cls.type, field );
|
2020-07-22 09:02:30 +02:00
|
|
|
|
2020-06-14 01:22:08 +02:00
|
|
|
if( prop )
|
|
|
|
{
|
|
|
|
vref->AddAllowedClass( cls.type, prop );
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2020-06-14 01:22:08 +02:00
|
|
|
if( prop->TypeHash() == TYPE_HASH( int ) )
|
2020-07-19 22:22:49 +01:00
|
|
|
{
|
2020-06-14 01:22:08 +02:00
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC );
|
2023-05-26 18:43:23 +01:00
|
|
|
}
|
2024-12-23 08:36:46 -08:00
|
|
|
else if( prop->TypeHash() == TYPE_HASH( std::optional<int> ) )
|
2024-12-02 16:29:41 -05:00
|
|
|
{
|
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC );
|
|
|
|
vref->SetIsOptional();
|
|
|
|
}
|
2025-03-06 14:02:37 +00:00
|
|
|
else if( prop->TypeHash() == TYPE_HASH( double ) )
|
|
|
|
{
|
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC_DOUBLE );
|
|
|
|
}
|
|
|
|
else if( prop->TypeHash() == TYPE_HASH( std::optional<double> ) )
|
|
|
|
{
|
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC_DOUBLE );
|
|
|
|
vref->SetIsOptional();
|
|
|
|
}
|
2023-05-26 18:43:23 +01:00
|
|
|
else if( prop->TypeHash() == TYPE_HASH( bool ) )
|
|
|
|
{
|
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC );
|
2020-07-19 22:22:49 +01:00
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
else if( prop->TypeHash() == TYPE_HASH( wxString ) )
|
2020-07-19 22:22:49 +01:00
|
|
|
{
|
2020-06-14 01:22:08 +02:00
|
|
|
vref->SetType( LIBEVAL::VT_STRING );
|
2020-07-19 22:22:49 +01:00
|
|
|
}
|
2020-06-16 21:49:09 +02:00
|
|
|
else if ( prop->HasChoices() )
|
|
|
|
{ // it's an enum, we treat it as string
|
|
|
|
vref->SetType( LIBEVAL::VT_STRING );
|
2024-12-02 16:29:41 -05:00
|
|
|
vref->SetIsEnum( true );
|
2020-06-16 21:49:09 +02:00
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
else
|
|
|
|
{
|
2025-01-06 19:50:38 +00:00
|
|
|
wxString msg = wxString::Format( wxT( "PCBEXPR_UCODE::createVarRef: Unknown "
|
|
|
|
"property type %s from %s." ),
|
|
|
|
cls.name,
|
|
|
|
field );
|
2024-12-23 08:36:46 -08:00
|
|
|
wxFAIL_MSG( msg );
|
2020-06-14 01:22:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
if( vref->GetType() == LIBEVAL::VT_UNDEFINED )
|
2020-07-30 12:24:29 +01:00
|
|
|
vref->SetType( LIBEVAL::VT_PARSE_ERROR );
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-12-19 22:38:34 -05:00
|
|
|
return vref;
|
2020-06-14 01:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
BOARD* PCBEXPR_CONTEXT::GetBoard() const
|
2021-08-16 10:53:27 +01:00
|
|
|
{
|
|
|
|
if( m_items[0] )
|
|
|
|
return m_items[0]->GetBoard();
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Unit Resolvers
|
|
|
|
*/
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
const std::vector<wxString>& PCBEXPR_UNIT_RESOLVER::GetSupportedUnits() const
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
2025-03-06 14:02:37 +00:00
|
|
|
static const std::vector<wxString> pcbUnits = { wxT( "mil" ), wxT( "mm" ), wxT( "in" ),
|
2025-02-10 20:57:51 +00:00
|
|
|
wxT( "deg" ), wxT( "fs" ), wxT( "ps" ) };
|
|
|
|
|
2020-06-14 01:22:08 +02:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
return pcbUnits;
|
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
wxString PCBEXPR_UNIT_RESOLVER::GetSupportedUnitsMessage() const
|
2022-11-29 14:18:44 +00:00
|
|
|
{
|
2025-02-10 20:57:51 +00:00
|
|
|
return _( "must be mm, in, mil, deg, fs, or ps" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<EDA_UNITS>& PCBEXPR_UNIT_RESOLVER::GetSupportedUnitsTypes() const
|
|
|
|
{
|
|
|
|
static const std::vector<EDA_UNITS> pcbUnits = { EDA_UNITS::MILS, EDA_UNITS::MM, EDA_UNITS::INCH,
|
|
|
|
EDA_UNITS::DEGREES, EDA_UNITS::FS, EDA_UNITS::PS };
|
|
|
|
|
|
|
|
return pcbUnits;
|
2022-11-29 14:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
double PCBEXPR_UNIT_RESOLVER::Convert( const wxString& aString, int unitId ) const
|
2022-11-29 14:18:44 +00:00
|
|
|
{
|
|
|
|
double v = wxAtof( aString );
|
|
|
|
|
|
|
|
switch( unitId )
|
2020-10-17 00:14:59 +01:00
|
|
|
{
|
2022-11-29 14:18:44 +00:00
|
|
|
case 0: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS, aString );
|
2025-03-01 20:24:37 +00:00
|
|
|
case 1: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MM, aString );
|
2025-03-02 11:34:30 +01:00
|
|
|
case 2: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::INCH, aString );
|
2025-02-10 20:57:51 +00:00
|
|
|
case 3: return v;
|
|
|
|
case 4: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::FS, aString );
|
|
|
|
case 5: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::PS, aString );
|
2022-11-29 14:18:44 +00:00
|
|
|
default: return v;
|
2020-10-17 00:14:59 +01:00
|
|
|
}
|
2022-11-29 14:18:44 +00:00
|
|
|
};
|
2020-10-17 00:14:59 +01:00
|
|
|
|
2020-07-19 22:22:49 +01:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
const std::vector<wxString>& PCBEXPR_UNITLESS_RESOLVER::GetSupportedUnits() const
|
2022-11-29 14:18:44 +00:00
|
|
|
{
|
|
|
|
static const std::vector<wxString> emptyUnits;
|
|
|
|
|
|
|
|
return emptyUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2025-02-10 20:57:51 +00:00
|
|
|
const std::vector<EDA_UNITS>& PCBEXPR_UNITLESS_RESOLVER::GetSupportedUnitsTypes() const
|
|
|
|
{
|
|
|
|
static const std::vector<EDA_UNITS> emptyUnits;
|
|
|
|
|
|
|
|
return emptyUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
double PCBEXPR_UNITLESS_RESOLVER::Convert( const wxString& aString, int unitId ) const
|
2022-11-29 14:18:44 +00:00
|
|
|
{
|
|
|
|
return wxAtof( aString );
|
2020-06-14 01:22:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_COMPILER::PCBEXPR_COMPILER( LIBEVAL::UNIT_RESOLVER* aUnitResolver )
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
2022-11-29 14:18:44 +00:00
|
|
|
m_unitResolver.reset( aUnitResolver );
|
2020-06-14 01:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* PCB Expression Evaluator
|
|
|
|
*/
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_EVALUATOR::PCBEXPR_EVALUATOR( LIBEVAL::UNIT_RESOLVER* aUnitResolver ) :
|
2021-05-30 19:47:57 -04:00
|
|
|
m_result( 0 ),
|
2025-05-01 15:38:50 +02:00
|
|
|
m_units( EDA_UNITS::MM ),
|
2022-11-29 14:18:44 +00:00
|
|
|
m_compiler( aUnitResolver ),
|
2021-05-30 19:47:57 -04:00
|
|
|
m_ucode(),
|
|
|
|
m_errorStatus()
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-30 19:47:57 -04:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_EVALUATOR::~PCBEXPR_EVALUATOR()
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
bool PCBEXPR_EVALUATOR::Evaluate( const wxString& aExpr )
|
2020-06-14 01:22:08 +02:00
|
|
|
{
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_UCODE ucode;
|
|
|
|
PCBEXPR_CONTEXT preflightContext( NULL_CONSTRAINT, F_Cu );
|
2020-07-21 16:49:55 +01:00
|
|
|
|
2020-10-15 16:58:35 +01:00
|
|
|
if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) )
|
|
|
|
return false;
|
2020-06-14 01:22:08 +02:00
|
|
|
|
2023-08-21 15:26:03 +01:00
|
|
|
PCBEXPR_CONTEXT evaluationContext( NULL_CONSTRAINT, F_Cu );
|
2020-07-30 12:24:29 +01:00
|
|
|
LIBEVAL::VALUE* result = ucode.Run( &evaluationContext );
|
2020-06-14 01:22:08 +02:00
|
|
|
|
|
|
|
if( result->GetType() == LIBEVAL::VT_NUMERIC )
|
2025-02-10 20:57:51 +00:00
|
|
|
{
|
2020-06-14 01:22:08 +02:00
|
|
|
m_result = KiROUND( result->AsDouble() );
|
2025-02-10 20:57:51 +00:00
|
|
|
m_units = result->GetUnits();
|
|
|
|
}
|
2020-06-14 01:22:08 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|