diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index e0a6ee6417..ff0c5f3769 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -327,7 +327,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); Zoom_Automatique( false ); SetSheetNumberAndCount(); - + g_RootSheet->SetPageNumbers(); m_canvas->Refresh( true ); return true; diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index d197b4d22f..4d149a1e6d 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -56,6 +56,7 @@ SCH_SHEET::SCH_SHEET( const wxPoint& pos ) : m_screen = NULL; m_name.Printf( wxT( "Sheet%8.8lX" ), (long) m_TimeStamp ); m_fileName.Printf( wxT( "file%8.8lX.sch" ), (long) m_TimeStamp ); + m_number = 1; } @@ -72,6 +73,7 @@ SCH_SHEET::SCH_SHEET( const SCH_SHEET& aSheet ) : m_name = aSheet.m_name; m_fileName = aSheet.m_fileName; m_pins = aSheet.m_pins; + m_number = aSheet.m_number; for( size_t i = 0; i < m_pins.size(); i++ ) m_pins[i].SetParent( this ); @@ -182,11 +184,6 @@ bool SCH_SHEET::Load( LINE_READER& aLine, wxString& aErrorMsg ) SCH_SHEET_PIN* sheetPin; char* ptcar; - if( IsRootSheet() ) - m_number = 1; - else - m_number = GetRootSheet()->CountSheets(); - SetTimeStamp( GetNewTimeStamp() ); // sheets are added to the GetDrawItems() like other schematic components. @@ -1166,6 +1163,21 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter ) } +void SCH_SHEET::SetPageNumbers() +{ + int pageNumber = 1; + std::vector< const SCH_SHEET* > sheets; + + GetRootSheet()->GetSheets( sheets ); + + for( unsigned i = 0; i < sheets.size(); i++ ) + { + const_cast< SCH_SHEET* >( sheets[i] )->m_number = pageNumber; + pageNumber += 1; + } +} + + SCH_SHEET* SCH_SHEET::FindSheetByName( const wxString& aSheetName ) { std::vector< const SCH_SHEET* > sheets; @@ -1175,7 +1187,7 @@ SCH_SHEET* SCH_SHEET::FindSheetByName( const wxString& aSheetName ) for( unsigned i = 0; i < sheets.size(); i++ ) { if( sheets[i]->GetName().CmpNoCase( aSheetName ) == 0 ) - return const_cast< SCH_SHEET*>( sheets[i] ); + return const_cast< SCH_SHEET* >( sheets[i] ); } return NULL; diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 5e11eb6dab..f5182f8b97 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -610,6 +610,18 @@ public: EDA_ITEM* Clone() const; + /** + * Function SetPageNumbers + * + * sets the page numbers for each sheet by load order. + * + * The root sheet is always used to set the page numbers no matter which sheet this + * function is called. This function will only have meaning when loading legacy + * schematics. The upcoming s-expression schematic file format will allow for user + * defined page numbers. + */ + void SetPageNumbers(); + /** * Function FindSheetByName *