From e893ed45905afed3fab50f428da1491405154edd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 9 Mar 2024 11:58:23 +0000 Subject: [PATCH] Pass symbol's netlist to footprint preview widget. This allows us to show the pin functions on the corresponding pads. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17349 (cherry picked from commit 72ba31ba27175d42b66c9ce849472e26bbb8408e) --- common/widgets/footprint_preview_widget.cpp | 6 +++ common/widgets/grid_text_button_helpers.cpp | 4 +- cvpcb/display_footprints_frame.cpp | 17 +------ eeschema/dialogs/dialog_field_properties.cpp | 47 ++++++++++++++----- eeschema/dialogs/dialog_field_properties.h | 2 +- eeschema/fields_grid_table.cpp | 34 +++++++++++--- include/widgets/footprint_preview_widget.h | 31 ++++++++---- pcbnew/dialogs/dialog_exchange_footprints.cpp | 15 ++++-- pcbnew/footprint.cpp | 10 +++- pcbnew/footprint.h | 6 +++ pcbnew/footprint_chooser_frame.cpp | 17 ++++--- pcbnew/footprint_preview_panel.cpp | 4 ++ pcbnew/footprint_preview_panel.h | 6 +++ pcbnew/pcb_painter.cpp | 4 +- 14 files changed, 143 insertions(+), 60 deletions(-) diff --git a/common/widgets/footprint_preview_widget.cpp b/common/widgets/footprint_preview_widget.cpp index 342c0a3b0f..2b0f882501 100644 --- a/common/widgets/footprint_preview_widget.cpp +++ b/common/widgets/footprint_preview_widget.cpp @@ -92,6 +92,12 @@ void FOOTPRINT_PREVIEW_WIDGET::SetUserUnits( EDA_UNITS aUnits ) } +void FOOTPRINT_PREVIEW_WIDGET::SetPinFunctions( const std::map& aPinFunctions ) +{ + m_prev_panel->SetPinFunctions( aPinFunctions ); +} + + void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID ) { if( !m_prev_panel || m_libid == aFPID ) diff --git a/common/widgets/grid_text_button_helpers.cpp b/common/widgets/grid_text_button_helpers.cpp index 92760ae70a..9a2060dbe0 100644 --- a/common/widgets/grid_text_button_helpers.cpp +++ b/common/widgets/grid_text_button_helpers.cpp @@ -287,8 +287,8 @@ protected: /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ std::string m_symbolNetlist; }; diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 5c4cf51da3..4784fef8d2 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -465,21 +465,14 @@ void DISPLAY_FOOTPRINTS_FRAME::ReloadFootprint( FOOTPRINT* aFootprint ) return; GetBoard()->DeleteAllFootprints(); - GetBoard()->RemoveUnusedNets( nullptr ); GetCanvas()->GetView()->Clear(); - for( PAD* pad : aFootprint->Pads() ) { const COMPONENT_NET& net = m_currentComp->GetNet( pad->GetNumber() ); if( !net.GetPinFunction().IsEmpty() ) - { - NETINFO_ITEM* netinfo = new NETINFO_ITEM( GetBoard() ); - netinfo->SetNetname( net.GetPinFunction() ); - GetBoard()->Add( netinfo ); - pad->SetNet( netinfo ); - } + pad->SetPinFunction( net.GetPinFunction() ); } GetBoard()->Add( aFootprint ); @@ -504,7 +497,6 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() return; GetBoard()->DeleteAllFootprints(); - GetBoard()->RemoveUnusedNets( nullptr ); GetCanvas()->GetView()->Clear(); INFOBAR_REPORTER infoReporter( m_infoBar ); @@ -528,12 +520,7 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay() const COMPONENT_NET& net = comp->GetNet( pad->GetNumber() ); if( !net.GetPinFunction().IsEmpty() ) - { - NETINFO_ITEM* netinfo = new NETINFO_ITEM( GetBoard() ); - netinfo->SetNetname( net.GetPinFunction() ); - GetBoard()->Add( netinfo ); - pad->SetNet( netinfo ); - } + pad->SetPinFunction( net.GetPinFunction() ); } } diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 72876ff33a..cc280da838 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -429,17 +429,28 @@ DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen if( m_fieldId == FOOTPRINT_FIELD ) { - LIB_SYMBOL* symbol = aField->GetParent(); - wxString netlist; - /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ - netlist << wxString::Format( wxS( "%d\r" ), symbol->GetPinCount() ); + wxString netlist; - wxArrayString fpFilters = symbol->GetFPFilters(); + std::vector pinList; + + aField->GetParent()->GetPins( pinList, 0, 1 ); // All units, but a single convert + + wxArrayString pins; + + for( LIB_PIN* pin : pinList ) + pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); + + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + + netlist << wxS( "\r" ); + + wxArrayString fpFilters = aField->GetParent()->GetFPFilters(); if( !fpFilters.IsEmpty() ) netlist << EscapeString( wxJoin( fpFilters, ' ' ), CTX_LINE ); @@ -473,7 +484,7 @@ void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField ) } -DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, +DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_EDIT_FRAME* aParent, const wxString& aTitle, const SCH_FIELD* aField ) : DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ), @@ -483,17 +494,27 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen if( aField->GetParent() && aField->GetParent()->Type() == SCH_SYMBOL_T ) { - SCH_SYMBOL* symbol = static_cast( aField->GetParent() ); - wxString netlist; + SCH_SYMBOL* symbol = static_cast( aField->GetParent() ); + SCH_SHEET_PATH sheetPath = aParent->GetCurrentSheet(); m_fieldId = aField->GetId(); /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ - netlist << wxString::Format( wxS( "%zu\r" ), symbol->GetFullPinCount() ); + wxString netlist; + + wxArrayString pins; + + for( SCH_PIN* pin : symbol->GetPins( &sheetPath ) ) + pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); + + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + + netlist << wxS( "\r" ); wxArrayString fpFilters = symbol->GetLibSymbolRef()->GetFPFilters(); diff --git a/eeschema/dialogs/dialog_field_properties.h b/eeschema/dialogs/dialog_field_properties.h index 8e0dd13b28..098d721351 100644 --- a/eeschema/dialogs/dialog_field_properties.h +++ b/eeschema/dialogs/dialog_field_properties.h @@ -136,7 +136,7 @@ public: class DIALOG_SCH_FIELD_PROPERTIES : public DIALOG_FIELD_PROPERTIES { public: - DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const wxString& aTitle, + DIALOG_SCH_FIELD_PROPERTIES( SCH_EDIT_FRAME* aParent, const wxString& aTitle, const SCH_FIELD* aField ); ~DIALOG_SCH_FIELD_PROPERTIES() {} diff --git a/eeschema/fields_grid_table.cpp b/eeschema/fields_grid_table.cpp index d0b22b5855..845c576c5f 100644 --- a/eeschema/fields_grid_table.cpp +++ b/eeschema/fields_grid_table.cpp @@ -62,16 +62,24 @@ enum static wxString netList( SCH_SYMBOL* aSymbol, SCH_SHEET_PATH& aSheetPath ) { + wxCHECK( aSymbol && aSymbol->GetLibSymbolRef(), wxEmptyString ); + /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ wxString netlist; - netlist << wxString::Format( wxS( "%zu\r" ), aSymbol->GetFullPinCount() ); + wxArrayString pins; - wxCHECK( aSymbol && aSymbol->GetLibSymbolRef(), wxEmptyString ); + for( SCH_PIN* pin : aSymbol->GetPins( &aSheetPath ) ) + pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); + + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + + netlist << wxS( "\r" ); wxArrayString fpFilters = aSymbol->GetLibSymbolRef()->GetFPFilters(); @@ -88,12 +96,24 @@ static wxString netList( LIB_SYMBOL* aSymbol ) { /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ wxString netlist; - netlist << wxString::Format( wxS( "%d\r" ), aSymbol->GetPinCount() ); + std::vector pinList; + + aSymbol->GetPins( pinList, 0, 1 ); // All units, but a single convert + + wxArrayString pins; + + for( LIB_PIN* pin : pinList ) + pins.push_back( pin->GetNumber() + ' ' + pin->GetShownName() ); + + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + + netlist << wxS( "\r" ); wxArrayString fpFilters = aSymbol->GetFPFilters(); diff --git a/include/widgets/footprint_preview_widget.h b/include/widgets/footprint_preview_widget.h index b576813eee..3a3e51a25c 100644 --- a/include/widgets/footprint_preview_widget.h +++ b/include/widgets/footprint_preview_widget.h @@ -48,9 +48,8 @@ public: FOOTPRINT_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ); /** - * Return whether the widget initialized properly. This could return false - * if Kiway is not available. If this returns false, no other methods should - * be called. + * Return whether the widget initialized properly. This could return false if Kiway is + * not available. If this returns false, no other methods should be called. */ bool IsInitialized() const { return m_prev_panel != nullptr; } @@ -70,8 +69,15 @@ public: void SetUserUnits( EDA_UNITS aUnits ); /** - * Set the currently displayed footprint. Any footprint passed in here - * must have been passed to CacheFootprint before. + * Set the pin functions from the symbol's netlist. This allows us to display them in + * the corresponding pads. + * @param aPinFunctions a map from pin_number to pin_function + */ + void SetPinFunctions( const std::map& aPinFunctions ); + + /** + * Set the currently displayed footprint. Any footprint passed in here *MUST* have been + * passed to CacheFootprint before. */ void DisplayFootprint( const LIB_ID& aFPID ); @@ -111,8 +117,15 @@ public: virtual void SetUserUnits( EDA_UNITS aUnits ) = 0; /** - * Set the currently displayed footprint. Any footprint passed in here - * must have been passed to CacheFootprint before. + * Set the pin functions from the symbol's netlist. This allows us to display them in + * the corresponding pads. + * @param aPinFunctions a map from pin_number to pin_function + */ + virtual void SetPinFunctions( const std::map& aPinFunctions ) = 0; + + /** + * Set the currently displayed footprint. Any footprint passed in here *MUST* have been + * passed to CacheFootprint before. */ virtual bool DisplayFootprint( LIB_ID const& aFPID ) = 0; @@ -139,8 +152,8 @@ public: virtual const KIGFX::COLOR4D& GetForegroundColor() const = 0; /** - * Return a footprint preview panel instance via Kiface. May return null - * if Kiway is not available or there is any error on load. + * Return a footprint preview panel instance via Kiface. May return null if Kiway is not + * available or there is any error on load. */ static FOOTPRINT_PREVIEW_PANEL_BASE* Create( wxWindow* aParent, KIWAY& aKiway ); }; diff --git a/pcbnew/dialogs/dialog_exchange_footprints.cpp b/pcbnew/dialogs/dialog_exchange_footprints.cpp index 7267bd859b..02900aa429 100644 --- a/pcbnew/dialogs/dialog_exchange_footprints.cpp +++ b/pcbnew/dialogs/dialog_exchange_footprints.cpp @@ -408,12 +408,21 @@ void DIALOG_EXCHANGE_FOOTPRINTS::ViewAndSelectFootprint( wxCommandEvent& event ) { /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ wxString netlist; - netlist << wxString::Format( wxS( "%u\r" ), m_currentFootprint->GetUniquePadCount() ); + wxArrayString pins; + + for( const wxString& pad : m_currentFootprint->GetUniquePadNumbers() ) + pins.push_back( pad + ' ' + wxEmptyString /* leave pinName empty */ ); + + if( !pins.IsEmpty() ) + netlist << EscapeString( wxJoin( pins, '\t' ), CTX_LINE ); + + netlist << wxS( "\r" ); + netlist << EscapeString( m_currentFootprint->GetFilters(), CTX_LINE ) << wxS( "\r" ); std::string payload( netlist.ToStdString() ); diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index cdb280d1a9..c11872e103 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -1591,7 +1591,7 @@ unsigned FOOTPRINT::GetPadCount( INCLUDE_NPTH_T aIncludeNPTH ) const } -unsigned FOOTPRINT::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const +std::set FOOTPRINT::GetUniquePadNumbers( INCLUDE_NPTH_T aIncludeNPTH ) const { std::set usedNumbers; @@ -1618,7 +1618,13 @@ unsigned FOOTPRINT::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const usedNumbers.insert( pad->GetNumber() ); } - return usedNumbers.size(); + return usedNumbers; +} + + +unsigned FOOTPRINT::GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH ) const +{ + return GetUniquePadNumbers( aIncludeNPTH ).size(); } diff --git a/pcbnew/footprint.h b/pcbnew/footprint.h index 6bbaeb8547..51ee679b58 100644 --- a/pcbnew/footprint.h +++ b/pcbnew/footprint.h @@ -778,6 +778,12 @@ public: */ unsigned GetUniquePadCount( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const; + /** + * Return the names of the unique, non-blank pads. + */ + std::set + GetUniquePadNumbers( INCLUDE_NPTH_T aIncludeNPTH = INCLUDE_NPTH_T(INCLUDE_NPTH) ) const; + /** * Return the next available pad number in the footprint. * diff --git a/pcbnew/footprint_chooser_frame.cpp b/pcbnew/footprint_chooser_frame.cpp index 1b927ce7d4..e41c71ef90 100644 --- a/pcbnew/footprint_chooser_frame.cpp +++ b/pcbnew/footprint_chooser_frame.cpp @@ -229,6 +229,7 @@ FOOTPRINT_CHOOSER_FRAME::~FOOTPRINT_CHOOSER_FRAME() } } + bool FOOTPRINT_CHOOSER_FRAME::filterFootprint( LIB_TREE_NODE& aNode ) { if( aNode.m_Type == LIB_TREE_NODE::TYPE::LIBRARY ) @@ -322,15 +323,18 @@ void FOOTPRINT_CHOOSER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) /* * Symbol netlist format: - * pinCount - * fpFilters + * pinNumber pinName pinNumber pinName... + * fpFilter fpFilter... */ - std::vector strings = split( payload, "\r" ); + std::map pinNames; + std::vector strings = split( payload, "\r" ); - if( strings.size() >= 1 ) + if( strings.size() >= 1 && !strings[0].empty() ) { - wxString pinCountStr( strings[0] ); - pinCountStr.ToInt( &m_pinCount ); + for( const wxString& pin : wxSplit( strings[0], '\t' ) ) + pinNames[ pin.BeforeFirst( ' ' ) ] = pin.AfterFirst( ' ' ); + + m_pinCount = pinNames.size(); if( m_pinCount > 0 ) { @@ -353,6 +357,7 @@ void FOOTPRINT_CHOOSER_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail ) m_filterByFPFilters->Show( true ); } + m_chooserPanel->GetViewerPanel()->SetPinFunctions( pinNames ); break; } diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 2ca88732d9..190a7a28fd 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -126,6 +127,9 @@ void FOOTPRINT_PREVIEW_PANEL::renderFootprint( std::shared_ptr aFootp PCB_DIM_CENTER_T, PCB_DIM_RADIAL_T } ); + for( PAD* pad : aFootprint->Pads() ) + pad->SetPinFunction( m_pinFunctions[ pad->GetNumber() ] ); + // Ensure we are not using the high contrast mode to display the selected footprint KIGFX::PAINTER* painter = GetView()->GetPainter(); auto settings = static_cast( painter->GetSettings() ); diff --git a/pcbnew/footprint_preview_panel.h b/pcbnew/footprint_preview_panel.h index e6c5a8e2a2..b1d0ce6953 100644 --- a/pcbnew/footprint_preview_panel.h +++ b/pcbnew/footprint_preview_panel.h @@ -55,6 +55,11 @@ public: virtual ~FOOTPRINT_PREVIEW_PANEL( ); virtual void SetUserUnits( EDA_UNITS aUnits ) override { m_userUnits = aUnits; } + virtual void SetPinFunctions( const std::map& aPinFunctions ) override + { + m_pinFunctions = aPinFunctions; + } + virtual bool DisplayFootprint( const LIB_ID& aFPID ) override; virtual void DisplayFootprints( std::shared_ptr aFootprintA, std::shared_ptr aFootprintB ) override; @@ -91,6 +96,7 @@ private: std::unique_ptr m_dummyBoard; std::unique_ptr m_displayOptions; EDA_UNITS m_userUnits; + std::map m_pinFunctions; std::shared_ptr m_currentFootprint; std::shared_ptr m_otherFootprint; }; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 3714f92594..4495db6663 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1142,10 +1142,10 @@ void PCB_PAINTER::draw( const PAD* aPad, int aLayer ) padNumber = UnescapeString( aPad->GetNumber() ); if( dynamic_cast( viewer_settings() ) ) - netname = aPad->GetUnescapedShortNetname(); + netname = aPad->GetPinFunction(); } - if( displayOpts ) + if( displayOpts && !dynamic_cast( viewer_settings() ) ) { if( displayOpts->m_NetNames == 1 || displayOpts->m_NetNames == 3 ) netname = aPad->GetUnescapedShortNetname();