73#include <wx/filedlg.h> 
   75#include <wx/richmsgdlg.h> 
   76#include <wx/stdpaths.h> 
  100    if( aFileSet.size() != 1 )
 
  102        msg.Printf( 
"Eeschema:%s() takes only a single filename.", __WXFUNCTION__ );
 
  107    wxString   fullFileName( aFileSet[0] );
 
  108    wxFileName wx_filename( fullFileName );
 
  112    wxASSERT_MSG( wx_filename.IsAbsolute(), wxS( 
"Path is not absolute!" ) );
 
  116        msg.Printf( 
_( 
"Schematic '%s' is already open by '%s' at '%s'." ), fullFileName,
 
  132    wxFileName pro = fullFileName;
 
  135    bool is_new = !wxFileName::IsFileReadable( fullFileName );
 
  141        msg.Printf( 
_( 
"Schematic '%s' does not exist.  Do you wish to create it?" ),
 
  144        if( !
IsOK( 
this, msg ) )
 
  148    wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGING );
 
  149    ProcessEventLocally( e );
 
  159    SetStatusText( wxEmptyString );
 
  163                                                        : 
_( 
"Load Schematic" ), 1,
 
  169    if( differentProject )
 
  171        if( !
Prj().IsNullProject() )
 
  183        wxFileName legacyPro( pro );
 
  188        if( !pro.Exists() && !legacyPro.Exists() && !( aCtl & 
KICTL_CREATE ) )
 
  193    std::unique_ptr<SCHEMATIC> newSchematic = std::make_unique<SCHEMATIC>( &
Prj() );
 
  198    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 )
 
  232        newSchematic->CreateDefaultScreens();
 
  239        if( schFileType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
 
  241            msg.Printf( 
_( 
"'%s' is not a KiCad schematic file.\nUse File -> Import for " 
  242                           "non-KiCad schematic files." ),
 
  245            progressReporter.Hide();
 
  255        pi->SetProgressReporter( &progressReporter );
 
  257        bool failedLoad = 
false;
 
  267                const std::vector<TOP_LEVEL_SHEET_INFO>& topLevelSheets = projectFile.
GetTopLevelSheets();
 
  269                if( !topLevelSheets.empty() )
 
  277                        wxFileName sheetFileName( 
Prj().GetProjectPath(), sheetInfo.filename );
 
  278                        wxString sheetPath = sheetFileName.GetFullPath();
 
  280                        if( !wxFileName::FileExists( sheetPath ) )
 
  282                            wxLogWarning( wxT( 
"Top-level sheet file not found: %s" ), sheetPath );
 
  286                        SCH_SHEET* sheet = pi->LoadSchematicFile( sheetPath, newSchematic.get() );
 
  292                            if( sheetInfo.uuid != 
niluuid )
 
  294                                const_cast<KIID&
>( sheet->
m_Uuid ) = sheetInfo.uuid;
 
  297                            sheet->
SetName( sheetInfo.name );
 
  300                            newSchematic->AddTopLevelSheet( sheet );
 
  303                                       wxS( 
"Loaded top-level sheet '%s' (UUID %s) from %s" ),
 
  312                    if( !newSchematic->GetTopLevelSheets().empty() )
 
  314                        newSchematic->CurrentSheet().clear();
 
  315                        newSchematic->CurrentSheet().push_back( newSchematic->GetTopLevelSheets()[0] );
 
  318                                   wxS( 
"Loaded multi-root schematic with %zu top-level sheets, current sheet set to '%s'" ),
 
  319                                   newSchematic->GetTopLevelSheets().size(),
 
  320                                   newSchematic->GetTopLevelSheets()[0]->GetName() );
 
  325                                   wxS( 
"Loaded multi-root schematic with no top-level sheets!" ) );
 
  331                    newSchematic->SetRoot( pi->LoadSchematicFile( fullFileName, newSchematic.get() ) );
 
  335                    newSchematic->Root().SetName( 
_( 
"Root" ) );
 
  338                               wxS( 
"Loaded schematic with root sheet UUID %s" ),
 
  339                               newSchematic->Root().m_Uuid.AsString() );
 
  341                               "After loading: Current sheet path='%s', size=%zu, empty=%d",
 
  342                               newSchematic->CurrentSheet().Path().AsString(),
 
  343                               newSchematic->CurrentSheet().size(),
 
  344                               newSchematic->CurrentSheet().empty() ? 1 : 0 );
 
  348            if( !pi->GetError().IsEmpty() )
 
  351                                              "occurred attempting to load hierarchical sheets." ),
 
  357            newSchematic->CreateDefaultScreens();
 
  358            msg.Printf( 
_( 
"Error loading schematic '%s'." ), fullFileName );
 
  359            progressReporter.Hide();
 
  366            newSchematic->CreateDefaultScreens();
 
  367            msg.Printf( 
_( 
"Error loading schematic '%s'." ), fullFileName );
 
  368            progressReporter.Hide();
 
  373        catch( 
const std::bad_alloc& )
 
  375            newSchematic->CreateDefaultScreens();
 
  376            msg.Printf( 
_( 
"Memory exhausted loading schematic '%s'." ), fullFileName );
 
  377            progressReporter.Hide();
 
  397            msg.Printf( 
_( 
"Failed to load '%s'." ), fullFileName );
 
  414                                _( 
"An error was found when loading the schematic that has " 
  415                                   "been automatically fixed.  Please save the schematic to " 
  416                                   "repair the broken file or it may not be usable with other " 
  417                                   "versions of KiCad." ) );
 
  428        if( schFileType == SCH_IO_MGR::SCH_LEGACY )
 
  433                std::vector<SCH_ITEM*> deleted;
 
  435                for( 
SCH_ITEM* item : screen->Items() )
 
  440                        std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
 
  444                        wire->SetEndPoint( entry->
GetEnd() );
 
  446                        screen->Append( wire.release() );
 
  447                        deleted.push_back( item );
 
  452                    screen->Remove( item );
 
  468                wxArrayString libNames;
 
  472                if( !libNames.IsEmpty() )
 
  474                    if( 
eeconfig()->m_Appearance.show_illegal_symbol_lib_dialog )
 
  476                        wxRichMessageDialog invalidLibDlg(
 
  478                                _( 
"Illegal entry found in project file symbol library list." ),
 
  479                                _( 
"Project Load Warning" ),
 
  480                                wxOK | wxCENTER | wxICON_EXCLAMATION );
 
  481                        invalidLibDlg.ShowDetailedText(
 
  482                                _( 
"Symbol libraries defined in the project file symbol library " 
  483                                   "list are no longer supported and will be removed.\n\n" 
  484                                   "This may cause broken symbol library links under certain " 
  486                        invalidLibDlg.ShowCheckBox( 
_( 
"Do not show this dialog again." ) );
 
  487                        invalidLibDlg.ShowModal();
 
  489                                !invalidLibDlg.IsCheckBoxChecked();
 
  500                    editor->RescueSymbolLibTableProject( 
false );
 
  510                wxFileName cacheFn = pro;
 
  512                wxLogTrace( 
traceAutoSave, 
"[SetName dbg] cacheFn BEFORE path='%s' name='%s' full='%s' arg='%s'",
 
  513                            cacheFn.GetPath(), cacheFn.GetName(), cacheFn.GetFullPath(), cacheFn.GetName() + 
"-cache" );
 
  514                cacheFn.SetName( cacheFn.GetName() + 
"-cache" );
 
  515                wxLogTrace( 
traceAutoSave, 
"[SetName dbg] cacheFn AFTER  path='%s' name='%s' full='%s'",
 
  516                            cacheFn.GetPath(), cacheFn.GetName(), cacheFn.GetFullPath() );
 
  519                msg.Printf( 
_( 
"The project symbol library cache file '%s' was not found." ),
 
  520                            cacheFn.GetFullName() );
 
  521                extMsg = 
_( 
"This can result in a broken schematic under certain conditions.  " 
  522                            "If the schematic does not have any missing symbols upon opening, " 
  523                            "save it immediately before making any changes to prevent data " 
  524                            "loss.  If there are missing symbols, either manual recovery of " 
  525                            "the schematic or recovery of the symbol cache library file and " 
  526                            "reloading the schematic is required." );
 
  528                wxMessageDialog dlgMissingCache( 
this, msg, 
_( 
"Warning" ),
 
  529                                                 wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
 
  530                dlgMissingCache.SetExtendedMessage( extMsg );
 
  531                dlgMissingCache.SetOKCancelLabels(
 
  532                        wxMessageDialog::ButtonLabel( 
_( 
"Load Without Cache File" ) ),
 
  533                        wxMessageDialog::ButtonLabel( 
_( 
"Abort" ) ) );
 
  535                if( dlgMissingCache.ShowModal() == wxID_CANCEL )
 
  548            m_infoBar->ShowMessage( 
_( 
"This file was created by an older version of KiCad. " 
  549                                       "It will be converted to the new format when saved." ),
 
  557                screen->FixLegacyPowerSymbolMismatches();
 
  568                first_screen = schematic.
GetNext();
 
  574                m_infoBar->ShowMessage( 
_( 
"This file was created by an older version of KiCad. " 
  575                                           "It will be converted to the new format when saved." ),
 
  583            if( 
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221002 )
 
  586            if( 
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20221110 )
 
  589            if( 
Schematic().RootScreen()->GetFileFormatVersionAtLoad() < 20230221 )
 
  592                    screen->FixLegacyPowerSymbolMismatches();
 
  595                screen->MigrateSimModels();
 
  607                   "Before CheckForMissingSymbolInstances: Current sheet path='%s', size=%zu",
 
  617                   "After SetScreen: Current sheet path='%s', size=%zu",
 
  623        if( 
Schematic().ConnectionGraph()->GetBusesNeedingMigration().size() > 0 )
 
  632        progressReporter.
Report( 
_( 
"Updating connections..." ) );
 
  639            m_infoBar->QueueShowMessage( 
_( 
"This schematic contains symbols that have leading " 
  640                                            "and/or trailing white space field names." ),
 
  662    if( schFileType == SCH_IO_MGR::SCH_LEGACY )
 
  672    wxCommandEvent changedEvt( EDA_EVT_SCHEMATIC_CHANGED );
 
  673    ProcessEventLocally( changedEvt );
 
  675    if( !differentProject && 
Kiface().IsSingle() )
 
  684        wxCHECK2( listener, 
continue );
 
  688        wxWindow* win = 
dynamic_cast<wxWindow*
>( listener );
 
  691            win->HandleWindowEvent( e );
 
  693            listener->SafelyProcessEvent( e );
 
  701    if( fn.FileExists() && !fn.IsFileWritable() )
 
  705        m_infoBar->ShowMessage( 
_( 
"Schematic is read only." ),
 
 
  731        wxString msg = 
_( 
"This operation replaces the contents of the current schematic, " 
  732                          "which will be permanently lost.\n\n" 
  733                          "Do you want to proceed?" );
 
  735        if( !
IsOK( 
this, msg ) )
 
  741    wxString 
path = wxPathOnly( 
Prj().GetProjectFullName() );
 
  743    wxString fileFiltersStr;
 
  744    wxString allWildcardsStr;
 
  746    for( 
const SCH_IO_MGR::SCH_FILE_T& 
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
 
  748        if( 
fileType == SCH_IO_MGR::SCH_KICAD || 
fileType == SCH_IO_MGR::SCH_LEGACY )
 
  761        if( !fileFiltersStr.IsEmpty() )
 
  762            fileFiltersStr += wxChar( 
'|' );
 
  770    fileFiltersStr = 
_( 
"All supported formats" ) + wxS( 
"|" ) + allWildcardsStr + wxS( 
"|" )
 
  773    wxFileDialog dlg( 
this, 
_( 
"Import Schematic" ), 
path, wxEmptyString, fileFiltersStr,
 
  774                      wxFD_OPEN | wxFD_FILE_MUST_EXIST ); 
 
  777    dlg.SetCustomizeHook( importOptions );
 
  779    if( dlg.ShowModal() == wxID_CANCEL )
 
  799        wxFileName projectFn( dlg.GetPath() );
 
  804    wxFileName fn = dlg.GetPath();
 
  806    if( !fn.IsFileReadable() )
 
  808        wxLogError( 
_( 
"Insufficient permissions to read file '%s'." ), fn.GetFullPath() );
 
  812    SCH_IO_MGR::SCH_FILE_T pluginType = SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN;
 
  814    for( 
const SCH_IO_MGR::SCH_FILE_T& 
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
 
  821        if( pi->CanReadSchematicFile( fn.GetFullPath() ) )
 
  828    if( pluginType == SCH_IO_MGR::SCH_FILE_T::SCH_FILE_UNKNOWN )
 
  830        wxLogError( 
_( 
"No loader can read the specified file: '%s'." ), fn.GetFullPath() );
 
 
  845    wxFileName schematicFileName;
 
  846    wxFileName oldFileName;
 
  851    wxCHECK( screen, 
false );
 
  854    if( aSavePath.IsEmpty() )
 
  859    oldFileName = schematicFileName;
 
  864    if( !schematicFileName.DirExists() )
 
  866        if( !wxMkdir( schematicFileName.GetPath() ) )
 
  868            msg.Printf( 
_( 
"Error saving schematic file '%s'.\n%s" ),
 
  869                        schematicFileName.GetFullPath(),
 
  870                        "Could not create directory: %s" + schematicFileName.GetPath() );
 
  880    wxFileName projectFile( schematicFileName );
 
  884    if( projectFile.FileExists() )
 
  892    wxLogTrace( 
traceAutoSave, wxS( 
"Saving file " ) + schematicFileName.GetFullPath() );
 
  898            schematicFileName.GetFullPath() );
 
  900    if( pluginType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
 
  901        pluginType = SCH_IO_MGR::SCH_KICAD;
 
  907        pi->SaveSchematicFile( schematicFileName.GetFullPath(), aSheet, &
Schematic() );
 
  912        msg.Printf( 
_( 
"Error saving schematic file '%s'.\n%s" ),
 
  913                    schematicFileName.GetFullPath(),
 
  924        msg.Printf( 
_( 
"File '%s' saved." ),  screen->
GetFileName() );
 
  925        SetStatusText( msg, 0 );
 
 
  943                         const wxFileName& aOldRoot, 
const wxFileName& aNewRoot,
 
  944                         bool aSaveCopy, 
bool aCopySubsheets, 
bool aIncludeExternSheets,
 
  945                         std::unordered_map<SCH_SCREEN*, wxString>& aFilenameMap,
 
  946                         wxString& aErrorMsg )
 
  950    for( 
size_t i = 0; i < aScreens.
GetCount(); i++ )
 
  954        wxCHECK2( screen, 
continue );
 
  961        if( !src.IsAbsolute() )
 
  962            src.MakeAbsolute( aOldRoot.GetPath() );
 
  964        bool internalSheet = src.GetPath().StartsWith( aOldRoot.GetPath() );
 
  966        if( aCopySubsheets && ( internalSheet || aIncludeExternSheets ) )
 
  968            wxFileName dest = src;
 
  970            if( internalSheet && dest.MakeRelativeTo( aOldRoot.GetPath() ) )
 
  971                dest.MakeAbsolute( aNewRoot.GetPath() );
 
  973                dest.Assign( aNewRoot.GetPath(), dest.GetFullName() );
 
  976                        wxS( 
"Moving schematic from '%s' to '%s'." ),
 
  978                        dest.GetFullPath() );
 
  980            if( !dest.DirExists() && !dest.Mkdir() )
 
  982                aErrorMsg.Printf( 
_( 
"Folder '%s' could not be created.\n\n" 
  983                                     "Make sure you have write permissions and try again." ),
 
  989                aFilenameMap[screen] = dest.GetFullPath();
 
  996                aFilenameMap[screen] = wxString();
 
 1004        if( !sheet.Last()->IsTopLevelSheet() )
 
 1005            sheet.MakeFilePathRelativeToParentSheet();
 
 
 1017    bool        success           = 
true;
 
 1018    bool        updateFileHistory = 
false;
 
 1019    bool        createNewProject  = 
false;
 
 1020    bool        copySubsheets     = 
false;
 
 1021    bool        includeExternSheets = 
false;
 
 1025    wxFileName  fn = fileName;
 
 1029    std::unordered_map<SCH_SCREEN*, wxString> filenameMap;
 
 1032    if( 
Prj().IsNullProject() || aSaveAs )
 
 1035        wxCHECK( 
Kiface().IsSingle() || aSaveAs, 
false );
 
 1037        wxFileName newFileName;
 
 1038        wxFileName savePath( 
Prj().GetProjectFullName() );
 
 1040        if( !savePath.IsOk() || !savePath.IsDirWritable() )
 
 1044            if( !savePath.IsOk() || !savePath.IsDirWritable() )
 
 1048        if( savePath.HasExt() )
 
 1051            savePath.SetName( wxEmptyString );
 
 1053        wxFileDialog dlg( 
this, 
_( 
"Schematic Files" ), savePath.GetPath(), savePath.GetFullName(),
 
 1055                          wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
 
 1060        if( 
Kiface().IsSingle() || aSaveAs )
 
 1062            dlg.SetCustomizeHook( newProjectHook );
 
 1065        if( dlg.ShowModal() == wxID_CANCEL )
 
 1070        if( ( !newFileName.DirExists() && !newFileName.Mkdir() ) ||
 
 1071            !newFileName.IsDirWritable() )
 
 1073            msg.Printf( 
_( 
"Folder '%s' could not be created.\n\n" 
 1074                           "Make sure you have write permissions and try again." ),
 
 1075                        newFileName.GetPath() );
 
 1077            wxMessageDialog dlgBadPath( 
this, msg, 
_( 
"Error" ),
 
 1078                                        wxOK | wxICON_EXCLAMATION | wxCENTER );
 
 1080            dlgBadPath.ShowModal();
 
 1095            updateFileHistory = 
true;
 
 1103                                 copySubsheets, includeExternSheets, filenameMap, msg ) )
 
 1105            wxMessageDialog dlgBadFilePath( 
this, msg, 
_( 
"Error" ),
 
 1106                                            wxOK | wxICON_EXCLAMATION | wxCENTER );
 
 1108            dlgBadFilePath.ShowModal();
 
 1112    else if( !fn.FileExists() )
 
 1115        updateFileHistory = 
true;
 
 1126    if( filenameMap.empty() || !saveCopy )
 
 1128        for( 
size_t i = 0; i < screens.
GetCount(); i++ )
 
 1133    wxArrayString overwrittenFiles;
 
 1134    wxArrayString lockedFiles;
 
 1136    for( 
size_t i = 0; i < screens.
GetCount(); i++ )
 
 1140        wxCHECK2( screen, 
continue );
 
 1143        wxFileName tmpFn = filenameMap[screen];
 
 1148        if( tmpFn.FileExists() && !tmpFn.IsFileWritable() )
 
 1149            lockedFiles.Add( tmpFn.GetFullPath() );
 
 1156        if( tmpFn.FileExists() )
 
 1157            overwrittenFiles.Add( tmpFn.GetFullPath() );
 
 1160    if( !lockedFiles.IsEmpty() )
 
 1162        for( 
const wxString& lockedFile : lockedFiles )
 
 1167                msg += 
"\n" + lockedFile;
 
 1170        wxRichMessageDialog dlg( 
this, wxString::Format( 
_( 
"Failed to save %s." ),
 
 1172                                 _( 
"Locked File Warning" ),
 
 1173                                 wxOK | wxICON_WARNING | wxCENTER );
 
 1174        dlg.SetExtendedMessage( 
_( 
"You do not have write permissions to:\n\n" ) + msg );
 
 1180    if( !overwrittenFiles.IsEmpty() )
 
 1182        for( 
const wxString& overwrittenFile : overwrittenFiles )
 
 1185                msg = overwrittenFile;
 
 1187                msg += 
"\n" + overwrittenFile;
 
 1190        wxRichMessageDialog dlg( 
this, 
_( 
"Saving will overwrite existing files." ),
 
 1191                                 _( 
"Save Warning" ),
 
 1192                                 wxOK | wxCANCEL | wxCANCEL_DEFAULT | wxCENTER |
 
 1193                                 wxICON_EXCLAMATION );
 
 1194        dlg.ShowDetailedText( 
_( 
"The following files will be overwritten:\n\n" ) + msg );
 
 1195        dlg.SetOKCancelLabels( wxMessageDialog::ButtonLabel( 
_( 
"Overwrite Files" ) ),
 
 1196                               wxMessageDialog::ButtonLabel( 
_( 
"Abort Project Save" ) ) );
 
 1198        if( dlg.ShowModal() == wxID_CANCEL )
 
 1204    for( 
size_t i = 0; i < screens.
GetCount(); i++ )
 
 1208        wxCHECK2( screen, 
continue );
 
 1211        wxFileName tmpFn = filenameMap[screen];
 
 1215            updateFileHistory = 
true;
 
 1223                if( !sheetFileName.IsOk()
 
 1228                sheet->
SetFileName( sheetFileName.GetFullPath() );
 
 1232            filenameMap[screen] = tmpFn.GetFullPath();
 
 1244        if( sheets.size() == 1 )
 
 1250        if( !saveCopy && tmpFn.GetFullPath() != screen->
GetFileName() )
 
 1259    if( aSaveAs && success )
 
 1262    if( updateFileHistory )
 
 1273        wxCHECK2( sheet, 
continue );
 
 1278            sheets.emplace_back( std::make_pair( sheet->
m_Uuid, sheet->
GetName() ) );
 
 1282    wxASSERT( filenameMap.count( 
Schematic().RootScreen() ) );
 
 1283    wxFileName projectPath( filenameMap.at( 
Schematic().RootScreen() ) );
 
 1286    if( 
Prj().IsNullProject() || ( aSaveAs && !saveCopy ) )
 
 1291    else if( saveCopy && createNewProject )
 
 1301    if( !
Kiface().IsSingle() )
 
 
 1319                                 const std::map<std::string, UTF8>* aProperties )
 
 1321    wxFileName             filename( aFileName );
 
 1322    wxFileName             newfilename;
 
 1323    SCH_IO_MGR::SCH_FILE_T 
fileType = (SCH_IO_MGR::SCH_FILE_T) aFileType;
 
 1325    wxCommandEvent changingEvt( EDA_EVT_SCHEMATIC_CHANGING );
 
 1326    ProcessEventLocally( changingEvt );
 
 1328    std::unique_ptr<SCHEMATIC> newSchematic = std::make_unique<SCHEMATIC>( &
Prj() );
 
 1332    case SCH_IO_MGR::SCH_ALTIUM:
 
 1333    case SCH_IO_MGR::SCH_CADSTAR_ARCHIVE:
 
 1334    case SCH_IO_MGR::SCH_EAGLE:
 
 1335    case SCH_IO_MGR::SCH_LTSPICE:
 
 1336    case SCH_IO_MGR::SCH_EASYEDA:
 
 1337    case SCH_IO_MGR::SCH_EASYEDAPRO:
 
 1341        wxCHECK_MSG( aFileName.IsEmpty() || filename.IsAbsolute(), 
false,
 
 1342                     wxS( 
"Import schematic: path is not absolute!" ) );
 
 1353                                                   this, std::placeholders::_1 ) );
 
 1356            if( 
eeconfig()->m_System.show_import_issues )
 
 1361            pi->SetProgressReporter( &progressReporter );
 
 1363            SCH_SHEET* loadedSheet = pi->LoadSchematicFile( aFileName, newSchematic.get(), 
nullptr,
 
 1384                newfilename.SetPath( 
Prj().GetProjectPath() );
 
 1385                newfilename.SetName( 
Prj().GetProjectName() );
 
 1394                progressReporter.
Report( 
_( 
"Updating connections..." ) );
 
 1416            wxString msg = wxString::Format( 
_( 
"Error loading schematic '%s'." ), aFileName );
 
 1419            msg.Printf( 
_( 
"Failed to load '%s'." ), aFileName );
 
 1422        catch( 
const std::exception& exc )
 
 1427            wxString msg = wxString::Format( 
_( 
"Unhandled exception occurred loading schematic " 
 1428                                                "'%s'." ), aFileName );
 
 1431            msg.Printf( 
_( 
"Failed to load '%s'." ), aFileName );
 
 1444        wxCommandEvent e( EDA_EVT_SCHEMATIC_CHANGED );
 
 1445        ProcessEventLocally( e );
 
 1449            wxCHECK2( listener, 
continue );
 
 1453            wxWindow* win = 
dynamic_cast<wxWindow*
>( listener );
 
 1456                win->HandleWindowEvent( e );
 
 1458                listener->SafelyProcessEvent( e );
 
 
 1484        if( simFrame && !simFrame->Close() )
 
 1487        if( screen->IsContentModified() )
 
 
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
 
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.
 
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
 
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.
 
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 the selected state of the copy subsheets option.
 
bool GetCopySubsheets() const
Gets the selected state of the include external sheets option.
 
bool IsAttachedToDialog() const
 
bool GetIncludeExternSheets() const
Gets if this hook has attached controls to a dialog box.
 
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?
 
wxString AsString() const
 
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 #SYMBOL_LIB objects.
 
static void GetLibNamesAndPaths(PROJECT *aProject, wxString *aPaths, wxArrayString *aNames=nullptr)
 
static void SetLibNamesAndPaths(PROJECT *aProject, const wxString &aPaths, const wxArrayString &aNames)
 
bool TagSave(const wxString &aProjectPath, const wxString &aFileType)
Tag a manual save in the local history repository.
 
bool Init(const wxString &aProjectPath)
Initialize the local history repository for the given project path.
 
bool CommitFullProjectSnapshot(const wxString &aProjectPath, const wxString &aTitle)
Commit a snapshot of the entire project directory (excluding the .history directory and ignored trans...
 
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.
 
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()
 
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
 
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 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.
 
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.
 
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
 
void FixupJunctionsAfterImport()
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)
 
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.
 
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.
 
friend class SCH_EDITOR_CONTROL
 
std::vector< wxEvtHandler * > m_schematicChangeListeners
 
void CreateDefaultScreens()
 
SCH_SHEET_PATH & GetCurrentSheet() const
 
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
 
SCHEMATIC & Schematic() const
 
void updateTitle()
Set the main window title bar text.
 
void SetSchematic(SCHEMATIC *aSchematic)
 
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 ...
 
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.
 
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 OnImportProject(wxCommandEvent &event)
 
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
 
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.
 
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
 
bool IsVirtualRootSheet() 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.
 
The SIMULATOR_FRAME holds the main user-interface for running simulations.
 
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.
 
@ OUTDATED_SAVE
OUTDATED_SAVE Messages that should be cleared on save.
 
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)
 
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)
 
void ProjectChanged() override
 
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 THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
 
#define KICTL_CREATE
caller thinks requested project files may not exist.
 
#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
 
Implement a participant in the KIWAY alchemy.
 
virtual void PreloadLibraries(KIWAY *aKiway)
 
Information about a top-level schematic sheet.
 
wxLogTrace helper definitions.
 
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
 
Definition of file extensions used in Kicad.