2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file autosel.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Routines for automatic selection of modules. */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-04-21 17:56:27 +00:00
|
|
|
#include "kicad_string.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#define QUOTE '\''
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
class FOOTPRINT_ALIAS
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-04-05 20:49:15 +00:00
|
|
|
int m_Type;
|
|
|
|
wxString m_Name;
|
2009-05-06 11:55:36 +00:00
|
|
|
wxString m_FootprintName;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
FOOTPRINT_ALIAS() { m_Type = 0; }
|
2009-04-05 20:49:15 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
typedef boost::ptr_vector< FOOTPRINT_ALIAS > FOOTPRINT_ALIAS_LIST;
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
|
|
|
* read the string between quotes and put it in aTarget
|
|
|
|
* put text in aTarget
|
|
|
|
* return a pointer to the last read char (the second quote if Ok)
|
|
|
|
*/
|
2011-06-10 14:33:52 +00:00
|
|
|
wxString GetQuotedText( wxString & text )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2011-06-10 14:33:52 +00:00
|
|
|
int i = text.Find( QUOTE );
|
|
|
|
if( wxNOT_FOUND == i ) return wxT( "" );
|
|
|
|
wxString shrt = text.Mid( i + 1 );
|
|
|
|
i = shrt.Find( QUOTE );
|
|
|
|
if( wxNOT_FOUND == i ) return wxT( "" );
|
|
|
|
text = shrt.Mid( i + 1 );
|
|
|
|
return shrt.Mid( 0, i );
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
FOOTPRINT_ALIAS_LIST aliases;
|
|
|
|
FOOTPRINT_ALIAS* alias;
|
|
|
|
wxFileName fn;
|
|
|
|
wxString msg, tmp;
|
|
|
|
char Line[1024];
|
|
|
|
FILE* file;
|
|
|
|
size_t ii;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
if( m_components.empty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Find equivalents in all available files. */
|
2009-04-23 15:02:18 +00:00
|
|
|
for( ii = 0; ii < m_AliasLibNames.GetCount(); ii++ )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
fn = m_AliasLibNames[ii];
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2011-06-16 14:40:58 +00:00
|
|
|
if( !fn.HasExt() ) {
|
|
|
|
fn.SetExt( FootprintAliasFileExtension );
|
|
|
|
// above fails if filename have more than one point
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fn.SetExt( fn.GetExt() + wxT( "." ) + FootprintAliasFileExtension );
|
|
|
|
}
|
2009-04-08 18:06:22 +00:00
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "Footprint alias library file <%s> could not be \
|
|
|
|
found in the default search paths." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullName() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = wxFopen( tmp, wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( file == NULL )
|
|
|
|
{
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "Error opening alias library <%s>." ), GetChars( tmp ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
char* text = Line;
|
2011-06-10 14:33:52 +00:00
|
|
|
wxString value, footprint, wtext = FROM_UTF8( Line );
|
2009-05-06 11:55:36 +00:00
|
|
|
|
2011-06-10 14:33:52 +00:00
|
|
|
value = GetQuotedText( wtext );
|
2009-04-21 17:56:27 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( text == NULL || ( *text == 0 ) || value.IsEmpty() )
|
2009-04-21 17:56:27 +00:00
|
|
|
continue;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-06-10 14:33:52 +00:00
|
|
|
footprint = GetQuotedText( wtext );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( footprint.IsEmpty() )
|
|
|
|
continue;
|
2009-04-21 17:56:27 +00:00
|
|
|
|
2011-06-10 14:33:52 +00:00
|
|
|
value.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
alias = new FOOTPRINT_ALIAS();
|
|
|
|
alias->m_Name = value;
|
|
|
|
alias->m_FootprintName = footprint;
|
|
|
|
aliases.push_back( alias );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( file );
|
|
|
|
}
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Display the number of footprint aliases. */
|
2009-05-06 11:55:36 +00:00
|
|
|
msg.Printf( _( "%d footprint aliases found." ), aliases.size() );
|
2009-04-21 17:56:27 +00:00
|
|
|
SetStatusText( msg, 0 );
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
ii = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-11-29 15:05:01 +00:00
|
|
|
m_ListCmp->SetSelection( ii++, true );
|
2009-05-06 11:55:36 +00:00
|
|
|
|
|
|
|
if( !component.m_Module.IsEmpty() )
|
|
|
|
continue;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2011-06-10 14:33:52 +00:00
|
|
|
bool found = false;
|
2011-08-29 19:50:05 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( alias.m_Name.CmpNoCase( component.m_Value ) != 0 )
|
|
|
|
continue;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2011-08-29 19:50:05 +00:00
|
|
|
/* filter alias so one can use multiple aliases (for polar and nonpolar caps for
|
|
|
|
* example) */
|
2011-06-10 14:33:52 +00:00
|
|
|
FOOTPRINT_INFO *module = m_footprints.GetModuleInfo( alias.m_FootprintName );
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
size_t filtercount = component.m_FootprintFilter.GetCount();
|
|
|
|
found = ( 0 == filtercount ); // if no entries, do not filter
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2011-06-12 16:38:43 +00:00
|
|
|
for( size_t jj = 0; jj < filtercount && !found; jj++ )
|
2011-06-10 14:33:52 +00:00
|
|
|
{
|
|
|
|
found = module->m_Module.Matches( component.m_FootprintFilter[jj] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-05-06 11:55:36 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "Component %s: footprint %s not found in \
|
|
|
|
any of the project footprint libraries." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( component.m_Reference ),
|
|
|
|
GetChars( alias.m_FootprintName ) );
|
2011-08-29 19:50:05 +00:00
|
|
|
wxMessageBox( msg, _( "CvPcb Error" ), wxOK | wxICON_ERROR,
|
2009-05-06 11:55:36 +00:00
|
|
|
this );
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2011-06-10 14:33:52 +00:00
|
|
|
if( found )
|
|
|
|
{
|
|
|
|
SetNewPkg( alias.m_FootprintName );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|