void FOOTPRINT_INFO::load() { FP_LIB_TABLE* fptable = m_owner->GetTable(); wxASSERT( fptable ); std::auto_ptr<MODULE> m( fptable->FootprintLoad( m_nickname, m_fpname ) ); if( m.get() == NULL ) // Should happen only with malformed/broken libraries { m_pad_count = 0; m_unique_pad_count = 0; } else { m_pad_count = m->GetPadCount( DO_NOT_INCLUDE_NPTH ); m_unique_pad_count = m->GetUniquePadCount( DO_NOT_INCLUDE_NPTH ); m_keywords = m->GetKeywords(); m_doc = m->GetDescription(); // tell ensure_loaded() I'm loaded. m_loaded = true; } }
bool FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary( const wxString& aLibrary, MODULE* aModule, bool aOverwrite, bool aDisplayDialog ) { if( aModule == NULL ) return false; SetMsgPanel( aModule ); // Legacy libraries are readable, but modifying legacy format is not allowed // So prompt the user if he try to add/replace a footprint in a legacy lib wxString libfullname = Prj().PcbFootprintLibs()->FindRow( aLibrary )->GetFullURI(); IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libfullname ); if( piType == IO_MGR::LEGACY ) { DisplayInfoMessage( this, INFO_LEGACY_LIB_WARN_EDIT ); return false; } // Ask what to use as the footprint name in the library wxString footprintName = aModule->GetFPID().GetFootprintName(); if( aDisplayDialog ) { wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName ); if( dlg.ShowModal() != wxID_OK ) return false; // canceled by user footprintName = dlg.GetValue(); footprintName.Trim( true ); footprintName.Trim( false ); if( footprintName.IsEmpty() ) return false; if( ! MODULE::IsLibNameValid( footprintName ) ) { wxString msg = wxString::Format( _("Error:\none of invalid chars '%s' found\nin '%s'" ), MODULE::StringLibNameInvalidChars( true ), GetChars( footprintName ) ); DisplayError( NULL, msg ); return false; } aModule->SetFPID( FPID( footprintName ) ); } // Ensure this footprint has a libname if( footprintName.IsEmpty() ) { footprintName = wxT("noname"); aModule->SetFPID( FPID( footprintName ) ); } bool module_exists = false; try { FP_LIB_TABLE* tbl = Prj().PcbFootprintLibs(); MODULE* m = tbl->FootprintLoad( aLibrary, footprintName ); if( m ) { delete m; module_exists = true; // an existing footprint is found in current lib if( aDisplayDialog ) { wxString msg = wxString::Format( FMT_MOD_EXISTS, footprintName.GetData(), aLibrary.GetData() ); SetStatusText( msg ); } if( !aOverwrite ) { // Do not save the given footprint: an old one exists return true; } } // this always overwrites any existing footprint, but should yell on its // own if the library or footprint is not writable. tbl->FootprintSave( aLibrary, aModule ); } catch( const IO_ERROR& ioe ) { DisplayError( this, ioe.errorText ); return false; } if( aDisplayDialog ) { wxString fmt = module_exists ? _( "Component [%s] replaced in '%s'" ) : _( "Component [%s] added in '%s'" ); wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibrary.GetData() ); SetStatusText( msg ); } return true; }