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-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <drc/drc_rtree.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <track.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <pcb_group.h>
|
2020-10-21 23:59:40 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2020-07-30 11:24:29 +00:00
|
|
|
#include <pcb_expr_evaluator.h>
|
2021-06-01 05:17:57 +00:00
|
|
|
#include <wx/log.h>
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-09-25 18:26:58 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <connectivity/connectivity_algo.h>
|
|
|
|
#include <connectivity/from_to_cache.h>
|
|
|
|
|
2020-10-08 21:59:40 +00:00
|
|
|
#include <drc/drc_engine.h>
|
2020-10-22 12:36:28 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
2020-09-25 18:26:58 +00:00
|
|
|
|
|
|
|
bool exprFromTo( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
LIBEVAL::VALUE* argTo = aCtx->Pop();
|
|
|
|
LIBEVAL::VALUE* argFrom = aCtx->Pop();
|
|
|
|
|
|
|
|
result->Set(0.0);
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if(!item)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto ftCache = item->GetBoard()->GetConnectivity()->GetFromToCache();
|
|
|
|
|
|
|
|
if( !ftCache )
|
|
|
|
{
|
|
|
|
wxLogWarning( "Attempting to call fromTo() with non-existent from-to cache, aborting...");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ftCache->IsOnFromToPath( static_cast<BOARD_CONNECTED_ITEM*>( item ),
|
|
|
|
argFrom->AsString(), argTo->AsString() ) )
|
|
|
|
{
|
|
|
|
result->Set(1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-09-27 17:05:16 +00:00
|
|
|
static void existsOnLayer( 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;
|
|
|
|
|
2021-05-20 22:05:27 +00:00
|
|
|
if( !arg && aCtx->HasErrorCallback() )
|
2020-07-19 21:22:49 +00:00
|
|
|
{
|
2020-07-28 22:49:17 +00:00
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
2020-09-27 17:05:16 +00:00
|
|
|
wxT( "existsOnLayer()" ) ) );
|
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
|
|
|
|
2021-05-20 22:05:27 +00:00
|
|
|
if( !anyMatch && aCtx->HasErrorCallback() )
|
2020-09-14 08:02:07 +00:00
|
|
|
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-19 21:22:49 +00:00
|
|
|
|
2021-02-22 01:13:38 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2021-05-01 14:46:50 +00:00
|
|
|
if( item->Type() == PCB_PAD_T && static_cast<PAD*>( item )->GetAttribute() == PAD_ATTRIB::PTH )
|
2021-02-20 12:12:23 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
else if( item->Type() == PCB_VIA_T )
|
2020-07-22 20:27:38 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
2020-06-16 19:49:09 +00:00
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
static bool insideFootprintCourtyard( BOARD_ITEM* aItem, const EDA_RECT& aItemBBox,
|
|
|
|
std::shared_ptr<SHAPE> aItemShape, PCB_EXPR_CONTEXT* aCtx,
|
|
|
|
FOOTPRINT* aFootprint, PCB_LAYER_ID aSide = UNDEFINED_LAYER )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET footprintCourtyard;
|
|
|
|
|
|
|
|
if( aSide == F_Cu )
|
|
|
|
footprintCourtyard = aFootprint->GetPolyCourtyardFront();
|
|
|
|
else if( aSide == B_Cu )
|
|
|
|
footprintCourtyard = aFootprint->GetPolyCourtyardBack();
|
|
|
|
else if( aFootprint->IsFlipped() )
|
|
|
|
footprintCourtyard = aFootprint->GetPolyCourtyardBack();
|
|
|
|
else
|
|
|
|
footprintCourtyard = aFootprint->GetPolyCourtyardFront();
|
|
|
|
|
|
|
|
if( aItem->Type() == PCB_ZONE_T || aItem->Type() == PCB_FP_ZONE_T )
|
|
|
|
{
|
|
|
|
// A zone must be entirely inside the courtyard to be considered
|
|
|
|
if( !aFootprint->GetBoundingBox().Contains( aItemBBox ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !aFootprint->GetBoundingBox().Intersects( aItemBBox ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aItemShape )
|
|
|
|
aItemShape = aItem->GetEffectiveShape( aCtx->GetLayer() );
|
|
|
|
|
|
|
|
return footprintCourtyard.Collide( aItemShape.get() );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideCourtyard()" ) ) );
|
|
|
|
}
|
|
|
|
|
2020-07-28 22:49:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
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
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
2020-07-28 22:49:17 +00:00
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
BOARD* board = item->GetBoard();
|
|
|
|
EDA_RECT itemBBox;
|
|
|
|
std::shared_ptr<SHAPE> shape;
|
|
|
|
|
2021-01-05 22:18:37 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
|
|
|
|
else
|
|
|
|
itemBBox = item->GetBoundingBox();
|
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
auto insideFootprint =
|
2021-01-05 22:18:37 +00:00
|
|
|
[&]( FOOTPRINT* footprint ) -> bool
|
|
|
|
{
|
2021-03-20 20:09:57 +00:00
|
|
|
if( !footprint )
|
|
|
|
return false;
|
2021-01-05 22:18:37 +00:00
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
|
|
|
std::pair<BOARD_ITEM*, BOARD_ITEM*> key( footprint, item );
|
|
|
|
auto i = board->m_InsideCourtyardCache.find( key );
|
2021-01-05 22:18:37 +00:00
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
if( i != board->m_InsideCourtyardCache.end() )
|
|
|
|
return i->second;
|
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
bool res = insideFootprintCourtyard( item, itemBBox, shape, context, footprint );
|
2021-03-20 20:09:57 +00:00
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
board->m_InsideCourtyardCache[ key ] = res;
|
|
|
|
return res;
|
2021-03-20 20:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( FOOTPRINT* candidate : board->Footprints() )
|
|
|
|
{
|
|
|
|
if( candidate->GetReference().Matches( arg->AsString() ) )
|
|
|
|
{
|
|
|
|
if( insideFootprint( candidate ) )
|
2021-02-26 17:18:31 +00:00
|
|
|
{
|
2021-03-20 20:09:57 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
2021-02-26 17:18:31 +00:00
|
|
|
}
|
2021-03-20 20:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void insideFrontCourtyard( 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 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideFrontCourtyard()" ) ) );
|
|
|
|
}
|
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
BOARD* board = item->GetBoard();
|
|
|
|
EDA_RECT itemBBox;
|
|
|
|
std::shared_ptr<SHAPE> shape;
|
|
|
|
|
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
|
|
|
|
else
|
|
|
|
itemBBox = item->GetBoundingBox();
|
|
|
|
|
|
|
|
auto insideFootprint =
|
|
|
|
[&]( FOOTPRINT* footprint ) -> bool
|
|
|
|
{
|
|
|
|
if( !footprint )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
|
|
|
std::pair<BOARD_ITEM*, BOARD_ITEM*> key( footprint, item );
|
|
|
|
auto i = board->m_InsideFCourtyardCache.find( key );
|
|
|
|
|
|
|
|
if( i != board->m_InsideFCourtyardCache.end() )
|
|
|
|
return i->second;
|
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
bool res = insideFootprintCourtyard( item, itemBBox, shape, context, footprint,
|
2021-03-20 20:09:57 +00:00
|
|
|
F_Cu );
|
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
board->m_InsideFCourtyardCache[ key ] = res;
|
|
|
|
return res;
|
2021-03-20 20:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( FOOTPRINT* candidate : board->Footprints() )
|
|
|
|
{
|
|
|
|
if( candidate->GetReference().Matches( arg->AsString() ) )
|
|
|
|
{
|
|
|
|
if( insideFootprint( candidate ) )
|
2021-02-26 17:18:31 +00:00
|
|
|
{
|
2021-03-20 20:09:57 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
2021-02-26 17:18:31 +00:00
|
|
|
}
|
2021-03-20 20:09:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 22:18:37 +00:00
|
|
|
|
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
static void insideBackCourtyard( 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 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideBackCourtyard()" ) ) );
|
|
|
|
}
|
2021-03-20 20:09:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
BOARD* board = item->GetBoard();
|
|
|
|
EDA_RECT itemBBox;
|
|
|
|
std::shared_ptr<SHAPE> shape;
|
|
|
|
|
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
|
|
|
|
else
|
|
|
|
itemBBox = item->GetBoundingBox();
|
2021-01-05 22:18:37 +00:00
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
auto insideFootprint =
|
|
|
|
[&]( FOOTPRINT* footprint ) -> bool
|
|
|
|
{
|
|
|
|
if( !footprint )
|
|
|
|
return false;
|
|
|
|
|
2021-02-27 21:33:05 +00:00
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
2021-02-26 19:19:56 +00:00
|
|
|
std::pair<BOARD_ITEM*, BOARD_ITEM*> key( footprint, item );
|
2021-03-20 20:09:57 +00:00
|
|
|
auto i = board->m_InsideBCourtyardCache.find( key );
|
2021-02-26 19:19:56 +00:00
|
|
|
|
2021-03-20 20:09:57 +00:00
|
|
|
if( i != board->m_InsideBCourtyardCache.end() )
|
2021-02-26 19:19:56 +00:00
|
|
|
return i->second;
|
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
bool res = insideFootprintCourtyard( item, itemBBox, shape, context, footprint,
|
2021-03-20 20:09:57 +00:00
|
|
|
B_Cu );
|
2021-02-26 19:19:56 +00:00
|
|
|
|
2021-03-23 19:46:49 +00:00
|
|
|
board->m_InsideBCourtyardCache[ key ] = res;
|
|
|
|
return res;
|
2021-02-26 19:19:56 +00:00
|
|
|
};
|
|
|
|
|
2020-07-30 17:06:50 +00:00
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
2021-01-05 22:18:37 +00:00
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 0 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
2020-07-30 17:06:50 +00:00
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
2021-01-05 22:18:37 +00:00
|
|
|
if( insideFootprint( dynamic_cast<FOOTPRINT*>( context->GetItem( 1 ) ) ) )
|
|
|
|
result->Set( 1.0 );
|
2020-07-30 17:06:50 +00:00
|
|
|
}
|
|
|
|
else
|
2020-07-28 22:49:17 +00:00
|
|
|
{
|
2021-02-26 19:19:56 +00:00
|
|
|
for( FOOTPRINT* candidate : board->Footprints() )
|
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
|
|
|
{
|
2021-01-05 22:18:37 +00:00
|
|
|
if( insideFootprint( candidate ) )
|
|
|
|
{
|
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
|
|
|
}
|
2020-07-30 17:06:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "insideArea()" ) ) );
|
|
|
|
}
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
2020-08-07 20:18:33 +00:00
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
BOARD* board = item->GetBoard();
|
2021-06-01 21:06:10 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
|
2021-02-26 19:19:56 +00:00
|
|
|
EDA_RECT itemBBox;
|
|
|
|
std::shared_ptr<SHAPE> shape;
|
|
|
|
|
2021-01-05 21:28:42 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
itemBBox = static_cast<ZONE*>( item )->GetCachedBoundingBox();
|
|
|
|
else
|
|
|
|
itemBBox = item->GetBoundingBox();
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
auto itemIsInsideArea =
|
|
|
|
[&]( ZONE* area ) -> bool
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( !area->GetCachedBoundingBox().Intersects( itemBBox ) )
|
2020-10-25 15:02:49 +00:00
|
|
|
return false;
|
|
|
|
|
2021-02-04 13:42:30 +00:00
|
|
|
// Collisions include touching, so we need to deflate outline by enough to
|
|
|
|
// exclude touching. This is particularly important for detecting copper fills
|
|
|
|
// as they will be exactly touching along the entire border.
|
2021-06-01 21:06:10 +00:00
|
|
|
SHAPE_POLY_SET areaOutline = *area->Outline();
|
|
|
|
areaOutline.Deflate( bds.GetDRCEpsilon(), 0, SHAPE_POLY_SET::ALLOW_ACUTE_CORNERS );
|
2021-02-04 13:42:30 +00:00
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
if( item->GetFlags() & HOLE_PROXY )
|
|
|
|
{
|
|
|
|
if( item->Type() == PCB_PAD_T )
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( item );
|
2020-10-25 15:02:49 +00:00
|
|
|
const SHAPE_SEGMENT* holeShape = pad->GetEffectiveHoleShape();
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
return areaOutline.Collide( holeShape );
|
2020-10-25 15:02:49 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
VIA* via = static_cast<VIA*>( item );
|
|
|
|
const SHAPE_CIRCLE holeShape( via->GetPosition(), via->GetDrillValue() );
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
return areaOutline.Collide( &holeShape );
|
2020-10-25 15:02:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
if( item->Type() == PCB_FOOTPRINT_T )
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
|
2020-10-25 15:02:49 +00:00
|
|
|
|
2020-11-20 13:55:10 +00:00
|
|
|
if( ( footprint->GetFlags() & MALFORMED_COURTYARDS ) != 0 )
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
aCtx->ReportError( _( "Footprint's courtyard is not a single, closed shape." ) );
|
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
if( ( area->GetLayerSet() & LSET::FrontMask() ).any() )
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyardFront();
|
|
|
|
|
|
|
|
if( courtyard.OutlineCount() == 0 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
aCtx->ReportError( _( "Footprint has no front courtyard." ) );
|
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
return areaOutline.Collide( &courtyard.Outline( 0 ) );
|
2020-10-25 15:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
if( ( area->GetLayerSet() & LSET::BackMask() ).any() )
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
|
|
|
SHAPE_POLY_SET courtyard = footprint->GetPolyCourtyardBack();
|
|
|
|
|
|
|
|
if( courtyard.OutlineCount() == 0 )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
aCtx->ReportError( _( "Footprint has no back courtyard." ) );
|
|
|
|
|
2020-10-25 15:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
return areaOutline.Collide( &courtyard.Outline( 0 ) );
|
2020-10-25 15:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-05 21:28:42 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T || item->Type() == PCB_FP_ZONE_T )
|
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2021-02-27 21:33:05 +00:00
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
if( !zone->IsFilled() )
|
2021-02-27 21:33:05 +00:00
|
|
|
return false;
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
DRC_RTREE* zoneRTree = board->m_CopperZoneRTrees[ zone ].get();
|
2021-01-05 21:28:42 +00:00
|
|
|
|
2021-06-02 13:00:11 +00:00
|
|
|
std::vector<SHAPE*> shapes;
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
if( zoneRTree )
|
2021-01-05 21:28:42 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
for( PCB_LAYER_ID layer : area->GetLayerSet().Seq() )
|
2021-02-04 13:42:30 +00:00
|
|
|
{
|
2021-06-02 13:00:11 +00:00
|
|
|
if( zoneRTree->QueryColliding( itemBBox, &areaOutline, layer ) )
|
2021-03-07 17:54:49 +00:00
|
|
|
return true;
|
2021-02-04 13:42:30 +00:00
|
|
|
}
|
2021-01-05 21:28:42 +00:00
|
|
|
}
|
2020-10-25 15:02:49 +00:00
|
|
|
|
2021-02-04 13:42:30 +00:00
|
|
|
return false;
|
2021-01-05 21:28:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-05 22:18:37 +00:00
|
|
|
if( !shape )
|
|
|
|
shape = item->GetEffectiveShape( context->GetLayer() );
|
2020-10-25 15:02:49 +00:00
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
return areaOutline.Collide( shape.get() );
|
2021-01-05 21:28:42 +00:00
|
|
|
}
|
2020-10-25 15:02:49 +00:00
|
|
|
};
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
auto checkArea =
|
|
|
|
[&]( ZONE* area ) -> bool
|
2021-02-26 19:19:56 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( !area || area == item || area->GetParent() == item )
|
2021-02-26 19:19:56 +00:00
|
|
|
return false;
|
|
|
|
|
2021-02-27 21:33:05 +00:00
|
|
|
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
|
2021-06-01 21:06:10 +00:00
|
|
|
std::pair<BOARD_ITEM*, BOARD_ITEM*> key( area, item );
|
2021-02-27 21:33:05 +00:00
|
|
|
auto i = board->m_InsideAreaCache.find( key );
|
2021-02-26 19:19:56 +00:00
|
|
|
|
|
|
|
if( i != board->m_InsideAreaCache.end() )
|
|
|
|
return i->second;
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
bool isInside = itemIsInsideArea( area );
|
2021-02-26 19:19:56 +00:00
|
|
|
|
2021-02-28 01:01:14 +00:00
|
|
|
board->m_InsideAreaCache[ key ] = isInside;
|
|
|
|
return isInside;
|
2021-02-26 19:19:56 +00:00
|
|
|
};
|
|
|
|
|
2020-08-07 20:18:33 +00:00
|
|
|
if( arg->AsString() == "A" )
|
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( dynamic_cast<ZONE*>( context->GetItem( 0 ) ) ) )
|
2020-10-25 15:02:49 +00:00
|
|
|
result->Set( 1.0 );
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
|
|
|
else if( arg->AsString() == "B" )
|
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( dynamic_cast<ZONE*>( context->GetItem( 1 ) ) ) )
|
2020-10-25 15:02:49 +00:00
|
|
|
result->Set( 1.0 );
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
2020-10-25 20:53:24 +00:00
|
|
|
else if( KIID::SniffTest( arg->AsString() ) )
|
|
|
|
{
|
|
|
|
KIID target( arg->AsString() );
|
|
|
|
|
2021-06-01 21:06:10 +00:00
|
|
|
for( ZONE* area : board->Zones() )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
|
|
|
// Only a single zone can match the UUID; exit once we find a match whether
|
|
|
|
// "inside" or not
|
2021-06-01 21:06:10 +00:00
|
|
|
if( area->m_Uuid == target )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( area ) )
|
2020-10-25 20:53:24 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
for( ZONE* area : footprint->Zones() )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
|
|
|
// Only a single zone can match the UUID; exit once we find a match whether
|
|
|
|
// "inside" or not
|
2021-06-01 21:06:10 +00:00
|
|
|
if( area->m_Uuid == target )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( area ) )
|
2020-10-25 20:53:24 +00:00
|
|
|
result->Set( 1.0 );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Match on zone name
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
for( ZONE* area : board->Zones() )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( area->GetZoneName().Matches( arg->AsString() ) )
|
2020-08-07 20:18:33 +00:00
|
|
|
{
|
2020-10-25 20:53:24 +00:00
|
|
|
// Many zones can match the name; exit only when we find an "inside"
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( area ) )
|
2020-10-25 15:02:49 +00:00
|
|
|
{
|
2020-10-21 23:59:40 +00:00
|
|
|
result->Set( 1.0 );
|
2020-10-25 15:02:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-21 23:59:40 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-25 20:53:24 +00:00
|
|
|
|
2021-02-26 19:19:56 +00:00
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
for( ZONE* area : footprint->Zones() )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
|
|
|
// Many zones can match the name; exit only when we find an "inside"
|
2021-06-01 21:06:10 +00:00
|
|
|
if( area->GetZoneName().Matches( arg->AsString() ) )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
2021-06-01 21:06:10 +00:00
|
|
|
if( checkArea( area ) )
|
2020-10-25 20:53:24 +00:00
|
|
|
{
|
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-07 20:18:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-24 01:05:46 +00:00
|
|
|
static void memberOf( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
LIBEVAL::VALUE* arg = aCtx->Pop();
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if( !arg )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "memberOf()" ) ) );
|
|
|
|
}
|
2020-09-24 01:05:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
PCB_GROUP* group = item->GetParentGroup();
|
2020-09-24 01:05:46 +00:00
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
if( !group && item->GetParent() && item->GetParent()->Type() == PCB_FOOTPRINT_T )
|
2020-09-25 17:37:03 +00:00
|
|
|
group = item->GetParent()->GetParentGroup();
|
2020-09-24 01:05:46 +00:00
|
|
|
|
|
|
|
while( group )
|
|
|
|
{
|
|
|
|
if( group->GetName().Matches( arg->AsString() ) )
|
|
|
|
{
|
|
|
|
result->Set( 1.0 );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-25 17:37:03 +00:00
|
|
|
group = group->GetParentGroup();
|
2020-09-24 01:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-26 22:04:53 +00:00
|
|
|
static void isMicroVia( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
auto via = dyn_cast<VIA*>( item );
|
|
|
|
|
|
|
|
if( via && via->GetViaType() == VIATYPE::MICROVIA )
|
|
|
|
{
|
|
|
|
result->Set ( 1.0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void isBlindBuriedVia( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
auto via = dyn_cast<VIA*>( item );
|
|
|
|
|
|
|
|
if( via && via->GetViaType() == VIATYPE::BLIND_BURIED )
|
|
|
|
{
|
|
|
|
result->Set ( 1.0 );
|
|
|
|
}
|
2020-10-08 21:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-20 23:03:34 +00:00
|
|
|
static void isCoupledDiffPair( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
|
|
|
|
BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if( a && b )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = a->GetNet();
|
|
|
|
wxString coupledNet, dummy;
|
|
|
|
|
|
|
|
if( netinfo && DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) != 0 )
|
|
|
|
{
|
|
|
|
if( b->GetNetname() == coupledNet )
|
|
|
|
result->Set( 1.0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-28 00:54:55 +00:00
|
|
|
static void inDiffPair( LIBEVAL::CONTEXT* aCtx, void* self )
|
|
|
|
{
|
|
|
|
LIBEVAL::VALUE* arg = aCtx->Pop();
|
|
|
|
PCB_EXPR_VAR_REF* vref = static_cast<PCB_EXPR_VAR_REF*>( self );
|
|
|
|
BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr;
|
|
|
|
LIBEVAL::VALUE* result = aCtx->AllocValue();
|
|
|
|
|
|
|
|
result->Set( 0.0 );
|
|
|
|
aCtx->Push( result );
|
|
|
|
|
|
|
|
if( !arg )
|
|
|
|
{
|
2021-05-20 22:05:27 +00:00
|
|
|
if( aCtx->HasErrorCallback() )
|
|
|
|
{
|
|
|
|
aCtx->ReportError( wxString::Format( _( "Missing argument to '%s'" ),
|
|
|
|
wxT( "inDiffPair()" ) ) );
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:54:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item && item->IsConnected() )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNet();
|
|
|
|
|
|
|
|
wxString refName = netinfo->GetNetname();
|
|
|
|
wxString baseName, coupledNet;
|
|
|
|
|
|
|
|
int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName );
|
|
|
|
|
|
|
|
if( polarity == 0 )
|
|
|
|
return;
|
|
|
|
|
2021-04-22 02:41:17 +00:00
|
|
|
if( BOARD* board = item->GetBoard() )
|
|
|
|
{
|
|
|
|
if( !board->FindNet( coupledNet ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-28 00:54:55 +00:00
|
|
|
if( baseName.Matches( arg->AsString() ) )
|
|
|
|
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-09-23 21:50:06 +00:00
|
|
|
RegisterAllFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions()
|
2020-09-27 18:43:44 +00:00
|
|
|
{
|
2020-09-23 21:50:06 +00:00
|
|
|
m_funcs.clear();
|
2020-09-27 18:43:44 +00:00
|
|
|
RegisterFunc( "existsOnLayer('x')", existsOnLayer );
|
2020-09-23 21:50:06 +00:00
|
|
|
RegisterFunc( "isPlated()", isPlated );
|
|
|
|
RegisterFunc( "insideCourtyard('x')", insideCourtyard );
|
2021-03-20 20:09:57 +00:00
|
|
|
RegisterFunc( "insideFrontCourtyard('x')", insideFrontCourtyard );
|
|
|
|
RegisterFunc( "insideBackCourtyard('x')", insideBackCourtyard );
|
2020-09-23 21:50:06 +00:00
|
|
|
RegisterFunc( "insideArea('x')", insideArea );
|
|
|
|
RegisterFunc( "isMicroVia()", isMicroVia );
|
|
|
|
RegisterFunc( "isBlindBuriedVia()", isBlindBuriedVia );
|
|
|
|
RegisterFunc( "memberOf('x')", memberOf );
|
|
|
|
RegisterFunc( "fromTo('x','y')", exprFromTo );
|
2021-03-20 23:03:34 +00:00
|
|
|
RegisterFunc( "isCoupledDiffPair()", isCoupledDiffPair );
|
2021-02-28 00:54:55 +00:00
|
|
|
RegisterFunc( "inDiffPair('x')", inDiffPair );
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
|
|
|
|
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 ) :
|
|
|
|
LIBEVAL::VALUE( double( aLayer ) )
|
|
|
|
{};
|
|
|
|
|
|
|
|
virtual bool EqualTo( const VALUE* b ) const override
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
wxPGChoices& layerMap = ENUM_MAP<PCB_LAYER_ID>::Instance().Choices();
|
|
|
|
PCB_LAYER_ID layerId = ToLAYER_ID( (int) AsDouble() );
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < layerMap.GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
wxPGChoiceEntry& entry = layerMap[ii];
|
|
|
|
|
|
|
|
if( entry.GetValue() == layerId && entry.GetText().Matches( b->AsString() ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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-09-27 18:43:44 +00:00
|
|
|
if( m_itemIndex == 2 )
|
|
|
|
{
|
|
|
|
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
|
|
|
|
return PCB_LAYER_VALUE( context->GetLayer() );
|
|
|
|
}
|
|
|
|
|
2021-01-02 22:25:28 +00:00
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return LIBEVAL::VALUE();
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2020-11-15 17:48:25 +00:00
|
|
|
return LIBEVAL::VALUE();
|
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 );
|
2021-05-03 12:04:15 +00:00
|
|
|
return 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 )
|
|
|
|
return LIBEVAL::VALUE( str );
|
2020-06-16 19:49:09 +00:00
|
|
|
}
|
2020-07-23 10:35:05 +00:00
|
|
|
|
2021-05-03 12:04:15 +00:00
|
|
|
return LIBEVAL::VALUE();
|
2020-06-13 23:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
|
2021-01-11 22:08:07 +00:00
|
|
|
LIBEVAL::VALUE PCB_EXPR_NETCLASS_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return LIBEVAL::VALUE();
|
|
|
|
|
|
|
|
if( item->IsConnected() )
|
|
|
|
return LIBEVAL::VALUE( static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNetClassName() );
|
|
|
|
else
|
|
|
|
return LIBEVAL::VALUE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LIBEVAL::VALUE PCB_EXPR_NETNAME_REF::GetValue( LIBEVAL::CONTEXT* aCtx )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = GetObject( aCtx );
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return LIBEVAL::VALUE();
|
|
|
|
|
|
|
|
if( item->IsConnected() )
|
|
|
|
return LIBEVAL::VALUE( static_cast<BOARD_CONNECTED_ITEM*>( item )->GetNetname() );
|
|
|
|
else
|
|
|
|
return LIBEVAL::VALUE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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".
|
|
|
|
|
2021-01-12 12:45:39 +00:00
|
|
|
if( aField.CmpNoCase( "NetClass" ) == 0 )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
|
|
|
if( aVar == "A" )
|
|
|
|
return std::make_unique<PCB_EXPR_NETCLASS_REF>( 0 );
|
|
|
|
else if( aVar == "B" )
|
|
|
|
return std::make_unique<PCB_EXPR_NETCLASS_REF>( 1 );
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
2021-01-12 12:45:39 +00:00
|
|
|
else if( aField.CmpNoCase( "NetName" ) == 0 )
|
2021-01-11 22:08:07 +00:00
|
|
|
{
|
|
|
|
if( aVar == "A" )
|
|
|
|
return std::make_unique<PCB_EXPR_NETNAME_REF>( 0 );
|
|
|
|
else if( aVar == "B" )
|
|
|
|
return std::make_unique<PCB_EXPR_NETNAME_REF>( 1 );
|
|
|
|
else
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-03-25 00:34:57 +00:00
|
|
|
if( aVar == "A" || aVar == "AB" )
|
2020-10-26 23:49:11 +00:00
|
|
|
vref = std::make_unique<PCB_EXPR_VAR_REF>( 0 );
|
2020-08-11 13:33:16 +00:00
|
|
|
else if( aVar == "B" )
|
2020-10-26 23:49:11 +00:00
|
|
|
vref = std::make_unique<PCB_EXPR_VAR_REF>( 1 );
|
2020-09-27 18:43:44 +00:00
|
|
|
else if( aVar == "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 );
|
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 );
|
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
|
|
|
|
{
|
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-10-16 23:14:59 +00:00
|
|
|
virtual wxString GetSupportedUnitsMessage() const override
|
|
|
|
{
|
|
|
|
return _( "must be mm, in, or mil" );
|
|
|
|
}
|
|
|
|
|
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-10-02 22:04:16 +00:00
|
|
|
case 0: return DoubleValueFromString( EDA_UNITS::MILS, aString );
|
2020-08-15 16:30:55 +00:00
|
|
|
case 1: return DoubleValueFromString( EDA_UNITS::MILLIMETRES, aString );
|
2020-10-02 20:51:24 +00:00
|
|
|
case 2: return DoubleValueFromString( EDA_UNITS::INCHES, aString );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-30 23:47:57 +00:00
|
|
|
PCB_EXPR_EVALUATOR::PCB_EXPR_EVALUATOR() :
|
|
|
|
m_result( 0 ),
|
|
|
|
m_compiler(),
|
|
|
|
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;
|
2020-08-12 15:26:10 +00:00
|
|
|
PCB_EXPR_CONTEXT preflightContext( 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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|