From a78cefc7d4323861aba5dbd7024a8da5d3891daf Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sun, 3 Jul 2022 16:21:30 +0100 Subject: [PATCH] ADDED: Plotting of sheet objects with go to page hyperlinks (pdf for now) --- eeschema/sch_sheet.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ eeschema/sch_sheet.h | 8 +++++++ 2 files changed, 59 insertions(+) diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index c44d40ce57..5bab628eee 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -908,6 +908,48 @@ void SCH_SHEET::renumberPins() } +int SCH_SHEET::guessPageFromParentScreen() const +{ + SCH_SCREEN* parentScreen = static_cast( m_parent ); + int vPageNumParent = parentScreen->GetVirtualPageNumber(); + SCH_SHEET_LIST sheets = parentScreen->Schematic()->GetSheets(); + + wxCHECK( sheets.size() >= vPageNumParent && vPageNumParent > 0, m_screen->GetVirtualPageNumber() ); + + // We can use the virtual page number as an index to find the instance + SCH_SHEET_PATH parentSheetPath = sheets.at( vPageNumParent - 1 ); + + // Make sure our asumption about the virtual page number being the index-1 is correct + wxCHECK( parentSheetPath.LastScreen()->GetFileName() == parentScreen->GetFileName(), + m_screen->GetVirtualPageNumber() ); + + KIID_PATH parentSheetKIIDPath = parentSheetPath.PathWithoutRootUuid(); + + for( const SCH_SHEET_INSTANCE& instance : m_instances ) + { + KIID_PATH instancePath = instance.m_Path; + + if( instancePath.MakeRelativeTo( parentSheetKIIDPath ) && instancePath.size() == 1 ) + { + // find the virtual page number of this path + auto isThePath = [&]( const SCH_SHEET_PATH& aPath ) -> bool + { + return aPath.PathWithoutRootUuid() == instance.m_Path; + }; + + auto result = std::find_if( sheets.begin(), sheets.end(), isThePath ); + + wxCHECK( result != sheets.end(), m_screen->GetVirtualPageNumber() ); + + return result - sheets.begin() + 1; + } + } + + wxFAIL_MSG( "Couldn't find a valid path?" ); + return m_screen->GetVirtualPageNumber(); +} + + void SCH_SHEET::GetEndPoints( std::vector & aItemList ) { for( SCH_SHEET_PIN* sheetPin : m_pins ) @@ -1056,6 +1098,15 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter, bool aBackground ) const aPlotter->Rect( m_pos, m_pos + m_size, FILL_T::NO_FILL, penWidth ); } + // Make the sheet object a clickable hyperlink (e.g. for PDF plotter) + if( !aBackground ) + { + BOX2I rect( m_pos, m_size ); + int virtualPage = guessPageFromParentScreen(); + wxString hyperlinkDestination = EDA_TEXT::GotoPageHyperlinkString( virtualPage ); + aPlotter->HyperlinkBox( rect, hyperlinkDestination ); + } + // Plot sheet pins for( SCH_SHEET_PIN* sheetPin : m_pins ) sheetPin->Plot( aPlotter, aBackground ); diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 37ac02948f..1f61ecea3b 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -450,6 +450,14 @@ protected: */ void renumberPins(); + /** + * Guess the virtual page number of this sheet based on the virtual page number currently set + * on the parent screen. (Useful helper function for plotting) + * + * @return the instance corresponding to this sheet + */ + int guessPageFromParentScreen() const; + private: bool doIsConnected( const VECTOR2I& aPosition ) const override;