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) 2021 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{
40 m_settingsManager( true /* headless */ )
41 { }
42
44 std::unique_ptr<BOARD> m_board;
45};
46
48{
49public:
52
53 virtual wxWindow* GetToolCanvas() const override { return nullptr; }
54};
55
56BOOST_FIXTURE_TEST_SUITE( MultichannelTool, MULTICHANNEL_TEST_FIXTURE )
57
58RULE_AREA* findRuleAreaByPartialName( MULTICHANNEL_TOOL* aTool, const wxString& aName )
59{
60 auto ruleData = aTool->GetData();
61
62 for( auto& ra : ruleData->m_areas )
63 {
64 if( ra.m_ruleName.Contains(( aName ) ) )
65 return &ra;
66 }
67
68 return nullptr;
69}
70
71
73{
74 std::vector<wxString> tests = {
75 "vme-wren"
76 };
77
78 for( const wxString& relPath : tests )
79 {
80 KI_TEST::LoadBoard( m_settingsManager, relPath, m_board );
81
82 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
83
84 TOOL_MANAGER toolMgr;
85 MOCK_TOOLS_HOLDER *toolsHolder = new MOCK_TOOLS_HOLDER;
86
87 toolMgr.SetEnvironment( m_board.get(), nullptr, nullptr, nullptr, toolsHolder );
88
89 MULTICHANNEL_TOOL *mtTool = new MULTICHANNEL_TOOL; // TOOL_MANAGER owns the tools
90 toolMgr.RegisterTool( mtTool );
91
92 //RULE_AREAS_DATA* raData = m_parentTool->GetData();
93
94 mtTool->QuerySheets();
95
96 auto ruleData = mtTool->GetData();
97
98 printf("RA multichannel sheets = %d\n", (int) ruleData->m_areas.size() );
99
100 BOOST_CHECK_EQUAL( ruleData->m_areas.size(), 72 );
101
102 int cnt = 0;
103
104 ruleData->m_replaceExisting = true;
105 for( auto& ra : ruleData->m_areas )
106 {
107 if ( ra.m_sheetName == wxT("io_driver.kicad_sch") || ra.m_sheetName == wxT("pp_driver_2x.kicad_sch") )
108 {
109 ra.m_generateEnabled = true;
110 cnt++;
111 }
112 }
113
114 printf("Autogenerating %d RAs\n", cnt );
115
116 TOOL_EVENT dummyEvent;
117
118 mtTool->AutogenerateRuleAreas( dummyEvent );
119 mtTool->FindExistingRuleAreas();
120
121 int n_areas_io = 0, n_areas_pp = 0, n_areas_other = 0;
122
123
124 printf("Found %d RAs after commit\n", (int) ruleData->m_areas.size() );
125
126 for( auto ra : ruleData->m_areas )
127 {
128 printf("SN '%s'\n", ra.m_ruleName.c_str().AsChar() );
129 if( ra.m_ruleName.Contains( wxT("io_drivers_fp") ) )
130 {
131 n_areas_io++;
132 BOOST_CHECK_EQUAL( ra.m_raFootprints.size(), 31 );
133 }
134 else if( ra.m_ruleName.Contains( wxT("io_drivers_pp") ) )
135 {
136 n_areas_pp++;
137 BOOST_CHECK_EQUAL( ra.m_raFootprints.size(), 11 );
138 }
139 else
140 {
141 n_areas_other++;
142 }
143 }
144
145 printf("IO areas=%d, PP areas=%d, others=%d\n", n_areas_io, n_areas_pp, n_areas_other );
146
147 BOOST_CHECK_EQUAL( n_areas_io, 16 );
148 BOOST_CHECK_EQUAL( n_areas_pp, 16 );
149 BOOST_CHECK_EQUAL( n_areas_other, 0 );
150
151 const std::vector<wxString> rulesToTest = { wxT("io_drivers_fp" ), wxT("io_drivers_pp" ) };
152
153 for( auto ruleName : rulesToTest )
154 {
155 for( auto refArea : ruleData->m_areas )
156 {
157 if( !refArea.m_ruleName.Contains( ruleName ) )
158 continue;
159
160 printf("REF AREA: '%s'\n", refArea.m_ruleName.c_str().AsChar() );
161
162 for ( auto 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 = TMATCH::CONNECTION_GRAPH::BuildFromFootprintSet( refArea.m_raFootprints );
171 auto cgTarget = TMATCH::CONNECTION_GRAPH::BuildFromFootprintSet( targetArea.m_raFootprints );
172
174
175 auto status = cgRef->FindIsomorphism( cgTarget.get(), result );
176 printf( "topo match: '%s' [%d] -> '%s' [%d] result %d\n",
177 refArea.m_ruleName.c_str().AsChar(),
178 (int) refArea.m_raFootprints.size(),
179 targetArea.m_ruleName.c_str().AsChar(),
180 (int) targetArea.m_raFootprints.size(), status );
181
182 for( const auto& iter : result )
183 {
184 printf("%s : %s\n", iter.second->GetReference().c_str().AsChar(),
185 iter.first->GetReference().c_str().AsChar()
186 );
187 }
188
189 BOOST_CHECK_EQUAL( status, TMATCH::CONNECTION_GRAPH::ST_OK );
190 }
191 }
192 }
193
194 auto refArea = findRuleAreaByPartialName( mtTool, wxT("io_drivers_fp/bank3/io78/") );
195
196 BOOST_ASSERT( refArea );
197
198 const std::vector<wxString> targetAreaNames ( { wxT("io_drivers_fp/bank2/io78/"), wxT("io_drivers_fp/bank1/io78/"), wxT("io_drivers_fp/bank0/io01/") } );
199
200 for( wxString targetRaName : targetAreaNames )
201 {
202 auto targetRA = findRuleAreaByPartialName( mtTool, targetRaName );
203
204 BOOST_ASSERT( targetRA != nullptr );
205
206 printf("Clone to: %s\n", targetRA->m_ruleName.c_str().AsChar() );
207
208 ruleData->m_compatMap[ targetRA ].m_doCopy = true;
209 }
210
211 int result = mtTool->RepeatLayout( TOOL_EVENT(), refArea->m_area );
212
213 BOOST_ASSERT( result >= 0 );
214 }
215}
216
217BOOST_AUTO_TEST_SUITE_END()
Container for design settings for a BOARD object.
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)
static std::unique_ptr< CONNECTION_GRAPH > BuildFromFootprintSet(const std::set< FOOTPRINT * > &aFps)
Definition: topo_match.cpp:520
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:148
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< BOARD > m_board
RULE_AREA * findRuleAreaByPartialName(MULTICHANNEL_TOOL *aTool, const wxString &aName)
BOOST_FIXTURE_TEST_CASE(MultichannelToolRegressions, MULTICHANNEL_TEST_FIXTURE)