70#include <wx/filedlg.h>
72#include <wx/richmsgdlg.h>
73#include <wx/stdpaths.h>
83#include "widgets/filedlg_hook_save_project.h"
96 if( aFileSet.size() != 1 )
98 msg.Printf(
"Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
103 wxString fullFileName( aFileSet[0] );
104 wxFileName wx_filename( fullFileName );
107 wxASSERT_MSG( wx_filename.IsAbsolute(), wxS(
"Path is not absolute!" ) );
111 msg.Printf(
_(
"Schematic '%s' is already open by '%s' at '%s'." ), fullFileName,
127 wxFileName pro = fullFileName;
130 bool is_new = !wxFileName::IsFileReadable( fullFileName );
136 msg.Printf(
_(
"Schematic '%s' does not exist. Do you wish to create it?" ),
139 if( !
IsOK(
this, msg ) )
143 wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGING );
144 ProcessEventLocally( e );
155 SetStatusText( wxEmptyString );
159 :
_(
"Loading Schematic" ), 1 );
163 if( differentProject )
165 if( !
Prj().IsNullProject() )
176 wxFileName legacyPro( pro );
181 if( !pro.Exists() && !legacyPro.Exists() && !( aCtl &
KICTL_CREATE ) )
190 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
220 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
230 if( is_new || schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
236 if( schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
238 msg.Printf(
_(
"'%s' is not a KiCad schematic file.\nUse File -> Import for "
239 "non-KiCad schematic files." ),
242 progressReporter.Hide();
248 wxFileName autoSaveFn = fullFileName;
251 autoSaveFn.ClearExt();
267 pi->SetProgressReporter( &progressReporter );
269 bool failedLoad =
false;
284 if( !pi->GetError().IsEmpty() )
287 "occurred attempting to load hierarchical sheets." ),
293 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName);
294 progressReporter.Hide();
301 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName);
302 progressReporter.Hide();
307 catch(
const std::bad_alloc& )
309 msg.Printf(
_(
"Memory exhausted loading schematic '%s'." ), fullFileName );
310 progressReporter.Hide();
328 msg.Printf(
_(
"Failed to load '%s'." ), fullFileName );
341 _(
"An error was found when loading the schematic that has "
342 "been automatically fixed. Please save the schematic to "
343 "repair the broken file or it may not be usable with other "
344 "versions of KiCad." ) );
355 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
360 std::vector<SCH_ITEM*> deleted;
362 for(
SCH_ITEM* item : screen->Items() )
367 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
371 wire->SetEndPoint( entry->
GetEnd() );
373 screen->Append( wire.release() );
374 deleted.push_back( item );
379 screen->Remove( item );
395 wxArrayString libNames;
399 if( !libNames.IsEmpty() )
401 if(
eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
403 wxRichMessageDialog invalidLibDlg(
405 _(
"Illegal entry found in project file symbol library list." ),
406 _(
"Project Load Warning" ),
407 wxOK | wxCENTER | wxICON_EXCLAMATION );
408 invalidLibDlg.ShowDetailedText(
409 _(
"Symbol libraries defined in the project file symbol library "
410 "list are no longer supported and will be removed.\n\n"
411 "This may cause broken symbol library links under certain "
413 invalidLibDlg.ShowCheckBox(
_(
"Do not show this dialog again." ) );
414 invalidLibDlg.ShowModal();
416 !invalidLibDlg.IsCheckBoxChecked();
427 editor->RescueSymbolLibTableProject(
false );
437 wxFileName cacheFn = pro;
439 cacheFn.SetName( cacheFn.GetName() +
"-cache" );
442 msg.Printf(
_(
"The project symbol library cache file '%s' was not found." ),
443 cacheFn.GetFullName() );
444 extMsg =
_(
"This can result in a broken schematic under certain conditions. "
445 "If the schematic does not have any missing symbols upon opening, "
446 "save it immediately before making any changes to prevent data "
447 "loss. If there are missing symbols, either manual recovery of "
448 "the schematic or recovery of the symbol cache library file and "
449 "reloading the schematic is required." );
451 wxMessageDialog dlgMissingCache(
this, msg,
_(
"Warning" ),
452 wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
453 dlgMissingCache.SetExtendedMessage( extMsg );
454 dlgMissingCache.SetOKCancelLabels(
455 wxMessageDialog::ButtonLabel(
_(
"Load Without Cache File" ) ),
456 wxMessageDialog::ButtonLabel(
_(
"Abort" ) ) );
458 if( dlgMissingCache.ShowModal() == wxID_CANCEL )
472 "It will be converted to the new format when saved." ),
480 screen->FixLegacyPowerSymbolMismatches();
492 "It will be converted to the new format when saved." ),
497 screen->UpdateLocalLibSymbolLinks();
500 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221002 )
503 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221110 )
506 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
509 screen->FixLegacyPowerSymbolMismatches();
512 screen->MigrateSimModels();
530 if(
Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
544 "and/or trailing white space field names." ),
566 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
576 wxCommandEvent changedEvt( EDA_EVT_SCHEMATIC_CHANGED );
577 ProcessEventLocally( changedEvt );
581 wxCHECK2( listener,
continue );
585 wxWindow* win =
dynamic_cast<wxWindow*
>( listener );
588 win->HandleWindowEvent( e );
590 listener->SafelyProcessEvent( e );
598 if( fn.FileExists() && !fn.IsFileWritable() )
621 wxString msg =
_(
"This operation replaces the contents of the current schematic, "
622 "which will be permanently lost.\n\n"
623 "Do you want to proceed?" );
625 if( !
IsOK(
this, msg ) )
631 wxString
path = wxPathOnly(
Prj().GetProjectFullName() );
633 wxString fileFiltersStr;
634 wxString allWildcardsStr;
636 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
638 if(
fileType == SCH_IO_MGR::SCH_KICAD ||
fileType == SCH_IO_MGR::SCH_LEGACY )
651 if( !fileFiltersStr.IsEmpty() )
652 fileFiltersStr += wxChar(
'|' );
660 fileFiltersStr =
_(
"All supported formats" ) + wxS(
"|" ) + allWildcardsStr + wxS(
"|" )
663 wxFileDialog dlg(
this,
_(
"Import Schematic" ),
path, wxEmptyString, fileFiltersStr,
664 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
667 dlg.SetCustomizeHook( importOptions );
669 if( dlg.ShowModal() == wxID_CANCEL )
689 wxFileName projectFn( dlg.GetPath() );
696 wxFileName fn = dlg.GetPath();
698 if( !fn.IsFileReadable() )
700 wxLogError(
_(
"Insufficient permissions to read file '%s'." ), fn.GetFullPath() );
704 SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
706 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
713 if( pi->CanReadSchematicFile( fn.GetFullPath() ) )
720 if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
722 wxLogError(
_(
"No loader can read the specified file: '%s'." ), fn.GetFullPath() );
737 wxFileName schematicFileName;
738 wxFileName oldFileName;
743 wxCHECK( screen,
false );
746 if( aSavePath.IsEmpty() )
751 oldFileName = schematicFileName;
756 if( !schematicFileName.DirExists() )
758 if( !wxMkdir( schematicFileName.GetPath() ) )
760 msg.Printf(
_(
"Error saving schematic file '%s'.\n%s" ),
761 schematicFileName.GetFullPath(),
762 "Could not create directory: %s" + schematicFileName.GetPath() );
772 wxFileName projectFile( schematicFileName );
776 if( projectFile.FileExists() )
783 wxString tempFile = wxFileName::CreateTempFileName( wxS(
"eeschema" ) );
786 wxLogTrace(
traceAutoSave, wxS(
"Saving file " ) + schematicFileName.GetFullPath() );
792 schematicFileName.GetFullPath() );
794 if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
795 pluginType = SCH_IO_MGR::SCH_KICAD;
801 pi->SaveSchematicFile( tempFile, aSheet, &
Schematic() );
806 msg.Printf(
_(
"Error saving schematic file '%s'.\n%s" ),
807 schematicFileName.GetFullPath(),
811 msg.Printf(
_(
"Failed to create temporary file '%s'." ),
816 wxRemoveFile( tempFile );
827 success = wxRenameFile( tempFile, schematicFileName.GetFullPath() );
831 msg.Printf(
_(
"Error saving schematic file '%s'.\n"
832 "Failed to rename temporary file '%s'." ),
833 schematicFileName.GetFullPath(),
837 msg.Printf(
_(
"Failed to rename temporary file '%s'." ),
846 wxFileName autoSaveFileName = schematicFileName;
849 if( autoSaveFileName.FileExists() )
852 wxS(
"Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
855 wxRemoveFile( autoSaveFileName.GetFullPath() );
860 msg.Printf(
_(
"File '%s' saved." ), screen->
GetFileName() );
861 SetStatusText( msg, 0 );
879 bool updateFileHistory =
false;
880 bool createNewProject =
false;
884 wxFileName fn = fileName;
888 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
891 if(
Prj().IsNullProject() || aSaveAs )
894 wxCHECK(
Kiface().IsSingle() || aSaveAs,
false );
896 wxFileName newFileName;
897 wxFileName savePath(
Prj().GetProjectFullName() );
899 if( !savePath.IsOk() || !savePath.IsDirWritable() )
903 if( !savePath.IsOk() || !savePath.IsDirWritable() )
907 if( savePath.HasExt() )
910 savePath.SetName( wxEmptyString );
912 wxFileDialog dlg(
this,
_(
"Schematic Files" ), savePath.GetPath(), savePath.GetFullName(),
914 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
919 if(
Kiface().IsSingle() || aSaveAs )
921 dlg.SetCustomizeHook( newProjectHook );
924 if( dlg.ShowModal() == wxID_CANCEL )
929 if( ( !newFileName.DirExists() && !newFileName.Mkdir() ) ||
930 !newFileName.IsDirWritable() )
932 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
933 "Make sure you have write permissions and try again." ),
934 newFileName.GetPath() );
936 wxMessageDialog dlgBadPath(
this, msg,
_(
"Error" ),
937 wxOK | wxICON_EXCLAMATION | wxCENTER );
939 dlgBadPath.ShowModal();
950 updateFileHistory =
true;
958 for(
size_t i = 0; i < screens.
GetCount(); i++ )
962 wxCHECK2( screen,
continue );
973 if( tmp.FileExists() )
976 if( tmp.GetPath().IsEmpty() )
978 tmp.SetPath( newFileName.GetPath() );
980 else if( tmp.GetPath() == fn.GetPath() )
982 tmp.SetPath( newFileName.GetPath() );
984 else if( tmp.GetPath().StartsWith( fn.GetPath() ) )
988 wxString newPath = newFileName.GetPath();
989 newPath += tmp.GetPath().Right( fn.GetPath().Length() );
990 tmp.SetPath( newPath );
994 wxS(
"Moving schematic from '%s' to '%s'." ),
998 if( !tmp.DirExists() && !tmp.Mkdir() )
1000 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
1001 "Make sure you have write permissions and try again." ),
1002 newFileName.GetPath() );
1004 wxMessageDialog dlgBadFilePath(
this, msg,
_(
"Error" ),
1005 wxOK | wxICON_EXCLAMATION | wxCENTER );
1007 dlgBadFilePath.ShowModal();
1012 filenameMap[screen] = tmp.GetFullPath();
1020 if( !sheet.Last()->IsRootSheet() )
1021 sheet.MakeFilePathRelativeToParentSheet();
1024 else if( !fn.FileExists() )
1027 updateFileHistory =
true;
1038 if( filenameMap.empty() || !saveCopy )
1040 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1045 wxArrayString overwrittenFiles;
1046 wxArrayString lockedFiles;
1048 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1052 wxCHECK2( screen,
continue );
1055 wxFileName tmpFn = filenameMap[screen];
1060 if( tmpFn.FileExists() && !tmpFn.IsFileWritable() )
1061 lockedFiles.Add( tmpFn.GetFullPath() );
1068 if( tmpFn.FileExists() )
1069 overwrittenFiles.Add( tmpFn.GetFullPath() );
1072 if( !lockedFiles.IsEmpty() )
1074 for(
const wxString& lockedFile : lockedFiles )
1079 msg +=
"\n" + lockedFile;
1082 wxRichMessageDialog dlg(
this, wxString::Format(
_(
"Failed to save %s." ),
1084 _(
"Locked File Warning" ),
1085 wxOK | wxICON_WARNING | wxCENTER );
1086 dlg.SetExtendedMessage(
_(
"You do not have write permissions to:\n\n" ) + msg );
1092 if( !overwrittenFiles.IsEmpty() )
1094 for(
const wxString& overwrittenFile : overwrittenFiles )
1097 msg = overwrittenFile;
1099 msg +=
"\n" + overwrittenFile;
1102 wxRichMessageDialog dlg(
this,
_(
"Saving will overwrite existing files." ),
1103 _(
"Save Warning" ),
1104 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER |
1105 wxICON_EXCLAMATION );
1106 dlg.ShowDetailedText(
_(
"The following files will be overwritten:\n\n" ) + msg );
1107 dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel(
_(
"Overwrite Files" ) ),
1108 wxMessageDialog::ButtonLabel(
_(
"Abort Project Save" ) ) );
1110 if( dlg.ShowModal() == wxID_CANCEL )
1116 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1120 wxCHECK2( screen,
continue );
1123 wxFileName tmpFn = filenameMap[screen];
1127 updateFileHistory =
true;
1135 if( !sheetFileName.IsOk()
1140 sheet->
SetFileName( sheetFileName.GetFullPath() );
1144 filenameMap[screen] = tmpFn.GetFullPath();
1156 if( sheets.size() == 1 )
1162 if( !saveCopy && tmpFn.GetFullPath() != screen->
GetFileName() )
1172 if( !aSaveAs && !success )
1175 if( aSaveAs && success )
1178 if( updateFileHistory )
1189 wxCHECK2( sheet,
continue );
1196 wxCHECK2( screen,
continue );
1200 sheets.emplace_back( std::make_pair( screen->
GetUuid(), wxT(
"Root" ) ) );
1204 sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
1208 wxASSERT( filenameMap.count(
Schematic().RootScreen() ) );
1209 wxFileName projectPath( filenameMap.at(
Schematic().RootScreen() ) );
1212 if(
Prj().IsNullProject() || ( aSaveAs && !saveCopy ) )
1217 else if( saveCopy && createNewProject )
1227 if( !
Kiface().IsSingle() )
1247 wxFileName fn = tmpFileName;
1255 bool autoSaveOk =
true;
1257 if( fn.GetPath().IsEmpty() )
1258 tmp.AssignDir(
Prj().GetProjectPath() );
1260 tmp.AssignDir( fn.GetPath() );
1268 wxString title = GetTitle();
1270 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1311 const std::map<std::string, UTF8>* aProperties )
1313 wxFileName filename( aFileName );
1314 wxFileName newfilename;
1315 SCH_IO_MGR::SCH_FILE_T
fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType;
1317 wxCommandEvent changingEvt( EDA_EVT_SCHEMATIC_CHANGING );
1318 ProcessEventLocally( changingEvt );
1322 case SCH_IO_MGR::SCH_ALTIUM:
1323 case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
1324 case SCH_IO_MGR::SCH_EAGLE:
1325 case SCH_IO_MGR::SCH_LTSPICE:
1326 case SCH_IO_MGR::SCH_EASYEDA:
1327 case SCH_IO_MGR::SCH_EASYEDAPRO:
1331 wxCHECK_MSG( aFileName.IsEmpty() || filename.IsAbsolute(),
false,
1332 wxS(
"Import schematic: path is not absolute!" ) );
1343 this, std::placeholders::_1 ) );
1346 if(
eeconfig()->m_System.show_import_issues )
1351 pi->SetProgressReporter( &progressReporter );
1372 newfilename.SetPath(
Prj().GetProjectPath() );
1373 newfilename.SetName(
Prj().GetProjectName() );
1399 wxString msg = wxString::Format(
_(
"Error loading schematic '%s'." ), aFileName );
1402 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1405 catch(
const std::exception& exc )
1410 wxString msg = wxString::Format(
_(
"Unhandled exception occurred loading schematic "
1411 "'%s'." ), aFileName );
1414 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1427 wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGED );
1428 ProcessEventLocally( e );
1432 wxCHECK2( listener,
continue );
1436 wxWindow* win =
dynamic_cast<wxWindow*
>( listener );
1439 win->HandleWindowEvent( e );
1441 listener->SafelyProcessEvent( e );
1467 if( simFrame && !simFrame->Close() )
1470 if( screen->IsContentModified() )
1493 wxLogTrace(
traceAutoSave,
"Creating auto save file %s", autoSaveFileName.GetFullPath() );
1495 wxCHECK( autoSaveFileName.IsDirWritable(),
false );
1499 std::vector< wxString > autoSavedFiles;
1501 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1511 autoSavedFiles.emplace_back( fn.GetFullPath() );
1514 wxTextFile autoSaveFile( autoSaveFileName.GetFullPath() );
1516 if( autoSaveFileName.FileExists() && !wxRemoveFile( autoSaveFileName.GetFullPath() ) )
1518 wxLogTrace(
traceAutoSave,
"Error removing auto save file %s",
1519 autoSaveFileName.GetFullPath() );
1525 if( autoSavedFiles.empty() )
1528 if( !autoSaveFile.Create() )
1531 for(
const wxString& fileName : autoSavedFiles )
1533 wxLogTrace(
traceAutoSave,
"Adding auto save file %s to %s",
1534 fileName, autoSaveFileName.GetName() );
1535 autoSaveFile.AddLine( fileName );
1538 if( !autoSaveFile.Write() )
1541 wxLogTrace(
traceAutoSave,
"Auto save file '%s' written", autoSaveFileName.GetFullName() );
1547void removeFile(
const wxString& aFilename, wxArrayString& aUnremoved )
1549 wxLogTrace(
traceAutoSave, wxS(
"Removing auto save file " ) + aFilename );
1551 if( wxFileExists( aFilename ) && !wxRemoveFile( aFilename ) )
1552 aUnremoved.Add( aFilename );
1558 if( !
Pgm().IsGUI() )
1561 wxCHECK_RET( aFileName.IsOk(), wxS(
"Invalid file name!" ) );
1564 wxS(
"Checking for auto save file " ) + aFileName.GetFullPath() );
1566 if( !aFileName.FileExists() )
1570 "Well this is potentially embarrassing!\n"
1571 "It appears that the last time you were editing one or more of the schematic files\n"
1572 "were not saved properly. Do you wish to restore the last saved edits you made?" );
1574 int response = wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1577 wxTextFile fileList( aFileName.GetFullPath() );
1579 if( !fileList.Open() )
1581 msg.Printf(
_(
"The file '%s' could not be opened.\n"
1582 "Manual recovery of automatically saved files is required." ),
1583 aFileName.GetFullPath() );
1585 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
this );
1589 if( response == wxYES )
1591 wxArrayString unrecoveredFiles;
1593 for( wxString fn = fileList.GetFirstLine(); !fileList.Eof(); fn = fileList.GetNextLine() )
1595 wxFileName recoveredFn = fn;
1596 wxString tmp = recoveredFn.GetName();
1600 recoveredFn.SetName( tmp );
1602 wxFileName backupFn = recoveredFn;
1606 wxLogTrace(
traceAutoSave, wxS(
"Recovering auto save file:\n"
1607 " Original file: '%s'\n"
1608 " Backup file: '%s'\n"
1609 " Auto save file: '%s'" ),
1610 recoveredFn.GetFullPath(), backupFn.GetFullPath(), fn );
1612 if( !wxFileExists( fn ) )
1614 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1618 else if( recoveredFn.Exists()
1619 && !wxCopyFile( recoveredFn.GetFullPath(), backupFn.GetFullPath() ) )
1621 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1624 else if( !wxRenameFile( fn, recoveredFn.GetFullPath() ) )
1626 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1630 if( !unrecoveredFiles.IsEmpty() )
1632 msg =
_(
"The following automatically saved file(s) could not be restored\n" );
1634 for(
size_t i = 0; i < unrecoveredFiles.GetCount(); i++ )
1635 msg += unrecoveredFiles[i] + wxS(
"\n" );
1637 msg +=
_(
"Manual recovery will be required to restore the file(s) above." );
1638 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
1642 wxArrayString unremovedFiles;
1643 removeFile( aFileName.GetFullPath(), unremovedFiles );
1645 if( !unremovedFiles.IsEmpty() )
1647 msg.Printf(
_(
"The autosave file '%s' could not be removed.\n"
1648 "Manual removal will be required." ),
1649 unremovedFiles[0] );
1651 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
this );
1663 if( !
Pgm().IsGUI() )
1666 wxCHECK_RET( aFileName.IsOk(), wxS(
"Invalid file name!" ) );
1668 if( !aFileName.FileExists() )
1671 wxTextFile fileList( aFileName.GetFullPath() );
1672 wxArrayString unremovedFiles;
1674 for( wxString fn = fileList.GetFirstLine(); !fileList.Eof(); fn = fileList.GetNextLine() )
1677 removeFile( aFileName.GetFullPath(), unremovedFiles );
1679 if( !unremovedFiles.IsEmpty() )
1681 wxString msg =
_(
"The following automatically saved file(s) could not be removed\n" );
1683 for(
size_t i = 0; i < unremovedFiles.GetCount(); i++ )
1684 msg += unremovedFiles[i] + wxS(
"\n" );
1686 msg +=
_(
"Manual removal will be required for the file(s) above." );
1687 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
this );
1694 static wxString autoSaveFileName( wxS(
"#auto_saved_files#" ) );
1696 return autoSaveFileName;
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static TOOL_ACTION zoomFitScreen
bool IsContentModified() const
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)
Class DIALOG_HTML_REPORTER.
WX_HTML_REPORT_BOX * m_Reporter
static std::vector< IMPORT_PROJECT_DESC > RunModal(wxWindow *aParent, const std::vector< IMPORT_PROJECT_DESC > &aProjectDesc)
Create and show a dialog (modal) and returns the data from it after completion.
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
void LoadWindowState(const wxString &aFileName)
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
SETTINGS_MANAGER * GetSettingsManager() const
void UpdateFileHistory(const wxString &FullFileName, FILE_HISTORY *aFileHistory=nullptr)
Update the list of recently opened files.
wxString GetMruPath() const
bool IsWritable(const wxFileName &aFileName, bool aVerbose=true)
Check if aFileName can be written.
std::unique_ptr< LOCKFILE > m_file_checker
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void RefreshCanvas() override
bool LockFile(const wxString &aFileName)
Mark a schematic file as being in use.
A base class for most all the KiCad significant classes used in schematics and boards.
EE_TYPE OfType(KICAD_T aType) const
bool GetCreateNewProject() const
Gets if this hook has attached controls to a dialog box.
bool IsAttachedToDialog() const
bool GetShowIssues() const
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 const wxString Problem() const
what was the problem?
APP_SETTINGS_BASE * KifaceSettings() const
bool IsSingle() const
Is this KIFACE running under single_top?
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
static REPORTER & GetInstance()
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
A small class to help profiling.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
Plugin class for import plugins that support choosing a project.
std::vector< FILE_INFO_PAIR > & GetSheets()
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
static SYMBOL_LIBS * SchLibs(PROJECT *aProject)
These are all prefaced with "Sch".
virtual void SetReadOnly(bool aReadOnly=true)
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual void SetElem(PROJECT::ELEM aIndex, _ELEM *aElem)
virtual PROJECT_FILE & GetProjectFile() const
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 Reset()
Initialize this schematic to a blank one, unloading anything existing.
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
void FixupJunctions()
Add junctions to this schematic where required.
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
void SetProject(PROJECT *aPrj)
CONNECTION_GRAPH * ConnectionGraph() const
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SyncView()
Mark all items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
Class for a bus to bus entry.
VECTOR2I GetPosition() const override
void DisplaySheet(SCH_SCREEN *aScreen)
Handle actions specific to the schematic editor.
bool IsContentModified() const override
Get if the current schematic has been modified but not saved.
const wxString & getAutoSaveFileName() const
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
void SaveProjectLocalSettings() override
Save changes to the project settings to the project (.pro) file.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetScreen(BASE_SCREEN *aScreen) override
bool AskToSaveChanges()
Check if any of the screens has unsaved changes and asks the user whether to save or drop them.
bool doAutoSave() override
Save the schematic files that have been modified and not yet saved.
std::vector< wxEvtHandler * > m_schematicChangeListeners
SCH_SHEET_PATH & GetCurrentSheet() const
SCHEMATIC & Schematic() const
void updateTitle()
Set the main window title bar text.
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath)
Save aSheet to a schematic file.
bool LoadProjectSettings()
Load the KiCad project file (*.pro) settings specific to Eeschema.
void RecomputeIntersheetRefs()
Update the schematic's page reference map for all global labels, and refresh the labels so that they ...
bool updateAutoSaveFile()
void UpdateHierarchyNavigator(bool aRefreshNetNavigator=true, bool aClear=false)
Update the hierarchy navigation tree and history.
bool importFile(const wxString &aFileName, int aFileType, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load the given filename but sets the path to the current project path.
void LoadDrawingSheet()
Load the drawing sheet file.
virtual void DeleteAutoSaveFile(const wxFileName &aFileName) override
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void ClearRepeatItemsList()
Clear the list of items which are to be repeated with the insert key.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
void OnImportProject(wxCommandEvent &event)
virtual void CheckForAutoSaveFile(const wxFileName &aFileName) override
This overloaded version checks if the auto save master file "#auto_saved_files#" exists and recovers ...
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
wxString GetCurrentFileName() const override
Get the full filename + path of the currently opened file in the frame.
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
void saveProjectSettings() override
Save any design-related project settings associated with this frame.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath, int aCtl=0)
Return a plugin type given a schematic using the file extension of aSchematicPath.
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 UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
void PruneOrphanedSheetInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
void BuildClientSheetPathList()
Build the list of sheet paths sharing a screen for each screen in use.
bool HasSymbolFieldNamesWithWhiteSpace() const
void PruneOrphanedSymbolInstances(const wxString &aProjectName, const SCH_SHEET_LIST &aValidSheetPaths)
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
SCH_SHEET * GetSheet(unsigned int aIndex) const
int ReplaceDuplicateTimeStamps()
Test all sheet and symbol objects in the schematic for duplicate time stamps and replaces them as nec...
void ClearDrawingState()
Clear the state flags of all the items in the screen.
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Return the number of times this screen is used.
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr) const
Test all of the connectable objects in the schematic for unused connection points.
EE_RTREE & Items()
Get the full RTree, usually for iterating.
const wxString & GetFileName() const
const KIID & GetUuid() const
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
int GetFileFormatVersionAtLoad() const
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 SetInitialPageNumbers()
Set initial sheet page numbers.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
bool IsModified() const
Check the entire hierarchy for any modifications.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
void CheckForMissingSymbolInstances(const wxString &aProjectName)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetFileName(const wxString &aFilename)
wxString GetFileName() const
Return the filename corresponding to this sheet.
void SetName(const wxString &aName)
SCH_SCREEN * GetScreen() const
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Save a copy of the current project under the given path.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Call BackupProject() if a new backup is needed according to the current backup policy.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
A collection of SYMBOL_LIB objects.
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
static void ResolvePossibleSymlinks(wxFileName &aFilename)
void Flush()
Build the HTML messages page.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
@ OUTDATED_SAVE
OUTDATED_SAVE Messages that should be cleared on save.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
MESSAGE_TYPE GetMessageType() const
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
A wrapper for reporting to a wxString object.
const wxString & GetMessages() const
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
bool AskOverrideLock(wxWindow *aParent, const wxString &aMessage)
Display a dialog indicating the file is already open, with an option to reset the lock.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
static bool empty(const wxTextEntryBase *aCtrl)
void removeFile(const wxString &aFilename, wxArrayString &aUnremoved)
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static const std::string BackupFileSuffix
static const std::string AutoSaveFilePrefix
static wxString KiCadSchematicFileWildcard()
const wxChar *const traceAutoSave
Flag to enable auto save feature debug tracing.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
Common command IDs shared by more than one of the KiCad applications.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define KICTL_CREATE
caller thinks requested project files may not exist.
#define KICTL_REVERT
reverting to a previously-saved (KiCad) file.
#define KICTL_KICAD_ONLY
chosen file is from KiCad according to user
PGM_BASE & Pgm()
The global program "get" accessor.
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
bool show_import_issues
Stored value for "show import issues" when importing non-KiCad designs to this application.
bool show_illegal_symbol_lib_dialog
Container that describes file type info.
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
bool m_CanRead
Whether the IO can read this file type.
wxString FileFilter() const
Definition for symbol library class.
wxLogTrace helper definitions.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
Definition of file extensions used in Kicad.