From 7df0879a4475b38fd7f4036cababd60df8352c85 Mon Sep 17 00:00:00 2001 From: FPiorski <2428389-FPiorski@users.noreply.gitlab.com> Date: Wed, 16 Oct 2024 00:20:37 +0200 Subject: [PATCH] ADDED: Clickable links on hierarchical sheets, sheet pins and hierarchical labels in PDF exports of schematics. By default, the new links get generated instead of popup menus for those elements. Can be turned off in the plot dialog or from the cli. Fixes https://gitlab.com/kicad/code/kicad/-/issues/18900 --- common/jobs/job_export_sch_plot.cpp | 3 + common/jobs/job_export_sch_plot.h | 1 + eeschema/dialogs/dialog_plot_schematic.cpp | 27 +- .../dialogs/dialog_plot_schematic_base.cpp | 6 +- .../dialogs/dialog_plot_schematic_base.fbp | 247 +++++++++++------- eeschema/dialogs/dialog_plot_schematic_base.h | 3 +- eeschema/eeschema_jobs_handler.cpp | 1 + eeschema/eeschema_settings.cpp | 3 + eeschema/eeschema_settings.h | 1 + eeschema/sch_label.cpp | 28 +- eeschema/sch_plotter.h | 2 + eeschema/sch_sheet.cpp | 26 +- kicad/cli/command_sch_export_plot.cpp | 8 + 13 files changed, 243 insertions(+), 113 deletions(-) diff --git a/common/jobs/job_export_sch_plot.cpp b/common/jobs/job_export_sch_plot.cpp index 2c3253d82e..063e460954 100644 --- a/common/jobs/job_export_sch_plot.cpp +++ b/common/jobs/job_export_sch_plot.cpp @@ -76,6 +76,7 @@ JOB_EXPORT_SCH_PLOT::JOB_EXPORT_SCH_PLOT( bool aIsCli ) : m_HPGLPenSize( 1.0 ), m_HPGLPaperSizeSelect( JOB_HPGL_PAGE_SIZE::DEFAULT ), m_PDFPropertyPopups( true ), + m_PDFHierarchicalLinks( true ), m_PDFMetadata( true ), m_theme(), m_outputDirectory(), @@ -101,6 +102,8 @@ JOB_EXPORT_SCH_PLOT::JOB_EXPORT_SCH_PLOT( bool aIsCli ) : "hpgl_page_size", &m_HPGLPaperSizeSelect, m_HPGLPaperSizeSelect ) ); m_params.emplace_back( new JOB_PARAM( "pdf_property_popups", &m_PDFPropertyPopups, m_PDFPropertyPopups ) ); + m_params.emplace_back( new JOB_PARAM( "pdf_hierarchical_links", &m_PDFHierarchicalLinks, + m_PDFHierarchicalLinks ) ); m_params.emplace_back( new JOB_PARAM( "pdf_metadata", &m_PDFMetadata, m_PDFMetadata ) ); m_params.emplace_back( new JOB_PARAM( "color_theme", &m_theme, m_theme ) ); m_params.emplace_back( diff --git a/common/jobs/job_export_sch_plot.h b/common/jobs/job_export_sch_plot.h index 67c491c792..9897fd49e5 100644 --- a/common/jobs/job_export_sch_plot.h +++ b/common/jobs/job_export_sch_plot.h @@ -92,6 +92,7 @@ public: double m_HPGLPenSize; // for HPGL format only: pen size JOB_HPGL_PAGE_SIZE m_HPGLPaperSizeSelect; bool m_PDFPropertyPopups; + bool m_PDFHierarchicalLinks; bool m_PDFMetadata; wxString m_theme; diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index edf4d9ec08..3e634c8027 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -131,6 +131,7 @@ void DIALOG_PLOT_SCHEMATIC::initDlg() setOpenFileAfterPlot( cfg->m_PlotPanel.open_file_after_plot ); m_plotPDFPropertyPopups->SetValue( cfg->m_PlotPanel.pdf_property_popups ); + m_plotPDFHierarchicalLinks->SetValue( cfg->m_PlotPanel.pdf_hierarchical_links ); m_plotPDFMetadata->SetValue( cfg->m_PlotPanel.pdf_metadata ); // HPGL plot origin and unit system configuration @@ -177,15 +178,16 @@ void DIALOG_PLOT_SCHEMATIC::initDlg() else if( m_job ) { m_plotFormatOpt->SetSelection( static_cast( m_job->m_plotFormat ) ); - m_plotBackgroundColor->SetValue( m_job->m_useBackgroundColor ); - m_penWidth.SetValue( m_job->m_HPGLPenSize ); + m_plotBackgroundColor->SetValue( m_job->m_useBackgroundColor ); + m_penWidth.SetValue( m_job->m_HPGLPenSize ); m_HPGLPaperSizeSelect = static_cast( m_job->m_HPGLPaperSizeSelect ); - m_plotPDFPropertyPopups->SetValue( m_job->m_PDFPropertyPopups ); - m_plotPDFMetadata->SetValue( m_job->m_PDFMetadata ); - m_colorTheme->Enable( m_job->m_plotFormat != SCH_PLOT_FORMAT::HPGL ); - m_ModeColorOption->Enable( m_job->m_plotFormat != SCH_PLOT_FORMAT::HPGL ); - m_plotOriginOpt->SetSelection( static_cast( m_job->m_HPGLPlotOrigin ) ); - m_pageSizeSelect = static_cast( m_job->m_pageSizeSelect ); + m_plotPDFPropertyPopups->SetValue( m_job->m_PDFPropertyPopups ); + m_plotPDFHierarchicalLinks->SetValue( m_job->m_PDFHierarchicalLinks ); + m_plotPDFMetadata->SetValue( m_job->m_PDFMetadata ); + m_colorTheme->Enable( m_job->m_plotFormat != SCH_PLOT_FORMAT::HPGL ); + m_ModeColorOption->Enable( m_job->m_plotFormat != SCH_PLOT_FORMAT::HPGL ); + m_plotOriginOpt->SetSelection( static_cast( m_job->m_HPGLPlotOrigin ) ); + m_pageSizeSelect = static_cast( m_job->m_pageSizeSelect ); // Set the plot format switch( m_job->m_plotFormat ) @@ -320,6 +322,7 @@ void DIALOG_PLOT_SCHEMATIC::OnUpdateUI( wxUpdateUIEvent& event ) m_openFileAfterPlot->Enable( fmt == PLOT_FORMAT::PDF ); m_plotPDFPropertyPopups->Enable( fmt == PLOT_FORMAT::PDF ); + m_plotPDFHierarchicalLinks->Enable( fmt == PLOT_FORMAT::PDF ); m_plotPDFMetadata->Enable( fmt == PLOT_FORMAT::PDF ); m_paperSizeOption->Set( paperSizes ); @@ -359,9 +362,10 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( RENDER_SETTINGS* aSettings ) cfg->m_PlotPanel.format = static_cast( GetPlotFileFormat() ); cfg->m_PlotPanel.hpgl_origin = m_plotOriginOpt->GetSelection(); cfg->m_PlotPanel.hpgl_paper_size = static_cast( m_HPGLPaperSizeSelect ); - cfg->m_PlotPanel.pdf_property_popups = m_plotPDFPropertyPopups->GetValue(); - cfg->m_PlotPanel.pdf_metadata = m_plotPDFMetadata->GetValue(); - cfg->m_PlotPanel.open_file_after_plot = getOpenFileAfterPlot(); + cfg->m_PlotPanel.pdf_property_popups = m_plotPDFPropertyPopups->GetValue(); + cfg->m_PlotPanel.pdf_hierarchical_links = m_plotPDFHierarchicalLinks->GetValue(); + cfg->m_PlotPanel.pdf_metadata = m_plotPDFMetadata->GetValue(); + cfg->m_PlotPanel.open_file_after_plot = getOpenFileAfterPlot(); // HPGL Pen Size is stored in mm in config cfg->m_PlotPanel.hpgl_pen_size = m_HPGLPenSize / schIUScale.IU_PER_MM; @@ -437,6 +441,7 @@ void DIALOG_PLOT_SCHEMATIC::plotSchematic( bool aPlotAll ) plotOpts.m_useBackgroundColor = m_plotBackgroundColor->GetValue(); plotOpts.m_theme = colors->GetFilename(); plotOpts.m_PDFPropertyPopups = m_plotPDFPropertyPopups->GetValue(); + plotOpts.m_PDFHierarchicalLinks = m_plotPDFHierarchicalLinks->GetValue(); plotOpts.m_PDFMetadata = m_plotPDFMetadata->GetValue(); plotOpts.m_HPGLPaperSizeSelect = static_cast( m_HPGLPaperSizeSelect ); plotOpts.m_HPGLPlotOrigin = diff --git a/eeschema/dialogs/dialog_plot_schematic_base.cpp b/eeschema/dialogs/dialog_plot_schematic_base.cpp index 91e6939623..d7b71af590 100644 --- a/eeschema/dialogs/dialog_plot_schematic_base.cpp +++ b/eeschema/dialogs/dialog_plot_schematic_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -164,6 +164,10 @@ DIALOG_PLOT_SCHEMATIC_BASE::DIALOG_PLOT_SCHEMATIC_BASE( wxWindow* parent, wxWind m_plotPDFPropertyPopups->SetValue(true); sbSizer4->Add( m_plotPDFPropertyPopups, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + m_plotPDFHierarchicalLinks = new wxCheckBox( sbSizer4->GetStaticBox(), wxID_ANY, _("Generate clickable links for hierarchical elements"), wxDefaultPosition, wxDefaultSize, 0 ); + m_plotPDFHierarchicalLinks->SetValue(true); + sbSizer4->Add( m_plotPDFHierarchicalLinks, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + m_plotPDFMetadata = new wxCheckBox( sbSizer4->GetStaticBox(), wxID_ANY, _("Generate metadata from AUTHOR && SUBJECT variables"), wxDefaultPosition, wxDefaultSize, 0 ); m_plotPDFMetadata->SetToolTip( _("Generate PDF document properties from AUTHOR and SUBJECT text variables") ); diff --git a/eeschema/dialogs/dialog_plot_schematic_base.fbp b/eeschema/dialogs/dialog_plot_schematic_base.fbp index d6d8019a97..abcdb2ee62 100644 --- a/eeschema/dialogs/dialog_plot_schematic_base.fbp +++ b/eeschema/dialogs/dialog_plot_schematic_base.fbp @@ -1,34 +1,36 @@ - + - C++ - 1 - source_name - 0 - 0 + + 1 + connect + none + + + 0 + 1 res UTF-8 - connect dialog_plot_schematic_base 1000 - none - - 1 + 1 + UI Dialog_plot_schematic_base - . - + 0 + source_name + 1 + 0 + source_name + + + 1 1 - 1 - 1 - 1 - UI - 0 - 1 0 + 0 0 wxAUI_MGR_DEFAULT @@ -82,10 +84,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -144,10 +146,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -209,10 +211,10 @@ 1 1 1 - + 0 - - + 0 + 0 0 @@ -295,10 +297,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -393,10 +395,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -458,10 +460,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -527,10 +529,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -595,10 +597,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -660,10 +662,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -728,10 +730,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -793,10 +795,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -861,10 +863,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -929,10 +931,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -994,10 +996,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1062,10 +1064,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1167,10 +1169,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1232,10 +1234,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1300,10 +1302,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1365,10 +1367,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1433,10 +1435,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1511,10 +1513,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1567,6 +1569,71 @@ + + 5 + wxBOTTOM|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 1 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Generate clickable links for hierarchical elements + + 0 + + + 0 + + 1 + m_plotPDFHierarchicalLinks + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 wxBOTTOM|wxRIGHT|wxLEFT @@ -1576,10 +1643,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1655,10 +1722,10 @@ 1 1 1 - + 0 - - + 0 + 0 @@ -1735,10 +1802,10 @@ 1 1 1 - + 0 - - + 0 + 0 diff --git a/eeschema/dialogs/dialog_plot_schematic_base.h b/eeschema/dialogs/dialog_plot_schematic_base.h index 95b6c12dec..b0f4dd2e43 100644 --- a/eeschema/dialogs/dialog_plot_schematic_base.h +++ b/eeschema/dialogs/dialog_plot_schematic_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -67,6 +67,7 @@ class DIALOG_PLOT_SCHEMATIC_BASE : public DIALOG_SHIM wxTextCtrl* m_penWidthCtrl; wxStaticText* m_penWidthUnits; wxCheckBox* m_plotPDFPropertyPopups; + wxCheckBox* m_plotPDFHierarchicalLinks; wxCheckBox* m_plotPDFMetadata; wxStaticBoxSizer* m_otherOptions; wxCheckBox* m_openFileAfterPlot; diff --git a/eeschema/eeschema_jobs_handler.cpp b/eeschema/eeschema_jobs_handler.cpp index fdef58e01e..da9114e0f8 100644 --- a/eeschema/eeschema_jobs_handler.cpp +++ b/eeschema/eeschema_jobs_handler.cpp @@ -318,6 +318,7 @@ int EESCHEMA_JOBS_HANDLER::JobExportPlot( JOB* aJob ) plotOpts.m_HPGLPenSize = aPlotJob->m_HPGLPenSize; plotOpts.m_HPGLPlotOrigin = hpglOrigin; plotOpts.m_PDFPropertyPopups = aPlotJob->m_PDFPropertyPopups; + plotOpts.m_PDFHierarchicalLinks = aPlotJob->m_PDFHierarchicalLinks; plotOpts.m_PDFMetadata = aPlotJob->m_PDFMetadata; plotOpts.m_outputDirectory = aPlotJob->m_outputDirectory; plotOpts.m_outputFile = aPlotJob->m_outputFile; diff --git a/eeschema/eeschema_settings.cpp b/eeschema/eeschema_settings.cpp index 4b54296cad..34eb12339a 100644 --- a/eeschema/eeschema_settings.cpp +++ b/eeschema/eeschema_settings.cpp @@ -546,6 +546,9 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : m_params.emplace_back( new PARAM( "plot.pdf_property_popups", &m_PlotPanel.pdf_property_popups, true ) ); + m_params.emplace_back( new PARAM( "plot.pdf_hierarchical_links", + &m_PlotPanel.pdf_hierarchical_links, true ) ); + m_params.emplace_back( new PARAM( "plot.pdf_metadata", &m_PlotPanel.pdf_metadata, true ) ); diff --git a/eeschema/eeschema_settings.h b/eeschema/eeschema_settings.h index 238e642f09..cb5de5db52 100644 --- a/eeschema/eeschema_settings.h +++ b/eeschema/eeschema_settings.h @@ -260,6 +260,7 @@ public: double hpgl_pen_size; int hpgl_origin; bool pdf_property_popups; + bool pdf_hierarchical_links; bool pdf_metadata; bool open_file_after_plot; }; diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 181af8e457..2c1505231d 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -1344,8 +1344,34 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_O aPlotter->PlotPoly( s_poly, FILL_T::NO_FILL, penWidth ); } + // Make sheet pins and hierarchical labels clickable hyperlinks + bool linkAlreadyPlotted = false; + if( aPlotOpts.m_PDFHierarchicalLinks ) + { + if( Type() == SCH_HIER_LABEL_T ) + { + if( sheet->size() >= 2 ) + { + SCH_SHEET_PATH path = *sheet; + path.pop_back(); + aPlotter->HyperlinkBox( GetBodyBoundingBox(), + EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); + linkAlreadyPlotted = true; + } + } + else if( Type() == SCH_SHEET_PIN_T ) + { + SCH_SHEET_PATH path = *sheet; + SCH_SHEET* parent = static_cast( m_parent ); + path.push_back( parent ); + aPlotter->HyperlinkBox( GetBodyBoundingBox(), + EDA_TEXT::GotoPageHref( path.GetPageNumber() ) ); + linkAlreadyPlotted = true; + } + } + // Plot attributes to a hypertext menu - if( aPlotOpts.m_PDFPropertyPopups ) + if( aPlotOpts.m_PDFPropertyPopups && !linkAlreadyPlotted ) { std::vector properties; diff --git a/eeschema/sch_plotter.h b/eeschema/sch_plotter.h index 68e25edae4..1c53ac5aea 100644 --- a/eeschema/sch_plotter.h +++ b/eeschema/sch_plotter.h @@ -89,6 +89,7 @@ struct SCH_PLOT_OPTS double m_HPGLPenSize; // for HPGL format only: pen size HPGL_PAGE_SIZE m_HPGLPaperSizeSelect; bool m_PDFPropertyPopups; + bool m_PDFHierarchicalLinks; bool m_PDFMetadata; wxString m_theme; @@ -106,6 +107,7 @@ struct SCH_PLOT_OPTS m_HPGLPenSize( 1.0 ), m_HPGLPaperSizeSelect( HPGL_PAGE_SIZE::DEFAULT ), m_PDFPropertyPopups( false ), + m_PDFHierarchicalLinks( false ), m_PDFMetadata( false ), m_theme(), m_outputDirectory(), diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 904f068b91..424a004697 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include // for KiROUND @@ -1247,18 +1248,25 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter, bool aBackground, const SCH_PLOT_OPTS& } // Make the sheet object a clickable hyperlink (e.g. for PDF plotter) - std::vector properties; - - properties.emplace_back( EDA_TEXT::GotoPageHref( findSelf().GetPageNumber() ) ); - - for( const SCH_FIELD& field : GetFields() ) + if( aPlotOpts.m_PDFHierarchicalLinks ) { - properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), - field.GetName(), - field.GetShownText( false ) ) ); + aPlotter->HyperlinkBox( GetBoundingBox(), + EDA_TEXT::GotoPageHref( findSelf().GetPageNumber() ) ); } + else if( aPlotOpts.m_PDFPropertyPopups ) + { + std::vector properties; - aPlotter->HyperlinkMenu( GetBoundingBox(), properties ); + properties.emplace_back( EDA_TEXT::GotoPageHref( findSelf().GetPageNumber() ) ); + + for( const SCH_FIELD& field : GetFields() ) + { + properties.emplace_back( wxString::Format( wxT( "!%s = %s" ), field.GetName(), + field.GetShownText( false ) ) ); + } + + aPlotter->HyperlinkMenu( GetBoundingBox(), properties ); + } // Plot sheet pins for( SCH_SHEET_PIN* sheetPin : m_pins ) diff --git a/kicad/cli/command_sch_export_plot.cpp b/kicad/cli/command_sch_export_plot.cpp index 9772915354..6a3367918e 100644 --- a/kicad/cli/command_sch_export_plot.cpp +++ b/kicad/cli/command_sch_export_plot.cpp @@ -36,6 +36,7 @@ #define ARG_HPGL_ORIGIN "--origin" #define ARG_PAGES "--pages" #define ARG_EXCLUDE_PDF_PROPERTY_POPUPS "--exclude-pdf-property-popups" +#define ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS "--exclude-pdf-hierarchical-links" #define ARG_EXCLUDE_PDF_METADATA "--exclude-pdf-metadata" const JOB_HPGL_PLOT_ORIGIN_AND_UNITS hpgl_origin_ops[4] = { @@ -81,6 +82,11 @@ CLI::SCH_EXPORT_PLOT_COMMAND::SCH_EXPORT_PLOT_COMMAND( const std::string& aName, .help( UTF8STDSTR( _( "Do not generate property popups in PDF" ) ) ) .flag(); + m_argParser.add_argument( ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS ) + .help( UTF8STDSTR( _( "Do not generate clickable links for hierarchical elements " + "in PDF" ) ) ) + .flag(); + m_argParser.add_argument( ARG_EXCLUDE_PDF_METADATA ) .help( UTF8STDSTR( _( "Do not generate PDF metadata from AUTHOR and SUBJECT variables" ) ) ) .flag(); @@ -184,6 +190,8 @@ int CLI::SCH_EXPORT_PLOT_COMMAND::doPerform( KIWAY& aKiway ) else if( m_plotFormat == SCH_PLOT_FORMAT::PDF ) { plotJob->m_PDFPropertyPopups = !m_argParser.get( ARG_EXCLUDE_PDF_PROPERTY_POPUPS ); + plotJob->m_PDFHierarchicalLinks = + !m_argParser.get( ARG_EXCLUDE_PDF_HIERARCHICAL_LINKS ); plotJob->m_PDFMetadata = !m_argParser.get( ARG_EXCLUDE_PDF_METADATA ); }