2020-07-03 16:36:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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-07-30 11:24:29 +00:00
|
|
|
#include <reporter.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <pcb_expr_evaluator.h>
|
2020-06-16 19:49:09 +00:00
|
|
|
|
|
|
|
|
2020-07-23 20:47:38 +00:00
|
|
|
static void onLayer( LIBEVAL::CONTEXT* aCtx, void *self )
|
2020-07-22 20:27:38 +00:00
|
|
|
{
|
2020-09-05 16:00:29 +00:00
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
|
|
|
|
LIBEVAL::VALUE* arg = aCtx->Pop();
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
if( !arg )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-07-28 22:49:17 +00:00
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "onLayer()" ) ) );
|
2020-07-22 20:27:38 +00:00
|
|
|
return;
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
wxString layerName = arg->AsString();
|
2020-09-05 16:00:29 +00:00
|
|
|
wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
|
|
|
|
bool anyMatch = false;
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-09-05 16:00:29 +00:00
|
|
|
wxPGChoiceEntry& entry = layerMap[ii];
|
|
|
|
|
|
|
|
if( entry.GetText().Matches( layerName ) )
|
|
|
|
{
|
|
|
|
anyMatch = true;
|
|
|
|
|
|
|
|
if( item->IsOnLayer( ToLAYER_ID( entry.GetValue() ) ) )
|
|
|
|
{
|
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2020-07-22 20:27:38 +00:00
|
|
|
}
|
2020-07-22 13:08:57 +00:00
|
|
|
|
2020-09-05 16:00:29 +00:00
|
|
|
if( !anyMatch )
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Unrecognized layer '%s' " ), layerName ) );
|
2020-07-22 20:27:38 +00:00
|
|
|
}
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-07-28 22:49:17 +00:00
|
|
|
static void isPlated( LIBEVAL::CONTEXT* aCtx, void* self )
|
2020-07-22 20:27:38 +00:00
|
|
|
{
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
2020-06-19 21:33:29 +00:00
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
2020-07-22 13:08:57 +00:00
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
2020-07-23 20:47:38 +00:00
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
2020-07-22 20:27:38 +00:00
|
|
|
D_PAD* pad = dynamic_cast<D_PAD*>( item );
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-07-22 20:27:38 +00:00
|
|
|
if( pad && pad->GetAttribute() == PAD_ATTRIB_STANDARD )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-07-28 22:49:17 +00:00
|
|
|
static void insideCourtyard( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
2020-07-30 17:06:50 +00:00
|
|
|
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
LIBEVAL::VALUE* arg = aCtx->Pop();
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
2020-07-28 22:49:17 +00:00
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if( !arg )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideCourtyard()" ) ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
2020-07-30 17:06:50 +00:00
|
|
|
MODULE* footprint = nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
|
|
|
footprint = dynamic_cast<MODULE*>( context->GetItem( 0 ) );
|
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
|
|
|
footprint = dynamic_cast<MODULE*>( context->GetItem( 1 ) );
|
|
|
|
}
|
|
|
|
else
|
2020-07-28 22:49:17 +00:00
|
|
|
{
|
2020-07-30 17:06:50 +00:00
|
|
|
for( MODULE* candidate : item->GetBoard()->Modules() )
|
2020-07-28 22:49:17 +00:00
|
|
|
{
|
2020-07-30 17:06:50 +00:00
|
|
|
if( candidate->GetReference().Matches( arg->AsString() ) )
|
2020-07-28 22:49:17 +00:00
|
|
|
{
|
2020-07-30 17:06:50 +00:00
|
|
|
footprint = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
if( footprint )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET footprintCourtyard;
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
if( footprint->IsFlipped() )
|
|
|
|
footprintCourtyard = footprint->GetPolyCourtyardBack();
|
|
|
|
else
|
|
|
|
footprintCourtyard = footprint->GetPolyCourtyardFront();
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
SHAPE_POLY_SET testPoly;
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-08-12 21:18:13 +00:00
|
|
|
item->TransformShapeWithClearanceToPolygon( testPoly, context->GetLayer(), 0 );
|
2020-07-30 17:06:50 +00:00
|
|
|
testPoly.BooleanIntersection( footprintCourtyard, SHAPE_POLY_SET::PM_FAST );
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
if( testPoly.OutlineCount() )
|
|
|
|
result->Set( 1.0 );
|
2020-07-28 22:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
static void insideArea( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
LIBEVAL::VALUE* arg = aCtx->Pop();
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if( !arg )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideArea()" ) ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
ZONE_CONTAINER* zone = nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
|
|
|
zone = dynamic_cast<ZONE_CONTAINER*>( context->GetItem( 0 ) );
|
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
|
|
|
zone = dynamic_cast<ZONE_CONTAINER*>( context->GetItem( 1 ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( ZONE_CONTAINER* candidate : item->GetBoard()->Zones() )
|
|
|
|
{
|
|
|
|
if( candidate->GetZoneName().Matches( arg->AsString() ) )
|
|
|
|
{
|
|
|
|
zone = candidate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 14:15:43 +00:00
|
|
|
if( zone )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2020-09-04 23:24:35 +00:00
|
|
|
SHAPE_POLY_SET testPoly;
|
2020-08-07 20:18:33 +00:00
|
|
|
|
2020-08-12 21:18:13 +00:00
|
|
|
item->TransformShapeWithClearanceToPolygon( testPoly, context->GetLayer(), 0 );
|
2020-09-04 23:24:35 +00:00
|
|
|
testPoly.BooleanIntersection( *zone->Outline(), SHAPE_POLY_SET::PM_FAST );
|
2020-08-07 20:18:33 +00:00
|
|
|
|
|
|
|
if( testPoly.OutlineCount() )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 19:49:09 +00:00
|
|
|
PCB_EXPR_BUILTIN_FUNCTIONS::PCB_EXPR_BUILTIN_FUNCTIONS()
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
auto registerFunc = [&]( const wxString& funcSignature, LIBEVAL::FUNC_CALL_REF funcPtr )
|
2020-07-22 20:27:38 +00:00
|
|
|
{
|
|
|
|
wxString funcName = funcSignature.BeforeFirst( '(' );
|
|
|
|
m_funcs[ std::string( funcName.Lower() ) ] = std::move( funcPtr );
|
|
|
|
m_funcSigs.Add( funcSignature );
|
|
|
|
};
|
|
|
|
|
|
|
|
registerFunc( "onLayer('x')", onLayer );
|
|
|
|
registerFunc( "isPlated()", isPlated );
|
2020-07-28 22:49:17 +00:00
|
|
|
registerFunc( "insideCourtyard('x')", insideCourtyard );
|
2020-08-07 20:18:33 +00:00
|
|
|
registerFunc( "insideArea('x')", insideArea );
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-07-23 20:47:38 +00:00
|
|
|
BOARD_ITEM* PCB_EXPR_VAR_REF::GetObject( LIBEVAL::CONTEXT* aCtx ) const
|
2020-07-22 07:02:30 +00:00
|
|
|
{
|
2020-08-12 15:26:10 +00:00
|
|
|
wxASSERT( dynamic_cast<PCB_EXPR_CONTEXT*>( aCtx ) );
|
|
|
|
|
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-07-23 20:47:38 +00:00
|
|
|
LIBEVAL::VALUE PCB_EXPR_VAR_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
2020-06-16 19:49:09 +00:00
|
|
|
{
|
2020-07-23 20:47:38 +00:00
|
|
|
BOARD_ITEM* item = const_cast<BOARD_ITEM*>( GetObject( aCtx ) );
|
2020-07-19 21:22:49 +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
|
|
|
|
// simplier "A.Via_Type == 'buried'" is perfectly clear. Instead, return an undefined
|
|
|
|
// value when the property doesn't appear on a particular object.
|
|
|
|
|
|
|
|
return LIBEVAL::VALUE( "UNDEFINED" );
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( m_type == LIBEVAL::VT_NUMERIC )
|
|
|
|
return LIBEVAL::VALUE( (double) item->Get<int>( it->second ) );
|
|
|
|
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 );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 10:35:05 +00:00
|
|
|
const wxAny& any = item->Get( it->second );
|
2020-06-16 19:49:09 +00:00
|
|
|
any.GetAs<wxString>( &str );
|
|
|
|
}
|
2020-07-23 10:35:05 +00:00
|
|
|
|
2020-07-25 11:58:17 +00:00
|
|
|
return LIBEVAL::VALUE( str );
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +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-08-11 13:33:16 +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-08-11 13:33:16 +00:00
|
|
|
std::unique_ptr<PCB_EXPR_VAR_REF> vref;;
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
if( aVar == "A" )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
vref.reset( new PCB_EXPR_VAR_REF( 0 ) );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
2020-08-11 13:33:16 +00:00
|
|
|
else if( aVar == "B" )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
vref.reset( new PCB_EXPR_VAR_REF( 1 ) );
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
return nullptr;
|
2020-07-19 21:22:49 +00:00
|
|
|
}
|
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 );
|
2020-07-28 19:31:48 +00:00
|
|
|
field.Replace( "_", " " );
|
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 );
|
|
|
|
vref->SetIsEnum ( true );
|
|
|
|
}
|
2020-06-13 23:22:08 +00:00
|
|
|
else
|
|
|
|
{
|
2020-07-30 11:24:29 +00:00
|
|
|
wxFAIL_MSG( "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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class PCB_UNIT_RESOLVER : public LIBEVAL::UNIT_RESOLVER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~PCB_UNIT_RESOLVER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
virtual const std::vector<wxString>& GetSupportedUnits() const override
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
static const std::vector<wxString> pcbUnits = { "mil", "mm", "in" };
|
2020-06-13 23:22:08 +00:00
|
|
|
|
|
|
|
return pcbUnits;
|
|
|
|
}
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
virtual double Convert( const wxString& aString, int unitId ) const override
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2020-08-11 13:33:16 +00:00
|
|
|
double v = wxAtof( aString );
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2020-06-13 23:22:08 +00:00
|
|
|
switch( unitId )
|
|
|
|
{
|
2020-08-15 16:30:55 +00:00
|
|
|
case 0: return DoubleValueFromString( EDA_UNITS::INCHES, aString, true );
|
|
|
|
case 1: return DoubleValueFromString( EDA_UNITS::MILLIMETRES, aString );
|
|
|
|
case 2: return DoubleValueFromString( EDA_UNITS::INCHES, aString, false );
|
2020-07-19 21:22:49 +00:00
|
|
|
default: return v;
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
PCB_EXPR_COMPILER::PCB_EXPR_COMPILER()
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2020-07-21 15:49:55 +00:00
|
|
|
m_unitResolver = std::make_unique<PCB_UNIT_RESOLVER>();
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-11 13:33:16 +00:00
|
|
|
PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR()
|
2020-06-13 23:22:08 +00:00
|
|
|
{
|
2020-07-22 07:02:30 +00:00
|
|
|
m_result = 0;
|
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;
|
2020-08-12 15:26:10 +00:00
|
|
|
PCB_EXPR_CONTEXT preflightContext( F_Cu );
|
2020-07-21 15:49:55 +00:00
|
|
|
|
2020-07-30 11:24:29 +00:00
|
|
|
m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext );
|
2020-06-13 23:22:08 +00:00
|
|
|
|
2020-08-12 15:26:10 +00:00
|
|
|
PCB_EXPR_CONTEXT evaluationContext( 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;
|
|
|
|
}
|
|
|
|
|