KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_libeval_compiler.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <boost/test/data/test_case.hpp>
23
24#include <wx/wx.h>
25
26#include <layer_ids.h>
27#include <gal/color4d.h>
28#include <geometry/eda_angle.h>
30#include <drc/drc_rule.h>
32#include <drc/drc_rule_parser.h>
33#include <ki_exception.h>
34#include <reporter.h>
35#include <pcbnew/board.h>
37#include <pcbnew/pcb_shape.h>
38#include <pcbnew/pcb_table.h>
39#include <pcbnew/pcb_track.h>
40#include <pcbnew/footprint.h>
41#include <pcbnew/pad.h>
42#include <pcbnew/pcb_text.h>
43#include <pcbnew/pad.h>
44#include <pcbnew/zone.h>
46#include <properties/property.h>
49
50
51BOOST_AUTO_TEST_SUITE(Libeval_Compiler)
52
54{
55 wxString expression;
58
59 friend std::ostream& operator<<( std::ostream& os, const EXPR_TO_TEST& expr )
60 {
61 os << expr.expression;
62 return os;
63 }
64};
65
67
68static bool testEvalExpr( const wxString& expr, const LIBEVAL::VALUE& expectedResult,
69 BOARD_ITEM* itemA, BOARD_ITEM* itemB, bool expectError = false )
70{
72 PCBEXPR_UCODE ucode;
75 bool ok = true;
76
77 context.SetItems( itemA, itemB );
78
79
80 BOOST_TEST_MESSAGE( "Expr: '" << expr.c_str() << "'" );
81
82 bool error = !compiler.Compile( expr, &ucode, &preflightContext );
83
84 BOOST_CHECK_EQUAL( error, expectError );
85
86 if( error != expectError )
87 {
88 BOOST_TEST_MESSAGE( "Result: FAIL: " << compiler.GetError().message.c_str() <<
89 " (code pos: " << compiler.GetError().srcPos << ")" );
90
91 return false;
92 }
93
94 if( error )
95 return true;
96
98
99 if( ok )
100 {
101 result = ucode.Run( &context );
102 ok = ( result->EqualTo( &context, &expectedResult ) );
103 }
104
105 if( expectedResult.GetType() == LIBEVAL::VT_NUMERIC )
106 {
107 BOOST_CHECK_EQUAL( result->AsDouble(), expectedResult.AsDouble() );
108 }
109 else
110 {
111 BOOST_CHECK_EQUAL( result->AsString(), expectedResult.AsString() );
112 }
113
114 return ok;
115}
116
117
118static void expectCompileError( const wxString& aExpr )
119{
120 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
121 PCBEXPR_UCODE ucode;
123
124 compiler.Compile( aExpr, &ucode, &preflight );
125
126 BOOST_CHECK_MESSAGE( compiler.IsErrorPending(), "Expected a compile error for: " << aExpr.mb_str() );
127}
128
129
130static void expectCompileSuccess( const wxString& aExpr )
131{
132 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
133 PCBEXPR_UCODE ucode;
135
136 compiler.Compile( aExpr, &ucode, &preflight );
137
138 BOOST_CHECK_MESSAGE( !compiler.IsErrorPending(), "Expected expression to compile: " << aExpr.mb_str() );
139}
140
141
142BOOST_AUTO_TEST_CASE( SimpleExpressions )
143{
144 auto test =
145 [&]( const wxString& expr, const LIBEVAL::VALUE& expectedResult )
146 {
147 testEvalExpr( expr, expectedResult, nullptr, nullptr );
148 };
149
150 test( "10mm + 20 mm", VAL( 30e6 ) );
151 test( "3*(7+8)", VAL( 3 * ( 7 + 8 ) ) );
152 test( "3*7+8", VAL( 3 * 7 + 8 ) );
153 test( "(3*7)+8", VAL( 3 * 7 + 8 ) );
154
155 testEvalExpr( "10mm + 20)", VAL( 0 ), nullptr, nullptr, true );
156
157 test( "1", VAL( 1 ) );
158 test( "1.5", VAL( 1.5 ) );
159 test( "1,5", VAL( 1.5 ) );
160 test( "1mm", VAL( 1e6 ) );
161
162 // Any White-space is OK
163 test( " 1 + 2 ", VAL( 3 ) );
164
165 // Decimals are OK in expressions
166 test( "1.5 + 0.2 + 0.1", VAL( 1.8 ) );
167
168 // Negatives are OK
169 test( "3 - 10", VAL( -7 ) );
170
171 // Lots of operands
172 test( "1 + 2 + 10 + 1000.05", VAL( 1013.05 ) );
173
174 // Operator precedence
175 test( "1 + 2 - 4 * 20 / 2", VAL( -37 ) );
176
177 // Parens
178 test( "(1)", VAL( 1 ) );
179
180 // Parens affect precedence
181 test( "-(1 + (2 - 4)) * 20.8 / 2", VAL( 10.4 ) );
182
183 // Unary addition is a sign, not a leading operator
184 test( "+2 - 1", VAL( 1 ) );
185
186 // A short-circuited || must yield a normalized 1, not the raw (nonzero) left operand, so a
187 // boolean feeding a further operator behaves the same as the non-short-circuited path.
188 test( "(2 || 0) == 1", VAL( 1 ) );
189 test( "(7 || 0) + 5", VAL( 6 ) );
190}
191
192
193BOOST_AUTO_TEST_CASE( IntrospectedProperties )
194{
196 propMgr.Rebuild();
197
198 BOARD brd;
199
200 const NETINFO_LIST& netInfo = brd.GetNetInfo();
201
202 std::shared_ptr<NETCLASS> netclass1( new NETCLASS( "HV_LINE" ) );
203 std::shared_ptr<NETCLASS> netclass2( new NETCLASS( "otherClass" ) );
204
205 NETINFO_ITEM* net1info = new NETINFO_ITEM( &brd, "net1", 1 );
206 NETINFO_ITEM* net2info = new NETINFO_ITEM( &brd, "net2", 2 );
207
208 net1info->SetNetClass( netclass1 );
209 net2info->SetNetClass( netclass2 );
210
211 PCB_TRACK trackA( &brd );
212 PCB_TRACK trackB( &brd );
213
214 trackA.SetNet( net1info );
215 trackB.SetNet( net2info );
216
217 trackB.SetLayer( F_Cu );
218
219 trackA.SetWidth( pcbIUScale.MilsToIU( 10 ) );
220 trackB.SetWidth( pcbIUScale.MilsToIU( 20 ) );
221
222 auto test =
223 [&]( const wxString& expr, const LIBEVAL::VALUE& expectedResult )
224 {
225 testEvalExpr( expr, expectedResult, &trackA, &trackB );
226 };
227
228 test( "A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))", VAL( 0.0 ) );
229 test( "A.Width > B.Width", VAL( 0.0 ) );
230 test( "A.Width + B.Width", VAL( pcbIUScale.MilsToIU( 10 ) + pcbIUScale.MilsToIU( 20 ) ) );
231 test( "A.Netclass", VAL( "HV_LINE" ) );
232 test( "A.Net_Class == 'HV_LINE'", VAL( 1.0 ) );
233 test( "(A.Netclass == 'HV_LINE') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')", VAL( 1.0 ) );
234 test( "A.Netclass + 1.0", VAL( 1.0 ) );
235 test( "A.hasNetclass('HV_LINE')", VAL( 1.0 ) );
236 test( "A.hasNetclass('HV_*')", VAL( 1.0 ) );
237 test( "A.existsOnLayer(B.Layer)", VAL( 1.0 ) );
238 test( "A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'", VAL( 1.0 ) );
239 test( "(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')", VAL( 1.0 ) );
240 test( "A.type == 'Via' && A.isMicroVia()", VAL( 0.0 ) );
241}
242
243
244BOOST_AUTO_TEST_CASE( IntrospectedExtendedNumericProperties )
245{
247 propMgr.Rebuild();
248
249 BOARD brd;
250 ZONE zone( &brd );
251
252 zone.SetLayer( F_Cu );
253 zone.SetAssignedPriority( 7 );
254 zone.SetHatchOrientation( EDA_ANGLE( 45.0, DEGREES_T ) );
255 zone.SetMinIslandArea( 123456789LL );
256
257 testEvalExpr( wxT( "A.Priority == 7" ), VAL( 1.0 ), &zone, &zone );
258 testEvalExpr( wxT( "A.Hatch_Orientation == 45deg" ), VAL( 1.0 ), &zone, &zone );
259 testEvalExpr( wxT( "A.Minimum_Island_Area == 123456789" ), VAL( 1.0 ), &zone, &zone );
260
261 PCB_SHAPE ellipse( &brd, SHAPE_T::ELLIPSE );
262 ellipse.SetEllipseRotation( EDA_ANGLE( 30.0, DEGREES_T ) );
263
264 testEvalExpr( wxT( "A.Ellipse_Rotation == 30deg" ), VAL( 1.0 ), &ellipse, &ellipse );
265
266 FOOTPRINT footprint( &brd );
267 footprint.SetLocalSolderPasteMarginRatio( 0.125 );
268
269 testEvalExpr( wxT( "A.Solderpaste_Margin_Ratio_Override == 0.125" ), VAL( 1.0 ), &footprint, &footprint );
270
271 footprint.SetLocalSolderPasteMarginRatio( std::nullopt );
272
273 testEvalExpr( wxT( "A.Solderpaste_Margin_Ratio_Override == null" ), VAL( 1.0 ), &footprint, &footprint );
274}
275
276
277BOOST_AUTO_TEST_CASE( UnitlessStringProperties )
278{
280 propMgr.Rebuild();
281
282 BOARD brd;
283 FOOTPRINT footprint( &brd );
284 PAD* pad = new PAD( &footprint );
285 PCB_TEXT text( &brd );
286
287 footprint.SetReference( wxT( "R1" ) );
288 footprint.SetValue( wxT( "4k7" ) );
289 pad->SetNumber( wxT( "2" ) );
290 footprint.Add( pad );
291 text.SetText( wxT( "4k7" ) );
292
293 testEvalExpr( wxT( "A.Pad_Number == '2'" ), VAL( 1.0 ), pad, pad );
294 testEvalExpr( wxT( "A.Pad_Number == 2" ), VAL( 1.0 ), pad, pad );
295 testEvalExpr( wxT( "A.Reference == 'R1'" ), VAL( 1.0 ), &footprint, &footprint );
296 testEvalExpr( wxT( "A.Text == '4k7'" ), VAL( 1.0 ), &text, &text );
297 testEvalExpr( wxT( "A.Text != '4700'" ), VAL( 1.0 ), &text, &text );
298 testEvalExpr( wxT( "A.Text == 4700" ), VAL( 1.0 ), &text, &text );
299 testEvalExpr( wxT( "A.getField('Value') > 3300" ), VAL( 1.0 ), &footprint, &footprint );
300 testEvalExpr( wxT( "A.getField('Value') > 3k3" ), VAL( 1.0 ), &footprint, &footprint );
301 testEvalExpr( wxT( "A.Text < 1" ), VAL( 0.0 ), &text, &text );
302}
303
304
305BOOST_AUTO_TEST_CASE( RenamedProperties )
306{
308 propMgr.Rebuild();
309
310 BOARD brd;
311 PCB_TRACK track( &brd );
312
313 track.SetStart( VECTOR2I( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 2.0 ) ) );
314 track.SetEnd( VECTOR2I( pcbIUScale.mmToIU( 3.0 ), pcbIUScale.mmToIU( 4.0 ) ) );
315
316 expectCompileSuccess( wxT( "A.Origin_X == 1mm" ) );
317 expectCompileSuccess( wxT( "A.Origin_Y == 2mm" ) );
318
319 testEvalExpr( wxT( "A.Origin_X == 1mm" ), VAL( 1.0 ), &track, &track );
320 testEvalExpr( wxT( "A.Origin_Y == 2mm" ), VAL( 1.0 ), &track, &track );
321 testEvalExpr( wxT( "A.Origin_X != A.End_X" ), VAL( 1.0 ), &track, &track );
322 testEvalExpr( wxT( "A.origin_y != A.End_Y" ), VAL( 1.0 ), &track, &track );
323
324 testEvalExpr( wxT( "A.Start_X == 1mm" ), VAL( 1.0 ), &track, &track );
325 testEvalExpr( wxT( "A.Start_Y == 2mm" ), VAL( 1.0 ), &track, &track );
326}
327
328
329BOOST_AUTO_TEST_CASE( IntrospectedColorProperties )
330{
332 propMgr.Rebuild();
333
334 BOARD brd;
335 PCB_TABLE table( &brd, 0 );
336
337 auto checkColor =
338 [&]( const COLOR4D& aColor, const wxString& aExpectedCss )
339 {
340 table.SetBorderColor( aColor );
341 BOOST_CHECK_EQUAL( aColor.ToCSSString(), aExpectedCss );
342
343 wxString expression = wxT( "A.Border_Color == '" ) + aExpectedCss + wxT( "'" );
344 testEvalExpr( expression, VAL( 1.0 ), &table, &table );
345 };
346
347 checkColor( COLOR4D( 0.25, 0.5, 0.75, 0.5 ), wxT( "rgba(64, 128, 191, 0.502)" ) );
348 checkColor( COLOR4D( 1.0, 0.0, 0.0, 1.0 ), wxT( "rgb(255, 0, 0)" ) );
349}
350
351
352BOOST_AUTO_TEST_CASE( ExpressionPropertyTypesAreSupported )
353{
355 propMgr.Rebuild();
356
357 std::set<std::pair<TYPE_ID, PROPERTY_BASE*>> seen;
358 std::map<wxString, std::set<LIBEVAL::VAR_TYPE_T>> fieldTypes;
359
360 for( const PROPERTY_MANAGER::CLASS_INFO& cls : propMgr.GetAllClasses() )
361 {
362 if( !propMgr.IsOfType( cls.type, TYPE_HASH( BOARD_ITEM ) ) )
363 continue;
364
365 for( PROPERTY_BASE* prop : cls.properties )
366 {
367 if( !seen.emplace( cls.type, prop ).second )
368 continue;
369
371
372 BOOST_CHECK_MESSAGE( kind != PCBEXPR_PROPERTY_KIND::UNSUPPORTED,
373 "Unsupported expression property: class=" << cls.name.mb_str()
374 << ", property=" << prop->Name().mb_str()
375 << ", type_hash=" << prop->TypeHash() );
376
378 fieldTypes[prop->Name()].insert( PCBEXPR_VAR_REF::ExpressionType( kind ) );
379 }
380 }
381
382 // PCB_TARGET::Shape is numeric while EDA_SHAPE::Shape is an enum, so a global
383 // expression reference cannot have one stable public type.
384 auto shapeTypes = fieldTypes.find( wxT( "Shape" ) );
385 BOOST_REQUIRE( shapeTypes != fieldTypes.end() );
386 BOOST_CHECK_EQUAL( shapeTypes->second.size(), 2u );
387 fieldTypes.erase( shapeTypes );
388
389 for( const auto& [field, types] : fieldTypes )
390 {
391 BOOST_CHECK_MESSAGE( types.size() == 1, "Incompatible expression types for property: " << field.mb_str() );
392 }
393
394 expectCompileError( wxT( "A.Shape" ) );
395}
396
397
398BOOST_AUTO_TEST_CASE( IntrospectedPropertyAvailability )
399{
401 propMgr.Rebuild();
402
403 BOARD brd;
404 ZONE zone( &brd );
405
406 zone.SetLayer( F_Cu );
407 zone.SetAssignedPriority( 7 );
408 zone.SetIsRuleArea( true );
409
410 testEvalExpr( wxT( "A.Priority == 7" ), VAL( 0.0 ), &zone, &zone );
411
412 zone.SetIsRuleArea( false );
413
414 testEvalExpr( wxT( "A.Priority == 7" ), VAL( 1.0 ), &zone, &zone );
415}
416
417
418BOOST_AUTO_TEST_CASE( InNetChainClassWildcard )
419{
421 propMgr.Rebuild();
422
423 BOARD brd;
424
425 std::shared_ptr<NET_SETTINGS> netSettings = brd.GetDesignSettings().m_NetSettings;
426 netSettings->SetNetChainClass( wxT( "ChainHS" ), wxT( "HighSpeed" ) );
427
428 NETINFO_ITEM* netUnclassified = new NETINFO_ITEM( &brd, "netA", 1 );
429 NETINFO_ITEM* netClassified = new NETINFO_ITEM( &brd, "netB", 2 );
430 NETINFO_ITEM* netNoChain = new NETINFO_ITEM( &brd, "netC", 3 );
431
432 netUnclassified->SetNetChain( wxT( "ChainOrphan" ) );
433 netClassified->SetNetChain( wxT( "ChainHS" ) );
434
435 PCB_TRACK trackUnclassified( &brd );
436 PCB_TRACK trackClassified( &brd );
437 PCB_TRACK trackNoChain( &brd );
438
439 trackUnclassified.SetNet( netUnclassified );
440 trackClassified.SetNet( netClassified );
441 trackNoChain.SetNet( netNoChain );
442
443 // A chain with no class assignment must not match any inNetChainClass() pattern,
444 // including the '*' wildcard.
445 testEvalExpr( wxT( "A.inNetChainClass('*')" ), VAL( 0.0 ), &trackUnclassified, &trackUnclassified );
446 testEvalExpr( wxT( "A.inNetChainClass('HighSpeed')" ), VAL( 0.0 ), &trackUnclassified, &trackUnclassified );
447
448 // Net with no chain at all must not match either.
449 testEvalExpr( wxT( "A.inNetChainClass('*')" ), VAL( 0.0 ), &trackNoChain, &trackNoChain );
450
451 // Properly classified chain must match both wildcard and exact patterns.
452 testEvalExpr( wxT( "A.inNetChainClass('*')" ), VAL( 1.0 ), &trackClassified, &trackClassified );
453 testEvalExpr( wxT( "A.inNetChainClass('HighSpeed')" ), VAL( 1.0 ), &trackClassified, &trackClassified );
454 testEvalExpr( wxT( "A.inNetChainClass('High*')" ), VAL( 1.0 ), &trackClassified, &trackClassified );
455 testEvalExpr( wxT( "A.inNetChainClass('LowSpeed')" ), VAL( 0.0 ), &trackClassified, &trackClassified );
456}
457
458BOOST_AUTO_TEST_CASE( StackedMicroviaExpression )
459{
461 propMgr.Rebuild();
462
463 BOARD brd;
464 brd.SetCopperLayerCount( 4 );
465
466 auto microvia = []( BOARD* aBoard, const VECTOR2I& aPos, PCB_LAYER_ID aTop, PCB_LAYER_ID aBottom )
467 {
468 PCB_VIA* via = new PCB_VIA( aBoard );
469
470 via->SetViaType( VIATYPE::MICROVIA );
471 via->SetPosition( aPos );
472 via->SetLayerPair( aTop, aBottom );
473 via->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.25 ) );
474 via->SetDrill( pcbIUScale.mmToIU( 0.1 ) );
475 aBoard->Add( via );
476
477 return via;
478 };
479
480 VECTOR2I origin( 0, 0 );
481 VECTOR2I away( pcbIUScale.mmToIU( 10 ), 0 );
482
483 PCB_VIA* upperHop = microvia( &brd, origin, F_Cu, In1_Cu );
484 PCB_VIA* lowerHop = microvia( &brd, origin, In1_Cu, In2_Cu );
485 PCB_VIA* lone = microvia( &brd, away, F_Cu, In1_Cu );
486
487 PCB_VIA* through = new PCB_VIA( &brd );
488
489 through->SetViaType( VIATYPE::THROUGH );
490 through->SetPosition( origin );
491 through->SetLayerPair( F_Cu, B_Cu );
492 through->SetWidth( PADSTACK::ALL_LAYERS, pcbIUScale.mmToIU( 0.6 ) );
493 through->SetDrill( pcbIUScale.mmToIU( 0.3 ) );
494 brd.Add( through );
495
496 // Both hops of a stack are in it, not just the one on top.
497 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 1.0 ), upperHop, upperHop );
498 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 1.0 ), lowerHop, lowerHop );
499
500 // A microvia landing on nothing is not a stack.
501 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 0.0 ), lone, lone );
502
503 // A through via sharing the position of a stack is not part of it.
504 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 0.0 ), through, through );
505
506 // The predicate composes with the rest of the language.
507 testEvalExpr( wxT( "A.isMicroVia() && !A.isStackedVia()" ), VAL( 1.0 ), lone, lone );
508
509 // The relation is cached for the whole board, so an edit has to drop it.
510 PCB_VIA* landing = microvia( &brd, away, In1_Cu, In2_Cu );
511 brd.IncrementTimeStamp();
512
513 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 1.0 ), lone, lone );
514 testEvalExpr( wxT( "A.isStackedVia()" ), VAL( 1.0 ), landing, landing );
515}
516
517BOOST_AUTO_TEST_CASE( ParentNavigation )
518{
520 propMgr.Rebuild();
521
522 BOARD brd;
523
524 FOOTPRINT fp( &brd );
525 fp.SetReference( wxT( "J1" ) );
526
527 // A text item living inside the footprint. Its direct parent is the footprint, so
528 // "A.Parent" navigates to J1.
529 PCB_TEXT* text = new PCB_TEXT( &fp );
530 text->SetText( wxT( "J1" ) );
531 fp.Add( text );
532
533 // The headline capability: getField() only returns a value when its receiver is a
534 // footprint, so this passes solely because navigation steps from the text to its parent.
535 testEvalExpr( wxT( "A.Parent.getField('Reference') == 'J1'" ), VAL( 1.0 ), text, text );
536
537 // The exact pattern from the issue (parent field compared to the text's own value).
538 testEvalExpr( wxT( "A.Parent.getField('Reference') == A.Text" ), VAL( 1.0 ), text, text );
539
540 // The parent resolves to a footprint object that can be type-queried.
541 testEvalExpr( wxT( "A.Parent.Type == 'Footprint'" ), VAL( 1.0 ), text, text );
542
543 // Regression: the terminal "Parent" string still yields the parent footprint reference,
544 // i.e. the object and the string refer to the same parent.
545 testEvalExpr( wxT( "A.Parent == 'J1'" ), VAL( 1.0 ), text, text );
546
547 // Without navigation getField() has a non-footprint receiver and returns "", so this must
548 // NOT match - it guards against the navigation silently applying to the base item.
549 testEvalExpr( wxT( "A.getField('Reference') == 'J1'" ), VAL( 0.0 ), text, text );
550
551 // Error cases. These are code-generation errors (not parse errors), which the shared
552 // testEvalExpr does not observe through Compile()'s return value, so check the pending-error
553 // status directly. None of these expressions contain a bare number, so the only error that
554 // can be raised is the unrecognized item/property we are testing for.
555 // An unknown property on the parent, an unknown navigation step, and navigation on the
556 // layer pseudo-item (which has no parent).
557 expectCompileError( wxT( "A.Parent.bogusProperty" ) );
558 expectCompileError( wxT( "A.bogus.Reference == 'J1'" ) );
559 expectCompileError( wxT( "L.Parent.Type == 'Footprint'" ) );
560}
561
562
563// A property missing on a child item resolves against its parent footprint.
564BOOST_AUTO_TEST_CASE( PropertyParentFallback )
565{
567
568 BOARD brd;
569
570 FOOTPRINT fp( &brd );
571 fp.SetReference( wxT( "J1" ) );
572
573 PCB_TEXT* text = new PCB_TEXT( &fp );
574 fp.Add( text );
575
576 testEvalExpr( wxT( "A.Reference == 'J1'" ), VAL( 1.0 ), text, text );
577 testEvalExpr( wxT( "A.Reference == 'J2'" ), VAL( 0.0 ), text, text );
578}
579
580
581// A bool property must be readable in a rule.
582BOOST_AUTO_TEST_CASE( BoolPropertyEvaluation )
583{
585
586 BOARD brd;
587
588 FOOTPRINT fp( &brd );
589
590 testEvalExpr( wxT( "A.Do_not_Populate == 0" ), VAL( 1.0 ), &fp, &fp );
591
592 fp.SetDNP( true );
593
594 testEvalExpr( wxT( "A.Do_not_Populate == 1" ), VAL( 1.0 ), &fp, &fp );
595}
596
597
598// Queries read flags and fields through the current assembly variant.
599BOOST_AUTO_TEST_CASE( VariantAwareEvaluation )
600{
602
603 BOARD brd;
604
605 FOOTPRINT fp( &brd );
606 fp.SetValue( wxT( "BaseVal" ) );
607
608 FOOTPRINT_VARIANT* variant = fp.AddVariant( wxT( "V1" ) );
609 variant->SetDNP( true );
610 variant->SetFieldValue( wxT( "Value" ), wxT( "VariantVal" ) );
611
612 brd.AddVariant( wxT( "V1" ) );
613 brd.SetCurrentVariant( wxT( "V1" ) );
614
615 testEvalExpr( wxT( "A.Do_not_Populate == 1" ), VAL( 1.0 ), &fp, &fp );
616 testEvalExpr( wxT( "A.getField('Value') == 'VariantVal'" ), VAL( 1.0 ), &fp, &fp );
617
618 // Without a current variant the base values apply.
619 brd.SetCurrentVariant( wxEmptyString );
620
621 testEvalExpr( wxT( "A.Do_not_Populate == 0" ), VAL( 1.0 ), &fp, &fp );
622 testEvalExpr( wxT( "A.getField('Value') == 'BaseVal'" ), VAL( 1.0 ), &fp, &fp );
623}
624
625
626// Reference resolves as a property with the fallback above, so the query normalizer
627// must leave it alone. getField() has no such fallback.
628BOOST_AUTO_TEST_CASE( FieldAliasNormalization )
629{
630 std::vector<PROPERTY_ROW_DATA> rows;
631
632 BOOST_CHECK_EQUAL( normalizeQueryFieldAliases( wxS( "A.Reference == 'R1'" ), rows ), wxS( "A.Reference == 'R1'" ) );
633
634 // A field with no property behind it needs the rewrite to resolve at all.
635 BOOST_CHECK_EQUAL( normalizeQueryFieldAliases( wxS( "A.Value == 'X'" ), rows ),
636 wxS( "A.getField('Value') == 'X'" ) );
637
638 PROPERTY_ROW_DATA customField;
639 customField.propertyName = wxS( "My Field" );
640 customField.property = nullptr;
642 customField.isMixed = false;
643
644 BOOST_CHECK_EQUAL( normalizeQueryFieldAliases( wxS( "A.My_Field == 'X'" ), { customField } ),
645 wxS( "A.getField('My Field') == 'X'" ) );
646}
647
648
649BOOST_AUTO_TEST_CASE( ReceiverValidation )
650{
651 expectCompileSuccess( wxT( "L == 'F.Cu'" ) );
652 expectCompileSuccess( wxT( "AB.isCoupledDiffPair()" ) );
653 expectCompileSuccess( wxT( "A.Parent.Reference == 'J1'" ) );
654 expectCompileSuccess( wxT( "A.Width == 1mm" ) );
655
656 expectCompileError( wxT( "L.Width == 1mm" ) );
657 expectCompileError( wxT( "AB.Width == A.Width" ) );
658 expectCompileError( wxT( "AB.Parent.Reference == 'J1'" ) );
659}
660
661
662BOOST_AUTO_TEST_CASE( LayerReceiverLayerField )
663{
664 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
665 PCBEXPR_UCODE ucode;
667
668 compiler.Compile( wxT( "L.Layer == '*.Paste'" ), &ucode, &preflight );
669 BOOST_REQUIRE( !compiler.IsErrorPending() );
670
671 BOARD brd;
672 PCB_TRACK track( &brd );
675
676 paste.SetItems( &track, &track );
677 copper.SetItems( &track, &track );
678
679 BOOST_CHECK_EQUAL( ucode.Run( &paste )->AsDouble(), 1.0 );
680 BOOST_CHECK_EQUAL( ucode.Run( &copper )->AsDouble(), 0.0 );
681}
682
683
684BOOST_AUTO_TEST_CASE( DynamicCourtyardArgument )
685{
687
688 BOARD board;
689 FOOTPRINT* target = new FOOTPRINT( &board );
690 target->SetReference( wxS( "U1" ) );
691 KI_TEST::DrawRect( *target, { 0, 0 }, { pcbIUScale.mmToIU( 4 ), pcbIUScale.mmToIU( 4 ) },
692 0, pcbIUScale.mmToIU( 0.05 ), F_CrtYd );
693 board.Add( target );
694
695 FOOTPRINT* other = new FOOTPRINT( &board );
696 other->SetReference( wxS( "U2" ) );
697 board.Add( other );
698
699 PCB_SHAPE graphic( other, SHAPE_T::SEGMENT );
700 graphic.SetLayer( F_Fab );
701 graphic.SetStart( { 0, 0 } );
702 graphic.SetEnd( { pcbIUScale.mmToIU( 1 ), 0 } );
703 graphic.SetWidth( pcbIUScale.mmToIU( 0.05 ) );
704
705 PCB_TEXT targetChild( target );
706 PCB_TEXT otherChild( other );
707
708 for( const wxString& expression : {
709 wxString( "A.intersectsFrontCourtyard(B.Parent)" ),
710 wxString( "A.intersectsCourtyard(B.Parent.Reference)" ),
711 wxString( "A.intersectsFrontCourtyard(B.Parent.getField('Reference'))" ) } )
712 {
713 BOOST_TEST_CONTEXT( expression )
714 {
715 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
716 PCBEXPR_UCODE ucode;
719
720 BOOST_REQUIRE( compiler.Compile( expression, &ucode, &preflight ) );
721 BOOST_REQUIRE_MESSAGE( !compiler.IsErrorPending(), compiler.GetError().message );
723
724 context.SetItems( &graphic, &targetChild );
725 BOOST_CHECK_EQUAL( ucode.Run( &context )->AsDouble(), 1.0 );
726
727 context.SetItems( &graphic, &otherChild );
728 BOOST_CHECK_EQUAL( ucode.Run( &context )->AsDouble(), 0.0 );
729
730 context.SetItems( &graphic, &targetChild );
731 BOOST_CHECK_EQUAL( ucode.Run( &context )->AsDouble(), 1.0 );
732 }
733 }
734}
735
736
737BOOST_AUTO_TEST_CASE( FunctionArgumentValidation )
738{
739 expectCompileError( wxS( "A.intersectsFrontCourtyard()" ) );
740 expectCompileError( wxS( "A.intersectsFrontCourtyard('')" ) );
741 expectCompileError( wxS( "A.memberOfFootprint('')" ) );
742 expectCompileError( wxS( "A.fromTo('U1-1')" ) );
743 expectCompileError( wxS( "A.intersectsFrontCourtyard(B.UnknownProperty)" ) );
744 expectCompileError( wxS( "A.intersectsFrontCourtyard(B.Parent.unknownFunction())" ) );
745}
746
747
748BOOST_AUTO_TEST_CASE( ExpressionStackCapacity )
749{
750 LIBEVAL::UCODE code;
751 LIBEVAL::CONTEXT context;
752
753 // Reach the exact capacity before reducing the operands to a single result.
754 for( int i = 0; i < LIBEVAL::CONTEXT::STACK_CAPACITY; ++i )
755 code.AddOp( new LIBEVAL::UOP( TR_UOP_PUSH_VALUE, std::make_unique<VAL>( 1.0 ) ) );
756
757 for( int i = 1; i < LIBEVAL::CONTEXT::STACK_CAPACITY; ++i )
758 code.AddOp( new LIBEVAL::UOP( TR_OP_ADD ) );
759
760 wxString error;
761 context.SetErrorCallback( [&]( const wxString& aMessage, int ) { error = aMessage; } );
762
764 BOOST_CHECK( error.IsEmpty() );
765 BOOST_CHECK_EQUAL( context.SP(), 0 );
766}
767
768
769BOOST_AUTO_TEST_CASE( ExpressionStackOverflow )
770{
772
773 wxString args = wxS( "'F.Cu'" );
774
775 for( int i = 0; i < LIBEVAL::CONTEXT::STACK_CAPACITY; ++i )
776 args += wxS( ", 'F.Cu'" );
777
778 PCBEXPR_COMPILER literalCompiler( new PCBEXPR_UNIT_RESOLVER() );
780 PCBEXPR_UCODE literalCode;
781
782 BOOST_CHECK( !literalCompiler.Compile( wxS( "A.existsOnLayer(" ) + args + wxS( ")" ),
783 &literalCode, &preflight ) );
784 BOOST_CHECK_EQUAL( literalCompiler.GetError().message,
785 wxS( "Expression evaluation stack overflow" ) );
786 BOOST_CHECK_EQUAL( preflight.SP(), 0 );
787 BOOST_CHECK( !preflight.HasErrorCallback() );
788
789 // A dynamic argument skips literal preflight. Exercise the runtime limit and the
790 // short-circuit loop with a condition like the one read from a custom rule file.
791 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
792 PCBEXPR_UCODE dynamicCode;
793 wxString expression = wxS( "A.Layer == 'F.Cu' && A.existsOnLayer(B.Layer, " )
794 + args + wxS( ")" );
795
796 BOOST_REQUIRE_MESSAGE( compiler.Compile( expression, &dynamicCode, &preflight ),
797 compiler.GetError().message );
798 BOOST_REQUIRE_MESSAGE( !compiler.IsErrorPending(), compiler.GetError().message );
799
800 BOARD board;
801 PCB_TRACK track( &board );
802 track.SetLayer( F_Cu );
803
805 context.SetItems( &track, &track );
806
807 wxString error;
808 context.SetErrorCallback( [&]( const wxString& aMessage, int ) { error = aMessage; } );
809
810 BOOST_CHECK_EQUAL( dynamicCode.Run( &context )->AsDouble(), 0.0 );
811 BOOST_CHECK_EQUAL( error, wxS( "Expression evaluation stack overflow" ) );
812 BOOST_CHECK_EQUAL( context.SP(), 0 );
813
814 PCBEXPR_UCODE validCode;
815 BOOST_REQUIRE( compiler.Compile( wxS( "A.existsOnLayer('F.Cu')" ), &validCode, &preflight ) );
816 BOOST_CHECK_EQUAL( validCode.Run( &context )->AsDouble(), 1.0 );
817}
818
819
820BOOST_AUTO_TEST_CASE( MalformedConditionSwappedItemRetry )
821{
823
824 BOARD board;
825 PCB_TRACK trackA( &board );
826 PCB_TRACK trackB( &board );
827 trackA.SetLayer( F_Cu );
828 trackB.SetLayer( B_Cu );
829
830 // The first run leaves unused arguments plus the function result on the stack.
831 // Without cleanup, the swapped-item retry exceeds the capacity at twice argumentCount.
832 for( int argumentCount : { LIBEVAL::CONTEXT::STACK_CAPACITY / 2,
834 {
835 BOOST_TEST_CONTEXT( argumentCount )
836 {
837 wxString args = wxS( "'F.Cu'" );
838
839 for( int i = 1; i < argumentCount; ++i )
840 args += wxS( ", 'F.Cu'" );
841
842 wxString source = wxS( "(version 1)(rule test (condition \"A.existsOnLayer(" )
843 + args + wxS( ")\")(constraint clearance (min 0.2mm)))" );
844 std::vector<std::shared_ptr<DRC_RULE>> rules;
845 DRC_RULES_PARSER parser( source, wxS( "stack cleanup regression" ) );
847
848 parser.Parse( rules, &reporter );
849 BOOST_REQUIRE_MESSAGE( !reporter.GetMessages().Contains( wxS( "ERROR:" ) ),
850 reporter.GetMessages() );
851 BOOST_REQUIRE_EQUAL( rules.size(), 1 );
852 BOOST_REQUIRE( rules.front()->m_Condition );
853 reporter.Clear();
854
855 BOOST_CHECK( !rules.front()->m_Condition->EvaluateFor(
856 &trackA, &trackB, CLEARANCE_CONSTRAINT, F_Cu, &reporter ) );
857
858 wxString messages = reporter.GetMessages();
859 BOOST_CHECK( !messages.Contains( wxS( "stack overflow" ) ) );
860 BOOST_CHECK_EQUAL( messages.Replace( wxS( "Malformed expression" ), wxEmptyString ), 2 );
861
862 // Also exercise the reused thread-local context used by DRC without a reporter.
863 BOOST_CHECK( !rules.front()->m_Condition->EvaluateFor(
864 &trackA, &trackB, CLEARANCE_CONSTRAINT, F_Cu ) );
865
866 DRC_RULE_CONDITION validCondition( wxS( "A.Layer == 'B.Cu' && B.Layer == 'F.Cu'" ) );
867 BOOST_REQUIRE( validCondition.Compile( nullptr ) );
868 BOOST_CHECK( validCondition.EvaluateFor(
869 &trackA, &trackB, CLEARANCE_CONSTRAINT, F_Cu ) );
870 }
871 }
872}
873
874
875BOOST_AUTO_TEST_CASE( SingleItemRulePreflight )
876{
878
879 for( const wxString& constraint : { wxString( "assertion \"A.Type == 'Graphic'\"" ),
880 wxString( "hole_size (min 0.2mm)" ),
881 wxString( "text_height (min 1mm)" ),
882 wxString( "text_thickness (min 0.1mm)" ),
883 wxString( "track_segment_length (min 1mm)" ),
884 wxString( "annular_width (min 0.1mm)" ),
885 wxString( "solder_mask_expansion (opt 0mm)" ),
886 wxString( "solder_paste_abs_margin (opt 0mm)" ),
887 wxString( "solder_paste_rel_margin (opt 0mm)" ),
888 wxString( "disallow track" ),
889 wxString( "via_diameter (min 0.5mm)" ),
890 wxString( "length (max 100mm)" ),
891 wxString( "net_chain_length (max 100mm)" ),
892 wxString( "stub_length (max 1mm)" ),
893 wxString( "return_path (layer 'B.Cu')" ),
894 wxString( "skew (max 1mm)" ),
895 wxString( "via_count (max 2)" ),
896 wxString( "via_dangling (max 0)" ),
897 wxString( "bridged_mask (min 0)" ),
898 wxString( "microvia_stack_depth (max 2)" ),
899 wxString( "hole_aspect_ratio (max 1)" ) } )
900 {
901 for( bool conditionFirst : { true, false } )
902 {
903 BOOST_TEST_CONTEXT( constraint << ", condition first: " << conditionFirst )
904 {
905 wxString condition = wxS( "(condition \"B.Type == 'Graphic'\")" );
906 wxString body = wxString::Format( wxS( "(constraint %s)" ), constraint );
907 wxString source = wxS( "(version 1)\n(rule test\n" )
908 + ( conditionFirst ? condition + wxS( "\n" ) + body
909 : body + wxS( "\n" ) + condition ) + wxS( "\n)" );
910 std::vector<std::shared_ptr<DRC_RULE>> rules;
912 wxString controlSource = source;
913 controlSource.Replace( wxS( "B.Type" ), wxS( "A.Type" ) );
914 DRC_RULES_PARSER controlParser( controlSource, wxS( "single item control" ) );
915 controlParser.Parse( rules, &reporter );
916 BOOST_REQUIRE_MESSAGE( !reporter.GetMessages().Contains( wxS( "ERROR:" ) ), reporter.GetMessages() );
917 reporter.Clear();
918
919 DRC_RULES_PARSER parser( source, wxS( "single item preflight" ) );
920 parser.Parse( rules, &reporter );
921 BOOST_CHECK_MESSAGE( reporter.GetMessages().Contains( wxS( "Item 'B'" ) ),
922 reporter.GetMessages() );
923
924 DRC_RULES_PARSER throwingParser( source, wxS( "single item preflight" ) );
925 BOOST_CHECK_EXCEPTION( throwingParser.Parse( rules, nullptr ), PARSE_ERROR,
926 [conditionFirst]( const PARSE_ERROR& error )
927 {
928 return error.What().Contains( wxS( "Item 'B' is not available" ) )
929 && error.lineNumber == ( conditionFirst ? 3 : 4 );
930 } );
931 }
932 }
933 }
934}
935
936
937BOOST_AUTO_TEST_CASE( PairConditionsInSingleItemRules )
938{
940
941 for( const wxString& body : {
942 wxString( "(condition \"A.intersectsFrontCourtyard(B.Parent)\")"
943 "(constraint assertion \"A.Type == 'Graphic'\")" ),
944 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint hole_size (min 0.2mm))" ),
945 wxString( "(constraint assertion \"B.Type == 'Graphic'\")" ),
946 wxString( "(constraint assertion \"A.intersectsFrontCourtyard(B.Parent.getField('Reference'))\")" ),
947 wxString( "(condition \"B.Type == 'Graphic'\")(constraint clearance (min 0.2mm))"
948 "(constraint hole_size (min 0.2mm))" ),
949 wxString( "(condition \"AB.isCoupledDiffPair() && B.Type == 'Track'\")"
950 "(constraint length (max 100mm))" ) } )
951 {
952 BOOST_TEST_CONTEXT( body )
953 {
954 std::vector<std::shared_ptr<DRC_RULE>> rules;
955 DRC_RULES_PARSER parser( wxS( "(version 1)(rule test " ) + body + wxS( ")" ), wxS( "preflight" ) );
956 BOOST_CHECK_EXCEPTION( parser.Parse( rules, nullptr ), PARSE_ERROR,
957 []( const PARSE_ERROR& error )
958 {
959 return error.What().Contains( wxS( "Item 'B' is not available" ) );
960 } );
961 }
962 }
963
964 for( const wxString& body : {
965 wxString( "(condition \"A.Reference == 'B.Width'\")(constraint hole_size (min 0.2mm))" ),
966 wxString( "(constraint assertion \"A.Type == 'Graphic'\")" ),
967 wxString( "(condition \"A.intersectsFrontCourtyard(B.Parent)\")"
968 "(constraint physical_clearance (min 100mm))" ),
969 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint diff_pair_gap (min 0.2mm))" ),
970 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint track_width (min 0.2mm))" ),
971 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint diff_pair_uncoupled (max 1mm))" ),
972 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint length (max 100mm))" ),
973 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint net_chain_length (max 100mm))" ),
974 wxString( "(condition \"AB.isCoupledDiffPair()\")(constraint skew (max 1mm))" ),
975 wxString( "(condition \"B.Type == 'Track'\")(constraint track_width (min 0.2mm))" ),
976 wxString( "(condition \"B.Type == 'Track'\")(constraint track_angle (min 45))" ),
977 wxString( "(condition \"B.Type == 'Zone'\")(constraint thermal_relief_gap (min 0.2mm))" ) } )
978 {
979 BOOST_TEST_CONTEXT( body )
980 {
981 std::vector<std::shared_ptr<DRC_RULE>> rules;
983 DRC_RULES_PARSER parser( wxS( "(version 1)(rule test " ) + body + wxS( ")" ), wxS( "preflight" ) );
984 parser.Parse( rules, &reporter );
985 BOOST_CHECK_MESSAGE( !reporter.GetMessages().Contains( wxS( "ERROR:" ) ), reporter.GetMessages() );
986 }
987 }
988}
989
990
991BOOST_AUTO_TEST_CASE( PairItemDependency )
992{
993 auto requiresPairItems =
994 []( const wxString& aExpr )
995 {
996 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
997 PCBEXPR_UCODE ucode;
999
1000 BOOST_REQUIRE( compiler.Compile( aExpr, &ucode, &preflight ) );
1001 return ucode.RequiresPairItems();
1002 };
1003
1004 BOOST_CHECK( !requiresPairItems( wxT( "A.Width == 1mm" ) ) );
1005 BOOST_CHECK( requiresPairItems( wxT( "B.Width == 1mm" ) ) );
1006 BOOST_CHECK( requiresPairItems( wxT( "AB.isCoupledDiffPair()" ) ) );
1007 BOOST_CHECK( !requiresPairItems( wxT( "A.Reference == 'B.Width'" ) ) );
1008}
1009
1010
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
Construction utilities for PCB tests.
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
void SetCurrentVariant(const wxString &aVariant)
Definition board.cpp:3016
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
void AddVariant(const wxString &aVariantName)
Definition board.cpp:3048
void IncrementTimeStamp()
Definition board.cpp:448
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
bool Compile(REPORTER *aReporter, int aSourceLine=0, int aSourceOffset=0)
bool EvaluateFor(const BOARD_ITEM *aItemA, const BOARD_ITEM *aItemB, int aConstraint, PCB_LAYER_ID aLayer, REPORTER *aReporter=nullptr)
Variant information for a footprint.
Definition footprint.h:178
void SetDNP(bool aDNP)
Definition footprint.h:193
void SetFieldValue(const wxString &aFieldName, const wxString &aValue)
Set a field value override for this variant.
Definition footprint.h:224
void SetDNP(bool aDNP=true)
Definition footprint.h:948
void SetLocalSolderPasteMarginRatio(std::optional< double > aRatio)
Definition footprint.h:488
void SetReference(const wxString &aReference)
Definition footprint.h:799
void SetValue(const wxString &aValue)
Definition footprint.h:822
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
FOOTPRINT_VARIANT * AddVariant(const wxString &aVariantName)
Add a new variant with the given name.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
wxString ToCSSString() const
Definition color4d.cpp:146
bool IsErrorPending() const
const ERROR_STATUS & GetError() const
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
void SetErrorCallback(ERROR_CALLBACK aCallback)
static constexpr int STACK_CAPACITY
void AddOp(UOP *uop)
VALUE * Run(CONTEXT *ctx)
virtual const wxString & AsString() const
virtual double AsDouble() const
VAR_TYPE_T GetType() const
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:44
Handle the data for a net.
Definition netinfo.h:50
void SetNetChain(const wxString &aNetChain)
Definition netinfo.h:123
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:232
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
bool RequiresPairItems() const
static PCBEXPR_PROPERTY_KIND ClassifyProperty(const PROPERTY_BASE *aProperty)
static LIBEVAL::VAR_TYPE_T ExpressionType(PCBEXPR_PROPERTY_KIND aKind)
void SetWidth(int aWidth) override
void SetEnd(const VECTOR2I &aEnd) override
void SetEllipseRotation(const EDA_ANGLE &aA) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
void SetDrill(int aDrill)
Definition pcb_track.h:831
void SetPosition(const VECTOR2I &aPoint) override
Definition pcb_track.h:616
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
For a via m_layer contains the top layer, the other layer is in m_bottomLayer/.
void SetViaType(VIATYPE aViaType)
Definition pcb_track.h:427
void SetWidth(int aWidth) override
virtual size_t TypeHash() const =0
Return type-id of the property type.
const wxString & Name() const
Definition property.h:221
Provide class metadata.
static PROPERTY_MANAGER & Instance()
void Rebuild()
Rebuild the list of all registered properties.
std::vector< CLASS_INFO > GetAllClasses()
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
A wrapper for reporting to a wxString object.
Definition reporter.h:242
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetHatchOrientation(const EDA_ANGLE &aStep)
Definition zone.h:332
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
void SetIsRuleArea(bool aEnable)
Definition zone.h:835
void SetAssignedPriority(unsigned aPriority)
Definition zone.h:117
void SetMinIslandArea(long long int aArea)
Definition zone.h:867
wxString normalizeQueryFieldAliases(const wxString &aExpression, const std::vector< PROPERTY_ROW_DATA > &aRows)
@ CLEARANCE_CONSTRAINT
@ NULL_CONSTRAINT
@ DEGREES_T
Definition eda_angle.h:30
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
std::string source
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ F_Paste
Definition layer_ids.h:100
@ B_Cu
Definition layer_ids.h:61
@ In2_Cu
Definition layer_ids.h:63
@ F_Fab
Definition layer_ids.h:115
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
#define TR_UOP_PUSH_VALUE
#define TR_OP_ADD
void DrawRect(FOOTPRINT &aFootprint, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
Draw a rectangle on a footprint.
PCBEXPR_PROPERTY_KIND
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
friend std::ostream & operator<<(std::ostream &os, const EXPR_TO_TEST &expr)
LIBEVAL::VALUE expectedResult
A filename or source description, a problem input line, a line number, a byte offset,...
PROPERTY_MATCH_MODE matchMode
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
const std::string table
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
std::vector< DATABASE_CONNECTION::ROW > rows
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
static void expectCompileError(const wxString &aExpr)
static void expectCompileSuccess(const wxString &aExpr)
LIBEVAL::VALUE VAL
static bool testEvalExpr(const wxString &expr, const LIBEVAL::VALUE &expectedResult, BOARD_ITEM *itemA, BOARD_ITEM *itemB, bool expectError=false)
BOOST_AUTO_TEST_CASE(SimpleExpressions)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708