65 wxFileName schematicFileName;
73 wxCHECK( screen,
false );
77 aSaveUnderNewName =
true;
82 if( aSaveUnderNewName )
84 wxFileName savePath(
Prj().GetProjectFullName() );
86 if( !savePath.IsOk() || !savePath.IsDirWritable() )
90 if( !savePath.IsOk() || !savePath.IsDirWritable() )
94 wxFileDialog dlg(
this,
_(
"Schematic Files" ), savePath.GetPath(),
96 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
98 if( dlg.ShowModal() == wxID_CANCEL )
101 schematicFileName = dlg.GetPath();
103 if( schematicFileName.GetExt().IsEmpty() )
110 wxFileName tempFile( schematicFileName );
111 tempFile.SetName( wxT(
"." ) + tempFile.GetName() );
112 tempFile.SetExt( tempFile.GetExt() + wxT(
"$" ) );
116 wxT(
"Saving file <" ) + schematicFileName.GetFullPath() + wxT(
">" ) );
119 schematicFileName.GetFullPath() );
124 pi->Save( tempFile.GetFullPath(), aSheet, &
Schematic() );
129 msg.Printf(
_(
"Error saving schematic file \"%s\".\n%s" ),
130 schematicFileName.GetFullPath(), ioe.
What() );
133 msg.Printf(
_(
"Failed to create temporary file \"%s\"" ), tempFile.GetFullPath() );
137 wxRemoveFile( tempFile.GetFullPath() );
145 success = wxRenameFile( tempFile.GetFullPath(), schematicFileName.GetFullPath() );
149 msg.Printf(
_(
"Error saving schematic file \"%s\".\n" 150 "Failed to rename temporary file %s" ),
151 schematicFileName.GetFullPath(), tempFile.GetFullPath() );
154 msg.Printf(
_(
"Failed to rename temporary file \"%s\"" ), tempFile.GetFullPath() );
162 wxFileName autoSaveFileName = schematicFileName;
165 if( autoSaveFileName.FileExists() )
168 wxT(
"Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
171 wxRemoveFile( autoSaveFileName.GetFullPath() );
175 if( aSaveUnderNewName )
177 screen->
SetFileName( schematicFileName.GetFullPath() );
178 aSheet->
SetFileName( schematicFileName.GetFullPath() );
179 LockFile( schematicFileName.GetFullPath() );
186 msg.Printf(
_(
"File \"%s\" saved." ), screen->
GetFileName() );
187 SetStatusText( msg, 0 );
216 if( fn.IsDirWritable() && !fn.FileExists() )
237 auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>(
Kiface().KifaceSettings() );
240 if( aFileSet.size() != 1 )
242 msg.Printf(
"Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
247 wxString fullFileName( aFileSet[0] );
250 wxASSERT_MSG( wxFileName( fullFileName ).IsAbsolute(), wxT(
"Path is not absolute!" ) );
254 msg.Printf(
_(
"Schematic file \"%s\" is already open." ), fullFileName );
264 wxFileName pro = fullFileName;
267 bool is_new = !wxFileName::IsFileReadable( fullFileName );
273 msg.Printf(
_(
"Schematic \"%s\" does not exist. Do you wish to create it?" ),
276 if( !
IsOK(
this, msg ) )
291 SetStatusText( wxEmptyString );
308 if( differentProject )
310 if( !
Prj().IsNullProject() )
318 wxFileName legacyPro( pro );
323 if( !pro.Exists() && !legacyPro.Exists() && !( aCtl &
KICTL_CREATE ) )
329 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
352 Prj().SchSymbolLibTable();
359 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
382 SCH_PLUGIN* plugin = SCH_IO_MGR::FindPlugin( schFileType );
389 if( !pi->GetError().IsEmpty() )
392 _(
"The entire schematic could not be loaded. Errors " 393 "occurred attempting to load \nhierarchical sheet " 405 msg.Printf(
_(
"Error loading schematic file \"%s\".\n%s" ),
406 fullFileName, ioe.
What() );
409 msg.Printf(
_(
"Failed to load \"%s\"" ), fullFileName );
422 _(
"An error was found when loading the schematic that has " 423 "been automatically fixed. Please save the schematic to " 424 "repair the broken file or it may not be usable with other " 425 "versions of KiCad." ) );
436 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
450 wxArrayString libNames;
454 if( !libNames.IsEmpty() )
458 wxRichMessageDialog invalidLibDlg(
460 _(
"Illegal entry found in project file symbol library list." ),
461 _(
"Project Load Warning" ),
462 wxOK | wxCENTER | wxICON_EXCLAMATION );
463 invalidLibDlg.ShowDetailedText(
464 _(
"Symbol libraries defined in the project file symbol library " 465 "list are no longer supported and will be removed.\n\nThis may " 466 "cause broken symbol library links under certain conditions." ) );
467 invalidLibDlg.ShowCheckBox(
_(
"Do not show this dialog again." ) );
468 invalidLibDlg.ShowModal();
470 !invalidLibDlg.IsCheckBoxChecked();
478 if( !cfg || !cfg->m_RescueNeverShow )
491 "It will be converted to the new format when saved." ),
508 "It will be converted to the new format when saved." ),
513 screen->UpdateLocalLibSymbolLinks();
526 if(
Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
559 if( fn.FileExists() && !fn.IsFileWritable() )
576 wxString fullFileName;
581 wxLogError( wxT(
"Document not ready, cannot import" ) );
586 wxString path = wxPathOnly(
Prj().GetProjectFullName() );
588 wxFileDialog dlg(
this,
_(
"Append Schematic" ), path, wxEmptyString,
591 if( dlg.ShowModal() == wxID_CANCEL )
594 fullFileName = dlg.GetPath();
614 wxString msg =
_(
"This operation cannot be undone.\n\n" 615 "Do you want to save the current document before proceeding?" );
617 if(
IsOK(
this, msg ) )
632 wxString path = wxPathOnly(
Prj().GetProjectFullName() );
635 std::list<std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>> loaders;
644 wxString fileFilters;
645 wxString allWildcards;
647 for(
auto& loader : loaders )
649 if( !fileFilters.IsEmpty() )
650 fileFilters += wxChar(
'|' );
652 fileFilters += wxGetTranslation( loader.first );
659 fileFilters =
_(
"All supported formats|" ) + allWildcards +
"|" + fileFilters;
661 wxFileDialog dlg(
this,
_(
"Import Schematic" ), path, wxEmptyString, fileFilters,
662 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
664 if( dlg.ShowModal() == wxID_CANCEL )
674 wxFileName projectFn( dlg.GetPath() );
681 wxFileName fn = dlg.GetPath();
683 SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
685 for(
auto& loader : loaders )
689 pluginType = loader.second;
694 if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
696 wxLogError(
wxString::Format(
"unexpected file extension: %s", fn.GetExt() ) );
710 bool updateFileType =
false;
714 wxFileName fn = fileName;
717 wxArrayString overwrittenFiles;
719 for(
size_t i = 0; i < screens.
GetCount(); i++ )
723 wxCHECK2( screen,
continue );
736 if( tmpFn.FileExists() )
737 overwrittenFiles.Add( tmpFn.GetFullPath() );
740 if( !overwrittenFiles.IsEmpty() )
742 for(
const wxString& overwrittenFile : overwrittenFiles )
745 msg = overwrittenFile;
747 msg +=
"\n" + overwrittenFile;
750 wxRichMessageDialog dlg(
this,
_(
"Saving will overwrite existing files." ),
752 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER | wxICON_EXCLAMATION );
753 dlg.ShowDetailedText(
_(
"The following files will be overwritten:\n\n" ) + msg );
754 dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel(
_(
"Overwrite Files" ) ),
755 wxMessageDialog::ButtonLabel(
_(
"Abort Project Save" ) ) );
757 if( dlg.ShowModal() == wxID_CANCEL )
763 for(
size_t i = 0; i < screens.
GetCount(); i++ )
767 wxCHECK2( screen,
continue );
774 updateFileType =
true;
779 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
795 if( sheets.size() == 1 )
813 sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
817 Pgm().GetSettingsManager().SaveProject();
819 if( !
Kiface().IsSingle() )
824 SetStatusText( msg, 0 );
838 wxFileName fn = tmpFileName;
842 bool autoSaveOk =
true;
844 if( fn.GetPath().IsEmpty() )
845 tmp.AssignDir(
Prj().GetProjectPath() );
847 tmp.AssignDir( fn.GetPath() );
855 for(
size_t i = 0; i < screens.
GetCount(); i++ )
893 wxFileName newfilename;
896 switch( (SCH_IO_MGR::SCH_FILE_T) aFileType )
898 case SCH_IO_MGR::SCH_ALTIUM:
899 case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
900 case SCH_IO_MGR::SCH_EAGLE:
902 wxASSERT_MSG( wxFileName( aFileName ).IsAbsolute(),
903 wxT(
"Import schematic caller didn't send full filename" ) );
916 SCH_IO_MGR::FindPlugin( (SCH_IO_MGR::SCH_FILE_T) aFileType ) );
927 if( layoutfile.Open( layoutfn.GetFullPath(),
"wb" ) )
933 newfilename.SetPath(
Prj().GetProjectPath() );
934 newfilename.SetName(
Prj().GetProjectName() );
965 msg.Printf(
_(
"Error loading schematic \"%s\".\n%s" ), aFileName, ioe.
What() );
968 msg.Printf(
_(
"Failed to load \"%s\"" ), aFileName );
989 if( screen->IsModify() )
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
void Save_File(bool doSaveAs=false)
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
bool IsModified()
Check the entire hierarchy for any modifications.
const wxString & GetFileName() const
Handle the graphic items list to draw/plot the frame and title block.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
static void LibNamesAndPaths(PROJECT *aProject, bool doSave, wxString *aPaths, wxArrayString *aNames=NULL)
Save or load the names of the currently configured part libraries (without paths).
void SetVirtualPageNumber(int aPageNumber)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library TODO brief description.
SETTINGS_MANAGER * GetSettingsManager() const
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generates the connection data for the entire schematic hierarchy.
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
CONNECTION_GRAPH * ConnectionGraph() const override
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
This file is part of the common library.
void SaveProjectAs(const wxString &aFullPath)
Sets the currently loaded project path and saves it (pointers remain valid)
const std::string ProjectFileExtension
void SetScreen(BASE_SCREEN *aScreen) override
virtual PROJECT_FILE & GetProjectFile() const
#define KICTL_CREATE
caller thinks requested project files may not exist.
bool AskToSaveChanges()
Checks if any of the screens has unsaved changes and asks the user whether to save or drop them.
wxString KiCadSchematicFileWildcard()
int GetFileFormatVersionAtLoad() const
void ResolveERCExclusions()
Update markers to match recorded exclusions.
static TOOL_ACTION zoomFitScreen
void UpdateTitle()
Set the main window title bar text.
void OnAppendProject(wxCommandEvent &event)
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
bool IsWritable(const wxFileName &aFileName)
Checks if aFileName can be written.
SCH_SCREEN * GetScreen() const
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
A small class to help profiling.
bool importFile(const wxString &aFileName, int aFileType)
Load the given filename but sets the path to the current project path.
bool SaveEEFile(SCH_SHEET *aSheet, bool aSaveUnderNewName=false)
Save aSheet to a schematic file.
void LoadWindowState(const wxString &aFileName)
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
void OnImportProject(wxCommandEvent &event)
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
EESCHEMA_SETTINGS * eeconfig() const
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetRoot(SCH_SHEET *aRootSheet)
Initializes the schematic with a new root sheet.
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
Handle actions specific to the schematic editor.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath)
Return a plugin type given a schematic using the file extension of aSchematicPath.
wxString GetMruPath() const
wxString CadstarSchematicArchiveFileWildcard()
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
static DS_DATA_MODEL & GetTheInstance()
static function: returns the instance of DS_DATA_MODEL used in the application
Base class that schematic file and library loading and saving plugins should derive from.
void SetFileName(wxString aFilename)
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
void CheckForAutoSaveFile(const wxFileName &aFileName)
Check if an auto save file exists for aFileName and takes the appropriate action depending on the use...
bool IsSingle() const
Is this KIFACE_I running under single_top?
virtual const wxString What() const
A composite of Problem() and Where()
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void SyncView()
Mark all items for refresh.
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls BackupProject if a new backup is needed according to the current backup policy.
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.
SCHEMATIC & Schematic() const
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
Definition of file extensions used in Kicad.
bool AppendSchematic()
Import a KiCad schematic into the current sheet.
static wxString EmptyLayout()
Return a string containing the empty layout shape.
bool CreateArchiveLibraryCacheFile(bool aUseCurrentSheetFilename=false)
Create a symbol library file with the name of the root document plus the '-cache' suffix,...
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
wxLogTrace helper definitions.
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr)
Test all of the connectable objects in the schematic for unused connection points.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
wxString GetFileName() const
Return the filename corresponding to this sheet.
const std::string LegacyProjectFileExtension
void SetProject(PROJECT *aPrj)
virtual bool IsNullProject() const
Check if this project is a null project (i.e.
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
const std::string LegacySchematicFileExtension
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
bool LoadProjectSettings()
Loads the KiCad project file (*.pro) settings specific to Eeschema.
A wrapper for reporting to a wxString object.
void DismissOutdatedSave()
Dismisses the infobar for outdated save warnings and updates the containing layout and AUI manager (i...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
bool doAutoSave() override
Save the schematic files that have been modified and not yet saved.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static wxString GetAutoSaveFilePrefix()
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
void Reset()
Initializes this schematic to a blank one, unloading anything existing.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
std::vector< FILE_INFO_PAIR > & GetSheets()
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
virtual void SetReadOnly(bool aReadOnly=true)
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
wxString EagleSchematicFileWildcard()
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
bool SaveProject(const wxString &aFullPath=wxEmptyString)
Saves a loaded project.
SCH_SHEET * GetSheet(unsigned int aIndex) const
const std::string KiCadSchematicFileExtension
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
OUTDATED_SAVE Messages that should be cleared on save.
bool backup_on_autosave
Trigger a backup on autosave.
SCH_SHEET_PATH & GetCurrentSheet() const
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
void ClearDrawingState()
Clear the state flags of all the items in the screen.
void SetFileName(const wxString &aFileName)
static REPORTER & GetInstance()
Definition for part library class.
#define SEXPR_SCHEMATIC_FILE_VERSION
Symbol library file version.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_PART reference for each SCH_COMPONENT found in the full schematic.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
wxString AltiumSchematicFileWildcard()
void SetInitialPageNumbers()
Set initial sheet page numbers.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
bool show_illegal_symbol_lib_dialog
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.