KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_silk_rule_area_issue24177.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 */
20
39
41
42#include <board.h>
44#include <pcb_shape.h>
45#include <pcb_track.h>
46#include <zone.h>
47#include <drc/drc_engine.h>
48#include <drc/drc_item.h>
51
52
60
61
62BOOST_FIXTURE_TEST_CASE( RuleAreaDoesNotCauseSilkOrMaskViolationsIssue24177,
64{
65 m_board = std::make_unique<BOARD>();
66 m_board->SetCopperLayerCount( 2 );
67
68 // Logical rule area on F.Cu. Its layer set covers the mask and silk targets
69 // that the silk-clearance and solder-mask providers walk; without the fix
70 // the providers would insert this zone into their rtrees and report bogus
71 // clearance violations against the silk segment below.
72 ZONE* ruleArea = new ZONE( m_board.get() );
73 ruleArea->SetIsRuleArea( true );
74 ruleArea->SetLayerSet( LSET( { F_Cu, F_Mask, F_SilkS } ) );
75 ruleArea->AppendCorner( VECTOR2I( 0, 0 ), -1 );
76 ruleArea->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), 0 ), -1 );
77 ruleArea->AppendCorner( VECTOR2I( pcbIUScale.mmToIU( 20 ), pcbIUScale.mmToIU( 20 ) ), -1 );
78 ruleArea->AppendCorner( VECTOR2I( 0, pcbIUScale.mmToIU( 20 ) ), -1 );
79 m_board->Add( ruleArea );
80
81 // Silk segment placed across the rule-area boundary so any collision-based
82 // check using the rule area's effective shape would flag it.
83 PCB_SHAPE* silk = new PCB_SHAPE( m_board.get(), SHAPE_T::SEGMENT );
84 silk->SetLayer( F_SilkS );
85 silk->SetStart( VECTOR2I( pcbIUScale.mmToIU( 5 ), pcbIUScale.mmToIU( 10 ) ) );
86 silk->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 25 ), pcbIUScale.mmToIU( 10 ) ) );
87 silk->SetStroke( STROKE_PARAMS( pcbIUScale.mmToIU( 0.15 ), LINE_STYLE::SOLID ) );
88 m_board->Add( silk );
89
90 // Unrelated copper trace to keep the connectivity graph non-trivial.
91 PCB_TRACK* trace = new PCB_TRACK( m_board.get() );
92 trace->SetLayer( F_Cu );
93 trace->SetStart( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 0 ) ) );
94 trace->SetEnd( VECTOR2I( pcbIUScale.mmToIU( 30 ), pcbIUScale.mmToIU( 20 ) ) );
95 trace->SetWidth( pcbIUScale.mmToIU( 0.2 ) );
96 m_board->Add( trace );
97
98 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
99
100 if( !bds.m_DRCEngine )
101 bds.m_DRCEngine = std::make_shared<DRC_ENGINE>( m_board.get(), &bds );
102
103 bds.m_DRCEngine->InitEngine( wxFileName() );
104
105 // Focus the run on the providers we changed.
106 for( int code = 0; code < DRCE_LAST; ++code )
108
113
114 int silkClearance = 0;
115 int silkMaskClearance = 0;
116 int silkEdgeClearance = 0;
117 int solderMaskBridge = 0;
118
120 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
121 const std::function<void( PCB_MARKER* )>& /*aPathGenerator*/ )
122 {
123 switch( aItem->GetErrorCode() )
124 {
125 case DRCE_SILK_CLEARANCE: ++silkClearance; break;
126 case DRCE_SILK_MASK_CLEARANCE: ++silkMaskClearance; break;
127 case DRCE_SILK_EDGE_CLEARANCE: ++silkEdgeClearance; break;
128 case DRCE_SOLDERMASK_BRIDGE: ++solderMaskBridge; break;
129 default: break;
130 }
131 } );
132
133 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
134
136
137 BOOST_CHECK_EQUAL( silkClearance, 0 );
138 BOOST_CHECK_EQUAL( silkMaskClearance, 0 );
139 BOOST_CHECK_EQUAL( silkEdgeClearance, 0 );
140 BOOST_CHECK_EQUAL( solderMaskBridge, 0 );
141}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:125
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
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 ClearViolationHandler()
Definition drc_engine.h:173
void InitEngine(const wxFileName &aRulePath)
Initialize the DRC engine.
void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:198
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:240
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition pcb_shape.h:98
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:93
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:96
virtual void SetWidth(int aWidth)
Definition pcb_track.h:90
Simple container to manage line stroke parameters.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
void SetIsRuleArea(bool aEnable)
Definition zone.h:803
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:628
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
@ DRCE_SILK_EDGE_CLEARANCE
Definition drc_item.h:99
@ DRCE_SILK_MASK_CLEARANCE
Definition drc_item.h:97
@ DRCE_SOLDERMASK_BRIDGE
Definition drc_item.h:94
@ DRCE_SILK_CLEARANCE
Definition drc_item.h:100
@ DRCE_LAST
Definition drc_item.h:124
@ SEGMENT
Definition eda_shape.h:50
@ F_Mask
Definition layer_ids.h:97
@ F_SilkS
Definition layer_ids.h:100
@ F_Cu
Definition layer_ids.h:64
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
DRC_SILK_RULE_AREA_FIXTURE()=default
BOOST_FIXTURE_TEST_CASE(RuleAreaDoesNotCauseSilkOrMaskViolationsIssue24177, DRC_SILK_RULE_AREA_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687