KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_zone_filler.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
25#include <boost/test/data/test_case.hpp>
26
28#include <board.h>
30#include <pad.h>
31#include <pcb_track.h>
32#include <footprint.h>
33#include <zone.h>
34#include <drc/drc_item.h>
36
37
46
47
48int delta = KiROUND( 0.006 * pcbIUScale.IU_PER_MM );
49
50
52{
53 KI_TEST::LoadBoard( m_settingsManager, "zone_filler", m_board );
54
55 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
56
57 KI_TEST::FillZones( m_board.get() );
58
59 // Now that the zones are filled we're going to increase the size of -some- pads and
60 // tracks so that they generate DRC errors. The test then makes sure that those errors
61 // are generated, and that the other pads and tracks do -not- generate errors.
62
63 for( PAD* pad : m_board->Footprints()[0]->Pads() )
64 {
65 if( pad->GetNumber() == "2" || pad->GetNumber() == "4" || pad->GetNumber() == "6" )
66 {
67 pad->SetSize( PADSTACK::ALL_LAYERS,
68 pad->GetSize( PADSTACK::ALL_LAYERS ) + VECTOR2I( delta, delta ) );
69 }
70 }
71
72 int ii = 0;
73 KIID arc8;
74 KIID arc12;
75
76 for( PCB_TRACK* track : m_board->Tracks() )
77 {
78 if( track->Type() == PCB_ARC_T )
79 {
80 ii++;
81
82 if( ii == 8 )
83 {
84 arc8 = track->m_Uuid;
85 track->SetWidth( track->GetWidth() + delta + delta );
86 }
87 else if( ii == 12 )
88 {
89 arc12 = track->m_Uuid;
90 track->Move( VECTOR2I( -delta, -delta ) );
91 }
92 }
93 }
94
95 bool foundPad2Error = false;
96 bool foundPad4Error = false;
97 bool foundPad6Error = false;
98 bool foundArc8Error = false;
99 bool foundArc12Error = false;
100 bool foundOtherError = false;
101
102 bds.m_DRCEngine->InitEngine( wxFileName() ); // Just to be sure to be sure
103
105 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
106 const std::function<void( PCB_MARKER* )>& aPathGenerator )
107 {
108 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
109 {
110 BOARD_ITEM* item_a = m_board->ResolveItem( aItem->GetMainItemID() );
111 PAD* pad_a = dynamic_cast<PAD*>( item_a );
112 PCB_TRACK* trk_a = dynamic_cast<PCB_TRACK*>( item_a );
113
114 BOARD_ITEM* item_b = m_board->ResolveItem( aItem->GetAuxItemID() );
115 PAD* pad_b = dynamic_cast<PAD*>( item_b );
116 PCB_TRACK* trk_b = dynamic_cast<PCB_TRACK*>( item_b );
117
118 if( pad_a && pad_a->GetNumber() == "2" ) foundPad2Error = true;
119 else if( pad_a && pad_a->GetNumber() == "4" ) foundPad4Error = true;
120 else if( pad_a && pad_a->GetNumber() == "6" ) foundPad6Error = true;
121 else if( pad_b && pad_b->GetNumber() == "2" ) foundPad2Error = true;
122 else if( pad_b && pad_b->GetNumber() == "4" ) foundPad4Error = true;
123 else if( pad_b && pad_b->GetNumber() == "6" ) foundPad6Error = true;
124 else if( trk_a && trk_a->m_Uuid == arc8 ) foundArc8Error = true;
125 else if( trk_a && trk_a->m_Uuid == arc12 ) foundArc12Error = true;
126 else if( trk_b && trk_b->m_Uuid == arc8 ) foundArc8Error = true;
127 else if( trk_b && trk_b->m_Uuid == arc12 ) foundArc12Error = true;
128 else foundOtherError = true;
129
130 }
131 } );
132
133 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
134
135 BOOST_CHECK_EQUAL( foundPad2Error, true );
136 BOOST_CHECK_EQUAL( foundPad4Error, true );
137 BOOST_CHECK_EQUAL( foundPad6Error, true );
138 BOOST_CHECK_EQUAL( foundArc8Error, true );
139 BOOST_CHECK_EQUAL( foundArc12Error, true );
140 BOOST_CHECK_EQUAL( foundOtherError, false );
141}
142
143
145{
146 KI_TEST::LoadBoard( m_settingsManager, "notched_zones", m_board );
147
148 // Older algorithms had trouble where the filleted zones intersected and left notches.
149 // See:
150 // https://gitlab.com/kicad/code/kicad/-/issues/2737
151 // https://gitlab.com/kicad/code/kicad/-/issues/2752
152 SHAPE_POLY_SET frontCopper;
153
154 KI_TEST::FillZones( m_board.get() );
155
156 frontCopper = SHAPE_POLY_SET();
157
158 for( ZONE* zone : m_board->Zones() )
159 {
160 if( zone->GetLayerSet().Contains( F_Cu ) )
161 {
162 frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ) );
163 }
164 }
165
166 BOOST_CHECK_EQUAL( frontCopper.OutlineCount(), 2 );
167}
168
169
170static const std::vector<wxString> RegressionZoneFillTests_tests = {
171 "issue18",
172 "issue2568",
173 "issue3812",
174 "issue5102",
175 "issue5313",
176 "issue5320",
177 "issue5567",
178 "issue5830",
179 "issue6039",
180 "issue6260",
181 "issue6284",
182 "issue7086",
183 "issue14294", // Bad Clipper2 fill
184 "fill_bad" // Missing zone clearance expansion
185};
186
187
189 boost::unit_test::data::make( RegressionZoneFillTests_tests ), relPath )
190{
191 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
192
193 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
194
195 KI_TEST::FillZones( m_board.get() );
196
197 std::vector<DRC_ITEM> violations;
198
200 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
201 const std::function<void( PCB_MARKER* )>& aPathGenerator )
202 {
203 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
204 violations.push_back( *aItem );
205 } );
206
207 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
208
209 if( violations.empty() )
210 {
211 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
212 BOOST_TEST_MESSAGE( wxString::Format( "Zone fill regression: %s passed", relPath ) );
213 }
214 else
215 {
216 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
217
218 std::map<KIID, EDA_ITEM*> itemMap;
219 m_board->FillItemMap( itemMap );
220
221 for( const DRC_ITEM& item : violations )
222 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
223
224 BOOST_ERROR( wxString::Format( "Zone fill regression: %s failed", relPath ) );
225 }
226}
227
228
229static const std::vector<wxString> RegressionSliverZoneFillTests_tests = {
230 "issue16182" // Slivers
231};
232
233
234BOOST_DATA_TEST_CASE_F( ZONE_FILL_TEST_FIXTURE, RegressionSliverZoneFillTests,
235 boost::unit_test::data::make( RegressionSliverZoneFillTests_tests ),
236 relPath )
237{
238 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
239
240 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
241
242 KI_TEST::FillZones( m_board.get() );
243
244 std::vector<DRC_ITEM> violations;
245
247 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& aPos, int aLayer,
248 const std::function<void( PCB_MARKER* )>& aPathGenerator )
249 {
250 if( aItem->GetErrorCode() == DRCE_COPPER_SLIVER )
251 violations.push_back( *aItem );
252 } );
253
254 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
255
256 if( violations.empty() )
257 {
258 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
259 BOOST_TEST_MESSAGE( wxString::Format( "Zone fill copper sliver regression: %s passed", relPath ) );
260 }
261 else
262 {
263 UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCH );
264
265 std::map<KIID, EDA_ITEM*> itemMap;
266 m_board->FillItemMap( itemMap );
267
268 for( const DRC_ITEM& item : violations )
269 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR, itemMap ) );
270
271 BOOST_ERROR( wxString::Format( "Zone fill copper sliver regression: %s failed", relPath ) );
272 }
273}
274
275
276static const std::vector<std::pair<wxString,int>> RegressionTeardropFill_tests = {
277 { "teardrop_issue_JPC2", 5 }, // Arcs with teardrops connecting to pads
278};
279
280
282 boost::unit_test::data::make( RegressionTeardropFill_tests ), test )
283{
284 const wxString& relPath = test.first;
285 const int count = test.second;
286
287 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
288
289 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
290
291 KI_TEST::FillZones( m_board.get() );
292
293 int zoneCount = 0;
294
295 for( ZONE* zone : m_board->Zones() )
296 {
297 if( zone->IsTeardropArea() )
298 zoneCount++;
299 }
300
301 BOOST_CHECK_MESSAGE( zoneCount == count, "Expected " << count << " teardrop zones in "
302 << relPath << ", found "
303 << zoneCount );
304}
305
306
308{
309
310 std::vector<wxString> tests = { { "issue19956/issue19956" } // Arcs with teardrops connecting to pads
311 };
312
313 for( const wxString& relPath : tests )
314 {
315 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
316 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
317 KI_TEST::FillZones( m_board.get() );
318
319 for( ZONE* zone : m_board->Zones() )
320 {
321 for( PCB_LAYER_ID layer : zone->GetLayerSet() )
322 {
323 std::shared_ptr<SHAPE> a_shape( zone->GetEffectiveShape( layer ) );
324
325 for( PAD* pad : m_board->GetPads() )
326 {
327 std::shared_ptr<SHAPE> pad_shape( pad->GetEffectiveShape( layer ) );
328 int clearance = pad_shape->GetClearance( a_shape.get() );
329 BOOST_CHECK_MESSAGE( pad->GetNetCode() == zone->GetNetCode() || clearance != 0,
330 wxString::Format( "Pad %s from Footprint %s has net code %s and "
331 "is connected to zone with net code %s",
332 pad->GetNumber(),
333 pad->GetParentFootprint()->GetReferenceAsString(),
334 pad->GetNetname(),
335 zone->GetNetname() ) );
336 }
337 }
338 }
339 }
340}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
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...
Definition board_item.h:79
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).
Definition drc_engine.h:118
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
const KIID m_Uuid
Definition eda_item.h:516
Definition kiid.h:49
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:145
Definition pad.h:54
const wxString & GetNumber() const
Definition pad.h:136
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
int OutlineCount() const
Return the number of outlines in the set.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
@ DRCE_CLEARANCE
Definition drc_item.h:44
@ DRCE_COPPER_SLIVER
Definition drc_item.h:93
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ F_Cu
Definition layer_ids.h:64
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
void FillZones(BOARD *m_board)
@ RPT_SEVERITY_ERROR
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
int clearance
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
static const std::vector< wxString > RegressionZoneFillTests_tests
int delta
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_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:98
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695