41#include <wx/filename.h>
42#include <wx/stdpaths.h>
51 BOOST_CHECK_NE( pi.get(),
nullptr );
62 fn.AppendDir(
"eagle" );
63 fn.SetFullName( sch_file );
78 const wxString& aProjectStem,
79 std::unique_ptr<SCHEMATIC>& aSchematic )
86 wxString sep = wxFileName::GetPathSeparator();
87 wxString projectDir = wxStandardPaths::Get().GetTempDir() + sep + aProjectStem
90 if( wxDirExists( projectDir ) )
91 wxFileName::Rmdir( projectDir, wxPATH_RMDIR_RECURSIVE );
93 wxFileName::Mkdir( projectDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
95 wxString projectPath = projectDir + sep + aProjectStem + wxT(
".kicad_pro" );
101 aSchematic = std::make_unique<SCHEMATIC>( &
project );
111 loadedSheet = pi->LoadSchematicFile( aEagleFn.GetFullPath(), aSchematic.get() );
113 catch(
const std::exception& e )
115 BOOST_FAIL( std::string(
"LoadSchematicFile threw: " ) + e.what() );
119 BOOST_FAIL(
"LoadSchematicFile threw unknown exception" );
140 std::unique_ptr<SCHEMATIC> schematic;
146 const std::vector<SCH_SHEET*>& topSheets = schematic->GetTopLevelSheets();
154 BOOST_CHECK( sheet !=
nullptr );
155 BOOST_CHECK( sheet->m_Uuid !=
niluuid );
160 BOOST_CHECK( !sheet->GetScreen()->GetFileName().IsEmpty() );
166 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
169 std::set<KIID_PATH> hierPaths;
172 hierPaths.insert(
path.Path() );
174 int totalSymbols = 0;
175 int orphanedSymbols = 0;
189 bool foundMatch =
false;
193 if( hierPaths.count( inst.m_Path ) )
205 BOOST_CHECK_GT( totalSymbols, 0 );
228 std::unique_ptr<SCHEMATIC> schematic;
234 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
236 std::unordered_set<wxString> globalTexts;
237 std::unordered_set<wxString> localTexts;
247 globalTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
250 localTexts.insert(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() );
256 const std::vector<wxString> expectedGlobalNets = {
257 wxS(
"A1" ), wxS(
"A2" ), wxS(
"A3" ),
258 wxS(
"B1" ), wxS(
"B2" ), wxS(
"B3" )
261 for(
const wxString& netName : expectedGlobalNets )
263 BOOST_CHECK_MESSAGE( globalTexts.count( netName ) > 0,
264 "Missing global Eagle net label '" << netName.ToStdString()
265 <<
"' — flat namespace requires SCH_GLOBALLABEL." );
266 BOOST_CHECK_MESSAGE( localTexts.count( netName ) == 0,
267 "Found local SCH_LABEL '" << netName.ToStdString()
268 <<
"' — Eagle net should be global." );
273 const std::vector<wxString> expectedLocalBuses = {
274 wxS(
"A[1..3]" ), wxS(
"B[1..3]" )
277 for(
const wxString& busName : expectedLocalBuses )
279 BOOST_CHECK_MESSAGE( globalTexts.count( busName ) == 0,
280 "Found global SCH_GLOBALLABEL '" << busName.ToStdString()
281 <<
"' — Eagle bus should remain a local SCH_LABEL." );
301 std::unique_ptr<SCHEMATIC> schematic;
304 SCH_SHEET_LIST hierarchy = schematic->BuildSheetListSortedByPageNumbers();
310 std::map<wxString, const SCH_SYMBOL*> symbolByLibItem;
328 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV" ) ) == 1 );
329 BOOST_REQUIRE( symbolByLibItem.count( wxS(
"MYDEV_NC" ) ) == 1 );
331 auto collectNames = [](
const SCH_SYMBOL* aSym )
333 std::multiset<wxString> names;
335 for(
const SCH_PIN*
pin : aSym->GetAllLibPins() )
336 names.insert(
pin->GetName() );
342 for(
const auto& [libItem, sym] : symbolByLibItem )
344 for(
const SCH_PIN*
pin : sym->GetAllLibPins() )
346 BOOST_CHECK_MESSAGE(
pin->GetName().Find(
'@' ) == wxNOT_FOUND,
347 libItem.ToStdString() <<
" pin kept Eagle tag '"
348 <<
pin->GetName().ToStdString() <<
"'." );
354 std::map<wxString, wxString> nameByPad;
356 for(
const SCH_PIN*
pin : symbolByLibItem[wxS(
"MYDEV" )]->GetAllLibPins() )
357 nameByPad[
pin->GetNumber()] =
pin->GetName();
365 std::multiset<wxString> ncNames = collectNames( symbolByLibItem[wxS(
"MYDEV_NC" )] );
388 std::unique_ptr<SCHEMATIC> schematic;
394 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
396 SCH_SCREEN* sheetScreen = sheetPath.LastScreen();
403 if(
static_cast<SCH_LABEL_BASE*
>( item )->GetText() == wxS(
"DETACHEDLABEL" ) )
406 screen = sheetScreen;
411 BOOST_REQUIRE_MESSAGE( detached,
"DETACHEDLABEL global label not imported" );
417 double wireDist = std::numeric_limits<double>::max();
427 double d = seg.
Distance( labelPos );
437 BOOST_CHECK_MESSAGE( wireDist <=
schIUScale.MilsToIU( 1 ),
438 "Label is " << ( wireDist /
schIUScale.IU_PER_MM )
439 <<
" mm from its wire" );
447 BOOST_CHECK_MESSAGE(
std::abs( offsetMM - 10.0 ) < 1.0,
448 "Label projected to " << offsetMM
449 <<
" mm from the wire's left end, expected 10 mm" );
460 std::unique_ptr<SCHEMATIC> schematic;
467 for(
const SCH_SHEET_PATH& sheetPath : schematic->BuildSheetListSortedByPageNumbers() )
493 BOOST_REQUIRE_MESSAGE( netLabel,
"placed net label was not imported" );
498 BOOST_REQUIRE_MESSAGE( c4,
"CPOL-EU symbol C4 (variant ordinal 131) was not imported" );
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.