2020-06-04 11:04:03 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include "board.h"
|
2021-06-11 21:07:02 +00:00
|
|
|
#include "pcb_track.h"
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2023-08-21 14:26:03 +00:00
|
|
|
#include <pcbexpr_evaluator.h>
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
2023-12-24 01:21:58 +00:00
|
|
|
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
|
2020-06-04 11:04:03 +00:00
|
|
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
2023-09-07 11:22:10 +00:00
|
|
|
#include <core/profile.h>
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2022-11-29 14:18:44 +00:00
|
|
|
bool testEvalExpr( const std::string expr, LIBEVAL::VALUE expectedResult, bool expectError = false,
|
|
|
|
BOARD_ITEM* itemA = nullptr, BOARD_ITEM* itemB = nullptr )
|
2020-06-04 11:04:03 +00:00
|
|
|
{
|
2023-08-21 14:26:03 +00:00
|
|
|
PCBEXPR_COMPILER compiler( new PCB_UNIT_RESOLVER() );
|
|
|
|
PCBEXPR_UCODE ucode;
|
2020-06-04 11:04:03 +00:00
|
|
|
bool ok = true;
|
|
|
|
|
2023-08-21 14:26:03 +00:00
|
|
|
PCBEXPR_CONTEXT context, preflightContext;
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2020-10-06 09:22:07 +00:00
|
|
|
context.SetItems( itemA, itemB );
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2020-10-06 09:22:07 +00:00
|
|
|
bool error = !compiler.Compile( expr, &ucode, &preflightContext );
|
2023-12-19 17:39:26 +00:00
|
|
|
|
|
|
|
|
2020-06-04 11:04:03 +00:00
|
|
|
if( error )
|
|
|
|
{
|
|
|
|
if ( expectError )
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
return ok;
|
2020-08-18 14:17:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-04 11:04:03 +00:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIBEVAL::VALUE result;
|
|
|
|
|
|
|
|
if( ok )
|
|
|
|
{
|
2020-10-06 09:22:07 +00:00
|
|
|
result = *ucode.Run( &context );
|
|
|
|
ok = (result.EqualTo( &expectedResult) );
|
2020-06-04 11:04:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main( int argc, char *argv[] )
|
|
|
|
{
|
|
|
|
PROPERTY_MANAGER& propMgr = PROPERTY_MANAGER::Instance();
|
|
|
|
propMgr.Rebuild();
|
|
|
|
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-06-04 11:04:03 +00:00
|
|
|
using VAL = LIBEVAL::VALUE;
|
|
|
|
|
2020-10-06 09:22:07 +00:00
|
|
|
|
|
|
|
|
2020-06-04 11:04:03 +00:00
|
|
|
/* testEvalExpr( "10mm + 20 mm", VAL(30e6) );
|
|
|
|
testEvalExpr( "3*(7+8)", VAL(3*(7+8)) );
|
|
|
|
testEvalExpr( "3*7+8", VAL(3*7+8) );
|
|
|
|
testEvalExpr( "(3*7)+8", VAL(3*7+8) );
|
|
|
|
testEvalExpr( "10mm + 20)", VAL(0), true );
|
2020-08-18 14:17:16 +00:00
|
|
|
*/
|
2020-06-04 11:04:03 +00:00
|
|
|
|
|
|
|
BOARD brd;
|
|
|
|
|
|
|
|
NETINFO_LIST& netInfo = brd.GetNetInfo();
|
|
|
|
|
|
|
|
NETCLASSPTR netclass1( new NETCLASS("HV") );
|
|
|
|
NETCLASSPTR netclass2( new NETCLASS("otherClass" ) );
|
|
|
|
|
|
|
|
auto net1info = new NETINFO_ITEM( &brd, "net1", 1);
|
|
|
|
auto net2info = new NETINFO_ITEM( &brd, "net2", 2);
|
2020-08-18 14:17:16 +00:00
|
|
|
|
2020-06-04 11:04:03 +00:00
|
|
|
net1info->SetClass( netclass1 );
|
|
|
|
net2info->SetClass( netclass2 );
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK trackA( &brd );
|
|
|
|
PCB_TRACK trackB( &brd );
|
2020-06-04 11:04:03 +00:00
|
|
|
|
|
|
|
trackA.SetNet( net1info );
|
|
|
|
trackB.SetNet( net2info );
|
|
|
|
|
2020-06-17 22:36:31 +00:00
|
|
|
trackB.SetLayer( F_Cu );
|
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
trackA.SetWidth( Mils2iu( 10 ) );
|
|
|
|
trackB.SetWidth( Mils2iu( 20 ) );
|
2020-06-04 11:04:03 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
testEvalExpr( "A.fromTo('U1', 'U3') && A.NetClass == 'DDR3_A' ", VAL(0), false, &trackA, &trackB );
|
2020-10-06 09:22:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2020-07-19 21:22:49 +00:00
|
|
|
// testEvalExpr( "A.onlayer('F.Cu') || A.onlayer('B.Cu')", VAL( 1.0 ), false, &trackA, &trackB );
|
2020-09-27 17:05:16 +00:00
|
|
|
testEvalExpr( "A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))", VAL( 0.0 ), false, &trackA, &trackB );
|
2020-06-17 22:36:31 +00:00
|
|
|
return 0;
|
2020-07-19 21:22:49 +00:00
|
|
|
testEvalExpr( "A.Width > B.Width", VAL( 0.0 ), false, &trackA, &trackB );
|
|
|
|
testEvalExpr( "A.Width + B.Width", VAL( Mils2iu(10) + Mils2iu(20) ), false, &trackA, &trackB );
|
2020-06-04 11:04:03 +00:00
|
|
|
|
|
|
|
testEvalExpr( "A.Netclass", VAL( (const char*) trackA.GetNetClassName().c_str() ), false, &trackA, &trackB );
|
2020-07-19 21:22:49 +00:00
|
|
|
testEvalExpr( "(A.Netclass == 'HV') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')", VAL( 1.0 ), false, &trackA, &trackB );
|
2020-06-04 11:04:03 +00:00
|
|
|
testEvalExpr( "A.Netclass + 1.0", VAL( 1.0 ), false, &trackA, &trackB );
|
2020-07-19 21:22:49 +00:00
|
|
|
testEvalExpr( "A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'", VAL( 0.0 ), false, &trackA, &trackB );
|
|
|
|
testEvalExpr( "(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')", VAL( 0.0 ), false, &trackA, &trackB );
|
2020-06-17 22:36:31 +00:00
|
|
|
|
2020-06-04 11:04:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|