2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-02-02 17:39:59 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
|
2011-10-19 20:32:21 +00:00
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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 backanno.cpp
|
|
|
|
* @brief Functions for backannotating footprint information.
|
|
|
|
*/
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <build_version.h>
|
2013-02-02 17:39:59 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <netlist.h>
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2008-05-08 20:34:39 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
bool SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile( wxString& aFullFilename,
|
2013-02-11 18:50:55 +00:00
|
|
|
bool aForceFieldsVisibleAttribute,
|
|
|
|
bool aFieldsVisibleAttributeState )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-08-05 19:53:42 +00:00
|
|
|
// Build a flat list of components in schematic:
|
|
|
|
SCH_REFERENCE_LIST referencesList;
|
2013-02-02 17:39:59 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2011-08-05 19:53:42 +00:00
|
|
|
SheetList.GetComponents( referencesList, false );
|
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
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,
|
2011-08-19 13:08:24 +00:00
|
|
|
// replace footprint field value by the new value:
|
2013-02-02 17:39:59 +00:00
|
|
|
wxString reference;
|
|
|
|
wxString footprint;
|
|
|
|
wxString buffer;
|
|
|
|
wxString value;
|
|
|
|
|
|
|
|
while( cmpFileReader.ReadLine() )
|
2008-05-07 23:41:05 +00:00
|
|
|
{
|
2013-02-02 17:39:59 +00:00
|
|
|
buffer = FROM_UTF8( cmpFileReader.Line() );
|
|
|
|
|
|
|
|
if( ! buffer.StartsWith( wxT("BeginCmp") ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Begin component description.
|
|
|
|
reference.Empty();
|
|
|
|
footprint.Empty();
|
|
|
|
|
|
|
|
while( cmpFileReader.ReadLine() )
|
2008-05-07 23:41:05 +00:00
|
|
|
{
|
2013-02-02 17:39:59 +00:00
|
|
|
buffer = FROM_UTF8( cmpFileReader.Line() );
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
if( buffer.StartsWith( wxT("EndCmp") ) )
|
|
|
|
break;
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
// store string value, stored between '=' and ';' delimiters.
|
|
|
|
value = buffer.AfterFirst( '=' );
|
|
|
|
value = value.BeforeLast( ';');
|
|
|
|
value.Trim(true);
|
|
|
|
value.Trim(false);
|
2011-08-05 19:53:42 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
if( buffer.StartsWith( wxT("Reference") ) )
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
2013-02-02 17:39:59 +00:00
|
|
|
reference = value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( buffer.StartsWith( wxT("IdModule =" ) ) )
|
|
|
|
{
|
|
|
|
footprint = value;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// A block is read: initialize the footprint field of the correponding 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( reference.CmpNoCase( referencesList[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 = referencesList[ii].GetComponent();
|
|
|
|
SCH_FIELD * fpfield = component->GetField( FOOTPRINT );
|
2013-03-18 19:36:07 +00:00
|
|
|
fpfield->SetText( footprint );
|
2013-02-02 17:39:59 +00:00
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
if( aForceFieldsVisibleAttribute )
|
|
|
|
{
|
2013-03-30 17:49:58 +00:00
|
|
|
component->GetField( FOOTPRINT )
|
|
|
|
->SetVisible( aFieldsVisibleAttributeState );
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-07 23:41:05 +00:00
|
|
|
}
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
bool SCH_EDIT_FRAME::LoadCmpToFootprintLinkFile()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2013-02-11 18:50:55 +00:00
|
|
|
wxString path = wxGetCwd();
|
2011-03-28 18:23:01 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
wxFileDialog dlg( this, _( "Load Component-Footprint Link File" ),
|
2013-02-11 18:50:55 +00:00
|
|
|
path, wxEmptyString,
|
2013-02-02 17:39:59 +00:00
|
|
|
ComponentFileExtensionWildcard,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2011-03-28 18:23:01 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2008-05-16 09:21:01 +00:00
|
|
|
return false;
|
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
wxString filename = dlg.GetPath();
|
|
|
|
wxString title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2011-03-28 18:23:01 +00:00
|
|
|
title += wxT( " " ) + filename;
|
|
|
|
SetTitle( title );
|
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
int response = wxMessageBox( _( "Do you want to force all the footprint fields visibility?" ),
|
|
|
|
_( "Field Visibility Change" ),
|
2011-03-28 18:23:01 +00:00
|
|
|
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
|
|
|
|
|
|
|
|
if( response == wxCANCEL )
|
|
|
|
return false;
|
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
bool changevisibility = response == wxYES;
|
|
|
|
bool visible = false;
|
|
|
|
|
|
|
|
if( changevisibility )
|
|
|
|
{
|
|
|
|
response = wxMessageBox( _( "Do you want to make all the footprint fields visible?" ),
|
|
|
|
_( "Field Visibility Option" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
|
|
|
|
if( response == wxCANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
visible = response == wxYES;
|
|
|
|
}
|
2011-03-28 18:23:01 +00:00
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
if( ! ProcessCmpToFootprintLinkFile( filename, changevisibility, visible ) )
|
2008-05-07 23:41:05 +00:00
|
|
|
{
|
2013-02-11 18:50:55 +00:00
|
|
|
wxString msg;
|
2013-02-02 17:39:59 +00:00
|
|
|
msg.Printf( _( "Failed to open component-footprint link file <%s>" ), filename.GetData() );
|
2011-03-28 18:23:01 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2013-02-11 18:50:55 +00:00
|
|
|
OnModify();
|
2011-03-28 18:23:01 +00:00
|
|
|
return true;
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|