bool PCB_EDIT_FRAME::Files_io_from_id( int id ) { wxString msg; // If an edit is in progress, stop it. // For something else than save, get rid of current tool. if( id == ID_SAVE_BOARD ) m_canvas->EndMouseCapture( -1, m_canvas->GetDefaultCursor() ); else m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); switch( id ) { case ID_LOAD_FILE: { int open_ctl = 0; wxString fileName = Prj().AbsolutePath( GetBoard()->GetFileName() ); return AskLoadBoardFileName( this, &open_ctl, &fileName, true ) && OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl ); } case ID_IMPORT_NON_KICAD_BOARD: { int open_ctl = 1; wxString fileName; // = Prj().AbsolutePath( GetBoard()->GetFileName() ); return AskLoadBoardFileName( this, &open_ctl, &fileName, false ) && OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl ); } case ID_MENU_READ_BOARD_BACKUP_FILE: case ID_MENU_RECOVER_BOARD_AUTOSAVE: { wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() ); wxFileName fn = currfn; if( id == ID_MENU_RECOVER_BOARD_AUTOSAVE ) { wxString rec_name = GetAutoSaveFilePrefix() + fn.GetName(); fn.SetName( rec_name ); } else { wxString backup_ext = fn.GetExt() + GetBackupSuffix(); fn.SetExt( backup_ext ); } if( !fn.FileExists() ) { msg.Printf( _( "Recovery file \"%s\" not found." ), fn.GetFullPath() ); DisplayInfoMessage( this, msg ); return false; } msg.Printf( _( "OK to load recovery or backup file \"%s\"" ), fn.GetFullPath() ); if( !IsOK( this, msg ) ) return false; GetScreen()->ClrModify(); // do not prompt the user for changes if( OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) ) ) { // Re-set the name since name or extension was changed GetBoard()->SetFileName( currfn.GetFullPath() ); UpdateTitle(); return true; } return false; } case ID_APPEND_FILE: wxFAIL_MSG( "OBSOLETE! Should have gone though modern toolset." ); case ID_NEW_BOARD: { if( !Clear_Pcb( true ) ) return false; wxFileName fn( wxStandardPaths::Get().GetDocumentsDir(), wxT( "noname" ), ProjectFileExtension ); Prj().SetProjectFullName( fn.GetFullPath() ); fn.SetExt( PcbFileExtension ); GetBoard()->SetFileName( fn.GetFullPath() ); onBoardLoaded(); OnModify(); return true; } case ID_SAVE_BOARD: if( !GetBoard()->GetFileName().IsEmpty() ) return SavePcbFile( Prj().AbsolutePath( GetBoard()->GetFileName() ) ); // Fall through case ID_COPY_BOARD_AS: case ID_SAVE_BOARD_AS: { wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() ); wxFileName fn( pro_dir, _( "noname" ), KiCadPcbFileExtension ); wxString filename = fn.GetFullPath(); if( AskSaveBoardFileName( this, &filename ) ) { if( id == ID_COPY_BOARD_AS ) return SavePcbCopy( filename ); else return SavePcbFile( filename, NO_BACKUP_FILE ); } return false; } default: wxLogDebug( wxT( "File_io Internal Error" ) ); return false; } }
void PCB_EDIT_FRAME::Files_io_from_id( int id ) { wxString msg; // If an edition is in progress, stop it. // For something else than save, get rid of current tool. if( id == ID_SAVE_BOARD ) m_canvas->EndMouseCapture( -1, m_canvas->GetDefaultCursor() ); else m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); switch( id ) { case ID_LOAD_FILE: { // LoadOnePcbFile( GetBoard()->GetFileName(), append=false, aForceFileDialog=true ); int open_ctl; wxString fileName = Prj().AbsolutePath( GetBoard()->GetFileName() ); if( !AskLoadBoardFileName( this, &open_ctl, &fileName ) ) return; OpenProjectFiles( std::vector<wxString>( 1, fileName ), open_ctl ); } break; case ID_MENU_READ_BOARD_BACKUP_FILE: case ID_MENU_RECOVER_BOARD_AUTOSAVE: { wxFileName currfn = Prj().AbsolutePath( GetBoard()->GetFileName() ); wxFileName fn = currfn; if( id == ID_MENU_RECOVER_BOARD_AUTOSAVE ) { wxString rec_name = wxString( autosavePrefix ) + fn.GetName(); fn.SetName( rec_name ); } else { wxString backup_ext = fn.GetExt()+ backupSuffix; fn.SetExt( backup_ext ); } if( !fn.FileExists() ) { msg.Printf( _( "Recovery file '%s' not found." ), GetChars( fn.GetFullPath() ) ); DisplayInfoMessage( this, msg ); break; } msg.Printf( _( "OK to load recovery or backup file '%s'" ), GetChars(fn.GetFullPath() ) ); if( !IsOK( this, msg ) ) break; GetScreen()->ClrModify(); // do not prompt the user for changes // LoadOnePcbFile( fn.GetFullPath(), aAppend=false, aForceFileDialog=false ); OpenProjectFiles( std::vector<wxString>( 1, fn.GetFullPath() ) ); // Re-set the name since name or extension was changed GetBoard()->SetFileName( currfn.GetFullPath() ); UpdateTitle(); } break; case ID_APPEND_FILE: { int open_ctl; wxString fileName; if( !AskLoadBoardFileName( this, &open_ctl, &fileName, true ) ) break; AppendBoardFile( fileName, open_ctl ); m_canvas->Refresh(); } break; case ID_NEW_BOARD: { if( !Clear_Pcb( true ) ) break; wxFileName fn( wxStandardPaths::Get().GetDocumentsDir(), wxT( "noname" ), ProjectFileExtension ); Prj().SetProjectFullName( fn.GetFullPath() ); fn.SetExt( PcbFileExtension ); GetBoard()->SetFileName( fn.GetFullPath() ); UpdateTitle(); ReCreateLayerBox(); break; } case ID_SAVE_BOARD: if( ! GetBoard()->GetFileName().IsEmpty() ) { SavePcbFile( Prj().AbsolutePath( GetBoard()->GetFileName() ) ); break; } // Fall through case ID_COPY_BOARD_AS: case ID_SAVE_BOARD_AS: { wxString pro_dir = wxPathOnly( Prj().GetProjectFullName() ); wxFileName fn( pro_dir, _( "noname" ), KiCadPcbFileExtension ); wxString filename = fn.GetFullPath(); if( AskSaveBoardFileName( this, &filename ) ) { if( id == ID_COPY_BOARD_AS ) SavePcbCopy( filename ); else SavePcbFile( filename, NO_BACKUP_FILE ); } } break; default: DisplayError( this, wxT( "File_io Internal Error" ) ); break; } }