wip refactoring: use virtual page numbers for page navigation

"Real" page numbers are just strings and could be duplicated. Virtual page
numbers are guaranteed to be unique, since they indicate a sequence.
This commit is contained in:
Roberto Fernandez Bautista 2022-08-04 16:58:15 -04:00 committed by Jeff Young
parent 51bcfaafd7
commit 516c4cb2d3
6 changed files with 52 additions and 34 deletions

View File

@ -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<SCH_TEXT*>( m_parent );
@ -750,42 +750,32 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const
if( it != Schematic()->GetPageRefsMap().end() )
{
std::map<int, wxString> sheetNames;
std::vector<int> 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() ] = _( "<root sheet>" );
else
sheetNames[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
}
std::map<int, wxString> sheetNames = Schematic()->GetVirtualPageToSheetNamesMap();
std::map<int, wxString> 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;

View File

@ -1292,31 +1292,29 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
}
else
{
std::vector<wxString> pageListCopy;
std::vector<int> 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<int, wxString> 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();

View File

@ -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 );

View File

@ -289,6 +289,33 @@ bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
}
std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
{
std::map<int, wxString> namesMap;
for( const SCH_SHEET_PATH& sheet : GetSheets() )
{
if( sheet.size() == 1 )
namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
else
namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
}
return namesMap;
}
std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
{
std::map<int, wxString> pagesMap;
for( const SCH_SHEET_PATH& sheet : GetSheets() )
pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
return pagesMap;
}
wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
{
wxString newbuf;

View File

@ -161,6 +161,9 @@ public:
std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
std::map<int, wxString> GetVirtualPageToSheetNamesMap() const;
std::map<int, wxString> GetVirtualPageToSheetPagesMap() const;
wxString ConvertRefsToKIIDs( const wxString& aSource ) const;
wxString ConvertKIIDsToRefs( const wxString& aSource ) const;

View File

@ -55,16 +55,16 @@ void SCH_NAVIGATE_TOOL::CleanHistory()
int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent )
{
wxString* page = aEvent.Parameter<wxString*>();
int* page = aEvent.Parameter<int*>();
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 );