Commit 8b5ba9ff authored by charras's avatar charras

Fixed a bug in search function in Eeschema: search for a component reference...

Fixed a bug in search function in Eeschema: search for a component reference in a complex hierarchy was broken
parent 6e611930
...@@ -111,8 +111,9 @@ SCH_SHEET* SCH_SHEET_PATH::Last() ...@@ -111,8 +111,9 @@ SCH_SHEET* SCH_SHEET_PATH::Last()
*/ */
SCH_SCREEN* SCH_SHEET_PATH::LastScreen() SCH_SCREEN* SCH_SHEET_PATH::LastScreen()
{ {
if( m_numSheets ) SCH_SHEET* lastSheet = Last();
return m_sheets[m_numSheets - 1]->m_AssociatedScreen; if( lastSheet )
return lastSheet->m_AssociatedScreen;
return NULL; return NULL;
} }
...@@ -123,8 +124,9 @@ SCH_SCREEN* SCH_SHEET_PATH::LastScreen() ...@@ -123,8 +124,9 @@ SCH_SCREEN* SCH_SHEET_PATH::LastScreen()
*/ */
SCH_ITEM* SCH_SHEET_PATH::LastDrawList() SCH_ITEM* SCH_SHEET_PATH::LastDrawList()
{ {
if( m_numSheets && m_sheets[m_numSheets - 1]->m_AssociatedScreen ) SCH_SHEET* lastSheet = Last();
return m_sheets[m_numSheets - 1]->m_AssociatedScreen->EEDrawList; if( lastSheet && lastSheet->m_AssociatedScreen )
return lastSheet->m_AssociatedScreen->EEDrawList;
return NULL; return NULL;
} }
...@@ -333,7 +335,7 @@ SCH_ITEM* SCH_SHEET_PATH::MatchNextItem( wxFindReplaceData& aSearchData, ...@@ -333,7 +335,7 @@ SCH_ITEM* SCH_SHEET_PATH::MatchNextItem( wxFindReplaceData& aSearchData,
} }
else else
{ {
if( drawItem->Matches( aSearchData ) ) if( drawItem->Matches( aSearchData, Last() ) )
return drawItem; return drawItem;
} }
...@@ -631,7 +633,7 @@ SCH_ITEM* SCH_SHEET_LIST::MatchNextItem( wxFindReplaceData& aSearchData, ...@@ -631,7 +633,7 @@ SCH_ITEM* SCH_SHEET_LIST::MatchNextItem( wxFindReplaceData& aSearchData,
} }
else else
{ {
if( drawItem->Matches( aSearchData ) ) if( drawItem->Matches( aSearchData, sheet ) )
{ {
if( aSheetFoundIn ) if( aSheetFoundIn )
*aSheetFoundIn = sheet; *aSheetFoundIn = sheet;
......
...@@ -420,7 +420,28 @@ void SCH_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) ...@@ -420,7 +420,28 @@ void SCH_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
} }
bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData ) bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void * aAuxData )
{ {
if( aAuxData && m_FieldId == REFERENCE )
{
SCH_COMPONENT* pSch = (SCH_COMPONENT*) m_Parent;
SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
wxString fulltext = pSch->GetRef( sheet );
if( m_AddExtraText )
{
/* For more than one part per package, we must add the part selection
* A, B, ... or 1, 2, .. to the reference. */
int part_id = pSch->GetUnitSelection( sheet );
#if defined(KICAD_GOST)
fulltext.Append( '.' );
part_id = '1' - 1 + part_id;
#else
part_id = 'A' - 1 + part_id;
#endif
fulltext.Append( part_id );
}
return SCH_ITEM::Matches( fulltext, aSearchData );
}
return SCH_ITEM::Matches( m_Text, aSearchData ); return SCH_ITEM::Matches( m_Text, aSearchData );
} }
...@@ -119,9 +119,13 @@ public: ...@@ -119,9 +119,13 @@ public:
* Compare schematic field text against search string. * Compare schematic field text against search string.
* *
* @param aSearchData - Criteria to search against. * @param aSearchData - Criteria to search against.
* @param aAuxData - a pointer on auxiliary data, if needed.
* the sheet path is needed for REFERENCE field because m_Text
* value is just the valeur displayed, and in complex hierarchies
* this is only one of all references (one per sheet path)
* @return True if this field text matches the search criteria. * @return True if this field text matches the search criteria.
*/ */
virtual bool Matches( wxFindReplaceData& aSearchData ); virtual bool Matches( wxFindReplaceData& aSearchData, void * aAuxData );
}; };
......
...@@ -1153,19 +1153,30 @@ void SCH_COMPONENT::Mirror_Y(int aYaxis_position) ...@@ -1153,19 +1153,30 @@ void SCH_COMPONENT::Mirror_Y(int aYaxis_position)
} }
bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData ) bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void * aAuxData )
{ {
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS ) ) // Search reference.
{ // reference is a special field because a part identifier is added
if( !GetField( REFERENCE )->Matches( aSearchData ) ) // in multi parts per package
return GetField( VALUE )->Matches( aSearchData ); // the .m_AddExtraText of the field msut be set to add this identifier:
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
if( Entry && Entry->GetPartCount() > 1 )
GetField( REFERENCE )->m_AddExtraText = true;
else
GetField( REFERENCE )->m_AddExtraText = false;
if( GetField( REFERENCE )->Matches( aSearchData, aAuxData ) )
return true; return true;
}
for( size_t i = 0; i < NUMBER_OF_FIELDS; i++ ) if( GetField( VALUE )->Matches( aSearchData, aAuxData ) )
return true;
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS ) )
return false;
for( size_t i = VALUE+1; i < NUMBER_OF_FIELDS; i++ )
{ {
if( GetField( i )->Matches( aSearchData ) ) if( GetField( i )->Matches( aSearchData, aAuxData ) )
return true; return true;
} }
......
...@@ -353,9 +353,12 @@ public: ...@@ -353,9 +353,12 @@ public:
* Compare schematic component reference and value fields against search string. * Compare schematic component reference and value fields against search string.
* *
* @param aSearchData - Criteria to search against. * @param aSearchData - Criteria to search against.
* @param aAuxData - a pointer on auxiliary data, if needed.
* When searching string in REFERENCE field we must know the sheet path
* This param is used in this case
* @return True if this component reference or value field matches the search criteria. * @return True if this component reference or value field matches the search criteria.
*/ */
virtual bool Matches( wxFindReplaceData& aSearchData ); virtual bool Matches( wxFindReplaceData& aSearchData, void * aAuxData );
#if defined (DEBUG) #if defined (DEBUG)
......
...@@ -181,7 +181,7 @@ wxPoint SCH_TEXT::GetSchematicTextOffset() ...@@ -181,7 +181,7 @@ wxPoint SCH_TEXT::GetSchematicTextOffset()
} }
bool SCH_TEXT::Matches( wxFindReplaceData& aSearchData ) bool SCH_TEXT::Matches( wxFindReplaceData& aSearchData, void * aAuxData )
{ {
return SCH_ITEM::Matches( m_Text, aSearchData ); return SCH_ITEM::Matches( m_Text, aSearchData );
} }
......
...@@ -149,9 +149,10 @@ public: ...@@ -149,9 +149,10 @@ public:
* Compare schematic text entry against search string. * Compare schematic text entry against search string.
* *
* @param aSearchData - Criterial to search against. * @param aSearchData - Criterial to search against.
* @param aAuxData - a pointer on auxiliary data, if needed. Can be null
* @return True if this schematic text item matches the search criteria. * @return True if this schematic text item matches the search criteria.
*/ */
virtual bool Matches( wxFindReplaceData& aSearchData ); virtual bool Matches( wxFindReplaceData& aSearchData, void * aAuxData );
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ); void Show( int nestLevel, std::ostream& os );
......
...@@ -100,9 +100,13 @@ public: ...@@ -100,9 +100,13 @@ public:
* objects derived from EDA_BaseStruct. * objects derived from EDA_BaseStruct.
* *
* @param aSearchData - The search criteria. * @param aSearchData - The search criteria.
* @param aAuxData - a pointer on auxiliary data, if needed (NULL if not used).
* When searching string in REFERENCE field we must know the sheet path
* This param is used in such cases
* @return True if this schematic text item matches the search criteria. * @return True if this schematic text item matches the search criteria.
*/ */
virtual bool Matches( wxFindReplaceData& aSearchData ) { return false; } virtual bool Matches( wxFindReplaceData& aSearchData, void * aAuxData )
{ return false; }
/** /**
* Compare schematic item against search string. * Compare schematic item against search string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment