From e0f0bb2edda4139e2ab89cf45edf96a29e9e8bb1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 10 Jun 2022 14:11:42 +0200 Subject: [PATCH] Eeschema: Fix issues when converting a label/text to another label text type. - make convert to/from SCH_DIRECTIVE_LABEL working. - Autoplace fields of new labels Fixes #11779 https://gitlab.com/kicad/code/kicad/issues/11779 --- eeschema/tools/sch_edit_tool.cpp | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 8bf82d4253..efd5134e1e 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1752,6 +1752,15 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) TEXT_SPIN_STYLE orientation = text->GetTextSpinStyle(); wxString txt = UnescapeString( text->GetText() ); + if( text->Type() == SCH_DIRECTIVE_LABEL_T ) + { + // a SCH_DIRECTIVE_LABEL has no text, but it has at least one field + // containing the net class name + SCH_DIRECTIVE_LABEL* dirlabel = + dynamic_cast( selection.GetItem( i ) ); + txt = UnescapeString( dirlabel->GetFields()[0].GetText() ); + } + // There can be characters in a SCH_TEXT object that can break labels so we have to // fix them here. if( text->Type() == SCH_TEXT_T ) @@ -1783,12 +1792,33 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) // in the new text item type. // newtext->SetFlags( text->GetEditFlags() ); - newtext->SetShape( text->GetShape() ); + + if( newtext->Type() == SCH_DIRECTIVE_LABEL_T ) + { + // a SCH_DIRECTIVE_LABEL has at least one field containing the net class name + // build it: + SCH_DIRECTIVE_LABEL* new_dirlabel = static_cast( newtext ); + SCH_FIELD name( position, 0, new_dirlabel, wxT( "Netclass" ) ); + name.SetText( txt ); + name.SetVisible( true ); + new_dirlabel->GetFields().push_back( name ); + } + else + { + // We cannot use a shape from SCH_DIRECTIVE_LABEL_T label + // It has no meaning for a H or G label + if( text->Type() == SCH_DIRECTIVE_LABEL_T ) + newtext->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); + else + newtext->SetShape( text->GetShape() ); + } + newtext->SetTextSpinStyle( orientation ); newtext->SetTextSize( text->GetTextSize() ); newtext->SetTextThickness( text->GetTextThickness() ); newtext->SetItalic( text->IsItalic() ); newtext->SetBold( text->IsBold() ); + newtext->AutoplaceFields( m_frame->GetScreen(), false ); if( selected ) m_toolMgr->RunAction( EE_ACTIONS::removeItemFromSel, true, text ); @@ -1988,6 +2018,7 @@ void SCH_EDIT_TOOL::setTransitions() Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toHLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toGLabel.MakeEvent() ); + Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toCLabel.MakeEvent() ); Go( &SCH_EDIT_TOOL::ChangeTextType, EE_ACTIONS::toText.MakeEvent() ); Go( &SCH_EDIT_TOOL::BreakWire, EE_ACTIONS::breakWire.MakeEvent() );