42#include <wx/filename.h>
43#include <wx/stdpaths.h>
53 BOOST_CHECK_NE( pi.get(),
nullptr );
64 fn.AppendDir(
"eagle" );
65 fn.SetFullName( sch_file );
80 const wxString& aProjectStem,
81 std::unique_ptr<SCHEMATIC>& aSchematic )
88 wxString sep = wxFileName::GetPathSeparator();
89 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
92 if( wxDirExists( projectDir ) )
93 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
95 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
97 wxString projectPath = projectDir + sep + aProjectStem + wxT(
".kicad_pro" );
103 aSchematic = std::make_unique<SCHEMATIC>( &
project );
113 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
115 catch(
const std::exception& e )
117 BOOST_FAIL( std::string(
"LoadSchematicFile threw: " ) + e.what() );
121 BOOST_FAIL(
"LoadSchematicFile threw unknown exception" );
142 std::unique_ptr<SCHEMATIC> schematic;
148 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
156 BOOST_CHECK( sheet !=
nullptr );
157 BOOST_CHECK( sheet->m_Uuid !=
niluuid );
162 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
168 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
171 std::set<KIID_PATH> hierPaths;
174 hierPaths.insert(
path.Path() );
176 int totalSymbols = 0;
177 int orphanedSymbols = 0;
191 bool foundMatch =
false;
195 if( hierPaths.count( inst.m_Path ) )
207 BOOST_CHECK_GT( totalSymbols, 0 );
230 std::unique_ptr<SCHEMATIC> schematic;
236 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
238 std::unordered_set<wxString> globalTexts;
239 std::unordered_set<wxString> localTexts;
249 globalTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
252 localTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
258 const std::vector<wxString> expectedGlobalNets = {
259 wxS(
"A1" ), wxS(
"A2" ), wxS(
"A3" ),
260 wxS(
"B1" ), wxS(
"B2" ), wxS(
"B3" )
263 for(
const wxString& netName : expectedGlobalNets )
265 BOOST_CHECK_MESSAGE( globalTexts.count( netName ) > 0,
266 "Missing global Eagle net label '" << netName.ToStdString()
267 <<
"' — flat namespace requires SCH_GLOBALLABEL." );
268 BOOST_CHECK_MESSAGE( localTexts.count( netName ) == 0,
269 "Found local SCH_LABEL '" << netName.ToStdString()
270 <<
"' — Eagle net should be global." );
275 const std::vector<wxString> expectedLocalBuses = {
276 wxS(
"A[1..3]" ), wxS(
"B[1..3]" )
279 for(
const wxString& busName : expectedLocalBuses )
281 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
282 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
283 <<
"' — Eagle bus should remain a local SCH_LABEL." );
303 std::unique_ptr<SCHEMATIC> schematic;
306 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
312 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
330 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV" ) ) == 1 );
331 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV_NC" ) ) == 1 );
333 auto collectNames = [](
const SCH_SYMBOL* aSym )
335 std::multiset<wxString> names;
337 for(
const SCH_PIN*
pin : aSym->GetAllLibPins() )
338 names.insert(
pin->GetName() );
344 for(
const auto& [libItem, sym] : symbolByLibItem )
346 for(
const SCH_PIN*
pin : sym->GetAllLibPins() )
348 BOOST_CHECK_MESSAGE(
pin->GetName().Find(
'@' ) == wxNOT_FOUND,
349 libItem.ToStdString() <<
" pin kept Eagle tag '"
350 <<
pin->GetName().ToStdString() <<
"'." );
356 std::map<wxString, wxString> nameByPad;
358 for(
const SCH_PIN*
pin : symbolByLibItem[wxS(
"MYDEV" )]->GetAllLibPins() )
359 nameByPad[
pin->GetNumber()] =
pin->GetName();
367 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS(
"MYDEV_NC" )] );
390 std::unique_ptr<SCHEMATIC> schematic;
396 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
398 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
405 if(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() == wxS(
"DETACHEDLABEL" ) )
408 screen = sheetScreen;
413 BOOST_REQUIRE_MESSAGE( detached,
"DETACHEDLABEL global label not imported" );
419 double wireDist = std::numeric_limits<double>::max();
429 double d = seg.
Distance( labelPos );
439 BOOST_CHECK_MESSAGE( wireDist <=
schIUScale.MilsToIU( 1 ),
440 "Label is " << ( wireDist /
schIUScale.IU_PER_MM )
441 <<
" mm from its wire" );
449 BOOST_CHECK_MESSAGE(
std::abs( offsetMM - 10.0 ) < 1.0,
450 "Label projected to " << offsetMM
451 <<
" mm from the wire's left end, expected 10 mm" );
462 std::unique_ptr<SCHEMATIC> schematic;
469 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
495 BOOST_REQUIRE_MESSAGE( netLabel,
"placed net label was not imported" );
500 BOOST_REQUIRE_MESSAGE( c4,
"CPOL-EU symbol C4 (variant ordinal 131) was not imported" );
514 std::unique_ptr<SCHEMATIC> schematic;
517 std::map<wxString, LIB_SYMBOL*> libSymbolByRef;
519 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
535 BOOST_REQUIRE_GT( libSymbolByRef.size(), 0 );
539 for(
const auto& [ref, libSymbol] : libSymbolByRef )
541 const wxString libRef = libSymbol->GetReferenceField().GetText();
542 const wxString libValue = libSymbol->GetValueField().GetText();
544 BOOST_CHECK_MESSAGE( !libRef.Contains( wxS(
"${" ) ),
545 ref.ToStdString() <<
" library reference prefix is '"
546 << libRef.ToStdString() <<
"'" );
547 BOOST_CHECK_MESSAGE( !libValue.Contains( wxS(
"${" ) ),
548 ref.ToStdString() <<
" library value is '"
549 << libValue.ToStdString() <<
"'" );
552 if( libRef.IsEmpty() )
556 wxString expectedPrefix = ref;
558 while( !expectedPrefix.IsEmpty() && wxIsdigit( expectedPrefix.Last() ) )
559 expectedPrefix.RemoveLast();
561 BOOST_CHECK_MESSAGE( libRef == expectedPrefix,
562 ref.ToStdString() <<
" library reference prefix is '"
563 << libRef.ToStdString() <<
"', expected '"
564 << expectedPrefix.ToStdString() <<
"'" );
570 BOOST_CHECK_GT( prefixCount, 30 );
579 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
585 const wxFileName eagleFn( corpus + wxS(
"/Other/OLINUXINO/HARDWARE/A20-OLinuXino-MICRO/2. Older hardware "
586 "revisions/Hardware revision L1/T2-OLINUXINO-MICRO_Rev_L1.sch" ) );
588 if( !eagleFn.FileExists() )
594 std::unique_ptr<SCHEMATIC> schematic;
599 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
619 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
625 const wxFileName eagleFn( corpus + wxS(
"/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
626 "revisions/A20-OLinuXino-LIME2 hardware revision G2/"
627 "A20-OLinuXino-Lime2_Rev_G2.sch" ) );
629 if( !eagleFn.FileExists() )
635 std::unique_ptr<SCHEMATIC> schematic;
640 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
653 BOOST_CHECK_GT( symbols, 0 );
661 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
667 const wxFileName eagleFn( corpus + wxS(
"/Other/OLINUXINO/HARDWARE/A20-OLinuXino-LIME2/2. Older hardware "
668 "revisions/A20-OLinuXino-LIME2 hardware revision K2/"
669 "A20-OLinuXino-Lime2_Rev_K2.sch" ) );
671 if( !eagleFn.FileExists() )
677 std::unique_ptr<SCHEMATIC> schematic;
682 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
constexpr EDA_IU_SCALE schIUScale
A base class for most all the KiCad significant classes used in schematics and boards.
virtual const wxString & GetText() const
Return the string associated with the text object.
EE_TYPE OfType(KICAD_T aType) const
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
virtual SETTINGS_MANAGER & GetSettingsManager() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
Container for project specific data.
virtual const wxString & GetText() const override
Return the string associated with the text object.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
bool IsWire() const
Return true if the line is a wire.
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
EE_RTREE & Items()
Get the full RTree, usually for iterating.
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.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
const LIB_ID & GetLibId() const override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
PGM_BASE & Pgm()
The global program "get" accessor.
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_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,...
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.