Remove requirement that non-power symbols share a name and value

There is no technical reason for this restriction for non-power symbols, so let's remove it.
This will allow more flexibility and compatibility with other tools.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/9389
This commit is contained in:
Jon Evans 2022-08-20 17:43:20 -04:00
parent af34835fdf
commit 8694c37376
6 changed files with 20 additions and 42 deletions

View File

@ -305,8 +305,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
if( !m_grid->CommitPendingChanges() ) if( !m_grid->CommitPendingChanges() )
return false; return false;
// We need to keep the name and the value the same at the moment! wxString newName = EscapeString( m_SymbolNameCtrl->GetValue(), CTX_LIBID );
wxString newName = EscapeString( m_fields->at( VALUE_FIELD ).GetText(), CTX_LIBID );
wxString oldName = m_libEntry->GetName(); wxString oldName = m_libEntry->GetName();
if( oldName != newName ) if( oldName != newName )
@ -363,7 +362,6 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
m_libEntry->SetParent( newParent ); m_libEntry->SetParent( newParent );
} }
// We need to keep the name and the value the same at the moment!
m_libEntry->SetName( newName ); m_libEntry->SetName( newName );
m_libEntry->SetDescription( m_DescCtrl->GetValue() ); m_libEntry->SetDescription( m_DescCtrl->GetValue() );
m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() ); m_libEntry->SetKeyWords( m_KeywordCtrl->GetValue() );
@ -374,9 +372,15 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow()
m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() ); m_Parent->SetShowDeMorgan( m_AsConvertButt->GetValue() );
if( m_OptionPower->GetValue() ) if( m_OptionPower->GetValue() )
{
m_libEntry->SetPower(); m_libEntry->SetPower();
// Power symbols must have value matching name for now
m_libEntry->GetValueField().SetText( newName );
}
else else
{
m_libEntry->SetNormal(); m_libEntry->SetNormal();
}
m_libEntry->SetIncludeInBom( !m_excludeFromBomCheckBox->GetValue() ); m_libEntry->SetIncludeInBom( !m_excludeFromBomCheckBox->GetValue() );
m_libEntry->SetIncludeOnBoard( !m_excludeFromBoardCheckBox->GetValue() ); m_libEntry->SetIncludeOnBoard( !m_excludeFromBoardCheckBox->GetValue() );
@ -442,10 +446,6 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
} }
} }
} }
else if( event.GetRow() == VALUE_FIELD && event.GetCol() == FDC_VALUE )
{
m_SymbolNameCtrl->ChangeValue( event.GetString() );
}
editor->DecRef(); editor->DecRef();
} }
@ -453,7 +453,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSymbolNameText( wxCommandEvent& event ) void DIALOG_LIB_SYMBOL_PROPERTIES::OnSymbolNameText( wxCommandEvent& event )
{ {
if( !m_Parent->IsSymbolFromSchematic() || m_OptionPower->IsChecked() ) if( m_OptionPower->IsChecked() )
m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() ); m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
} }
@ -736,7 +736,7 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI( wxUpdateUIEvent& event )
int row = m_grid->GetGridCursorRow(); int row = m_grid->GetGridCursorRow();
int col = m_grid->GetGridCursorCol(); int col = m_grid->GetGridCursorCol();
if( row == VALUE_FIELD && col == FDC_VALUE ) if( row == VALUE_FIELD && col == FDC_VALUE && m_OptionPower->IsChecked() )
{ {
wxGridCellEditor* editor = m_grid->GetCellEditor( row, col ); wxGridCellEditor* editor = m_grid->GetCellEditor( row, col );
m_SymbolNameCtrl->ChangeValue( editor->GetValue() ); m_SymbolNameCtrl->ChangeValue( editor->GetValue() );

View File

@ -681,11 +681,6 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow()
for( unsigned i = 0; i < m_fields->size(); ++i ) for( unsigned i = 0; i < m_fields->size(); ++i )
m_fields->at( i ).Offset( m_symbol->GetPosition() ); m_fields->at( i ).Offset( m_symbol->GetPosition() );
LIB_SYMBOL* entry = GetParent()->GetLibSymbol( m_symbol->GetLibId() );
if( entry && entry->IsPower() )
m_fields->at( VALUE_FIELD ).SetText( m_symbol->GetLibId().GetLibItemName() );
SCH_FIELDS& fields = m_symbol->GetFields(); SCH_FIELDS& fields = m_symbol->GetFields();
fields.clear(); fields.clear();

View File

@ -365,7 +365,8 @@ void LIB_SYMBOL::SetName( const wxString& aName )
m_name = aName; m_name = aName;
m_libId.SetLibItemName( aName ); m_libId.SetLibItemName( aName );
GetValueField().SetText( aName ); if( IsPower() )
GetValueField().SetText( aName );
} }

View File

@ -871,10 +871,7 @@ void SCH_SYMBOL::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, b
} }
else if( id == VALUE_FIELD ) else if( id == VALUE_FIELD )
{ {
if( aResetOtherFields ) SetValue( aPath, UnescapeString( libField->GetText() ) );
SetValue( aPath, UnescapeString( m_lib_id.GetLibItemName() ) ); // alias-specific value
else
SetValue( aPath, UnescapeString( libField->GetText() ) );
} }
else if( id == FOOTPRINT_FIELD ) else if( id == FOOTPRINT_FIELD )
{ {

View File

@ -480,7 +480,8 @@ void SYMBOL_EDIT_FRAME::CreateNewSymbol()
break; break;
case VALUE_FIELD: case VALUE_FIELD:
field->SetText( name ); if( parent->IsPower() )
field->SetText( name );
break; break;
case FOOTPRINT_FIELD: case FOOTPRINT_FIELD:

View File

@ -527,11 +527,7 @@ void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
LIB_SYMBOL* parent = aField->GetParent(); LIB_SYMBOL* parent = aField->GetParent();
wxCHECK( parent, /* void */ ); wxCHECK( parent, /* void */ );
// Editing the symbol value field is equivalent to creating a new symbol based on the if( aField->GetId() < MANDATORY_FIELDS )
// current symbol. Set the dialog message to inform the user.
if( aField->GetId() == VALUE_FIELD )
caption = _( "Edit Symbol Name" );
else if( aField->GetId() < MANDATORY_FIELDS )
caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) ); caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
else else
caption.Printf( _( "Edit '%s' Field" ), aField->GetName() ); caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
@ -545,27 +541,15 @@ void SYMBOL_EDITOR_EDIT_TOOL::editFieldProperties( LIB_FIELD* aField )
wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID ); wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() ); wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue;
if( renamed ) saveCopyInUndoList( parent, UNDO_REDO::LIBEDIT );
saveCopyInUndoList( parent, UNDO_REDO::LIB_RENAME );
else
saveCopyInUndoList( parent, UNDO_REDO::LIBEDIT );
dlg.UpdateField( aField ); dlg.UpdateField( aField );
if( renamed ) updateItem( aField, true );
{ m_frame->GetCanvas()->Refresh();
parent->SetName( newFieldValue ); m_frame->OnModify();
m_frame->UpdateAfterSymbolProperties( &oldFieldValue ); m_frame->UpdateSymbolMsgPanelInfo();
}
else
{
updateItem( aField, true );
m_frame->GetCanvas()->Refresh();
m_frame->OnModify();
m_frame->UpdateSymbolMsgPanelInfo();
}
} }