Bug fixes for fields when editing a symbol from the schematic.

1) Don't reset value when name changes
2) Don't fire events when initialising dialog
3) Make sure when symbol is saved back to schematic that only current
instance has its ref updated, but that all instances have their other
fields updated.
4) When saving symbol back to board always use the fields from the
editor and not the (alias-specific) ones from the library.

Fixes https://gitlab.com/kicad/code/kicad/issues/8159
This commit is contained in:
Jeff Young 2021-04-09 17:10:40 +01:00
parent d2c7df155b
commit df5f010514
8 changed files with 64 additions and 26 deletions

View File

@ -753,8 +753,14 @@ bool DIALOG_EDIT_COMPONENTS_LIBID::TransferDataFromWindow()
cmp.m_Screen->SetModify();
if ( m_checkBoxUpdateFields->IsChecked() )
cmp.m_Component->UpdateFields( false, false );
{
cmp.m_Component->UpdateFields( nullptr,
false, /* update style */
false, /* update ref */
false, /* update other fields */
false, /* reset ref */
true /* reset other fields */ );
}
}
}

View File

@ -166,10 +166,10 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow()
m_grid->ProcessTableMessage( msg );
adjustGridColumns( m_grid->GetRect().GetWidth() );
m_SymbolNameCtrl->SetValue( m_libEntry->GetName() );
m_SymbolNameCtrl->ChangeValue( m_libEntry->GetName() );
m_DescCtrl->SetValue( m_libEntry->GetDescription() );
m_KeywordCtrl->SetValue( m_libEntry->GetKeyWords() );
m_DescCtrl->ChangeValue( m_libEntry->GetDescription() );
m_KeywordCtrl->ChangeValue( m_libEntry->GetKeyWords() );
m_SelNumberOfUnits->SetValue( m_libEntry->GetUnitCount() );
m_OptionPartsInterchangeable->SetValue( !m_libEntry->UnitsLocked() || m_libEntry->GetUnitCount() == 1 );
m_AsConvertButt->SetValue( m_libEntry->HasConversion() );
@ -180,7 +180,7 @@ bool DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataToWindow()
m_ShowPinNumButt->SetValue( m_libEntry->ShowPinNumbers() );
m_ShowPinNameButt->SetValue( m_libEntry->ShowPinNames() );
m_PinsNameInsideButt->SetValue( m_libEntry->GetPinNameOffset() != 0 );
m_pinNameOffset.SetValue( m_libEntry->GetPinNameOffset() );
m_pinNameOffset.ChangeValue( m_libEntry->GetPinNameOffset() );
wxArrayString tmp = m_libEntry->GetFPFilters();
m_FootprintFilterListBox->Append( tmp );
@ -443,7 +443,8 @@ void DIALOG_LIB_SYMBOL_PROPERTIES::OnGridCellChanging( wxGridEvent& event )
void DIALOG_LIB_SYMBOL_PROPERTIES::OnSymbolNameText( wxCommandEvent& event )
{
m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
if( !m_Parent->IsSymbolFromSchematic() )
m_grid->SetCellValue( VALUE_FIELD, FDC_VALUE, m_SymbolNameCtrl->GetValue() );
}

View File

@ -1603,7 +1603,7 @@ void SCH_EDIT_FRAME::onSize( wxSizeEvent& aEvent )
}
void SCH_EDIT_FRAME::UpdateSymbolFromEditor( const LIB_PART& aSymbol )
void SCH_EDIT_FRAME::SaveSymbolToSchematic( const LIB_PART& aSymbol )
{
wxString msg;
bool appendToUndo = false;
@ -1642,7 +1642,12 @@ void SCH_EDIT_FRAME::UpdateSymbolFromEditor( const LIB_PART& aSymbol )
}
symbol->SetLibSymbol( aSymbol.Flatten().release() );
symbol->UpdateFields( true, true );
symbol->UpdateFields( &GetCurrentSheet(),
true, /* update style */
true, /* update ref */
true, /* update other fields */
false, /* reset ref */
false /* reset other fields */ );
currentScreen->Append( symbol );
selectionTool->SelectHighlightItem( symbol );

View File

