7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-18 15:59:17 +00:00

Update Altium importer to use textbox flag

Textboxes in Altium might have intrinsic borders that don't count in
their text width, so we need to buffer this in KiCad

Fixes https://gitlab.com/kicad/code/kicad/-/issues/18417
This commit is contained in:
Seth Hillbrand 2024-08-16 15:02:00 -07:00
parent a8a4de029e
commit ecd27883b6
2 changed files with 51 additions and 7 deletions

View File

@ -1077,7 +1077,7 @@ ATEXT6::ATEXT6( ALTIUM_BINARY_PARSER& aReader, std::map<uint32_t, wxString>& aSt
}
else
{
isFrame = false;
isFrame = textbox_rect_height != 0 && textbox_rect_width != 0;
isOffsetBorder = false;
}

View File

@ -4135,7 +4135,7 @@ void ALTIUM_PCB::ConvertTexts6ToBoardItemOnLayer( const ATEXT6& aElem, PCB_LAYER
{
std::unique_ptr<PCB_TEXTBOX> pcbTextbox = std::make_unique<PCB_TEXTBOX>( m_board );
std::unique_ptr<PCB_TEXT> pcbText = std::make_unique<PCB_TEXT>( m_board );
bool isTextbox = ( aElem.textbox_rect_height != 0 );
bool isTextbox = aElem.isFrame;
static const std::map<wxString, wxString> variableMap = {
{ "LAYER_NAME", "LAYER" },
@ -4154,8 +4154,12 @@ void ALTIUM_PCB::ConvertTexts6ToBoardItemOnLayer( const ATEXT6& aElem, PCB_LAYER
item = pcbTextbox.get();
text = pcbTextbox.get();
pcbTextbox->SetPosition( aElem.position - VECTOR2I( 0, aElem.textbox_rect_height ) );
pcbTextbox->SetRectangleHeight( aElem.textbox_rect_height );
pcbTextbox->SetRectangleWidth( aElem.textbox_rect_width );
pcbTextbox->SetRectangleHeight( aElem.textbox_rect_height + aElem.margin_border_width );
pcbTextbox->SetRectangleWidth( aElem.textbox_rect_width + aElem.margin_border_width );
pcbTextbox->SetMarginBottom( aElem.margin_border_width / 2 );
pcbTextbox->SetMarginLeft( aElem.margin_border_width / 2 );
pcbTextbox->SetMarginRight( aElem.margin_border_width / 2 );
pcbTextbox->SetMarginTop( aElem.margin_border_width / 2 );
switch( aElem.textbox_rect_justification )
{
@ -4222,7 +4226,7 @@ void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con
EDA_TEXT* text = fpText.get();
PCB_FIELD* field = nullptr;
bool isTextbox = ( aElem.textbox_rect_height != 0 );
bool isTextbox = aElem.isFrame;
bool toAdd = false;
if( aElem.isDesignator )
@ -4258,9 +4262,13 @@ void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con
text = fpTextbox.get();
fpTextbox->SetPosition( aElem.position - VECTOR2I( 0, aElem.textbox_rect_height ) );
fpTextbox->SetStart( aElem.position - VECTOR2I( 0, aElem.textbox_rect_height ) );
fpTextbox->SetRectangleHeight( aElem.textbox_rect_height );
fpTextbox->SetRectangleWidth( aElem.textbox_rect_width );
fpTextbox->SetRectangleHeight( aElem.textbox_rect_height + aElem.margin_border_width );
fpTextbox->SetRectangleWidth( aElem.textbox_rect_width + aElem.margin_border_width );
fpTextbox->SetBorderEnabled( false );
fpTextbox->SetMarginBottom( aElem.margin_border_width / 2 );
fpTextbox->SetMarginLeft( aElem.margin_border_width / 2 );
fpTextbox->SetMarginRight( aElem.margin_border_width / 2 );
fpTextbox->SetMarginTop( aElem.margin_border_width / 2 );
// KiCad only does top? alignment for textboxes atm
switch( aElem.textbox_rect_justification )
@ -4301,6 +4309,42 @@ void ALTIUM_PCB::ConvertTexts6ToFootprintItemOnLayer( FOOTPRINT* aFootprint, con
else
{
text->SetTextPos( aElem.position );
switch( aElem.textbox_rect_justification )
{
case ALTIUM_TEXT_POSITION::LEFT_TOP:
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
break;
case ALTIUM_TEXT_POSITION::LEFT_CENTER:
text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
break;
case ALTIUM_TEXT_POSITION::LEFT_BOTTOM:
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
break;
case ALTIUM_TEXT_POSITION::CENTER_TOP:
text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
break;
case ALTIUM_TEXT_POSITION::CENTER_BOTTOM:
text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
break;
case ALTIUM_TEXT_POSITION::RIGHT_TOP:
text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
break;
case ALTIUM_TEXT_POSITION::RIGHT_BOTTOM:
text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
break;
default:
text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
break;
}
}