20#include <boost/test/unit_test.hpp>
48struct ALTIUM_SCH_IMPORT_FIXTURE
50 ALTIUM_SCH_IMPORT_FIXTURE() :
51 m_loadInfoScope( &NULL_REPORTER::GetInstance() ),
52 m_schematic( nullptr )
54 m_settingsManager.LoadProject(
"" );
55 m_schematic.SetProject( &m_settingsManager.Prj() );
59 ~ALTIUM_SCH_IMPORT_FIXTURE() { m_schematic.Reset(); }
61 wxString dataFile(
const wxString& aName )
const
64 +
"/plugins/altium/issue22943/" )
68 wxString issue24861DataFile(
const wxString& aName )
const
71 +
"/plugins/altium/issue24861/" )
75 wxString issue22908DataFile(
const wxString& aName )
const
78 +
"/plugins/altium/issue22908/" )
82 wxString ticket1303DataFile(
const wxString& aName )
const
85 +
"/plugins/altium/ticket1303/" )
89 wxString issue16903DataFile(
const wxString& aName )
const
92 +
"/plugins/altium/issue16903/" )
96 wxString eDPAdapterDataFile(
const wxString& aName )
const
99 +
"pcbnew/plugins/altium/eDP_adapter_dvt1_source/" )
104 LOAD_INFO_REPORTER_SCOPE m_loadInfoScope;
105 SETTINGS_MANAGER m_settingsManager;
112BOOST_FIXTURE_TEST_SUITE( AltiumSchImport, ALTIUM_SCH_IMPORT_FIXTURE )
128 wxArrayString libNames;
131 std::set<wxString> libSymbolNames( libNames.begin(), libNames.end() );
134 std::vector<SCH_SYMBOL*> fromMountingHoles;
141 fromMountingHoles.push_back( sym );
149 const LIB_ID& libId = sym->GetLibId();
150 BOOST_CHECK( libId.
IsValid() );
153 <<
"' does not resolve in mounting_holes.SchLib" );
163 const wxString projectFile =
directory.PathStr() +
"/2_cubesat_bus.kicad_pro";
176 std::set<wxString> files;
179 files.insert(
static_cast<SCH_SHEET*
>( item )->GetFileName() );
188 const std::set<wxString> hostFiles = sheetFiles( root );
189 BOOST_CHECK( hostFiles.contains( wxS(
"2_cubesat_bus_1.kicad_sch" ) ) );
191 std::map<std::string, UTF8> properties{ {
"hierarchical_sheet_load",
"1" } };
192 auto appended = std::make_unique<SCH_SHEET>( &schematic );
193 appended->SetFileName( dataFile(
"1_cover.SchDoc" ) );
199 for(
const wxString& file : sheetFiles( appended.get() ) )
200 BOOST_CHECK_MESSAGE( !hostFiles.contains( file ), file <<
" is already saved by the host" );
209 std::map<std::string, UTF8> properties;
210 properties.emplace(
"project_file",
UTF8( issue24861DataFile( wxT(
"Repeated_Schematic.PrjPcb" ) ) ) );
211 properties.emplace(
"sch0",
UTF8( issue24861DataFile( wxT(
"Repeated_Schematic.SchDoc" ) ) ) );
212 properties.emplace(
"sch1",
UTF8( issue24861DataFile( wxT(
"Channel.SchDoc" ) ) ) );
217 const std::vector<SCH_SHEET*> topLevelSheets = m_schematic.GetTopLevelSheets();
218 BOOST_REQUIRE_EQUAL( topLevelSheets.size(), 1 );
219 BOOST_CHECK_EQUAL( topLevelSheets.front()->GetName(), wxT(
"Repeated_Schematic" ) );
221 std::optional<SCH_SHEET_PATH> topLevelPath;
222 std::map<wxString, SCH_SHEET_PATH> channelPaths;
228 if( sheet && sheet->
GetName() == wxT(
"Repeated_Schematic" ) )
229 topLevelPath = sheetPath;
230 else if( sheet && sheet->
GetName().StartsWith( wxT(
"CH" ) ) )
231 channelPaths.emplace( sheet->
GetName(), sheetPath );
237 BOOST_REQUIRE_EQUAL( channelPaths.size(), 3 );
238 BOOST_CHECK_EQUAL( channelPaths.at( wxT(
"CH1" ) ).GetPageNumber(), wxT(
"2" ) );
239 BOOST_CHECK_EQUAL( channelPaths.at( wxT(
"CH2" ) ).GetPageNumber(), wxT(
"3" ) );
240 BOOST_CHECK_EQUAL( channelPaths.at( wxT(
"CH3" ) ).GetPageNumber(), wxT(
"4" ) );
242 std::set<wxString> ledReferences;
243 std::set<wxString> resistorReferences;
245 for(
const auto& [channelName, sheetPath] : channelPaths )
250 wxString ref = symbol->
GetRef( &sheetPath );
252 if( ref.StartsWith( wxT(
"LED" ) ) )
253 ledReferences.insert( ref );
254 else if( ref.StartsWith( wxT(
"R" ) ) )
255 resistorReferences.insert( ref );
259 BOOST_CHECK( ledReferences == std::set<wxString>( { wxT(
"LED1_CH1" ), wxT(
"LED1_CH2" ),
260 wxT(
"LED1_CH3" ) } ) );
261 BOOST_CHECK( resistorReferences == std::set<wxString>( { wxT(
"R1_CH1" ), wxT(
"R1_CH2" ),
262 wxT(
"R1_CH3" ) } ) );
272 std::map<std::string, UTF8> properties;
273 properties.emplace(
"project_file",
UTF8( issue24861DataFile( wxT(
"Repeated_Schematic.PrjPcb" ) ) ) );
274 properties.emplace(
"sch0",
UTF8( issue24861DataFile( wxT(
"Repeated_Schematic.SchDoc" ) ) ) );
275 properties.emplace(
"sch1",
UTF8( issue24861DataFile( wxT(
"Channel.SchDoc" ) ) ) );
279 const std::vector<SCH_SHEET*> topLevelSheets = m_schematic.GetTopLevelSheets();
280 BOOST_REQUIRE_EQUAL( topLevelSheets.size(), 1 );
281 BOOST_CHECK( topLevelSheets.front()->m_Uuid == topLevelSheets.front()->GetScreen()->GetUuid() );
283 std::set<SCH_SCREEN*> channelScreens;
287 if( sheetPath.Last()->GetName().StartsWith( wxT(
"CH" ) ) )
288 channelScreens.insert( sheetPath.LastScreen() );
308 static const std::vector<VECTOR2I> crosses = {
309 { 360, 500 }, { 360, 540 }, { 360, 610 }, { 360, 600 }, { 360, 620 }, { 360, 530 }, { 360, 460 },
310 { 360, 450 }, { 170, 550 }, { 170, 540 }, { 170, 520 }, { 170, 510 }, { 170, 610 }, { 170, 590 },
311 { 170, 580 }, { 880, 500 }, { 880, 540 }, { 880, 610 }, { 880, 600 }, { 880, 620 }, { 880, 530 },
312 { 880, 460 }, { 880, 450 }, { 690, 550 }, { 690, 540 }, { 690, 520 }, { 690, 510 }, { 690, 610 },
313 { 690, 590 }, { 690, 580 }, { 480, 650 }, { 1000, 650 }, { 290, 340 }, { 810, 340 }
316 const int gridPitch = m_schematic.Settings().m_ConnectionGridSize;
318 const int flipY = ( pageHeight / gridPitch ) * gridPitch;
320 std::set<std::pair<int, int>>
expected;
322 for(
const VECTOR2I& cross : crosses )
325 std::set<std::pair<int, int>>
actual;
327 size_t actualCount = 0;
332 actual.emplace( item->GetPosition().x, item->GetPosition().y );
350 &m_schematic,
nullptr,
nullptr );
362 bool foundMergedScreen =
false;
368 if( !screen || screen == rootSheet->
GetScreen() )
371 std::optional<VECTOR2I> posA;
372 std::optional<VECTOR2I> posB;
378 if( label->
GetText() == wxT(
"ONLY_A" ) )
380 else if( label->
GetText() == wxT(
"ONLY_B" ) )
387 foundMergedScreen =
true;
391 int subSheetCount = 0;
403 BOOST_CHECK_MESSAGE( *posA != *posB,
"Merged pages must be tiled, not overlapping" );
407 bool foundSigLabel =
false;
411 if(
static_cast<SCH_HIERLABEL*
>( item )->GetText() == wxT(
"SIG" ) )
412 foundSigLabel =
true;
415 BOOST_CHECK_MESSAGE( foundSigLabel,
416 "Pruned sheet pin must survive as a hierarchical label" );
419 BOOST_CHECK_MESSAGE( foundMergedScreen,
420 "Both pages of the multi-file sheet symbol must load into one screen" );
441 m_schematic.RefreshHierarchy();
444 const std::map<wxString, SYMBOL_ORIENTATION_PROP>
expected = {
451 std::map<wxString, SYMBOL_ORIENTATION_PROP>
actual;
458 wxString ref = symbol->
GetRef( &sheetPath );
465 for(
const auto& [ref, angle] :
expected )
467 BOOST_REQUIRE_MESSAGE(
actual.count( ref ),
"Symbol '" << ref <<
"' not found on import" );
468 BOOST_CHECK_MESSAGE(
actual.at( ref ) == angle,
469 "Symbol '" << ref <<
"' imported with orientation " <<
actual.at( ref )
470 <<
", expected " << angle );
483 plugin.
LoadSchematicFile( issue16903DataFile( wxT(
"hierarchical_schematic_top.SchDoc" ) ),
487 m_schematic.RefreshHierarchy();
constexpr EDA_IU_SCALE schIUScale
virtual const wxString & GetText() const
Return the string associated with the text object.
EE_TYPE OfType(KICAD_T aType) const
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const wxString GetUniStringLibNickname() const
static REPORTER & GetInstance()
int GetHeightIU(double aIUScale) const
Get the page height in IU.
Holds all the data relating to one schematic.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
void SetProject(PROJECT *aPrj)
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Base class for any item which can be embedded within the SCHEMATIC container class,...
const PAGE_INFO & GetPageSettings() 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.
SCH_SCREEN * GetScreen() const
SYMBOL_ORIENTATION_PROP GetOrientationProp() const
const LIB_ID & GetLibId() const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
VECTOR2I GetPosition() const override
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.
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
std::string GetTestDataRootDir()
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_CASE(Issue22943_SourceLibrarySymbolLibId)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I