@ -815,7 +815,7 @@ public:
*
* @param aSymbol is the #LIB_PART to update.
*/
void UpdateSymbolFromEditor( const LIB_PART& aSymbol );
void SaveSymbolToSchematic( const LIB_PART& aSymbol );
/**
* Update the schematic's page reference map for all global labels, and refresh the labels

View File

@ -117,7 +117,12 @@ SCH_COMPONENT::SCH_COMPONENT( const LIB_PART& aPart, const LIB_ID& aLibId,
SetLibSymbol( part.release() );
// Copy fields from the library symbol
UpdateFields( true, true );
UpdateFields( aSheet,
true, /* update style */
false, /* update ref */
false, /* update other fields */
true, /* reset ref */
true /* reset other fields */ );
// Update the reference -- just the prefix for now.
if( aSheet )
@ -767,7 +772,8 @@ SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName, bool aIncludeDe
}
void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
void SCH_COMPONENT::UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef,
bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields )
{
if( m_part )
{
@ -781,9 +787,6 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
int id = libField->GetId();
SCH_FIELD* schField;
if( id == REFERENCE_FIELD && !aResetRef )
continue;
if( id >= 0 && id < MANDATORY_FIELDS )
{
schField = GetFieldById( id );
@ -800,24 +803,42 @@ void SCH_COMPONENT::UpdateFields( bool aResetStyle, bool aResetRef )
}
}
if( aResetStyle )
if( aUpdateStyle )
{
schField->ImportValues( *libField );
schField->SetTextPos( m_pos + libField->GetTextPos() );
}
if( id == VALUE_FIELD )
if( id == REFERENCE_FIELD )
{
schField->SetText( m_lib_id.GetLibItemName() ); // fetch alias-specific value
symbolName = m_lib_id.GetLibItemName();
if( aResetOtherFields )
SetRef( aPath, m_part->GetReferenceField().GetText() );
else if( aUpdateRef )
SetRef( aPath, libField->GetText() );
}
else if( id == VALUE_FIELD )
{
if( aResetOtherFields )
SetValue( m_lib_id.GetLibItemName() ); // fetch alias-specific value
else
SetValue( libField->GetText() );
}
else if( id == FOOTPRINT_FIELD )
{
if( aResetOtherFields || aUpdateOtherFields )
SetFootprint( libField->GetText() );
}
else if( id == DATASHEET_FIELD )
{
schField->SetText( GetDatasheet() ); // fetch alias-specific value
if( aResetOtherFields )
schField->SetText( GetDatasheet() ); // fetch alias-specific value
else if( aUpdateOtherFields )
schField->SetText( libField->GetText() );
}
else
{
schField->SetText( libField->GetText() );
if( aResetOtherFields || aUpdateOtherFields )
schField->SetText( libField->GetText() );
}
}
}

View File

@ -405,10 +405,15 @@ public:
/**
* Restore fields to the original library values.
*
* @param aResetStyle selects whether fields should reset the position and text attribute.
* @param aResetRef selects whether the reference field should be restored.
* @param aUpdateStyle selects whether fields should update the position and text attributes.
* @param aUpdateRef selects whether the reference field should be updated.
* @param aUpdateOtherFields selects whether non-reference fields should be updated.
* @param aResetRef selects whether the reference should be reset to the library value.
* @param aResetOtherFields selects whether non-reference fields should be reset to library
* values.
*/
void UpdateFields( bool aResetStyle, bool aResetRef = false );
void UpdateFields( const SCH_SHEET_PATH* aPath, bool aUpdateStyle, bool aUpdateRef,
bool aUpdateOtherFields, bool aResetRef, bool aResetOtherFields );
/**
* Return the number of fields in this symbol.

View File

@ -505,7 +505,7 @@ bool SYMBOL_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
{
case wxID_YES:
if( schframe && GetCurPart() ) // Should be always the case
schframe->UpdateSymbolFromEditor( *GetCurPart() );
schframe->SaveSymbolToSchematic( *GetCurPart());
return true;

View File

@ -519,7 +519,7 @@ void SYMBOL_EDIT_FRAME::Save()
}
else
{
schframe->UpdateSymbolFromEditor( *m_my_part );
schframe->SaveSymbolToSchematic( *m_my_part );
GetScreen()->ClrModify();
}
}