diff --git a/eeschema/dialogs/dialog_symbol_remap.cpp b/eeschema/dialogs/dialog_symbol_remap.cpp index 40120627e0..41c1cdaaf6 100644 --- a/eeschema/dialogs/dialog_symbol_remap.cpp +++ b/eeschema/dialogs/dialog_symbol_remap.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -45,6 +46,17 @@ DIALOG_SYMBOL_REMAP::DIALOG_SYMBOL_REMAP( SCH_EDIT_FRAME* aParent ) : DIALOG_SYMBOL_REMAP_BASE( aParent ) { + wxString text; + + text = _( "This schematic currently uses the symbol library list look up method for " + "loading schematic symbols. KiCad will attempt to map the existing symbols " + "to use the new symbol library table. Remapping will change project files " + "and schematics will not be compatible with previous versions of KiCad. " + "All files that are changed will be backed up with the .v4 extension should " + "you need to revert any changes. If you choose to skip this step, you will " + "be responsible for manually remapping the symbols." ); + + m_htmlCtrl->AppendToPage( text ); } @@ -52,6 +64,8 @@ void DIALOG_SYMBOL_REMAP::OnRemapSymbols( wxCommandEvent& aEvent ) { wxBusyCursor busy; + backupProject(); + // The schematic is fully loaded, any legacy library symbols have been rescued. Now // check to see if the schematic has not been converted to the symbol library table // method for looking up symbols. @@ -263,3 +277,99 @@ bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_COMPONENT* aSymbol ) return false; } + + +void DIALOG_SYMBOL_REMAP::backupProject() +{ + static wxString ext = "v4"; + + wxString errorMsg; + wxFileName destFileName; + SCH_SCREENS schematic; + + // Back up the schematic files. + for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) + { + destFileName = screen->GetFileName(); + destFileName.SetName( destFileName.GetFullName() ); + destFileName.SetExt( ext ); + + wxLogTrace( "KICAD_TRACE_PATHS", "Backing up file '%s' to file '%s'.", + screen->GetFileName(), destFileName.GetFullPath() ); + + if( wxFileName::Exists( screen->GetFileName() ) + && !wxCopyFile( screen->GetFileName(), destFileName.GetFullPath() ) ) + { + errorMsg += wxPrintf( _( "Failed to back up file '%s'.\n" ), screen->GetFileName() ); + } + } + + // Back up the project file. + destFileName = Prj().GetProjectFullName(); + destFileName.SetName( destFileName.GetFullName() ); + destFileName.SetExt( ext ); + + wxLogTrace( "KICAD_TRACE_PATHS", "Backing up file '%s' to file '%s'.", + Prj().GetProjectFullName(), destFileName.GetFullPath() ); + + if( wxFileName::Exists( Prj().GetProjectFullName() ) + && !wxCopyFile( Prj().GetProjectFullName(), destFileName.GetFullPath() ) ) + { + errorMsg += wxPrintf( _( "Failed to back up file '%s'.\n" ), Prj().GetProjectFullName() ); + } + + wxFileName srcFileName; + + // Back up the cache library. + srcFileName.SetPath( Prj().GetProjectPath() ); + srcFileName.SetName( Prj().GetProjectName() + "-cache" ); + srcFileName.SetExt( SchematicLibraryFileExtension ); + + destFileName = srcFileName; + destFileName.SetName( destFileName.GetFullName() ); + destFileName.SetExt( ext ); + + wxLogTrace( "KICAD_TRACE_PATHS", "Backing up file '%s' to file '%s'.", + srcFileName.GetFullPath(), destFileName.GetFullPath() ); + + if( srcFileName.Exists() + && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) + { + errorMsg += wxPrintf( _( "Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() ); + } + + // Back up the rescue library if it exists. + srcFileName.SetName( Prj().GetProjectName() + "-rescue" ); + destFileName.SetName( srcFileName.GetFullName() ); + + wxLogTrace( "KICAD_TRACE_PATHS", "Backing up file '%s' to file '%s'.", + srcFileName.GetFullPath(), destFileName.GetFullPath() ); + + if( srcFileName.Exists() + && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) + { + errorMsg += wxPrintf( _( "Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() ); + } + + // Back up the rescue library document file if it exists. + srcFileName.SetName( Prj().GetProjectName() + "-rescue" ); + srcFileName.SetExt( "dcm" ); + destFileName.SetName( srcFileName.GetFullName() ); + + wxLogTrace( "KICAD_TRACE_PATHS", "Backing up file '%s' to file '%s'.", + srcFileName.GetFullPath(), destFileName.GetFullPath() ); + + if( srcFileName.Exists() + && !wxCopyFile( srcFileName.GetFullPath(), destFileName.GetFullPath() ) ) + { + errorMsg += wxPrintf( _( "Failed to back up file '%s'.\n" ), srcFileName.GetFullPath() ); + } + + if( !errorMsg.IsEmpty() ) + { + errorMsg.Trim(); + DisplayErrorMessage( this, _( "Some of the project files could not be backed up." ), + errorMsg ); + } +} + diff --git a/eeschema/dialogs/dialog_symbol_remap.h b/eeschema/dialogs/dialog_symbol_remap.h index 7fe1bfe6a3..5d8251db01 100644 --- a/eeschema/dialogs/dialog_symbol_remap.h +++ b/eeschema/dialogs/dialog_symbol_remap.h @@ -63,6 +63,18 @@ private: void remapSymbolsToLibTable( REPORTER& aReporter ); bool remapSymbolToLibTable( SCH_COMPONENT* aSymbol ); + + /** + * Backup all of the files that could be modified by the remapping with a .v4 file extension + * in case something goes wrong. + * + * Backup the following: + * - All schematic (*.sch -> *.sch.v4 ) files. + * - The project (*.pro) -> *.pro.v4) file. + * - The cache library (*-cache.lib -> *.-cache.lib.v4) file. + * - The rescue library (*-rescue.lib -> *.rescue.lib.v4) file. + */ + void backupProject(); }; #endif // _DIALOG_SYMBOL_REMAP_H_ diff --git a/eeschema/dialogs/dialog_symbol_remap_base.cpp b/eeschema/dialogs/dialog_symbol_remap_base.cpp index 5f1d839970..2f886fdded 100644 --- a/eeschema/dialogs/dialog_symbol_remap_base.cpp +++ b/eeschema/dialogs/dialog_symbol_remap_base.cpp @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Aug 4 2017) +// C++ code generated with wxFormBuilder (version Nov 22 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "wx_html_report_panel.h" @@ -21,9 +21,8 @@ DIALOG_SYMBOL_REMAP_BASE::DIALOG_SYMBOL_REMAP_BASE( wxWindow* parent, wxWindowID wxBoxSizer* bSizer2; bSizer2 = new wxBoxSizer( wxHORIZONTAL ); - m_staticText1 = new wxStaticText( this, wxID_ANY, _("This schematic currently uses the symbol library look\nup method for loading schematic symbols. KiCad will\nattempt to map the existing symbols to use the new\nsymbol library table. If you choose to skip\nthis step, you will be responsible for manually assigning\nsymbols."), wxDefaultPosition, wxDefaultSize, 0 ); - m_staticText1->Wrap( -1 ); - bSizer2->Add( m_staticText1, 0, wxALL|wxEXPAND, 5 ); + m_htmlCtrl = new wxHtmlWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); + bSizer2->Add( m_htmlCtrl, 4, wxALL|wxEXPAND, 5 ); wxBoxSizer* bSizer3; bSizer3 = new wxBoxSizer( wxVERTICAL ); @@ -38,7 +37,7 @@ DIALOG_SYMBOL_REMAP_BASE::DIALOG_SYMBOL_REMAP_BASE( wxWindow* parent, wxWindowID bSizer2->Add( bSizer3, 1, wxEXPAND, 5 ); - bSizer1->Add( bSizer2, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); + bSizer1->Add( bSizer2, 3, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 ); wxBoxSizer* bSizer4; bSizer4 = new wxBoxSizer( wxVERTICAL ); @@ -49,7 +48,7 @@ DIALOG_SYMBOL_REMAP_BASE::DIALOG_SYMBOL_REMAP_BASE( wxWindow* parent, wxWindowID bSizer4->Add( m_messagePanel, 1, wxEXPAND | wxALL, 5 ); - bSizer1->Add( bSizer4, 1, wxEXPAND, 5 ); + bSizer1->Add( bSizer4, 5, wxEXPAND, 5 ); this->SetSizer( bSizer1 ); diff --git a/eeschema/dialogs/dialog_symbol_remap_base.fbp b/eeschema/dialogs/dialog_symbol_remap_base.fbp index 92ed886039..3343b65fb0 100644 --- a/eeschema/dialogs/dialog_symbol_remap_base.fbp +++ b/eeschema/dialogs/dialog_symbol_remap_base.fbp @@ -96,7 +96,7 @@ 5 wxEXPAND|wxLEFT|wxRIGHT|wxTOP - 0 + 3 bSizer2 @@ -105,8 +105,8 @@ 5 wxALL|wxEXPAND - 0 - + 4 + 1 1 1 @@ -134,7 +134,6 @@ 0 0 wxID_ANY - This schematic currently uses the symbol library look up method for loading schematic symbols. KiCad will attempt to map the existing symbols to use the new symbol library table. If you choose to skip this step, you will be responsible for manually assigning symbols. 0 @@ -142,7 +141,7 @@ 0 1 - m_staticText1 + m_htmlCtrl 1 @@ -152,17 +151,19 @@ Resizable 1 - - + wxHW_SCROLLBAR_AUTO + ; forward_declare 0 - -1 + + + @@ -377,7 +378,7 @@ 5 wxEXPAND - 1 + 5 bSizer4 diff --git a/eeschema/dialogs/dialog_symbol_remap_base.h b/eeschema/dialogs/dialog_symbol_remap_base.h index d75ea084aa..3534a5d7aa 100644 --- a/eeschema/dialogs/dialog_symbol_remap_base.h +++ b/eeschema/dialogs/dialog_symbol_remap_base.h @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Aug 4 2017) +// C++ code generated with wxFormBuilder (version Nov 22 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO "NOT" EDIT THIS FILE! +// PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #ifndef __DIALOG_SYMBOL_REMAP_BASE_H__ @@ -11,16 +11,15 @@ #include #include #include -class DIALOG_SHIM; class WX_HTML_REPORT_PANEL; #include "dialog_shim.h" -#include -#include +#include #include #include #include #include +#include #include #include #include @@ -37,7 +36,7 @@ class DIALOG_SYMBOL_REMAP_BASE : public DIALOG_SHIM private: protected: - wxStaticText* m_staticText1; + wxHtmlWindow* m_htmlCtrl; wxButton* m_buttonRemp; wxButton* m_buttonClose; WX_HTML_REPORT_PANEL* m_messagePanel; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index c6a38495d0..931210b2cb 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -339,10 +339,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // best remapping results. RescueLegacyProject( false ); - // Make backups of current schematics just in case something goes wrong. - for( SCH_SCREEN* screen = schematic.GetFirst(); screen; screen = schematic.GetNext() ) - SaveEEFile( screen, false, CREATE_BACKUP_FILE ); - DIALOG_SYMBOL_REMAP dlgRemap( this ); dlgRemap.ShowQuasiModal();