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.
This commit is contained in:
jean-pierre charras 2023-04-10 09:57:25 +02:00
parent adc213a04d
commit f01e083f7c
2 changed files with 20 additions and 1 deletions

View File

@ -61,6 +61,7 @@
#include <progress_reporter.h>
#include <sch_shape.h>
using namespace TSCHEMATIC_T;
@ -1948,7 +1949,6 @@ SCH_FIELD* SCH_SEXPR_PARSER::parseSchField( SCH_ITEM* aParent )
std::unique_ptr<SCH_FIELD> field = std::make_unique<SCH_FIELD>( VECTOR2I(-1,-1), -1,
aParent, name );
field->SetText( value );
field->SetVisible( true );
@ -3858,6 +3858,10 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText()
|| field->GetInternalName() == wxT( "Intersheetrefs" ) ) ) // Current name
{
SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( 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

View File

@ -2165,8 +2165,23 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent )
SCH_LABEL_BASE* new_label = dynamic_cast<SCH_LABEL_BASE*>( 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<SCH_FIELD>& 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 );