KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_zone.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <pcbnew_utils/board_test_utils.h>
#include <board.h>
#include <collectors.h>
#include <footprint.h>
#include <geometry/shape_arc.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_poly_set.h>
#include <geometry/shape_utils.h>
#include <netinfo.h>
#include <pad.h>
#include <padstack.h>
#include <pcb_painter.h>
#include <pcb_track.h>
#include <zone.h>
#include <zone_utils.h>

Go to the source code of this file.

Classes

struct  ZONE_TEST_FIXTURE
 
class  STUB_COLLECTORS_GUIDE
 Minimal COLLECTORS_GUIDE so GetCoverageArea() can be exercised headlessly. More...
 

Functions

static std::unique_ptr< ZONECreateSquareZone (BOARD_ITEM_CONTAINER &aParent, BOX2I aBox, PCB_LAYER_ID aLayer)
 
static std::unique_ptr< ZONECreateSimilarZone (BOARD_ITEM_CONTAINER &aParent, const ZONE &aOther, PCB_LAYER_ID aLayer)
 Create a similar zone (same outline) on a different layer.
 
 BOOST_AUTO_TEST_CASE (SingleLayer)
 
 BOOST_AUTO_TEST_CASE (MultipleLayers)
 
 BOOST_AUTO_TEST_CASE (RescuedLayers)
 During zone loading, the layer is set to Rescue if the layer is not found.
 
 BOOST_AUTO_TEST_CASE (RuleAreaInnerLayersExpandMode)
 Verify that a rule area on all inner copper layers does not produce a spurious layer validation error when the footprint uses the default EXPAND_INNER_LAYERS stackup mode.
 
 BOOST_AUTO_TEST_CASE (CircleZoneCutoutRoundTrip)
 Zones created by converting a circle shape carry arc metadata in their outline.
 
 BOOST_AUTO_TEST_CASE (EmptyZoneGetPosition)
 Verify that GetPosition() on a zone with no outline vertices does not throw or crash.
 
 BOOST_AUTO_TEST_CASE (ZoneMergeNull)
 
 BOOST_AUTO_TEST_CASE (ZoneMergeNonNullNoMerge)
 
 BOOST_AUTO_TEST_CASE (ZoneMergeNonNullMerge)
 
 BOOST_AUTO_TEST_CASE (ZoneMergeMergeSameGeomDifferentOrder)
 
static PCB_VIAAddVia (BOARD &aBoard, const VECTOR2I &aPos, int aNetCode, PCB_LAYER_ID aTopLayer=F_Cu, PCB_LAYER_ID aBotLayer=B_Cu)
 
static PADAddPadToBoard (BOARD &aBoard, const VECTOR2I &aPos, int aNetCode, PCB_LAYER_ID aLayer=F_Cu)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_NonOverlapping)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_ItemCountWins)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_SimilarCountsSmallerWins)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_MultiLayerAggregate)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_SameNetEqualPriority)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_EqualAreaNoChange)
 
 BOOST_AUTO_TEST_CASE (AutoPriority_SameNetGroupInheritsEdge)
 
 BOOST_AUTO_TEST_CASE (RuleAreaCoverageAreaNotZero)
 A rule area has no filled polygons, so its coverage area must be derived from its outline.
 
 BOOST_AUTO_TEST_CASE (FilledZoneCoverageUsesFilledPolygons)
 A filled (non-rule-area) zone must continue to report its coverage area from its filled polygons, not its outline, so a sparsely-filled zone keeps its existing selection behaviour.
 
 BOOST_AUTO_TEST_CASE (RuleAreaOutlineDrawnAboveCopper)
 A rule area's outline must be drawn on the zone layer, which sorts above copper, so unrelated tracks and pads on the same copper layer cannot paint over it and leave a broken-looking border (issue 24688).
 

Function Documentation

◆ AddPadToBoard()

