From b80824951eab5d69a0da35d9b3e1aa2a7d821f71 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 6 Sep 2022 11:18:09 +0100 Subject: [PATCH] Clean up some of the PDF hypertext stuff, and add opening HTTP[S] urls. Fixes https://gitlab.com/kicad/code/kicad/issues/12153 --- common/plotters/PDF_plotter.cpp | 68 +++++++++++++++++++++------------ eeschema/sch_field.cpp | 5 ++- eeschema/sch_label.cpp | 18 ++++++++- eeschema/sch_line.cpp | 2 +- 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/common/plotters/PDF_plotter.cpp b/common/plotters/PDF_plotter.cpp index bfd27bf3b1..fc77e1480c 100644 --- a/common/plotters/PDF_plotter.cpp +++ b/common/plotters/PDF_plotter.cpp @@ -955,52 +955,70 @@ bool PDF_PLOTTER::EndPlot() { const BOX2D& box = menuPair.first; const std::vector& urls = menuPair.second; - - // We currently only support menu links for internal pages and property lists. - // This vector holds the menu titles and (optional) page numbers. - std::vector> menuItems; + wxString js = wxT( "var aParams = [ " ); for( const wxString& url : urls ) { - wxString pageNumber; - if( url.StartsWith( "!" ) ) { - menuItems.push_back( { url.AfterFirst( '!' ), -1 } ); + wxString property = url.AfterFirst( '!' ); + + if( property.Find( "http:" ) >= 0 ) + { + wxString href = property.substr( property.Find( "http:" ) ); + + js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ), + EscapeString( property, CTX_JS_STR ), + EscapeString( href, CTX_JS_STR ) ); + } + else if( property.Find( "https:" ) >= 0 ) + { + wxString href = property.substr( property.Find( "https:" ) ); + + js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ), + EscapeString( property, CTX_JS_STR ), + EscapeString( href, CTX_JS_STR ) ); + } + else + { + js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ), + EscapeString( property, CTX_JS_STR ) ); + } } - else if( EDA_TEXT::IsGotoPageHref( url, &pageNumber ) ) + else if( url.StartsWith( "#" ) ) { + wxString pageNumber = url.AfterFirst( '#' ); + for( size_t ii = 0; ii < m_pageNumbers.size(); ++ii ) { if( m_pageNumbers[ii] == pageNumber ) - menuItems.push_back( { pageNumber, ii } ); + { + wxString menuText = wxString::Format( _( "Show Page %s" ), pageNumber ); + + js += wxString::Format( wxT( "{ cName: '%s', cReturn: '#%d' }, " ), + EscapeString( menuText, CTX_JS_STR ), + static_cast( ii ) ); + break; + } } } - } - - wxString js = wxT( "var aParams = [ " ); - - for( const std::pair& menuItem : menuItems ) - { - if( menuItem.second < 0 ) + else if( url.StartsWith( "http:" ) || url.StartsWith( "https:" ) ) { - js += wxString::Format( wxT( "{ cName: '%s', cReturn: null }, " ), - EscapeString( menuItem.first, CTX_JS_STR ) ); - } - else - { - wxString menuText = wxString::Format( _( "Show Page %s" ), menuItem.first ); + wxString menuText = wxString::Format( _( "Open %s" ), url ); - js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%d' }, " ), + js += wxString::Format( wxT( "{ cName: '%s', cReturn: '%s' }, " ), EscapeString( menuText, CTX_JS_STR ), - menuItem.second ); + EscapeString( url, CTX_JS_STR ) ); } } js += wxT( "]; " ); js += wxT( "var cChoice = app.popUpMenuEx.apply\\( app, aParams \\); " ); - js += wxT( "if\\( cChoice != null \\) this.pageNum = cChoice; " ); + js += wxT( "if\\( cChoice != null && cChoice.startsWith\\( '#' \\) \\)" + " this.pageNum = cChoice.slice\\( 1 \\); " ); + js += wxT( "else if\\( cChoice != null && cChoice.startsWith\\( 'http' \\) \\)" + " app.launchURL\\( cChoice \\);" ); startPdfObject( menuHandle ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index f2a987704d..da7e6556e6 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -983,13 +983,16 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const SCH_LABEL_BASE* label = static_cast( m_parent ); std::vector> pages; std::vector pageHrefs; + BOX2I bbox = GetBoundingBox(); label->GetIntersheetRefs( &pages ); for( const std::pair& page : pages ) pageHrefs.push_back( wxT( "#" ) + page.first ); - aPlotter->HyperlinkMenu( GetBoundingBox(), pageHrefs ); + bbox.Offset( label->GetSchematicTextOffset( settings ) ); + + aPlotter->HyperlinkMenu( bbox, pageHrefs ); } } diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 17f52da36d..e51866cdd8 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -882,6 +882,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const static std::vector s_poly; RENDER_SETTINGS* settings = aPlotter->RenderSettings(); + SCHEMATIC* schematic = Schematic(); SCH_CONNECTION* connection = Connection(); int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; COLOR4D color = settings->GetLayerColor( layer ); @@ -917,6 +918,21 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const { std::vector properties; + if( schematic && connection ) + { + auto& netSettings = schematic->Prj().GetProjectFile().m_NetSettings; + wxString netName = connection->Name(); + wxString className = netSettings->GetEffectiveNetClass( netName )->GetName(); + + properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), + _( "Net" ), + UnescapeString( netName ) ) ); + + properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), + _( "Resolved netclass" ), + UnescapeString( className ) ) ); + } + for( const SCH_FIELD& field : GetFields() ) { properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), @@ -924,7 +940,7 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const field.GetShownText() ) ); } - aPlotter->HyperlinkMenu( GetBoundingBox(), properties ); + aPlotter->HyperlinkMenu( GetBodyBoundingBox(), properties ); } } diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp index f55060d58c..bb8623f639 100644 --- a/eeschema/sch_line.cpp +++ b/eeschema/sch_line.cpp @@ -858,7 +858,7 @@ void SCH_LINE::Plot( PLOTTER* aPlotter, bool aBackground ) const UnescapeString( netName ) ) ); properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), - _( "Net class" ), + _( "Resolved netclass" ), UnescapeString( className ) ) ); } }