From 14f3a22f3d2f3517a9c126d20049d835bcc321cd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Jun 2024 13:42:12 +0100 Subject: [PATCH] ADDED: support editing unit in Reference Field Properties. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17362 --- eeschema/dialogs/dialog_field_properties.cpp | 38 +++++- .../dialogs/dialog_field_properties_base.cpp | 11 +- .../dialogs/dialog_field_properties_base.fbp | 127 ++++++++++++++++++ .../dialogs/dialog_field_properties_base.h | 6 +- eeschema/sch_symbol.cpp | 4 +- eeschema/sch_symbol.h | 4 +- 6 files changed, 180 insertions(+), 10 deletions(-) diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 5afb397253..771e32f801 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -67,9 +67,6 @@ DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const m_note->SetFont( KIUI::GetInfoFont( this ).Italic() ); m_note->Show( false ); - // The field ID is initialized in the derived object's ctor. - m_fieldId = VALUE_FIELD; - m_scintillaTricks = new SCINTILLA_TRICKS( m_StyledTextCtrl, wxT( "{}" ), true, // onAcceptFn [this]( wxKeyEvent& aEvent ) @@ -157,6 +154,8 @@ DIALOG_FIELD_PROPERTIES::DIALOG_FIELD_PROPERTIES( SCH_BASE_FRAME* aParent, const { const LIB_SYMBOL* symbol = static_cast( aField->GetParentSymbol() ); + m_fieldId = aField->GetId(); + /* * Symbol netlist format: * pinNumber pinName pinNumber pinName... @@ -301,6 +300,15 @@ void DIALOG_FIELD_PROPERTIES::init() m_TextCtrl->Show( false ); } + // Show the unit selector for reference fields on multi-unit symbols + bool showUnitSelector = m_fieldId == REFERENCE_FIELD + && m_field->GetParentSymbol() + && m_field->GetParentSymbol()->Type() == SCH_SYMBOL_T + && m_field->GetParentSymbol()->IsMulti(); + + m_unitLabel->Show( showUnitSelector ); + m_unitChoice->Show( showUnitSelector ); + // Show the footprint selection dialog if this is the footprint field. m_TextValueSelectButton->SetBitmap( KiBitmapBundle( BITMAPS::small_library ) ); m_TextValueSelectButton->Show( m_fieldId == FOOTPRINT_FIELD ); @@ -425,6 +433,22 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataToWindow() m_StyledTextCtrl->EmptyUndoBuffer(); } + if( m_unitChoice->IsShown() ) + { + const SCH_SYMBOL* symbol = static_cast( m_field->GetParentSymbol() ); + + for( int ii = 1; ii <= symbol->GetUnitCount(); ii++ ) + { + if( symbol->HasUnitDisplayName( ii ) ) + m_unitChoice->Append( symbol->GetUnitDisplayName( ii ) ); + else + m_unitChoice->Append( symbol->SubReference( ii, false ) ); + } + + if( symbol->GetUnit() <= ( int )m_unitChoice->GetCount() ) + m_unitChoice->SetSelection( symbol->GetUnit() - 1 ); + } + m_fontCtrl->SetFontSelection( m_font ); m_posX.SetValue( m_position.x ); @@ -570,6 +594,14 @@ void DIALOG_FIELD_PROPERTIES::UpdateField( SCH_COMMIT* aCommit, SCH_FIELD* aFiel symbol->SetValueFieldText( m_text ); else if( fieldType == FOOTPRINT_FIELD ) symbol->SetFootprintFieldText( m_text ); + + // Set the unit selection in multiple units per package + if( m_unitChoice->IsShown() ) + { + int unit_selection = m_unitChoice->IsEnabled() ? m_unitChoice->GetSelection() + 1 : 1; + symbol->SetUnitSelection( aSheetPath, unit_selection ); + symbol->SetUnit( unit_selection ); + } } else if( parent && parent->Type() == SCH_GLOBAL_LABEL_T ) { diff --git a/eeschema/dialogs/dialog_field_properties_base.cpp b/eeschema/dialogs/dialog_field_properties_base.cpp index 0ab433902e..1cdebd2834 100644 --- a/eeschema/dialogs/dialog_field_properties_base.cpp +++ b/eeschema/dialogs/dialog_field_properties_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.1.0-0-g733bf3d) +// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -72,6 +72,15 @@ DIALOG_FIELD_PROPERTIES_BASE::DIALOG_FIELD_PROPERTIES_BASE( wxWindow* parent, wx m_TextValueSelectButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW|0 ); bTextValueBoxSizer->Add( m_TextValueSelectButton, 0, wxALIGN_CENTER_VERTICAL, 5 ); + m_unitLabel = new wxStaticText( this, wxID_ANY, _("Unit:"), wxDefaultPosition, wxDefaultSize, 0 ); + m_unitLabel->Wrap( -1 ); + bTextValueBoxSizer->Add( m_unitLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 15 ); + + wxArrayString m_unitChoiceChoices; + m_unitChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_unitChoiceChoices, 0 ); + m_unitChoice->SetSelection( 0 ); + bTextValueBoxSizer->Add( m_unitChoice, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + bUpperBoxSizer->Add( bTextValueBoxSizer, 1, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 ); diff --git a/eeschema/dialogs/dialog_field_properties_base.fbp b/eeschema/dialogs/dialog_field_properties_base.fbp index ac1207cbd0..50c637c785 100644 --- a/eeschema/dialogs/dialog_field_properties_base.fbp +++ b/eeschema/dialogs/dialog_field_properties_base.fbp @@ -363,6 +363,133 @@ OnTextValueSelectButtonClick + + 15 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + Unit: + 0 + + 0 + + + 0 + + 1 + m_unitLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALIGN_CENTER_VERTICAL|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_unitChoice + 1 + + + protected + 1 + + Resizable + 0 + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + diff --git a/eeschema/dialogs/dialog_field_properties_base.h b/eeschema/dialogs/dialog_field_properties_base.h index 36525902cb..e009b31dfc 100644 --- a/eeschema/dialogs/dialog_field_properties_base.h +++ b/eeschema/dialogs/dialog_field_properties_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.1.0-0-g733bf3d) +// C++ code generated with wxFormBuilder (version 4.0.0-0-g0efcecf) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -29,9 +29,9 @@ class STD_BITMAP_BUTTON; #include #include #include +#include #include #include -#include #include #include #include @@ -50,6 +50,8 @@ class DIALOG_FIELD_PROPERTIES_BASE : public DIALOG_SHIM wxTextCtrl* m_TextCtrl; wxStyledTextCtrl* m_StyledTextCtrl; STD_BITMAP_BUTTON* m_TextValueSelectButton; + wxStaticText* m_unitLabel; + wxChoice* m_unitChoice; wxStaticText* m_note; wxCheckBox* m_visible; wxCheckBox* m_nameVisible; diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 139fe3e476..3b5851222b 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -457,7 +457,7 @@ int SCH_SYMBOL::GetUnitCount() const } -wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit ) +wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit ) const { wxCHECK( m_part, ( wxString::Format( _( "Unit %s" ), SubReference( aUnit ) ) ) ); @@ -465,7 +465,7 @@ wxString SCH_SYMBOL::GetUnitDisplayName( int aUnit ) } -bool SCH_SYMBOL::HasUnitDisplayName( int aUnit ) +bool SCH_SYMBOL::HasUnitDisplayName( int aUnit ) const { wxCHECK( m_part, false ); diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index b12eef7b51..2b0fbe1ad9 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -256,14 +256,14 @@ public: * * @return true if the display name of a unit is set, otherwise false. */ - bool HasUnitDisplayName( int aUnit ); + bool HasUnitDisplayName( int aUnit ) const; /** * Return the display name for a given unit \a aUnit. * * @return the display name of a unit if set, or the ordinal name of the unit otherwise. */ - wxString GetUnitDisplayName( int aUnit ); + wxString GetUnitDisplayName( int aUnit ) const; void SetBodyStyle( int aBodyStyle ) override;