void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event ) { FOOTPRINT_ALIAS_LIST aliases; FOOTPRINT_ALIAS* alias; COMPONENT* component; wxFileName fn; wxString msg, tmp; char Line[1024]; FILE* file; size_t ii; SEARCH_STACK& search = Kiface().KifaceSearch(); if( m_netlist.IsEmpty() ) return; // Find equivalents in all available files. for( ii = 0; ii < m_AliasLibNames.GetCount(); ii++ ) { fn = m_AliasLibNames[ii]; if( !fn.HasExt() ) { fn.SetExt( FootprintAliasFileExtension ); // above fails if filename has more than one point } else { fn.SetExt( fn.GetExt() + wxT( "." ) + FootprintAliasFileExtension ); } tmp = search.FindValidPath( fn.GetFullPath() ); if( !tmp ) { msg.Printf( _( "Footprint alias library file '%s' could not be found in the " "default search paths." ), GetChars( fn.GetFullName() ) ); wxMessageBox( msg, FMT_TITLE_LIB_LOAD_ERROR, wxOK | wxICON_ERROR ); continue; } file = wxFopen( tmp, wxT( "rt" ) ); if( file == NULL ) { msg.Printf( _( "Error opening alias library '%s'." ), GetChars( tmp ) ); wxMessageBox( msg, FMT_TITLE_LIB_LOAD_ERROR, wxOK | wxICON_ERROR ); continue; } while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL ) { char* text = Line; wxString value, footprint, wtext = FROM_UTF8( Line ); value = GetQuotedText( wtext ); if( text == NULL || ( *text == 0 ) || value.IsEmpty() ) continue; footprint = GetQuotedText( wtext ); if( footprint.IsEmpty() ) continue; value.Replace( wxT( " " ), wxT( "_" ) ); alias = new FOOTPRINT_ALIAS(); alias->m_Name = value; alias->m_FootprintName = footprint; aliases.push_back( alias ); } fclose( file ); } // Display the number of footprint aliases. msg.Printf( _( "%d footprint aliases found." ), aliases.size() ); SetStatusText( msg, 0 ); m_skipComponentSelect = true; ii = 0; for( unsigned kk = 0; kk < m_netlist.GetCount(); kk++ ) { component = m_netlist.GetComponent( kk ); bool found = false; m_compListBox->SetSelection( ii++, true ); if( !component->GetFPID().empty() ) continue; BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases ) { if( alias.m_Name.CmpNoCase( component->GetValue() ) != 0 ) continue; // filter alias so one can use multiple aliases (for polar and // nonpolar caps for example) const FOOTPRINT_INFO *module = m_footprints.GetModuleInfo( alias.m_FootprintName ); if( module ) { size_t filtercount = component->GetFootprintFilters().GetCount(); found = ( 0 == filtercount ); // if no entries, do not filter for( size_t jj = 0; jj < filtercount && !found; jj++ ) { found = module->GetFootprintName().Matches( component->GetFootprintFilters()[jj] ); } } else { msg.Printf( _( "Component %s: footprint %s not found in any of the project " "footprint libraries." ), GetChars( component->GetReference() ), GetChars( alias.m_FootprintName ) ); wxMessageBox( msg, _( "CvPcb Error" ), wxOK | wxICON_ERROR, this ); } if( found ) { SetNewPkg( alias.m_FootprintName ); break; } } // obviously the last chance: there's only one filter matching one footprint if( !found && 1 == component->GetFootprintFilters().GetCount() ) { // we do not need to analyse wildcards: single footprint do not // contain them and if there are wildcards it just will not match any const FOOTPRINT_INFO* module = m_footprints.GetModuleInfo( component->GetFootprintFilters()[0] ); if( module ) { SetNewPkg( component->GetFootprintFilters()[0] ); } } } m_skipComponentSelect = false; }
// read the .equ files and populate the list of equivalents int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wxString * aErrorMessages ) { char Line[1024]; int error_count = 0; FILE* file; wxFileName fn; wxString tmp, error_msg; SEARCH_STACK& search = Kiface().KifaceSearch(); // Find equivalences in all available files, and populates the // equiv_List with all equivalences found in .equ files for( unsigned ii = 0; ii < m_EquFilesNames.GetCount(); ii++ ) { fn = wxExpandEnvVars( m_EquFilesNames[ii] ); tmp = search.FindValidPath( fn.GetFullPath() ); if( !tmp ) { error_count++; if( aErrorMessages ) { error_msg.Printf( _( "Equivalence file '%s' could not be found in the " "default search paths." ), GetChars( fn.GetFullName() ) ); if( ! aErrorMessages->IsEmpty() ) *aErrorMessages << wxT("\n\n"); *aErrorMessages += error_msg; } continue; } file = wxFopen( tmp, wxT( "rt" ) ); if( file == NULL ) { error_count++; if( aErrorMessages ) { error_msg.Printf( _( "Error opening equivalence file '%s'." ), GetChars( tmp ) ); if( ! aErrorMessages->IsEmpty() ) *aErrorMessages << wxT("\n\n"); *aErrorMessages += error_msg; } continue; } while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL ) { char* text = Line; wxString value, footprint, wtext = FROM_UTF8( Line ); value = GetQuotedText( wtext ); if( text == NULL || ( *text == 0 ) || value.IsEmpty() ) continue; footprint = GetQuotedText( wtext ); if( footprint.IsEmpty() ) continue; value.Replace( wxT( " " ), wxT( "_" ) ); FOOTPRINT_EQUIVALENCE* equivItem = new FOOTPRINT_EQUIVALENCE(); equivItem->m_ComponentValue = value; equivItem->m_FootprintFPID = footprint; aList.push_back( equivItem ); } fclose( file ); } return error_count; }