ADDED: support editing unit in Reference Field Properties.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17362
This commit is contained in:
Jeff Young 2024-06-02 13:42:12 +01:00
parent 86d7cf5d96
commit 14f3a22f3d
6 changed files with 180 additions and 10 deletions

View File

@ -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<const LIB_SYMBOL*>( aField->GetParentSymbol() );
m_fieldId = aField->GetId();
/*
* Symbol netlist format:
* pinNumber pinName <tab> 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<const SCH_SYMBOL*>( 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 )
{

View File

@ -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 );

View File

@ -363,6 +363,133 @@
<event name="OnButtonClick">OnTextValueSelectButtonClick</event>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">15</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Unit:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_unitLabel</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="true">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxChoice" expanded="true">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="choices"></property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_unitChoice</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="true">

View File

@ -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 <wx/image.h>
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/choice.h>
#include <wx/sizer.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/panel.h>
#include <wx/gbsizer.h>
#include <wx/dialog.h>
@ -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;

View File

@ -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 );

View File

@ -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;