44#include <wx/filename.h>
45#include <wx/stdpaths.h>
55 BOOST_CHECK_NE( pi.get(),
nullptr );
66 fn.AppendDir(
"eagle" );
67 fn.SetFullName( sch_file );
82 const wxString& aProjectStem,
83 std::unique_ptr<SCHEMATIC>& aSchematic )
90 wxString sep = wxFileName::GetPathSeparator();
91 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
94 if( wxDirExists( projectDir ) )
95 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
97 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
99 wxString projectPath = projectDir + sep + aProjectStem + wxT(
".kicad_pro" );
105 aSchematic = std::make_unique<SCHEMATIC>( &
project );
115 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
117 catch(
const std::exception& e )
119 BOOST_FAIL( std::string(
"LoadSchematicFile threw: " ) + e.what() );
123 BOOST_FAIL(
"LoadSchematicFile threw unknown exception" );
144 std::unique_ptr<SCHEMATIC> schematic;
150 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
164 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
170 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
173 std::set<KIID_PATH> hierPaths;
176 hierPaths.insert(
path.Path() );
178 int totalSymbols = 0;
179 int orphanedSymbols = 0;
193 bool foundMatch =
false;
197 if( hierPaths.count( inst.m_Path ) )
209 BOOST_CHECK_GT( totalSymbols, 0 );
232 std::unique_ptr<SCHEMATIC> schematic;
238 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
240 std::unordered_set<wxString> globalTexts;
241 std::unordered_set<wxString> localTexts;
251 globalTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
254 localTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
260 const std::vector<wxString> expectedGlobalNets = {
261 wxS(
"A1" ), wxS(
"A2" ), wxS(
"A3" ),
262 wxS(
"B1" ), wxS(
"B2" ), wxS(
"B3" )
265 for(
const wxString& netName : expectedGlobalNets )
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." );
277 const std::vector<wxString> expectedLocalBuses = {
278 wxS(
"A[1..3]" ), wxS(
"B[1..3]" )
281 for(
const wxString& busName : expectedLocalBuses )
283 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
284 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
285 <<
"' — Eagle bus should remain a local SCH_LABEL." );
305 std::unique_ptr<SCHEMATIC> schematic;
308 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
314 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
332 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV" ) ) == 1 );
333 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV_NC" ) ) == 1 );
335 auto collectNames = [](
const SCH_SYMBOL* aSym )
337 std::multiset<wxString> names;
339 for(
const SCH_PIN*
pin : aSym->GetAllLibPins() )
340 names.insert(
pin->GetName() );
346 for(
const auto& [libItem, sym] : symbolByLibItem )
348 for(
const SCH_PIN*
pin : sym->GetAllLibPins() )
350 BOOST_CHECK_MESSAGE(
pin->GetName().Find(
'@' ) == wxNOT_FOUND,
351 libItem.ToStdString() <<
" pin kept Eagle tag '"
352 <<
pin->GetName().ToStdString() <<
"'." );
358 std::map<wxString, wxString> nameByPad;
360 for(
const SCH_PIN*
pin : symbolByLibItem[wxS(
"MYDEV" )]->GetAllLibPins() )
361 nameByPad[
pin->GetNumber()] =
pin->GetName();
369 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS(
"MYDEV_NC" )] );
392 std::unique_ptr<SCHEMATIC> schematic;
398 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
400 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
407 if(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() == wxS(
"DETACHEDLABEL" ) )
410 screen = sheetScreen;
421 double wireDist = std::numeric_limits<double>::max();
431 double d = seg.
Distance( labelPos );
441 BOOST_CHECK_MESSAGE( wireDist <=
schIUScale.MilsToIU( 1 ),
442 "Label is " << ( wireDist /
schIUScale.IU_PER_MM )
443 <<
" mm from its wire" );
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" );
464 std::unique_ptr<SCHEMATIC> schematic;
471 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
485 if( label->
GetText() == wxS(
"VSS" ) )
516 std::unique_ptr<SCHEMATIC> schematic;
519 std::map<wxString, int> autoLabelCounts;
521 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
532 if(
text.StartsWith( wxS(
"N$" ) ) )
533 autoLabelCounts[
text]++;
537 for(
const auto& [
text, count] : autoLabelCounts )
538 BOOST_CHECK_MESSAGE( count > 1,
text <<
" labels a lone wired segment" );
551 std::unique_ptr<SCHEMATIC> schematic;
554 std::map<wxString, LIB_SYMBOL*> libSymbolByRef;
556 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
572 BOOST_REQUIRE_GT( libSymbolByRef.size(), 0 );
576 for(
const auto& [ref, libSymbol] : libSymbolByRef )
578 const wxString libRef = libSymbol->GetReferenceField().GetText();
579 const wxString libValue = libSymbol->GetValueField().GetText();
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() <<
"'" );
589 if( libRef.IsEmpty() )
593 wxString expectedPrefix = ref;
595 while( !expectedPrefix.IsEmpty() && wxIsdigit( expectedPrefix.Last() ) )
596 expectedPrefix.RemoveLast();
598 BOOST_CHECK_MESSAGE( libRef == expectedPrefix,
599 ref.ToStdString() <<
" library reference prefix is '"
600 << libRef.ToStdString() <<
"', expected '"
601 << expectedPrefix.ToStdString() <<
"'" );
607 BOOST_CHECK_GT( prefixCount, 30 );
616 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
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" ) );
625 if( !eagleFn.FileExists() )
631 std::unique_ptr<SCHEMATIC> schematic;
636 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
656 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
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" ) );
666 if( !eagleFn.FileExists() )
672 std::unique_ptr<SCHEMATIC> schematic;
677 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
690 BOOST_CHECK_GT( symbols, 0 );
698 if( !wxGetEnv( wxS(
"KICAD_IMPORT_CORPUS" ), &corpus ) )
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" ) );
708 if( !eagleFn.FileExists() )
714 std::unique_ptr<SCHEMATIC> schematic;
719 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
745 if( symbol->
GetRef( &sheetPath ) != aRef )
750 if(
pin->GetNumber() == aPinNumber &&
pin->Connection( &sheetPath ) )
751 return pin->Connection( &sheetPath )->Name();
756 BOOST_ERROR(
"pin has no connection" );
768 std::unique_ptr<SCHEMATIC> schematic;
772 schematic->FixupJunctionsAfterImport();
774 const SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
775 schematic->ConnectionGraph()->Recalculate( sheets,
true );
777 auto netOf = [&](
const wxString& aRef,
const wxString& aPinNumber )
779 return eagleNetOf( sheets, aRef, aPinNumber );
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" ) ) );
794 std::unique_ptr<SCHEMATIC> schematic;
797 schematic->FixupJunctionsAfterImport();
799 const SCH_SHEET_LIST sheets = schematic->BuildSheetListSortedByPageNumbers();
800 schematic->ConnectionGraph()->Recalculate( sheets,
true );
805 BOOST_CHECK_NE(
eagleNetOf( sheets, wxS(
"R1" ), wxS(
"2" ) ),
eagleNetOf( sheets, wxS(
"R3" ), wxS(
"1" ) ) );
809 BOOST_CHECK_NE(
eagleNetOf( sheets, wxS(
"R5" ), wxS(
"1" ) ),
eagleNetOf( sheets, wxS(
"R7" ), wxS(
"1" ) ) );
constexpr EDA_IU_SCALE schIUScale
A base class for most all the KiCad significant classes used in schematics and boards.
virtual VECTOR2I GetTextSize() const
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
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
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
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
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
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.
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_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)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.