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