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:
parent
51bcfaafd7
commit
516c4cb2d3
|
@ -740,7 +740,7 @@ void SCH_FIELD::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const
|
||||||
{
|
{
|
||||||
constexpr int START_ID = 1;
|
constexpr int START_ID = 1;
|
||||||
|
|
||||||
static wxString back = "HYPERTEXT_BACK";
|
static int back = -1;
|
||||||
wxMenu menu;
|
wxMenu menu;
|
||||||
SCH_TEXT* label = dynamic_cast<SCH_TEXT*>( m_parent );
|
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() )
|
if( it != Schematic()->GetPageRefsMap().end() )
|
||||||
{
|
{
|
||||||
std::map<int, wxString> sheetNames;
|
std::vector<int> pageListCopy;
|
||||||
std::vector<int> pageListCopy;
|
|
||||||
|
|
||||||
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
||||||
if( !Schematic()->Settings().m_IntersheetRefsListOwnPage )
|
if( !Schematic()->Settings().m_IntersheetRefsListOwnPage )
|
||||||
{
|
{
|
||||||
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
|
int currentPage = Schematic()->CurrentSheet().GetVirtualPageNumber();
|
||||||
alg::delete_matching( pageListCopy, currentPage );
|
alg::delete_matching( pageListCopy, currentPage );
|
||||||
|
|
||||||
if( pageListCopy.empty() )
|
if( pageListCopy.empty() )
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort( pageListCopy.begin(), pageListCopy.end(),
|
std::sort( pageListCopy.begin(), pageListCopy.end() );
|
||||||
[]( const wxString& a, const wxString& b ) -> bool
|
|
||||||
{
|
|
||||||
return StrNumCmp( a, b, true ) < 0;
|
|
||||||
} );
|
|
||||||
|
|
||||||
for( const SCH_SHEET_PATH& sheet : Schematic()->GetSheets() )
|
std::map<int, wxString> sheetNames = Schematic()->GetVirtualPageToSheetNamesMap();
|
||||||
{
|
std::map<int, wxString> sheetPages = Schematic()->GetVirtualPageToSheetPagesMap();
|
||||||
if( sheet.size() == 1 )
|
|
||||||
sheetNames[ sheet.GetVirtualPageNumber() ] = _( "<root sheet>" );
|
|
||||||
else
|
|
||||||
sheetNames[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int i = 0; i < (int) pageListCopy.size(); ++i )
|
for( int i = 0; i < (int) pageListCopy.size(); ++i )
|
||||||
{
|
{
|
||||||
menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
|
menu.Append( i + START_ID, wxString::Format( _( "Go to Page %s (%s)" ),
|
||||||
pageListCopy[i],
|
sheetPages[ pageListCopy[i] ],
|
||||||
sheetNames[ pageListCopy[i] ] ) );
|
sheetNames[ pageListCopy[i] ] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.AppendSeparator();
|
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;
|
int sel = aFrame->GetPopupMenuSelectionFromUser( menu ) - START_ID;
|
||||||
void* param = nullptr;
|
void* param = nullptr;
|
||||||
|
|
|
@ -1292,31 +1292,29 @@ bool SCH_GLOBALLABEL::ResolveTextVar( wxString* token, int aDepth ) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::vector<wxString> pageListCopy;
|
std::vector<int> pageListCopy;
|
||||||
|
|
||||||
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
pageListCopy.insert( pageListCopy.end(), it->second.begin(), it->second.end() );
|
||||||
std::sort( pageListCopy.begin(), pageListCopy.end(),
|
std::sort( pageListCopy.begin(), pageListCopy.end() );
|
||||||
[]( const wxString& a, const wxString& b ) -> bool
|
|
||||||
{
|
|
||||||
return StrNumCmp( a, b, true ) < 0;
|
|
||||||
} );
|
|
||||||
|
|
||||||
if( !settings.m_IntersheetRefsListOwnPage )
|
if( !settings.m_IntersheetRefsListOwnPage )
|
||||||
{
|
{
|
||||||
wxString currentPage = Schematic()->CurrentSheet().GetPageNumber();
|
int currentPage = Schematic()->CurrentSheet().GetVirtualPageNumber();
|
||||||
alg::delete_matching( pageListCopy, currentPage );
|
alg::delete_matching( pageListCopy, currentPage );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<int, wxString> sheetPages = Schematic()->GetVirtualPageToSheetPagesMap();
|
||||||
|
|
||||||
if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )
|
if( ( settings.m_IntersheetRefsFormatShort ) && ( pageListCopy.size() > 2 ) )
|
||||||
{
|
{
|
||||||
ref.Append( wxString::Format( wxT( "%s..%s" ),
|
ref.Append( wxString::Format( wxT( "%s..%s" ),
|
||||||
pageListCopy.front(),
|
sheetPages[pageListCopy.front()],
|
||||||
pageListCopy.back() ) );
|
sheetPages[pageListCopy.back()] ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( const wxString& pageNo : pageListCopy )
|
for( const int& pageNo : pageListCopy )
|
||||||
ref.Append( wxString::Format( wxT( "%s," ), pageNo ) );
|
ref.Append( wxString::Format( wxT( "%s," ), sheetPages[pageNo] ) );
|
||||||
|
|
||||||
if( !ref.IsEmpty() && ref.Last() == ',' )
|
if( !ref.IsEmpty() && ref.Last() == ',' )
|
||||||
ref.RemoveLast();
|
ref.RemoveLast();
|
||||||
|
|
|
@ -415,7 +415,7 @@ void SCH_TEXT::DoHypertextMenu( EDA_DRAW_FRAME* aFrame ) const
|
||||||
sheetNames[destPage] ) );
|
sheetNames[destPage] ) );
|
||||||
|
|
||||||
int sel = aFrame->GetPopupMenuSelectionFromUser( menu );
|
int sel = aFrame->GetPopupMenuSelectionFromUser( menu );
|
||||||
void* param = &sheetPages[destPage];
|
void* param = &destPage;
|
||||||
|
|
||||||
if( param )
|
if( param )
|
||||||
aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param );
|
aFrame->GetToolManager()->RunAction( EE_ACTIONS::hypertextCommand, true, param );
|
||||||
|
|
|
@ -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 SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
|
||||||
{
|
{
|
||||||
wxString newbuf;
|
wxString newbuf;
|
||||||
|
|
|
@ -161,6 +161,9 @@ public:
|
||||||
|
|
||||||
std::map<wxString, std::set<int>>& GetPageRefsMap() { return m_labelToPageRefsMap; }
|
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 ConvertRefsToKIIDs( const wxString& aSource ) const;
|
||||||
wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
|
wxString ConvertKIIDsToRefs( const wxString& aSource ) const;
|
||||||
|
|
||||||
|
|
|
@ -55,16 +55,16 @@ void SCH_NAVIGATE_TOOL::CleanHistory()
|
||||||
|
|
||||||
int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent )
|
int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
wxString* page = aEvent.Parameter<wxString*>();
|
int* page = aEvent.Parameter<int*>();
|
||||||
|
|
||||||
wxCHECK( page, 0 );
|
wxCHECK( page, 0 );
|
||||||
|
|
||||||
auto goToPage =
|
auto goToPage =
|
||||||
[&]( wxString* aPage )
|
[&]( int* aPage )
|
||||||
{
|
{
|
||||||
for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
|
for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
|
||||||
{
|
{
|
||||||
if( sheet.GetPageNumber() == *aPage )
|
if( sheet.GetVirtualPageNumber() == *aPage )
|
||||||
{
|
{
|
||||||
changeSheet( sheet );
|
changeSheet( sheet );
|
||||||
return;
|
return;
|
||||||
|
@ -72,7 +72,7 @@ int SCH_NAVIGATE_TOOL::HypertextCommand( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if( *page == "HYPERTEXT_BACK" )
|
if( *page == -1 )
|
||||||
Back( aEvent );
|
Back( aEvent );
|
||||||
else
|
else
|
||||||
goToPage( page );
|
goToPage( page );
|
||||||
|
|
Loading…
Reference in New Issue