bool operator<( const CMP_LIBRARY& aItem1, const CMP_LIBRARY& aItem2 ) { /* The cache library always is sorted to the end of the library list. */ if( aItem2.IsCache() ) return true; if( aItem1.IsCache() ) return false; // If the sort order array isn't set, then sort alphabetically except. if( CMP_LIBRARY::GetSortOrder().IsEmpty() ) return Cmp_KEEPCASE( aItem1.GetName(), aItem2.GetName() ) < 0; int i1 = CMP_LIBRARY::GetSortOrder().Index( aItem1.GetName(), false ); int i2 = CMP_LIBRARY::GetSortOrder().Index( aItem2.GetName(), false ); if( i1 == wxNOT_FOUND && i2 == wxNOT_FOUND ) return true; if( i1 == wxNOT_FOUND && i2 != wxNOT_FOUND ) return false; if( i1 != wxNOT_FOUND && i2 == wxNOT_FOUND ) return true; return ( i1 - i2 ) < 0; }
void SCH_EDIT_FRAME::backAnnotateFootprints( const std::string& aChangedSetOfReferences ) throw( IO_ERROR, boost::bad_pointer ) { // Build a flat list of components in schematic: SCH_REFERENCE_LIST refs; SCH_SHEET_LIST sheets( g_RootSheet ); bool isChanged = false; sheets.GetComponents( Prj().SchLibs(), refs, false ); DSNLEXER lexer( aChangedSetOfReferences, FROM_UTF8( __func__ ) ); PTREE doc; try { Scan( &doc, &lexer ); #if defined(DEBUG) && 0 STRING_FORMATTER sf; Format( &sf, 0, 0, doc ); printf( "%s: '%s'\n", __func__, sf.GetString().c_str() ); #endif CPTREE& back_anno = doc.get_child( "back_annotation" ); wxString footprint; for( PTREE::const_iterator ref = back_anno.begin(); ref != back_anno.end(); ++ref ) { wxASSERT( ref->first == "ref" ); wxString reference = (UTF8&) ref->second.front().first; // Ensure the "fpid" node contains a footprint name, // and get it if exists if( ref->second.get_child( "fpid" ).size() ) { wxString tmp = (UTF8&) ref->second.get_child( "fpid" ).front().first; footprint = tmp; } else footprint.Empty(); // DBG( printf( "%s: ref:%s fpid:%s\n", __func__, TO_UTF8( reference ), TO_UTF8( footprint ) ); ) // Search the component in the flat list for( unsigned ii = 0; ii < refs.GetCount(); ++ii ) { if( Cmp_KEEPCASE( reference, refs[ii].GetRef() ) == 0 ) { // We have found a candidate. // Note: it can be not unique (multiple parts per package) // So we *do not* stop the search here SCH_COMPONENT* component = refs[ii].GetComp(); SCH_FIELD* fpfield = component->GetField( FOOTPRINT ); const wxString& oldfp = fpfield->GetText(); if( !oldfp && fpfield->IsVisible() ) { fpfield->SetVisible( false ); } // DBG( printf("%s: ref:%s fpid:%s\n", __func__, TO_UTF8( refs[ii].GetRef() ), TO_UTF8( footprint ) );) if( oldfp != footprint ) isChanged = true; fpfield->SetText( footprint ); } } } } catch( const PTREE_ERROR& ex ) { // remap the exception to something the caller is likely to understand. THROW_IO_ERROR( ex.what() ); } if( isChanged ) OnModify(); }
bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( const wxString& aFullFilename, bool aForceVisibilityState, bool aVisibilityState ) { // Build a flat list of components in schematic: SCH_REFERENCE_LIST referencesList; SCH_SHEET_LIST sheetList( g_RootSheet ); sheetList.GetComponents( Prj().SchLibs(), referencesList, false ); FILE* cmpFile = wxFopen( aFullFilename, wxT( "rt" ) ); if( cmpFile == NULL ) return false; // cmpFileReader dtor will close cmpFile FILE_LINE_READER cmpFileReader( cmpFile, aFullFilename ); // Now, for each component found in file, // replace footprint field value by the new value: wxString reference; wxString footprint; wxString buffer; wxString value; while( cmpFileReader.ReadLine() ) { buffer = FROM_UTF8( cmpFileReader.Line() ); if( !buffer.StartsWith( wxT( "BeginCmp" ) ) ) continue; // Begin component description. reference.Empty(); footprint.Empty(); while( cmpFileReader.ReadLine() ) { buffer = FROM_UTF8( cmpFileReader.Line() ); if( buffer.StartsWith( wxT( "EndCmp" ) ) ) break; // store string value, stored between '=' and ';' delimiters. value = buffer.AfterFirst( '=' ); value = value.BeforeLast( ';' ); value.Trim(true); value.Trim(false); if( buffer.StartsWith( wxT( "Reference" ) ) ) { reference = value; } else if( buffer.StartsWith( wxT( "IdModule" ) ) ) { footprint = value; } } // A block is read: initialize the footprint field of the corresponding component // if the footprint name is not empty if( reference.IsEmpty() ) continue; // Search the component in the flat list for( unsigned ii = 0; ii < referencesList.GetCount(); ii++ ) { if( Cmp_KEEPCASE( reference, referencesList[ii].GetRef() ) == 0 ) { // We have found a candidate. // Note: it can be not unique (multiple units per part) // So we *do not* stop the search here SCH_COMPONENT* component = referencesList[ii].GetComp(); SCH_FIELD* fpfield = component->GetField( FOOTPRINT ); fpfield->SetText( footprint ); if( aForceVisibilityState ) { component->GetField( FOOTPRINT )->SetVisible( aVisibilityState ); } } } } return true; }
bool operator==( const CMP_LIBRARY& aLibrary, const wxString& aName ) { // See our header class_libentry.h for function Cmp_KEEPCASE(). return Cmp_KEEPCASE( aLibrary.GetName(), aName ) == 0; }