Be more careful about non-visible elements in fields autoplacer.

Fixes https://gitlab.com/kicad/code/kicad/issues/10774

(cherry picked from commit f241617478)
This commit is contained in:
Jeff Young 2022-02-28 00:17:55 +00:00
parent d20c2fe5c5
commit 6fd898d1b3
2 changed files with 25 additions and 13 deletions

View File

@ -144,14 +144,14 @@ public:
*/ */
void DoAutoplace( bool aManual ) void DoAutoplace( bool aManual )
{ {
bool force_wire_spacing = false; bool forceWireSpacing = false;
SIDE_AND_NPINS sideandpins = chooseSideForFields( aManual ); SIDE_AND_NPINS sideandpins = chooseSideForFields( aManual );
SIDE field_side = sideandpins.side; SIDE field_side = sideandpins.side;
wxPoint fbox_pos = fieldBoxPlacement( sideandpins ); wxPoint fbox_pos = fieldBoxPlacement( sideandpins );
EDA_RECT field_box( fbox_pos, m_fbox_size ); EDA_RECT field_box( fbox_pos, m_fbox_size );
if( aManual ) if( aManual )
force_wire_spacing = fitFieldsBetweenWires( &field_box, field_side ); forceWireSpacing = fitFieldsBetweenWires( &field_box, field_side );
// Move the fields // Move the fields
int last_y_coord = field_box.GetTop(); int last_y_coord = field_box.GetTop();
@ -160,6 +160,9 @@ public:
{ {
SCH_FIELD* field = m_fields[field_idx]; SCH_FIELD* field = m_fields[field_idx];
if( !field->IsVisible() )
continue;
if( m_allow_rejustify ) if( m_allow_rejustify )
{ {
if( sideandpins.pins > 0 ) if( sideandpins.pins > 0 )
@ -175,8 +178,8 @@ public:
} }
} }
wxPoint pos( fieldHorizPlacement( field, field_box ), wxPoint pos( fieldHPlacement( field, field_box ),
fieldVertPlacement( field, field_box, &last_y_coord, !force_wire_spacing ) ); fieldVPlacement( field, field_box, &last_y_coord, !forceWireSpacing ) );
if( m_align_to_grid ) if( m_align_to_grid )
{ {
@ -201,7 +204,15 @@ protected:
int max_field_width = 0; int max_field_width = 0;
int total_height = 0; int total_height = 0;
std::vector<SCH_FIELD*> visibleFields;
for( SCH_FIELD* field : m_fields ) for( SCH_FIELD* field : m_fields )
{
if( field->IsVisible() )
visibleFields.push_back( field );
}
for( SCH_FIELD* field : visibleFields )
{ {
if( m_symbol->GetTransform().y1 ) if( m_symbol->GetTransform().y1 )
field->SetTextAngle( TEXT_ANGLE_VERT ); field->SetTextAngle( TEXT_ANGLE_VERT );
@ -215,7 +226,7 @@ protected:
max_field_width = std::max( max_field_width, field_width ); max_field_width = std::max( max_field_width, field_width );
// Remove interline spacing from field_height for last line. // Remove interline spacing from field_height for last line.
if( field == m_fields[ m_fields.size() - 1 ] ) if( field == visibleFields.back() )
field_height *= 0.62; field_height *= 0.62;
if( !aDynamic ) if( !aDynamic )
@ -322,6 +333,7 @@ protected:
if( item_box.Intersects( aRect ) ) if( item_box.Intersects( aRect ) )
filtered.push_back( item ); filtered.push_back( item );
} }
return filtered; return filtered;
} }
@ -642,7 +654,7 @@ protected:
* *
* @return Correct field horizontal position * @return Correct field horizontal position
*/ */
int fieldHorizPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox ) int fieldHPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox )
{ {
int field_hjust; int field_hjust;
int field_xcoord; int field_xcoord;
@ -677,13 +689,13 @@ protected:
* *
* @param aField - the field to place. * @param aField - the field to place.
* @param aFieldBox - box in which fields will be placed. * @param aFieldBox - box in which fields will be placed.
* @param aPosAccum - pointer to a position accumulator * @param aAccumulatedPosition - pointer to a position accumulator
* @param aDynamic - use dynamic spacing * @param aDynamic - use dynamic spacing
* *
* @return Correct field vertical position * @return Correct field vertical position
*/ */
int fieldVertPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox, int *aPosAccum, int fieldVPlacement( SCH_FIELD *aField, const EDA_RECT &aFieldBox, int *aAccumulatedPosition,
bool aDynamic ) bool aDynamic )
{ {
int field_height; int field_height;
int padding; int padding;
@ -704,9 +716,9 @@ protected:
padding = FIELD_PADDING; padding = FIELD_PADDING;
} }
int placement = *aPosAccum + padding / 2 + field_height / 2; int placement = *aAccumulatedPosition + padding / 2 + field_height / 2;
*aPosAccum += padding + field_height; *aAccumulatedPosition += padding + field_height;
return placement; return placement;
} }

View File

@ -917,10 +917,10 @@ const EDA_RECT LIB_SYMBOL::GetBodyBoundingBox( int aUnit, int aConvert, bool aIn
{ {
const LIB_PIN& pin = static_cast<const LIB_PIN&>( item ); const LIB_PIN& pin = static_cast<const LIB_PIN&>( item );
// Note: the roots of the pins are always inlcuded for symbols that don't have a // Note: the roots of the pins are always included for symbols that don't have a
// well-defined body. // well-defined body.
if( aIncludePins ) if( aIncludePins && pin.IsVisible() )
bbox.Merge( pin.GetBoundingBox( false, true ) ); bbox.Merge( pin.GetBoundingBox( false, true ) );
else else
bbox.Merge( pin.GetPinRoot() ); bbox.Merge( pin.GetPinRoot() );