CADSTAR Schematic: Fix Text Positioning within Symbols

This commit is contained in:
Roberto Fernandez Bautista 2021-04-09 20:11:12 +01:00
parent 4c914421a1
commit 9148542219
3 changed files with 53 additions and 3 deletions

View File

@ -235,7 +235,7 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
if( strings.GetCount() ) // GetCount() == 0 for void strings
{
if( aLine >= 0 && ( aLine < (int)strings.GetCount() ) )
if( aLine >= 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
text = strings.Item( aLine );
else
text = strings.Item( 0 );
@ -267,6 +267,11 @@ EDA_RECT EDA_TEXT::GetTextBox( int aLine, bool aInvertY ) const
wxSize textsize = wxSize( dx, dy );
wxPoint pos = GetTextPos();
if( IsMultilineAllowed() && aLine > 0 && ( aLine < static_cast<int>( strings.GetCount() ) ) )
{
pos.y -= aLine * GetInterline();
}
if( aInvertY )
pos.y = -pos.y;

View File

@ -2541,6 +2541,15 @@ void CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextIte
wxPoint positionOffset( 0, aKiCadTextItem->GetInterline() );
RotatePoint( &positionOffset, txtAngleDecideg );
EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
if( textEdaItem && ( textEdaItem->Type() == LIB_TEXT_T )
|| ( textEdaItem->Type() == LIB_FIELD_T ) )
{
// Y coordinate increases upwards in the symbol editor
positionOffset.y = -positionOffset.y;
}
//Count num of additional lines
wxString text = aKiCadTextItem->GetText();
int numExtraLines = text.Replace( "\n", "\n" );

View File

@ -1281,10 +1281,12 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
for( std::pair<TEXT_ID, TEXT> textPair : symbol.Texts )
{
TEXT csText = textPair.second;
LIB_TEXT* libtext = new LIB_TEXT( aPart );
libtext->SetText( csText.Text );
libtext->SetUnit( gateNumber );
libtext->SetPosition( getKiCadLibraryPoint( csText.Position, symbol.Origin ) );
libtext->SetMultilineAllowed( true ); // temporarily so that we calculate bbox correctly
applyTextSettings( libtext,
csText.TextCodeID,
@ -1293,8 +1295,40 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdef
csText.OrientAngle,
csText.Mirror );
// Split out multi line text items into individual text elements
if( csText.Text.Contains( "\n" ) )
{
wxArrayString strings;
wxStringSplit( csText.Text, strings, '\n' );
wxPoint firstLinePos;
for( int ii = 0; ii < strings.size(); ++ii )
{
EDA_RECT bbox = libtext->GetTextBox( ii, true );
wxPoint linePos = { bbox.GetLeft(), -bbox.GetBottom() };
RotatePoint( &linePos, libtext->GetTextPos(), -libtext->GetTextAngle() );
LIB_TEXT* line = static_cast<LIB_TEXT*>( libtext->Clone() );
line->SetText( strings[ii] );
line->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
line->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
line->SetTextPos( linePos );
// Multiline text not allowed in LIB_TEXT
line->SetMultilineAllowed( false );
aPart->AddDrawItem( line );
}
delete libtext;
}
else
{
// Multiline text not allowed in LIB_TEXT
libtext->SetMultilineAllowed( false );
aPart->AddDrawItem( libtext );
}
}
if( symbol.TextLocations.find( SYMBOL_NAME_ATTRID ) != symbol.TextLocations.end() )
{
@ -2494,6 +2528,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
{
// Some KiCad schematic text items only permit a limited amount of angles
// and text justifications
case LIB_TEXT_T:
case SCH_FIELD_T:
case LIB_FIELD_T:
{
@ -2560,6 +2595,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadT
return;
default:
wxFAIL_MSG( "Unexpected item type" );
return;
}
}