static PAD * AddPadToBoard ( BOARD & aBoard,
const VECTOR2I & aPos,
int aNetCode,
PCB_LAYER_ID aLayer = F_Cu )
static

◆ AddVia()

static PCB_VIA * AddVia ( BOARD & aBoard,
const VECTOR2I & aPos,
int aNetCode,
PCB_LAYER_ID aTopLayer = F_Cu,
PCB_LAYER_ID aBotLayer = B_Cu )
static

◆ BOOST_AUTO_TEST_CASE() [1/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_EqualAreaNoChange )

◆ BOOST_AUTO_TEST_CASE() [2/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_ItemCountWins )

◆ BOOST_AUTO_TEST_CASE() [3/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_MultiLayerAggregate )

◆ BOOST_AUTO_TEST_CASE() [4/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_NonOverlapping )

◆ BOOST_AUTO_TEST_CASE() [5/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_SameNetEqualPriority )

◆ BOOST_AUTO_TEST_CASE() [6/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_SameNetGroupInheritsEdge )

◆ BOOST_AUTO_TEST_CASE() [7/20]

BOOST_AUTO_TEST_CASE ( AutoPriority_SimilarCountsSmallerWins )

◆ BOOST_AUTO_TEST_CASE() [8/20]

BOOST_AUTO_TEST_CASE ( CircleZoneCutoutRoundTrip )

Zones created by converting a circle shape carry arc metadata in their outline.

