eeschema page numbers: match print and plotting ordering to page number ordering

- new function SCH_SHEET_LIST::SortByPageNumbers() which uses SCH_SHEET::ComparePageNum for the sorting algorithm
- SortByPageNumbers() is called after every call to BuildSheetList()
This commit is contained in:
Roberto Fernandez Bautista 2020-11-29 18:30:58 +00:00 committed by Wayne Stambaugh
parent 9380d6f533
commit b1270bc9ab
8 changed files with 65 additions and 0 deletions

View File

@ -54,9 +54,14 @@ void DIALOG_PLOT_SCHEMATIC::CreateDXFFile( bool aPlotAll, bool aPlotFrameRef,
SCH_SHEET_LIST sheetList;
if( aPlotAll )
{
sheetList.BuildSheetList( &schframe->Schematic().Root(), true );
sheetList.SortByPageNumbers();
}
else
{
sheetList.push_back( schframe->GetCurrentSheet() );
}
REPORTER& reporter = m_MessagesBox->Reporter();

View File

@ -102,9 +102,14 @@ void DIALOG_PLOT_SCHEMATIC::createHPGLFile( bool aPlotAll, bool aPlotFrameRef,
SCH_SHEET_LIST sheetList;
if( aPlotAll )
{
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
sheetList.SortByPageNumbers();
}
else
{
sheetList.push_back( m_parent->GetCurrentSheet() );
}
REPORTER& reporter = m_MessagesBox->Reporter();

View File

@ -57,9 +57,14 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef,
SCH_SHEET_LIST sheetList;
if( aPlotAll )
{
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
sheetList.SortByPageNumbers();
}
else
{
sheetList.push_back( m_parent->GetCurrentSheet() );
}
// Allocate the plotter and set the job level parameter
PDF_PLOTTER* plotter = new PDF_PLOTTER();

View File

@ -54,9 +54,14 @@ void DIALOG_PLOT_SCHEMATIC::createPSFile( bool aPlotAll, bool aPlotFrameRef,
SCH_SHEET_LIST sheetList;
if( aPlotAll )
{
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
sheetList.SortByPageNumbers();
}
else
{
sheetList.push_back( m_parent->GetCurrentSheet() );
}
for( unsigned i = 0; i < sheetList.size(); i++ )
{

View File

@ -53,9 +53,14 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef,
SCH_SHEET_LIST sheetList;
if( aPrintAll )
{
sheetList.BuildSheetList( &m_parent->Schematic().Root(), true );
sheetList.SortByPageNumbers();
}
else
{
sheetList.push_back( m_parent->GetCurrentSheet() );
}
for( unsigned i = 0; i < sheetList.size(); i++ )
{

View File

@ -426,7 +426,10 @@ void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber )
SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet, bool aCheckIntegrity )
{
if( aSheet != NULL )
{
BuildSheetList( aSheet, aCheckIntegrity );
SortByPageNumbers();
}
}
@ -477,6 +480,29 @@ void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity )
}
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;
} );
if( aUpdateVirtualPageNums )
{
int virtualPageNum = 1;
for( SCH_SHEET_PATH& sheet : *this )
{
sheet.SetVirtualPageNumber( virtualPageNum++ );
}
}
}
bool SCH_SHEET_LIST::NameExists( const wxString& aSheetName )
{
for( const SCH_SHEET_PATH& sheet : *this )

View File

@ -436,12 +436,25 @@ public:
* Build the list of sheets and their sheet path from \a aSheet.
*
* If \a aSheet is the root sheet, the full sheet path and sheet list are built.
*
* The list will be ordered as per #SCH_SCREEN::GetSheets which results in sheets being ordered
* in the legacy way of using the X and Y positions of the sheets.
*
* @see #SortByPageNumbers to sort by page numbers
*
* @param aSheet is the starting sheet from which the list is built, or NULL
* indicating that g_RootSheet should be used.
* @throw std::bad_alloc if the memory for the sheet path list could not be allocated.
*/
void BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity );
/**
* Sorts the list of sheets by page number. This should be called after #BuildSheetList
*
* @param aUpdateVirtualPageNums If true, updates the virtual page numbers to match the new
* ordering
*/
void SortByPageNumbers( bool aUpdateVirtualPageNums = true );
bool NameExists( const wxString& aSheetName );

View File

@ -357,6 +357,7 @@ SCH_SHEET_LIST& SCHEMATIC::GetFullHierarchy() const
hierarchy.clear();
hierarchy.BuildSheetList( m_rootSheet, false );
hierarchy.SortByPageNumbers();
return hierarchy;
}