CHANGED: Fields may now optionally display their name before their value

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11457
This commit is contained in:
Jon Evans 2022-09-03 16:54:05 -04:00
parent ca5d95a62b
commit 4ea0a80df0
15 changed files with 139 additions and 9 deletions

View File

@ -331,6 +331,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataToWindow()
} }
m_visible->SetValue( m_isVisible ); m_visible->SetValue( m_isVisible );
m_nameVisible->SetValue( m_isNameVisible );
return true; return true;
} }
@ -400,6 +401,7 @@ bool DIALOG_FIELD_PROPERTIES::TransferDataFromWindow()
m_verticalJustification = GR_TEXT_V_ALIGN_BOTTOM; m_verticalJustification = GR_TEXT_V_ALIGN_BOTTOM;
m_isVisible = m_visible->GetValue(); m_isVisible = m_visible->GetValue();
m_isNameVisible = m_nameVisible->GetValue();
return true; return true;
} }
@ -424,6 +426,7 @@ DIALOG_LIB_FIELD_PROPERTIES::DIALOG_LIB_FIELD_PROPERTIES( SCH_BASE_FRAME* aParen
DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField ) DIALOG_FIELD_PROPERTIES( aParent, aTitle, aField )
{ {
m_fieldId = aField->GetId(); m_fieldId = aField->GetId();
m_isNameVisible = aField->IsNameShown();
if( m_fieldId == VALUE_FIELD ) if( m_fieldId == VALUE_FIELD )
m_text = UnescapeString( aField->GetText() ); m_text = UnescapeString( aField->GetText() );
@ -449,6 +452,8 @@ void DIALOG_LIB_FIELD_PROPERTIES::UpdateField( LIB_FIELD* aField )
updateText( aField ); updateText( aField );
aField->SetNameShown( m_isNameVisible );
aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) ); aField->SetHorizJustify( EDA_TEXT::MapHorizJustify( m_horizontalJustification ) );
aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) ); aField->SetVertJustify( EDA_TEXT::MapVertJustify( m_verticalJustification ) );
aField->SetTextPos( m_position ); 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_position = m_field->GetPosition();
m_isNameVisible = m_field->IsNameShown();
m_horizontalJustification = m_field->GetEffectiveHorizJustify(); m_horizontalJustification = m_field->GetEffectiveHorizJustify();
m_verticalJustification = m_field->GetEffectiveVertJustify(); 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->SetFont( m_font );
aField->SetNameShown( m_isNameVisible );
// Note that we must set justifications before we can ask if they're flipped. If the old // 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 // justification is center then it won't know (whereas if the new justification is center
// the we don't care). // the we don't care).

View File

