Eeschema: move find sheet by name from SCH_SHEET_PATH to SCH_SHEET.
* Move FindSheetByName() function from SCH_SHEEET_PATH to SCH_SHEET object and update calls to FindSheetByName() accordingly. * Remove SCH_SHEET_PATH::FindSheet() which was unused. * Add sorting option to SCH_SHEET::GetSheets().
This commit is contained in:
parent
7c637ea7be
commit
cb13e57973
|
@ -1166,7 +1166,24 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter )
|
|||
}
|
||||
|
||||
|
||||
unsigned SCH_SHEET::GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const
|
||||
SCH_SHEET* SCH_SHEET::FindSheetByName( const wxString& aSheetName )
|
||||
{
|
||||
std::vector< const SCH_SHEET* > sheets;
|
||||
|
||||
GetSheets( sheets );
|
||||
|
||||
for( unsigned i = 0; i < sheets.size(); i++ )
|
||||
{
|
||||
if( sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 )
|
||||
return const_cast< SCH_SHEET*>( sheets[i] );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
unsigned SCH_SHEET::GetSheets( std::vector< const SCH_SHEET* >& aSheetList,
|
||||
bool aSortByPath ) const
|
||||
{
|
||||
// Sheet pointers must be unique.
|
||||
wxASSERT( find( aSheetList.begin(), aSheetList.end(), this ) == aSheetList.end() );
|
||||
|
@ -1183,6 +1200,9 @@ unsigned SCH_SHEET::GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const
|
|||
item = item->Next();
|
||||
}
|
||||
|
||||
if( aSortByPath )
|
||||
std::sort( aSheetList.begin(), aSheetList.end(), SortByPath() );
|
||||
|
||||
return aSheetList.size();
|
||||
}
|
||||
|
||||
|
@ -1225,7 +1245,7 @@ const SCH_SHEET* SCH_SHEET::GetRootSheet() const
|
|||
}
|
||||
|
||||
|
||||
void SCH_SHEET::GetPath( SCH_CONST_SHEETS& aSheetPath ) const
|
||||
void SCH_SHEET::GetPath( std::vector< const SCH_SHEET* >& aSheetPath ) const
|
||||
{
|
||||
aSheetPath.insert( aSheetPath.begin(), const_cast<SCH_SHEET*>( this ) );
|
||||
|
||||
|
@ -1579,7 +1599,7 @@ int SCH_SHEET::operator-( const SCH_SHEET& aRhs ) const
|
|||
if( this == &aRhs )
|
||||
return 0;
|
||||
|
||||
SCH_CONST_SHEETS lhsPath, rhsPath;
|
||||
std::vector< const SCH_SHEET* > lhsPath, rhsPath;
|
||||
|
||||
GetPath( lhsPath );
|
||||
aRhs.GetPath( rhsPath );
|
||||
|
|
|
@ -577,6 +577,25 @@ public:
|
|||
*/
|
||||
bool operator<( const SCH_SHEET& aRhs ) const;
|
||||
|
||||
/**
|
||||
* Structure SortByPath
|
||||
*
|
||||
* tests if \a aLhs is less than \a aRhs.
|
||||
*
|
||||
* @param aLhs is the left hand side reference to a #SCH_SHEET for comparison.
|
||||
* @param aRhs is the right hand side reference to a #SCH_SHEET for comparison.
|
||||
* @return true if \a aLhs is less than \a aRhs otherwise false.
|
||||
*/
|
||||
struct SortByPath
|
||||
{
|
||||
bool operator()( const SCH_SHEET* aLhs, const SCH_SHEET* aRhs )
|
||||
{
|
||||
wxCHECK( aLhs != NULL && aRhs != NULL, false );
|
||||
|
||||
return *aLhs < *aRhs;
|
||||
}
|
||||
};
|
||||
|
||||
int operator-( const SCH_SHEET& aRhs ) const;
|
||||
|
||||
wxPoint GetPosition() const { return m_pos; }
|
||||
|
@ -591,15 +610,33 @@ public:
|
|||
|
||||
EDA_ITEM* Clone() const;
|
||||
|
||||
/**
|
||||
* Function FindSheetByName
|
||||
*
|
||||
* searches this #SCH_SHEET and all of it's sub-sheets for a sheet named \a aSheetName.
|
||||
*
|
||||
* @param aSheetName is the name of the sheet to find.
|
||||
* @return a pointer to the sheet named \a aSheetName if found or NULL if not found.
|
||||
*/
|
||||
SCH_SHEET* FindSheetByName( const wxString& aSheetName );
|
||||
|
||||
/**
|
||||
* Function GetSheets
|
||||
*
|
||||
* add the point to #SCH_SHEET and all of it's sub-sheets to \a aSheetList.
|
||||
* add the pointers to the #SCH_SHEET and all of it's sub-sheets to \a aSheetList.
|
||||
*
|
||||
* By default no sorting is performed and the #SCH_SHEET pointers are add to the list
|
||||
* in the order they were loaded when the schematic was parse. When \a aSortByPath is
|
||||
* true, the list is sorted using the < operator which sort by path length then path
|
||||
* time stamps. This has the same sorting effect as the old SCH_SHEET_PATH::Cmp()
|
||||
* function.
|
||||
*
|
||||
* @param aSheetList is a reference to a set containing the #SCH_SHEET pointers.
|
||||
* @param aSortByPath true to sort by path. False for load order.
|
||||
* @return the number of #SCH_SHEET object pointers in \a aSheetList.
|
||||
*/
|
||||
unsigned GetSheets( std::vector<const SCH_SHEET*>& aSheetList ) const;
|
||||
unsigned GetSheets( std::vector< const SCH_SHEET* >& aSheetList,
|
||||
bool aSortByPath = false ) const;
|
||||
|
||||
/**
|
||||
* Function GetSheetPaths
|
||||
|
@ -647,9 +684,9 @@ public:
|
|||
* recurses up the parent branch up to the root sheet adding a pointer for each
|
||||
* parent sheet to \a aSheetPath.
|
||||
*
|
||||
* @param aSheetPath is a refernce to an #SCH_SHEETS object to populate.
|
||||
* @param aSheetPath is a refernce to an #SCH_SHEET object to populate.
|
||||
*/
|
||||
void GetPath( std::vector<const SCH_SHEET*>& aSheetPath ) const;
|
||||
void GetPath( std::vector< const SCH_SHEET* >& aSheetPath ) const;
|
||||
|
||||
/**
|
||||
* Function GetPath
|
||||
|
@ -797,9 +834,4 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
typedef std::vector< SCH_SHEET* > SCH_SHEETS;
|
||||
typedef std::vector< const SCH_SHEET* > SCH_CONST_SHEETS;
|
||||
typedef SCH_SHEETS::iterator SCH_SHEETS_ITER;
|
||||
typedef SCH_SHEETS::const_iterator SCH_SHEETS_CITER;
|
||||
|
||||
#endif /* SCH_SHEEET_H */
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
||||
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2011-2015 Wayne Stambaugh <stambaughw@verizon.net>
|
||||
* Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.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
|
||||
|
@ -294,30 +294,6 @@ bool SCH_SHEET_PATH::operator==( const SCH_SHEET_PATH& d1 ) const
|
|||
}
|
||||
|
||||
|
||||
int SCH_SHEET_PATH::FindSheet( const wxString& aFileName ) const
|
||||
{
|
||||
for( unsigned i = 0; i < m_numSheets; i++ )
|
||||
{
|
||||
if( m_sheets[i]->GetFileName().CmpNoCase( aFileName ) == 0 )
|
||||
return (int)i;
|
||||
}
|
||||
|
||||
return SHEET_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_SHEET_PATH::FindSheetByName( const wxString& aSheetName )
|
||||
{
|
||||
for( unsigned i = 0; i < m_numSheets; i++ )
|
||||
{
|
||||
if( m_sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 )
|
||||
return m_sheets[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
/* Class SCH_SHEET_LIST to handle the list of Sheets in a hierarchy */
|
||||
/********************************************************************/
|
||||
|
@ -535,17 +511,3 @@ SCH_ITEM* SCH_SHEET_LIST::FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aShe
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName )
|
||||
{
|
||||
for( int i = 0; i < m_count; i++ )
|
||||
{
|
||||
SCH_SHEET* sheet = m_list[i].FindSheetByName( aSheetName );
|
||||
|
||||
if( sheet )
|
||||
return sheet;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -220,18 +220,6 @@ public:
|
|||
*/
|
||||
SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_ITEM* aLastItem = NULL, bool aWrap = false ) const;
|
||||
|
||||
int FindSheet( const wxString& aFileName ) const;
|
||||
|
||||
/**
|
||||
* Function FindSheetByName
|
||||
*
|
||||
* searches the #SCH_SHEET_PATH for a sheet named \a aSheetName.
|
||||
*
|
||||
* @param aSheetName is the name of the sheet to find.
|
||||
* @return a pointer to the sheet named \a aSheetName if found or NULL if not found.
|
||||
*/
|
||||
SCH_SHEET* FindSheetByName( const wxString& aSheetName );
|
||||
|
||||
SCH_SHEET_PATH& operator=( const SCH_SHEET_PATH& d1 );
|
||||
|
||||
bool operator==( const SCH_SHEET_PATH& d1 ) const;
|
||||
|
@ -375,16 +363,6 @@ public:
|
|||
SCH_ITEM* FindPreviousItem( KICAD_T aType, SCH_SHEET_PATH** aSheetFound = NULL,
|
||||
SCH_ITEM* aLastItem = NULL, bool aWrap = true );
|
||||
|
||||
/**
|
||||
* Function FindSheetByName
|
||||
*
|
||||
* searches the entire #SCH_SHEET_LIST for a sheet named \a aSheetName.
|
||||
*
|
||||
* @param aSheetName is the name of the sheet to find.
|
||||
* @return a pointer to the sheet named \a aSheetName if found or NULL if not found.
|
||||
*/
|
||||
SCH_SHEET* FindSheetByName( const wxString& aSheetName );
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,7 +86,7 @@ bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET* aHierarchy )
|
|||
}
|
||||
|
||||
// Duplicate sheet names are not valid.
|
||||
const SCH_SHEET* sheet = hierarchy.FindSheetByName( dlg.GetSheetName() );
|
||||
const SCH_SHEET* sheet = g_RootSheet->FindSheetByName( dlg.GetSheetName() );
|
||||
|
||||
if( sheet && (sheet != aSheet) )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue