KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue23403_shared_subsheet_screen.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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
29
30#include <boost/test/unit_test.hpp>
31#include <eeschema_test_utils.h>
32
34#include <sch_screen.h>
35#include <sch_sheet.h>
36#include <schematic.h>
39#include <locale_io.h>
41
42#include <wx/filename.h>
43
44
46{
49 {
50 wxFileName projectPath( KI_TEST::GetEeschemaTestDataDir() );
51 projectPath.AppendDir( "issue23403" );
52 projectPath.SetName( "issue23403" );
53 projectPath.SetExt( FILEEXT::ProjectFileExtension );
54
55 m_settingsManager.LoadProject( projectPath.GetFullPath().ToStdString() );
56 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
58 m_schematic->SetProject( m_project );
59 }
60
62 {
63 m_schematic.reset();
64 }
65
67 std::unique_ptr<SCHEMATIC> m_schematic;
69};
70
71
72static SCH_SCREEN* findSubSheetScreen( SCH_SHEET* aTopSheet, const wxString& aSubFileName )
73{
74 if( !aTopSheet || !aTopSheet->GetScreen() )
75 return nullptr;
76
77 for( SCH_ITEM* item : aTopSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
78 {
79 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
80
81 if( subSheet->GetScreen()
82 && subSheet->GetScreen()->GetFileName().EndsWith( aSubFileName ) )
83 {
84 return subSheet->GetScreen();
85 }
86 }
87
88 return nullptr;
89}
90
91
92BOOST_FIXTURE_TEST_SUITE( Issue23403SharedSubsheetScreen, ISSUE23403_FIXTURE )
93
94
95
99BOOST_AUTO_TEST_CASE( SharedSubSheetScreenReuse )
100{
102
103 wxFileName dataDir( KI_TEST::GetEeschemaTestDataDir() );
104 dataDir.AppendDir( "issue23403" );
105
106 wxFileName rootFile( dataDir.GetPath(), "issue23403", FILEEXT::KiCadSchematicFileExtension );
107 wxFileName topFile( dataDir.GetPath(), "top_level_sheet_1",
109
110 BOOST_REQUIRE_MESSAGE( rootFile.FileExists(),
111 "Test data missing: " + rootFile.GetFullPath().ToStdString() );
112 BOOST_REQUIRE_MESSAGE( topFile.FileExists(),
113 "Test data missing: " + topFile.GetFullPath().ToStdString() );
114
116
117 SCH_SHEET* sheet1 = io.LoadSchematicFile( rootFile.GetFullPath(), m_schematic.get() );
118 BOOST_REQUIRE( sheet1 != nullptr );
119
120 SCH_SHEET* sheet2 = io.LoadSchematicFile( topFile.GetFullPath(), m_schematic.get() );
121 BOOST_REQUIRE( sheet2 != nullptr );
122
123 SCH_SCREEN* screen1 = findSubSheetScreen( sheet1, wxT( "shared1.kicad_sch" ) );
124 SCH_SCREEN* screen2 = findSubSheetScreen( sheet2, wxT( "shared1.kicad_sch" ) );
125
126 BOOST_REQUIRE_MESSAGE( screen1 != nullptr,
127 "First top-level sheet should contain shared1 sub-sheet" );
128 BOOST_REQUIRE_MESSAGE( screen2 != nullptr,
129 "Second top-level sheet should contain shared1 sub-sheet" );
130
131 BOOST_CHECK_MESSAGE( screen1 == screen2,
132 "Both top-level sheets must share the same SCH_SCREEN for shared1" );
133
134 BOOST_CHECK_MESSAGE( screen1->GetRefCount() >= 2,
135 "Shared screen ref count should be at least 2, got "
136 + std::to_string( screen1->GetRefCount() ) );
137
138 delete sheet1;
139 delete sheet2;
140}
141
142
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Container for project specific data.
Definition project.h:62
A SCH_IO derivation for loading schematic files using the new s-expression file format.
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,...
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
const wxString & GetFileName() const
Definition sch_screen.h:150
int GetRefCount() const
Definition sch_screen.h:168
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
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
std::vector< FAB_LAYER_COLOR > dummy
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
static SCH_SCREEN * findSubSheetScreen(SCH_SHEET *aTopSheet, const wxString &aSubFileName)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
@ SCH_SHEET_T
Definition typeinfo.h:172
Definition of file extensions used in Kicad.