KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pns_basics.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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
26#include <optional>
27
28#include <pcbnew/board.h>
29#include <pcbnew/pad.h>
30#include <pcbnew/pcb_track.h>
32
34#include <router/pns_item.h>
36#include <router/pns_node.h>
37#include <router/pns_router.h>
38#include <router/pns_segment.h>
39#include <router/pns_solid.h>
40#include <router/pns_via.h>
41
42static bool isCopper( const PNS::ITEM* aItem )
43{
44 if( !aItem )
45 return false;
46
47 BOARD_ITEM* parent = aItem->Parent();
48
49 if( parent && parent->Type() == PCB_PAD_T )
50 {
51 PAD* pad = static_cast<PAD*>( parent );
52
53 if( pad->IsAperturePad() || pad->IsNPTHWithNoCopper() )
54 return false;
55 }
56
57 return true;
58}
59
60
61static bool isHole( const PNS::ITEM* aItem )
62{
63 if( !aItem )
64 return false;
65
66 return aItem->OfKind( PNS::ITEM::HOLE_T );
67}
68
69
70static bool isEdge( const PNS::ITEM* aItem )
71{
72 if( !aItem )
73 return false;
74
75 const BOARD_ITEM *parent = aItem->BoardItem();
76
77 return parent && ( parent->IsOnLayer( Edge_Cuts ) || parent->IsOnLayer( Margin ) );
78}
79
80
82{
83public:
87
89
90 virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB,
91 bool aUseClearanceEpsilon = true ) override
92 {
93 PNS::CONSTRAINT constraint;
94 int rv = 0;
95 PNS_LAYER_RANGE layers;
96
97 if( !aB )
98 layers = aA->Layers();
99 else if( isEdge( aA ) )
100 layers = aB->Layers();
101 else if( isEdge( aB ) )
102 layers = aA->Layers();
103 else
104 layers = aA->Layers().Intersection( aB->Layers() );
105
106 // Normalize layer range (no -1 magic numbers)
108
109 for( int layer = layers.Start(); layer <= layers.End(); ++layer )
110 {
111 if( isHole( aA ) && isHole( aB) )
112 {
113 if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_HOLE_TO_HOLE, aA, aB, layer, &constraint ) )
114 {
115 if( constraint.m_Value.Min() > rv )
116 rv = constraint.m_Value.Min();
117 }
118 }
119 else if( isHole( aA ) || isHole( aB ) )
120 {
121 if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_HOLE_CLEARANCE, aA, aB, layer, &constraint ) )
122 {
123 if( constraint.m_Value.Min() > rv )
124 rv = constraint.m_Value.Min();
125 }
126 }
127 else if( isCopper( aA ) && ( !aB || isCopper( aB ) ) )
128 {
129 if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_CLEARANCE, aA, aB, layer, &constraint ) )
130 {
131 if( constraint.m_Value.Min() > rv )
132 rv = constraint.m_Value.Min();
133 }
134 }
135 else if( isEdge( aA ) || ( aB && isEdge( aB ) ) )
136 {
137 if( QueryConstraint( PNS::CONSTRAINT_TYPE::CT_EDGE_CLEARANCE, aA, aB, layer, &constraint ) )
138 {
139 if( constraint.m_Value.Min() > rv )
140 rv = constraint.m_Value.Min();
141 }
142 }
143 }
144
145 return rv;
146 }
147
148 virtual PNS::NET_HANDLE DpCoupledNet( PNS::NET_HANDLE aNet ) override { return nullptr; }
149 virtual int DpNetPolarity( PNS::NET_HANDLE aNet ) override { return -1; }
150
151 virtual bool DpNetPair( const PNS::ITEM* aItem, PNS::NET_HANDLE& aNetP,
152 PNS::NET_HANDLE& aNetN ) override
153 {
154 return false;
155 }
156
157 virtual int NetCode( PNS::NET_HANDLE aNet ) override
158 {
159 return -1;
160 }
161
162 virtual wxString NetName( PNS::NET_HANDLE aNet ) override
163 {
164 return wxEmptyString;
165 }
166
167 virtual bool QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA,
168 const PNS::ITEM* aItemB, int aLayer,
169 PNS::CONSTRAINT* aConstraint ) override
170 {
171 ITEM_KEY key;
172
173 key.a = aItemA;
174 key.b = aItemB;
175 key.type = aType;
176
177 auto it = m_ruleMap.find( key );
178
179 if( it == m_ruleMap.end() )
180 {
181 int cl;
182 switch( aType )
183 {
187 default: return false;
188 }
189
190 //printf("GetDef %s %s %d cl %d\n", aItemA->KindStr().c_str(), aItemB->KindStr().c_str(), aType, cl );
191
192 aConstraint->m_Type = aType;
193 aConstraint->m_Value.SetMin( cl );
194
195 return true;
196 }
197 else
198 {
199 *aConstraint = it->second;
200 }
201
202 return true;
203 }
204
205 int ClearanceEpsilon() const override { return m_clearanceEpsilon; }
206
207 struct ITEM_KEY
208 {
209 const PNS::ITEM* a = nullptr;
210 const PNS::ITEM* b = nullptr;
212
213 bool operator==( const ITEM_KEY& other ) const
214 {
215 return a == other.a && b == other.b && type == other.type;
216 }
217
218 bool operator<( const ITEM_KEY& other ) const
219 {
220 if( a < other.a )
221 {
222 return true;
223 }
224 else if ( a == other.a )
225 {
226 if( b < other.b )
227 return true;
228 else if ( b == other.b )
229 return type < other.type;
230 }
231
232 return false;
233 }
234 };
235
236 bool IsInNetTie( const PNS::ITEM* aA ) override { return false; }
237
238 bool IsNetTieExclusion( const PNS::ITEM* aItem, const VECTOR2I& aCollisionPos,
239 const PNS::ITEM* aCollidingItem ) override
240 {
241 return false;
242 }
243
244 bool IsDrilledHole( const PNS::ITEM* aItem ) override { return false; }
245
246 bool IsNonPlatedSlot( const PNS::ITEM* aItem ) override { return false; }
247
248 bool IsKeepout( const PNS::ITEM* aObstacle, const PNS::ITEM* aItem, bool* aEnforce ) override
249 {
250 return false;
251 }
252
253 void AddMockRule( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB,
254 PNS::CONSTRAINT& aConstraint )
255 {
256 ITEM_KEY key;
257
258 key.a = aItemA;
259 key.b = aItemB;
260 key.type = aType;
261
262 m_ruleMap[key] = aConstraint;
263 }
264
265 int m_defaultClearance = 200000;
266 int m_defaultHole2Hole = 220000;
268
269private:
270 std::map<ITEM_KEY, PNS::CONSTRAINT> m_ruleMap;
272};
273
274struct PNS_TEST_FIXTURE;
275
277{
278public:
280 m_testFixture( aFixture )
281 {}
282
284
285 void HideItem( PNS::ITEM* aItem ) override {};
286 void DisplayItem( const PNS::ITEM* aItem, int aClearance, bool aEdit = false,
287 int aFlags = 0 ) override {};
289
290 bool TestInheritTrackWidth( PNS::ITEM* aItem, int* aInheritedWidth,
291 const VECTOR2I& aStartPosition = VECTOR2I() )
292 {
293 m_startLayer = aItem->Layer();
294 return inheritTrackWidth( aItem, aInheritedWidth, aStartPosition );
295 }
296
297private:
299};
300
301
317
318
323
324static void dumpObstacles( const PNS::NODE::OBSTACLES &obstacles )
325{
326 for( const PNS::OBSTACLE& obs : obstacles )
327 {
328 BOOST_TEST_MESSAGE( wxString::Format( "%p [%s] - %p [%s], clearance %d",
329 obs.m_head, obs.m_head->KindStr().c_str(),
330 obs.m_item, obs.m_item->KindStr().c_str(),
331 obs.m_clearance ) );
332 }
333}
334
336{
337 PNS::VIA* v1 = new PNS::VIA( VECTOR2I( 0, 1000000 ), PNS_LAYER_RANGE( F_Cu, B_Cu ), 50000, 10000 );
338 PNS::VIA* v2 = new PNS::VIA( VECTOR2I( 0, 2000000 ), PNS_LAYER_RANGE( F_Cu, B_Cu ), 50000, 10000 );
339
340 std::unique_ptr<PNS::NODE> world ( new PNS::NODE );
341
342 v1->SetNet( (PNS::NET_HANDLE) 1 );
343 v2->SetNet( (PNS::NET_HANDLE) 2 );
344
345 world->SetMaxClearance( 10000000 );
346 world->SetRuleResolver( &m_ruleResolver );
347
348 world->AddRaw( v1 );
349 world->AddRaw( v2 );
350
351 BOOST_TEST_MESSAGE( "via to via, no violations" );
352 {
353 PNS::NODE::OBSTACLES obstacles;
354 int count = world->QueryColliding( v1, obstacles );
355 dumpObstacles( obstacles );
356 BOOST_CHECK_EQUAL( obstacles.size(), 0 );
357 BOOST_CHECK_EQUAL( count, 0 );
358 }
359
360 BOOST_TEST_MESSAGE( "via to via, forced copper to copper violation" );
361 {
362 PNS::NODE::OBSTACLES obstacles;
363 m_ruleResolver.m_defaultClearance = 1000000;
364 world->QueryColliding( v1, obstacles );
365 dumpObstacles( obstacles );
366
367 BOOST_CHECK_EQUAL( obstacles.size(), 1 );
368 const auto& first = *obstacles.begin();
369
370 BOOST_CHECK_EQUAL( first.m_head, v1 );
371 BOOST_CHECK_EQUAL( first.m_item, v2 );
372 BOOST_CHECK_EQUAL( first.m_clearance, m_ruleResolver.m_defaultClearance );
373 }
374
375 BOOST_TEST_MESSAGE( "via to via, forced hole to hole violation" );
376 {
377 PNS::NODE::OBSTACLES obstacles;
378 m_ruleResolver.m_defaultClearance = 200000;
379 m_ruleResolver.m_defaultHole2Hole = 1000000;
380
381 world->QueryColliding( v1, obstacles );
382 dumpObstacles( obstacles );
383
384 BOOST_CHECK_EQUAL( obstacles.size(), 1 );
385 auto iter = obstacles.begin();
386 const auto& first = *iter++;
387
388 BOOST_CHECK_EQUAL( first.m_head, v1->Hole() );
389 BOOST_CHECK_EQUAL( first.m_item, v2->Hole() );
390 BOOST_CHECK_EQUAL( first.m_clearance, m_ruleResolver.m_defaultHole2Hole );
391 }
392
393 BOOST_TEST_MESSAGE( "via to via, forced copper to hole violation" );
394 {
395 PNS::NODE::OBSTACLES obstacles;
396 m_ruleResolver.m_defaultHole2Hole = 220000;
397 m_ruleResolver.m_defaultHole2Copper = 1000000;
398
399 world->QueryColliding( v1, obstacles );
400 dumpObstacles( obstacles );
401
402 BOOST_CHECK_EQUAL( obstacles.size(), 2 );
403 auto iter = obstacles.begin();
404 const auto& first = *iter++;
405
406 // There is no guarantee on what order the two collisions will be in...
407 BOOST_CHECK( ( first.m_head == v1 && first.m_item == v2->Hole() )
408 || ( first.m_head == v1->Hole() && first.m_item == v2 ) );
409
410 BOOST_CHECK_EQUAL( first.m_clearance, m_ruleResolver.m_defaultHole2Copper );
411 }
412}
413
414
415BOOST_FIXTURE_TEST_CASE( PNSViaBackdrillRetention, PNS_TEST_FIXTURE )
416{
417 PNS::VIA via( VECTOR2I( 1000, 2000 ), PNS_LAYER_RANGE( F_Cu, B_Cu ), 40000, 20000, nullptr,
419 via.SetHoleLayers( PNS_LAYER_RANGE( F_Cu, In2_Cu ) );
420 via.SetHolePostMachining( std::optional<PAD_DRILL_POST_MACHINING_MODE>( PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ) );
421 via.SetSecondaryDrill( std::optional<int>( 12000 ) );
422 via.SetSecondaryHoleLayers( std::optional<PNS_LAYER_RANGE>( PNS_LAYER_RANGE( F_Cu, In1_Cu ) ) );
423 via.SetSecondaryHolePostMachining( std::optional<PAD_DRILL_POST_MACHINING_MODE>( PAD_DRILL_POST_MACHINING_MODE::NOT_POST_MACHINED ) );
424
425 PNS::VIA viaCopy( via );
426 std::unique_ptr<PNS::VIA> viaClone( via.Clone() );
427
428 auto checkVia = [&]( const PNS::VIA& candidate )
429 {
430 BOOST_CHECK_EQUAL( candidate.HoleLayers().Start(), via.HoleLayers().Start() );
431 BOOST_CHECK_EQUAL( candidate.HoleLayers().End(), via.HoleLayers().End() );
432 BOOST_CHECK( candidate.HolePostMachining().has_value() );
433 BOOST_CHECK( candidate.HolePostMachining().value() == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK );
434 BOOST_CHECK( candidate.SecondaryDrill().has_value() );
435 BOOST_CHECK_EQUAL( candidate.SecondaryDrill().value(), via.SecondaryDrill().value() );
436 BOOST_CHECK( candidate.SecondaryHoleLayers().has_value() );
437 BOOST_CHECK_EQUAL( candidate.SecondaryHoleLayers()->Start(),
438 via.SecondaryHoleLayers()->Start() );
439 BOOST_CHECK_EQUAL( candidate.SecondaryHoleLayers()->End(),
440 via.SecondaryHoleLayers()->End() );
441 BOOST_CHECK( candidate.SecondaryHolePostMachining().has_value() );
442
443 // run this BOOST_CHECK only if possible to avoid crash
444 if( candidate.SecondaryHolePostMachining().has_value() )
445 BOOST_CHECK( candidate.SecondaryHolePostMachining().value() == via.SecondaryHolePostMachining().value() );
446 };
447
448 checkVia( viaCopy );
449 checkVia( *viaClone );
450}
451
452
453BOOST_AUTO_TEST_CASE( PCBViaBackdrillCloneRetainsData )
454{
455 BOARD board;
456 PCB_VIA via( &board );
457
458 via.SetPrimaryDrillStartLayer( F_Cu );
459 via.SetPrimaryDrillEndLayer( B_Cu );
460 via.SetFrontPostMachining( std::optional<PAD_DRILL_POST_MACHINING_MODE>( PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ) );
461 via.SetSecondaryDrillSize( std::optional<int>( 15000 ) );
462 via.SetSecondaryDrillStartLayer( F_Cu );
463 via.SetSecondaryDrillEndLayer( In2_Cu );
464
465 via.SetBackPostMachining( std::optional<PAD_DRILL_POST_MACHINING_MODE>( PAD_DRILL_POST_MACHINING_MODE::COUNTERBORE ) );
466 via.SetTertiaryDrillSize( std::optional<int>( 8000 ) );
467 via.SetTertiaryDrillStartLayer( B_Cu );
468 via.SetTertiaryDrillEndLayer( In4_Cu );
469
470 PCB_VIA viaCopy( via );
471 std::unique_ptr<PCB_VIA> viaClone( static_cast<PCB_VIA*>( via.Clone() ) );
472
473 auto checkVia = [&]( const PCB_VIA& candidate )
474 {
475 BOOST_CHECK_EQUAL( candidate.GetPrimaryDrillStartLayer(), via.GetPrimaryDrillStartLayer() );
476 BOOST_CHECK_EQUAL( candidate.GetPrimaryDrillEndLayer(), via.GetPrimaryDrillEndLayer() );
477 BOOST_CHECK( candidate.GetFrontPostMachining().has_value() );
478 BOOST_CHECK_EQUAL( static_cast<int>( candidate.GetFrontPostMachining().value() ),
479 static_cast<int>( via.GetFrontPostMachining().value() ) );
480 BOOST_CHECK( candidate.GetSecondaryDrillSize().has_value() );
481 BOOST_CHECK_EQUAL( candidate.GetSecondaryDrillSize().value(),
482 via.GetSecondaryDrillSize().value() );
483 BOOST_CHECK_EQUAL( candidate.GetSecondaryDrillStartLayer(),
484 via.GetSecondaryDrillStartLayer() );
485 BOOST_CHECK_EQUAL( candidate.GetSecondaryDrillEndLayer(),
486 via.GetSecondaryDrillEndLayer() );
487
488 BOOST_CHECK( candidate.GetBackPostMachining().has_value() );
489 BOOST_CHECK_EQUAL( static_cast<int>( candidate.GetBackPostMachining().value() ),
490 static_cast<int>( via.GetBackPostMachining().value() ) );
491 BOOST_CHECK( candidate.GetTertiaryDrillSize().has_value() );
492 BOOST_CHECK_EQUAL( candidate.GetTertiaryDrillSize().value(),
493 via.GetTertiaryDrillSize().value() );
494 BOOST_CHECK_EQUAL( candidate.GetTertiaryDrillStartLayer(),
495 via.GetTertiaryDrillStartLayer() );
496 BOOST_CHECK_EQUAL( candidate.GetTertiaryDrillEndLayer(),
497 via.GetTertiaryDrillEndLayer() );
498 };
499
500 checkVia( viaCopy );
501 checkVia( *viaClone );
502}
503
504
513BOOST_AUTO_TEST_CASE( PNSLayerRangeSwapBehavior )
514{
515 // On a 2-layer board with FRONT_INNER_BACK mode, BoardCopperLayerCount() returns 2.
516 // The code would calculate PNS_LAYER_RANGE(1, 2 - 2) = PNS_LAYER_RANGE(1, 0)
517 // Since start > end, the constructor swaps them to (0, 1), which would span
518 // both F_Cu and B_Cu incorrectly.
519
520 PNS_LAYER_RANGE innerLayersRange2Layer( 1, 0 ); // What would happen on 2-layer board
521
522 // Verify the swap behavior that causes the bug
523 BOOST_CHECK_EQUAL( innerLayersRange2Layer.Start(), 0 );
524 BOOST_CHECK_EQUAL( innerLayersRange2Layer.End(), 1 );
525 BOOST_CHECK( innerLayersRange2Layer.Overlaps( 0 ) ); // F_Cu
526 BOOST_CHECK( innerLayersRange2Layer.Overlaps( 1 ) ); // B_Cu
527
528 // On a 4-layer board, inner layers are 1 and 2, so PNS_LAYER_RANGE(1, 4-2) = (1, 2)
529 PNS_LAYER_RANGE innerLayersRange4Layer( 1, 2 ); // Correct for 4-layer board
530
531 BOOST_CHECK_EQUAL( innerLayersRange4Layer.Start(), 1 );
532 BOOST_CHECK_EQUAL( innerLayersRange4Layer.End(), 2 );
533 BOOST_CHECK( !innerLayersRange4Layer.Overlaps( 0 ) ); // F_Cu - should not overlap
534 BOOST_CHECK( innerLayersRange4Layer.Overlaps( 1 ) ); // In1_Cu
535 BOOST_CHECK( innerLayersRange4Layer.Overlaps( 2 ) ); // In2_Cu
536 BOOST_CHECK( !innerLayersRange4Layer.Overlaps( 3 ) ); // B_Cu - should not overlap
537}
538
539
547BOOST_FIXTURE_TEST_CASE( PNSSegmentSplitPreservesLockedState, PNS_TEST_FIXTURE )
548{
549 std::unique_ptr<PNS::NODE> world( new PNS::NODE );
550 world->SetMaxClearance( 10000000 );
551 world->SetRuleResolver( &m_ruleResolver );
552
554
555 VECTOR2I segStart( 0, 0 );
556 VECTOR2I segEnd( 10000000, 0 );
557 VECTOR2I splitPt( 5000000, 0 );
558
559 PNS::SEGMENT* lockedSeg = new PNS::SEGMENT( SEG( segStart, segEnd ), net );
560 lockedSeg->SetWidth( 250000 );
561 lockedSeg->SetLayers( PNS_LAYER_RANGE( F_Cu ) );
562 lockedSeg->Mark( PNS::MK_LOCKED );
563
564 BOOST_CHECK( lockedSeg->IsLocked() );
565
566 world->AddRaw( lockedSeg );
567
568 // Clone the locked segment and set up two halves (simulating SplitAdjacentSegments)
569 std::unique_ptr<PNS::SEGMENT> clone1( PNS::Clone( *lockedSeg ) );
570 std::unique_ptr<PNS::SEGMENT> clone2( PNS::Clone( *lockedSeg ) );
571
572 clone1->SetEnds( segStart, splitPt );
573 clone2->SetEnds( splitPt, segEnd );
574
575 BOOST_CHECK_MESSAGE( clone1->IsLocked(),
576 "First half of split locked segment must retain locked state" );
577 BOOST_CHECK_MESSAGE( clone2->IsLocked(),
578 "Second half of split locked segment must retain locked state" );
579 BOOST_CHECK_EQUAL( clone1->Width(), lockedSeg->Width() );
580 BOOST_CHECK_EQUAL( clone2->Width(), lockedSeg->Width() );
581}
582
583
591BOOST_FIXTURE_TEST_CASE( PNSInheritTrackWidthCursorProximity, PNS_TEST_FIXTURE )
592{
593 std::unique_ptr<PNS::NODE> world( new PNS::NODE );
594 world->SetMaxClearance( 10000000 );
595 world->SetRuleResolver( &m_ruleResolver );
596
597 VECTOR2I padPos( 0, 0 );
599
600 // Pad at origin with a small circular shape
602 pad->SetShape( new SHAPE_CIRCLE( padPos, 500000 ) );
603 pad->SetPos( padPos );
604 pad->SetLayers( PNS_LAYER_RANGE( F_Cu ) );
605 pad->SetNet( net );
606 world->AddRaw( pad );
607
608 // Narrow track going right (250um width)
609 int narrowWidth = 250000;
610 PNS::SEGMENT* narrowSeg = new PNS::SEGMENT( SEG( padPos, VECTOR2I( 5000000, 0 ) ), net );
611 narrowSeg->SetWidth( narrowWidth );
612 narrowSeg->SetLayers( PNS_LAYER_RANGE( F_Cu ) );
613 world->AddRaw( narrowSeg );
614
615 // Wide track going up (500um width)
616 int wideWidth = 500000;
617 PNS::SEGMENT* wideSeg = new PNS::SEGMENT( SEG( padPos, VECTOR2I( 0, -5000000 ) ), net );
618 wideSeg->SetWidth( wideWidth );
619 wideSeg->SetLayers( PNS_LAYER_RANGE( F_Cu ) );
620 world->AddRaw( wideSeg );
621
622 int inherited = 0;
623
624 // Without cursor position, should fall back to minimum width
625 BOOST_CHECK( m_iface->TestInheritTrackWidth( pad, &inherited ) );
626 BOOST_CHECK_EQUAL( inherited, narrowWidth );
627
628 // Cursor near the narrow track (to the right) should select narrow width
629 inherited = 0;
630 BOOST_CHECK( m_iface->TestInheritTrackWidth( pad, &inherited, VECTOR2I( 2000000, 0 ) ) );
631 BOOST_CHECK_EQUAL( inherited, narrowWidth );
632
633 // Cursor near the wide track (upward) should select wide width
634 inherited = 0;
635 BOOST_CHECK( m_iface->TestInheritTrackWidth( pad, &inherited, VECTOR2I( 0, -2000000 ) ) );
636 BOOST_CHECK_EQUAL( inherited, wideWidth );
637
638 // Cursor slightly offset toward narrow track should still select narrow
639 inherited = 0;
640 BOOST_CHECK( m_iface->TestInheritTrackWidth( pad, &inherited, VECTOR2I( 100000, 50000 ) ) );
641 BOOST_CHECK_EQUAL( inherited, narrowWidth );
642
643 // Cursor slightly offset toward wide track should select wide
644 inherited = 0;
645 BOOST_CHECK( m_iface->TestInheritTrackWidth( pad, &inherited, VECTOR2I( 50000, -100000 ) ) );
646 BOOST_CHECK_EQUAL( inherited, wideWidth );
647}
648
649
657BOOST_AUTO_TEST_CASE( PCBExprGeometryDependentFunctionDetection )
658{
659 PCBEXPR_COMPILER compiler( new PCBEXPR_UNIT_RESOLVER() );
660
661 auto compileAndCheck = [&]( const wxString& aExpr, bool aExpectGeometry )
662 {
663 PCBEXPR_UCODE ucode;
664 PCBEXPR_CONTEXT ctx( 0, F_Cu );
665
666 bool ok = compiler.Compile( aExpr.ToUTF8().data(), &ucode, &ctx );
667 BOOST_CHECK_MESSAGE( ok, "Failed to compile: " + aExpr );
668
669 if( ok )
670 {
671 BOOST_CHECK_MESSAGE( ucode.HasGeometryDependentFunctions() == aExpectGeometry,
672 wxString::Format( "Expression '%s': expected geometry=%s, got %s",
673 aExpr,
674 aExpectGeometry ? "true" : "false",
676 ? "true" : "false" ) );
677 }
678 };
679
680 // Property-based conditions should NOT be geometry-dependent
681 compileAndCheck( wxT( "A.NetClass == 'Power'" ), false );
682 compileAndCheck( wxT( "A.Type == 'via'" ), false );
683 compileAndCheck( wxT( "A.NetName == '/VCC'" ), false );
684
685 // Geometry-dependent functions SHOULD be detected
686 compileAndCheck( wxT( "A.intersectsCourtyard('U1')" ), true );
687 compileAndCheck( wxT( "A.intersectsArea('Zone1')" ), true );
688 compileAndCheck( wxT( "A.enclosedByArea('Zone1')" ), true );
689 compileAndCheck( wxT( "A.intersectsFrontCourtyard('U1')" ), true );
690 compileAndCheck( wxT( "A.intersectsBackCourtyard('U1')" ), true );
691
692 // Deprecated aliases should also be detected
693 compileAndCheck( wxT( "A.insideCourtyard('U1')" ), true );
694 compileAndCheck( wxT( "A.insideArea('Zone1')" ), true );
695}
696
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:319
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
T Min() const
Definition minoptmax.h:33
void SetMin(T v)
Definition minoptmax.h:41
PNS::RULE_RESOLVER * GetRuleResolver() override
void DisplayItem(const PNS::ITEM *aItem, int aClearance, bool aEdit=false, int aFlags=0) override
void HideItem(PNS::ITEM *aItem) override
MOCK_PNS_KICAD_IFACE(PNS_TEST_FIXTURE *aFixture)
PNS_TEST_FIXTURE * m_testFixture
bool TestInheritTrackWidth(PNS::ITEM *aItem, int *aInheritedWidth, const VECTOR2I &aStartPosition=VECTOR2I())
virtual int NetCode(PNS::NET_HANDLE aNet) override
bool IsNetTieExclusion(const PNS::ITEM *aItem, const VECTOR2I &aCollisionPos, const PNS::ITEM *aCollidingItem) override
bool IsKeepout(const PNS::ITEM *aObstacle, const PNS::ITEM *aItem, bool *aEnforce) override
virtual int Clearance(const PNS::ITEM *aA, const PNS::ITEM *aB, bool aUseClearanceEpsilon=true) override
virtual bool QueryConstraint(PNS::CONSTRAINT_TYPE aType, const PNS::ITEM *aItemA, const PNS::ITEM *aItemB, int aLayer, PNS::CONSTRAINT *aConstraint) override
bool IsInNetTie(const PNS::ITEM *aA) override
std::map< ITEM_KEY, PNS::CONSTRAINT > m_ruleMap
virtual PNS::NET_HANDLE DpCoupledNet(PNS::NET_HANDLE aNet) override
bool IsDrilledHole(const PNS::ITEM *aItem) override
void AddMockRule(PNS::CONSTRAINT_TYPE aType, const PNS::ITEM *aItemA, const PNS::ITEM *aItemB, PNS::CONSTRAINT &aConstraint)
bool IsNonPlatedSlot(const PNS::ITEM *aItem) override
virtual bool DpNetPair(const PNS::ITEM *aItem, PNS::NET_HANDLE &aNetP, PNS::NET_HANDLE &aNetN) override
virtual wxString NetName(PNS::NET_HANDLE aNet) override
int ClearanceEpsilon() const override
virtual int DpNetPolarity(PNS::NET_HANDLE aNet) override
Definition pad.h:55
bool HasGeometryDependentFunctions() const
Base class for PNS router board items.
Definition pns_item.h:98
BOARD_ITEM * Parent() const
Definition pns_item.h:199
void SetLayers(const PNS_LAYER_RANGE &aLayers)
Definition pns_item.h:213
const PNS_LAYER_RANGE & Layers() const
Definition pns_item.h:212
virtual int Layer() const
Definition pns_item.h:216
bool OfKind(int aKindMask) const
Definition pns_item.h:181
virtual void Mark(int aMarker) const
Definition pns_item.h:261
virtual BOARD_ITEM * BoardItem() const
Definition pns_item.h:207
bool IsLocked() const
Definition pns_item.h:278
Keep the router "world" - i.e.
Definition pns_node.h:240
std::set< OBSTACLE > OBSTACLES
Definition pns_node.h:252
int Width() const override
Definition pns_segment.h:88
void SetWidth(int aWidth) override
Definition pns_segment.h:83
bool inheritTrackWidth(PNS::ITEM *aItem, int *aInheritedWidth, const VECTOR2I &aStartPosition)
Represent a contiguous set of PCB layers.
int Start() const
bool Overlaps(const PNS_LAYER_RANGE &aOther) const
int End() const
PNS_LAYER_RANGE Intersection(const PNS_LAYER_RANGE &aOther) const
Shortcut for comparisons/overlap tests.
Definition seg.h:42
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition layer_ids.h:174
@ Edge_Cuts
Definition layer_ids.h:112
@ B_Cu
Definition layer_ids.h:65
@ In2_Cu
Definition layer_ids.h:67
@ Margin
Definition layer_ids.h:113
@ In4_Cu
Definition layer_ids.h:69
@ In1_Cu
Definition layer_ids.h:66
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:171
@ F_Cu
Definition layer_ids.h:64
CONSTRAINT_TYPE
Definition pns_node.h:52
void * NET_HANDLE
Definition pns_item.h:55
@ MK_LOCKED
Definition pns_item.h:45
std::unique_ptr< typename std::remove_const< T >::type > Clone(const T &aItem)
Definition pns_item.h:344
bool operator<(const ITEM_KEY &other) const
bool operator==(const ITEM_KEY &other) const
An abstract function object, returning a design rule (clearance, diff pair gap, etc) required between...
Definition pns_node.h:73
MINOPTMAX< int > m_Value
Definition pns_node.h:75
CONSTRAINT_TYPE m_Type
Definition pns_node.h:74
Hold an object colliding with another object, along with some useful data about the collision.
Definition pns_node.h:88
SETTINGS_MANAGER m_settingsManager
MOCK_RULE_RESOLVER m_ruleResolver
PNS::ROUTER * m_router
MOCK_PNS_KICAD_IFACE * m_iface
VECTOR3I v1(5, 5, 5)
static bool isEdge(const PNS::ITEM *aItem)
static bool isHole(const PNS::ITEM *aItem)
static void dumpObstacles(const PNS::NODE::OBSTACLES &obstacles)
BOOST_FIXTURE_TEST_CASE(PNSHoleCollisions, PNS_TEST_FIXTURE)
static bool isCopper(const PNS::ITEM *aItem)
BOOST_AUTO_TEST_CASE(PCBViaBackdrillCloneRetainsData)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I v2(1, 0)
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:87
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695