25#include <boost/test/data/test_case.hpp>
68 for(
PAD*
pad : m_board->Footprints()[0]->Pads() )
70 if(
pad->GetNumber() ==
"2" ||
pad->GetNumber() ==
"4" ||
pad->GetNumber() ==
"6" )
81 for(
PCB_TRACK* track : m_board->Tracks() )
90 track->SetWidth( track->GetWidth() +
delta +
delta );
94 arc12 = track->m_Uuid;
100 bool foundPad2Error =
false;
101 bool foundPad4Error =
false;
102 bool foundPad6Error =
false;
103 bool foundArc8Error =
false;
104 bool foundArc12Error =
false;
105 bool foundOtherError =
false;
110 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
111 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
115 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
116 PAD* pad_a =
dynamic_cast<PAD*
>( item_a );
119 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
120 PAD* pad_b =
dynamic_cast<PAD*
>( item_b );
123 if( pad_a && pad_a->
GetNumber() ==
"2" ) foundPad2Error =
true;
124 else if( pad_a && pad_a->
GetNumber() ==
"4" ) foundPad4Error =
true;
125 else if( pad_a && pad_a->
GetNumber() ==
"6" ) foundPad6Error =
true;
126 else if( pad_b && pad_b->
GetNumber() ==
"2" ) foundPad2Error =
true;
127 else if( pad_b && pad_b->
GetNumber() ==
"4" ) foundPad4Error =
true;
128 else if( pad_b && pad_b->
GetNumber() ==
"6" ) foundPad6Error =
true;
129 else if( trk_a && trk_a->
m_Uuid == arc8 ) foundArc8Error =
true;
130 else if( trk_a && trk_a->
m_Uuid == arc12 ) foundArc12Error =
true;
131 else if( trk_b && trk_b->
m_Uuid == arc8 ) foundArc8Error =
true;
132 else if( trk_b && trk_b->
m_Uuid == arc12 ) foundArc12Error =
true;
133 else foundOtherError =
true;
163 for(
ZONE* zone : m_board->Zones() )
165 if( zone->GetLayerSet().Contains(
F_Cu ) )
202 std::vector<DRC_ITEM> violations;
205 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
206 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
209 violations.push_back( *aItem );
214 if( violations.empty() )
223 std::map<KIID, EDA_ITEM*> itemMap;
224 m_board->FillItemMap( itemMap );
226 for(
const DRC_ITEM& item : violations )
229 BOOST_ERROR( wxString::Format(
"Zone fill regression: %s failed", relPath ) );
249 std::vector<DRC_ITEM> violations;
252 [&](
const std::shared_ptr<DRC_ITEM>& aItem,
const VECTOR2I& aPos,
int aLayer,
253 const std::function<
void(
PCB_MARKER* )>& aPathGenerator )
256 violations.push_back( *aItem );
261 if( violations.empty() )
264 BOOST_TEST_MESSAGE( wxString::Format(
"Zone fill copper sliver regression: %s passed", relPath ) );
270 std::map<KIID, EDA_ITEM*> itemMap;
271 m_board->FillItemMap( itemMap );
273 for(
const DRC_ITEM& item : violations )
276 BOOST_ERROR( wxString::Format(
"Zone fill copper sliver regression: %s failed", relPath ) );
282 {
"teardrop_issue_JPC2", 5 },
289 const wxString& relPath =
test.first;
290 const int count =
test.second;
300 for(
ZONE* zone : m_board->Zones() )
302 if( zone->IsTeardropArea() )
306 BOOST_CHECK_MESSAGE( zoneCount == count,
"Expected " << count <<
" teardrop zones in "
307 << relPath <<
", found "
315 std::vector<wxString> tests = { {
"issue19956/issue19956" }
318 for(
const wxString& relPath : tests )
324 for(
ZONE* zone : m_board->Zones() )
328 std::shared_ptr<SHAPE> a_shape( zone->GetEffectiveShape( layer ) );
330 for(
PAD*
pad : m_board->GetPads() )
332 std::shared_ptr<SHAPE> pad_shape(
pad->GetEffectiveShape( layer ) );
333 int clearance = pad_shape->GetClearance( a_shape.get() );
334 BOOST_CHECK_MESSAGE(
pad->GetNetCode() == zone->GetNetCode() ||
clearance != 0,
335 wxString::Format(
"Pad %s from Footprint %s has net code %s and "
336 "is connected to zone with net code %s",
338 pad->GetParentFootprint()->GetReferenceAsString(),
340 zone->GetNetname() ) );
370 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } } guard{ cfg.
m_ZoneFillIterativeRefill, originalIterativeRefill };
377 ZONE* gndZone =
nullptr;
379 for(
ZONE* zone : m_board->Zones() )
381 if( zone->GetNetname() ==
"GND" )
388 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone not found in test board" );
392 bool hasOutline = m_board->GetBoardPolygonOutlines( boardOutline,
true );
393 BOOST_REQUIRE_MESSAGE( hasOutline,
"Board outline not found" );
395 double boardArea = 0.0;
406 double fillRatio = gndFilledArea / boardArea;
408 BOOST_TEST_MESSAGE( wxString::Format(
"Board area: %.2f sq mm, GND filled area: %.2f sq mm, "
409 "Fill ratio: %.1f%%",
410 boardArea / 1e6, gndFilledArea / 1e6,
411 fillRatio * 100.0 ) );
413 BOOST_CHECK_MESSAGE( fillRatio >= 0.25,
414 wxString::Format(
"GND zone fill ratio %.1f%% is less than expected 25%%. "
415 "This indicates issue 21746 - lower priority zones not "
416 "filling areas where higher priority isolated islands "
418 fillRatio * 100.0 ) );
443 int viasWithUnreachableFlashing = 0;
444 int totalConditionalVias = 0;
446 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
447 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
449 for(
PCB_TRACK* track : m_board->Tracks() )
456 if( !
via->GetRemoveUnconnected() )
459 totalConditionalVias++;
462 bool flashedOnIn1 =
via->FlashLayer( in1Cu );
463 bool flashedOnIn2 =
via->FlashLayer( in2Cu );
465 if( !flashedOnIn1 && !flashedOnIn2 )
469 int holeRadius =
via->GetDrillValue() / 2;
472 bool zoneReachesVia =
false;
474 for(
ZONE* zone : m_board->Zones() )
476 if( zone->GetIsRuleArea() )
479 if( zone->GetNetCode() !=
via->GetNetCode() )
484 if( !zone->IsOnLayer( layer ) )
487 if( !zone->HasFilledPolysForLayer( layer ) )
490 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
492 if( fill->Contains( viaCenter, -1, holeRadius ) )
494 zoneReachesVia =
true;
504 if( !zoneReachesVia && ( flashedOnIn1 || flashedOnIn2 ) )
505 viasWithUnreachableFlashing++;
508 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias with unreachable "
509 "flashing: %d", totalConditionalVias,
510 viasWithUnreachableFlashing ) );
512 BOOST_CHECK_MESSAGE( viasWithUnreachableFlashing == 0,
513 wxString::Format(
"Found %d vias flashed on zone layers where the zone "
514 "fill doesn't actually reach them. This indicates "
515 "issue 22010 is not fixed.",
516 viasWithUnreachableFlashing ) );
538 int viasShortingZones = 0;
539 int totalConditionalVias = 0;
541 for(
PCB_TRACK* track : m_board->Tracks() )
548 if( !
via->GetRemoveUnconnected() )
551 totalConditionalVias++;
555 for(
ZONE* zone : m_board->Zones() )
557 if( zone->GetIsRuleArea() )
560 if( zone->GetNetCode() ==
via->GetNetCode() )
565 if( !
via->FlashLayer( layer ) )
568 if( !zone->HasFilledPolysForLayer( layer ) )
571 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
572 int viaRadius =
via->GetWidth( layer ) / 2;
574 if( fill->Contains( viaCenter, -1, viaRadius ) )
577 "Via at (%d, %d) on net %s is flashing on layer %s where zone "
578 "net %s is filled - this creates a short!",
579 viaCenter.
x, viaCenter.
y,
via->GetNetname(),
580 m_board->GetLayerName( layer ), zone->GetNetname() ) );
587 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional vias: %d, Vias shorting zones: %d",
588 totalConditionalVias, viasShortingZones ) );
590 BOOST_CHECK_MESSAGE( viasShortingZones == 0,
591 wxString::Format(
"Found %d vias flashed on layers where they short to "
592 "zones with different nets. This indicates issue 12964 "
594 viasShortingZones ) );
612 KI_TEST::LoadBoard( m_settingsManager,
"hatch_thermal_connectivity/hatch_thermal_connectivity",
617 m_board->BuildConnectivity();
619 int unconnectedCount = m_board->GetConnectivity()->GetUnconnectedCount(
false );
621 BOOST_CHECK_MESSAGE( unconnectedCount == 0,
622 wxString::Format(
"Found %d unconnected items after zone fill. "
623 "Hatch zone thermal reliefs should maintain connectivity "
624 "even with large hatch gaps.",
625 unconnectedCount ) );
649 PCB_LAYER_ID in1Cu = m_board->GetLayerID( wxT(
"In1.Cu" ) );
651 ZONE* gndZone =
nullptr;
653 for(
ZONE* zone : m_board->Zones() )
655 if( zone->GetNetname() ==
"GND" && zone->IsOnLayer( in1Cu ) )
662 BOOST_REQUIRE_MESSAGE( gndZone !=
nullptr,
"GND zone on In1.Cu not found in test board" );
670 "GND zone has no fill on In1.Cu" );
678 double zoneOutlineArea = gndZone->
Outline()->
Area();
680 BOOST_REQUIRE_MESSAGE( zoneOutlineArea > 0.0,
"Zone outline area must be positive" );
682 double fillArea = 0.0;
684 for(
int i = 0; i < fill->OutlineCount(); i++ )
685 fillArea +=
std::abs( fill->Outline( i ).Area() );
687 double fillRatio = fillArea / zoneOutlineArea;
691 BOOST_CHECK_GE( fillRatio, 0.90 );
714 struct ScopeGuard {
bool& ref;
bool orig; ~ScopeGuard() { ref = orig; } }
722 std::vector<ZONE*> keepouts;
724 for(
ZONE* zone : m_board->Zones() )
726 if( zone->GetIsRuleArea() && zone->GetDoNotAllowZoneFills() )
727 keepouts.push_back( zone );
730 BOOST_REQUIRE_MESSAGE( !keepouts.empty(),
"No zone keepouts found in test board" );
733 int violationCount = 0;
735 for(
ZONE* keepout : keepouts )
737 for(
PCB_LAYER_ID layer : keepout->GetLayerSet().Seq() )
742 for(
ZONE* zone : m_board->Zones() )
744 if( zone->GetIsRuleArea() )
747 if( !zone->IsOnLayer( layer ) )
750 if( !zone->HasFilledPolysForLayer( layer ) )
753 const std::shared_ptr<SHAPE_POLY_SET>& fill = zone->GetFilledPolysList( layer );
761 double intersectionArea = 0;
767 if( intersectionArea > 1e6 )
770 "Zone %s fill on layer %s overlaps keepout by %.2f sq mm",
772 m_board->GetLayerName( layer ),
773 intersectionArea / 1e6 ) );
781 BOOST_CHECK_MESSAGE( violationCount == 0,
782 wxString::Format(
"Found %d zone fills overlapping keepout areas. "
783 "This indicates issue 22809 - iterative refiller "
784 "ignores zone keepouts.", violationCount ) );
807 PCB_LAYER_ID in2Cu = m_board->GetLayerID( wxT(
"In2.Cu" ) );
808 int padsWithMissingFlashing = 0;
809 int totalConditionalPads = 0;
811 for(
FOOTPRINT* footprint : m_board->Footprints() )
813 for(
PAD*
pad : footprint->Pads() )
815 if( !
pad->GetRemoveUnconnected() )
818 if( !
pad->HasHole() )
821 if(
pad->GetNetname() !=
"VBUS_DUT" &&
pad->GetNetname() !=
"VBUS_DBG" )
824 totalConditionalPads++;
827 bool shouldFlash =
false;
829 for(
ZONE* zone : m_board->Zones() )
831 if( zone->GetIsRuleArea() )
834 if( zone->GetNetCode() !=
pad->GetNetCode() )
837 if( !zone->IsOnLayer( in2Cu ) )
840 if( zone->Outline()->Contains(
pad->GetPosition() ) )
847 if( shouldFlash && !
pad->FlashLayer( in2Cu ) )
850 "Pad %s at (%d, %d) on net %s is inside zone but not flashing on In2.Cu",
851 pad->GetNumber(),
pad->GetPosition().x,
pad->GetPosition().y,
852 pad->GetNetname() ) );
853 padsWithMissingFlashing++;
858 BOOST_TEST_MESSAGE( wxString::Format(
"Total conditional pads: %d, Pads with missing "
859 "flashing: %d", totalConditionalPads,
860 padsWithMissingFlashing ) );
862 BOOST_CHECK_MESSAGE( padsWithMissingFlashing == 0,
863 wxString::Format(
"Found %d TH pads that should flash on inner layers "
864 "but don't. This indicates issue 22826 is not fixed.",
865 padsWithMissingFlashing ) );
883 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
893 if( !commit.
Empty() )
897 int teardropCount = 0;
898 bool foundBadTeardrop =
false;
900 for(
ZONE* zone : m_board->Zones() )
902 if( !zone->IsTeardropArea() )
919 int concaveCount = 0;
921 for(
int i = 0; i <
chain.PointCount(); i++ )
923 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
924 int next = ( i + 1 ) %
chain.PointCount();
930 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
940 if( concaveCount > 5 )
943 "indicating possible corner intersection",
945 foundBadTeardrop =
true;
949 BOOST_CHECK_MESSAGE( teardropCount > 0,
"Expected at least one teardrop zone" );
951 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
952 "Found teardrop with excessive concave vertices, indicating "
953 "issue 19405 - teardrop curve intersecting rounded rectangle corner" );
970 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
980 if( !commit.
Empty() )
984 int teardropCount = 0;
985 bool foundBadTeardrop =
false;
987 for(
ZONE* zone : m_board->Zones() )
989 if( !zone->IsTeardropArea() )
1003 int concaveCount = 0;
1005 for(
int i = 0; i <
chain.PointCount(); i++ )
1007 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1008 int next = ( i + 1 ) %
chain.PointCount();
1013 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1019 if( concaveCount > 5 )
1023 foundBadTeardrop =
true;
1027 BOOST_CHECK_MESSAGE( teardropCount > 0,
"Expected at least one teardrop zone" );
1029 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
1030 "Found teardrop with excessive concave vertices on oval pad, "
1031 "indicating curve is not tangent to semicircular end" );
1048 toolMgr.
SetEnvironment( m_board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1058 if( !commit.
Empty() )
1062 PAD* largePad =
nullptr;
1064 for(
FOOTPRINT* fp : m_board->Footprints() )
1066 for(
PAD*
pad : fp->Pads() )
1076 BOOST_REQUIRE_MESSAGE( largePad !=
nullptr,
"Expected a circular pad in test board" );
1082 int teardropCount = 0;
1083 bool foundBadTeardrop =
false;
1085 for(
ZONE* zone : m_board->Zones() )
1087 if( !zone->IsTeardropArea() )
1100 int concaveCount = 0;
1102 for(
int i = 0; i <
chain.PointCount(); i++ )
1104 int prev = ( i == 0 ) ?
chain.PointCount() - 1 : i - 1;
1105 int next = ( i + 1 ) %
chain.PointCount();
1110 int64_t cross = (int64_t)
v1.x *
v2.y - (int64_t)
v1.y *
v2.x;
1116 if( concaveCount > 5 )
1118 BOOST_TEST_MESSAGE( wxString::Format(
"Large circle teardrop has %d concave vertices",
1120 foundBadTeardrop =
true;
1125 int maxError = m_board->GetDesignSettings().m_MaxError;
1127 for(
int i = 0; i <
chain.PointCount(); i++ )
1130 double dist = ( pt - padCenter ).EuclideanNorm();
1133 if( dist > padRadius * 0.5 && dist < padRadius * 1.5 )
1135 double deviation =
std::abs( dist - padRadius );
1138 if( deviation > maxError * 5 && deviation < padRadius * 0.2 )
1141 "Teardrop point at distance %.2f from pad center (radius %.2f), "
1142 "deviation %.2f exceeds tolerance",
1143 dist / 1000.0, padRadius / 1000.0, deviation / 1000.0 ) );
1149 BOOST_CHECK_MESSAGE( teardropCount > 0,
"Expected at least one teardrop zone" );
1151 BOOST_CHECK_MESSAGE( !foundBadTeardrop,
1152 "Found teardrop with excessive concave vertices on large circle, "
1153 "indicating anchor points may not be on circle edge" );
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
const wxString & GetNumber() const
VECTOR2I GetPosition() const override
const VECTOR2I & GetSize(PCB_LAYER_ID aLayer) const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
double Area()
Return the area of this poly set.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
int OutlineCount() const
Return the number of outlines in the set.
TEARDROP_MANAGER manage and build teardrop areas A teardrop area is a polygonal area (a copper ZONE) ...
void UpdateTeardrops(BOARD_COMMIT &aCommit, const std::vector< BOARD_ITEM * > *dirtyPadsAndVias, const std::set< PCB_TRACK * > *dirtyTracks, bool aForceFullUpdate=false)
Update teardrops on a list of items.
Handle a list of polygons defining a copper zone.
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
double GetFilledArea()
This area is cached from the most recent call to CalculateFilledArea().
SHAPE_POLY_SET * Outline()
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
double CalculateFilledArea()
Compute the area currently occupied by the zone fill.
bool m_ZoneFillIterativeRefill
Enable iterative zone filling to handle isolated islands in higher priority zones.
PCB_LAYER_ID
A quick note on layer IDs:
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
const SHAPE_LINE_CHAIN chain
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
static const std::vector< wxString > RegressionZoneFillTests_tests
static const std::vector< std::pair< wxString, int > > RegressionTeardropFill_tests
BOOST_DATA_TEST_CASE_F(ZONE_FILL_TEST_FIXTURE, RegressionZoneFillTests, boost::unit_test::data::make(RegressionZoneFillTests_tests), relPath)
static const std::vector< wxString > RegressionSliverZoneFillTests_tests
BOOST_FIXTURE_TEST_CASE(BasicZoneFills, ZONE_FILL_TEST_FIXTURE)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
VECTOR2< int32_t > VECTOR2I