bool SCH_EDIT_FRAME::doAutoSave() { wxFileName tmpFileName = g_RootSheet->GetFileName(); wxFileName fn = tmpFileName; wxFileName tmp; SCH_SCREENS screens; bool autoSaveOk = true; tmp.AssignDir( fn.GetPath() ); if( !IsWritable( tmp ) ) return false; for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) { // Only create auto save files for the schematics that have been modified. if( !screen->IsSave() ) continue; tmpFileName = fn = screen->GetFileName(); // Auto save file name is the normal file name prefixed with $. fn.SetName( wxT( "$" ) + fn.GetName() ); screen->SetFileName( fn.GetFullPath() ); if( SaveEEFile( screen, false, NO_BACKUP_FILE ) ) screen->SetModify(); else autoSaveOk = false; screen->SetFileName( tmpFileName.GetFullPath() ); } if( autoSaveOk ) m_autoSaveState = false; return autoSaveOk; }
bool DIALOG_SYMBOL_REMAP::backupProject( REPORTER& aReporter ) { static wxString backupFolder = "rescue-backup"; wxString tmp; wxString errorMsg; wxFileName srcFileName; wxFileName destFileName; wxFileName backupPath; SCH_SCREENS schematic; // Copy backup files to different folder so as not to pollute the project folder. destFileName.SetPath( Prj().GetProjectPath() ); destFileName.AppendDir( backupFolder ); backupPath = destFileName; if( !destFileName.DirExists() ) { if( !destFileName.Mkdir() ) { errorMsg.Printf( _( "Cannot create project remap back up folder \"%s\"." ), destFileName.GetPath() ); wxMessageDialog dlg( this, errorMsg, _( "Backup Error" ), wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION ); dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Continue with Rescue" ) ), wxMessageDialog::ButtonLabel( _( "Abort Rescue" ) ) ); if( dlg.ShowModal() == wxID_NO ) return false; } } // Time stamp to append to file name in case multiple remappings are performed. wxString timeStamp = wxDateTime::Now().Format( "-%Y-%m-%d-%H-%M-%S" ); // Back up symbol library table. srcFileName.SetPath( Prj().GetProjectPath() ); srcFileName.SetName( SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() ); destFileName = srcFileName; destFileName.AppendDir( backupFolder ); destFileName.SetName( destFileName.GetName() + timeStamp ); tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), srcFileName.GetFullPath(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( wxFileName::Exists( srcFileName.GetFullPath() ) && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() ); errorMsg += tmp; } // Back up the schematic files. for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) { destFileName = screen->GetFileName(); destFileName.SetName( destFileName.GetName() + timeStamp ); // Check for nest hierarchical schematic paths. if( destFileName.GetPath() != backupPath.GetPath() ) { destFileName.SetPath( backupPath.GetPath() ); wxArrayString srcDirs = wxFileName( screen->GetFileName() ).GetDirs(); wxArrayString destDirs = wxFileName( Prj().GetProjectPath() ).GetDirs(); for( size_t i = destDirs.GetCount(); i < srcDirs.GetCount(); i++ ) destFileName.AppendDir( srcDirs[i] ); } else { destFileName.AppendDir( backupFolder ); } tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), screen->GetFileName(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( !destFileName.DirExists() && !destFileName.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) ) { tmp.Printf( _( "Failed to create backup folder \"%s\"\n" ), destFileName.GetPath() ); errorMsg += tmp; continue; } if( wxFileName::Exists( screen->GetFileName() ) && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), screen->GetFileName() ); errorMsg += tmp; } } // Back up the project file. destFileName = Prj().GetProjectFullName(); destFileName.SetName( destFileName.GetName() + timeStamp ); destFileName.AppendDir( backupFolder ); tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), Prj().GetProjectFullName(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( wxFileName::Exists( Prj().GetProjectFullName() ) && !wxCopyFile( Prj().GetProjectFullName(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), Prj().GetProjectFullName() ); errorMsg += tmp; } // Back up the cache library. srcFileName.SetPath( Prj().GetProjectPath() ); srcFileName.SetName( Prj().GetProjectName() + "-cache" ); srcFileName.SetExt( SchematicLibraryFileExtension ); destFileName = srcFileName; destFileName.SetName( destFileName.GetName() + timeStamp ); destFileName.AppendDir( backupFolder ); tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), srcFileName.GetFullPath(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( srcFileName.Exists() && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() ); errorMsg += tmp; } // Back up the rescue symbol library if it exists. srcFileName.SetName( Prj().GetProjectName() + "-rescue" ); destFileName.SetName( srcFileName.GetName() + timeStamp ); tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), srcFileName.GetFullPath(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( srcFileName.Exists() && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() ); errorMsg += tmp; } // Back up the rescue symbol library document file if it exists. srcFileName.SetExt( "dcm" ); destFileName.SetExt( srcFileName.GetExt() ); tmp.Printf( _( "Backing up file \"%s\" to file \"%s\"." ), srcFileName.GetFullPath(), destFileName.GetFullPath() ); aReporter.Report( tmp, REPORTER::RPT_INFO ); if( srcFileName.Exists() && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) { tmp.Printf( _( "Failed to back up file \"%s\".\n" ), srcFileName.GetFullPath() ); errorMsg += tmp; } if( !errorMsg.IsEmpty() ) { wxMessageDialog dlg( this, _( "Some of the project files could not be backed up." ), _( "Backup Error" ), wxYES_NO | wxCENTRE | wxRESIZE_BORDER | wxICON_QUESTION ); errorMsg.Trim(); dlg.SetExtendedMessage( errorMsg ); dlg.SetYesNoLabels( wxMessageDialog::ButtonLabel( _( "Continue with Rescue" ) ), wxMessageDialog::ButtonLabel( _( "Abort Rescue" ) ) ); if( dlg.ShowModal() == wxID_NO ) return false; } return true; }
XNODE* NETLIST_EXPORTER_GENERIC::makeDesignHeader() { SCH_SCREEN* screen; XNODE* xdesign = node( wxT( "design" ) ); XNODE* xtitleBlock; XNODE* xsheet; XNODE* xcomment; wxString sheetTxt; wxFileName sourceFileName; // the root sheet is a special sheet, call it source xdesign->AddChild( node( wxT( "source" ), g_RootSheet->GetScreen()->GetFileName() ) ); xdesign->AddChild( node( wxT( "date" ), DateAndTime() ) ); // which Eeschema tool xdesign->AddChild( node( wxT( "tool" ), wxT( "Eeschema " ) + GetBuildVersion() ) ); /* Export the sheets information */ SCH_SHEET_LIST sheetList( g_RootSheet ); for( unsigned i = 0; i < sheetList.size(); i++ ) { screen = sheetList[i].LastScreen(); xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) ); // get the string representation of the sheet index number. // Note that sheet->GetIndex() is zero index base and we need to increment the // number by one to make it human readable sheetTxt.Printf( wxT( "%u" ), i + 1 ); xsheet->AddAttribute( wxT( "number" ), sheetTxt ); xsheet->AddAttribute( wxT( "name" ), sheetList[i].PathHumanReadable() ); xsheet->AddAttribute( wxT( "tstamps" ), sheetList[i].Path() ); TITLE_BLOCK tb = screen->GetTitleBlock(); xsheet->AddChild( xtitleBlock = node( wxT( "title_block" ) ) ); xtitleBlock->AddChild( node( wxT( "title" ), tb.GetTitle() ) ); xtitleBlock->AddChild( node( wxT( "company" ), tb.GetCompany() ) ); xtitleBlock->AddChild( node( wxT( "rev" ), tb.GetRevision() ) ); xtitleBlock->AddChild( node( wxT( "date" ), tb.GetDate() ) ); // We are going to remove the fileName directories. sourceFileName = wxFileName( screen->GetFileName() ); xtitleBlock->AddChild( node( wxT( "source" ), sourceFileName.GetFullName() ) ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("1") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment1() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("2") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment2() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("3") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment3() ); xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) ); xcomment->AddAttribute( wxT("number"), wxT("4") ); xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() ); } return xdesign; }
void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef ) { wxString msg; if( aPrintAll ) { SCH_SHEET_PATH* sheetpath; SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); SCH_SHEET_LIST SheetList( NULL ); sheetpath = SheetList.GetFirst(); SCH_SHEET_PATH list; WX_TEXT_CTRL_REPORTER reporter(m_MessagesBox); for( ; ; ) { if( sheetpath == NULL ) { break; } SCH_SCREEN* screen; list.Clear(); if( list.BuildSheetPathInfoFromSheetPathValue( sheetpath->Path() ) ) { m_parent->SetCurrentSheet( list ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); screen = m_parent->GetCurrentSheet().LastScreen(); } else // Should not happen { return; } sheetpath = SheetList.GetNext(); try { wxString fname = m_parent->GetUniqueFilenameForCurrentSheet(); wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname, ext, &reporter ); bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen, getModeColor() ? false : true, aPrintFrameRef ); if( !success ) { msg.Printf( _( "Error creating file '%s'\n" ), GetChars( plotFileName.GetFullPath() ) ); } else { msg.Printf( _( "File '%s' OK\n" ), GetChars( plotFileName.GetFullPath() ) ); } m_MessagesBox->AppendText( msg ); } catch( const IO_ERROR& e ) { // Cannot plot SVG file msg.Printf( wxT( "SVG Plotter Exception : '%s'" ), GetChars( e.errorText ) ); m_MessagesBox->AppendText( msg ); m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); return; } } m_parent->SetCurrentSheet( oldsheetpath ); m_parent->GetCurrentSheet().UpdateAllScreenReferences(); m_parent->SetSheetNumberAndCount(); } else // Print current sheet { SCH_SCREEN* screen = (SCH_SCREEN*) m_parent->GetScreen(); try { wxString fname = screen->GetFileName(); wxString ext = SVG_PLOTTER::GetDefaultFileExtension(); wxFileName fn = createPlotFileName( m_outputDirectoryName, fname, ext ); bool success = plotOneSheetSVG( m_parent, fn.GetFullPath(), screen, getModeColor() ? false : true, aPrintFrameRef ); if( success ) { msg.Printf( _( "Plot: <%s> OK\n" ), GetChars( fn.GetFullPath() ) ); } else // Error { msg.Printf( _( "Unable to create <%s>\n" ), GetChars( fn.GetFullPath() ) ); } m_MessagesBox->AppendText( msg ); } catch( const IO_ERROR& e ) { // Cannot plot SVG file msg.Printf( wxT( "SVG Plotter Exception : <%s>"), GetChars( e.errorText ) ); m_MessagesBox->AppendText( msg ); return; } } }
void SCH_EDIT_FRAME::OnCloseWindow( wxCloseEvent& aEvent ) { LIB_EDIT_FRAME * libeditFrame = LIB_EDIT_FRAME::GetActiveLibraryEditor();; if( libeditFrame && !libeditFrame->Close() ) // Can close component editor? return; LIB_VIEW_FRAME* viewlibFrame = LIB_VIEW_FRAME::GetActiveLibraryViewer( this ); if( viewlibFrame && !viewlibFrame->Close() ) // Can close component viewer? return; SCH_SHEET_LIST SheetList; if( SheetList.IsModified() ) { wxString msg; msg.Printf( _("Save the changes in\n<%s>\nbefore closing?"), GetChars( g_RootSheet->GetScreen()->GetFileName() ) ); int ii = DisplayExitDialog( this, msg ); switch( ii ) { case wxID_CANCEL: aEvent.Veto(); return; case wxID_NO: break; case wxID_YES: wxCommandEvent tmp( ID_SAVE_PROJECT ); OnSaveProject( tmp ); break; } } // Close the find dialog and perserve it's setting if it is displayed. if( m_dlgFindReplace ) { m_findDialogPosition = m_dlgFindReplace->GetPosition(); m_findDialogSize = m_dlgFindReplace->GetSize(); m_findStringHistoryList = m_dlgFindReplace->GetFindEntries(); m_replaceStringHistoryList = m_dlgFindReplace->GetReplaceEntries(); m_dlgFindReplace->Destroy(); m_dlgFindReplace = NULL; } SCH_SCREENS screens; wxFileName fn; for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) { fn = screen->GetFileName(); // Auto save file name is the normal file name prepended with $. fn.SetName( wxT( "$" ) + fn.GetName() ); if( fn.FileExists() && fn.IsFileWritable() ) wxRemoveFile( fn.GetFullPath() ); } SheetList.ClearModifyStatus(); if( !g_RootSheet->GetScreen()->GetFileName().IsEmpty() && (g_RootSheet->GetScreen()->GetDrawItems() != NULL) ) UpdateFileHistory( g_RootSheet->GetScreen()->GetFileName() ); g_RootSheet->GetScreen()->Clear(); // all sub sheets are deleted, only the main sheet is usable m_CurrentSheet->Clear(); Destroy(); }