bool FOOTPRINT_EDIT_FRAME::RevertFootprint() { if( GetScreen()->IsModify() && m_revertModule ) { wxString msg = wxString::Format( _( "Revert \"%s\" to last version saved?" ), GetChars( GetLoadedFPID().GetLibItemName() ) ); if( ConfirmRevertDialog( this, msg ) ) { Clear_Pcb( false ); AddModuleToBoard( (MODULE*) m_revertModule->Clone() ); Zoom_Automatique( false ); Update3DView(); GetScreen()->ClearUndoRedoList(); GetScreen()->ClrModify(); updateView(); m_canvas->Refresh(); return true; } } return false; }
void FOOTPRINT_EDIT_FRAME::restoreLastFootprint() { const wxString& curFootprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME ); const wxString& curNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME ); if( curNickname.Length() && curFootprintName.Length() ) { LIB_ID id; id.SetLibNickname( curNickname ); id.SetLibItemName( curFootprintName ); MODULE* module = loadFootprint( id ); if( module ) AddModuleToBoard( module ); } }
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module( const wxString& aName ) { wxString lastOpenedPathForLoading = m_mruPath; wxConfigBase* cfg = Kiface().KifaceSettings(); if( cfg ) cfg->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading ); wxFileName fn; if( aName != wxT("") ) fn = aName; else fn = getFootprintFilenameFromUser( this, lastOpenedPathForLoading ); if( !fn.IsOk() ) return NULL; FILE* fp = wxFopen( fn.GetFullPath(), wxT( "rt" ) ); if( !fp ) { wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( fn.GetFullPath() ) ); DisplayError( this, msg ); return NULL; } if( cfg ) // Save file path { lastOpenedPathForLoading = fn.GetPath(); cfg->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading ); } wxString moduleName; IO_MGR::PCB_FILE_T fileType = detect_file_type( fp, fn.GetFullPath(), &moduleName ); if( fileType == IO_MGR::FILE_TYPE_NONE ) { DisplayError( this, FMT_NOT_MODULE ); return NULL; } MODULE* module = NULL; try { module = try_load_footprint( fn, fileType, moduleName ); if( !module ) { wxString msg = wxString::Format( FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetFullPath() ) ); DisplayError( this, msg ); return NULL; } } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.What() ); // if the footprint is not loaded, exit. // However, even if an error happens, it can be loaded, because in KICAD and GPCB format, // a fp library is a set of separate files, and the error(s) are not necessary when // reading the selected file if( !module ) return NULL; } module->SetFPID( LIB_ID( wxEmptyString, moduleName ) ); // Insert footprint in list AddModuleToBoard( module ); // Display info : SetMsgPanel( module ); PlaceModule( module, NULL ); if( IsGalCanvasActive() ) module->SetPosition( wxPoint( 0, 0 ) ); GetBoard()->m_Status_Pcb = 0; GetBoard()->BuildListOfNets(); updateView(); return module; }