KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_multichannel.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 (C) 2024 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
26#include <board.h>
28#include <pad.h>
29#include <pcb_track.h>
30#include <footprint.h>
31#include <zone.h>
32#include <drc/drc_item.h>
36
38{
39 MULTICHANNEL_TEST_FIXTURE() : m_settingsManager( true /* headless */ ) {}
40
42 std::unique_ptr<BOARD> m_board;
43};
44
46{
47public:
50
51 virtual wxWindow* GetToolCanvas() const override { return nullptr; }
52};
53
54BOOST_FIXTURE_TEST_SUITE( MultichannelTool, MULTICHANNEL_TEST_FIXTURE )
55
56RULE_AREA* findRuleAreaByPartialName( MULTICHANNEL_TOOL* aTool, const wxString& aName )
57{
58 for( RULE_AREA& ra : aTool->GetData()->m_areas )
59 {
60 if( ra.m_ruleName.Contains( ( aName ) ) )
61 return &ra;
62 }
63
64 return nullptr;
65}
66
67
69{
71
72 std::vector<wxString> tests = { "vme-wren" };
73
74 for( const wxString& relPath : tests )
75 {
76 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
77
78 TOOL_MANAGER toolMgr;
79 MOCK_TOOLS_HOLDER* toolsHolder = new MOCK_TOOLS_HOLDER;
80
81 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, toolsHolder );
82
83 MULTICHANNEL_TOOL* mtTool = new MULTICHANNEL_TOOL; // TOOL_MANAGER owns the tools
84 toolMgr.RegisterTool( mtTool );
85
86 //RULE_AREAS_DATA* raData = m_parentTool->GetData();
87
89
90 auto ruleData = mtTool->GetData();
91
92 BOOST_TEST_MESSAGE( wxString::Format( "RA multichannel sheets = %d",
93 static_cast<int>( ruleData->m_areas.size() ) ) );
94
95 BOOST_CHECK_EQUAL( ruleData->m_areas.size(), 72 );
96
97 int cnt = 0;
98
99 ruleData->m_replaceExisting = true;
100
101 for( RULE_AREA& ra : ruleData->m_areas )
102 {
103 if( ra.m_sheetName == wxT( "io_driver.kicad_sch" )
104 || ra.m_sheetName == wxT( "pp_driver_2x.kicad_sch" ) )
105 {
106 ra.m_generateEnabled = true;
107 cnt++;
108 }
109 }
110
111 BOOST_TEST_MESSAGE( wxString::Format( "Autogenerating %d RAs", cnt ) );
112
113 TOOL_EVENT dummyEvent;
114
115 mtTool->AutogenerateRuleAreas( dummyEvent );
116 mtTool->FindExistingRuleAreas();
117
118 int n_areas_io = 0, n_areas_pp = 0, n_areas_other = 0;
119
120 BOOST_TEST_MESSAGE( wxString::Format( "Found %d RAs after commit",
121 static_cast<int>(ruleData->m_areas.size() ) ) );
122
123 for( const RULE_AREA& ra : ruleData->m_areas )
124 {
125 BOOST_TEST_MESSAGE( wxString::Format( "SN '%s'", ra.m_ruleName ) );
126
127 if( ra.m_ruleName.Contains( wxT( "io_drivers_fp" ) ) )
128 {
129 n_areas_io++;
130 BOOST_CHECK_EQUAL( ra.m_raFootprints.size(), 31 );
131 }
132 else if( ra.m_ruleName.Contains( wxT( "io_drivers_pp" ) ) )
133 {
134 n_areas_pp++;
135 BOOST_CHECK_EQUAL( ra.m_raFootprints.size(), 11 );
136 }
137 else
138 {
139 n_areas_other++;
140 }
141 }
142
143 BOOST_TEST_MESSAGE( wxString::Format( "IO areas=%d, PP areas=%d, others=%d",
144 n_areas_io, n_areas_pp, n_areas_other ) );
145
146 BOOST_CHECK_EQUAL( n_areas_io, 16 );
147 BOOST_CHECK_EQUAL( n_areas_pp, 16 );
148 BOOST_CHECK_EQUAL( n_areas_other, 0 );
149
150 const std::vector<wxString> rulesToTest = { wxT( "io_drivers_fp" ),
151 wxT( "io_drivers_pp" ) };
152
153 for( const wxString& ruleName : rulesToTest )
154 {
155 for( const RULE_AREA& refArea : ruleData->m_areas )
156 {
157 if( !refArea.m_ruleName.Contains( ruleName ) )
158 continue;
159
160 BOOST_TEST_MESSAGE( wxString::Format( "REF AREA: '%s'", refArea.m_ruleName ) );
161
162 for( const RULE_AREA& targetArea : ruleData->m_areas )
163 {
164 if( targetArea.m_area == refArea.m_area )
165 continue;
166
167 if( !targetArea.m_ruleName.Contains( ruleName ) )
168 continue;
169
170 auto cgRef = CONNECTION_GRAPH::BuildFromFootprintSet( refArea.m_raFootprints );
171 auto cgTarget =
172 CONNECTION_GRAPH::BuildFromFootprintSet( targetArea.m_raFootprints );
173
175
176 CONNECTION_GRAPH::STATUS status =
177 cgRef->FindIsomorphism( cgTarget.get(), result );
178
179 BOOST_TEST_MESSAGE( wxString::Format(
180 "topo match: '%s' [%d] -> '%s' [%d] result %d",
181 refArea.m_ruleName.c_str().AsChar(),
182 static_cast<int>( refArea.m_raFootprints.size() ),
183 targetArea.m_ruleName.c_str().AsChar(),
184 static_cast<int>( targetArea.m_raFootprints.size() ), status ) );
185
186 for( const auto& iter : result )
187 {
188 BOOST_TEST_MESSAGE( wxString::Format( "%s : %s",
189 iter.second->GetReference(),
190 iter.first->GetReference() ) );
191 }
192
193 BOOST_CHECK_EQUAL( status, TMATCH::CONNECTION_GRAPH::ST_OK );
194 }
195 }
196 }
197
198 auto refArea = findRuleAreaByPartialName( mtTool, wxT( "io_drivers_fp/bank3/io78/" ) );
199
200 BOOST_ASSERT( refArea );
201
202 const std::vector<wxString> targetAreaNames( { wxT( "io_drivers_fp/bank2/io78/" ),
203 wxT( "io_drivers_fp/bank1/io78/" ),
204 wxT( "io_drivers_fp/bank0/io01/" ) } );
205
206 for( const wxString& targetRaName : targetAreaNames )
207 {
208 auto targetRA = findRuleAreaByPartialName( mtTool, targetRaName );
209
210 BOOST_ASSERT( targetRA != nullptr );
211
212 BOOST_TEST_MESSAGE( wxString::Format( "Clone to: %s", targetRA->m_ruleName ) );
213
214 ruleData->m_compatMap[targetRA].m_doCopy = true;
215 }
216
217 int result = mtTool->RepeatLayout( TOOL_EVENT(), refArea->m_area );
218
219 BOOST_ASSERT( result >= 0 );
220 }
221}
222
223
virtual wxWindow * GetToolCanvas() const override
Canvas access.
RULE_AREAS_DATA * GetData()
int RepeatLayout(const TOOL_EVENT &aEvent, ZONE *aRefZone)
int AutogenerateRuleAreas(const TOOL_EVENT &aEvent)
Generic, UI-independent tool event.
Definition: tool_event.h:167
Master controller class:
Definition: tool_manager.h:62
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
std::map< FOOTPRINT *, FOOTPRINT * > COMPONENT_MATCHES
Definition: topo_match.h:149
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< BOARD > m_board
wxString m_sheetName
std::set< FOOTPRINT * > m_raFootprints
wxString m_ruleName
bool m_generateEnabled
BOOST_AUTO_TEST_SUITE_END()
RULE_AREA * findRuleAreaByPartialName(MULTICHANNEL_TOOL *aTool, const wxString &aName)
BOOST_FIXTURE_TEST_CASE(MultichannelToolRegressions, MULTICHANNEL_TEST_FIXTURE)