42#include <wx/filename.h>
43#include <wx/stdpaths.h>
52 BOOST_CHECK_NE( pi.get(),
nullptr );
63 fn.AppendDir(
"eagle" );
64 fn.SetFullName( sch_file );
79 const wxString& aProjectStem,
80 std::unique_ptr<SCHEMATIC>& aSchematic )
87 wxString sep = wxFileName::GetPathSeparator();
88 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
91 if( wxDirExists( projectDir ) )
92 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
94 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
96 wxString projectPath = projectDir + sep + aProjectStem + wxT(
".kicad_pro" );
102 aSchematic = std::make_unique<SCHEMATIC>( &
project );
112 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
114 catch(
const std::exception& e )
116 BOOST_FAIL( std::string(
"LoadSchematicFile threw: " ) + e.what() );
120 BOOST_FAIL(
"LoadSchematicFile threw unknown exception" );
141 std::unique_ptr<SCHEMATIC> schematic;
147 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
155 BOOST_CHECK( sheet !=
nullptr );
156 BOOST_CHECK( sheet->m_Uuid !=
niluuid );
161 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
167 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
170 std::set<KIID_PATH> hierPaths;
173 hierPaths.insert(
path.Path() );
175 int totalSymbols = 0;
176 int orphanedSymbols = 0;
190 bool foundMatch =
false;
194 if( hierPaths.count( inst.m_Path ) )
206 BOOST_CHECK_GT( totalSymbols, 0 );
229 std::unique_ptr<SCHEMATIC> schematic;
235 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
237 std::unordered_set<wxString> globalTexts;
238 std::unordered_set<wxString> localTexts;
248 globalTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
251 localTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
257 const std::vector<wxString> expectedGlobalNets = {
258 wxS(
"A1" ), wxS(
"A2" ), wxS(
"A3" ),
259 wxS(
"B1" ), wxS(
"B2" ), wxS(
"B3" )
262 for(
const wxString& netName : expectedGlobalNets )
264 BOOST_CHECK_MESSAGE( globalTexts.count( netName ) > 0,
265 "Missing global Eagle net label '" << netName.ToStdString()
266 <<
"' — flat namespace requires SCH_GLOBALLABEL." );
267 BOOST_CHECK_MESSAGE( localTexts.count( netName ) == 0,
268 "Found local SCH_LABEL '" << netName.ToStdString()
269 <<
"' — Eagle net should be global." );
274 const std::vector<wxString> expectedLocalBuses = {
275 wxS(
"A[1..3]" ), wxS(
"B[1..3]" )
278 for(
const wxString& busName : expectedLocalBuses )
280 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
281 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
282 <<
"' — Eagle bus should remain a local SCH_LABEL." );
302 std::unique_ptr<SCHEMATIC> schematic;
305 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
311 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
329 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV" ) ) == 1 );
330 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV_NC" ) ) == 1 );
332 auto collectNames = [](
const SCH_SYMBOL* aSym )
334 std::multiset<wxString> names;
336 for(
const SCH_PIN*
pin : aSym->GetAllLibPins() )
337 names.insert(
pin->GetName() );
343 for(
const auto& [libItem, sym] : symbolByLibItem )
345 for(
const SCH_PIN*
pin : sym->GetAllLibPins() )
347 BOOST_CHECK_MESSAGE(
pin->GetName().Find(
'@' ) == wxNOT_FOUND,
348 libItem.ToStdString() <<
" pin kept Eagle tag '"
349 <<
pin->GetName().ToStdString() <<
"'." );
355 std::map<wxString, wxString> nameByPad;
357 for(
const SCH_PIN*
pin : symbolByLibItem[wxS(
"MYDEV" )]->GetAllLibPins() )
358 nameByPad[
pin->GetNumber()] =
pin->GetName();
366 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS(
"MYDEV_NC" )] );
389 std::unique_ptr<SCHEMATIC> schematic;
395 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
397 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
404 if(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() == wxS(
"DETACHEDLABEL" ) )
407 screen = sheetScreen;
412 BOOST_REQUIRE_MESSAGE( detached,
"DETACHEDLABEL global label not imported" );
418 double wireDist = std::numeric_limits<double>::max();
428 double d = seg.
Distance( labelPos );
438 BOOST_CHECK_MESSAGE( wireDist <=
schIUScale.MilsToIU( 1 ),
439 "Label is " << ( wireDist /
schIUScale.IU_PER_MM )
440 <<
" mm from its wire" );
448 BOOST_CHECK_MESSAGE(
std::abs( offsetMM - 10.0 ) < 1.0,
449 "Label projected to " << offsetMM
450 <<
" mm from the wire's left end, expected 10 mm" );
461 std::unique_ptr<SCHEMATIC> schematic;
468 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
494 BOOST_REQUIRE_MESSAGE( netLabel,
"placed net label was not imported" );
499 BOOST_REQUIRE_MESSAGE( c4,
"CPOL-EU symbol C4 (variant ordinal 131) was not imported" );
513 std::unique_ptr<SCHEMATIC> schematic;
516 std::map<wxString, LIB_SYMBOL*> libSymbolByRef;
518 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
534 BOOST_REQUIRE_GT( libSymbolByRef.size(), 0 );
538 for(
const auto& [ref, libSymbol] : libSymbolByRef )
540 const wxString libRef = libSymbol->GetReferenceField().GetText();
541 const wxString libValue = libSymbol->GetValueField().GetText();
543 BOOST_CHECK_MESSAGE( !libRef.Contains( wxS(
"${" ) ),
544 ref.ToStdString() <<
" library reference prefix is '"
545 << libRef.ToStdString() <<
"'" );
546 BOOST_CHECK_MESSAGE( !libValue.Contains( wxS(
"${" ) ),
547 ref.ToStdString() <<
" library value is '"
548 << libValue.ToStdString() <<
"'" );
551 if( libRef.IsEmpty() )
555 wxString expectedPrefix = ref;
557 while( !expectedPrefix.IsEmpty() && wxIsdigit( expectedPrefix.Last() ) )
558 expectedPrefix.RemoveLast();
560 BOOST_CHECK_MESSAGE( libRef == expectedPrefix,
561 ref.ToStdString() <<
" library reference prefix is '"
562 << libRef.ToStdString() <<
"', expected '"
563 << expectedPrefix.ToStdString() <<
"'" );
569 BOOST_CHECK_GT( prefixCount, 30 );
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.
@ REFERENCE
Field Reference of part, i.e. "IC21".
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_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.