KiCad PCB EDA Suite
test_zone_filler.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <qa/pcbnew/board_test_utils.h>
#include <board.h>
#include <board_design_settings.h>
#include <pad.h>
#include <pcb_track.h>
#include <footprint.h>
#include <zone.h>
#include <drc/drc_item.h>
#include <settings/settings_manager.h>

Go to the source code of this file.

Classes

struct  ZONE_FILL_TEST_FIXTURE
 

Functions

 BOOST_FIXTURE_TEST_CASE (BasicZoneFills, ZONE_FILL_TEST_FIXTURE)
 
 BOOST_FIXTURE_TEST_CASE (NotchedZones, ZONE_FILL_TEST_FIXTURE)
 
 BOOST_FIXTURE_TEST_CASE (RegressionZoneFillTests, ZONE_FILL_TEST_FIXTURE)
 

Variables

constexpr int delta = KiROUND( 0.006 * IU_PER_MM )
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

BOOST_FIXTURE_TEST_CASE ( BasicZoneFills  ,
ZONE_FILL_TEST_FIXTURE   
)

Definition at line 50 of file test_zone_filler.cpp.

51 {
52  KI_TEST::LoadBoard( m_settingsManager, "zone_filler", m_board );
53 
54  BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
55 
56  KI_TEST::FillZones( m_board.get(), 6 );
57 
58  // Now that the zones are filled we're going to increase the size of -some- pads and
59  // tracks so that they generate DRC errors. The test then makes sure that those errors
60  // are generated, and that the other pads and tracks do -not- generate errors.
61 
62  for( PAD* pad : m_board->Footprints()[0]->Pads() )
63  {
64  if( pad->GetNumber() == "2" || pad->GetNumber() == "4" || pad->GetNumber() == "6" )
65  pad->SetSize( pad->GetSize() + wxSize( delta, delta ) );
66  }
67 
68  int ii = 0;
69  KIID arc8;
70  KIID arc12;
71 
72  for( PCB_TRACK* track : m_board->Tracks() )
73  {
74  if( track->Type() == PCB_ARC_T )
75  {
76  ii++;
77 
78  if( ii == 8 )
79  {
80  arc8 = track->m_Uuid;
81  track->SetWidth( track->GetWidth() + delta + delta );
82  }
83  else if( ii == 12 )
84  {
85  arc12 = track->m_Uuid;
86  track->Move( wxPoint( -delta, -delta ) );
87  }
88  }
89  }
90 
91  bool foundPad2Error = false;
92  bool foundPad4Error = false;
93  bool foundPad6Error = false;
94  bool foundArc8Error = false;
95  bool foundArc12Error = false;
96  bool foundOtherError = false;
97 
98  bds.m_DRCEngine->InitEngine( wxFileName() ); // Just to be sure to be sure
99 
100  bds.m_DRCEngine->SetViolationHandler(
101  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
102  {
103  if( aItem->GetErrorCode() == DRCE_CLEARANCE )
104  {
105  BOARD_ITEM* item_a = m_board->GetItem( aItem->GetMainItemID() );
106  PAD* pad_a = dynamic_cast<PAD*>( item_a );
107  PCB_TRACK* trk_a = dynamic_cast<PCB_TRACK*>( item_a );
108 
109  BOARD_ITEM* item_b = m_board->GetItem( aItem->GetAuxItemID() );
110  PAD* pad_b = dynamic_cast<PAD*>( item_b );
111  PCB_TRACK* trk_b = dynamic_cast<PCB_TRACK*>( item_b );
112 
113  if( pad_a && pad_a->GetNumber() == "2" ) foundPad2Error = true;
114  else if( pad_a && pad_a->GetNumber() == "4" ) foundPad4Error = true;
115  else if( pad_a && pad_a->GetNumber() == "6" ) foundPad6Error = true;
116  else if( pad_b && pad_b->GetNumber() == "2" ) foundPad2Error = true;
117  else if( pad_b && pad_b->GetNumber() == "4" ) foundPad4Error = true;
118  else if( pad_b && pad_b->GetNumber() == "6" ) foundPad6Error = true;
119  else if( trk_a && trk_a->m_Uuid == arc8 ) foundArc8Error = true;
120  else if( trk_a && trk_a->m_Uuid == arc12 ) foundArc12Error = true;
121  else if( trk_b && trk_b->m_Uuid == arc8 ) foundArc8Error = true;
122  else if( trk_b && trk_b->m_Uuid == arc12 ) foundArc12Error = true;
123  else foundOtherError = true;
124  }
125  } );
126 
127  bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
128 
129  BOOST_CHECK_EQUAL( foundPad2Error, true );
130  BOOST_CHECK_EQUAL( foundPad4Error, true );
131  BOOST_CHECK_EQUAL( foundPad6Error, true );
132  BOOST_CHECK_EQUAL( foundArc8Error, true );
133  BOOST_CHECK_EQUAL( foundArc12Error, true );
134  BOOST_CHECK_EQUAL( foundOtherError, false );
135 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
Definition: kiid.h:44
const wxString & GetNumber() const
Definition: pad.h:129
const KIID m_Uuid
Definition: eda_item.h:475
constexpr int delta
void FillZones(BOARD *m_board, int aFillVersion)
Definition: pad.h:57
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
Container for design settings for a BOARD object.

References delta, DRCE_CLEARANCE, KI_TEST::FillZones(), PAD::GetNumber(), KI_TEST::LoadBoard(), BOARD_DESIGN_SETTINGS::m_DRCEngine, EDA_ITEM::m_Uuid, MILLIMETRES, pad, and PCB_ARC_T.

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

BOOST_FIXTURE_TEST_CASE ( NotchedZones  ,
ZONE_FILL_TEST_FIXTURE   
)

Definition at line 138 of file test_zone_filler.cpp.

139 {
140  KI_TEST::LoadBoard( m_settingsManager, "notched_zones", m_board );
141 
142  // Older algorithms had trouble where the filleted zones intersected and left notches.
143  // See:
144  // https://gitlab.com/kicad/code/kicad/-/issues/2737
145  // https://gitlab.com/kicad/code/kicad/-/issues/2752
146 
147  // First, run a sanity check to validate that the saved board still has holes.
148  SHAPE_POLY_SET frontCopper;
149 
150  for( ZONE* zone : m_board->Zones() )
151  {
152  if( zone->GetLayerSet().Contains( F_Cu ) )
153  {
154  frontCopper.BooleanAdd( zone->GetFilledPolysList( F_Cu ),
156  }
157  }
158 
159  BOOST_CHECK_GT( frontCopper.OutlineCount(), 2 );
160 
161  // Now re-fill and make sure the holes are gone.
162  KI_TEST::FillZones( m_board.get(), 6 );
163 
164  frontCopper = SHAPE_POLY_SET();
165 
166  for( ZONE* zone : m_board->Zones() )
167  {
168  if( zone->GetLayerSet().Contains( F_Cu ) )
169  {
170  frontCopper.BooleanAdd( zone->GetFilledPolysList( F_Cu ),
172  }
173  }
174 
175  BOOST_CHECK_EQUAL( frontCopper.OutlineCount(), 2 );
176 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
Represent a set of closed polygons.
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
Definition: layer_ids.h:71
void FillZones(BOARD *m_board, int aFillVersion)
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)

References SHAPE_POLY_SET::BooleanAdd(), F_Cu, KI_TEST::FillZones(), KI_TEST::LoadBoard(), SHAPE_POLY_SET::OutlineCount(), and SHAPE_POLY_SET::PM_STRICTLY_SIMPLE.

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

BOOST_FIXTURE_TEST_CASE ( RegressionZoneFillTests  ,
ZONE_FILL_TEST_FIXTURE   
)

Definition at line 179 of file test_zone_filler.cpp.

180 {
181  std::vector<wxString> tests = { "issue18",
182  "issue2568",
183  "issue3812",
184  "issue5102",
185  "issue5313",
186  "issue5320",
187  "issue5567",
188  "issue5830",
189  "issue6039",
190  "issue6260",
191  "issue6284",
192  "issue7086" };
193 
194  for( const wxString& relPath : tests )
195  {
196  KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
197 
198  BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
199 
200  for( int fillVersion : { 5, 6 } )
201  {
202  KI_TEST::FillZones( m_board.get(), fillVersion );
203 
204  std::vector<DRC_ITEM> violations;
205 
206  bds.m_DRCEngine->SetViolationHandler(
207  [&]( const std::shared_ptr<DRC_ITEM>& aItem, wxPoint aPos )
208  {
209  if( aItem->GetErrorCode() == DRCE_CLEARANCE )
210  violations.push_back( *aItem );
211  } );
212 
213  bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
214 
215  if( violations.empty() )
216  {
217  BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
218  BOOST_TEST_MESSAGE( wxString::Format( "Zone fill regression: %s, V%d algo passed",
219  relPath,
220  fillVersion ) );
221  }
222  else
223  {
224  std::map<KIID, EDA_ITEM*> itemMap;
225  m_board->FillItemMap( itemMap );
226 
227  for( const DRC_ITEM& item : violations )
228  {
229  BOOST_TEST_MESSAGE( item.ShowReport( EDA_UNITS::INCHES, RPT_SEVERITY_ERROR,
230  itemMap ) );
231  }
232 
233  BOOST_ERROR( wxString::Format( "Zone fill regression: %s, V%d algo failed",
234  relPath,
235  fillVersion ) );
236  }
237  }
238  }
239 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void FillZones(BOARD *m_board, int aFillVersion)
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
Container for design settings for a BOARD object.

References DRCE_CLEARANCE, KI_TEST::FillZones(), Format(), INCHES, KI_TEST::LoadBoard(), BOARD_DESIGN_SETTINGS::m_DRCEngine, MILLIMETRES, and RPT_SEVERITY_ERROR.

Variable Documentation

◆ delta

constexpr int delta = KiROUND( 0.006 * IU_PER_MM )

Definition at line 47 of file test_zone_filler.cpp.

Referenced by EC_SNAPLINE::Apply(), EC_PERPLINE::Apply(), PNS::ApproximateSegmentAsRect(), PLOTTER::Arc(), PDF_PLOTTER::Arc(), PNS::TOPOLOGY::AssembleTuningPath(), BezierToPolyline(), BOOST_FIXTURE_TEST_CASE(), CN_CONNECTIVITY_ALGO::Build(), CircleToEndSegmentDeltaRadius(), Collide(), SHAPE_POLY_SET::CollideVertex(), MICROSTRIP::conductor_losses(), C_MICROSTRIP::conductor_losses(), GERBER_DRAW_ITEM::ConvertSegmentToPolygon(), AM_PRIMITIVE::ConvertShapeToPolygon(), D_CODE::ConvertShapeToPolygon(), PNS::coupledBypass(), EXCELLON_WRITER::createDrillFile(), KIGFX::SCH_PAINTER::draw(), DRAWING_TOOL::DrawDimension(), D_CODE::DrawFlashedShape(), KIGFX::GERBVIEW_PAINTER::drawFlashedShape(), DrawHalfOpenCylinder(), PCB_POINT_EDITOR::editArcEndpointKeepTangent(), fillArcGBRITEM(), PSLIKE_PLOTTER::FlashPadOval(), RENDER_3D_OPENGL::generate3dGrid(), RENDER_3D_OPENGL::generateRing(), PCB_DIM_ALIGNED::GetAngle(), SCH_NO_CONNECT::GetBoundingBox(), BOARD::GetPad(), BEZIER_POLY::GetPoly(), GERBER_DRAW_ITEM::GetTextD_CodePrms(), SCH_NO_CONNECT::HitTest(), PAD::HitTest(), CYLINDER::Intersect(), CYLINDER::IntersectP(), EDA_RECT::Intersects(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), SCH_MOVE_TOOL::Main(), SCH_GLOBALLABEL::MirrorHorizontally(), SCH_GLOBALLABEL::MirrorSpinStyle(), SCH_GLOBALLABEL::MirrorVertically(), mpInfoLayer::Move(), SCH_MOVE_TOOL::moveItem(), SHAPE_LINE_CHAIN::NextShape(), LIB_TEXT::NormalizeJustification(), DIALOG_SHIM::OnCharHook(), KIGFX::WX_VIEW_CONTROLS::onMotion(), KIGFX::WX_VIEW_CONTROLS::onScroll(), PCB_POINT_EDITOR::OnSelectionChange(), KIGFX::WX_VIEW_CONTROLS::onWheel(), EAGLE_PLUGIN::packagePolygon(), GPCB_FPL_CACHE::parseFOOTPRINT(), PCB_PARSER::parsePAD(), DRAWING_TOOL::PlaceImportedGraphics(), SCH_NO_CONNECT::Plot(), EDA_DRAW_PANEL_GAL::Refresh(), DRC_TEST_PROVIDER_VIA_DIAMETER::Run(), DRC_TEST_PROVIDER_TRACK_WIDTH::Run(), DRC_TEST_PROVIDER_DISALLOW::Run(), DRC_TEST_PROVIDER_ANNULAR_WIDTH::Run(), DRC_TEST_PROVIDER_CONNECTIVITY::Run(), DRC_TEST_PROVIDER_SILK_TO_MASK::Run(), DRC_TEST_PROVIDER_SILK_CLEARANCE::Run(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::Run(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::Run(), DRC_ENGINE::RunTests(), PNS::SOLID::SetPos(), PCB_GROUP::SetPosition(), FOOTPRINT::SetPosition(), KIGFX::VIEW::SetScale(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testCourtyardClearances(), DRC_TEST_PROVIDER_COURTYARD_CLEARANCE::testFootprintCourtyardDefinitions(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testPadClearances(), TestSegmentHit(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testTrackClearances(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZonesToZones(), KIGFX::COLOR4D::ToHSV(), DIALOG_PAD_PROPERTIES::transferDataToPad(), TransformArcToPolygon(), BOARD_ADAPTER::transformArcToSegments(), TransformCircleToPolygon(), TransformOvalToPolygon(), PAD::TransformShapeWithClearanceToPolygon(), SETTINGS_MANAGER::TriggerBackupIfNeeded(), PCB_POINT_EDITOR::updateItem(), and BOARD_INSPECTION_TOOL::UpdateSelectionRatsnest().