81#include <wx/filedlg.h>
83#include <wx/richmsgdlg.h>
84#include <wx/stdpaths.h>
116 if( listed.IsFileReadable() )
118 file = listed.GetFullPath();
134 screen->SetContentModified(
false );
146 wxMessageDialog dlg(
this, aMessage, aTitle, wxYES_NO | wxNO_DEFAULT | wxICON_WARNING | wxCENTER );
147 dlg.SetYesNoLabels(
_(
"&Reload" ),
_(
"&Keep My Edits" ) );
149 return dlg.ShowModal() == wxID_YES;
182 if( aFileSet.size() != 1 )
184 msg.Printf(
"Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
189 wxString fullFileName( aFileSet[0] );
190 wxFileName wx_filename( fullFileName );
193 wxASSERT_MSG( wx_filename.IsAbsolute(), wxS(
"Path is not absolute!" ) );
198 if(
Prj().IsLockOverrideGranted() )
204 msg.Printf(
_(
"Schematic '%s' is already open by '%s' at '%s'." ), fullFileName,
221 wxFileName pro = fullFileName;
224 bool is_new = !wxFileName::IsFileReadable( fullFileName );
230 msg.Printf(
_(
"Schematic '%s' does not exist. Do you wish to create it?" ), fullFileName );
232 if( !
IsOK(
this, msg ) )
236 wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGING );
237 ProcessEventLocally( e );
247 SetStatusText( wxEmptyString );
251 statusBar->ClearWarningMessages(
"load" );
262 if( differentProject )
264 if( !
Prj().IsNullProject() )
276 wxFileName legacyPro( pro );
281 if( !pro.Exists() && !legacyPro.Exists() && !( aCtl &
KICTL_CREATE ) )
291 std::unique_ptr<SCHEMATIC> newSchematic = std::make_unique<SCHEMATIC>( &
Prj() );
295 bool isNonKicadImport = schFileType != SCH_IO_MGR::SCH_KICAD
296 && schFileType != SCH_IO_MGR::SCH_LEGACY
297 && schFileType != SCH_IO_MGR::SCH_FILE_UNKNOWN;
303 if( isNonKicadImport )
305 progressReporter.Hide();
306 return importFile( fullFileName, schFileType,
nullptr );
309 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
330 wxFileName rfn( fullFileName );
331 rfn.MakeRelativeTo(
Prj().GetProjectPath() );
341 if( is_new || schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
343 newSchematic->CreateDefaultScreens();
350 if( schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
354 msg.Printf(
_(
"'%s' is not a KiCad schematic file.\n"
355 "Use File -> Import for non-KiCad schematic files." ), fullFileName );
360 msg.Printf(
_(
"'%s' is not a recognised schematic format." ), fullFileName );
363 progressReporter.Hide();
373 pi->SetProgressReporter( &progressReporter );
375 bool failedLoad =
false;
385 const std::vector<TOP_LEVEL_SHEET_INFO>& topLevelSheets = projectFile.
GetTopLevelSheets();
387 if( !topLevelSheets.empty() )
389 std::vector<SCH_SHEET*> loadedSheets;
395 schFileType == SCH_IO_MGR::SCH_LEGACY )
398 if( !wxFileName::FileExists( sheetPath ) )
400 wxLogWarning( wxT(
"Top-level sheet file not found: %s" ), sheetPath );
404 SCH_SHEET* sheet = pi->LoadSchematicFile( sheetPath, newSchematic.get() );
410 if( sheetInfo.uuid !=
niluuid )
412 const_cast<KIID&
>( sheet->
m_Uuid ) = sheetInfo.uuid;
415 sheet->
SetName( sheetInfo.name );
416 loadedSheets.push_back( sheet );
418 wxLogTrace(
tracePathsAndFiles, wxS(
"Loaded top-level sheet '%s' (UUID %s) from %s" ),
423 if( !loadedSheets.empty() )
425 newSchematic->SetTopLevelSheets( loadedSheets );
430 wxS(
"Loaded multi-root schematic with no top-level sheets!" ) );
431 newSchematic->CreateDefaultScreens();
437 SCH_SHEET* rootSheet = pi->LoadSchematicFile( fullFileName, newSchematic.get() );
441 newSchematic->SetTopLevelSheets( { rootSheet } );
445 if(
SCH_SHEET* topSheet = newSchematic->GetTopLevelSheet() )
446 topSheet->SetName(
_(
"Root" ) );
451 wxS(
"After loading: Current sheet path='%s', size=%zu, empty=%d" ),
452 newSchematic->CurrentSheet().Path().AsString(),
453 newSchematic->CurrentSheet().size(),
454 newSchematic->CurrentSheet().empty() ? 1 : 0 );
458 newSchematic->CreateDefaultScreens();
464 if( !pi->GetError().IsEmpty() )
467 "occurred attempting to load hierarchical sheets." ),
473 newSchematic->CreateDefaultScreens();
474 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName );
475 progressReporter.Hide();
482 newSchematic->CreateDefaultScreens();
483 msg.Printf(
_(
"Error loading schematic '%s'." ), fullFileName );
484 progressReporter.Hide();
489 catch(
const std::bad_alloc& )
491 newSchematic->CreateDefaultScreens();
492 msg.Printf(
_(
"Memory exhausted loading schematic '%s'." ), fullFileName );
493 progressReporter.Hide();
515 statusBar->AddWarningMessages(
"load", loadReporter.
GetMessages() );
517 msg.Printf(
_(
"Failed to load '%s'." ), fullFileName );
529 bool repairedPageNumbers =
false;
539 if( sheetList.
IsModified() || repairedPageNumbers )
541 DisplayInfoMessage(
this,
_(
"An error was found when loading the schematic that has been "
542 "automatically fixed. Please save the schematic to repair the "
543 "broken file or it may not be usable with other versions of "
550 statusBar->AddWarningMessages(
"load", loadReporter.
GetMessages() );
555 if( schFileType == SCH_IO_MGR::SCH_LEGACY )
560 std::vector<SCH_ITEM*> deleted;
562 for(
SCH_ITEM* item : screen->Items() )
567 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
571 wire->SetEndPoint( entry->
GetEnd() );
573 screen->Append( wire.release() );
574 deleted.push_back( item );
579 screen->Remove( item );
595 wxArrayString libNames;
599 if( !libNames.IsEmpty() )
601 if(
eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
603 wxRichMessageDialog dlg(
this,
604 _(
"Illegal entry found in project file symbol library list." ),
605 _(
"Project Load Warning" ),
606 wxOK | wxCENTER | wxICON_EXCLAMATION );
607 dlg.ShowDetailedText(
_(
"Symbol libraries defined in the project file symbol library "
608 "list are no longer supported and will be removed.\n\n"
609 "This may cause broken symbol library links under certain "
611 dlg.ShowCheckBox(
_(
"Do not show this dialog again." ) );
622 wxFileName cacheFn( fullFileName );
623 cacheFn.SetName( cacheFn.GetName() +
"-cache" );
625 bool cacheExists = cacheFn.FileExists();
636 if( !(*table)->HasRow( nickname ) )
640 row.
SetURI( cacheFn.GetFullPath() );
646 std::vector<KI_ERROR> libErrors;
651 statusBar->AddWarningMessages(
"load", libErrors );
658 editor->RescueSymbolLibTableProject(
false );
667 wxFileName cacheFn = pro;
669 wxLogTrace(
traceAutoSave,
"[SetName dbg] cacheFn BEFORE path='%s' name='%s' full='%s' arg='%s'",
670 cacheFn.GetPath(), cacheFn.GetName(), cacheFn.GetFullPath(), cacheFn.GetName() +
"-cache" );
671 cacheFn.SetName( cacheFn.GetName() +
"-cache" );
672 wxLogTrace(
traceAutoSave,
"[SetName dbg] cacheFn AFTER path='%s' name='%s' full='%s'",
673 cacheFn.GetPath(), cacheFn.GetName(), cacheFn.GetFullPath() );
676 msg.Printf(
_(
"The project symbol library cache file '%s' was not found." ), cacheFn.GetFullName() );
678 KICAD_MESSAGE_DIALOG dlg(
this, msg,
_(
"Warning" ), wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
679 dlg.SetExtendedMessage(
_(
"This can result in a broken schematic under certain conditions. If the "
680 "schematic does not have any missing symbols upon opening, save it "
681 "immediately before making any changes to prevent data loss. If there "
682 "are missing symbols, either manual recovery of the schematic or "
683 "recovery of the symbol cache library file and reloading the schematic is "
685 dlg.SetOKCancelLabels( KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Load Without Cache File" ) ),
686 KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Abort" ) ) );
688 if( dlg.ShowModal() == wxID_CANCEL )
701 m_infoBar->ShowMessage(
_(
"This file was created by an older version of KiCad. "
702 "It will be converted to the new format when saved." ),
703 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
710 screen->FixLegacyPowerSymbolMismatches();
721 first_screen = schematic.
GetNext();
727 m_infoBar->ShowMessage(
_(
"This file was created by an older version of KiCad. "
728 "It will be converted to the new format when saved." ),
729 wxICON_WARNING, WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
747 screen->FixLegacyPowerSymbolMismatches();
750 screen->MigrateSimModels();
761 wxLogTrace(
traceSchCurrentSheet,
"Before CheckForMissingSymbolInstances: Current sheet path='%s', size=%zu",
777 if( repairedPageNumbers )
785 const bool nativeNeedsFixup = schFileType == SCH_IO_MGR::SCH_KICAD
791 if( schFileType == SCH_IO_MGR::SCH_LEGACY || nativeNeedsFixup )
796 progressReporter.
Report(
_(
"Updating connections..." ) );
809 schFileVersion,
Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() ) )
811 progressReporter.Hide();
821 progressReporter.Show();
825 dummy.Push(
_(
"Schematic Cleanup" ),
831 m_infoBar->QueueShowMessage(
_(
"This schematic contains symbols that have leading "
832 "and/or trailing white space field names." ),
859 wxCommandEvent changedEvt( EDA_EVT_SCHEMATIC_CHANGED );
860 ProcessEventLocally( changedEvt );
862 if( !differentProject )
873 wxCHECK2( listener,
continue );
877 wxWindow* win =
dynamic_cast<wxWindow*
>( listener );
880 win->HandleWindowEvent( e );
882 listener->SafelyProcessEvent( e );
891 if( fn.FileExists() && !fn.IsFileWritable() )
895 m_infoBar->ShowMessage(
_(
"Schematic is read only." ), wxICON_WARNING,
896 WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE );
929 wxString msg =
_(
"This operation replaces the contents of the current schematic, "
930 "which will be permanently lost.\n\n"
931 "Do you want to proceed?" );
933 if( !
IsOK(
this, msg ) )
939 wxString
path = wxPathOnly(
Prj().GetProjectFullName() );
941 wxString fileFiltersStr;
942 wxString allWildcardsStr;
944 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
946 if(
fileType == SCH_IO_MGR::SCH_KICAD ||
fileType == SCH_IO_MGR::SCH_LEGACY )
959 if( !fileFiltersStr.IsEmpty() )
960 fileFiltersStr += wxChar(
'|' );
968 fileFiltersStr =
_(
"All supported formats" ) + wxS(
"|" ) + allWildcardsStr + wxS(
"|" ) + fileFiltersStr;
970 wxFileDialog dlg(
this,
_(
"Import Schematic" ),
path, wxEmptyString, fileFiltersStr,
971 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
974 dlg.SetCustomizeHook( importOptions );
978 if( dlg.ShowModal() == wxID_CANCEL )
998 wxFileName projectFn( dlg.GetPath() );
1003 wxFileName fn = dlg.GetPath();
1005 if( !fn.IsFileReadable() )
1007 wxLogError(
_(
"Insufficient permissions to read file '%s'." ), fn.GetFullPath() );
1011 SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
1013 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
1020 if( pi->CanReadSchematicFile( fn.GetFullPath() ) )
1027 if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
1029 wxLogError(
_(
"No loader can read the specified file: '%s'." ), fn.GetFullPath() );
1044 wxFileName schematicFileName;
1045 wxFileName oldFileName;
1050 wxCHECK( screen,
false );
1053 if( aSavePath.IsEmpty() )
1058 oldFileName = schematicFileName;
1063 if( !schematicFileName.DirExists() )
1065 if( !wxMkdir( schematicFileName.GetPath() ) )
1067 msg.Printf(
_(
"Error saving schematic file '%s'.\n%s" ),
1068 schematicFileName.GetFullPath(),
1069 "Could not create directory: %s" + schematicFileName.GetPath() );
1079 wxFileName projectFile( schematicFileName );
1083 if( projectFile.FileExists() )
1091 wxLogTrace(
traceAutoSave, wxS(
"Saving file " ) + schematicFileName.GetFullPath() );
1093 if(
m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
1098 if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
1099 pluginType = SCH_IO_MGR::SCH_KICAD;
1105 if( schematicFileName.FileExists() )
1110 pi->SaveSchematicFile( schematicFileName.GetFullPath(), aSheet, &
Schematic() );
1115 msg.Printf(
_(
"Error saving schematic file '%s'.\n%s" ),
1116 schematicFileName.GetFullPath(),
1128 msg.Printf(
_(
"File '%s' saved." ), screen->
GetFileName() );
1129 SetStatusText( msg, 0 );
1137 const wxFileName& aNewRoot,
bool aSaveCopy,
bool aCopySubsheets,
bool aIncludeExternSheets,
1138 std::unordered_map<SCH_SCREEN*, wxString>& aFilenameMap, wxString& aErrorMsg )
1142 for(
size_t i = 0; i < aScreens.
GetCount(); i++ )
1146 wxCHECK2( screen,
continue );
1158 if( !src.IsAbsolute() )
1159 src.MakeAbsolute( aOldRoot.GetPath() );
1161 bool internalSheet = src.GetPath().StartsWith( aOldRoot.GetPath() );
1163 if( aCopySubsheets && ( internalSheet || aIncludeExternSheets ) )
1165 wxFileName dest = src;
1167 if( internalSheet && dest.MakeRelativeTo( aOldRoot.GetPath() ) )
1168 dest.MakeAbsolute( aNewRoot.GetPath() );
1170 dest.Assign( aNewRoot.GetPath(), dest.GetFullName() );
1175 if( !dest.DirExists() && !dest.Mkdir() )
1177 aErrorMsg.Printf(
_(
"Folder '%s' could not be created.\n\n"
1178 "Make sure you have write permissions and try again." ),
1184 aFilenameMap[screen] = dest.GetFullPath();
1191 aFilenameMap[screen] = wxString();
1199 if( !sheet.Last()->IsTopLevelSheet() )
1200 sheet.MakeFilePathRelativeToParentSheet();
1212 bool success =
true;
1213 bool updateFileHistory =
false;
1214 bool createNewProject =
false;
1215 bool copySubsheets =
false;
1216 bool includeExternSheets =
false;
1220 wxFileName fn = fileName;
1224 std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
1227 if(
Prj().IsNullProject() || aSaveAs )
1230 wxCHECK(
Kiface().IsSingle() || aSaveAs,
false );
1232 wxFileName newFileName;
1233 wxFileName savePath(
Prj().GetProjectFullName() );
1235 if( !savePath.IsOk() || !savePath.IsDirWritable() )
1239 if( !savePath.IsOk() || !savePath.IsDirWritable() )
1243 if( savePath.HasExt() )
1246 savePath.SetName( wxEmptyString );
1248 wxFileDialog dlg(
this,
_(
"Schematic Files" ), savePath.GetPath(), savePath.GetFullName(),
1254 if(
Kiface().IsSingle() || aSaveAs )
1256 dlg.SetCustomizeHook( newProjectHook );
1261 if( dlg.ShowModal() == wxID_CANCEL )
1266 if( ( !newFileName.DirExists() && !newFileName.Mkdir() )
1267 || !newFileName.IsDirWritable() )
1269 msg.Printf(
_(
"Folder '%s' could not be created.\n\n"
1270 "Make sure you have write permissions and try again." ),
1271 newFileName.GetPath() );
1275 dlgBadPath.ShowModal();
1290 updateFileHistory =
true;
1298 filenameMap, msg ) )
1300 KICAD_MESSAGE_DIALOG dlgBadFilePath(
this, msg,
_(
"Error" ), wxOK | wxICON_EXCLAMATION | wxCENTER );
1302 dlgBadFilePath.ShowModal();
1306 else if( !fn.FileExists() )
1309 updateFileHistory =
true;
1320 if( filenameMap.empty() || !saveCopy )
1322 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1327 wxArrayString overwrittenFiles;
1328 wxArrayString lockedFiles;
1330 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1334 wxCHECK2( screen,
continue );
1337 wxFileName tmpFn = filenameMap[screen];
1342 if( tmpFn.FileExists() && !tmpFn.IsFileWritable() )
1343 lockedFiles.Add( tmpFn.GetFullPath() );
1350 if( tmpFn.FileExists() )
1351 overwrittenFiles.Add( tmpFn.GetFullPath() );
1354 if( !lockedFiles.IsEmpty() )
1356 for(
const wxString& lockedFile : lockedFiles )
1361 msg +=
"\n" + lockedFile;
1364 wxRichMessageDialog dlg(
this, wxString::Format(
_(
"Failed to save %s." ),
Schematic().Root().GetFileName() ),
1365 _(
"Locked File Warning" ), wxOK | wxICON_WARNING | wxCENTER );
1366 dlg.SetExtendedMessage(
_(
"You do not have write permissions to:\n\n" ) + msg );
1372 if( !overwrittenFiles.IsEmpty() )
1374 for(
const wxString& overwrittenFile : overwrittenFiles )
1377 msg = overwrittenFile;
1379 msg +=
"\n" + overwrittenFile;
1382 wxRichMessageDialog dlg(
this,
_(
"Saving will overwrite existing files." ),
_(
"Save Warning" ),
1383 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER | wxICON_EXCLAMATION );
1384 dlg.ShowDetailedText(
_(
"The following files will be overwritten:\n\n" ) + msg );
1385 dlg.SetOKCancelLabels( KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Overwrite Files" ) ),
1386 KICAD_MESSAGE_DIALOG::ButtonLabel(
_(
"Abort Project Save" ) ) );
1388 if( dlg.ShowModal() == wxID_CANCEL )
1394 std::vector<wxString> savedSheetPaths;
1396 for(
size_t i = 0; i < screens.
GetCount(); i++ )
1400 wxCHECK2( screen,
continue );
1403 wxFileName tmpFn = filenameMap[screen];
1407 updateFileHistory =
true;
1419 sheet->
SetFileName( sheetFileName.GetFullPath() );
1423 filenameMap[screen] = tmpFn.GetFullPath();
1435 if( sheets.size() == 1 )
1441 if( !saveCopy && tmpFn.GetFullPath() != screen->
GetFileName() )
1446 if( savedThisSheet )
1447 savedSheetPaths.push_back( tmpFn.GetFullPath() );
1449 success &= savedThisSheet;
1452 if( success && !saveCopy )
1463 if( updateFileHistory )
1474 wxCHECK2( sheet,
continue );
1478 sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
1481 wxASSERT( filenameMap.count(
Schematic().RootScreen() ) );
1482 wxFileName projectPath( filenameMap.at(
Schematic().RootScreen() ) );
1485 if(
Prj().IsNullProject() || ( aSaveAs && !saveCopy ) )
1490 else if( saveCopy && createNewProject )
1503 if( success && !saveCopy && !
Prj().IsNullProject() )
1518 if( !
Kiface().IsSingle() )
1526 sheet.LastScreen()->SetVirtualPageNumber( sheet.GetVirtualPageNumber() );
1538 if(
m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
1543 wxString backupMsg = backupReporter.
GetMessages();
1544 m_infoBar->ShowMessageFor( backupMsg.Trim(), 10000, wxICON_WARNING );
1555 const std::map<std::string, UTF8>* aProperties )
1557 bool success =
true;
1558 wxFileName filename( aFileName );
1559 wxFileName newfilename;
1560 SCH_IO_MGR::SCH_FILE_T
fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType;
1562 wxCommandEvent changingEvt( EDA_EVT_SCHEMATIC_CHANGING );
1563 ProcessEventLocally( changingEvt );
1566 statusBar->ClearWarningMessages(
"load" );
1571 std::unique_ptr<SCHEMATIC> newSchematic = std::make_unique<SCHEMATIC>( &
Prj() );
1575 case SCH_IO_MGR::SCH_ALTIUM:
1576 case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
1577 case SCH_IO_MGR::SCH_EAGLE:
1578 case SCH_IO_MGR::SCH_LTSPICE:
1579 case SCH_IO_MGR::SCH_EASYEDA:
1580 case SCH_IO_MGR::SCH_EASYEDAPRO:
1581 case SCH_IO_MGR::SCH_EASYEDAPRO_V3:
1582 case SCH_IO_MGR::SCH_PADS:
1583 case SCH_IO_MGR::SCH_GEDA:
1584 case SCH_IO_MGR::SCH_DIPTRACE:
1585 case SCH_IO_MGR::SCH_PCAD:
1586 case SCH_IO_MGR::SCH_ORCAD:
1587 case SCH_IO_MGR::SCH_EASYPC:
1588 case SCH_IO_MGR::SCH_TARGET3001:
1592 wxCHECK_MSG( aFileName.IsEmpty() || filename.IsAbsolute(),
false,
1593 wxS(
"Import schematic: path is not absolute!" ) );
1604 this, std::placeholders::_1 ) );
1607 if(
eeconfig()->m_System.show_import_issues )
1612 pi->SetProgressReporter( &progressReporter );
1614 SCH_SHEET* loadedSheet = pi->LoadSchematicFile( aFileName, newSchematic.get(),
nullptr, aProperties );
1625 bool loadedIsTopLevel = std::find( topLevelSheets.begin(), topLevelSheets.end(), loadedSheet )
1626 != topLevelSheets.end();
1627 bool loadedIsVirtualRoot = loadedSheet == &
Schematic().
Root()
1632 if( !loadedIsTopLevel && !loadedIsVirtualRoot )
1641 std::vector<wxString> sourceFpLibs;
1658 const wxString embeddedPrefix = wxS(
"kicad-embed://" );
1661 if( drawingSheetName.StartsWith( embeddedPrefix ) )
1663 wxString sheetFile = drawingSheetName.Mid( embeddedPrefix.length() );
1667 if( !embeddedWorksheet
1679 newfilename.SetPath(
Prj().GetProjectPath() );
1680 newfilename.SetName(
Prj().GetProjectName() );
1686 topSheet->SetFileName( newfilename.GetFullName() );
1691 progressReporter.
Report(
_(
"Updating connections..." ) );
1713 wxString msg = wxString::Format(
_(
"Error loading schematic '%s'." ), aFileName );
1716 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1721 catch(
const std::exception& exc )
1726 wxString msg = wxString::Format(
_(
"Unhandled exception occurred loading schematic '%s'." ), aFileName );
1729 msg.Printf(
_(
"Failed to load '%s'." ), aFileName );
1753 wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGED );
1754 ProcessEventLocally( e );
1758 wxCHECK2( listener,
continue );
1762 wxWindow* win =
dynamic_cast<wxWindow*
>( listener );
1765 win->HandleWindowEvent( e );
1767 listener->SafelyProcessEvent( e );
1773 statusBar->AddWarningMessages(
"load", loadReporter.
GetMessages() );
1800 if( simFrame && !simFrame->Close() )
1803 if( screen->IsContentModified() )
static TOOL_ACTION zoomFitScreen
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.
static bool ShouldPrompt(int aFileFormatVersionAtLoad, size_t aBusesNeedingMigration)
Multiple differently-named labels on a single bus subgraph were only permitted before KiCad 6....
static DS_DATA_MODEL & GetTheInstance()
Return the instance of DS_DATA_MODEL used in the application.
static const wxString & EmptyLayoutName()
Return the reserved drawing-sheet name that marks a design as deliberately having no sheet,...
void LoadWindowState(const wxString &aFileName)
void CheckForAutosaveFiles(const wxString &aProjectPath, const std::vector< wxString > &aExtensions)
Check for autosave files newer than their source files for the given project.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
SETTINGS_MANAGER * GetSettingsManager() const
wxTimer * m_autoSaveTimer
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.
void ReleaseFile()
Release the current file marked in use.
std::unique_ptr< LOCKFILE > m_file_checker
Prevents opening same file multiple times.
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.
void RefreshGitCommitPane()
Attach the git session if needed and refresh the version-control pane, when it is shown.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
EE_TYPE OfType(KICAD_T aType) const
EMBEDDED_FILE * GetEmbeddedFile(const wxString &aName) const
Returns the embedded file with the given name or nullptr if it does not exist.
bool GetCreateNewProject() const
Gets the selected state of the create new project option.
bool GetCopySubsheets() const
Gets the selected state of the copy subsheets option.
bool IsAttachedToDialog() const
Gets if this hook has attached controls to a dialog box.
bool GetIncludeExternSheets() const
Gets the selected state of the include external sheets option.
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?
void RefreshDrawingSheetPageInfo()
Update the drawing sheet proxy's page number and first-page flag from the current edit frame state.
wxString AsString() const
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
LOCAL_HISTORY & LocalHistory()
Return the LOCAL_HISTORY associated with this KIWAY.
A collection of LIB_SYMBOL objects.
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetDescription(const wxString &aDescription)
void SetURI(const wxString &aUri)
bool RunRegisteredSaversAndCommit(const wxString &aProjectPath, const wxString &aTitle, const wxString &aTagFileType=wxEmptyString)
Run all registered savers and, if any staged changes differ from HEAD, create a commit.
void RemoveAutosaveFiles(const wxString &aProjectPath) const
Remove every autosave file under the project at aProjectPath regardless of which source it shadowed.
static REPORTER & GetInstance()
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
void PreloadDesignBlockLibraries(KIWAY *aKiway)
Starts a background job to preload the global and project design block libraries.
A small class to help profiling.
void Show(std::ostream &aStream=std::cerr)
Print the elapsed time (in a suitable unit) to a stream.
virtual void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
bool KeepRefreshing(bool aWait=false) override
Update the UI dialog.
Plugin class for import plugins that support choosing a project.
The backing store for a PROJECT, in JSON format.
std::vector< FILE_INFO_PAIR > & GetSheets()
bool TopLevelSheetsChangedOnLoad() const
True when the last read of the file replaced a top-level sheet list held from before it.
void AcknowledgeTopLevelSheetChange()
Settle a changed list once the schematic has been loaded from it.
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
static LEGACY_SYMBOL_LIBS * LegacySchLibs(PROJECT *aProject)
Returns the list of symbol libraries from a legacy (pre-5.x) design This is only used from the remapp...
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 const wxString GetProjectName() const
Return the short name of the project.
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.
virtual bool HasMessage() const
Returns true if any messages were reported.
wxString m_SchDrawingSheetFileName
Holds all the data relating to one schematic.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
void LoadVariants()
This is a throw away method for variant testing.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
SCHEMATIC_SETTINGS & Settings() const
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
void SetProject(PROJECT *aPrj)
EMBEDDED_FILES * GetEmbeddedFiles() override
CONNECTION_GRAPH * ConnectionGraph() const
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
void SetTopLevelSheets(const std::vector< SCH_SHEET * > &aSheets)
Replace the top level sheets, rebuilding the hierarchy and connectivity around them.
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
int FixupJunctionsAfterImport(const std::function< void(SCH_LINE *, SCH_LINE *)> &aOnSplit={})
Add junctions to this schematic where required.
static wxFileName TopLevelSheetFile(const TOP_LEVEL_SHEET_INFO &aSheet, const wxString &aProjectPath, bool aLegacy)
The file loaded for a listed top-level sheet. A legacy project reads it under the legacy extension.
static TOOL_ACTION changeSheet
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
Commit for the schematic and symbol editors.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
void DisplaySheet(SCH_SCREEN *aScreen)
bool IsContentModified() const override
Get if the current schematic has been modified but not saved.
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.
NET_NAVIGATOR_TREE * m_netNavigator
bool TopLevelSheetsChangedOnDisk()
Check whether the last read of the project file brought a top-level sheet list that the open schemati...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SyncVariantUI()
Refill the toolbar variant control and any open symbol fields table from the schematic.
void RefreshNetNavigator(const NET_NAVIGATOR_ITEM_DATA *aSelection=nullptr, const std::vector< wxString > *aChangedNets=nullptr)
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.
friend class SCH_EDITOR_CONTROL
void SetCurrentVariant(const wxString &aVariantName)
bool RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
std::vector< wxEvtHandler * > m_schematicChangeListeners
bool ReloadFromDisk()
Reload the schematic and all its sheets from disk.
void CreateDefaultScreens()
PANEL_REMOTE_SYMBOL * m_remoteSymbolPane
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath, bool isSaveAs)
Save aSheet to a schematic file.
SCHEMATIC * m_schematic
The currently loaded schematic.
SCH_SHEET_PATH & GetCurrentSheet() const
void ProjectChanged() override
Notification event that the project has changed.
SCHEMATIC & Schematic() const
void updateTitle()
Set the main window title bar text.
void SetSchematic(SCHEMATIC *aSchematic)
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 ...
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.
bool ConfirmReloadFromDisk(const wxString &aMessage, const wxString &aTitle)
Ask whether to reload when that would discard unsaved edits.
void LoadDrawingSheet()
Load the drawing sheet file.
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 initScreenZoom()
Initialize the zoom value of the current screen and mark the screen as zoom-initialized.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
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 const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
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
void UpdateLocalLibSymbolLinks()
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in this schematic with the local projec...
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
const std::vector< SCH_SYMBOL_INSTANCE > & GetSymbolInstances() const
int GetFileFormatVersionAtLoad() const
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() 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.
bool RepairPageNumbers()
Assign valid page numbers to sheet paths whose stored page number is missing or collides with an earl...
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
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.
bool SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Save a copy of the current project under the given 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.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
Temporarily disable a window, and then re-enable on destruction.
static void ResolvePossibleSymlinks(wxFileName &aFilename)
void Flush()
Build the HTML messages page.
bool HasMessage() const override
Returns true if any messages were reported.
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.
#define KICAD_MESSAGE_DIALOG
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
static bool empty(const wxTextEntryBase *aCtrl)
bool PrepareSaveAsFiles(SCHEMATIC &aSchematic, SCH_SCREENS &aScreens, const wxFileName &aOldRoot, const wxFileName &aNewRoot, bool aSaveCopy, bool aCopySubsheets, bool aIncludeExternSheets, std::unordered_map< SCH_SCREEN *, wxString > &aFilenameMap, wxString &aErrorMsg)
#define THROW_IO_CANCELLED()
static const std::string LegacySchematicFileExtension
static const std::string ProjectFileExtension
static const std::string LegacyProjectFileExtension
static const std::string KiCadSchematicFileExtension
static const std::string LegacySymbolLibFileExtension
static wxString KiCadSchematicFileWildcard()
const wxChar *const traceSchCurrentSheet
Flag to enable debug output of current sheet tracking in the schematic editor.
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.
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
int ReconcileLegacyCacheSymbols(SYMBOL_LIBRARY_ADAPTER &aAdapter, const wxString &aCacheNickname, SCH_SCREENS &aScreens, std::vector< KI_ERROR > &aErrors)
Point symbols that are only available in a legacy project cache library at that cache.
Definition for symbol library class.
void ReadFootprintProps(const std::map< std::string, UTF8 > *aProps, wxString &aCacheNickname, std::vector< wxString > &aSourceFpLibs)
Read the footprint-import coordination properties out of a properties map.
PGM_BASE & Pgm()
The global program "get" accessor.
#define SKIP_CONNECTIVITY
#define DELETE_REMOVED_ITEMS
#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
Implement a participant in the KIWAY alchemy.
virtual void PreloadLibraries(KIWAY *aKiway)
Information about a top-level schematic sheet.
SYMBOL_IMPORT_RECONCILE_RESULT ReconcileImportedSymbols(SCH_IO &aPlugin, SCHEMATIC &aSchematic, PROJECT &aProject, const wxString &aSchematicPath, const std::map< std::string, UTF8 > *aProperties, REPORTER &aReporter)
Reconcile aSchematic against the definitions aPlugin retained while loading it.
wxLogTrace helper definitions.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
Definition of file extensions used in Kicad.