2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* 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>
|
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
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
const wxString BackAnnotateFileWildcard( wxT( "Eeschema Back Annotation File (*.stf)|*.stf" ) );
|
2008-05-08 20:34:39 +00:00
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
bool SCH_EDIT_FRAME::ProcessStuffFile( FILE* aFile, bool aSetFieldAttributeToVisible )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2008-05-16 09:21:01 +00:00
|
|
|
int LineNum = 0;
|
|
|
|
char* cp, Ref[256], FootPrint[256], Line[1024];
|
2011-03-28 18:23:01 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2011-08-05 19:53:42 +00:00
|
|
|
wxString reference;
|
|
|
|
wxString footprint;
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
// Build a flat list of components in schematic:
|
|
|
|
SCH_REFERENCE_LIST referencesList;
|
|
|
|
SheetList.GetComponents( referencesList, false );
|
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
// Now, foe each component found in file,
|
|
|
|
// replace footprint field value by the new value:
|
2011-08-05 19:53:42 +00:00
|
|
|
while( GetLine( aFile, Line, &LineNum, sizeof(Line) ) )
|
2008-05-07 23:41:05 +00:00
|
|
|
{
|
|
|
|
if( sscanf( Line, "comp = \"%s module = \"%s", Ref, FootPrint ) == 2 )
|
|
|
|
{
|
|
|
|
for( cp = Ref; *cp; cp++ )
|
|
|
|
if( *cp == '"' )
|
|
|
|
*cp = 0;
|
|
|
|
|
|
|
|
for( cp = FootPrint; *cp; cp++ )
|
|
|
|
if( *cp == '"' )
|
|
|
|
*cp = 0;
|
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
reference = FROM_UTF8( Ref );
|
|
|
|
footprint = FROM_UTF8( FootPrint );
|
|
|
|
|
|
|
|
// 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 );
|
2011-08-19 13:08:24 +00:00
|
|
|
/* Give a reasonable value to the field position and
|
|
|
|
* orientation, if the text is empty at position 0, because
|
|
|
|
* it is probably not yet initialized
|
|
|
|
*/
|
2011-08-05 19:53:42 +00:00
|
|
|
if( fpfield->m_Text.IsEmpty()
|
2011-10-19 20:32:21 +00:00
|
|
|
&& ( fpfield->GetPosition() == component->GetPosition() ) )
|
2011-08-05 19:53:42 +00:00
|
|
|
{
|
|
|
|
fpfield->m_Orient = component->GetField( VALUE )->m_Orient;
|
2011-10-19 20:32:21 +00:00
|
|
|
fpfield->SetPosition( component->GetField( VALUE )->GetPosition() );
|
2011-08-19 13:08:24 +00:00
|
|
|
fpfield->m_Size = component->GetField( VALUE )->m_Size;
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2011-08-19 13:08:24 +00:00
|
|
|
if( fpfield->m_Orient == 0 )
|
|
|
|
fpfield->m_Pos.y += 100;
|
|
|
|
else
|
|
|
|
fpfield->m_Pos.x += 100;
|
2011-08-05 19:53:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fpfield->m_Text = footprint;
|
|
|
|
|
|
|
|
if( aSetFieldAttributeToVisible )
|
|
|
|
component->GetField( FOOTPRINT )->m_Attributs &= ~TEXT_NO_VISIBLE;
|
|
|
|
else
|
|
|
|
component->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
|
|
|
|
}
|
|
|
|
}
|
2008-05-07 23:41:05 +00:00
|
|
|
}
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 19:53:42 +00:00
|
|
|
fclose( aFile );
|
2008-05-07 15:08:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SCH_EDIT_FRAME::ReadInputStuffFile()
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2011-03-28 18:23:01 +00:00
|
|
|
wxString title, filename;
|
|
|
|
FILE* file;
|
2008-05-07 23:41:05 +00:00
|
|
|
wxString msg;
|
2011-03-28 18:23:01 +00:00
|
|
|
bool visible = false;
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Load Back Annotate File" ), wxEmptyString, wxEmptyString,
|
|
|
|
BackAnnotateFileWildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2008-05-16 09:21:01 +00:00
|
|
|
return false;
|
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
filename = dlg.GetPath();
|
|
|
|
title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
|
|
|
title += wxT( " " ) + filename;
|
|
|
|
SetTitle( title );
|
|
|
|
|
|
|
|
int response = wxMessageBox( _( "Do you want to make all the foot print fields visible?" ),
|
|
|
|
_( "Field Display Option" ),
|
|
|
|
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
|
|
|
|
|
|
|
|
if( response == wxCANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( response == wxYES )
|
|
|
|
visible = true;
|
|
|
|
|
|
|
|
file = wxFopen( filename, wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( file == NULL )
|
2008-05-07 23:41:05 +00:00
|
|
|
{
|
2011-03-28 18:23:01 +00:00
|
|
|
msg.Printf( _( "Failed to open back annotate file <%s>" ), filename.GetData() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
ProcessStuffFile( file, visible );
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2011-03-28 18:23:01 +00:00
|
|
|
return true;
|
2008-05-07 15:08:16 +00:00
|
|
|
}
|