KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eagle_board_import.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
24
28
30
31#include <board.h>
32#include <footprint.h>
33#include <netinfo.h>
34#include <pcb_text.h>
35#include <pcb_track.h>
36
37#include <map>
38#include <wx/filename.h>
39
40
45
46
47BOOST_FIXTURE_TEST_SUITE( EagleBoardImport, EAGLE_BOARD_IMPORT_FIXTURE )
48
49
50
60BOOST_AUTO_TEST_CASE( ViaNetAssignment )
61{
62 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
63 + "plugins/eagle/Adafruit-AHT20-PCB/"
64 "Adafruit AHT20 Temperature & Humidity.brd";
65
66 BOOST_REQUIRE_MESSAGE( wxFileName::FileExists( dataPath ),
67 "Test board file not found: " + dataPath );
68
69 PCB_IO_EAGLE eaglePlugin;
70 BOARD* rawBoard = nullptr;
71
72 try
73 {
74 rawBoard = eaglePlugin.LoadBoard( dataPath, nullptr, nullptr );
75 }
76 catch( const IO_ERROR& e )
77 {
78 BOOST_FAIL( "IO_ERROR loading Eagle board: " + e.What().ToStdString() );
79 }
80 catch( const std::exception& e )
81 {
82 BOOST_FAIL( std::string( "Exception loading Eagle board: " ) + e.what() );
83 }
84
85 std::unique_ptr<BOARD> board( rawBoard );
86
87 BOOST_REQUIRE( board );
88
89 // Collect vias grouped by net name
90 std::map<wxString, int> viasPerNet;
91
92 for( PCB_TRACK* track : board->Tracks() )
93 {
94 if( track->Type() == PCB_VIA_T )
95 {
96 NETINFO_ITEM* net = track->GetNet();
97 BOOST_REQUIRE( net );
98
99 wxString netName = net->GetNetname();
100 viasPerNet[netName]++;
101 }
102 }
103
104 // The Eagle board has vias on these nets (verified from the XML source)
105 BOOST_CHECK_GT( viasPerNet[wxT( "SDA" )], 0 );
106 BOOST_CHECK_GT( viasPerNet[wxT( "SCL" )], 0 );
107 BOOST_CHECK_GT( viasPerNet[wxT( "GND" )], 0 );
108 BOOST_CHECK_GT( viasPerNet[wxT( "VCC" )], 0 );
109 BOOST_CHECK_GT( viasPerNet[wxT( "VDD" )], 0 );
110
111 // Verify exact counts from the Eagle XML
112 BOOST_CHECK_EQUAL( viasPerNet[wxT( "SDA" )], 2 );
113 BOOST_CHECK_EQUAL( viasPerNet[wxT( "SCL" )], 2 );
114 BOOST_CHECK_EQUAL( viasPerNet[wxT( "GND" )], 3 );
115 BOOST_CHECK_EQUAL( viasPerNet[wxT( "VCC" )], 2 );
116 BOOST_CHECK_EQUAL( viasPerNet[wxT( "VDD" )], 2 );
117
118 // No via should be unassigned (net code 0)
119 BOOST_CHECK_EQUAL( viasPerNet[wxT( "" )], 0 );
120}
121
122
136BOOST_AUTO_TEST_CASE( TextJustification )
137{
138 std::string dataPath = KI_TEST::GetPcbnewTestDataDir()
139 + "plugins/eagle/test_eagle_23016/test_eagle.brd";
140
141 BOOST_REQUIRE_MESSAGE( wxFileName::FileExists( dataPath ),
142 "Test board file not found: " + dataPath );
143
144 PCB_IO_EAGLE eaglePlugin;
145 BOARD* rawBoard = nullptr;
146
147 try
148 {
149 rawBoard = eaglePlugin.LoadBoard( dataPath, nullptr, nullptr );
150 }
151 catch( const IO_ERROR& e )
152 {
153 BOOST_FAIL( "IO_ERROR loading Eagle board: " + e.What().ToStdString() );
154 }
155 catch( const std::exception& e )
156 {
157 BOOST_FAIL( std::string( "Exception loading Eagle board: " ) + e.what() );
158 }
159
160 std::unique_ptr<BOARD> board( rawBoard );
161
162 BOOST_REQUIRE( board );
163
164 // Board should have 13 elements from the Eagle file
165 BOOST_CHECK_EQUAL( board->Footprints().size(), 13 );
166
167 // Find the I2C connector footprints and verify reference text justification.
168 // I2C0 and I2C1 are smashed but have no NAME attribute, so their Reference text
169 // goes through the non-smashed orientFPText() code path. With the footprint at R90
170 // and the package text at 0 degrees, the combined angle is 180, triggering the
171 // justification flip to RIGHT/TOP. Before the fix, the dead code branch
172 // (abs(degrees) <= -180) would never fire and justification stayed at LEFT/BOTTOM.
173 for( FOOTPRINT* fp : board->Footprints() )
174 {
175 wxString ref = fp->GetReference();
176
177 if( ref == wxT( "I2C0" ) || ref == wxT( "I2C1" ) )
178 {
179 PCB_TEXT& refText = fp->Reference();
180
183 ref + " reference horizontal justification should be RIGHT, got "
184 + std::to_string( refText.GetHorizJustify() ) );
185
188 ref + " reference vertical justification should be TOP, got "
189 + std::to_string( refText.GetVertJustify() ) );
190 }
191 }
192
193 // Verify the plain text pin labels have correct justification.
194 // "G SDA SCL V+" on F.SilkS (Eagle layer 21) should have LEFT/BOTTOM justification
195 // with 90-degree rotation so the text reads bottom-to-top matching the pin order.
196 int topPinLabelCount = 0;
197
198 for( BOARD_ITEM* item : board->Drawings() )
199 {
200 if( item->Type() != PCB_TEXT_T )
201 continue;
202
203 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
204
205 if( text->GetText() != wxT( "G SDA SCL V+" ) )
206 continue;
207
208 if( text->GetLayer() != F_SilkS )
209 continue;
210
211 topPinLabelCount++;
212
214 text->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT,
215 "Pin label text horizontal justification should be LEFT" );
216
218 text->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM,
219 "Pin label text vertical justification should be BOTTOM" );
220
222 text->GetTextAngle() == EDA_ANGLE( 90, DEGREES_T ),
223 "Pin label text angle should be 90 degrees" );
224 }
225
226 // Two instances of "G SDA SCL V+" on F.SilkS (one per connector)
227 BOOST_CHECK_EQUAL( topPinLabelCount, 2 );
228}
229
230
General utilities for PCB file IO for QA programs.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:221
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:224
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const char * what() const override
std::exception interface, returned as UTF-8
Handle the data for a net.
Definition netinfo.h:46
const wxString & GetNetname() const
Definition netinfo.h:100
Works with Eagle 6.x XML board files and footprints to implement the Pcbnew #PLUGIN API or a portion ...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
@ DEGREES_T
Definition eda_angle.h:31
@ F_SilkS
Definition layer_ids.h:96
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(ViaNetAssignment)
Verify that vias imported from an Eagle board are assigned to the correct nets.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_TOP
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85