KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema_test_utils.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 (C) 2019-2023 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
24#include "eeschema_test_utils.h"
27
28#include <cstdlib>
29#include <memory>
30
32#include <eeschema/sch_screen.h>
33#include <eeschema/schematic.h>
36
37
38void KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic( const wxString& aBaseName )
39{
40 wxFileName fn = GetSchematicPath( aBaseName );
41
42 BOOST_TEST_MESSAGE( fn.GetFullPath() );
43
44 wxFileName pro( fn );
46
47 // Schematic must be reset before a project is reloaded
49 m_manager.LoadProject( pro.GetFullPath() );
50
52
54 m_schematic.SetRoot( m_pi->LoadSchematicFile( fn.GetFullPath(), &m_schematic ) );
55
56 BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
57
59
60 SCH_SCREENS screens( m_schematic.Root() );
61
62 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
63 screen->UpdateLocalLibSymbolLinks();
64
66
67 // Restore all of the loaded symbol instances from the root sheet screen.
70
73
75 {
76 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
77 screen->MigrateSimModels();
78 }
79
82
83 sheets.AnnotatePowerSymbols();
85 // NOTE: This is required for multi-unit symbols to be correct
86 for( SCH_SHEET_PATH& sheet : sheets )
87 sheet.UpdateAllScreenReferences();
89 // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
90 // SchematicCleanUp must be freed from its UI dependencies.
91
92 std::unordered_set<SCH_SCREEN*> all_screens;
93
94 for( const SCH_SHEET_PATH& path : sheets )
95 all_screens.insert( path.LastScreen() );
96
97 SCH_RULE_AREA::UpdateRuleAreasInScreens( all_screens, nullptr );
98
99 m_schematic.ConnectionGraph()->Recalculate( sheets, true );
100}
101
102
103wxFileName KI_TEST::SCHEMATIC_TEST_FIXTURE::GetSchematicPath( const wxString& aBaseName )
104{
105 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
106 fn.AppendDir( "netlists" );
107 fn.AppendDir( aBaseName );
108 fn.SetName( aBaseName );
110
111 return fn;
112}
113
114
115template <typename Exporter>
117{
118 wxFileName netFile = m_schematic.Prj().GetProjectFullName();
119
120 if( aTest )
121 netFile.SetName( netFile.GetName() + "_test" );
122
123 netFile.SetExt( FILEEXT::NetlistFileExtension );
124
125 return netFile.GetFullPath();
126}
127
128
129template <typename Exporter>
131{
132 // In case of a crash the file may not have been deleted.
133 if( wxFileExists( GetNetlistPath( true ) ) )
134 wxRemoveFile( GetNetlistPath( true ) );
135
136 wxString errors;
137 WX_STRING_REPORTER reporter( &errors );
138 std::unique_ptr<Exporter> exporter = std::make_unique<Exporter>( &m_schematic );
139
140 bool success = exporter->WriteNetlist( GetNetlistPath( true ), GetNetlistOptions(), reporter );
141
142 BOOST_REQUIRE( success && errors.IsEmpty() );
143}
144
145
146template <typename Exporter>
148{
149 wxRemoveFile( GetNetlistPath( true ) );
150 m_schematic.Reset();
151}
152
153
154template <typename Exporter>
156{
157 LoadSchematic( aBaseName );
158 WriteNetlist();
159 CompareNetlists();
160 Cleanup();
161}
162
163
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr)
Update the connection graph for the given list of sheets.
virtual void LoadSchematic(const wxString &aRelativePath)
virtual wxFileName GetSchematicPath(const wxString &aBaseName)
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
Definition: project.cpp:309
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:138
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:144
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:154
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:194
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:164
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:207
SCH_SHEET & Root() const
Definition: schematic.h:113
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:96
static std::vector< std::pair< SCH_RULE_AREA *, SCH_SCREEN * > > UpdateRuleAreasInScreens(std::unordered_set< SCH_SCREEN * > &screens, KIGFX::SCH_VIEW *view)
Updates all rule area connectvity / caches in the given sheet paths.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:710
SCH_SCREEN * GetNext()
void FixLegacyPowerSymbolMismatches()
Fix legacy power symbols that have mismatched value text fields and invisible power pin names.
SCH_SCREEN * GetFirst()
const std::vector< SCH_SYMBOL_INSTANCE > & GetSymbolInstances() const
Definition: sch_screen.h:521
int GetFileFormatVersionAtLoad() const
Definition: sch_screen.h:128
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:526
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateSheetInstanceData(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads 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.
void TestNetlist(const wxString &aBaseName)
virtual wxString GetNetlistPath(bool aTest=false)
A wrapper for reporting to a wxString object.
Definition: reporter.h:165
static const std::string NetlistFileExtension
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of file extensions used in Kicad.