2013-04-25 16:29:35 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <cvpcb.h>
|
|
|
|
#include <cvpcb_mainframe.h>
|
|
|
|
#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 );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
if( wxNOT_FOUND == i )
|
|
|
|
return wxT( "" );
|
|
|
|
|
2011-06-10 14:33:52 +00:00
|
|
|
wxString shrt = text.Mid( i + 1 );
|
|
|
|
i = shrt.Find( QUOTE );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
if( wxNOT_FOUND == i )
|
|
|
|
return wxT( "" );
|
|
|
|
|
2011-06-10 14:33:52 +00:00
|
|
|
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;
|
2013-04-25 16:29:35 +00:00
|
|
|
COMPONENT* component;
|
2009-05-06 11:55:36 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxString msg, tmp;
|
|
|
|
char Line[1024];
|
|
|
|
FILE* file;
|
|
|
|
size_t ii;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( m_netlist.IsEmpty() )
|
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
|
|
|
|
2012-05-25 06:58:52 +00:00
|
|
|
if( !fn.HasExt() )
|
|
|
|
{
|
2011-06-16 14:40:58 +00:00
|
|
|
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 )
|
|
|
|
{
|
2013-04-25 16:29:35 +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 );
|
|
|
|
|
2012-05-25 06:58:52 +00:00
|
|
|
m_skipComponentSelect = true;
|
2009-05-06 11:55:36 +00:00
|
|
|
ii = 0;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
for( unsigned kk = 0; kk < m_netlist.GetCount(); kk++ )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
component = m_netlist.GetComponent( kk );
|
|
|
|
|
2011-10-20 11:28:37 +00:00
|
|
|
bool found = false;
|
2010-11-29 15:05:01 +00:00
|
|
|
m_ListCmp->SetSelection( ii++, true );
|
2009-05-06 11:55:36 +00:00
|
|
|
|
2013-04-28 20:20:40 +00:00
|
|
|
if( !component->GetFootprintName().IsEmpty() )
|
2009-05-06 11:55:36 +00:00
|
|
|
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-08-29 19:50:05 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( alias.m_Name.CmpNoCase( component->GetValue() ) != 0 )
|
2009-05-06 11:55:36 +00:00
|
|
|
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 )
|
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
size_t filtercount = component->GetFootprintFilters().GetCount();
|
2011-06-10 14:33:52 +00:00
|
|
|
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
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
found = module->m_Module.Matches( component->GetFootprintFilters()[jj] );
|
2011-06-10 14:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2009-05-06 11:55:36 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
msg.Printf( _( "Component %s: footprint %s not found in any of the project "
|
|
|
|
"footprint libraries." ),
|
|
|
|
GetChars( component->GetReference() ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( alias.m_FootprintName ) );
|
2013-04-25 16:29:35 +00:00
|
|
|
wxMessageBox( msg, _( "CvPcb Error" ), wxOK | wxICON_ERROR, this );
|
2009-04-23 15:02:18 +00:00
|
|
|
}
|
2013-04-25 16:29:35 +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
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2011-10-20 11:28:37 +00:00
|
|
|
/* obviously the last chance: there's only one filter matching one footprint */
|
2013-04-25 16:29:35 +00:00
|
|
|
if( !found && 1 == component->GetFootprintFilters().GetCount() )
|
|
|
|
{
|
2011-10-20 11:28:37 +00:00
|
|
|
/* we do not need to analyse wildcards: single footprint do not contain them */
|
|
|
|
/* and if there are wildcards it just will not match any */
|
2013-04-25 16:29:35 +00:00
|
|
|
FOOTPRINT_INFO *module = m_footprints.GetModuleInfo( component->GetFootprintFilters()[0] );
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
SetNewPkg( component->GetFootprintFilters()[0] );
|
2011-10-20 11:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2012-05-25 06:58:52 +00:00
|
|
|
m_skipComponentSelect = false;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|