From 5b1fdbe645b9fae8b262c8a2d9670e677d8440b5 Mon Sep 17 00:00:00 2001 From: John Beard Date: Wed, 15 Jan 2025 02:21:42 +0800 Subject: [PATCH] Symbol editor: use a default name when deriving a symbol A blank field is always an error, and it's quite likely the name will be somewhat similar to the parent symbol. --- eeschema/dialogs/dialog_lib_new_symbol.cpp | 28 +++++++++++++++++++++- eeschema/dialogs/dialog_lib_new_symbol.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/eeschema/dialogs/dialog_lib_new_symbol.cpp b/eeschema/dialogs/dialog_lib_new_symbol.cpp index 05b01189cc..ae5b5401bf 100644 --- a/eeschema/dialogs/dialog_lib_new_symbol.cpp +++ b/eeschema/dialogs/dialog_lib_new_symbol.cpp @@ -30,6 +30,12 @@ #include +static wxString getDerivativeName( const wxString& aParentName ) +{ + return wxString::Format( "%s_1", aParentName ); +} + + DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent, const wxArrayString& aSymbolNames, const wxString& aInheritFromSymbolName, @@ -37,7 +43,8 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent, DIALOG_LIB_NEW_SYMBOL_BASE( dynamic_cast( aParent ) ), m_pinTextPosition( aParent, m_staticPinTextPositionLabel, m_textPinTextPosition, m_staticPinTextPositionUnits, true ), - m_validator( std::move( aValidator ) ) + m_validator( std::move( aValidator ) ), + m_nameIsDefaulted( true ) { if( aSymbolNames.GetCount() ) { @@ -61,12 +68,24 @@ DIALOG_LIB_NEW_SYMBOL::DIALOG_LIB_NEW_SYMBOL( EDA_DRAW_FRAME* aParent, m_textName->SetValidator( FIELD_VALIDATOR( VALUE_FIELD ) ); m_textReference->SetValidator( FIELD_VALIDATOR( REFERENCE_FIELD ) ); + if( !aInheritFromSymbolName.IsEmpty() ) + { + m_textName->ChangeValue( getDerivativeName( aInheritFromSymbolName ) ); + m_nameIsDefaulted = true; + } + m_pinTextPosition.SetValue( schIUScale.MilsToIU( DEFAULT_PIN_NAME_OFFSET ) ); m_comboInheritanceSelect->Connect( FILTERED_ITEM_SELECTED, wxCommandEventHandler( DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect ), nullptr, this ); + m_textName->Bind( wxEVT_TEXT, + [this]( wxCommandEvent& aEvent ) + { + m_nameIsDefaulted = false; + } ); + // initial focus should be on first editable field. m_textName->SetFocus(); @@ -106,6 +125,13 @@ void DIALOG_LIB_NEW_SYMBOL::onParentSymbolSelect( wxCommandEvent& aEvent ) m_infoBar->Dismiss(); } + if( m_textName->IsEmpty() || m_nameIsDefaulted ) + { + m_textName->SetValue( getDerivativeName( parent ) ); + m_textName->SetInsertionPointEnd(); + m_nameIsDefaulted = true; + } + syncControls( !parent.IsEmpty() ); } diff --git a/eeschema/dialogs/dialog_lib_new_symbol.h b/eeschema/dialogs/dialog_lib_new_symbol.h index 2e070f4d76..84f7fbf294 100644 --- a/eeschema/dialogs/dialog_lib_new_symbol.h +++ b/eeschema/dialogs/dialog_lib_new_symbol.h @@ -106,4 +106,5 @@ private: private: UNIT_BINDER m_pinTextPosition; std::function m_validator; + bool m_nameIsDefaulted; };