Clipper2 cannot preserve arcs across boolean operations once either operand has a hole or the clip operand has outlines (see SHAPE_POLY_SET::booleanOp's assertion). Historically the "Add a Zone Cutout" tool fed arc-bearing outlines straight into BooleanSubtract, which produced point/arc metadata that disagreed after serialization and rendered as corrupt zones on reload.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24053

Definition at line 173 of file test_zone.cpp.

References SHAPE_POLY_SET::Append(), SHAPE_POLY_SET::ArcCount(), SHAPE_POLY_SET::Area(), SHAPE_POLY_SET::BooleanSubtract(), BOOST_TEST(), center, SHAPE_POLY_SET::CHole(), SHAPE_POLY_SET::ClearArcs(), SHAPE_POLY_SET::COutline(), SHAPE_POLY_SET::HoleCount(), SHAPE_LINE_CHAIN::IsClosed(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::OutlineCount(), pcbIUScale, SHAPE_LINE_CHAIN::PointCount(), radius, and SHAPE_LINE_CHAIN::SelfIntersecting().

◆ BOOST_AUTO_TEST_CASE() [9/20]

BOOST_AUTO_TEST_CASE ( EmptyZoneGetPosition )

Verify that GetPosition() on a zone with no outline vertices does not throw or crash.

Empty zones can be created by importers.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23125

Definition at line 232 of file test_zone.cpp.

References BOOST_TEST(), F_Cu, ZONE::GetNumCorners(), ZONE::GetPosition(), and ZONE::SetLayer().

◆ BOOST_AUTO_TEST_CASE() [10/20]

BOOST_AUTO_TEST_CASE ( FilledZoneCoverageUsesFilledPolygons )

A filled (non-rule-area) zone must continue to report its coverage area from its filled polygons, not its outline, so a sparsely-filled zone keeps its existing selection behaviour.

Definition at line 704 of file test_zone.cpp.

References SHAPE_POLY_SET::AddOutline(), BOOST_TEST(), KIGEOM::BoxToLineChain(), CreateSquareZone(), expected, F_Cu, FOOTPRINT::GetCoverageArea(), pcbIUScale, and GENERAL_COLLECTOR::SetGuide().

◆ BOOST_AUTO_TEST_CASE() [11/20]

BOOST_AUTO_TEST_CASE ( MultipleLayers )

◆ BOOST_AUTO_TEST_CASE() [12/20]

BOOST_AUTO_TEST_CASE ( RescuedLayers )

During zone loading, the layer is set to Rescue if the layer is not found.

This is not a UI-visible layer, so make sure it can still be retreived.

https://gitlab.com/kicad/code/kicad/-/issues/18553

Definition at line 108 of file test_zone.cpp.

References BOOST_TEST(), ZONE::GetFirstLayer(), ZONE::GetLayer(), ZONE::IsOnCopperLayer(), Rescue, and ZONE::SetLayer().

◆ BOOST_AUTO_TEST_CASE() [13/20]

BOOST_AUTO_TEST_CASE ( RuleAreaCoverageAreaNotZero )

A rule area has no filled polygons, so its coverage area must be derived from its outline.

Otherwise it reports a zero area and wins selection precedence over every enclosed item.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24464

Definition at line 668 of file test_zone.cpp.

References AddPadToBoard(), BOOST_TEST(), CreateSquareZone(), expected, F_Cu, FOOTPRINT::GetCoverageArea(), pad, pcbIUScale, and GENERAL_COLLECTOR::SetGuide().

◆ BOOST_AUTO_TEST_CASE() [14/20]

BOOST_AUTO_TEST_CASE ( RuleAreaInnerLayersExpandMode )

Verify that a rule area on all inner copper layers does not produce a spurious layer validation error when the footprint uses the default EXPAND_INNER_LAYERS stackup mode.

Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23042

Definition at line 127 of file test_zone.cpp.

References FOOTPRINT::Add(), B_Cu, BOOST_TEST(), EXPAND_INNER_LAYERS, F_Cu, BOARD_ITEM::GetLayer(), LSET::InternalCuMask(), PCB_ZONE_T, RECURSE, FOOTPRINT::RunOnChildren(), BASE_SET::set(), ZONE::SetIsRuleArea(), ZONE::SetLayerSet(), FOOTPRINT::SetStackupMode(), EDA_ITEM::Type(), and LSET::UserDefinedLayersMask().

◆ BOOST_AUTO_TEST_CASE() [15/20]

BOOST_AUTO_TEST_CASE ( RuleAreaOutlineDrawnAboveCopper )

A rule area's outline must be drawn on the zone layer, which sorts above copper, so unrelated tracks and pads on the same copper layer cannot paint over it and leave a broken-looking border (issue 24688).

A filled zone keeps its outline on the copper layer, beneath its own fill.

Definition at line 733 of file test_zone.cpp.

References BOOST_TEST(), F_Cu, ZONE_LAYER_FOR, and KIGFX::ZoneOutlineDrawnOnLayer().

◆ BOOST_AUTO_TEST_CASE() [16/20]

BOOST_AUTO_TEST_CASE ( SingleLayer )

◆ BOOST_AUTO_TEST_CASE() [17/20]

BOOST_AUTO_TEST_CASE ( ZoneMergeMergeSameGeomDifferentOrder )

◆ BOOST_AUTO_TEST_CASE() [18/20]

BOOST_AUTO_TEST_CASE ( ZoneMergeNonNullMerge )

◆ BOOST_AUTO_TEST_CASE() [19/20]

BOOST_AUTO_TEST_CASE ( ZoneMergeNonNullNoMerge )

Definition at line 260 of file test_zone.cpp.

References B_Cu, BOOST_TEST(), CreateSquareZone(), F_Cu, and MergeZonesWithSameOutline().

◆ BOOST_AUTO_TEST_CASE() [20/20]

BOOST_AUTO_TEST_CASE ( ZoneMergeNull )

Definition at line 243 of file test_zone.cpp.

References BOOST_TEST(), F_Cu, and MergeZonesWithSameOutline().

◆ CreateSimilarZone()

static std::unique_ptr< ZONE > CreateSimilarZone ( BOARD_ITEM_CONTAINER & aParent,
const ZONE & aOther,
PCB_LAYER_ID aLayer )
static

Create a similar zone (same outline) on a different layer.

Definition at line 62 of file test_zone.cpp.

References ZONE::Outline().

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ CreateSquareZone()