From 372e7b6312ce35adf39e4b2c443b4ff6cee2311e Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 10 Apr 2023 09:57:25 +0200 Subject: [PATCH] fix 2 issues related to SCH_GLOBALLABEL items: - Ensure the first field in m_fields has id = 0 to be seen has hypertext (it was not the case after reading a .kicad_sch file) - when converting this item to another label/text, remove this special Field from the copied field list to the converted label. From master branch. --- eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp | 6 +++++- eeschema/tools/sch_edit_tool.cpp | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index 57f17c2bea..84cbc92aee 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -61,6 +61,7 @@ #include #include + using namespace TSCHEMATIC_T; @@ -1948,7 +1949,6 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent ) std::unique_ptr field = std::make_unique( wxDefaultPosition, -1, aParent, name ); - field->SetText( value ); field->SetVisible( true ); @@ -3853,6 +3853,10 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText() || field->GetInternalName() == wxT( "Intersheetrefs" ) ) ) // Current name { SCH_GLOBALLABEL* label = static_cast( text.get() ); + // Ensure the Id of this special and first field is 0, needed by + // SCH_FIELD::IsHypertext() test + field->SetId( 0 ); + label->GetFields()[0] = *field; } else diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index f884d6b7dc..7035d4ff8f 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -2165,8 +2165,23 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) SCH_LABEL_BASE* new_label = dynamic_cast( newtext ); if( label && new_label ) + { new_label->AddFields( label->GetFields() ); + // A SCH_GLOBALLABEL has a specific field, that has no meaning for + // other labels, and expected to be the first field in list. + // It is the first field in list for this kind of label + // So remove field named "Intersheetrefs" if exists for other labels + int min_idx = new_label->Type() == SCH_GLOBAL_LABEL_T ? 1 : 0; + std::vector& fields = new_label->GetFields(); + + for( int ii = fields.size()-1; ii >= min_idx; ii-- ) + { + if( fields[ii].GetCanonicalName() == wxT( "Intersheetrefs" ) ) + fields.erase( fields.begin() + ii ); + } + } + if( selected ) m_toolMgr->RunAction( EE_ACTIONS::removeItemFromSel, true, item );