Fix SortByPageNumbers: use Sheet Name when page numbers are equal
This commit is contained in:
parent
258946d8b1
commit
2c75911669
|
@ -166,10 +166,7 @@ int HIERARCHY_TREE::OnCompareItems( const wxTreeItemId& item1, const wxTreeItemI
|
|||
SCH_SHEET_PATH* item1Path = &static_cast<TreeItemData*>( GetItemData( item1 ) )->m_SheetPath;
|
||||
SCH_SHEET_PATH* item2Path = &static_cast<TreeItemData*>( GetItemData( item2 ) )->m_SheetPath;
|
||||
|
||||
wxString item1PageNo = item1Path->Last()->GetPageNumber( *item1Path );
|
||||
wxString item2PageNo = item2Path->Last()->GetPageNumber( *item2Path );
|
||||
|
||||
return SCH_SHEET::ComparePageNum( item1PageNo, item2PageNo );
|
||||
return item1Path->ComparePageNumAndName( *item2Path );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1150,7 +1150,7 @@ void SCH_SHEET::SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString&
|
|||
int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString aPageNumberB )
|
||||
{
|
||||
if( aPageNumberA == aPageNumberB )
|
||||
return 1;
|
||||
return 0; // A == B
|
||||
|
||||
// First sort numerically if the page numbers are integers
|
||||
long pageA, pageB;
|
||||
|
@ -1159,29 +1159,25 @@ int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString aPag
|
|||
|
||||
if( isIntegerPageA && isIntegerPageB )
|
||||
{
|
||||
if( pageA > pageB )
|
||||
return 1;
|
||||
else if( pageA == pageB )
|
||||
return 0;
|
||||
if( pageA < pageB )
|
||||
return -1; //A < B
|
||||
else
|
||||
return -1;
|
||||
return 1; // A > B
|
||||
}
|
||||
|
||||
// Numerical page numbers always before strings
|
||||
if( isIntegerPageA )
|
||||
return -1;
|
||||
return -1; //A < B
|
||||
else if( isIntegerPageB )
|
||||
return 1;
|
||||
return 1; // A > B
|
||||
|
||||
// If not numeric, then sort as strings
|
||||
int result = aPageNumberA.Cmp( aPageNumberB );
|
||||
|
||||
if( result == 0 )
|
||||
return 0;
|
||||
else if( result > 0 )
|
||||
return 1;
|
||||
if( result > 0 )
|
||||
return 1; // A > B
|
||||
|
||||
return -1;
|
||||
return -1; //A < B
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -156,6 +156,27 @@ int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
|
|||
}
|
||||
|
||||
|
||||
int SCH_SHEET_PATH::ComparePageNumAndName( const SCH_SHEET_PATH& aSheetPathToTest ) const
|
||||
{
|
||||
wxString pageA = GetPageNumber();
|
||||
wxString pageB = aSheetPathToTest.GetPageNumber();
|
||||
|
||||
int pageNumComp = SCH_SHEET::ComparePageNum( pageA, pageB );
|
||||
|
||||
if( pageNumComp == 0 )
|
||||
{
|
||||
wxString nameA = Last()->GetName();
|
||||
wxString nameB = aSheetPathToTest.Last()->GetName();
|
||||
|
||||
return nameA.Cmp( nameB );
|
||||
}
|
||||
else
|
||||
{
|
||||
return pageNumComp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SCH_SHEET* SCH_SHEET_PATH::Last() const
|
||||
{
|
||||
if( !empty() )
|
||||
|
@ -499,10 +520,7 @@ void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums )
|
|||
std::sort( begin(), end(),
|
||||
[]( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
|
||||
{
|
||||
wxString pageA = a.GetPageNumber();
|
||||
wxString pageB = b.GetPageNumber();
|
||||
|
||||
return SCH_SHEET::ComparePageNum( pageA, pageB ) < 0;
|
||||
return a.ComparePageNumAndName(b) < 0;
|
||||
} );
|
||||
|
||||
if( aUpdateVirtualPageNums )
|
||||
|
|
|
@ -213,6 +213,16 @@ public:
|
|||
*/
|
||||
int Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const;
|
||||
|
||||
/**
|
||||
* Compare sheets by their page number and then by their name. Finally
|
||||
* compare using #Cmp()
|
||||
*
|
||||
* @return -1 if aSheetPathToTest is greater than this (should appear later in the sort order)
|
||||
* 0 if aSheetPathToTest is equal to this
|
||||
* 1 if aSheetPathToTest is less than this (should appear earlier in the sort order)
|
||||
*/
|
||||
int ComparePageNumAndName( const SCH_SHEET_PATH& aSheetPathToTest ) const;
|
||||
|
||||
/**
|
||||
* Return a pointer to the last #SCH_SHEET of the list.
|
||||
*
|
||||
|
@ -469,6 +479,9 @@ public:
|
|||
/**
|
||||
* Sort the list of sheets by page number. This should be called after #BuildSheetList
|
||||
*
|
||||
* If page numbers happen to be equal, then it compares the sheet names to ensure deterministic
|
||||
* ordering.
|
||||
*
|
||||
* @param aUpdateVirtualPageNums If true, updates the virtual page numbers to match the new
|
||||
* ordering
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue