Fixes for autoplace fields.

1) Don't factor in pin names when computing symbol body boundingbox.
2) Grid-snap only in the axis corresponding to the layout side.
3) We only need interline spacing *between* lines, not for each line.
4) Also cleans up the unit checking logic as the unit can't be more
than 0 unless it's a multi-unit symbol.

Fixes https://gitlab.com/kicad/code/kicad/issues/7907
This commit is contained in:
Jeff Young 2021-03-14 22:29:41 +00:00
parent 7415bf0c62
commit afab60ae06
3 changed files with 21 additions and 20 deletions

View File

@ -168,8 +168,11 @@ public:
if( m_align_to_grid )
{
pos.x = round_n( pos.x, Mils2iu( 50 ), field_side.x >= 0 );
pos.y = round_n( pos.y, Mils2iu( 50 ), field_side.y >= 0 );
if( abs( field_side.x ) > 0 )
pos.x = round_n( pos.x, Mils2iu( 50 ), field_side.x >= 0 );
if( abs( field_side.y ) > 0 )
pos.y = round_n( pos.y, Mils2iu( 50 ), field_side.y >= 0 );
}
field->SetPosition( pos );
@ -188,19 +191,21 @@ protected:
for( SCH_FIELD* field : m_fields )
{
int field_width;
int field_height;
if( m_symbol->GetTransform().y1 )
field->SetTextAngle( TEXT_ANGLE_VERT );
else
field->SetTextAngle( TEXT_ANGLE_HORIZ );
field_width = field->GetBoundingBox().GetWidth();
field_height = field->GetBoundingBox().GetHeight();
EDA_RECT bbox = field->GetBoundingBox();
int field_width = bbox.GetWidth();
int field_height = bbox.GetHeight();
max_field_width = std::max( max_field_width, field_width );
// Remove interline spacing from field_height for last line.
if( field == m_fields[ m_fields.size() - 1 ] )
field_height *= 0.62;
if( !aDynamic )
total_height += WIRE_V_SPACING;
else if( m_align_to_grid )

View File

@ -852,13 +852,8 @@ const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
for( const LIB_ITEM& item : m_drawings )
{
if( item.m_unit > 0
&& m_unitCount > 1
&& aUnit > 0
&& aUnit != item.m_unit )
{
if( item.m_unit > 0 && aUnit > 0 && aUnit != item.m_unit )
continue;
}
if( item.m_convert > 0 && aConvert > 0 && aConvert != item.m_convert )
continue;
@ -866,7 +861,10 @@ const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
if( item.Type() == LIB_FIELD_T )
continue;
bbox.Merge( item.GetBoundingBox() );
if( item.Type() == LIB_PIN_T )
bbox.Merge( static_cast<const LIB_PIN&>( item ).GetBoundingBox( false, true ) );
else
bbox.Merge( item.GetBoundingBox() );
}
return bbox;

View File

@ -220,9 +220,6 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
component->SetParent( m_frame->GetCurrentSheet().LastScreen() );
component->SetFlags( IS_NEW | IS_MOVED );
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
m_frame->SaveCopyForRepeatItem( component );
m_view->ClearPreview();
@ -237,6 +234,10 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
SCH_COMPONENT* next_comp = nullptr;
m_view->ClearPreview();
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), component, false );
EE_SELECTION new_sel;
@ -273,9 +274,6 @@ int SCH_DRAWING_TOOLS::PlaceComponent( const TOOL_EVENT& aEvent )
next_comp->SetUnit( new_unit );
next_comp->SetUnitSelection( new_unit );
if( m_frame->eeconfig()->m_AutoplaceFields.enable )
component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );
m_frame->SaveCopyForRepeatItem( next_comp );
m_view->AddToPreview( next_comp->Clone() );
m_selectionTool->AddItemToSel( next_comp );