2008-05-07 15:08:16 +00:00
|
|
|
/****************************************************************
|
2009-12-02 21:44:03 +00:00
|
|
|
* EESchema: backanno.cpp
|
|
|
|
* (functions for backannotating Footprint info
|
|
|
|
****************************************************************/
|
2008-05-07 15:08:16 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "wxEeschemaStruct.h"
|
|
|
|
#include "build_version.h"
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "general.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_sheet_path.h"
|
|
|
|
#include "sch_component.h"
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2008-05-07 15:08:16 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function FillFootprintFieldForAllInstancesofComponent
|
2008-05-16 09:21:01 +00:00
|
|
|
* Search for component "aReference", and place a Footprint in Footprint field
|
2009-11-03 13:26:31 +00:00
|
|
|
* @param aReference = reference of the component to initialize
|
2009-12-02 21:44:03 +00:00
|
|
|
* @param aFootPrint = new value for the filed Footprint component
|
2009-11-03 13:26:31 +00:00
|
|
|
* @param aSetVisible = true to have the field visible, false to set the
|
|
|
|
* invisible flag
|
2008-05-16 09:21:01 +00:00
|
|
|
* @return true if the given component is found
|
|
|
|
* Note:
|
2009-11-03 13:26:31 +00:00
|
|
|
* the component is searched in the whole schematic, and because some
|
|
|
|
* components
|
2008-05-16 09:21:01 +00:00
|
|
|
* have more than one instance (multiple parts per package components)
|
2009-11-03 13:26:31 +00:00
|
|
|
* the search is not stopped when a reference is found (all instances must be
|
|
|
|
* found).
|
2008-05-16 09:21:01 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool WinEDA_SchematicFrame::FillFootprintFieldForAllInstancesofComponent(
|
|
|
|
const wxString& aReference,
|
|
|
|
const wxString& aFootPrint,
|
|
|
|
bool aSetVisible )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH* sheet;
|
|
|
|
SCH_ITEM* DrawList = NULL;
|
|
|
|
SCH_SHEET_LIST SheetList;
|
|
|
|
SCH_COMPONENT* Cmp;
|
|
|
|
bool found = false;
|
2008-05-08 20:34:39 +00:00
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
for( sheet = SheetList.GetFirst();
|
|
|
|
sheet != NULL;
|
|
|
|
sheet = SheetList.GetNext() )
|
2008-05-08 20:34:39 +00:00
|
|
|
{
|
2008-05-15 15:59:11 +00:00
|
|
|
DrawList = (SCH_ITEM*) sheet->LastDrawList();
|
|
|
|
for( ; (DrawList != NULL); DrawList = DrawList->Next() )
|
|
|
|
{
|
2008-05-16 09:21:01 +00:00
|
|
|
if( DrawList->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
2008-05-15 15:59:11 +00:00
|
|
|
|
2008-05-16 09:21:01 +00:00
|
|
|
Cmp = (SCH_COMPONENT*) DrawList;
|
|
|
|
if( aReference.CmpNoCase( Cmp->GetRef( sheet ) ) == 0 )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
// Found: Init Footprint Field
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
if( Cmp->GetField( FOOTPRINT )->m_Text.IsEmpty()
|
|
|
|
&& ( Cmp->GetField( FOOTPRINT )->m_Pos == wxPoint( 0, 0 ) ) )
|
2008-05-16 09:21:01 +00:00
|
|
|
{
|
2009-11-03 13:26:31 +00:00
|
|
|
Cmp->GetField( FOOTPRINT )->m_Orient = Cmp->GetField(
|
|
|
|
VALUE )->m_Orient;
|
|
|
|
Cmp->GetField( FOOTPRINT )->m_Pos = Cmp->GetField(
|
|
|
|
VALUE )->m_Pos;
|
|
|
|
Cmp->GetField( FOOTPRINT )->m_Pos.y -= 100;
|
2008-05-16 09:21:01 +00:00
|
|
|
}
|
2009-11-03 13:26:31 +00:00
|
|
|
Cmp->GetField( FOOTPRINT )->m_Text = aFootPrint;
|
2008-05-16 09:21:01 +00:00
|
|
|
if( aSetVisible )
|
2009-11-03 13:26:31 +00:00
|
|
|
Cmp->GetField( FOOTPRINT )->m_Attributs &=
|
|
|
|
~TEXT_NO_VISIBLE;
|
2008-05-16 09:21:01 +00:00
|
|
|
else
|
2009-11-03 13:26:31 +00:00
|
|
|
Cmp->GetField( FOOTPRINT )->m_Attributs |= TEXT_NO_VISIBLE;
|
2008-05-16 09:21:01 +00:00
|
|
|
found = true;
|
2008-05-15 15:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-08 20:34:39 +00:00
|
|
|
}
|
2008-05-15 15:59:11 +00:00
|
|
|
|
2008-05-16 09:21:01 +00:00
|
|
|
return found;
|
2008-05-08 20:34:39 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ProcessStuffFile
|
2008-05-16 09:21:01 +00:00
|
|
|
* Read a "stuff" file created by cvpcb.
|
2008-05-15 15:59:11 +00:00
|
|
|
* That file has lines like:
|
|
|
|
* comp = "C1" module = "CP6"
|
|
|
|
* comp = "C2" module = "C1"
|
|
|
|
* comp = "C3" module = "C1"
|
|
|
|
* "comp =" gives the component reference
|
|
|
|
* "module =" gives the footprint name
|
|
|
|
*
|
2008-05-16 09:21:01 +00:00
|
|
|
* @param aStuffFile = file (*.stf) to Read.
|
2009-11-03 13:26:31 +00:00
|
|
|
* @param aSetFielsAttributeToVisible = true to set the footprint field flag to
|
|
|
|
* visible
|
|
|
|
* @return true if OK.
|
2008-05-15 15:59:11 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool WinEDA_SchematicFrame::ProcessStuffFile( FILE* aStuffFile, bool
|
|
|
|
aSetFielsAttributeToVisible )
|
|
|
|
{
|
2008-05-16 09:21:01 +00:00
|
|
|
int LineNum = 0;
|
|
|
|
char* cp, Ref[256], FootPrint[256], Line[1024];
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2008-05-16 09:21:01 +00:00
|
|
|
while( GetLine( aStuffFile, 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;
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
wxString reference = CONV_FROM_UTF8( Ref );
|
2008-05-16 09:21:01 +00:00
|
|
|
wxString Footprint = CONV_FROM_UTF8( FootPrint );
|
2009-11-03 13:26:31 +00:00
|
|
|
FillFootprintFieldForAllInstancesofComponent(
|
|
|
|
reference,
|
|
|
|
Footprint,
|
|
|
|
aSetFielsAttributeToVisible );
|
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
|
|
|
|
2008-05-07 15:08:16 +00:00
|
|
|
/* Backann footprint info to schematic.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool WinEDA_SchematicFrame::ReadInputStuffFile()
|
|
|
|
{
|
2008-05-07 15:08:16 +00:00
|
|
|
wxString Line, filename;
|
2008-05-07 23:41:05 +00:00
|
|
|
FILE* StuffFile;
|
|
|
|
wxString msg;
|
2008-05-16 09:21:01 +00:00
|
|
|
bool SetFieldToVisible = true;
|
2008-05-07 23:41:05 +00:00
|
|
|
|
|
|
|
filename = EDA_FileSelector( _( "Load Stuff File" ),
|
2009-11-03 13:26:31 +00:00
|
|
|
wxEmptyString,
|
|
|
|
wxEmptyString,
|
|
|
|
wxT( ".stf" ),
|
|
|
|
wxT( "*.stf" ),
|
2008-05-16 09:21:01 +00:00
|
|
|
this,
|
|
|
|
wxFD_OPEN,
|
|
|
|
FALSE
|
|
|
|
);
|
2008-05-07 23:41:05 +00:00
|
|
|
|
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return FALSE;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
Line = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2008-05-07 23:41:05 +00:00
|
|
|
Line += wxT( " " ) + filename;
|
|
|
|
SetTitle( Line );
|
2008-05-07 15:08:16 +00:00
|
|
|
|
|
|
|
if( filename.IsEmpty() )
|
|
|
|
return FALSE;
|
|
|
|
|
2008-05-16 09:21:01 +00:00
|
|
|
int diag = wxMessageBox(
|
2009-12-02 21:44:03 +00:00
|
|
|
_( "Set the foot print field to visible?" ),
|
2009-11-03 13:26:31 +00:00
|
|
|
_( "Field Display Option" ),
|
2008-05-16 09:21:01 +00:00
|
|
|
wxYES_NO | wxICON_QUESTION | wxCANCEL, this );
|
|
|
|
|
|
|
|
if( diag == wxCANCEL )
|
|
|
|
return false;
|
|
|
|
if( diag == wxYES )
|
|
|
|
SetFieldToVisible = true;
|
|
|
|
else
|
|
|
|
SetFieldToVisible = false;
|
|
|
|
|
2008-05-07 15:08:16 +00:00
|
|
|
StuffFile = wxFopen( filename, wxT( "rt" ) );
|
2008-05-07 23:41:05 +00:00
|
|
|
if( StuffFile == NULL )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
msg.Printf( _( "Failed to open stuff file <%s>" ), filename.GetData() );
|
2008-05-07 15:08:16 +00:00
|
|
|
DisplayError( this, msg, 20 );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-05-07 23:41:05 +00:00
|
|
|
|
2008-05-16 09:21:01 +00:00
|
|
|
ProcessStuffFile( StuffFile, SetFieldToVisible );
|
2008-05-07 15:08:16 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|