37#include <wx/filename.h>
46 wxCHECK( aSheet,
false );
51 wxFileName schematicFileName( aPath );
52 schematicFileName.MakeAbsolute();
54 if( !schematicFileName.DirExists() && !wxMkdir( schematicFileName.GetPath() ) )
57 if( schematicFileName.FileExists() && !schematicFileName.IsFileWritable() )
60 if( schematicFileName.FileExists() )
65 if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
66 pluginType = SCH_IO_MGR::SCH_KICAD;
72 pi->SaveSchematicFile( schematicFileName.GetFullPath(), aSheet, &aSchematic );
77 wxLogTrace( wxS(
"KI_TRACE_API" ), wxS(
"SaveSheetToFile failed: %s" ), ioe.
What() );
96 if( !topLevelSheets.empty() )
109 wxCHECK2( sheet,
continue );
112 sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
119 SCH_SCREEN* rootScreen = aSchematic.
RootScreen();
121 if( !rootScreen || rootScreen->
GetFileName().IsEmpty() )
124 SCH_SCREENS screens( aSchematic.
Root() );
125 screens.BuildClientSheetPathList();
129 for(
size_t i = 0; i < screens.GetCount(); i++ )
131 SCH_SCREEN* screen = screens.GetScreen( i );
133 wxCHECK2( screen,
continue );
137 if( !fileName.IsOk() )
142 if( sheets.size() == 1 )
147 success &=
SaveSheetToFile( screens.GetSheet( i ), aSchematic, fileName.GetFullPath() );
166 if( !rootScreen || !projectFile.HasName() || !projectFile.IsOk() )
169 syncProjectFile( aSchematic, aProject, rootScreen );
176 if( !saveScreens( aSchematic ) )
186 wxFileName schematicFileName( aFileName );
187 schematicFileName.MakeAbsolute();
189 if( !schematicFileName.IsOk() || !schematicFileName.IsDirWritable() )
196 if( !rootSheet || !rootScreen )
199 if( schematicFileName.GetFullPath() == rootScreen->
GetFileName() )
202 if( !
SaveSheetToFile( rootSheet, aSchematic, schematicFileName.GetFullPath() ) )
207 wxFileName projectFile( schematicFileName );
210 if( !projectFile.FileExists() )
212 if( !
Pgm().GetSettingsManager().SaveProjectCopy( projectFile.GetFullPath() ) )
224 schematicFileName.MakeAbsolute();
226 if( !schematicFileName.IsOk() || schematicFileName.GetName().IsEmpty() )
229 if( ( !schematicFileName.DirExists() && !schematicFileName.Mkdir() ) || !schematicFileName.IsDirWritable() )
236 if( !saveScreens( aSchematic ) )
239 syncProjectFile( aSchematic, aProject, aSchematic.
RootScreen() );
242 wxFileName projectFile( schematicFileName );
BASE_SCREEN class implementation.
void SetVirtualPageNumber(int aPageNumber)
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
void SetContentModified(bool aModified=true)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual SETTINGS_MANAGER & GetSettingsManager() const
std::vector< FILE_INFO_PAIR > & GetSheets()
SCHEMATIC_SETTINGS * m_SchematicSettings
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
Container for project specific data.
virtual void SetReadOnly(bool aReadOnly=true)
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual PROJECT_FILE & GetProjectFile() const
wxString m_SchDrawingSheetFileName
Holds all the data relating to one schematic.
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
bool HasHierarchy() const
Check if the hierarchy has been built.
SCH_SHEET * GetTopLevelSheet(int aIndex=0) const
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
std::vector< TOP_LEVEL_SHEET_INFO > TopLevelSheetInfos() const
The top-level sheets as the project file records them, with file names relative to the project.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath, int aCtl=0)
Return a plugin type given a schematic using the file extension of aSchematicPath.
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Return the number of times this screen is used.
const wxString & GetFileName() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
TITLE_BLOCK & GetTitleBlock()
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
bool IsVirtualRootSheet() const
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
const wxString & GetRevision() const
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
bool SaveSheetToFile(SCH_SHEET *aSheet, SCHEMATIC &aSchematic, const wxString &aPath)
Write a single sheet to disk via SCH_IO.
bool SaveSchematic(SCHEMATIC &aSchematic, PROJECT &aProject)
Save every screen in the hierarchy to its current path, then update the project file.
void UpdateProjectFile(SCHEMATIC &aSchematic, PROJECT &aProject)
Sync schematic metadata into the project file (.kicad_pro) and save it.
bool SaveSchematicCopy(SCHEMATIC &aSchematic, PROJECT &aProject, const wxString &aFileName, bool aCreateProject)
Save the root schematic to aFileName without changing the open document.
bool SaveSchematicAs(SCHEMATIC &aSchematic, PROJECT &aProject, const wxString &aFileName)
Save the schematic to aFileName and adopt it: the root sheet and screen are re-homed to the new path,...
PGM_BASE & Pgm()
The global program "get" accessor.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
wxString schRevision
Auto-propagated schematic title block revision.
Definition of file extensions used in Kicad.