KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_copper_thieving.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, see <http://www.gnu.org/licenses/>.
18 */
19
22#include <board.h>
24#include <drc/drc_engine.h>
25#include <drc/drc_item.h>
26#include <pcb_marker.h>
28#include <zone.h>
29
30
38
39
46BOOST_FIXTURE_TEST_CASE( ThievingZoneProducesNoIsolatedCopperViolations,
48{
49 m_board = std::make_unique<BOARD>();
50 m_board->SetCopperLayerCount( 2 );
51
52 // Each thieving stamp is an isolated island; without the DRC exclusion every
53 // one would trigger DRCE_ISOLATED_COPPER.
54 ZONE* zone = new ZONE( m_board.get() );
55 zone->SetLayer( F_Cu );
56 zone->AppendCorner( VECTOR2I( 0, 0 ), -1 );
57 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), 0 ), -1 );
58 zone->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ), -1 );
59 zone->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 20 ) ), -1 );
61
62 THIEVING_SETTINGS thieving;
64 thieving.element_size = pcbIUScale.mmToIU( 0.5 );
65 thieving.gap = pcbIUScale.mmToIU( 2.0 );
66 zone->SetThievingSettings( thieving );
68 m_board->Add( zone );
69
70 KI_TEST::FillZones( m_board.get() );
71
72 int isolatedCount = 0;
73 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
74
75 // Synthetic boards skip the loader, so the DRC engine is not yet wired up.
76 // The loader does this at board_loader.cpp:132; replicate it here.
77 if( !bds.m_DRCEngine )
78 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
79
80 bds.m_DRCEngine->InitEngine( wxFileName() );
81
82 // Disable all DRC checks except the one we care about so the test focuses on
83 // the isolated-copper path and runs fast on a synthetic board.
84 for( int code = 0; code < DRCE_LAST; ++code )
85 {
86 if( code != DRCE_ISOLATED_COPPER )
88 }
89
91 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
92 const std::function<void( PCB_MARKER* )>& /*aPathGenerator*/ )
93 {
94 if( aItem->GetErrorCode() == DRCE_ISOLATED_COPPER )
95 ++isolatedCount;
96 } );
97
98 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
99
100 BOOST_CHECK_EQUAL( isolatedCount, 0 );
101}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
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:168
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:603
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition zone.cpp:609
void SetThievingSettings(const THIEVING_SETTINGS &aSettings)
Definition zone.h:356
bool AppendCorner(VECTOR2I aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition zone.cpp:1280
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:825
@ DRCE_ISOLATED_COPPER
Definition drc_item.h:49
@ DRCE_LAST
Definition drc_item.h:124
@ F_Cu
Definition layer_ids.h:64
void FillZones(BOARD *m_board)
@ RPT_SEVERITY_IGNORE
Parameters that drive copper-thieving fill generation.
THIEVING_PATTERN pattern
BOOST_FIXTURE_TEST_CASE(ThievingZoneProducesNoIsolatedCopperViolations, DRC_COPPER_THIEVING_FIXTURE)
A copper-thieving zone produces a grid of intentionally-isolated stamps.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687