diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 6049849f3f..c81edada32 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -740,7 +740,7 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const { constexpr int START_ID = 1; - static wxString back = "HYPERTEXT_BACK"; + static int back = -1; wxMenu menu; SCH_TEXT* label = dynamic_cast( m_parent ); @@ -750,42 +750,32 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const if( it != Schematic()->GetPageRefsMap().end() ) { - std::map sheetNames; - std::vector pageListCopy; + std::vector pageListCopy; pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); if( !Schematic()->Settings().m_IntersheetRefsListOwnPage ) { - wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); + int currentPage = Schematic()->CurrentSheet().GetVirtualPageNumber(); alg::delete_matching( pageListCopy, currentPage ); if( pageListCopy.empty() ) return; } - std::sort( pageListCopy.begin(), pageListCopy.end(), - []( const wxString& a, const wxString& b ) -> bool - { - return StrNumCmp( a, b, true ) < 0; - } ); + std::sort( pageListCopy.begin(), pageListCopy.end() ); - for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() ) - { - if( sheet.size() == 1 ) - sheetNames[ sheet.GetVirtualPageNumber() ] = _( "" ); - else - sheetNames[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName(); - } + std::map sheetNames = Schematic()->GetVirtualPageToSheetNamesMap(); + std::map sheetPages = Schematic()->GetVirtualPageToSheetPagesMap(); for( int i = 0; i < (int) pageListCopy.size(); ++i ) { menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ), - pageListCopy[i], + sheetPages[ pageListCopy[i] ], sheetNames[ pageListCopy[i] ] ) ); } menu.AppendSeparator(); - menu.Append( 999, _( "Back to Previous Selected Sheet" ) ); + menu.Append( 999 + START_ID, _( "Back to Previous Selected Sheet" ) ); int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID; void* param = nullptr; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 6ec58b1994..35207084a8 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -1292,31 +1292,29 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const } else { - std::vector pageListCopy; + std::vector pageListCopy; pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() ); - std::sort( pageListCopy.begin(), pageListCopy.end(), - []( const wxString& a, const wxString& b ) -> bool - { - return StrNumCmp( a, b, true ) < 0; - } ); + std::sort( pageListCopy.begin(), pageListCopy.end() ); if( !settings.m_IntersheetRefsListOwnPage ) { - wxString currentPage = Schematic()->CurrentSheet().GetPageNumber(); + int currentPage = Schematic()->CurrentSheet().GetVirtualPageNumber(); alg::delete_matching( pageListCopy, currentPage ); } + std::map sheetPages = Schematic()->GetVirtualPageToSheetPagesMap(); + if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) ) { ref.Append( wxString::Format( wxT( "%s..%s" ), - pageListCopy.front(), - pageListCopy.back() ) ); + sheetPages[pageListCopy.front()], + sheetPages[pageListCopy.back()] ) ); } else { - for( const wxString& pageNo : pageListCopy ) - ref.Append( wxString::Format( wxT( "%s," ), pageNo ) ); + for( const int& pageNo : pageListCopy ) + ref.Append( wxString::Format( wxT( "%s," ), sheetPages[pageNo] ) ); if( !ref.IsEmpty() && ref.Last() == ',' ) ref.RemoveLast(); diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 1cdb99d011..b94d3be3be 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -415,7 +415,7 @@ void SCH_TEXT::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const sheetNames[destPage] ) ); int sel = aFrame->GetPopupMenuSelectionFromUser( menu ); - void* param = &sheetPages[destPage]; + void* param = &destPage; if( param ) aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param ); diff --git a/eeschema/schematic.cpp b/eeschema/schematic.cpp index 97a0287da5..98b30715e6 100644 --- a/eeschema/schematic.cpp +++ b/eeschema/schematic.cpp @@ -289,6 +289,33 @@ bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const } +std::map SCHEMATIC::GetVirtualPageToSheetNamesMap() const +{ + std::map namesMap; + + for( const SCH_SHEET_PATH& sheet : GetSheets() ) + { + if( sheet.size() == 1 ) + namesMap[sheet.GetVirtualPageNumber()] = _( "" ); + else + namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName(); + } + + return namesMap; +} + + +std::map SCHEMATIC::GetVirtualPageToSheetPagesMap() const +{ + std::map pagesMap; + + for( const SCH_SHEET_PATH& sheet : GetSheets() ) + pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber(); + + return pagesMap; +} + + wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const { wxString newbuf; diff --git a/eeschema/schematic.h b/eeschema/schematic.h index 7dde3d71e5..a6ad9742a1 100644 --- a/eeschema/schematic.h +++ b/eeschema/schematic.h @@ -161,6 +161,9 @@ public: std::map>& GetPageRefsMap() { return m_labelToPageRefsMap; } + std::map GetVirtualPageToSheetNamesMap() const; + std::map GetVirtualPageToSheetPagesMap() const; + wxString ConvertRefsToKIIDs( const wxString& aSource ) const; wxString ConvertKIIDsToRefs( const wxString& aSource ) const; diff --git a/eeschema/tools/sch_navigate_tool.cpp b/eeschema/tools/sch_navigate_tool.cpp index 1f9afdebbf..27f0cf6cb6 100644 --- a/eeschema/tools/sch_navigate_tool.cpp +++ b/eeschema/tools/sch_navigate_tool.cpp @@ -55,16 +55,16 @@ void SCH_NAVIGATE_TOOL::CleanHistory() int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent ) { - wxString* page = aEvent.Parameter(); + int* page = aEvent.Parameter(); wxCHECK( page, 0 ); auto goToPage = - [&]( wxString* aPage ) + [&]( int* aPage ) { for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() ) { - if( sheet.GetPageNumber() == *aPage ) + if( sheet.GetVirtualPageNumber() == *aPage ) { changeSheet( sheet ); return; @@ -72,7 +72,7 @@ int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent ) } }; - if( *page == "HYPERTEXT_BACK" ) + if( *page == -1 ) Back( aEvent ); else goToPage( page );