63#include <wx/filedlg.h>
65#include <wx/stdpaths.h>
72#if wxCHECK_VERSION( 3, 1, 7 )
73#include "widgets/filedlg_hook_save_project.h"
75#include "widgets/legacyfiledlg_save_project.h"
86 if( aFileSet.size() != 1 )
88 msg.Printf(
"Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
93 wxString fullFileName( aFileSet[0] );
94 wxFileName wx_filename( fullFileName );
97 wxASSERT_MSG( wx_filename.IsAbsolute(), wxT(
"Path is not absolute!" ) );
101 msg.Printf(
_(
"Schematic '%s' is already open." ), wx_filename.GetFullName() );
114 wxFileName pro = fullFileName;
117 bool is_new = !wxFileName::IsFileReadable( fullFileName );
123 msg.Printf(
_(
"Schematic '%s' does not exist. Do you wish to create it?" ),
126 if( !
IsOK(
this, msg ) )
138 SetStatusText( wxEmptyString );
142 :
_(
"Loading Schematic" ), 1 );
146 if( differentProject )
148 if( !
Prj().IsNullProject() )
156 wxFileName legacyPro( pro );
161 if( !pro.Exists() && !legacyPro.Exists() && !( aCtl &
KICTL_CREATE ) )
169 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
192 Prj().SchSymbolLibTable();
199 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
217 wxFileName autoSaveFn = fullFileName;
220 autoSaveFn.ClearExt();
226 SCH_PLUGIN* plugin = SCH_IO_MGR::FindPlugin( schFileType );
231 bool failedLoad =
false;
243 "occurred attempting to load hierarchical sheets." ),
249 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName);
250 progressReporter.Hide();
257 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName);
258 progressReporter.Hide();
263 catch(
const std::bad_alloc& )
265 msg.Printf(
_(
"Memory exhausted loading schematic '%s'." ), fullFileName );
266 progressReporter.Hide();
284 msg.Printf(
_(
"Failed to load '%s'." ), fullFileName );
297 _(
"An error was found when loading the schematic that has "
298 "been automatically fixed. Please save the schematic to "
299 "repair the broken file or it may not be usable with other "
300 "versions of KiCad." ) );
311 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
316 std::vector<SCH_ITEM*> deleted;
318 for(
SCH_ITEM* item : screen->Items() )
323 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
327 wire->SetEndPoint( entry->
GetEnd() );
329 screen->Append( wire.release() );
330 deleted.push_back( item );
335 screen->Remove( item );
351 wxArrayString libNames;
355 if( !libNames.IsEmpty() )
357 if(
eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
359 wxRichMessageDialog invalidLibDlg(
361 _(
"Illegal entry found in project file symbol library list." ),
362 _(
"Project Load Warning" ),
363 wxOK | wxCENTER | wxICON_EXCLAMATION );
364 invalidLibDlg.ShowDetailedText(
365 _(
"Symbol libraries defined in the project file symbol library "
366 "list are no longer supported and will be removed.\n\n"
367 "This may cause broken symbol library links under certain "
369 invalidLibDlg.ShowCheckBox(
_(
"Do not show this dialog again." ) );
370 invalidLibDlg.ShowModal();
372 !invalidLibDlg.IsCheckBoxChecked();
383 editor->RescueSymbolLibTableProject(
false );
393 wxFileName cacheFn = pro;
395 cacheFn.SetName( cacheFn.GetName() +
"-cache" );
398 msg.Printf(
_(
"The project symbol library cache file '%s' was not found." ),
399 cacheFn.GetFullName() );
400 extMsg =
_(
"This can result in a broken schematic under certain conditions. "
401 "If the schematic does not have any missing symbols upon opening, "
402 "save it immediately before making any changes to prevent data "
403 "loss. If there are missing symbols, either manual recovery of "
404 "the schematic or recovery of the symbol cache library file and "
405 "reloading the schematic is required." );
407 wxMessageDialog dlgMissingCache(
this, msg,
_(
"Warning" ),
408 wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
409 dlgMissingCache.SetExtendedMessage( extMsg );
410 dlgMissingCache.SetOKCancelLabels(
411 wxMessageDialog::ButtonLabel(
_(
"Load Without Cache File" ) ),
412 wxMessageDialog::ButtonLabel(
_(
"Abort" ) ) );
414 if( dlgMissingCache.ShowModal() == wxID_CANCEL )
428 "It will be converted to the new format when saved." ),
436 screen->FixLegacyPowerSymbolMismatches();
448 "It will be converted to the new format when saved." ),
453 screen->UpdateLocalLibSymbolLinks();
456 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221002 )
459 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221110 )
462 if(
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
464 screen->FixLegacyPowerSymbolMismatches();
467 screen->MigrateSimModels();
476 if(
Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
504 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
518 if( fn.FileExists() && !fn.IsFileWritable() )
540 wxLogError( wxT(
"Document not ready, cannot import" ) );
545 wxString
path = wxPathOnly(
Prj().GetProjectFullName() );
547 wxFileDialog dlg(
this,
_(
"Insert Schematic" ),
path, wxEmptyString,
550 if( dlg.ShowModal() == wxID_CANCEL )
579 wxString msg =
_(
"This operation cannot be undone.\n\n"
580 "Do you want to save the current document before proceeding?" );
582 if(
IsOK(
this, msg ) )
597 wxString
path = wxPathOnly(
Prj().GetProjectFullName() );
599 std::list<std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>> loaders;
610 wxString fileFilters;
611 wxString allWildcards;
613 for( std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>& loader : loaders )
615 if( !fileFilters.IsEmpty() )
616 fileFilters += wxChar(
'|' );
618 fileFilters += wxGetTranslation( loader.first );
625 fileFilters =
_(
"All supported formats" ) + wxS(
"|" ) + allWildcards + wxS(
"|" ) +
628 wxFileDialog dlg(
this,
_(
"Import Schematic" ),
path, wxEmptyString, fileFilters,
629 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
631 if( dlg.ShowModal() == wxID_CANCEL )
645 wxFileName projectFn( dlg.GetPath() );
652 wxFileName fn = dlg.GetPath();
654 SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
656 for( std::pair<const wxString, const SCH_IO_MGR::SCH_FILE_T>& loader : loaders )
660 pluginType = loader.second;
665 if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
667 wxLogError(
_(
"Unexpected file extension: '%s'." ), fn.GetExt() );
680 wxFileName schematicFileName;
681 wxFileName oldFileName;
686 wxCHECK( screen,
false );
689 wxCHECK( !aSavePath.IsEmpty(),
false );
693 oldFileName = schematicFileName;
701 wxString tempFile = wxFileName::CreateTempFileName( wxS(
"eeschema" ) );
704 wxLogTrace(
traceAutoSave, wxS(
"Saving file " ) + schematicFileName.GetFullPath() );
710 schematicFileName.GetFullPath() );
720 msg.Printf(
_(
"Error saving schematic file '%s'.\n%s" ),
721 schematicFileName.GetFullPath(),
725 msg.Printf(
_(
"Failed to create temporary file '%s'." ),
730 wxRemoveFile( tempFile );
738 success = wxRenameFile( tempFile, schematicFileName.GetFullPath() );
742 msg.Printf(
_(
"Error saving schematic file '%s'.\n"
743 "Failed to rename temporary file '%s'." ),
744 schematicFileName.GetFullPath(),
748 msg.Printf(
_(
"Failed to rename temporary file '%s'." ),
757 wxFileName autoSaveFileName = schematicFileName;
760 if( autoSaveFileName.FileExists() )
763 wxT(
"Removing auto save file <" ) + autoSaveFileName.GetFullPath() +
766 wxRemoveFile( autoSaveFileName.GetFullPath() );
771 msg.Printf(
_(
"File '%s' saved." ), screen->
GetFileName() );
772 SetStatusText( msg, 0 );
790 bool updateFileHistory =
false;
791 bool createNewProject =
false;
795 wxFileName fn = fileName;
799 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
802 if(
Prj().IsNullProject() || aSaveAs )
805 wxCHECK(
Kiface().IsSingle() || aSaveAs,
false );
807 wxFileName newFileName;
808 wxFileName savePath(
Prj().GetProjectFullName() );
810 if( !savePath.IsOk() || !savePath.IsDirWritable() )
814 if( !savePath.IsOk() || !savePath.IsDirWritable() )
818 if( savePath.HasExt() )
821 savePath.SetName( wxEmptyString );
823 wxFileDialog dlg(
this,
_(
"Schematic Files" ), savePath.GetPath(),
825 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
827#if wxCHECK_VERSION( 3, 1, 7 )
832 if(
Kiface().IsSingle() || aSaveAs )
834#if wxCHECK_VERSION( 3, 1, 7 )
835 dlg.SetCustomizeHook( newProjectHook );
841 if( dlg.ShowModal() == wxID_CANCEL )
844 newFileName = dlg.GetPath();
847 if( ( !newFileName.DirExists() && !newFileName.Mkdir() ) ||
848 !newFileName.IsDirWritable() )
850 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
851 "Make sure you have write permissions and try again." ),
852 newFileName.GetPath() );
854 wxMessageDialog dlgBadPath(
this, msg,
_(
"Error" ),
855 wxOK | wxICON_EXCLAMATION | wxCENTER );
857 dlgBadPath.ShowModal();
861#if wxCHECK_VERSION( 3, 1, 7 )
865 if( wxWindow* ec = dlg.GetExtraControl() )
873 updateFileHistory =
true;
881 for(
size_t i = 0; i < screens.
GetCount(); i++ )
885 wxCHECK2( screen,
continue );
896 if( tmp.FileExists() )
899 if( tmp.GetPath().IsEmpty() )
901 tmp.SetPath( newFileName.GetPath() );
903 else if( tmp.GetPath() == fn.GetPath() )
905 tmp.SetPath( newFileName.GetPath() );
907 else if( tmp.GetPath().StartsWith( fn.GetPath() ) )
911 wxString newPath = newFileName.GetPath();
912 newPath += tmp.GetPath().Right( fn.GetPath().Length() );
913 tmp.SetPath( newPath );
917 wxT(
"Moving schematic from '%s' to '%s'." ),
921 if( !tmp.DirExists() && !tmp.Mkdir() )
923 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
924 "Make sure you have write permissions and try again." ),
925 newFileName.GetPath() );
927 wxMessageDialog dlgBadFilePath(
this, msg,
_(
"Error" ),
928 wxOK | wxICON_EXCLAMATION | wxCENTER );
930 dlgBadFilePath.ShowModal();
935 filenameMap[screen] = tmp.GetFullPath();
945 if( sheet.Last()->IsRootSheet() )
948 sheet.MakeFilePathRelativeToParentSheet();
951 else if( !fn.FileExists() )
954 updateFileHistory =
true;
957 if( filenameMap.empty() || !saveCopy )
959 for(
size_t i = 0; i < screens.
GetCount(); i++ )
964 wxArrayString overwrittenFiles;
966 for(
size_t i = 0; i < screens.
GetCount(); i++ )
970 wxCHECK2( screen,
continue );
973 wxFileName tmpFn = filenameMap[screen];
983 if( tmpFn.FileExists() )
984 overwrittenFiles.Add( tmpFn.GetFullPath() );
987 if( !overwrittenFiles.IsEmpty() )
989 for(
const wxString& overwrittenFile : overwrittenFiles )
992 msg = overwrittenFile;
994 msg +=
"\n" + overwrittenFile;
997 wxRichMessageDialog dlg(
this,
_(
"Saving will overwrite existing files." ),
999 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER |
1000 wxICON_EXCLAMATION );
1001 dlg.ShowDetailedText(
_(
"The following files will be overwritten:\n\n" ) + msg );
1002 dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel(
_(
"Overwrite Files" ) ),
1003 wxMessageDialog::ButtonLabel(
_(
"Abort Project Save" ) ) );
1005 if( dlg.ShowModal() == wxID_CANCEL )
1011 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1015 wxCHECK2( screen,
continue );
1018 wxFileName tmpFn = filenameMap[screen];
1022 updateFileHistory =
true;
1034 sheet->
SetFileName( sheetFileName.GetFullPath() );
1038 filenameMap[screen] = tmpFn.GetFullPath();
1050 if( sheets.size() == 1 )
1056 if( !saveCopy && tmpFn.GetFullPath() != screen->
GetFileName() )
1066 if( !aSaveAs && !success )
1069 if( aSaveAs && success )
1072 if( updateFileHistory )
1083 wxCHECK2( sheet,
continue );
1090 wxCHECK2( screen,
continue );
1092 sheets.emplace_back( std::make_pair( screen->
GetUuid(), sheet->
GetName() ) );
1096 sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
1100 wxASSERT( filenameMap.count(
Schematic().RootScreen() ) );
1101 wxFileName projectPath( filenameMap.at(
Schematic().RootScreen() ) );
1104 if(
Prj().IsNullProject() || ( aSaveAs && !saveCopy ) )
1109 else if( saveCopy && createNewProject )
1119 if( !
Kiface().IsSingle() )
1124 SetStatusText( msg, 0 );
1139 wxFileName fn = tmpFileName;
1147 bool autoSaveOk =
true;
1149 if( fn.GetPath().IsEmpty() )
1150 tmp.AssignDir(
Prj().GetProjectPath() );
1152 tmp.AssignDir( fn.GetPath() );
1160 wxString title = GetTitle();
1162 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1204 wxFileName filename( aFileName );
1205 wxFileName newfilename;
1207 SCH_IO_MGR::SCH_FILE_T
fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType;
1211 case SCH_IO_MGR::SCH_ALTIUM:
1212 case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
1213 case SCH_IO_MGR::SCH_EAGLE:
1215 wxCHECK_MSG( filename.IsAbsolute(),
false,
1216 wxT(
"Import schematic: path is not absolute!" ) );
1221 msg.Printf(
_(
"Schematic '%s' is already open." ), filename.GetFullName() );
1240 errorReporter.ShowModal();
1249 newfilename.SetPath(
Prj().GetProjectPath() );
1250 newfilename.SetName(
Prj().GetProjectName() );
1280 wxString msg =
wxString::Format(
_(
"Error loading schematic '%s'." ), aFileName );
1283 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1288 catch(
const std::exception& exc )
1293 wxString msg =
wxString::Format(
_(
"Unhandled exception occurred loading schematic "
1294 "'%s'." ), aFileName );
1297 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1322 if( simFrame && !simFrame->Close() )
1325 if( screen->IsContentModified() )
1348 wxLogTrace(
traceAutoSave,
"Creating auto save file %s", autoSaveFileName.GetFullPath() );
1350 wxCHECK( autoSaveFileName.IsDirWritable(),
false );
1354 std::vector< wxString > autoSavedFiles;
1356 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1366 autoSavedFiles.emplace_back( fn.GetFullPath() );
1369 wxTextFile autoSaveFile( autoSaveFileName.GetFullPath() );
1371 if( autoSaveFileName.FileExists() && !wxRemoveFile( autoSaveFileName.GetFullPath() ) )
1373 wxLogTrace(
traceAutoSave,
"Error removing auto save file %s",
1374 autoSaveFileName.GetFullPath() );
1380 if( autoSavedFiles.empty() )
1383 if( !autoSaveFile.Create() )
1386 for(
const wxString& fileName : autoSavedFiles )
1388 wxLogTrace(
traceAutoSave,
"Adding auto save file %s to %s",
1389 fileName, autoSaveFileName.GetName() );
1390 autoSaveFile.AddLine( fileName );
1393 if( !autoSaveFile.Write() )
1396 wxLogTrace(
traceAutoSave,
"Auto save file '%s' written", autoSaveFileName.GetFullName() );
1407 wxCHECK_RET( aFileName.IsOk(), wxT(
"Invalid file name!" ) );
1410 wxT(
"Checking for auto save file " ) + aFileName.GetFullPath() );
1412 if( !aFileName.FileExists() )
1416 "Well this is potentially embarrassing!\n"
1417 "It appears that the last time you were editing one or more of the schematic files\n"
1418 "were not saved properly. Do you wish to restore the last saved edits you made?" );
1420 int response = wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
1423 wxTextFile autoSaveFile( aFileName.GetFullPath() );
1425 if( !autoSaveFile.Open() )
1427 msg.Printf(
_(
"The file '%s` could not be opened.\n"
1428 "Manual recovery of automatically saved files is required." ),
1429 aFileName.GetFullPath() );
1431 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
this );
1435 if( response == wxYES )
1437 wxArrayString unrecoveredFiles;
1439 for( wxString fn = autoSaveFile.GetFirstLine(); !autoSaveFile.Eof();
1440 fn = autoSaveFile.GetNextLine() )
1442 wxFileName recoveredFn = fn;
1443 wxString tmp = recoveredFn.GetName();
1447 recoveredFn.SetName( tmp );
1449 wxFileName backupFn = recoveredFn;
1453 wxLogTrace(
traceAutoSave, wxT(
"Recovering auto save file:\n"
1454 " Original file: '%s'\n"
1455 " Backup file: '%s'\n"
1456 " Auto save file: '%s'" ),
1457 recoveredFn.GetFullPath(), backupFn.GetFullPath(), fn );
1459 if( !wxFileExists( fn ) )
1461 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1465 else if( !wxCopyFile( recoveredFn.GetFullPath(), backupFn.GetFullPath() ) )
1467 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1470 else if( !wxRenameFile( fn, recoveredFn.GetFullPath() ) )
1472 unrecoveredFiles.Add( recoveredFn.GetFullPath() );
1476 if( !unrecoveredFiles.IsEmpty() )
1478 msg =
_(
"The following automatically saved file(s) could not be restored\n" );
1480 for(
size_t i = 0; i < unrecoveredFiles.GetCount(); i++ )
1481 msg += unrecoveredFiles[i] + wxT(
"\n" );
1483 msg +=
_(
"Manual recovery will be required to restore the file(s) above." );
1484 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
1490 wxArrayString unremovedFiles;
1492 for( wxString fn = autoSaveFile.GetFirstLine(); !autoSaveFile.Eof();
1493 fn = autoSaveFile.GetNextLine() )
1495 wxLogTrace(
traceAutoSave, wxT(
"Removing auto save file " ) + fn );
1497 if( wxFileExists( fn ) && !wxRemoveFile( fn ) )
1498 unremovedFiles.Add( fn );
1501 if( !unremovedFiles.IsEmpty() )
1503 msg =
_(
"The following automatically saved file(s) could not be removed\n" );
1505 for(
size_t i = 0; i < unremovedFiles.GetCount(); i++ )
1506 msg += unremovedFiles[i] + wxT(
"\n" );
1508 msg +=
_(
"Manual removal will be required for the file(s) above." );
1509 wxMessageBox( msg,
Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION,
1515 wxLogTrace(
traceAutoSave, wxT(
"Removing auto save file '%s'" ), aFileName.GetFullPath() );
1517 if( !wxRemoveFile( aFileName.GetFullPath() ) )
1519 msg.Printf(
_(
"The automatic save master file\n"
1521 "could not be deleted." ), aFileName.GetFullPath() );
1523 wxMessageDialog dlg(
this, msg,
Pgm().App().GetAppDisplayName(),
1524 wxOK | wxICON_EXCLAMATION | wxCENTER );
1526 dlg.SetExtendedMessage(
1527 _(
"This file must be manually removed or the auto save feature will be\n"
1528 "shown every time the schematic editor is launched." ) );
1537 static wxString autoSaveFileName( wxT(
"#auto_saved_files#" ) );
1539 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
Handle the graphic items list to draw/plot the frame and title block.
static DS_DATA_MODEL & GetTheInstance()
static function: returns 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)
Checks if aFileName can be written.
static wxString GetAutoSaveFilePrefix()
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
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?
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
< Helper widget to select whether a new project should be created for a file when saving
static wxWindow * Create(wxWindow *aParent)
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.
std::vector< FILE_INFO_PAIR > & GetSheets()
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
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
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.
CONNECTION_GRAPH * ConnectionGraph() const override
void FixupJunctions()
Add junctions to this schematic where required.
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
void SetProject(PROJECT *aPrj)
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
void SyncView()
Mark all items for refresh.
EESCHEMA_SETTINGS * eeconfig() const
Class for a bus to bus entry.
VECTOR2I GetPosition() const override
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
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
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.
void RecordERCExclusions()
Scan existing markers and record data from any that are Excluded.
void HardRedraw() override
Rebuild the GAL and redraw the screen.
void OnAppendProject(wxCommandEvent &event)
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 RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
bool importFile(const wxString &aFileName, int aFileType)
Load the given filename but sets the path to the current project path.
bool AddSheetAndUpdateDisplay(const wxString aFullFileName)
Add a sheet file into the current sheet and updates display.
void initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
void OnImportProject(wxCommandEvent &event)
void ResolveERCExclusions()
Update markers to match recorded exclusions.
bool AppendSchematic()
Import a KiCad schematic into the current sheet.
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.
void UpdateHierarchyNavigator()
Update the hierarchy navigation tree and history.
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.
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath)
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,...
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Base class that schematic file and library loading and saving plugins should derive from.
virtual const wxString & GetError() const
Return an error string to the caller.
virtual void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
virtual const wxString GetFileExtension() const =0
Return the file extension for the SCH_PLUGIN.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
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 BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
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()
Gets 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.
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.
SCH_SCREEN * GetScreen() const
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Sets the currently loaded project path and saves it (pointers remain valid) Note that this will not m...
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Saves a copy of the current project under the given path.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls 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 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.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
bool OverrideLock(wxWindow *aParent, const wxString &aMessage)
Display a dialog indicating the file is already open, with an option to reset the lock.
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.
bool IsGUI()
Determine if the application is running with a GUI.
This file is part of the common library.
const std::string BackupFileSuffix
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
const std::string LegacyProjectFileExtension
const std::string ProjectFileExtension
const std::string KiCadSchematicFileExtension
const std::string LegacySymbolLibFileExtension
wxString KiCadSchematicFileWildcard()
wxString CadstarSchematicArchiveFileWildcard()
wxString AltiumSchematicFileWildcard()
wxString EagleSchematicFileWildcard()
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.
#define KICTL_CREATE
caller thinks requested project files may not exist.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
bool show_illegal_symbol_lib_dialog
Definition for symbol library class.
wxLogTrace helper definitions.
Definition of file extensions used in Kicad.