2020-07-03 16:36:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-02-04 22:44:59 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-07-03 16:36:33 +00: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-13 23:22:08 +00:00
|
|
|
#include <cstdio>
|
2020-07-21 15:49:55 +00:00
|
|
|
#include <memory>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2022-11-29 14:18:44 +00:00
|
|
|
#include <board_connected_item.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <pcb_expr_evaluator.h>
|
2020-10-08 21:59:40 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2020-09-25 18:26:58 +00:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Specialized Expression References
|
|
|
|
*/
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-10-27 11:03:35 +00:00
|
|
|
BOARD_ITEM* PCB_EXPR_VAR_REF::GetObject( const LIBEVAL::CONTEXT* aCtx ) const
|
2020-07-22 07:02:30 +00:00
|
|
|
{
|
2020-10-27 11:03:35 +00:00
|
|
|
wxASSERT( dynamic_cast<const PCB_EXPR_CONTEXT*>( aCtx ) );
|
2020-08-12 15:26:10 +00:00
|
|
|
|
2020-07-23 20:47:38 +00:00
|
|
|
const PCB_EXPR_CONTEXT* ctx = static_cast<const PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
BOARD_ITEM* item = ctx->GetItem( m_itemIndex );
|
2020-06-16 19:49:09 +00:00
|
|
|
return item;
|
|
|
|
}
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-09-27 18:43:44 +00:00
|
|
|
class PCB_LAYER_VALUE : public LIBEVAL::VALUE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PCB_LAYER_VALUE( PCB_LAYER_ID aLayer ) :
|
2022-09-16 13:13:34 +00:00
|
|
|
LIBEVAL::VALUE( LayerName( aLayer ) ),
|
|
|
|
m_layer( aLayer )
|
2020-09-27 18:43:44 +00:00
|
|
|
{};
|
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
virtual bool EqualTo( LIBEVAL::CONTEXT* aCtx, const VALUE* b ) const override
|
2020-09-27 18:43:44 +00: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.
|
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
|
|
|
|
const wxString& layerName = b->AsString();
|
|
|
|
BOARD* board = static_cast<PCB_EXPR_CONTEXT*>( aCtx )->GetBoard();
|
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
|
|
|
auto i = board->m_LayerExpressionCache.find( layerName );
|
|
|
|
LSET mask;
|
2020-09-27 18:43:44 +00:00
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
if( i == board->m_LayerExpressionCache.end() )
|
2020-09-27 18:43:44 +00:00
|
|
|
{
|
2021-08-16 09:53:27 +00:00
|
|
|
for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
wxPGChoiceEntry& entry = layerMap[ii];
|
2020-09-27 18:43:44 +00:00
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
if( entry.GetText().Matches( layerName ) )
|
|
|
|
mask.set( ToLAYER_ID( entry.GetValue() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
board->m_LayerExpressionCache[ layerName ] = mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mask = i->second;
|
2020-09-27 18:43:44 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return mask.Contains( m_layer );
|
2020-09-27 18:43:44 +00:00
|
|
|
}
|
2022-09-16 13:13:34 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PCB_LAYER_ID m_layer;
|
2020-09-27 18:43:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
LIBEVAL::VALUE* PCB_EXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2020-06-16 19:49:09 +00:00
|
|
|
{
|
2022-09-16 13:13:34 +00:00
|
|
|
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
|
2020-09-27 18:43:44 +00:00
|
|
|
if( m_itemIndex == 2 )
|
2022-09-16 13:13:34 +00:00
|
|
|
return new PCB_LAYER_VALUE( context->GetLayer() );
|
2020-09-27 18:43:44 +00:00
|
|
|
|
2021-01-02 22:25:28 +00:00
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-02 22:25:28 +00:00
|
|
|
|
|
|
|
auto it = m_matchingTypes.find( TYPE_HASH( *item ) );
|
2020-06-13 23:22:08 +00:00
|
|
|
|
|
|
|
if( it == m_matchingTypes.end() )
|
|
|
|
{
|
2020-07-23 10:35:05 +00: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 22:37:31 +00:00
|
|
|
// simpler "A.Via_Type == 'buried'" is perfectly clear. Instead, return an undefined
|
2020-07-23 10:35:05 +00:00
|
|
|
// value when the property doesn't appear on a particular object.
|
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_type == LIBEVAL::VT_NUMERIC )
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE( (double) item->Get<int>( it->second ) );
|
2020-06-13 23:22:08 +00:00
|
|
|
else
|
|
|
|
{
|
2020-06-16 19:49:09 +00:00
|
|
|
wxString str;
|
2020-07-23 10:35:05 +00:00
|
|
|
|
2020-06-16 19:49:09 +00:00
|
|
|
if( !m_isEnum )
|
|
|
|
{
|
2020-08-18 17:34:48 +00:00
|
|
|
str = item->Get<wxString>( it->second );
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE( str );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 10:35:05 +00:00
|
|
|
const wxAny& any = item->Get( it->second );
|
2021-05-03 12:04:15 +00:00
|
|
|
bool valid = any.GetAs<wxString>( &str );
|
|
|
|
|
|
|
|
if( valid )
|
2022-09-16 13:13:34 +00:00
|
|
|
{
|
|
|
|
if( it->second->Name() == wxT( "Layer" ) )
|
|
|
|
return new PCB_LAYER_VALUE( context->GetBoard()->GetLayerID( str ) );
|
|
|
|
else
|
|
|
|
return new LIBEVAL::VALUE( str );
|
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
2020-07-23 10:35:05 +00:00
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
LIBEVAL::VALUE* PCB_EXPR_NETCLASS_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00: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 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-11 22:08:07 +00:00
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE( item->GetEffectiveNetClass()->GetName() );
|
2021-01-11 22:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
LIBEVAL::VALUE* PCB_EXPR_NETNAME_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
2022-08-14 11:03:18 +00: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 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-01-11 22:08:07 +00:00
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE( item->GetNetname() );
|
2021-01-11 22:08:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
LIBEVAL::VALUE* PCB_EXPR_TYPE_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2021-08-16 09:53:27 +00:00
|
|
|
{
|
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE();
|
2021-08-16 09:53:27 +00:00
|
|
|
|
2022-09-16 13:13:34 +00:00
|
|
|
return new LIBEVAL::VALUE( ENUM_MAP<KICAD_T>::Instance().ToString( item->Type() ) );
|
2021-08-16 09:53:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
LIBEVAL::FUNC_CALL_REF PCB_EXPR_UCODE::CreateFuncCall( const wxString& aName )
|
2020-06-16 19:49:09 +00:00
|
|
|
{
|
2020-07-19 21:22:49 +00:00
|
|
|
PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance();
|
|
|
|
|
2020-08-14 12:36:27 +00:00
|
|
|
return registry.Get( aName.Lower() );
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-09-24 13:39:59 +00:00
|
|
|
std::unique_ptr<LIBEVAL::VAR_REF> PCB_EXPR_UCODE::CreateVarRef( const wxString& aVar,
|
|
|
|
const wxString& aField )
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
2020-09-27 18:43:44 +00:00
|
|
|
std::unique_ptr<PCB_EXPR_VAR_REF> vref;
|
2020-06-13 23:22:08 +00:00
|
|
|
|
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" ) )
|
2021-01-11 22:08:07 +00:00
|
|
|
return std::make_unique<PCB_EXPR_NETCLASS_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2021-01-11 22:08:07 +00:00
|
|
|
return std::make_unique<PCB_EXPR_NETCLASS_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" ) )
|
2021-01-11 22:08:07 +00:00
|
|
|
return std::make_unique<PCB_EXPR_NETNAME_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2021-01-11 22:08:07 +00:00
|
|
|
return std::make_unique<PCB_EXPR_NETNAME_REF>( 1 );
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aField.CmpNoCase( wxT( "Type" ) ) == 0 )
|
2021-08-16 09:53:27 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
if( aVar == wxT( "A" ) )
|
2021-08-16 09:53:27 +00:00
|
|
|
return std::make_unique<PCB_EXPR_TYPE_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2021-08-16 09:53:27 +00:00
|
|
|
return std::make_unique<PCB_EXPR_TYPE_REF>( 1 );
|
|
|
|
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" ) )
|
2020-10-26 23:49:11 +00:00
|
|
|
vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "B" ) )
|
2020-10-26 23:49:11 +00:00
|
|
|
vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
|
2022-02-04 22:44:59 +00:00
|
|
|
else if( aVar == wxT( "L" ) )
|
2020-10-26 23:49:11 +00:00
|
|
|
vref = std::make_unique<PCB_EXPR_VAR_REF>( 2 );
|
2020-07-19 21:22:49 +00:00
|
|
|
else
|
2020-08-11 13:33:16 +00:00
|
|
|
return nullptr;
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
if( aField.length() == 0 ) // return reference to base object
|
|
|
|
{
|
|
|
|
return std::move( vref );
|
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
wxString field( aField );
|
2022-02-04 22:44:59 +00:00
|
|
|
field.Replace( wxT( "_" ), wxT( " " ) );
|
2020-07-21 22:42:40 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
|
|
|
if( propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
|
|
|
|
{
|
|
|
|
PROPERTY_BASE* prop = propMgr.GetProperty( cls.type, field );
|
2020-07-22 07:02:30 +00:00
|
|
|
|
2020-06-13 23:22:08 +00:00
|
|
|
if( prop )
|
|
|
|
{
|
|
|
|
vref->AddAllowedClass( cls.type, prop );
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-06-13 23:22:08 +00:00
|
|
|
if( prop->TypeHash() == TYPE_HASH( int ) )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-06-13 23:22:08 +00:00
|
|
|
vref->SetType( LIBEVAL::VT_NUMERIC );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
2020-06-13 23:22:08 +00:00
|
|
|
else if( prop->TypeHash() == TYPE_HASH( wxString ) )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-06-13 23:22:08 +00:00
|
|
|
vref->SetType( LIBEVAL::VT_STRING );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
else if ( prop->HasChoices() )
|
|
|
|
{ // it's an enum, we treat it as string
|
|
|
|
vref->SetType( LIBEVAL::VT_STRING );
|
2020-09-23 21:50:06 +00:00
|
|
|
vref->SetIsEnum ( true );
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
2020-06-13 23:22:08 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxFAIL_MSG( wxT( "PCB_EXPR_UCODE::createVarRef: Unknown property type." ) );
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
if( vref->GetType() == LIBEVAL::VT_UNDEFINED )
|
2020-07-30 11:24:29 +00:00
|
|
|
vref->SetType( LIBEVAL::VT_PARSE_ERROR );
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
return std::move( vref );
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-16 09:53:27 +00:00
|
|
|
BOARD* PCB_EXPR_CONTEXT::GetBoard() const
|
|
|
|
{
|
|
|
|
if( m_items[0] )
|
|
|
|
return m_items[0]->GetBoard();
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Unit Resolvers
|
|
|
|
*/
|
|
|
|
|
|
|
|
const std::vector<wxString>& PCB_UNIT_RESOLVER::GetSupportedUnits() const
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2022-11-29 14:18:44 +00:00
|
|
|
static const std::vector<wxString> pcbUnits = { wxT( "mil" ), wxT( "mm" ), wxT( "in" ) };
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
return pcbUnits;
|
|
|
|
}
|
2020-06-13 23:22:08 +00:00
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
wxString PCB_UNIT_RESOLVER::GetSupportedUnitsMessage() const
|
|
|
|
{
|
|
|
|
return _( "must be mm, in, or mil" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PCB_UNIT_RESOLVER::Convert( const wxString& aString, int unitId ) const
|
|
|
|
{
|
|
|
|
double v = wxAtof( aString );
|
|
|
|
|
|
|
|
switch( unitId )
|
2020-10-16 23:14:59 +00:00
|
|
|
{
|
2022-11-29 14:18:44 +00:00
|
|
|
case 0: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILS, aString );
|
|
|
|
case 1: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILLIMETRES, aString );
|
|
|
|
case 2: return EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::INCHES, aString );
|
|
|
|
default: return v;
|
2020-10-16 23:14:59 +00:00
|
|
|
}
|
2022-11-29 14:18:44 +00:00
|
|
|
};
|
2020-10-16 23:14:59 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
const std::vector<wxString>& PCB_UNITLESS_RESOLVER::GetSupportedUnits() const
|
|
|
|
{
|
|
|
|
static const std::vector<wxString> emptyUnits;
|
|
|
|
|
|
|
|
return emptyUnits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double PCB_UNITLESS_RESOLVER::Convert( const wxString& aString, int unitId ) const
|
|
|
|
{
|
|
|
|
return wxAtof( aString );
|
2020-06-13 23:22:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
PCB_EXPR_COMPILER::PCB_EXPR_COMPILER( LIBEVAL::UNIT_RESOLVER* aUnitResolver )
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2022-11-29 14:18:44 +00:00
|
|
|
m_unitResolver.reset( aUnitResolver );
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* PCB Expression Evaluator
|
|
|
|
*/
|
|
|
|
|
|
|
|
PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR( LIBEVAL::UNIT_RESOLVER* aUnitResolver ) :
|
2021-05-30 23:47:57 +00:00
|
|
|
m_result( 0 ),
|
2022-11-29 14:18:44 +00:00
|
|
|
m_compiler( aUnitResolver ),
|
2021-05-30 23:47:57 +00:00
|
|
|
m_ucode(),
|
|
|
|
m_errorStatus()
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-30 23:47:57 +00:00
|
|
|
|
2020-06-13 23:22:08 +00:00
|
|
|
PCB_EXPR_EVALUATOR::~PCB_EXPR_EVALUATOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_EXPR_EVALUATOR::Evaluate( const wxString& aExpr )
|
|
|
|
{
|
2020-07-23 20:47:38 +00:00
|
|
|
PCB_EXPR_UCODE ucode;
|
2022-04-02 14:08:32 +00:00
|
|
|
PCB_EXPR_CONTEXT preflightContext( NULL_CONSTRAINT, F_Cu );
|
2020-07-21 15:49:55 +00:00
|
|
|
|
2020-10-15 15:58:35 +00:00
|
|
|
if( !m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ) )
|
|
|
|
return false;
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2022-04-02 14:08:32 +00:00
|
|
|
PCB_EXPR_CONTEXT evaluationContext( NULL_CONSTRAINT, F_Cu );
|
2020-07-30 11:24:29 +00:00
|
|
|
LIBEVAL::VALUE* result = ucode.Run( &evaluationContext );
|
2020-06-13 23:22:08 +00:00
|
|
|
|
|
|
|
if( result->GetType() == LIBEVAL::VT_NUMERIC )
|
|
|
|
m_result = KiROUND( result->AsDouble() );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|