KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_altium_sch_import.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
22
23#include <lib_id.h>
24#include <schematic.h>
26#include <sch_screen.h>
27#include <sch_sheet.h>
28#include <sch_symbol.h>
30
31#include <set>
32#include <vector>
33
34
35namespace
36{
37
38struct ALTIUM_SCH_IMPORT_FIXTURE
39{
40 ALTIUM_SCH_IMPORT_FIXTURE() : m_schematic( nullptr )
41 {
42 m_settingsManager.LoadProject( "" );
43 m_schematic.SetProject( &m_settingsManager.Prj() );
44 m_schematic.Reset();
45 }
46
47 ~ALTIUM_SCH_IMPORT_FIXTURE() { m_schematic.Reset(); }
48
49 wxString dataFile( const wxString& aName ) const
50 {
51 return wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir()
52 + "/plugins/altium/issue22943/" )
53 + aName;
54 }
55
56 SETTINGS_MANAGER m_settingsManager;
57 SCHEMATIC m_schematic;
58};
59
60} // namespace
61
62
63BOOST_FIXTURE_TEST_SUITE( AltiumSchImport, ALTIUM_SCH_IMPORT_FIXTURE )
64
65
66// https://gitlab.com/kicad/code/kicad/-/issues/22943
67// A component placed from an external Altium library must be addressed by a well-formed library
68// id (source library nickname + real library reference) so it resolves against the library that
69// project import registers, instead of the importer's internal per-placement name.
70BOOST_AUTO_TEST_CASE( Issue22943_SourceLibrarySymbolLibId )
71{
72 SCH_IO_ALTIUM plugin;
73
74 SCH_SHEET* rootSheet = plugin.LoadSchematicFile( dataFile( "1_cover.SchDoc" ), &m_schematic );
75 BOOST_REQUIRE( rootSheet );
76 BOOST_REQUIRE( rootSheet->GetScreen() );
77
78 // The real reference names of every symbol contained in the source library.
79 wxArrayString libNames;
80 plugin.EnumerateSymbolLib( libNames, dataFile( "mounting_holes.SchLib" ) );
81
82 std::set<wxString> libSymbolNames( libNames.begin(), libNames.end() );
83 BOOST_REQUIRE( libSymbolNames.count( wxT( "MH M3" ) ) );
84
85 std::vector<SCH_SYMBOL*> fromMountingHoles;
86
87 for( SCH_ITEM* item : rootSheet->GetScreen()->Items().OfType( SCH_SYMBOL_T ) )
88 {
89 SCH_SYMBOL* sym = static_cast<SCH_SYMBOL*>( item );
90
91 if( sym->GetLibId().GetUniStringLibNickname() == wxT( "mounting_holes" ) )
92 fromMountingHoles.push_back( sym );
93 }
94
95 BOOST_REQUIRE( !fromMountingHoles.empty() );
96
97 // Every symbol drawn from the source library must name an item that actually exists there.
98 for( SCH_SYMBOL* sym : fromMountingHoles )
99 {
100 const LIB_ID& libId = sym->GetLibId();
101 BOOST_CHECK( libId.IsValid() );
102 BOOST_CHECK_MESSAGE( libSymbolNames.count( libId.GetUniStringLibItemName() ),
103 "Library id '" << libId.Format().wx_str()
104 << "' does not resolve in mounting_holes.SchLib" );
105 }
106}
107
108
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
UTF8 Format() const
Definition lib_id.cpp:132
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition lib_id.h:108
const wxString GetUniStringLibNickname() const
Definition lib_id.h:84
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,...
Definition sch_item.h:162
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:139
Schematic symbol object.
Definition sch_symbol.h:69
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:158
wxString wx_str() const
Definition utf8.cpp:41
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_SYMBOL_T
Definition typeinfo.h:169