From a03e6e4926641cf7e9a3029908871e608842c595 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 6 Dec 2021 07:47:18 -0500 Subject: [PATCH] Revert "Eeschema: fix broken page numbers when renaming a sheet file name." This reverts commit a468a79948a544aa3313b20a101b7c92dcfe3375. --- eeschema/dialogs/dialog_sheet_properties.cpp | 7 ++- eeschema/hierarch.cpp | 7 +-- eeschema/sch_edit_frame.cpp | 7 ++- eeschema/sch_field.cpp | 7 +-- .../sch_plugins/altium/sch_altium_plugin.cpp | 9 ++- .../cadstar/cadstar_sch_archive_loader.cpp | 6 +- eeschema/sch_screen.cpp | 2 +- eeschema/sch_sheet.cpp | 62 ++++++++++++++++--- eeschema/sch_sheet.h | 34 +++++++--- eeschema/sch_sheet_path.cpp | 38 +++++++++--- eeschema/sch_sheet_path.h | 9 +++ eeschema/sch_text.cpp | 2 +- eeschema/schematic.cpp | 2 +- eeschema/tools/sch_drawing_tools.cpp | 3 +- eeschema/tools/sch_edit_tool.cpp | 6 +- eeschema/tools/sch_editor_control.cpp | 8 ++- eeschema/tools/sch_navigate_tool.cpp | 6 +- qa/eeschema/test_sch_sheet_list.cpp | 46 +++++++------- qa/eeschema/test_sch_sheet_path.cpp | 17 +++-- 19 files changed, 193 insertions(+), 85 deletions(-) diff --git a/eeschema/dialogs/dialog_sheet_properties.cpp b/eeschema/dialogs/dialog_sheet_properties.cpp index d8c92b6363..cc2d5b8cd0 100644 --- a/eeschema/dialogs/dialog_sheet_properties.cpp +++ b/eeschema/dialogs/dialog_sheet_properties.cpp @@ -165,7 +165,7 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataToWindow() instance.push_back( m_sheet ); - wxString nextPageNumber = m_sheet->GetPageNumber(); + wxString nextPageNumber = m_sheet->GetPageNumber( instance ); m_pageNumberTextCtrl->ChangeValue( nextPageNumber ); @@ -373,7 +373,10 @@ bool DIALOG_SHEET_PROPERTIES::TransferDataFromWindow() instance.push_back( m_sheet ); - m_sheet->SetPageNumber( m_pageNumberTextCtrl->GetValue() ); + if( m_sheet->IsNew() ) + m_sheet->AddInstance( instance.Path() ); + + m_sheet->SetPageNumber( instance, m_pageNumberTextCtrl->GetValue() ); m_frame->TestDanglingEnds(); diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index e82d88abcd..4267e136bf 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -179,13 +179,10 @@ void HIERARCHY_NAVIG_DLG::buildHierarchyTree( SCH_SHEET_PATH* aList, wxTreeItemI for( SCH_ITEM* aItem : sheetChildren ) { SCH_SHEET* sheet = static_cast( aItem ); - - wxCHECK2( sheet, continue ); - aList->push_back( sheet ); wxString sheetName = formatPageString( sheet->GetFields()[SHEETNAME].GetShownText(), - sheet->GetPageNumber() ); + sheet->GetPageNumber( *aList ) ); m_nbsheets++; wxTreeItemId menu; menu = m_Tree->AppendItem( *aPreviousmenu, sheetName, 0, 1 ); @@ -269,7 +266,7 @@ wxString HIERARCHY_NAVIG_DLG::getRootString() SCH_SHEET_PATH rootPath; rootPath.push_back( rootSheet ); - return formatPageString ( _( "Root" ), rootSheet->GetPageNumber() ); + return formatPageString ( _( "Root" ), rootSheet->GetPageNumber( rootPath ) ); } diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 559e7eef59..4aada50c3f 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -542,7 +542,7 @@ void SCH_EDIT_FRAME::SetSheetNumberAndCount() GetCurrentSheet().SetVirtualPageNumber( sheet_number ); GetScreen()->SetVirtualPageNumber( sheet_number ); - GetScreen()->SetPageNumber( Schematic().CurrentSheet().Last()->GetPageNumber() ); + GetScreen()->SetPageNumber( GetCurrentSheet().GetPageNumber() ); } @@ -583,7 +583,8 @@ void SCH_EDIT_FRAME::CreateScreens() SCH_SHEET_PATH rootSheetPath; rootSheetPath.push_back( &m_schematic->Root() ); m_schematic->RootScreen()->SetPageNumber( wxT( "1" ) ); - m_schematic->Root().SetPageNumber( wxT( "1" ) ); + m_schematic->Root().AddInstance( rootSheetPath.Path() ); + m_schematic->Root().SetPageNumber( rootSheetPath, wxT( "1" ) ); if( GetScreen() == nullptr ) { @@ -1395,7 +1396,7 @@ void SCH_EDIT_FRAME::RecomputeIntersheetRefs() for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() ) { if( sheet.LastScreen() == screen ) - pageNumbers.push_back( sheet.Last()->GetPageNumber() ); + pageNumbers.push_back( sheet.GetPageNumber() ); } for( SCH_ITEM* item : screen->Items() ) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 0ea6853469..e753284924 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -627,10 +627,9 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) std::vector pageListCopy; pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); - if( !Schematic()->Settings().m_IntersheetRefsListOwnPage ) { - wxString currentPage = Schematic()->CurrentSheet().Last()->GetPageNumber(); + wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); alg::delete_matching( pageListCopy, currentPage ); if( pageListCopy.empty() ) @@ -646,9 +645,9 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() ) { if( sheet.size() == 1 ) - sheetNames[ sheet.Last()->GetPageNumber() ] = _( "" ); + sheetNames[ sheet.GetPageNumber() ] = _( "" ); else - sheetNames[ sheet.Last()->GetPageNumber() ] = sheet.Last()->GetName(); + sheetNames[ sheet.GetPageNumber() ] = sheet.Last()->GetName(); } for( int i = 0; i < (int) pageListCopy.size(); ++i ) diff --git a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp index b4a2979aa4..32798cb9e7 100644 --- a/eeschema/sch_plugins/altium/sch_altium_plugin.cpp +++ b/eeschema/sch_plugins/altium/sch_altium_plugin.cpp @@ -180,7 +180,8 @@ SCH_SHEET* SCH_ALTIUM_PLUGIN::Load( const wxString& aFileName, SCHEMATIC* aSchem SCH_SHEET_PATH sheetpath; sheetpath.push_back( m_rootSheet ); - m_rootSheet->SetPageNumber( "#" ); // We'll update later if we find a + m_rootSheet->AddInstance( sheetpath.Path() ); + m_rootSheet->SetPageNumber( sheetpath, "#" ); // We'll update later if we find a // pageNumber record for it } @@ -1519,7 +1520,9 @@ void SCH_ALTIUM_PLUGIN::ParseSheetSymbol( int aIndex, m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); sheetpath.push_back( sheet ); - sheet->SetPageNumber( "#" ); // We'll update later if we find a pageNumber record for it. + sheet->AddInstance( sheetpath.Path() ); + sheet->SetPageNumber( sheetpath, "#" ); // We'll update later if we find a pageNumber + // record for it m_sheets.insert( { aIndex, sheet } ); } @@ -2340,7 +2343,7 @@ void SCH_ALTIUM_PLUGIN::ParseParameter( const std::map& aPro SCH_SHEET_PATH sheetpath; m_rootSheet->LocatePathOfScreen( m_currentSheet->GetScreen(), &sheetpath ); - sheetpath.Last()->SetPageNumber( elem.text ); + m_rootSheet->SetPageNumber( sheetpath, elem.text ); } else if( paramName == "TITLE" ) { diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index d2c47e4a3b..141a64cc18 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -265,7 +265,8 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSheets() const std::vector& orphanSheets = findOrphanSheets(); SCH_SHEET_PATH rootPath; rootPath.push_back( m_rootSheet ); - m_rootSheet->SetPageNumber( wxT( "1" ) ); + m_rootSheet->AddInstance( rootPath.Path() ); + m_rootSheet->SetPageNumber( rootPath, wxT( "1" ) ); if( orphanSheets.size() > 1 ) { @@ -2148,9 +2149,10 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets( sheet->GetScreen()->SetFileName( fn.GetFullPath() ); aParentSheet.Last()->GetScreen()->Append( sheet ); instance.push_back( sheet ); + sheet->AddInstance( instance.Path() ); wxString pageNumStr = wxString::Format( "%d", getSheetNumber( aCadstarSheetID ) ); - sheet->SetPageNumber( pageNumStr ); + sheet->SetPageNumber( instance, pageNumStr ); sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 546636d6e7..1d67265f12 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -92,7 +92,7 @@ SCH_SCREEN::~SCH_SCREEN() SCHEMATIC* SCH_SCREEN::Schematic() const { wxCHECK_MSG( GetParent() && GetParent()->Type() == SCHEMATIC_T, nullptr, - "SCH_SCREEN must have a SCHEMATIC parent!" ); + "SCH_SCREEN must have a SCHEMATIC parent!" ); return static_cast( GetParent() ); } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 202fceb217..add3005a4c 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -138,7 +138,7 @@ SCH_SHEET::SCH_SHEET( const SCH_SHEET& aSheet ) : m_borderWidth = aSheet.m_borderWidth; m_borderColor = aSheet.m_borderColor; m_backgroundColor = aSheet.m_backgroundColor; - m_pageNumber = aSheet.m_pageNumber; + m_instances = aSheet.m_instances; if( m_screen ) m_screen->IncRefCount(); @@ -256,7 +256,7 @@ bool SCH_SHEET::ResolveTextVar( wxString* token, int aDepth ) const { if( sheet.Last() == this ) // Current sheet path found { - *token = wxString::Format( "%s", sheet.Last()->GetPageNumber() ); + *token = wxString::Format( "%s", sheet.GetPageNumber() ); return true; } } @@ -308,7 +308,7 @@ void SCH_SHEET::SwapData( SCH_ITEM* aItem ) std::swap( m_borderWidth, sheet->m_borderWidth ); std::swap( m_borderColor, sheet->m_borderColor ); std::swap( m_backgroundColor, sheet->m_backgroundColor ); - std::swap( m_pageNumber, sheet->m_pageNumber ); + std::swap( m_instances, sheet->m_instances ); } @@ -1096,7 +1096,8 @@ SCH_SHEET& SCH_SHEET::operator=( const SCH_ITEM& aItem ) m_pins.back()->SetParent( this ); } - m_pageNumber = m_pageNumber; + for( const SCH_SHEET_INSTANCE& instance : sheet->m_instances ) + m_instances.emplace_back( instance ); } return *this; @@ -1120,15 +1121,60 @@ bool SCH_SHEET::operator <( const SCH_ITEM& aItem ) const } -wxString SCH_SHEET::GetPageNumber() const +bool SCH_SHEET::AddInstance( const KIID_PATH& aSheetPath ) { - return m_pageNumber; + // a empty sheet path is illegal: + wxCHECK( aSheetPath.size() > 0, false ); + + wxString path; + + for( const SCH_SHEET_INSTANCE& instance : m_instances ) + { + // if aSheetPath is found, nothing to do: + if( instance.m_Path == aSheetPath ) + return false; + } + + SCH_SHEET_INSTANCE instance; + + instance.m_Path = aSheetPath; + + // This entry does not exist: add it with an empty page number. + m_instances.emplace_back( instance ); + return true; } -void SCH_SHEET::SetPageNumber( const wxString& aPageNumber ) +wxString SCH_SHEET::GetPageNumber( const SCH_SHEET_PATH& aInstance ) const { - m_pageNumber = aPageNumber; + wxString pageNumber; + KIID_PATH path = aInstance.Path(); + + for( const SCH_SHEET_INSTANCE& instance : m_instances ) + { + if( instance.m_Path == path ) + { + pageNumber = instance.m_PageNumber; + break; + } + } + + return pageNumber; +} + + +void SCH_SHEET::SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber ) +{ + KIID_PATH path = aInstance.Path(); + + for( SCH_SHEET_INSTANCE& instance : m_instances ) + { + if( instance.m_Path == path ) + { + instance.m_PageNumber = aPageNumber; + break; + } + } } diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 2b79337c2c..105b2f95c8 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -390,18 +390,36 @@ public: EDA_ITEM* Clone() const override; /** - * Return the sheet page number. - * - * @return the page number for the sheet. + * @return the list of #SCH_SHEET_INSTANCE objects for this sheet. */ - wxString GetPageNumber() const; + const std::vector GetInstances() const; /** - * Set the page number for the sheet. + * Add a new instance \a aSheetPath to the instance list. * - * @param[in] aPageNumber is the new page number for the sheet. + * If \a aSheetPath does not already exist, it is added to the list. If already exists + * in the list, do nothing. Sheet instances allow for the sharing in complex hierarchies + * which allows for per instance data such as page number for sheets to stored. + * + * @param[in] aInstance is the #KIID_PATH of the sheet instance to the instance list. + * @return false if the instance already exists, true if the instance was added. */ - void SetPageNumber( const wxString& aPageNumber ); + bool AddInstance( const KIID_PATH& aInstance ); + + /** + * Return the sheet page number for \a aInstance. + * + * @return the page number for the requested sheet instance. + */ + wxString GetPageNumber( const SCH_SHEET_PATH& aInstance ) const; + + /** + * Set the page number for the sheet instance \a aInstance. + * + * @param[in] aInstance is the hierarchical path of the sheet. + * @param[in] aReference is the new page number for the sheet. + */ + void SetPageNumber( const SCH_SHEET_PATH& aInstance, const wxString& aPageNumber ); /** * Compares page numbers of schematic sheets. @@ -443,7 +461,7 @@ private: KIGFX::COLOR4D m_borderColor; KIGFX::COLOR4D m_backgroundColor; - wxString m_pageNumber; + std::vector m_instances; }; diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 5e1494cfa9..c8fd73a646 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -159,8 +159,8 @@ int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const int SCH_SHEET_PATH::ComparePageNumAndName( const SCH_SHEET_PATH& aSheetPathToTest ) const { - wxString pageA = Last()->GetPageNumber(); - wxString pageB = aSheetPathToTest.Last()->GetPageNumber(); + wxString pageA = GetPageNumber(); + wxString pageB = aSheetPathToTest.GetPageNumber(); int pageNumComp = SCH_SHEET::ComparePageNum( pageA, pageB ); @@ -454,6 +454,26 @@ bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxStr } +wxString SCH_SHEET_PATH::GetPageNumber() const +{ + SCH_SHEET* sheet = Last(); + + wxCHECK( sheet, wxEmptyString ); + + return sheet->GetPageNumber( *this ); +} + + +void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber ) +{ + SCH_SHEET* sheet = Last(); + + wxCHECK( sheet, /* void */ ); + + sheet->SetPageNumber( *this, aPageNumber ); +} + + void SCH_SHEET_PATH::MakeFilePathRelativeToParentSheet() { wxCHECK( m_sheets.size() > 1, /* void */ ); @@ -560,7 +580,7 @@ void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums ) std::sort( begin(), end(), []( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool { - return a.ComparePageNumAndName( b ) < 0; + return a.ComparePageNumAndName(b) < 0; } ); if( aUpdateVirtualPageNums ) @@ -591,7 +611,7 @@ bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const { for( const SCH_SHEET_PATH& sheet : *this ) { - if( sheet.Last()->GetPageNumber() == aPageNumber ) + if( sheet.GetPageNumber() == aPageNumber ) return true; } @@ -943,7 +963,8 @@ void SCH_SHEET_LIST::UpdateSheetInstances( const std::vector wxCHECK2( sheet, continue ); - sheet->SetPageNumber( it->m_PageNumber ); + sheet->AddInstance( instance.Path() ); + sheet->SetPageNumber( instance, it->m_PageNumber ); } } @@ -971,7 +992,7 @@ std::vector SCH_SHEET_LIST::GetSheetInstances() const wxCHECK2( sheet, continue ); instance.m_Path = path.PathWithoutRootUuid(); - instance.m_PageNumber = sheet->GetPageNumber(); + instance.m_PageNumber = sheet->GetPageNumber( path ); retval.push_back( instance ); } @@ -988,7 +1009,7 @@ bool SCH_SHEET_LIST::AllSheetPageNumbersEmpty() const wxCHECK2( sheet, continue ); - if( !sheet->GetPageNumber().IsEmpty() ) + if( !sheet->GetPageNumber( instance ).IsEmpty() ) return false; } @@ -1010,8 +1031,9 @@ void SCH_SHEET_LIST::SetInitialPageNumbers() wxCHECK2( sheet, continue ); + sheet->AddInstance( instance.Path() ); tmp.Printf( "%d", pageNumber ); - sheet->SetPageNumber( tmp ); + sheet->SetPageNumber( instance, tmp ); pageNumber += 1; } } diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index d9411976f4..5ac9e44f73 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -183,6 +183,15 @@ public: int GetVirtualPageNumber() const { return m_virtualPageNumber; } + /** + * Set the sheet instance user definable page number. + * + * @note User definable page numbers can be any string devoid of white space characters. + */ + void SetPageNumber( const wxString& aPageNumber ); + + wxString GetPageNumber() const; + const SCH_SHEET* GetSheet( unsigned aIndex ) const { SCH_SHEET* retv = nullptr; diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 579bcdb949..dd3deee4bc 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -1271,7 +1271,7 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const if( !settings.m_IntersheetRefsListOwnPage ) { - wxString currentPage = Schematic()->CurrentSheet().Last()->GetPageNumber(); + wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); alg::delete_matching( pageListCopy, currentPage ); } diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 6b37695343..7b4a61d9fa 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -126,7 +126,7 @@ bool SCHEMATIC::ResolveTextVar( wxString* token, int aDepth ) const { if( token->IsSameAs( wxT( "#" ) ) ) { - *token = CurrentSheet().Last()->GetPageNumber(); + *token = CurrentSheet().GetPageNumber(); return true; } else if( token->IsSameAs( wxT( "##" ) ) ) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 00920c75df..43a266cebe 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -1369,7 +1369,8 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) { SCH_SHEET_PATH sheetPath = instance; sheetPath.push_back( sheet ); - sheetPath.Last()->SetPageNumber( wxString::Format( "%d", pageNum++ ) ); + sheet->AddInstance( sheetPath.Path() ); + sheet->SetPageNumber( sheetPath, wxString::Format( "%d", pageNum++ ) ); } if( m_frame->EditSheetProperties( static_cast( sheet ), diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 9d6a7f542a..6c65db80c8 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1752,7 +1752,7 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent ) wxString msg; wxString sheetPath = instance.PathHumanReadable( false ); - wxString pageNumber = instance.Last()->GetPageNumber(); + wxString pageNumber = instance.GetPageNumber(); msg.Printf( _( "Enter page number for sheet path%s" ), ( sheetPath.Length() > 20 ) ? "\n" + sheetPath : " " + sheetPath ); @@ -1761,12 +1761,12 @@ int SCH_EDIT_TOOL::EditPageNumber( const TOOL_EVENT& aEvent ) dlg.SetTextValidator( wxFILTER_ALPHANUMERIC ); // No white space. - if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == instance.Last()->GetPageNumber() ) + if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == instance.GetPageNumber() ) return 0; m_frame->SaveCopyInUndoList( screen, sheet, UNDO_REDO::CHANGED, false ); - instance.Last()->SetPageNumber( dlg.GetValue() ); + instance.SetPageNumber( dlg.GetValue() ); if( instance == m_frame->GetCurrentSheet() ) { diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 2954d733ae..5f621843b5 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -481,7 +481,7 @@ int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent ) { if( afterSheet ) { - if( afterSheet->Last()->GetPageNumber() == sheet->Last()->GetPageNumber() ) + if( afterSheet->GetPageNumber() == sheet->GetPageNumber() ) afterSheet = nullptr; continue; @@ -1541,6 +1541,8 @@ SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPas SCH_SHEET_PATH sheetPath = aPastePath; sheetPath.push_back( aSheet ); + aSheet->AddInstance( sheetPath.Path() ); + wxString pageNum; if( m_clipboardSheetInstances.count( aClipPath ) > 0 ) @@ -1548,7 +1550,7 @@ SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPas else pageNum = wxString::Format( "%d", static_cast( aPastedSheetsSoFar->size() ) ); - sheetPath.Last()->SetPageNumber( pageNum ); + aSheet->SetPageNumber( sheetPath, pageNum ); aPastedSheetsSoFar->push_back( sheetPath ); if( aSheet->GetScreen() == nullptr ) @@ -1921,7 +1923,7 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) while( hierarchy.PageNumberExists( pageNum ) ) pageNum = wxString::Format( "%d", ++page ); - pastedSheet.Last()->SetPageNumber( pageNum ); + pastedSheet.SetPageNumber( pageNum ); hierarchy.push_back( pastedSheet ); } } diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index a85e7bfd0e..954e48de1a 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019 CERN - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 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 @@ -46,7 +46,7 @@ int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent ) { for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() ) { - if( sheet.Last()->GetPageNumber() == *aPage ) + if( sheet.GetPageNumber() == *aPage ) { m_frame->GetToolManager()->RunAction( ACTIONS::cancelInteractive, true ); m_frame->GetToolManager()->RunAction( EE_ACTIONS::clearSelection, true ); @@ -69,7 +69,7 @@ int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent ) } else { - m_hypertextStack.push( m_frame->GetCurrentSheet().Last()->GetPageNumber() ); + m_hypertextStack.push( m_frame->GetCurrentSheet().GetPageNumber() ); goToPage( page ); } diff --git a/qa/eeschema/test_sch_sheet_list.cpp b/qa/eeschema/test_sch_sheet_list.cpp index 76472ac15a..e306a98677 100644 --- a/qa/eeschema/test_sch_sheet_list.cpp +++ b/qa/eeschema/test_sch_sheet_list.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020 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 as published by the @@ -126,9 +126,9 @@ BOOST_AUTO_TEST_CASE( TestSheetListPageProperties ) sheets.SetInitialPageNumbers(); // The root sheet should now be page 1. - BOOST_CHECK_EQUAL( sheets.at( 0 ).Last()->GetPageNumber(), "1" ); - BOOST_CHECK_EQUAL( sheets.at( 1 ).Last()->GetPageNumber(), "2" ); - BOOST_CHECK_EQUAL( sheets.at( 2 ).Last()->GetPageNumber(), "3" ); + BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" ); + BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" ); + BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" ); } @@ -142,8 +142,8 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign ) SCH_SHEET_LIST sheets = m_schematic.GetSheets(); BOOST_CHECK_EQUAL( sheets.size(), 2 ); - BOOST_CHECK_EQUAL( sheets.at( 0 ).Last()->GetPageNumber(), "i" ); - BOOST_CHECK_EQUAL( sheets.at( 1 ).Last()->GetPageNumber(), "ii" ); + BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" ); + BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" ); } BOOST_TEST_CONTEXT( "Read Root Sheet, prior to modification" ) @@ -154,11 +154,11 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign ) SCH_SHEET_LIST sheets = m_schematic.GetSheets(); BOOST_CHECK_EQUAL( sheets.size(), 5 ); - BOOST_CHECK_EQUAL( sheets.at( 0 ).Last()->GetPageNumber(), "1" ); - BOOST_CHECK_EQUAL( sheets.at( 1 ).Last()->GetPageNumber(), "2" ); - // BOOST_CHECK_EQUAL( sheets.at( 2 ).Last()->GetPageNumber(), "3" ); - // BOOST_CHECK_EQUAL( sheets.at( 3 ).Last()->GetPageNumber(), "4" ); - BOOST_CHECK_EQUAL( sheets.at( 4 ).Last()->GetPageNumber(), "5" ); + BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" ); + BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" ); + BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" ); + BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "4" ); + BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "5" ); } BOOST_TEST_CONTEXT( "Modify page numbers in root sheet" ) @@ -166,11 +166,11 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign ) SCH_SHEET_LIST sheets = m_schematic.GetSheets(); // Amend Page numbers - sheets.at( 0 ).Last()->SetPageNumber( "A" ); - sheets.at( 1 ).Last()->SetPageNumber( "B" ); - sheets.at( 2 ).Last()->SetPageNumber( "C" ); - sheets.at( 3 ).Last()->SetPageNumber( "D" ); - sheets.at( 4 ).Last()->SetPageNumber( "E" ); + sheets.at( 0 ).SetPageNumber( "A" ); + sheets.at( 1 ).SetPageNumber( "B" ); + sheets.at( 2 ).SetPageNumber( "C" ); + sheets.at( 3 ).SetPageNumber( "D" ); + sheets.at( 4 ).SetPageNumber( "E" ); // Save and reload wxString tempName = "complex_hierarchy_shared/complex_hierarchy_modified"; @@ -181,11 +181,11 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign ) sheets = m_schematic.GetSheets(); BOOST_CHECK_EQUAL( sheets.size(), 5 ); - BOOST_CHECK_EQUAL( sheets.at( 0 ).Last()->GetPageNumber(), "A" ); - BOOST_CHECK_EQUAL( sheets.at( 1 ).Last()->GetPageNumber(), "B" ); - BOOST_CHECK_EQUAL( sheets.at( 2 ).Last()->GetPageNumber(), "C" ); - // BOOST_CHECK_EQUAL( sheets.at( 3 ).Last()->GetPageNumber(), "D" ); - BOOST_CHECK_EQUAL( sheets.at( 4 ).Last()->GetPageNumber(), "E" ); + BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "A" ); + BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "B" ); + BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "C" ); + BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "D" ); + BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "E" ); // Cleanup wxRemoveFile( tempFn.GetFullPath() ); @@ -200,8 +200,8 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign ) SCH_SHEET_LIST sheets = m_schematic.GetSheets(); BOOST_CHECK_EQUAL( sheets.size(), 2 ); - BOOST_CHECK_EQUAL( sheets.at( 0 ).Last()->GetPageNumber(), "i" ); - BOOST_CHECK_EQUAL( sheets.at( 1 ).Last()->GetPageNumber(), "ii" ); + BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" ); + BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" ); } } diff --git a/qa/eeschema/test_sch_sheet_path.cpp b/qa/eeschema/test_sch_sheet_path.cpp index da3141fcf3..74c1903db7 100644 --- a/qa/eeschema/test_sch_sheet_path.cpp +++ b/qa/eeschema/test_sch_sheet_path.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2019-2020 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 @@ -85,6 +85,9 @@ BOOST_AUTO_TEST_CASE( Empty ) BOOST_CHECK_THROW( m_empty_path.at( 0 ), std::out_of_range ); + // Sheet paths with no SCH_SCHEET object are illegal. + CHECK_WX_ASSERT( m_empty_path.GetPageNumber() ); + // These accessors return nullptr when empty (i.e. they don't crash) BOOST_CHECK_EQUAL( m_empty_path.Last(), nullptr ); BOOST_CHECK_EQUAL( m_empty_path.LastScreen(), nullptr ); @@ -132,12 +135,14 @@ BOOST_AUTO_TEST_CASE( Compare ) */ BOOST_AUTO_TEST_CASE( SheetPathPageProperties ) { - BOOST_CHECK_EQUAL( m_linear.Last()->GetPageNumber(), wxEmptyString ); + BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), wxEmptyString ); - m_linear.Last()->SetPageNumber( "1" ); - BOOST_CHECK_EQUAL( m_linear.Last()->GetPageNumber(), "1" ); - m_linear.Last()->SetPageNumber( "i" ); - BOOST_CHECK_EQUAL( m_linear.Last()->GetPageNumber(), "i" ); + // Add new instance to sheet object. + BOOST_CHECK( m_linear.Last()->AddInstance( m_linear.Path() ) ); + m_linear.SetPageNumber( "1" ); + BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "1" ); + m_linear.SetPageNumber( "i" ); + BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "i" ); }