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 (C) 2021 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 <board.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <footprint.h>
31#include <zone.h>
32#include <drc/drc_item.h>
34
35
37{
39 m_settingsManager( true /* headless */ )
40 { }
41
43 std::unique_ptr<BOARD> m_board;
44};
45
46
47constexpr int delta = KiROUND( 0.006 * pcbIUScale.IU_PER_MM );
48
49
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() );
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() + VECTOR2I( 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( VECTOR2I( -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, VECTOR2I aPos, int aLayer )
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}
136
137
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 SHAPE_POLY_SET frontCopper;
147
148 KI_TEST::FillZones( m_board.get() );
149
150 frontCopper = SHAPE_POLY_SET();
151
152 for( ZONE* zone : m_board->Zones() )
153 {
154 if( zone->GetLayerSet().Contains( F_Cu ) )
155 {
156 frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ),
158 }
159 }
160
161 BOOST_CHECK_EQUAL( frontCopper.OutlineCount(), 2 );
162}
163
164
166{
167 std::vector<wxString> tests = { "issue18",
168 "issue2568",
169 "issue3812",
170 "issue5102",
171 "issue5313",
172 "issue5320",
173 "issue5567",
174 "issue5830",
175 "issue6039",
176 "issue6260",
177 "issue6284",
178 "issue7086",
179 "issue14294", // Bad Clipper2 fill
180 "fill_bad" // Missing zone clearance expansion
181 };
182
183 for( const wxString& relPath : tests )
184 {
185 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
186
187 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
188
189 KI_TEST::FillZones( m_board.get() );
190
191 std::vector<DRC_ITEM> violations;
192
193 bds.m_DRCEngine->SetViolationHandler(
194 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
195 {
196 if( aItem->GetErrorCode() == DRCE_CLEARANCE )
197 violations.push_back( *aItem );
198 } );
199
200 bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
201
202 if( violations.empty() )
203 {
204 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
205 BOOST_TEST_MESSAGE( (const char*)(wxString::Format( "Zone fill regression: %s passed", relPath ).utf8_str()) );
206 }
207 else
208 {
210
211 std::map<KIID, EDA_ITEM*> itemMap;
212 m_board->FillItemMap( itemMap );
213
214 for( const DRC_ITEM& item : violations )
215 {
216 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
217 itemMap ) );
218 }
219
220 BOOST_ERROR( (const char*)(wxString::Format( "Zone fill regression: %s failed", relPath ).utf8_str()) );
221 }
222 }
223}
224
225
226BOOST_FIXTURE_TEST_CASE( RegressionSliverZoneFillTests, ZONE_FILL_TEST_FIXTURE )
227{
228 std::vector<wxString> tests = { "issue16182" // Slivers
229 };
230
231 for( const wxString& relPath : tests )
232 {
233 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
234
235 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
236
237 KI_TEST::FillZones( m_board.get() );
238
239 std::vector<DRC_ITEM> violations;
240
241 bds.m_DRCEngine->SetViolationHandler(
242 [&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
243 {
244 if( aItem->GetErrorCode() == DRCE_COPPER_SLIVER )
245 violations.push_back( *aItem );
246 } );
247
248 bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
249
250 if( violations.empty() )
251 {
252 BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
253 BOOST_TEST_MESSAGE( (const char*)(wxString::Format( "Zone fill copper sliver regression: %s passed", relPath ).utf8_str()) );
254 }
255 else
256 {
258
259 std::map<KIID, EDA_ITEM*> itemMap;
260 m_board->FillItemMap( itemMap );
261
262 for( const DRC_ITEM& item : violations )
263 {
264 BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
265 itemMap ) );
266 }
267
268 BOOST_ERROR( (const char*)(wxString::Format( "Zone fill copper sliver regression: %s failed", relPath ).utf8_str()) );
269 }
270 }
271}
272
273
275{
276
277 std::vector<std::pair<wxString,int>> tests = { { "teardrop_issue_JPC2", 5 } // Arcs with teardrops connecting to pads
278 };
279
280 for( auto& [ relPath, count ] : tests )
281 {
282 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
283
284 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
285
286 KI_TEST::FillZones( m_board.get() );
287
288 int zoneCount = 0;
289
290 for( ZONE* zone : m_board->Zones() )
291 {
292 if( zone->IsTeardropArea() )
293 zoneCount++;
294 }
295
296 BOOST_CHECK_MESSAGE( zoneCount == count, "Expected " << count << " teardrop zones in "
297 << relPath << ", found "
298 << zoneCount );
299 }
300}
301
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
Definition: kiid.h:49
Definition: pad.h:59
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union For aFastMode meaning, see function booleanOp.
int OutlineCount() const
Return the number of outlines in the set.
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
@ DRCE_CLEARANCE
Definition: drc_item.h:43
@ DRCE_COPPER_SLIVER
Definition: drc_item.h:85
@ 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
const double IU_PER_MM
Definition: base_units.h:76
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
constexpr int delta
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
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:85
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588