2009-04-05 20:49:15 +00:00
|
|
|
/**********************/
|
|
|
|
/* CVPCB: 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"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.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
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
|
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)
|
|
|
|
*/
|
|
|
|
char * ReadQuotedText(wxString & aTarget, char * aText)
|
|
|
|
{
|
|
|
|
// search the first quote:
|
|
|
|
for( ; *aText != 0; aText++ )
|
|
|
|
{
|
|
|
|
if( *aText == QUOTE )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( *aText == 0 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
aText++;
|
|
|
|
for(; *aText != 0; aText++ )
|
|
|
|
{
|
|
|
|
if( *aText == QUOTE )
|
|
|
|
break;
|
|
|
|
aTarget.Append(*aText);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aText;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
|
|
|
* Called by the automatic association button
|
|
|
|
* Read *.equ files to try to find corresponding footprint
|
|
|
|
* for each component that is not already linked to a footprint ( a "free"
|
|
|
|
* component )
|
2009-04-21 17:56:27 +00:00
|
|
|
* format of a line:
|
|
|
|
* 'cmp_ref' 'footprint_name'
|
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];
|
|
|
|
fn.SetExt( 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;
|
|
|
|
wxString value, footprint;
|
|
|
|
|
|
|
|
text = ReadQuotedText( value, text );
|
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
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
text++;
|
|
|
|
text = ReadQuotedText( footprint, text );
|
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
|
|
|
|
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-21 17:56:27 +00:00
|
|
|
text++;
|
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
|
|
|
{
|
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
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( FOOTPRINT& footprint, m_footprints )
|
|
|
|
{
|
|
|
|
if( alias.m_FootprintName.CmpNoCase( footprint.m_Module ) == 0 )
|
2009-04-23 15:02:18 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
SetNewPkg( footprint.m_Module );
|
|
|
|
break;
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2009-05-06 11:55:36 +00:00
|
|
|
}
|
2009-04-23 15:02:18 +00:00
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
if( component.m_Module.IsEmpty() )
|
|
|
|
{
|
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 ) );
|
2009-05-06 11:55:36 +00:00
|
|
|
wxMessageBox( msg, _( "CVPcb Error" ), wxOK | wxICON_ERROR,
|
|
|
|
this );
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|