From 4ea0a80df02147b82313f9537a5974e908a9c2c9 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 3 Sep 2022 16:54:05 -0400 Subject: [PATCH] CHANGED: Fields may now optionally display their name before their value Fixes https://gitlab.com/kicad/code/kicad/-/issues/11457 --- eeschema/dialogs/dialog_field_properties.cpp | 9 +++ eeschema/dialogs/dialog_field_properties.h | 1 + .../dialogs/dialog_field_properties_base.cpp | 9 ++- .../dialogs/dialog_field_properties_base.fbp | 66 ++++++++++++++++++- .../dialogs/dialog_field_properties_base.h | 3 +- .../dialogs/dialog_update_symbol_fields.cpp | 3 + eeschema/lib_field.cpp | 14 ++++ eeschema/lib_field.h | 6 ++ eeschema/sch_field.cpp | 5 ++ eeschema/sch_field.h | 5 ++ eeschema/sch_painter.cpp | 2 +- .../kicad/sch_sexpr_lib_plugin_cache.cpp | 7 +- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 14 +++- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 3 + eeschema/schematic.keywords | 1 + 15 files changed, 139 insertions(+), 9 deletions(-) diff --git a/eeschema/dialogs/dialog_field_properties.cpp b/eeschema/dialogs/dialog_field_properties.cpp index 91b10dabbf..6694315556 100644 --- a/eeschema/dialogs/dialog_field_properties.cpp +++ b/eeschema/dialogs/dialog_field_properties.cpp @@ -331,6 +331,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataToWindow() } m_visible->SetValue( m_isVisible ); + m_nameVisible->SetValue( m_isNameVisible ); return true; } @@ -400,6 +401,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataFromWindow() m_verticalJustification = GR_TEXT_V_ALIGN_BOTTOM; m_isVisible = m_visible->GetValue(); + m_isNameVisible = m_nameVisible->GetValue(); return true; } @@ -424,6 +426,7 @@ DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ) { m_fieldId = aField->GetId(); + m_isNameVisible = aField->IsNameShown(); if( m_fieldId == VALUE_FIELD ) m_text = UnescapeString( aField->GetText() ); @@ -449,6 +452,8 @@ void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField ) updateText( aField ); + aField->SetNameShown( m_isNameVisible ); + aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) ); aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) ); aField->SetTextPos( m_position ); @@ -504,6 +509,8 @@ DIALOG_SCH_FIELD_PROPERTIES::DIALOG_SCH_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen m_position = m_field->GetPosition(); + m_isNameVisible = m_field->IsNameShown(); + m_horizontalJustification = m_field->GetEffectiveHorizJustify(); m_verticalJustification = m_field->GetEffectiveVertJustify(); @@ -664,6 +671,8 @@ void DIALOG_SCH_FIELD_PROPERTIES::UpdateField( SCH_FIELD* aField, SCH_SHEET_PATH aField->SetFont( m_font ); + aField->SetNameShown( m_isNameVisible ); + // Note that we must set justifications before we can ask if they're flipped. If the old // justification is center then it won't know (whereas if the new justification is center // the we don't care). diff --git a/eeschema/dialogs/dialog_field_properties.h b/eeschema/dialogs/dialog_field_properties.h index 077c922c43..15507d6ef6 100644 --- a/eeschema/dialogs/dialog_field_properties.h +++ b/eeschema/dialogs/dialog_field_properties.h @@ -101,6 +101,7 @@ protected: GR_TEXT_V_ALIGN_T m_verticalJustification; GR_TEXT_H_ALIGN_T m_horizontalJustification; bool m_isVisible; + bool m_isNameVisible; bool m_firstFocus; diff --git a/eeschema/dialogs/dialog_field_properties_base.cpp b/eeschema/dialogs/dialog_field_properties_base.cpp index b2b097b68a..a8b48d4ee0 100644 --- a/eeschema/dialogs/dialog_field_properties_base.cpp +++ b/eeschema/dialogs/dialog_field_properties_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -82,11 +82,16 @@ DIALOG_FIELD_PROPERTIES_BASE::DIALOG_FIELD_PROPERTIES_BASE( wxWindow* parent, wx bPropertiesSizer->Add( bUpperBoxSizer, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); wxBoxSizer* bSizer9; - bSizer9 = new wxBoxSizer( wxVERTICAL ); + bSizer9 = new wxBoxSizer( wxHORIZONTAL ); m_visible = new wxCheckBox( this, wxID_ANY, _("Visible"), wxDefaultPosition, wxDefaultSize, 0 ); bSizer9->Add( m_visible, 0, wxALIGN_LEFT|wxBOTTOM, 2 ); + m_nameVisible = new wxCheckBox( this, wxID_ANY, _("Show field name"), wxDefaultPosition, wxDefaultSize, 0 ); + m_nameVisible->SetToolTip( _("Show the field name in addtion to its value") ); + + bSizer9->Add( m_nameVisible, 0, wxLEFT, 5 ); + bPropertiesSizer->Add( bSizer9, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 ); diff --git a/eeschema/dialogs/dialog_field_properties_base.fbp b/eeschema/dialogs/dialog_field_properties_base.fbp index d227f5b2a5..8bbc6d70c1 100644 --- a/eeschema/dialogs/dialog_field_properties_base.fbp +++ b/eeschema/dialogs/dialog_field_properties_base.fbp @@ -430,7 +430,7 @@ bSizer9 - wxVERTICAL + wxHORIZONTAL none 2 @@ -496,6 +496,70 @@ + + 5 + wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Show field name + + 0 + + + 0 + + 1 + m_nameVisible + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + Show the field name in addtion to its value + + wxFILTER_NONE + wxDefaultValidator + + + + + + diff --git a/eeschema/dialogs/dialog_field_properties_base.h b/eeschema/dialogs/dialog_field_properties_base.h index 867c6f50ea..1706cb43a2 100644 --- a/eeschema/dialogs/dialog_field_properties_base.h +++ b/eeschema/dialogs/dialog_field_properties_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b) +// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -52,6 +52,7 @@ class DIALOG_FIELD_PROPERTIES_BASE : public DIALOG_SHIM wxBitmapButton* m_TextValueSelectButton; wxStaticText* m_note; wxCheckBox* m_visible; + wxCheckBox* m_nameVisible; wxStaticText* m_fontLabel; FONT_CHOICE* m_fontCtrl; BITMAP_BUTTON* m_separator1; diff --git a/eeschema/dialogs/dialog_update_symbol_fields.cpp b/eeschema/dialogs/dialog_update_symbol_fields.cpp index b45c662441..0d7acf6551 100644 --- a/eeschema/dialogs/dialog_update_symbol_fields.cpp +++ b/eeschema/dialogs/dialog_update_symbol_fields.cpp @@ -163,7 +163,10 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent ) field.SetText( parentField->GetText() ); if( resetVis ) + { field.SetVisible( parentField->IsVisible() ); + field.SetNameShown( parentField->IsNameShown() ); + } if( resetEffects ) { diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 94ca608e00..c82865bfeb 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -75,6 +75,7 @@ LIB_FIELD& LIB_FIELD::operator=( const LIB_FIELD& field ) m_name = field.m_name; m_parent = field.m_parent; m_autoAdded = field.m_autoAdded; + m_showName = field.m_showName; SetText( field.GetText() ); SetAttributes( field ); @@ -101,6 +102,7 @@ void LIB_FIELD::Init( int aId ) SetVisible( false ); m_autoAdded = false; + m_showName = false; } @@ -193,6 +195,7 @@ EDA_ITEM* LIB_FIELD::Clone() const void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const { aTarget->m_name = m_name; + aTarget->m_showName = m_showName; aTarget->CopyText( *this ); aTarget->SetAttributes( *this ); @@ -368,6 +371,17 @@ wxString LIB_FIELD::GetFullText( int unit ) const } +wxString LIB_FIELD::GetShownText( int aDepth ) const +{ + wxString text = EDA_TEXT::GetShownText( aDepth ); + + if( IsNameShown() ) + text = GetName() << wxT( ": " ) << text; + + return text; +} + + const BOX2I LIB_FIELD::GetBoundingBox() const { /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 0c1071608f..48c898ac5a 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -148,6 +148,8 @@ public: */ wxString GetFullText( int unit = 1 ) const; + wxString GetShownText( int aDepth = 0 ) const override; + SCH_LAYER_ID GetDefaultLayer() const; void BeginEdit( const VECTOR2I& aStartPoint ) override; @@ -176,6 +178,9 @@ public: bool IsAutoAdded() const { return m_autoAdded; } void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; } + bool IsNameShown() const { return m_showName; } + void SetNameShown( bool aShown = true ) { m_showName = aShown; } + private: /** @@ -213,6 +218,7 @@ private: int m_id; ///< @see enum MANDATORY_FIELD_T wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text) bool m_autoAdded; ///< Was this field automatically added to a LIB_SYMBOL? + bool m_showName; ///< Render the field's name in addition to its value }; #endif // CLASS_LIBENTRY_FIELDS_H diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 4f18c3ce88..5c47919a5a 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -199,6 +199,9 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const PROJECT* project = nullptr; wxString text = EDA_TEXT::GetShownText(); + if( IsNameShown() ) + text = GetName() << wxT( ": " ) << text; + if( text == "~" ) // Legacy placeholder for empty string { text = ""; @@ -361,6 +364,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset void SCH_FIELD::ImportValues( const LIB_FIELD& aSource ) { SetAttributes( aSource ); + SetNameShown( aSource.IsNameShown() ); } @@ -372,6 +376,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem ) SCH_FIELD* item = (SCH_FIELD*) aItem; std::swap( m_layer, item->m_layer ); + std::swap( m_showName, item->m_showName ); SwapText( *item ); SwapAttributes( *item ); } diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 3ce0e0b5bb..f805de7787 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -136,6 +136,9 @@ public: GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const; GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() const; + bool IsNameShown() const { return m_showName; } + void SetNameShown( bool aShown = true ) { m_showName = aShown; } + /** * @return true if the field is either empty or holds "~". */ @@ -230,6 +233,8 @@ private: wxString m_name; + bool m_showName; ///< Render the field name in addition to its value + mutable bool m_renderCacheValid; mutable VECTOR2I m_renderCachePos; mutable std::vector> m_renderCache; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 39ccf3e7fd..9d49714dff 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -893,7 +893,7 @@ void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer ) attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER; attrs.m_StrokeWidth = getTextThickness( aField ); - strokeText( UnescapeString( aField->GetText() ), textpos, attrs ); + strokeText( UnescapeString( aField->GetShownText() ), textpos, attrs ); } // Draw the umbilical line when in the schematic editor diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp index a5378e9335..405d0801c0 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_lib_plugin_cache.cpp @@ -391,7 +391,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS ) fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false ); - aFormatter.Print( aNestLevel, "(property %s %s (id %d) (at %s %s %g)\n", + aFormatter.Print( aNestLevel, "(property %s %s (id %d) (at %s %s %g)", aFormatter.Quotew( fieldName ).c_str(), aFormatter.Quotew( aField->GetText() ).c_str(), aField->GetId(), @@ -399,8 +399,11 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor FormatInternalUnits( aField->GetPosition().y ).c_str(), aField->GetTextAngle().AsDegrees() ); + if( aField->IsNameShown() ) + aFormatter.Print( aNestLevel, " (show_name)" ); + aField->Format( &aFormatter, aNestLevel, 0 ); - aFormatter.Print( aNestLevel, ")\n" ); + aFormatter.Print( aNestLevel, "\n)\n" ); } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index da3ef9d131..d571e40f2a 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -795,8 +795,13 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr& aSymbol parseEDA_TEXT( static_cast( field.get() ), field->GetId() == VALUE_FIELD ); break; + case T_show_name: + field->SetNameShown(); + NeedRIGHT(); + break; + default: - Expecting( "id, at or effects" ); + Expecting( "id, at, show_name, or effects" ); } } @@ -1902,8 +1907,13 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) parseEDA_TEXT( static_cast( field.get() ), field->GetId() == VALUE_FIELD ); break; + case T_show_name: + field->SetNameShown(); + NeedRIGHT(); + break; + default: - Expecting( "at or effects" ); + Expecting( "id, show_name, at or effects" ); } } diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 6152109312..2cca1d7570 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -813,6 +813,9 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel ) FormatInternalUnits( aField->GetPosition().y ).c_str(), EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() ); + if( aField->IsNameShown() ) + m_out->Print( aNestLevel, " (show_name)" ); + if( !aField->IsDefaultFormatting() || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) ) { diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index 40b0afacf7..a2000fc887 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -114,6 +114,7 @@ scale shape sheet sheet_instances +show_name size start stroke