void SCH_SCREEN::CheckComponentsToPartsLinks() { // Initialize or reinitialize the pointer to the LIB_PART for each component // found in m_drawList, but only if needed (change in lib or schematic) // therefore the calculation time is usually very low. if( m_drawList.GetCount() ) { PART_LIBS* libs = Prj().SchLibs(); int mod_hash = libs->GetModifyHash(); // Must we resolve? if( m_modification_sync != mod_hash ) { SCH_TYPE_COLLECTOR c; c.Collect( GetDrawItems(), SCH_COLLECTOR::ComponentsOnly ); SCH_COMPONENT::ResolveAll( c, libs ); m_modification_sync = mod_hash; // note the last mod_hash // guard against unneeded runs through this code path by printing trace DBG(printf("%s: resync-ing %s\n", __func__, TO_UTF8( GetFileName() ) );) }
void LIB_VIEW_FRAME::DisplayLibInfos() { PART_LIBS* libs = Prj().SchLibs(); if( libs ) { PART_LIB* lib = libs->FindLibrary( m_libraryName ); wxString title = wxString::Format( "Library Browser \u2014 %s", lib ? lib->GetFullFileName() : "no library selected" ); SetTitle( title ); } }
// Used in DataBaseGetName: this is a callback function for EDA_LIST_DIALOG // to display keywords and description of a component void DisplayCmpDocAndKeywords( wxString& aName, void* aData ) { PART_LIBS* libs = (PART_LIBS*) aData; wxASSERT( libs ); LIB_ALIAS* part = libs->FindLibraryEntry( aName ); if( !part ) return; aName = wxT( "Description: " ) + part->GetDescription(); aName += wxT( "\nKey Words: " ) + part->GetKeyWords(); }
bool SCH_EDIT_FRAME::IsSearchCacheObsolete( const SCH_FIND_REPLACE_DATA& aSearchCriteria ) { PART_LIBS* libs = Prj().SchLibs(); int mod_hash = libs->GetModifyHash(); // the cache is obsolete whenever any library changes. if( mod_hash != m_foundItems.GetLibHash() ) { m_foundItems.SetForceSearch(); m_foundItems.SetLibHash( mod_hash ); return true; } else if( m_foundItems.IsSearchRequired( aSearchCriteria ) ) return true; else return false; }
/** * Function insert_library * inserts a library into the project and refreshes libraries. * * @param aProject - project that will be modified * @param aLibrary - PART_LIB to add * @param aIndex - index in the list at which the library is to be inserted * * @return true on success, false on failure */ static bool insert_library( PROJECT *aProject, PART_LIB *aLibrary, size_t aIndex ) throw( boost::bad_pointer ) { wxArrayString libNames; wxString libPaths; wxString libName = aLibrary->GetName(); PART_LIBS *libs = dynamic_cast<PART_LIBS*>( aProject->GetElem( PROJECT::ELEM_SCH_PART_LIBS ) ); if( !libs ) { libs = new PART_LIBS(); aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs ); } try { PART_LIBS::LibNamesAndPaths( aProject, false, &libPaths, &libNames ); // Make sure the library is not already in the list while( libNames.Index( libName ) != wxNOT_FOUND ) libNames.Remove( libName ); // Add the library to the list and save libNames.Insert( libName, aIndex ); PART_LIBS::LibNamesAndPaths( aProject, true, &libPaths, &libNames ); } catch( const IO_ERROR& ) { // Could not get or save the current libraries. return false; } // Save the old libraries in case there is a problem after clear(). We'll // put them back in. boost::ptr_vector<PART_LIB> libsSave; libsSave.transfer( libsSave.end(), libs->begin(), libs->end(), *libs ); aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, NULL ); libs = new PART_LIBS(); try { libs->LoadAllLibraries( aProject ); } catch( const PARSE_ERROR& ) { // Some libraries were not found. There's no point in showing the error, // because it was already shown. Just don't do anything. } catch( const IO_ERROR& ) { // Restore the old list libs->clear(); libs->transfer( libs->end(), libsSave.begin(), libsSave.end(), libsSave ); return false; } aProject->SetElem( PROJECT::ELEM_SCH_PART_LIBS, libs ); return true; }
bool DIALOG_SYMBOL_REMAP::remapSymbolToLibTable( SCH_COMPONENT* aSymbol ) { wxCHECK_MSG( aSymbol != NULL, false, "Null pointer passed to remapSymbolToLibTable." ); wxCHECK_MSG( aSymbol->GetLibId().GetLibNickname().empty(), false, "Cannot remap symbol that is already mapped." ); wxCHECK_MSG( !aSymbol->GetLibId().GetLibItemName().empty(), false, "The symbol LIB_ID name is empty." ); PART_LIBS* libs = Prj().SchLibs(); for( PART_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it ) { // Ignore the cache library. if( it->IsCache() ) continue; LIB_ALIAS* alias = it->FindAlias( aSymbol->GetLibId().GetLibItemName().wx_str() ); // Found in the same library as the old look up method assuming the user didn't // change the libraries or library ordering since the last time the schematic was // loaded. if( alias ) { // Find the same library in the symbol library table using the full path and file name. wxString libFileName = it->GetFullFileName(); const LIB_TABLE_ROW* row = Prj().SchSymbolLibTable()->FindRowByURI( libFileName ); if( row ) { LIB_ID id = aSymbol->GetLibId(); id.SetLibNickname( row->GetNickName() ); // Don't resolve symbol library links now. aSymbol->SetLibId( id, nullptr, nullptr ); return true; } } } return false; }
size_t DIALOG_SYMBOL_REMAP::getLibsNotInGlobalSymbolLibTable( std::vector< PART_LIB* >& aLibs ) { PART_LIBS* libs = Prj().SchLibs(); for( PART_LIBS_BASE::iterator it = libs->begin(); it != libs->end(); ++it ) { // Ignore the cache library. if( it->IsCache() ) continue; // Check for the obvious library name. wxString libFileName = it->GetFullFileName(); if( !SYMBOL_LIB_TABLE::GetGlobalLibTable().FindRowByURI( libFileName ) ) aLibs.push_back( &(*it) ); } return aLibs.size(); }
void SCH_SCREEN::BuildSchCmpLinksToLibCmp() { // Initialize or reinitialize the pointer to the LIB_PART for each component // found in m_drawList, but only if needed (change in lib or schematic) // therefore the calculation time is usually very low. if( m_drawList.GetCount() ) { PART_LIBS* libs = Prj().SchLibs(); int mod_hash = libs->GetModifyHash(); // Must we resolve? if( m_modification_sync != mod_hash ) { SCH_TYPE_COLLECTOR c; c.Collect( GetDrawItems(), SCH_COLLECTOR::ComponentsOnly ); SCH_COMPONENT::ResolveAll( c, libs ); m_modification_sync = mod_hash; // note the last mod_hash } } }
bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName ) { SCH_SCREENS screens; PART_LIBS* libs = Prj().SchLibs(); std::unique_ptr<PART_LIB> libCache( new PART_LIB( LIBRARY_TYPE_EESCHEMA, aFileName ) ); libCache->SetCache(); /* examine all screens (not sheets) used and build the list of components * found in lib. * Complex hierarchies are not a problem because we just want * to know used components in libraries */ for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) { for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() ) { if( item->Type() != SCH_COMPONENT_T ) continue; SCH_COMPONENT* component = (SCH_COMPONENT*) item; // If not already saved in the new cache, put it: if( !libCache->FindEntry( component->GetPartName() ) ) { if( LIB_PART* part = libs->FindLibPart( component->GetPartName() ) ) { // AddPart() does first clone the part before adding. libCache->AddPart( part ); } } } } try { FILE_OUTPUTFORMATTER formatter( aFileName ); if( !libCache->Save( formatter ) ) { wxString msg = wxString::Format( _( "An error occurred attempting to save component library '%s'." ), GetChars( aFileName ) ); DisplayError( this, msg ); return false; } } catch( ... /* IO_ERROR ioe */ ) { wxString msg = wxString::Format( _( "Failed to create component library file '%s'" ), GetChars( aFileName ) ); DisplayError( this, msg ); return false; } return true; }