From a57ca559aa7d56b9079d11c403964acca40dfe11 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 11 Dec 2022 18:56:14 +0100 Subject: [PATCH] sch_field named Intersheetref in global labels: fix incorrect behavior when loading a sch file. This is a special field, always existing, that cannot be handled like other fields. Also avoid using translated names when initializing the field name. Translated names can be used only in UI, not in internal data. fixes #13113 fixes #13125 --- eeschema/sch_field.cpp | 4 ++-- eeschema/sch_field.h | 6 ++++++ eeschema/sch_label.cpp | 2 +- eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 8 +++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index c73b5cbecc..212231694c 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -887,9 +887,9 @@ wxString SCH_FIELD::GetCanonicalName() const else if( m_parent && m_parent->IsType( { SCH_LABEL_LOCATE_ANY_T } ) ) { // These should be stored in canonical format, but just in case: - if( m_name == _( "Net Class" ) ) + if( m_name == _( "Net Class" ) || m_name == wxT( "Net Class" ) ) return wxT( "Netclass" ); - else if (m_name == _( "Sheet References" ) ) + else if( m_name == _( "Sheet References" ) || m_name == wxT( "Sheet References" ) ) return wxT( "Intersheetrefs" ); else return m_name; diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 4c38fadc9d..60ae75fdc7 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -116,6 +116,12 @@ public: void SetName( const wxString& aName ) { m_name = aName; } + /** + * Get the initial name of the field set at creation (or set by SetName()). + * This is the raw field name with no translation and no change. + */ + const wxString& GetInternalName() { return m_name; } + int GetId() const { return m_id; } void SetId( int aId ); diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index 17c555b28f..36e04a25c6 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -1254,7 +1254,7 @@ SCH_GLOBALLABEL::SCH_GLOBALLABEL( const VECTOR2I& pos, const wxString& text ) : SetVertJustify( GR_TEXT_V_ALIGN_CENTER ); - m_fields.emplace_back( SCH_FIELD( pos, 0, this, _( "Sheet References" ) ) ); + m_fields.emplace_back( SCH_FIELD( pos, 0, this, wxT( "Sheet References" ) ) ); m_fields[0].SetText( wxT( "${INTERSHEET_REFS}" ) ); m_fields[0].SetVisible( false ); m_fields[0].SetLayer( LAYER_INTERSHEET_REFS ); diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index bf35ff5e8e..da83f870ba 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -3839,7 +3839,13 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText() SCH_FIELD* field = parseSchField( text.get() ); - static_cast( text.get() )->GetFields().emplace_back( *field ); + if( text->Type() == SCH_GLOBAL_LABEL_T && field->GetInternalName() == wxT( "Intersheetrefs") ) + { + SCH_GLOBALLABEL* label = static_cast( text.get() ); + label->GetFields()[0] = *field; + } + else + static_cast( text.get() )->GetFields().emplace_back( *field ); delete field; break;