From 1db8b322dae6152835a38ab94d8f5e5338796f83 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 28 Apr 2024 12:51:02 +0100 Subject: [PATCH] Make pin name/number visibility architecture more clear. --- eeschema/dialogs/dialog_symbol_properties.cpp | 15 +++------ eeschema/sch_symbol.cpp | 32 +++++++++++++++---- eeschema/sch_symbol.h | 6 ++-- eeschema/symbol.h | 4 +-- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/eeschema/dialogs/dialog_symbol_properties.cpp b/eeschema/dialogs/dialog_symbol_properties.cpp index a735de0600..29ed159621 100644 --- a/eeschema/dialogs/dialog_symbol_properties.cpp +++ b/eeschema/dialogs/dialog_symbol_properties.cpp @@ -749,32 +749,25 @@ bool DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow() case 2: m_symbol->SetOrientation( SYM_MIRROR_Y ); break; } - if( m_part ) - { - m_part->SetShowPinNames( m_ShowPinNameButt->GetValue() ); - m_part->SetShowPinNumbers( m_ShowPinNumButt->GetValue() ); - } + m_symbol->SetShowPinNames( m_ShowPinNameButt->GetValue() ); + m_symbol->SetShowPinNumbers( m_ShowPinNumButt->GetValue() ); // Restore m_Flag modified by SetUnit() and other change settings from the dialog m_symbol->ClearFlags(); m_symbol->SetFlags( flags ); // change all field positions from relative to absolute - for( unsigned i = 0; i < m_fields->size(); ++i ) + for( SCH_FIELD& field : *m_fields ) { - SCH_FIELD& field = m_fields->at( i ); - field.Offset( m_symbol->GetPosition() ); field.SetText( m_symbol->Schematic()->ConvertRefsToKIIDs( field.GetText() ) ); } SCH_FIELDS& fields = m_symbol->GetFields(); - fields.clear(); - for( size_t ii = 0; ii < m_fields->size(); ++ii ) + for( SCH_FIELD& field : *m_fields ) { - SCH_FIELD& field = m_fields->at( ii ); const wxString& fieldName = field.GetCanonicalName(); if( fieldName.IsEmpty() && field.GetText().IsEmpty() ) diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index 200faddb45..83787541ed 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -2598,15 +2598,33 @@ void SCH_SYMBOL::ClearBrightenedPins() } -bool SCH_SYMBOL::SCH_SYMBOL::GetShowPinNumbers() const -{ - return m_part && m_part->GetShowPinNumbers(); -} - - +/* + * When modified at the schematic level, we still store the values of these flags in the + * associated m_part. If m_part now diverges from other usages, a new derived LIB_SYMBOL + * will be created and stored locally in the schematic. + */ bool SCH_SYMBOL::GetShowPinNames() const { - return m_part && m_part->GetShowPinNames(); + wxCHECK( m_part, false ); + return m_part->GetShowPinNames(); +} + +void SCH_SYMBOL::SetShowPinNames( bool aShow ) +{ + wxCHECK( m_part, /* void */ ); + m_part->SetShowPinNames( aShow ); +} + +bool SCH_SYMBOL::GetShowPinNumbers() const +{ + wxCHECK( m_part, false ); + return m_part->GetShowPinNumbers(); +} + +void SCH_SYMBOL::SetShowPinNumbers( bool aShow ) +{ + wxCHECK( m_part, /* void */ ); + m_part->SetShowPinNumbers( aShow ); } diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index ff494eaf2b..b6e4381b6d 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -850,11 +850,11 @@ public: bool IsPower() const override; bool IsNormal() const override; - /* - * We don't currently support changing these at the schematic level. - */ bool GetShowPinNames() const override; + void SetShowPinNames( bool aShow ) override; + bool GetShowPinNumbers() const override; + void SetShowPinNumbers( bool aShow ) override; double Similarity( const SCH_ITEM& aOther ) const override; diff --git a/eeschema/symbol.h b/eeschema/symbol.h index 738a383524..c70bd5441e 100644 --- a/eeschema/symbol.h +++ b/eeschema/symbol.h @@ -120,13 +120,13 @@ public: /** * Set or clear the pin name visibility flag. */ - void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; } + virtual void SetShowPinNames( bool aShow ) { m_showPinNames = aShow; } virtual bool GetShowPinNames() const { return m_showPinNames; } /** * Set or clear the pin number visibility flag. */ - void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; } + virtual void SetShowPinNumbers( bool aShow ) { m_showPinNumbers = aShow; } virtual bool GetShowPinNumbers() const { return m_showPinNumbers; } /**