39#include <wx/filename.h>
57 wxFileName tmp( wxFileName::CreateTempFileName( wxS(
"saveas" ) ) );
58 wxString dirPath = tmp.GetPath();
59 wxString dirName = tmp.GetName();
60 wxRemoveFile( tmp.GetFullPath() );
62 wxFileName base( dirPath, wxEmptyString );
63 base.AppendDir( dirName );
77 wxCopyFile( dataDir.GetFullPath() + wxS(
"/issue13212.kicad_sch" ),
78 m_srcDir.GetFullPath() + wxS(
"/issue13212.kicad_sch" ) );
79 wxCopyFile( dataDir.GetFullPath() + wxS(
"/issue13212_subsheet_1.kicad_sch" ),
80 m_srcDir.GetFullPath() + wxS(
"/issue13212_subsheet_1.kicad_sch" ) );
81 wxCopyFile( dataDir.GetFullPath() + wxS(
"/issue13212_subsheet_2.kicad_sch" ),
82 m_externalDir.GetFullPath() + wxS(
"/issue13212_subsheet_2.kicad_sch" ) );
85 rootFile.SetFullName( wxS(
"issue13212.kicad_sch" ) );
87 wxFFile file( rootFile.GetFullPath(), wxS(
"rb" ) );
89 file.ReadAll( &content );
91 content.Replace( wxS(
"issue13212_subsheet_2.kicad_sch" ),
92 wxS(
"../external/issue13212_subsheet_2.kicad_sch" ) );
93 wxFFile outFile( rootFile.GetFullPath(), wxS(
"wb" ) );
94 outFile.Write( content );
101 fn.SetName( aRelativePath );
108 for(
size_t i = 0; i < aScreens.
GetCount(); i++ )
124 wxFileName srcRoot = GetSchematicPath( wxS(
"issue13212" ) );
126 wxFileName destRoot( m_baseDir );
127 destRoot.AppendDir( wxS(
"new" ) );
128 destRoot.AppendDir( wxS(
"location" ) );
129 destRoot.SetName( wxS(
"issue13212" ) );
131 { wxFileName destDir( destRoot ); destDir.SetFullName( wxEmptyString );
if( !destDir.DirExists() ) destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ); }
133 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
136 m_schematic->Root().SetFileName( destRoot.GetFullName() );
137 m_schematic->RootScreen()->SetFileName( destRoot.GetFullPath() );
140 false, filenameMap, msg );
146 for(
size_t i = 0; i < screens.
GetCount(); i++ )
150 if( wxString( s->
GetFileName() ).EndsWith( wxS(
"issue13212_subsheet_1.kicad_sch" ) ) )
152 else if( wxString( s->
GetFileName() ).EndsWith( wxS(
"issue13212_subsheet_2.kicad_sch" ) ) )
156 wxFileName internalExpected( destRoot.GetPath(), wxS(
"issue13212_subsheet_1.kicad_sch" ) );
159 wxFileName externalExpected( m_externalDir.GetFullPath(), wxS(
"issue13212_subsheet_2.kicad_sch" ) );
162 SCH_SHEET_LIST sheetList = m_schematic->BuildSheetListSortedByPageNumbers();
164 wxString externalSheetPath;
168 if(
path.Last()->GetFileName().Contains( wxS(
"issue13212_subsheet_2" ) ) )
169 externalSheetPath =
path.Last()->GetFileName();
172 BOOST_CHECK_EQUAL( externalSheetPath, wxS(
"../../external/issue13212_subsheet_2.kicad_sch" ) );
180 wxFileName srcRoot = GetSchematicPath( wxS(
"issue13212" ) );
182 wxFileName destRoot( m_baseDir );
183 destRoot.AppendDir( wxS(
"destall" ) );
184 destRoot.SetName( wxS(
"issue13212" ) );
186 { wxFileName destDir( destRoot ); destDir.SetFullName( wxEmptyString );
if( !destDir.DirExists() ) destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ); }
188 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
191 m_schematic->Root().SetFileName( destRoot.GetFullName() );
192 m_schematic->RootScreen()->SetFileName( destRoot.GetFullPath() );
195 true, filenameMap, msg );
200 for(
size_t i = 0; i < screens.
GetCount(); i++ )
204 if( wxString( s->
GetFileName() ).EndsWith( wxS(
"issue13212_subsheet_2.kicad_sch" ) ) )
208 wxFileName externalExpected( destRoot.GetPath(), wxS(
"issue13212_subsheet_2.kicad_sch" ) );
217 wxFileName srcRoot = GetSchematicPath( wxS(
"issue13212" ) );
219 wxFileName destRoot( m_baseDir );
220 destRoot.AppendDir( wxS(
"nocopy" ) );
221 destRoot.SetName( wxS(
"issue13212" ) );
223 { wxFileName destDir( destRoot ); destDir.SetFullName( wxEmptyString );
if( !destDir.DirExists() ) destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ); }
225 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
228 m_schematic->Root().SetFileName( destRoot.GetFullName() );
229 m_schematic->RootScreen()->SetFileName( destRoot.GetFullPath() );
232 false, filenameMap, msg );
237 for(
size_t i = 0; i < screens.
GetCount(); i++ )
241 if( wxString( s->
GetFileName() ).EndsWith( wxS(
"issue13212_subsheet_1.kicad_sch" ) ) )
245 wxFileName internalExpected( m_srcDir.GetFullPath(), wxS(
"issue13212_subsheet_1.kicad_sch" ) );
256 wxFileName srcRoot = GetSchematicPath( wxS(
"issue13212" ) );
258 wxFileName destRoot( m_baseDir );
259 destRoot.AppendDir( wxS(
"virtualroot" ) );
260 destRoot.SetName( wxS(
"issue13212" ) );
263 wxFileName destDir( destRoot );
264 destDir.SetFullName( wxEmptyString );
265 BOOST_REQUIRE( destDir.DirExists() || destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ) );
267 SCH_SCREEN* virtualRootScreen = m_schematic->Root().GetScreen();
269 BOOST_REQUIRE( virtualRootScreen != m_schematic->RootScreen() );
272 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
275 m_schematic->Root().SetFileName( destRoot.GetFullName() );
276 m_schematic->RootScreen()->SetFileName( destRoot.GetFullPath() );
279 false, filenameMap, msg ) );
289 wxFileName srcRoot = GetSchematicPath( wxS(
"issue13212" ) );
291 wxFileName destRoot( m_baseDir );
292 destRoot.AppendDir( wxS(
"virtualrootcopy" ) );
293 destRoot.SetName( wxS(
"issue13212" ) );
296 wxFileName destDir( destRoot );
297 destDir.SetFullName( wxEmptyString );
298 BOOST_REQUIRE( destDir.DirExists() || destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ) );
300 SCH_SCREEN* virtualRootScreen = m_schematic->Root().GetScreen();
302 BOOST_REQUIRE( virtualRootScreen != m_schematic->RootScreen() );
305 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
308 filenameMap[m_schematic->RootScreen()] = destRoot.GetFullPath();
311 false, filenameMap, msg ) );
313 BOOST_CHECK( !filenameMap.contains( virtualRootScreen ) );
322 std::vector<wxString> references;
329 wxFileName destFile( m_baseDir );
330 destFile.AppendDir( wxS(
"apicopy" ) );
331 destFile.SetName( wxS(
"copy" ) );
334 wxFileName destDir( destFile );
335 destDir.SetFullName( wxEmptyString );
336 BOOST_REQUIRE( destDir.DirExists() || destDir.Mkdir( 0777, wxPATH_MKDIR_FULL ) );
339 destFile.GetFullPath(),
false ) );
341 wxFFile written( destFile.GetFullPath(), wxS(
"rb" ) );
345 written.ReadAll( &content );
347 for(
const wxString& reference : references )
348 BOOST_CHECK( content.Contains( wxS(
"\"" ) + reference + wxS(
"\"" ) ) );
356 dataDir.AppendDir( wxS(
"variants" ) );
358 for(
const wxString&
name : { wxS(
"variants.kicad_pro" ), wxS(
"variants.kicad_sch" ),
359 wxS(
"pic_sockets.kicad_sch" ) } )
369 bool loaded = manager.
LoadProject( projectFile.GetFullPath(),
false );
374 std::unique_ptr<
PROJECT,
decltype( unload )> unloadGuard(
project, unload );
378 std::unique_ptr<SCHEMATIC> schematic(
382 SCH_SCREEN* firstScreen = schematic->RootScreen();
383 firstScreen->
SetFileName( m_baseDir.GetPathWithSep() + wxS(
"first_sheet.kicad_sch" ) );
386 titleBlock.
SetRevision( wxS(
"api-save-revision" ) );
391 wxFFile written( projectFile.GetFullPath(), wxS(
"rb" ) );
393 BOOST_REQUIRE( written.IsOpened() && written.ReadAll( &content ) );
394 BOOST_CHECK( content.Contains( wxS(
"api-save-revision" ) ) );
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
A generic fixture for loading schematics and associated settings for qa tests.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Container for project specific data.
wxFileName GetSchematicPath(const wxString &aRelativePath)
SAVEAS_SUBSHEET_FIXTURE()
Base class for any item which can be embedded within the SCHEMATIC container class,...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
const wxString & GetFileName() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
TITLE_BLOCK & GetTitleBlock()
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...
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
void SetRevision(const wxString &aRevision)
bool PrepareSaveAsFiles(SCHEMATIC &aSchematic, SCH_SCREENS &aScreens, const wxFileName &aOldRoot, const wxFileName &aNewRoot, bool aSaveCopy, bool aCopySubsheets, bool aIncludeExternSheets, std::unordered_map< SCH_SCREEN *, wxString > &aFilenameMap, wxString &aErrorMsg)
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
bool SaveSchematic(SCHEMATIC &aSchematic, PROJECT &aProject)
Save every screen in the hierarchy to its current path, then update the project file.
bool SaveSchematicCopy(SCHEMATIC &aSchematic, PROJECT &aProject, const wxString &aFileName, bool aCreateProject)
Save the root schematic to aFileName without changing the open document.
PGM_BASE & Pgm()
The global program "get" accessor.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName, REPORTER *aReporter)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ REFERENCE
Field Reference of part, i.e. "IC21".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(CopyInternalReferenceExternal)
static bool ScreensContain(SCH_SCREENS &aScreens, SCH_SCREEN *aScreen)
Definition of file extensions used in Kicad.