Map orientation when converting text types.

Also fixes up dangling state when converting.

Fixes: lp:1844716
* https://bugs.launchpad.net/kicad/+bug/1844716
This commit is contained in:
Jeff Young 2019-10-01 15:03:08 +01:00
parent 9a349065db
commit 58b9d5f69e
4 changed files with 33 additions and 9 deletions

View File

@ -58,6 +58,18 @@ int EDA_TEXT::MapOrientation( KICAD_T labelType, int aOrientation )
} }
int EDA_TEXT::MapOrientation( KICAD_T fromLabelType, KICAD_T toLabelType, int aOrientation )
{
bool fromNormal = ( ( fromLabelType == SCH_TEXT_T ) || ( fromLabelType == SCH_LABEL_T ) );
bool toNormal = ( ( toLabelType == SCH_TEXT_T ) || ( toLabelType == SCH_LABEL_T ) );
if( fromNormal != toNormal )
return MapOrientation( SCH_GLOBAL_LABEL_T, aOrientation );
else
return aOrientation;
}
EDA_TEXT_HJUSTIFY_T EDA_TEXT::MapHorizJustify( int aHorizJustify ) EDA_TEXT_HJUSTIFY_T EDA_TEXT::MapHorizJustify( int aHorizJustify )
{ {
wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT ); wxASSERT( aHorizJustify >= GR_TEXT_HJUSTIFY_LEFT && aHorizJustify <= GR_TEXT_HJUSTIFY_RIGHT );

View File

@ -163,20 +163,22 @@ SCH_TEXT* SCH_EDIT_FRAME::CreateNewText( int aType )
void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType ) void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
{ {
bool selected = aText->IsSelected(); KICAD_T oldType = aText->Type();
bool selected = aText->IsSelected();
wxCHECK_RET( aText->CanIncrementLabel(), "Cannot convert text type." ); wxCHECK_RET( aText->CanIncrementLabel(), "Cannot convert text type." );
if( aText->Type() == aNewType ) if( oldType == aNewType )
return; return;
SCH_TEXT* newtext = nullptr; SCH_TEXT* newtext = nullptr;
const wxPoint& position = aText->GetPosition(); const wxPoint& position = aText->GetPosition();
wxString txt = UnescapeString( aText->GetText() ); int orientation = aText->GetLabelSpinStyle();
wxString txt = UnescapeString( aText->GetText() );
// There can be characters in a SCH_TEXT object that can break labels so we have to // There can be characters in a SCH_TEXT object that can break labels so we have to
// fix them here. // fix them here.
if( aText->Type() == SCH_TEXT_T ) if( oldType == SCH_TEXT_T )
{ {
txt.Replace( "\n", "_" ); txt.Replace( "\n", "_" );
txt.Replace( "\r", "_" ); txt.Replace( "\r", "_" );
@ -196,7 +198,7 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
case SCH_TEXT_T: newtext = new SCH_TEXT( position, txt ); break; case SCH_TEXT_T: newtext = new SCH_TEXT( position, txt ); break;
default: default:
wxASSERT_MSG( false, wxString::Format( "Invalid text type: %d.", aNewType ) ); wxFAIL_MSG( wxString::Format( "Invalid text type: %d.", aNewType ) );
return; return;
} }
@ -206,7 +208,7 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
// //
newtext->SetFlags( aText->GetEditFlags() ); newtext->SetFlags( aText->GetEditFlags() );
newtext->SetShape( aText->GetShape() ); newtext->SetShape( aText->GetShape() );
newtext->SetLabelSpinStyle( aText->GetLabelSpinStyle() ); newtext->SetLabelSpinStyle( EDA_TEXT::MapOrientation( oldType, aNewType, orientation ) );
newtext->SetTextSize( aText->GetTextSize() ); newtext->SetTextSize( aText->GetTextSize() );
newtext->SetThickness( aText->GetThickness() ); newtext->SetThickness( aText->GetThickness() );
newtext->SetItalic( aText->IsItalic() ); newtext->SetItalic( aText->IsItalic() );
@ -232,6 +234,17 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aNewType )
if( aText->IsNew() ) if( aText->IsNew() )
delete aText; delete aText;
if( aNewType == SCH_TEXT_T )
{
if( newtext->IsDangling() )
{
newtext->SetIsDangling( false );
GetCanvas()->GetView()->Update( newtext, KIGFX::REPAINT );
}
}
else
TestDanglingEnds();
OnModify(); OnModify();
} }

View File

@ -790,9 +790,7 @@ bool SCH_SCREEN::TestDanglingEnds()
for( item = m_drawList.begin(); item; item = item->Next() ) for( item = m_drawList.begin(); item; item = item->Next() )
{ {
if( item->UpdateDanglingState( endPoints ) ) if( item->UpdateDanglingState( endPoints ) )
{
hasStateChanged = true; hasStateChanged = true;
}
} }
return hasStateChanged; return hasStateChanged;

View File

@ -239,6 +239,7 @@ public:
void Empty() { m_text.Empty(); } void Empty() { m_text.Empty(); }
static int MapOrientation( KICAD_T labelType, int aOrientation ); static int MapOrientation( KICAD_T labelType, int aOrientation );
static int MapOrientation( KICAD_T fromLabelType, KICAD_T toLabelType, int aOrientation );
static EDA_TEXT_HJUSTIFY_T MapHorizJustify( int aHorizJustify ); static EDA_TEXT_HJUSTIFY_T MapHorizJustify( int aHorizJustify );