2021-07-30 16:08:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-08-03 13:32:49 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-07-30 16:08:12 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2022-03-18 20:05:15 +00:00
|
|
|
#include <pcbnew_utils/board_test_utils.h>
|
2021-07-30 16:08:12 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
#include <pad.h>
|
|
|
|
#include <pcb_track.h>
|
|
|
|
#include <footprint.h>
|
2021-08-03 13:32:49 +00:00
|
|
|
#include <zone.h>
|
2021-07-30 16:08:12 +00:00
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
|
2021-07-30 16:08:12 +00:00
|
|
|
struct ZONE_FILL_TEST_FIXTURE
|
|
|
|
{
|
|
|
|
ZONE_FILL_TEST_FIXTURE() :
|
|
|
|
m_settingsManager( true /* headless */ )
|
2021-08-03 13:32:49 +00:00
|
|
|
{ }
|
2021-07-31 15:31:38 +00:00
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
SETTINGS_MANAGER m_settingsManager;
|
|
|
|
std::unique_ptr<BOARD> m_board;
|
2021-07-30 16:08:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-09-17 00:45:14 +00:00
|
|
|
constexpr int delta = KiROUND( 0.006 * pcbIUScale.IU_PER_MM );
|
2021-07-30 16:08:12 +00:00
|
|
|
|
|
|
|
|
2021-07-31 19:12:52 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( BasicZoneFills, ZONE_FILL_TEST_FIXTURE )
|
2021-07-30 16:08:12 +00:00
|
|
|
{
|
2021-08-03 13:32:49 +00:00
|
|
|
KI_TEST::LoadBoard( m_settingsManager, "zone_filler", m_board );
|
2021-07-30 16:08:12 +00:00
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
KI_TEST::FillZones( m_board.get() );
|
2021-07-30 16:08:12 +00:00
|
|
|
|
|
|
|
// Now that the zones are filled we're going to increase the size of -some- pads and
|
|
|
|
// tracks so that they generate DRC errors. The test then makes sure that those errors
|
|
|
|
// are generated, and that the other pads and tracks do -not- generate errors.
|
|
|
|
|
|
|
|
for( PAD* pad : m_board->Footprints()[0]->Pads() )
|
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
if( pad->GetNumber() == "2" || pad->GetNumber() == "4" || pad->GetNumber() == "6" )
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( pad->GetSize() + VECTOR2I( delta, delta ) );
|
2021-07-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ii = 0;
|
|
|
|
KIID arc8;
|
|
|
|
KIID arc12;
|
|
|
|
|
|
|
|
for( PCB_TRACK* track : m_board->Tracks() )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_ARC_T )
|
|
|
|
{
|
|
|
|
ii++;
|
|
|
|
|
|
|
|
if( ii == 8 )
|
|
|
|
{
|
|
|
|
arc8 = track->m_Uuid;
|
|
|
|
track->SetWidth( track->GetWidth() + delta + delta );
|
|
|
|
}
|
|
|
|
else if( ii == 12 )
|
|
|
|
{
|
|
|
|
arc12 = track->m_Uuid;
|
2023-02-19 03:40:07 +00:00
|
|
|
track->Move( VECTOR2I( -delta, -delta ) );
|
2021-07-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool foundPad2Error = false;
|
|
|
|
bool foundPad4Error = false;
|
|
|
|
bool foundPad6Error = false;
|
|
|
|
bool foundArc8Error = false;
|
|
|
|
bool foundArc12Error = false;
|
|
|
|
bool foundOtherError = false;
|
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
bds.m_DRCEngine->InitEngine( wxFileName() ); // Just to be sure to be sure
|
2021-07-30 16:08:12 +00:00
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
bds.m_DRCEngine->SetViolationHandler(
|
2022-08-15 16:59:34 +00:00
|
|
|
[&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
|
2021-07-30 16:08:12 +00:00
|
|
|
{
|
|
|
|
if( aItem->GetErrorCode() == DRCE_CLEARANCE )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item_a = m_board->GetItem( aItem->GetMainItemID() );
|
|
|
|
PAD* pad_a = dynamic_cast<PAD*>( item_a );
|
|
|
|
PCB_TRACK* trk_a = dynamic_cast<PCB_TRACK*>( item_a );
|
|
|
|
|
|
|
|
BOARD_ITEM* item_b = m_board->GetItem( aItem->GetAuxItemID() );
|
|
|
|
PAD* pad_b = dynamic_cast<PAD*>( item_b );
|
|
|
|
PCB_TRACK* trk_b = dynamic_cast<PCB_TRACK*>( item_b );
|
|
|
|
|
2021-08-23 23:10:21 +00:00
|
|
|
if( pad_a && pad_a->GetNumber() == "2" ) foundPad2Error = true;
|
|
|
|
else if( pad_a && pad_a->GetNumber() == "4" ) foundPad4Error = true;
|
|
|
|
else if( pad_a && pad_a->GetNumber() == "6" ) foundPad6Error = true;
|
|
|
|
else if( pad_b && pad_b->GetNumber() == "2" ) foundPad2Error = true;
|
|
|
|
else if( pad_b && pad_b->GetNumber() == "4" ) foundPad4Error = true;
|
|
|
|
else if( pad_b && pad_b->GetNumber() == "6" ) foundPad6Error = true;
|
|
|
|
else if( trk_a && trk_a->m_Uuid == arc8 ) foundArc8Error = true;
|
|
|
|
else if( trk_a && trk_a->m_Uuid == arc12 ) foundArc12Error = true;
|
|
|
|
else if( trk_b && trk_b->m_Uuid == arc8 ) foundArc8Error = true;
|
|
|
|
else if( trk_b && trk_b->m_Uuid == arc12 ) foundArc12Error = true;
|
|
|
|
else foundOtherError = true;
|
2021-07-30 16:08:12 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2021-08-03 13:32:49 +00:00
|
|
|
bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
|
2021-07-30 16:08:12 +00:00
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( foundPad2Error, true );
|
|
|
|
BOOST_CHECK_EQUAL( foundPad4Error, true );
|
|
|
|
BOOST_CHECK_EQUAL( foundPad6Error, true );
|
|
|
|
BOOST_CHECK_EQUAL( foundArc8Error, true );
|
|
|
|
BOOST_CHECK_EQUAL( foundArc12Error, true );
|
|
|
|
BOOST_CHECK_EQUAL( foundOtherError, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-31 19:12:52 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( NotchedZones, ZONE_FILL_TEST_FIXTURE )
|
2021-07-30 20:15:21 +00:00
|
|
|
{
|
2021-08-03 13:32:49 +00:00
|
|
|
KI_TEST::LoadBoard( m_settingsManager, "notched_zones", m_board );
|
2021-07-30 20:15:21 +00:00
|
|
|
|
|
|
|
// Older algorithms had trouble where the filleted zones intersected and left notches.
|
|
|
|
// See:
|
|
|
|
// https://gitlab.com/kicad/code/kicad/-/issues/2737
|
|
|
|
// https://gitlab.com/kicad/code/kicad/-/issues/2752
|
|
|
|
SHAPE_POLY_SET frontCopper;
|
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
KI_TEST::FillZones( m_board.get() );
|
2021-08-03 13:32:49 +00:00
|
|
|
|
2021-07-30 20:15:21 +00:00
|
|
|
frontCopper = SHAPE_POLY_SET();
|
|
|
|
|
|
|
|
for( ZONE* zone : m_board->Zones() )
|
|
|
|
{
|
|
|
|
if( zone->GetLayerSet().Contains( F_Cu ) )
|
|
|
|
{
|
2022-02-15 17:34:38 +00:00
|
|
|
frontCopper.BooleanAdd( *zone->GetFilledPolysList( F_Cu ),
|
2021-07-30 20:15:21 +00:00
|
|
|
SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( frontCopper.OutlineCount(), 2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-31 19:12:52 +00:00
|
|
|
BOOST_FIXTURE_TEST_CASE( RegressionZoneFillTests, ZONE_FILL_TEST_FIXTURE )
|
2021-07-30 20:15:21 +00:00
|
|
|
{
|
2021-07-31 15:31:38 +00:00
|
|
|
std::vector<wxString> tests = { "issue18",
|
|
|
|
"issue2568",
|
|
|
|
"issue3812",
|
|
|
|
"issue5102",
|
|
|
|
"issue5313",
|
|
|
|
"issue5320",
|
|
|
|
"issue5567",
|
|
|
|
"issue5830",
|
|
|
|
"issue6039",
|
|
|
|
"issue6260",
|
|
|
|
"issue6284",
|
2023-07-07 18:03:09 +00:00
|
|
|
"issue7086",
|
2023-07-26 19:36:13 +00:00
|
|
|
"issue14294", // Bad Clipper2 fill
|
|
|
|
"fill_bad" // Missing zone clearance expansion
|
2023-07-07 18:03:09 +00:00
|
|
|
};
|
2021-07-31 15:31:38 +00:00
|
|
|
|
|
|
|
for( const wxString& relPath : tests )
|
2021-07-30 20:15:21 +00:00
|
|
|
{
|
2021-08-03 13:32:49 +00:00
|
|
|
KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
|
|
|
|
|
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
KI_TEST::FillZones( m_board.get() );
|
|
|
|
|
|
|
|
std::vector<DRC_ITEM> violations;
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
bds.m_DRCEngine->SetViolationHandler(
|
2022-08-15 16:59:34 +00:00
|
|
|
[&]( const std::shared_ptr<DRC_ITEM>& aItem, VECTOR2I aPos, int aLayer )
|
2022-02-11 12:42:09 +00:00
|
|
|
{
|
|
|
|
if( aItem->GetErrorCode() == DRCE_CLEARANCE )
|
|
|
|
violations.push_back( *aItem );
|
|
|
|
} );
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
bds.m_DRCEngine->RunTests( EDA_UNITS::MILLIMETRES, true, false );
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
if( violations.empty() )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL( 1, 1 ); // quiet "did not check any assertions" warning
|
2022-03-21 12:49:07 +00:00
|
|
|
BOOST_TEST_MESSAGE( (const char*)(wxString::Format( "Zone fill regression: %s passed", relPath ).utf8_str()) );
|
2022-02-11 12:42:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-19 16:09:59 +00:00
|
|
|
UNITS_PROVIDER unitsProvider( pcbIUScale, EDA_UNITS::INCHES );
|
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
std::map<KIID, EDA_ITEM*> itemMap;
|
|
|
|
m_board->FillItemMap( itemMap );
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-02-11 12:42:09 +00:00
|
|
|
for( const DRC_ITEM& item : violations )
|
2021-07-31 15:31:38 +00:00
|
|
|
{
|
2022-09-19 16:09:59 +00:00
|
|
|
BOOST_TEST_MESSAGE( item.ShowReport( &unitsProvider, RPT_SEVERITY_ERROR,
|
2022-02-11 12:42:09 +00:00
|
|
|
itemMap ) );
|
2021-07-31 15:31:38 +00:00
|
|
|
}
|
2021-07-30 20:15:21 +00:00
|
|
|
|
2022-03-21 12:49:07 +00:00
|
|
|
BOOST_ERROR( (const char*)(wxString::Format( "Zone fill regression: %s failed", relPath ).utf8_str()) );
|
2021-07-30 20:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|