KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_unconnected_save.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 * 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
31#include <board.h>
33#include <pcb_marker.h>
34#include <drc/drc_item.h>
37
39{
41 m_settingsManager( true /* headless */ )
42 {
43 m_board = std::make_unique<BOARD>();
44 m_board->SetProject( &m_settingsManager.Prj() );
45 }
46
48 std::unique_ptr<BOARD> m_board;
49};
50
51
53{
54 // Create a mock unconnected items DRC marker
55 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
56 drcItem->SetItems( KIID( "12345678-1234-1234-1234-123456789abc" ), KIID( "87654321-4321-4321-4321-cba987654321" ) );
57
58 PCB_MARKER* marker = new PCB_MARKER( drcItem, VECTOR2I( 1000, 1000 ) );
59 m_board->Add( marker );
60
61 // Exclude the marker
62 marker->SetExcluded( true, "Test exclusion comment" );
63
64 // Record the DRC exclusions (this is what happens during save)
65 m_board->RecordDRCExclusions();
66
67 // Verify the exclusion was recorded
68 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
69 BOOST_CHECK( !bds.m_DrcExclusions.empty() );
70
71 // Get the serialized exclusion
72 wxString serialized = marker->SerializeToString();
73 BOOST_CHECK( bds.m_DrcExclusions.count( serialized ) == 1 );
74 BOOST_CHECK( bds.m_DrcExclusionComments[serialized] == "Test exclusion comment" );
75
76 // Simulate saving and reloading
77 // Clear the marker but keep the exclusions in design settings
78 m_board->DeleteMARKERs();
79
80 // Create a new marker with the same properties
81 std::shared_ptr<DRC_ITEM> newDrcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
82 newDrcItem->SetItems( KIID( "12345678-1234-1234-1234-123456789abc" ),
83 KIID( "87654321-4321-4321-4321-cba987654321" ) );
84
85 PCB_MARKER* newMarker = new PCB_MARKER( newDrcItem, VECTOR2I( 1000, 1000 ) );
86 m_board->Add( newMarker );
87
88 // Resolve exclusions (this is what happens when loading)
89 m_board->ResolveDRCExclusions( false );
90
91 // Verify the exclusion was restored
92 BOOST_CHECK( newMarker->IsExcluded() );
93 BOOST_CHECK( newMarker->GetComment() == "Test exclusion comment" );
94}
95
96
97BOOST_FIXTURE_TEST_CASE( DRCUnconnectedExclusionsMultipleSave, DRC_UNCONNECTED_SAVE_FIXTURE )
98{
99 // Create multiple unconnected items DRC markers
100 for( int i = 0; i < 5; ++i )
101 {
102 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
103 wxString id1 = wxString::Format( "12345678-1234-1234-1234-12345678%04d", i );
104 wxString id2 = wxString::Format( "87654321-4321-4321-4321-87654321%04d", i );
105 drcItem->SetItems( KIID( id1 ), KIID( id2 ) );
106
107 PCB_MARKER* marker = new PCB_MARKER( drcItem, VECTOR2I( 1000 * i, 1000 * i ) );
108 m_board->Add( marker );
109
110 // Exclude odd-numbered markers
111 if( i % 2 == 1 )
112 {
113 marker->SetExcluded( true, wxString::Format( "Exclusion %d", i ) );
114 }
115 }
116
117 // Record the DRC exclusions
118 m_board->RecordDRCExclusions();
119
120 // Verify the correct number of exclusions
121 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
122 BOOST_CHECK_EQUAL( bds.m_DrcExclusions.size(), 2 ); // Only odd markers: 1 and 3
123
124 // Clear all markers
125 m_board->DeleteMARKERs();
126
127 // Recreate all markers
128 for( int i = 0; i < 5; ++i )
129 {
130 std::shared_ptr<DRC_ITEM> drcItem = DRC_ITEM::Create( DRCE_UNCONNECTED_ITEMS );
131 wxString id1 = wxString::Format( "12345678-1234-1234-1234-12345678%04d", i );
132 wxString id2 = wxString::Format( "87654321-4321-4321-4321-87654321%04d", i );
133 drcItem->SetItems( KIID( id1 ), KIID( id2 ) );
134
135 PCB_MARKER* marker = new PCB_MARKER( drcItem, VECTOR2I( 1000 * i, 1000 * i ) );
136 m_board->Add( marker );
137 }
138
139 // Resolve exclusions
140 m_board->ResolveDRCExclusions( false );
141
142 // Verify only the correct markers are excluded
143 int excludedCount = 0;
144 for( PCB_MARKER* marker : m_board->Markers() )
145 {
146 if( marker->IsExcluded() )
147 {
148 excludedCount++;
149 // Verify it was one of the odd-numbered markers
150 BOOST_CHECK( marker->GetComment().Contains( "1" ) || marker->GetComment().Contains( "3" ) );
151 }
152 }
153 BOOST_CHECK_EQUAL( excludedCount, 2 );
154}
Container for design settings for a BOARD object.
std::map< wxString, wxString > m_DrcExclusionComments
std::set< wxString > m_DrcExclusions
static std::shared_ptr< DRC_ITEM > Create(int aErrorCode)
Constructs a DRC_ITEM for the given error code.
Definition: drc_item.cpp:393
Definition: kiid.h:49
bool IsExcluded() const
Definition: marker_base.h:93
void SetExcluded(bool aExcluded, const wxString &aComment=wxEmptyString)
Definition: marker_base.h:94
wxString GetComment() const
Definition: marker_base.h:100
wxString SerializeToString() const
Definition: pcb_marker.cpp:98
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
@ DRCE_UNCONNECTED_ITEMS
Definition: drc_item.h:39
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_FIXTURE_TEST_CASE(DRCUnconnectedExclusionsSave, DRC_UNCONNECTED_SAVE_FIXTURE)
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695