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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
33
34#include <boost/test/unit_test.hpp>
35#include <eeschema_test_utils.h>
36
38#include <sch_screen.h>
39#include <sch_sheet.h>
40#include <schematic.h>
43#include <locale_io.h>
45
46#include <wx/filename.h>
47
48
50{
53 {
54 wxFileName projectPath( KI_TEST::GetEeschemaTestDataDir() );
55 projectPath.AppendDir( "issue23403" );
56 projectPath.SetName( "issue23403" );
57 projectPath.SetExt( FILEEXT::ProjectFileExtension );
58
59 m_settingsManager.LoadProject( projectPath.GetFullPath().ToStdString() );
60 m_schematic = std::make_unique<SCHEMATIC>( nullptr );
62 m_schematic->SetProject( m_project );
63 }
64
66 {
67 m_schematic.reset();
68 }
69
71 std::unique_ptr<SCHEMATIC> m_schematic;
73};
74
75
76static SCH_SCREEN* findSubSheetScreen( SCH_SHEET* aTopSheet, const wxString& aSubFileName )
77{
78 if( !aTopSheet || !aTopSheet->GetScreen() )
79 return nullptr;
80
81 for( SCH_ITEM* item : aTopSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
82 {
83 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
84
85 if( subSheet->GetScreen()
86 && subSheet->GetScreen()->GetFileName().EndsWith( aSubFileName ) )
87 {
88 return subSheet->GetScreen();
89 }
90 }
91
92 return nullptr;
93}
94
95
96BOOST_FIXTURE_TEST_SUITE( Issue23403SharedSubsheetScreen, ISSUE23403_FIXTURE )
97
98
99
103BOOST_AUTO_TEST_CASE( SharedSubSheetScreenReuse )
104{
106
107 wxFileName dataDir( KI_TEST::GetEeschemaTestDataDir() );
108 dataDir.AppendDir( "issue23403" );
109
110 wxFileName rootFile( dataDir.GetPath(), "issue23403", FILEEXT::KiCadSchematicFileExtension );
111 wxFileName topFile( dataDir.GetPath(), "top_level_sheet_1",
113
114 BOOST_REQUIRE_MESSAGE( rootFile.FileExists(),
115 "Test data missing: " + rootFile.GetFullPath().ToStdString() );
116 BOOST_REQUIRE_MESSAGE( topFile.FileExists(),
117 "Test data missing: " + topFile.GetFullPath().ToStdString() );
118
120
121 SCH_SHEET* sheet1 = io.LoadSchematicFile( rootFile.GetFullPath(), m_schematic.get() );
122 BOOST_REQUIRE( sheet1 != nullptr );
123
124 SCH_SHEET* sheet2 = io.LoadSchematicFile( topFile.GetFullPath(), m_schematic.get() );
125 BOOST_REQUIRE( sheet2 != nullptr );
126
127 SCH_SCREEN* screen1 = findSubSheetScreen( sheet1, wxT( "shared1.kicad_sch" ) );
128 SCH_SCREEN* screen2 = findSubSheetScreen( sheet2, wxT( "shared1.kicad_sch" ) );
129
130 BOOST_REQUIRE_MESSAGE( screen1 != nullptr,
131 "First top-level sheet should contain shared1 sub-sheet" );
132 BOOST_REQUIRE_MESSAGE( screen2 != nullptr,
133 "Second top-level sheet should contain shared1 sub-sheet" );
134
135 BOOST_CHECK_MESSAGE( screen1 == screen2,
136 "Both top-level sheets must share the same SCH_SCREEN for shared1" );
137
138 BOOST_CHECK_MESSAGE( screen1->GetRefCount() >= 2,
139 "Shared screen ref count should be at least 2, got "
140 + std::to_string( screen1->GetRefCount() ) );
141
142 delete sheet1;
143 delete sheet2;
144}
145
146
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:41
Container for project specific data.
Definition project.h:65
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:168
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:119
const wxString & GetFileName() const
Definition sch_screen.h:154
int GetRefCount() const
Definition sch_screen.h:171
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:140
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)
@ SCH_SHEET_T
Definition typeinfo.h:179
Definition of file extensions used in Kicad.