From 0d3769b23459b9b5069f92771aafd16ff873f59f Mon Sep 17 00:00:00 2001
From: bennett78 <Unknown>
Date: Thu, 8 May 2008 20:34:39 +0000
Subject: [PATCH] Added SCH_COMPONENT *
 WinEDA_SchematicFrame::FindComponentByRef  for backanno.cpp, a better
 candidate for searching.

---
 eeschema/backanno.cpp      | 48 +++++++++++++++++++++++++++-----------
 include/wxEeschemaStruct.h |  2 ++
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/eeschema/backanno.cpp b/eeschema/backanno.cpp
index a81de36265..cacb05d4d5 100644
--- a/eeschema/backanno.cpp
+++ b/eeschema/backanno.cpp
@@ -17,13 +17,39 @@
 
 #include "protos.h"
 
+/**************************************************************/
+SCH_COMPONENT * WinEDA_SchematicFrame::FindComponentByRef(
+     const wxString& reference )
+/**************************************************************/
+{
+    DrawSheetPath*      sheet;
+    SCH_ITEM*           DrawList  = NULL;
+    EDA_SheetList       SheetList( NULL );
+
+    for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
+    {
+	DrawList = (SCH_ITEM*) sheet->LastDrawList();
+	for( ; (DrawList != NULL); DrawList = DrawList->Next() )
+	{
+	    if( DrawList->Type() == TYPE_SCH_COMPONENT )
+	    {
+		SCH_COMPONENT* pSch;
+
+		pSch = (SCH_COMPONENT*) DrawList;
+		if( reference.CmpNoCase( pSch->GetRef(sheet) ) == 0 )
+		    return pSch;
+	    }
+	}
+    }
+    return NULL;
+}
+
 /**************************************************************/
 bool WinEDA_SchematicFrame::ProcessStuffFile( FILE* StuffFile )
 /**************************************************************/
 {
     int             LineNum = 0;
     char*           cp, Ref[256], FootPrint[256], Line[1024];
-    SCH_ITEM*       DrawList = NULL;
     SCH_COMPONENT*  Cmp;
     PartTextStruct* TextField;
 
@@ -39,22 +65,18 @@ bool WinEDA_SchematicFrame::ProcessStuffFile( FILE* StuffFile )
                 if( *cp == '"' )
                     *cp = 0;
 
-            // printf("'%s' '%s'\n", Ref, FootPrint);
-
             wxString    reference = CONV_FROM_UTF8( Ref );
 
-            DrawList = WinEDA_SchematicFrame::FindComponentAndItem(
-                reference, TRUE, 2, wxEmptyString, false );
-
-            if( DrawList == NULL )
+            Cmp = WinEDA_SchematicFrame::FindComponentByRef( reference );
+            if( Cmp == NULL )
                 continue;
 
-            if( DrawList->Type() == TYPE_SCH_COMPONENT )
-            {
-                Cmp = (SCH_COMPONENT*) DrawList;
-                TextField = &Cmp->m_Field[FOOTPRINT];
-                TextField->m_Text = CONV_FROM_UTF8( FootPrint );
-            }
+#if defined(DEBUG)
+            printf( "  %s %s\n", CONV_TO_UTF8(Cmp->m_Field[REFERENCE].m_Text), 
+		 		     CONV_TO_UTF8(Cmp->m_Field[VALUE].m_Text) );
+#endif
+            TextField = &Cmp->m_Field[FOOTPRINT];
+            TextField->m_Text = CONV_FROM_UTF8( FootPrint );
         }
     }
 
diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h
index 34632158aa..d6f0c1ce91 100644
--- a/include/wxEeschemaStruct.h
+++ b/include/wxEeschemaStruct.h
@@ -89,6 +89,8 @@ public:
         bool
         IncludePin );
 
+    SCH_COMPONENT*          FindComponentByRef( const wxString& reference );
+
     SCH_ITEM*               FindComponentAndItem( const wxString& component_reference,
                                                   bool                          Find_in_hierarchy,
                                                   int                           SearchType,