@ -101,6 +101,7 @@ protected:
GR_TEXT_V_ALIGN_T m_verticalJustification; GR_TEXT_V_ALIGN_T m_verticalJustification;
GR_TEXT_H_ALIGN_T m_horizontalJustification; GR_TEXT_H_ALIGN_T m_horizontalJustification;
bool m_isVisible; bool m_isVisible;
bool m_isNameVisible;
bool m_firstFocus; bool m_firstFocus;

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // 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 ); bPropertiesSizer->Add( bUpperBoxSizer, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
wxBoxSizer* bSizer9; wxBoxSizer* bSizer9;
bSizer9 = new wxBoxSizer( wxVERTICAL ); bSizer9 = new wxBoxSizer( wxHORIZONTAL );
m_visible = new wxCheckBox( this, wxID_ANY, _("Visible"), wxDefaultPosition, wxDefaultSize, 0 ); m_visible = new wxCheckBox( this, wxID_ANY, _("Visible"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer9->Add( m_visible, 0, wxALIGN_LEFT|wxBOTTOM, 2 ); 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 ); bPropertiesSizer->Add( bSizer9, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 );

View File

@ -430,7 +430,7 @@
<object class="wxBoxSizer" expanded="1"> <object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="name">bSizer9</property> <property name="name">bSizer9</property>
<property name="orient">wxVERTICAL</property> <property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property> <property name="permission">none</property>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">2</property> <property name="border">2</property>
@ -496,6 +496,70 @@
<property name="window_style"></property> <property name="window_style"></property>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxLEFT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Show field name</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_nameVisible</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Show the field name in addtion to its value</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -52,6 +52,7 @@ class DIALOG_FIELD_PROPERTIES_BASE : public DIALOG_SHIM
wxBitmapButton* m_TextValueSelectButton; wxBitmapButton* m_TextValueSelectButton;
wxStaticText* m_note; wxStaticText* m_note;
wxCheckBox* m_visible; wxCheckBox* m_visible;
wxCheckBox* m_nameVisible;
wxStaticText* m_fontLabel; wxStaticText* m_fontLabel;
FONT_CHOICE* m_fontCtrl; FONT_CHOICE* m_fontCtrl;
BITMAP_BUTTON* m_separator1; BITMAP_BUTTON* m_separator1;

View File

@ -163,7 +163,10 @@ void DIALOG_UPDATE_SYMBOL_FIELDS::onOkButtonClicked( wxCommandEvent& aEvent )
field.SetText( parentField->GetText() ); field.SetText( parentField->GetText() );
if( resetVis ) if( resetVis )
{
field.SetVisible( parentField->IsVisible() ); field.SetVisible( parentField->IsVisible() );
field.SetNameShown( parentField->IsNameShown() );
}
if( resetEffects ) if( resetEffects )
{ {

View File

@ -75,6 +75,7 @@ LIB_FIELD& LIB_FIELD::operator=( const LIB_FIELD& field )
m_name = field.m_name; m_name = field.m_name;
m_parent = field.m_parent; m_parent = field.m_parent;
m_autoAdded = field.m_autoAdded; m_autoAdded = field.m_autoAdded;
m_showName = field.m_showName;
SetText( field.GetText() ); SetText( field.GetText() );
SetAttributes( field ); SetAttributes( field );
@ -101,6 +102,7 @@ void LIB_FIELD::Init( int aId )
SetVisible( false ); SetVisible( false );
m_autoAdded = 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 void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const
{ {
aTarget->m_name = m_name; aTarget->m_name = m_name;
aTarget->m_showName = m_showName;
aTarget->CopyText( *this ); aTarget->CopyText( *this );
aTarget->SetAttributes( *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 const BOX2I LIB_FIELD::GetBoundingBox() const
{ {
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when /* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when

View File

@ -148,6 +148,8 @@ public:
*/ */
wxString GetFullText( int unit = 1 ) const; wxString GetFullText( int unit = 1 ) const;
wxString GetShownText( int aDepth = 0 ) const override;
SCH_LAYER_ID GetDefaultLayer() const; SCH_LAYER_ID GetDefaultLayer() const;
void BeginEdit( const VECTOR2I& aStartPoint ) override; void BeginEdit( const VECTOR2I& aStartPoint ) override;
@ -176,6 +178,9 @@ public:
bool IsAutoAdded() const { return m_autoAdded; } bool IsAutoAdded() const { return m_autoAdded; }
void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; } void SetAutoAdded( bool aAutoAdded ) { m_autoAdded = aAutoAdded; }
bool IsNameShown() const { return m_showName; }
void SetNameShown( bool aShown = true ) { m_showName = aShown; }
private: private:
/** /**
@ -213,6 +218,7 @@ private:
int m_id; ///< @see enum MANDATORY_FIELD_T int m_id; ///< @see enum MANDATORY_FIELD_T
wxString m_name; ///< Name (not the field text value itself, that is #EDA_TEXT::m_Text) 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_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 #endif // CLASS_LIBENTRY_FIELDS_H

View File

@ -199,6 +199,9 @@ wxString SCH_FIELD::GetShownText( int aDepth ) const
PROJECT* project = nullptr; PROJECT* project = nullptr;
wxString text = EDA_TEXT::GetShownText(); wxString text = EDA_TEXT::GetShownText();
if( IsNameShown() )
text = GetName() << wxT( ": " ) << text;
if( text == "~" ) // Legacy placeholder for empty string if( text == "~" ) // Legacy placeholder for empty string
{ {
text = ""; text = "";
@ -361,6 +364,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
void SCH_FIELD::ImportValues( const LIB_FIELD& aSource ) void SCH_FIELD::ImportValues( const LIB_FIELD& aSource )
{ {
SetAttributes( aSource ); SetAttributes( aSource );
SetNameShown( aSource.IsNameShown() );
} }
@ -372,6 +376,7 @@ void SCH_FIELD::SwapData( SCH_ITEM* aItem )
SCH_FIELD* item = (SCH_FIELD*) aItem; SCH_FIELD* item = (SCH_FIELD*) aItem;
std::swap( m_layer, item->m_layer ); std::swap( m_layer, item->m_layer );
std::swap( m_showName, item->m_showName );
SwapText( *item ); SwapText( *item );
SwapAttributes( *item ); SwapAttributes( *item );
} }

View File

@ -136,6 +136,9 @@ public:
GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const; GR_TEXT_H_ALIGN_T GetEffectiveHorizJustify() const;
GR_TEXT_V_ALIGN_T GetEffectiveVertJustify() 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 "~". * @return true if the field is either empty or holds "~".
*/ */
@ -230,6 +233,8 @@ private:
wxString m_name; wxString m_name;
bool m_showName; ///< Render the field name in addition to its value
mutable bool m_renderCacheValid; mutable bool m_renderCacheValid;
mutable VECTOR2I m_renderCachePos; mutable VECTOR2I m_renderCachePos;
mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache; mutable std::vector<std::unique_ptr<KIFONT::GLYPH>> m_renderCache;

View File

@ -893,7 +893,7 @@ void SCH_PAINTER::draw( const LIB_FIELD *aField, int aLayer )
attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER; attrs.m_Valign = GR_TEXT_V_ALIGN_CENTER;
attrs.m_StrokeWidth = getTextThickness( aField ); 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 // Draw the umbilical line when in the schematic editor

View File

@ -391,7 +391,7 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor
if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS ) if( aField->GetId() >= 0 && aField->GetId() < MANDATORY_FIELDS )
fieldName = TEMPLATE_FIELDNAME::GetDefaultFieldName( aField->GetId(), false ); 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( fieldName ).c_str(),
aFormatter.Quotew( aField->GetText() ).c_str(), aFormatter.Quotew( aField->GetText() ).c_str(),
aField->GetId(), aField->GetId(),
@ -399,8 +399,11 @@ void SCH_SEXPR_PLUGIN_CACHE::saveField( LIB_FIELD* aField, OUTPUTFORMATTER& aFor
FormatInternalUnits( aField->GetPosition().y ).c_str(), FormatInternalUnits( aField->GetPosition().y ).c_str(),
aField->GetTextAngle().AsDegrees() ); aField->GetTextAngle().AsDegrees() );
if( aField->IsNameShown() )
aFormatter.Print( aNestLevel, " (show_name)" );
aField->Format( &aFormatter, aNestLevel, 0 ); aField->Format( &aFormatter, aNestLevel, 0 );
aFormatter.Print( aNestLevel, ")\n" ); aFormatter.Print( aNestLevel, "\n)\n" );
} }

View File

@ -795,8 +795,13 @@ LIB_FIELD* SCH_SEXPR_PARSER::parseProperty( std::unique_ptr<LIB_SYMBOL>& aSymbol
parseEDA_TEXT( static_cast<EDA_TEXT*>( field.get() ), field->GetId() == VALUE_FIELD ); parseEDA_TEXT( static_cast<EDA_TEXT*>( field.get() ), field->GetId() == VALUE_FIELD );
break; break;
case T_show_name:
field->SetNameShown();
NeedRIGHT();
break;
default: 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<EDA_TEXT*>( field.get() ), field->GetId() == VALUE_FIELD ); parseEDA_TEXT( static_cast<EDA_TEXT*>( field.get() ), field->GetId() == VALUE_FIELD );
break; break;
case T_show_name:
field->SetNameShown();
NeedRIGHT();
break;
default: default:
Expecting( "at or effects" ); Expecting( "id, show_name, at or effects" );
} }
} }

View File

@ -813,6 +813,9 @@ void SCH_SEXPR_PLUGIN::saveField( SCH_FIELD* aField, int aNestLevel )
FormatInternalUnits( aField->GetPosition().y ).c_str(), FormatInternalUnits( aField->GetPosition().y ).c_str(),
EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() ); EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() );
if( aField->IsNameShown() )
m_out->Print( aNestLevel, " (show_name)" );
if( !aField->IsDefaultFormatting() if( !aField->IsDefaultFormatting()
|| ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) ) || ( aField->GetTextHeight() != Mils2iu( DEFAULT_SIZE_TEXT ) ) )
{ {

View File

@ -114,6 +114,7 @@ scale
shape shape
sheet sheet
sheet_instances sheet_instances
show_name
size size
start start
stroke stroke