KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eagle_plugin.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) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Alejandro García Montoro <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
23
24#include <map>
25#include <set>
26
27#include <core/ignore.h>
28#include <kiway.h>
29#include <pgm_base.h>
30#include <lib_symbol.h>
31#include <sch_io/sch_io.h>
32#include <schematic.h>
33#include <sch_sheet.h>
34#include <sch_screen.h>
35#include <sch_symbol.h>
36#include <sch_pin.h>
37#include <sch_label.h>
38#include <sch_line.h>
39#include <sch_sheet_path.h>
40#include <connection_graph.h>
41#include <sch_connection.h>
44#include <wx/filename.h>
45#include <wx/stdpaths.h>
46#include <wx/utils.h>
48
53{
54 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
55 BOOST_CHECK_NE( pi.get(), nullptr );
56}
57
58
62static wxFileName getEagleTestSchematic( const wxString& sch_file )
63{
64 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
65 fn.AppendDir( "io" );
66 fn.AppendDir( "eagle" );
67 fn.SetFullName( sch_file );
68
69 return fn;
70}
71
72
81static SCH_SHEET* loadEagleSchematic( const wxFileName& aEagleFn,
82 const wxString& aProjectStem,
83 std::unique_ptr<SCHEMATIC>& aSchematic )
84{
85 // Stage the project in a private, freshly-emptied directory. The Eagle importer writes a
86 // "<stem>-eagle-import.kicad_sym" library plus a sym-lib-table into the project directory and
87 // keys duplicate-symbol-name disambiguation off the on-disk library, so leftover files from a
88 // previous run in the shared temp directory would make the imported symbol names
89 // non-deterministic.
90 wxString sep = wxFileName::GetPathSeparator();
91 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
92 + wxT( "-eagle-qa" );
93
94 if( wxDirExists( projectDir ) )
95 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
96
97 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
98
99 wxString projectPath = projectDir + sep + aProjectStem + wxT( ".kicad_pro" );
100
101 Pgm().GetSettingsManager().LoadProject( projectPath );
103 Pgm().GetLibraryManager().LoadProjectTables( project.GetProjectDirectory() );
104
105 aSchematic = std::make_unique<SCHEMATIC>( &project );
106 aSchematic->Reset();
107
108 IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ) );
109 BOOST_REQUIRE( pi.get() != nullptr );
110
111 SCH_SHEET* loadedSheet = nullptr;
112
113 try
114 {
115 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
116 }
117 catch( const std::exception& e )
118 {
119 BOOST_FAIL( std::string( "LoadSchematicFile threw: " ) + e.what() );
120 }
121 catch( ... )
122 {
123 BOOST_FAIL( "LoadSchematicFile threw unknown exception" );
124 }
125
126 BOOST_REQUIRE( loadedSheet != nullptr );
127 return loadedSheet;
128}
129
130
139BOOST_AUTO_TEST_CASE( ImportHierarchy )
140{
141 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
142 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
143
144 std::unique_ptr<SCHEMATIC> schematic;
145 SCH_SHEET* loadedSheet = loadEagleSchematic( eagleFn, wxS( "eagle_test" ), schematic );
146
147 // The returned sheet must be the virtual root (niluuid).
148 BOOST_CHECK( loadedSheet->m_Uuid == niluuid );
149
150 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
151
152 // The test file has exactly 2 Eagle pages; there must be no spurious default sheet.
153 BOOST_CHECK_EQUAL( topSheets.size(), 2 );
154
155 for( SCH_SHEET* sheet : topSheets )
156 {
157 // No top-level sheet should be the virtual root.
158 BOOST_CHECK( sheet != nullptr );
159 BOOST_CHECK( sheet->m_Uuid != niluuid );
160
161 // Every page must have a screen with a non-empty filename so SaveProject can
162 // write it to disk.
163 BOOST_REQUIRE( sheet->GetScreen() != nullptr );
164 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
165 }
166
167 // Verify the hierarchy paths match the symbol instance paths so PCB update works.
168 // Each symbol's hierarchical reference must have a path matching one of the top-level
169 // sheet paths in the hierarchy.
170 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
171 BOOST_CHECK_EQUAL( hierarchy.size(), 2 );
172
173 std::set<KIID_PATH> hierPaths;
174
175 for( const SCH_SHEET_PATH& path : hierarchy )
176 hierPaths.insert( path.Path() );
177
178 int totalSymbols = 0;
179 int orphanedSymbols = 0;
180
181 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
182 {
183 SCH_SCREEN* screen = sheetPath.LastScreen();
184
185 if( !screen )
186 continue;
187
188 for( const EDA_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
189 {
190 const SCH_SYMBOL* sym = static_cast<const SCH_SYMBOL*>( item );
191 ++totalSymbols;
192
193 bool foundMatch = false;
194
195 for( const SCH_SYMBOL_INSTANCE& inst : sym->GetInstances() )
196 {
197 if( hierPaths.count( inst.m_Path ) )
198 {
199 foundMatch = true;
200 break;
201 }
202 }
203
204 if( !foundMatch )
205 ++orphanedSymbols;
206 }
207 }
208
209 BOOST_CHECK_GT( totalSymbols, 0 );
210 BOOST_CHECK_EQUAL( orphanedSymbols, 0 );
211}
212
213
227BOOST_AUTO_TEST_CASE( LabelsRemainGlobalForFlatNamespace )
228{
229 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
230 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
231
232 std::unique_ptr<SCHEMATIC> schematic;
233 loadEagleSchematic( eagleFn, wxS( "eagle_label_kind" ), schematic );
234
235 // Bucket every label in the imported schematic by kind + text so we can verify that
236 // each named Eagle net produced a global label and no leftover local SCH_LABEL exists
237 // with that name. Bus labels (e.g. "A[1..3]") must stay local.
238 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
239
240 std::unordered_set<wxString> globalTexts;
241 std::unordered_set<wxString> localTexts;
242
243 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
244 {
245 SCH_SCREEN* screen = sheetPath.LastScreen();
246
247 if( !screen )
248 continue;
249
250 for( SCH_ITEM* item : screen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
251 globalTexts.insert( static_cast<SCH_LABEL_BASE*>( item )->GetText() );
252
253 for( SCH_ITEM* item : screen->Items().OfType( SCH_LABEL_T ) )
254 localTexts.insert( static_cast<SCH_LABEL_BASE*>( item )->GetText() );
255 }
256
257 // Named Eagle nets must produce at least one global label each, and none of these
258 // names may appear as a local SCH_LABEL — that would reintroduce the "/X" sheet-path
259 // prefix that broke board update.
260 const std::vector<wxString> expectedGlobalNets = {
261 wxS( "A1" ), wxS( "A2" ), wxS( "A3" ),
262 wxS( "B1" ), wxS( "B2" ), wxS( "B3" )
263 };
264
265 for( const wxString& netName : expectedGlobalNets )
266 {
267 BOOST_CHECK_MESSAGE( globalTexts.count( netName ) > 0,
268 "Missing global Eagle net label '" << netName.ToStdString()
269 << "' — flat namespace requires SCH_GLOBALLABEL." );
270 BOOST_CHECK_MESSAGE( localTexts.count( netName ) == 0,
271 "Found local SCH_LABEL '" << netName.ToStdString()
272 << "' — Eagle net should be global." );
273 }
274
275 // Bus labels (e.g. "A[1..3]") must stay local: Eagle buses are visual groupings, not
276 // electrical signals, so globalizing them would merge same-named buses project-wide.
277 const std::vector<wxString> expectedLocalBuses = {
278 wxS( "A[1..3]" ), wxS( "B[1..3]" )
279 };
280
281 for( const wxString& busName : expectedLocalBuses )
282 {
283 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
284 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
285 << "' — Eagle bus should remain a local SCH_LABEL." );
286 }
287}
288
289
300BOOST_AUTO_TEST_CASE( PinNameTagStripped )
301{
302 const wxFileName eagleFn = getEagleTestSchematic( "issue24483_pin_tag.sch" );
303 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
304
305 std::unique_ptr<SCHEMATIC> schematic;
306 loadEagleSchematic( eagleFn, wxS( "eagle_pin_tag" ), schematic );
307
308 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
309
310 // Key symbols by their library item name (e.g. "MYDEV"); the annotated reference is
311 // unreliable here because the no-connect device is annotated with a '#' power prefix. A
312 // single Eagle library imports without a library-name prefix on the symbol; the prefix is
313 // only added to disambiguate duplicate names across multiple Eagle libraries.
314 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
315
316 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
317 {
318 SCH_SCREEN* screen = sheetPath.LastScreen();
319
320 if( !screen )
321 continue;
322
323 for( const EDA_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
324 {
325 const SCH_SYMBOL* sym = static_cast<const SCH_SYMBOL*>( item );
326 symbolByLibItem[sym->GetLibId().GetLibItemName().wx_str()] = sym;
327 }
328 }
329
330 // The connected device maps pins to pads through <connect>; the no-connect device has no
331 // <connect> so pins are auto-numbered. Both paths must strip the tag from the display name.
332 BOOST_REQUIRE( symbolByLibItem.count( wxS( "MYDEV" ) ) == 1 );
333 BOOST_REQUIRE( symbolByLibItem.count( wxS( "MYDEV_NC" ) ) == 1 );
334
335 auto collectNames = []( const SCH_SYMBOL* aSym )
336 {
337 std::multiset<wxString> names;
338
339 for( const SCH_PIN* pin : aSym->GetAllLibPins() )
340 names.insert( pin->GetName() );
341
342 return names;
343 };
344
345 // No display name on either symbol may retain the "@<tag>" suffix.
346 for( const auto& [libItem, sym] : symbolByLibItem )
347 {
348 for( const SCH_PIN* pin : sym->GetAllLibPins() )
349 {
350 BOOST_CHECK_MESSAGE( pin->GetName().Find( '@' ) == wxNOT_FOUND,
351 libItem.ToStdString() << " pin kept Eagle tag '"
352 << pin->GetName().ToStdString() << "'." );
353 }
354 }
355
356 // For the connected device, the two "IN@n" pins must both display as "IN" yet keep their
357 // distinct pad mapping, and "NC@3" must strip to "NC".
358 std::map<wxString, wxString> nameByPad;
359
360 for( const SCH_PIN* pin : symbolByLibItem[wxS( "MYDEV" )]->GetAllLibPins() )
361 nameByPad[pin->GetNumber()] = pin->GetName();
362
363 BOOST_CHECK_EQUAL( nameByPad["1"], wxString( wxS( "IN" ) ) );
364 BOOST_CHECK_EQUAL( nameByPad["2"], wxString( wxS( "IN" ) ) );
365 BOOST_CHECK_EQUAL( nameByPad["3"], wxString( wxS( "GND" ) ) );
366 BOOST_CHECK_EQUAL( nameByPad["4"], wxString( wxS( "NC" ) ) );
367
368 // The no-connect device keeps every pin, so both tagged "IN" pins survive the strip.
369 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS( "MYDEV_NC" )] );
370 BOOST_CHECK_EQUAL( ncNames.count( wxS( "IN" ) ), 2 );
371 BOOST_CHECK_EQUAL( ncNames.count( wxS( "GND" ) ), 1 );
372 BOOST_CHECK_EQUAL( ncNames.count( wxS( "NC" ) ), 1 );
373}
374
375
387BOOST_AUTO_TEST_CASE( DetachedLabelProjectsOntoWire )
388{
389 const wxFileName eagleFn = getEagleTestSchematic( "eagle-import-testfile.sch" );
390 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
391
392 std::unique_ptr<SCHEMATIC> schematic;
393 loadEagleSchematic( eagleFn, wxS( "eagle_detached_label" ), schematic );
394
395 SCH_LABEL_BASE* detached = nullptr;
396 SCH_SCREEN* screen = nullptr;
397
398 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
399 {
400 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
401
402 if( !sheetScreen )
403 continue;
404
405 for( SCH_ITEM* item : sheetScreen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
406 {
407 if( static_cast<SCH_LABEL_BASE*>( item )->GetText() == wxS( "DETACHEDLABEL" ) )
408 {
409 detached = static_cast<SCH_LABEL_BASE*>( item );
410 screen = sheetScreen;
411 }
412 }
413 }
414
415 BOOST_REQUIRE_MESSAGE( detached, "DETACHEDLABEL global label not imported" );
416
417 // Positions carry an import-time sheet translation, so all checks are made relative to
418 // the wire's own endpoints.
419 const VECTOR2I labelPos = detached->GetPosition();
420 SEG wire;
421 double wireDist = std::numeric_limits<double>::max();
422
423 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
424 {
425 SCH_LINE* line = static_cast<SCH_LINE*>( item );
426
427 if( !line->IsWire() )
428 continue;
429
430 SEG seg( line->GetStartPoint(), line->GetEndPoint() );
431 double d = seg.Distance( labelPos );
432
433 if( d < wireDist )
434 {
435 wireDist = d;
436 wire = seg;
437 }
438 }
439
440 // The label must be on the wire.
441 BOOST_CHECK_MESSAGE( wireDist <= schIUScale.MilsToIU( 1 ),
442 "Label is " << ( wireDist / schIUScale.IU_PER_MM )
443 << " mm from its wire" );
444
445 // The wire is 40 mm long and the label sat 10 mm from the left end. Perpendicular
446 // projection preserves that; the old endpoint/midpoint snap would put it at 0 mm
447 // (endpoint) or 20 mm (midpoint) from the left end.
448 const VECTOR2I leftEnd = wire.A.x <= wire.B.x ? wire.A : wire.B;
449 const double offsetMM = std::abs( labelPos.x - leftEnd.x ) / (double) schIUScale.IU_PER_MM;
450
451 BOOST_CHECK_MESSAGE( std::abs( offsetMM - 10.0 ) < 1.0,
452 "Label projected to " << offsetMM
453 << " mm from the wire's left end, expected 10 mm" );
454}
455
456
457// issue 24829 dropped net labels under the raw netbuslabel element name
458// and lost symbols whose variant ordinal above 127 sign-extended negative
459BOOST_AUTO_TEST_CASE( BinaryNetLabelAndHighVariantImported )
460{
461 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
462 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
463
464 std::unique_ptr<SCHEMATIC> schematic;
465 loadEagleSchematic( eagleFn, wxS( "eagle_brenner_24829" ), schematic );
466
467 int symbolCount = 0;
468 SCH_SYMBOL* c4 = nullptr;
469 SCH_LABEL_BASE* vssLabel = nullptr;
470
471 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
472 {
473 SCH_SCREEN* screen = sheetPath.LastScreen();
474
475 if( !screen )
476 continue;
477
478 for( SCH_ITEM* item : screen->Items() )
479 {
480 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T
481 || item->Type() == SCH_HIER_LABEL_T )
482 {
483 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
484
485 if( label->GetText() == wxS( "VSS" ) )
486 vssLabel = label;
487 }
488 else if( item->Type() == SCH_SYMBOL_T )
489 {
490 ++symbolCount;
491 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
492
493 if( sym->GetField( FIELD_T::REFERENCE )->GetText() == wxS( "C4" ) )
494 c4 = sym;
495 }
496 }
497 }
498
499 // placed net label on VSS, previously dropped entirely; a dropped one comes back as a generated 40 mil label
500 BOOST_REQUIRE_MESSAGE( vssLabel, "VSS net label was not imported" );
501 BOOST_CHECK_NE( vssLabel->GetTextSize().x, schIUScale.MilsToIU( 40 ) );
502
503 // 36 placed instances, C4 is CPOL-EU with variant ordinal 131
504 BOOST_CHECK_EQUAL( symbolCount, 36 );
505 BOOST_REQUIRE_MESSAGE( c4, "CPOL-EU symbol C4 (variant ordinal 131) was not imported" );
506 BOOST_CHECK( c4->GetLibSymbolRef() != nullptr );
507}
508
509
510// a lone wired segment of an Eagle-generated N$ net needs no label, so every N$ label joins at least two places
511BOOST_AUTO_TEST_CASE( AutoNamedNetsLabelledOnlyWhenJoinedByName )
512{
513 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
514 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
515
516 std::unique_ptr<SCHEMATIC> schematic;
517 loadEagleSchematic( eagleFn, wxS( "eagle_auto_net_labels" ), schematic );
518
519 std::map<wxString, int> autoLabelCounts;
520
521 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
522 {
523 SCH_SCREEN* screen = sheetPath.LastScreen();
524
525 if( !screen )
526 continue;
527
528 for( SCH_ITEM* item : screen->Items().OfType( SCH_GLOBAL_LABEL_T ) )
529 {
530 const wxString& text = static_cast<SCH_LABEL_BASE*>( item )->GetText();
531
532 if( text.StartsWith( wxS( "N$" ) ) )
533 autoLabelCounts[text]++;
534 }
535 }
536
537 for( const auto& [text, count] : autoLabelCounts )
538 BOOST_CHECK_MESSAGE( count > 1, text << " labels a lone wired segment" );
539}
540
541
546BOOST_AUTO_TEST_CASE( LibrarySymbolFieldsKeepTheirText )
547{
548 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
549 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
550
551 std::unique_ptr<SCHEMATIC> schematic;
552 loadEagleSchematic( eagleFn, wxS( "eagle_field_text" ), schematic );
553
554 std::map<wxString, LIB_SYMBOL*> libSymbolByRef;
555
556 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
557 {
558 SCH_SCREEN* screen = sheetPath.LastScreen();
559
560 if( !screen )
561 continue;
562
563 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
564 {
565 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
566
567 if( sym->GetLibSymbolRef() )
568 libSymbolByRef[sym->GetField( FIELD_T::REFERENCE )->GetText()] = sym->GetLibSymbolRef().get();
569 }
570 }
571
572 BOOST_REQUIRE_GT( libSymbolByRef.size(), 0 );
573
574 int prefixCount = 0;
575
576 for( const auto& [ref, libSymbol] : libSymbolByRef )
577 {
578 const wxString libRef = libSymbol->GetReferenceField().GetText();
579 const wxString libValue = libSymbol->GetValueField().GetText();
580
581 BOOST_CHECK_MESSAGE( !libRef.Contains( wxS( "${" ) ),
582 ref.ToStdString() << " library reference prefix is '"
583 << libRef.ToStdString() << "'" );
584 BOOST_CHECK_MESSAGE( !libValue.Contains( wxS( "${" ) ),
585 ref.ToStdString() << " library value is '"
586 << libValue.ToStdString() << "'" );
587
588 // A deviceset can declare no prefix, which correctly leaves the field empty
589 if( libRef.IsEmpty() )
590 continue;
591
592 // Eagle names each part from the deviceset prefix and a number
593 wxString expectedPrefix = ref;
594
595 while( !expectedPrefix.IsEmpty() && wxIsdigit( expectedPrefix.Last() ) )
596 expectedPrefix.RemoveLast();
597
598 BOOST_CHECK_MESSAGE( libRef == expectedPrefix,
599 ref.ToStdString() << " library reference prefix is '"
600 << libRef.ToStdString() << "', expected '"
601 << expectedPrefix.ToStdString() << "'" );
602
603 ++prefixCount;
604 }
605
606 // Keep the prefix check from becoming vacuous if the fields come back empty
607 BOOST_CHECK_GT( prefixCount, 30 );
608}
609
610
611// A binary schematic's free-text blob can pass 32 KiB, and losing it drops every package name
612BOOST_AUTO_TEST_CASE( BinaryLargeFreeTextKeepsPackages )
613{
614 wxString corpus;
615
616 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
617 {
618 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
619 return;
620 }
621
622 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-MICRO/2. Older hardware "
623 "revisions/Hardware revision L1/T2-OLINUXINO-MICRO_Rev_L1.sch" ) );
624
625 if( !eagleFn.FileExists() )
626 {
627 BOOST_TEST_MESSAGE( "T2-OLINUXINO-MICRO_Rev_L1.sch is not in KICAD_IMPORT_CORPUS" );
628 return;
629 }
630
631 std::unique_ptr<SCHEMATIC> schematic;
632 loadEagleSchematic( eagleFn, wxS( "eagle_large_free_text" ), schematic );
633
634 SCH_SYMBOL* c1 = nullptr;
635
636 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
637 {
638 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
639 {
640 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
641
642 if( sym->GetField( FIELD_T::REFERENCE )->GetText() == wxS( "C1" ) )
643 c1 = sym;
644 }
645 }
646
647 BOOST_REQUIRE( c1 );
648 BOOST_CHECK( !c1->GetField( FIELD_T::FOOTPRINT )->GetText().IsEmpty() );
649}
650
651
652BOOST_AUTO_TEST_CASE( BinaryBusNamesKeepLongStringsAligned )
653{
654 wxString corpus;
655
656 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
657 {
658 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
659 return;
660 }
661
662 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
663 "revisions/A20-OLinuXino-LIME2 hardware revision G2/"
664 "A20-OLinuXino-Lime2_Rev_G2.sch" ) );
665
666 if( !eagleFn.FileExists() )
667 {
668 BOOST_TEST_MESSAGE( "A20-OLinuXino-Lime2_Rev_G2.sch is not in KICAD_IMPORT_CORPUS" );
669 return;
670 }
671
672 std::unique_ptr<SCHEMATIC> schematic;
673 loadEagleSchematic( eagleFn, wxS( "eagle_bus_names" ), schematic );
674
675 int symbols = 0;
676
677 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
678 {
679 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
680 {
681 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
682
683 // Missing bus names shift the strings so GND supplies take a capacitor value
684 BOOST_CHECK_MESSAGE( !sym->GetField( FIELD_T::REFERENCE )->GetText().Contains( wxS( "22uF" ) ),
686 symbols++;
687 }
688 }
689
690 BOOST_CHECK_GT( symbols, 0 );
691}
692
693
694BOOST_AUTO_TEST_CASE( BinaryLongStringsFollowRecordOrder )
695{
696 wxString corpus;
697
698 if( !wxGetEnv( wxS( "KICAD_IMPORT_CORPUS" ), &corpus ) )
699 {
700 BOOST_TEST_MESSAGE( "KICAD_IMPORT_CORPUS is not set" );
701 return;
702 }
703
704 const wxFileName eagleFn( corpus + wxS( "/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
705 "revisions/A20-OLinuXino-LIME2 hardware revision K2/"
706 "A20-OLinuXino-Lime2_Rev_K2.sch" ) );
707
708 if( !eagleFn.FileExists() )
709 {
710 BOOST_TEST_MESSAGE( "A20-OLinuXino-Lime2_Rev_K2.sch is not in KICAD_IMPORT_CORPUS" );
711 return;
712 }
713
714 std::unique_ptr<SCHEMATIC> schematic;
715 loadEagleSchematic( eagleFn, wxS( "eagle_long_string_order" ), schematic );
716
717 SCH_SYMBOL* led = nullptr;
718
719 for( const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
720 {
721 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
722 {
723 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
724
725 if( sym->GetField( FIELD_T::VALUE )->GetText() == wxS( "LED/RED/0603" ) )
726 led = sym;
727 }
728 }
729
730 // The blob holds a part's long value before its long name
731 BOOST_REQUIRE( led );
732 BOOST_CHECK( led->GetField( FIELD_T::REFERENCE )->GetText().StartsWith( wxS( "PWR_LED" ) ) );
733}
734
735
736// Name of the net a symbol pin sits on, after the connection graph has been built
737static wxString eagleNetOf( const SCH_SHEET_LIST& aSheets, const wxString& aRef, const wxString& aPinNumber )
738{
739 for( const SCH_SHEET_PATH& sheetPath : aSheets )
740 {
741 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
742 {
743 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
744
745 if( symbol->GetRef( &sheetPath ) != aRef )
746 continue;
747
748 for( SCH_PIN* pin : symbol->GetPins( &sheetPath ) )
749 {
750 if( pin->GetNumber() == aPinNumber && pin->Connection( &sheetPath ) )
751 return pin->Connection( &sheetPath )->Name();
752 }
753 }
754 }
755
756 BOOST_ERROR( "pin has no connection" );
757
758 return wxString();
759}
760
761
762// a wire end of one Eagle net landing mid-wire on another must not merge the two nets in KiCad
763BOOST_AUTO_TEST_CASE( TouchingWireEndsKeepNetsSeparate )
764{
765 const wxFileName eagleFn = getEagleTestSchematic( "issue24829_brenner.sch" );
766 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
767
768 std::unique_ptr<SCHEMATIC> schematic;
769 loadEagleSchematic( eagleFn, wxS( "eagle_touching_nets" ), schematic );
770
771 // The editor joins a wire end lying on another wire the same way when it cleans up after import
772 schematic->FixupJunctionsAfterImport();
773
774 const SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
775 schematic->ConnectionGraph()->Recalculate( sheets, true );
776
777 auto netOf = [&]( const wxString& aRef, const wxString& aPinNumber )
778 {
779 return eagleNetOf( sheets, aRef, aPinNumber );
780 };
781
782 BOOST_CHECK_EQUAL( netOf( wxS( "R13" ), wxS( "1" ) ), wxString( wxS( "VPP_8_14_18" ) ) );
783 BOOST_CHECK_EQUAL( netOf( wxS( "IC1" ), wxS( "7" ) ), wxString( wxS( "VPP_8_14_18" ) ) );
784 BOOST_CHECK_EQUAL( netOf( wxS( "Q5" ), wxS( "E" ) ), wxString( wxS( "VDD" ) ) );
785}
786
787
788// a pin lying on a wire of another Eagle net must not join the two nets in KiCad
789BOOST_AUTO_TEST_CASE( WireOverForeignPinKeepsNetsSeparate )
790{
791 const wxFileName eagleFn = getEagleTestSchematic( "issue26039_wire_over_pin.sch" );
792 BOOST_REQUIRE( wxFileExists( eagleFn.GetFullPath() ) );
793
794 std::unique_ptr<SCHEMATIC> schematic;
795 loadEagleSchematic( eagleFn, wxS( "eagle_wire_over_pin" ), schematic );
796
797 schematic->FixupJunctionsAfterImport();
798
799 const SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
800 schematic->ConnectionGraph()->Recalculate( sheets, true );
801
802 // R1.2 ends one wire on the wire running R3 to R4, R5.1 ends one on the wire running R7 to R8
803 BOOST_CHECK_EQUAL( eagleNetOf( sheets, wxS( "R1" ), wxS( "2" ) ), eagleNetOf( sheets, wxS( "R2" ), wxS( "1" ) ) );
804 BOOST_CHECK_EQUAL( eagleNetOf( sheets, wxS( "R3" ), wxS( "1" ) ), eagleNetOf( sheets, wxS( "R4" ), wxS( "2" ) ) );
805 BOOST_CHECK_NE( eagleNetOf( sheets, wxS( "R1" ), wxS( "2" ) ), eagleNetOf( sheets, wxS( "R3" ), wxS( "1" ) ) );
806
807 BOOST_CHECK_EQUAL( eagleNetOf( sheets, wxS( "R5" ), wxS( "1" ) ), eagleNetOf( sheets, wxS( "R6" ), wxS( "2" ) ) );
808 BOOST_CHECK_EQUAL( eagleNetOf( sheets, wxS( "R7" ), wxS( "1" ) ), eagleNetOf( sheets, wxS( "R8" ), wxS( "2" ) ) );
809 BOOST_CHECK_NE( eagleNetOf( sheets, wxS( "R5" ), wxS( "1" ) ), eagleNetOf( sheets, wxS( "R7" ), wxS( "1" ) ) );
810}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
const KIID m_Uuid
Definition eda_item.h:599
virtual VECTOR2I GetTextSize() const
Definition eda_text.h:301
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
void LoadProjectTables(std::initializer_list< LIBRARY_TABLE_TYPE > aTablesToLoad={})
(Re)loads the project library tables in the given list, or all tables if no list is given
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition pgm_base.h:124
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
Container for project specific data.
Definition project.h:63
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
Definition sch_line.h:145
VECTOR2I GetStartPoint() const
Definition sch_line.h:136
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
Schematic symbol object.
Definition sch_symbol.h:76
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:136
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:166
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
Definition sch_text.h:143
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition seg.cpp:668
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
wxString wx_str() const
Definition utf8.cpp:41
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
KIID niluuid(0)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
A simple container for schematic symbol instance information.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_CASE(FindPlugin)
Checks that the SCH_IO manager finds the Eagle plugin.
static wxFileName getEagleTestSchematic(const wxString &sch_file)
Get a schematic file from the test data eagle subdir.
static SCH_SHEET * loadEagleSchematic(const wxFileName &aEagleFn, const wxString &aProjectStem, std::unique_ptr< SCHEMATIC > &aSchematic)
Common Eagle-import scaffolding: stage a fresh project under tempDir, configure the library manager,...
static wxString eagleNetOf(const SCH_SHEET_LIST &aSheets, const wxString &aRef, const wxString &aPinNumber)
std::string path
KIBIS_PIN * pin
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
Definition of file extensions used in Kicad.