Cleanup API and use text bounding box for routing.

If someone wants to route around the text more tightly
they can now convert the text to polygons.

Fixes https://gitlab.com/kicad/code/kicad/issues/14252
This commit is contained in:
Jeff Young 2023-05-02 16:02:45 +01:00
parent 80f8cd2254
commit f27bc16d62
2 changed files with 18 additions and 49 deletions

View File

@ -1246,66 +1246,35 @@ bool PNS_KICAD_IFACE_BASE::syncZone( PNS::NODE* aWorld, ZONE* aZone, SHAPE_POLY_
}
bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB_LAYER_ID aLayer )
bool PNS_KICAD_IFACE_BASE::syncTextItem( PNS::NODE* aWorld, PCB_TEXT* aText, PCB_LAYER_ID aLayer )
{
if( !IsCopperLayer( aLayer ) )
return false;
std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE;
solid->SetLayer( aLayer );
solid->SetNet( -1 );
solid->SetParent( dynamic_cast<BOARD_ITEM*>( aText ) );
PCB_TEXT* pcb_text = dynamic_cast<PCB_TEXT*>( aText );
if( pcb_text && pcb_text->IsKnockout() )
{
TEXT_ATTRIBUTES attrs = pcb_text->GetAttributes();
SHAPE_POLY_SET buffer;
int margin = attrs.m_StrokeWidth * 1.5
+ GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
pcb_text->TransformBoundingBoxToPolygon( &buffer, margin );
// buffer should contain a single rectangular polygon
SHAPE_SIMPLE* rectShape = new SHAPE_SIMPLE;
for( int ii = 0; ii < buffer.Outline(0).PointCount(); ii++ )
{
VECTOR2I point = buffer.Outline(0).CPoint(ii);
rectShape->Append( point );
}
solid->SetShape( rectShape ); // takes ownership
}
else
{
solid->SetShape( aText->GetEffectiveTextShape()->Clone() );
}
solid->SetParent( aText );
solid->SetShape( shape ); // takes ownership
solid->SetRoutable( false );
TEXT_ATTRIBUTES attrs = aText->GetAttributes();
int margin = KiROUND( attrs.m_StrokeWidth / 2 );
SHAPE_POLY_SET cornerBuffer;
if( aText->IsKnockout() )
margin += attrs.m_StrokeWidth + GetKnockoutTextMargin( attrs.m_Size, attrs.m_StrokeWidth );
aText->TransformBoundingBoxToPolygon( &cornerBuffer, margin );
for( const VECTOR2I& pt : cornerBuffer.Outline( 0 ).CPoints() )
shape->Append( pt );
aWorld->Add( std::move( solid ) );
return true;
/* A coarser (but faster) method:
SHAPE_POLY_SET outline;
SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
aText->TransformBoundingBoxToPolygon( &outline, 0 );
for( auto iter = outline.CIterate( 0 ); iter; iter++ )
shape->Append( *iter );
solid->SetShape( shape );
solid->SetLayer( aLayer );
solid->SetNet( -1 );
solid->SetParent( nullptr );
solid->SetRoutable( false );
aWorld->Add( std::move( solid ) );
return true;
*/
}

View File

@ -31,7 +31,7 @@ class PNS_PCBNEW_DEBUG_DECORATOR;
class BOARD;
class BOARD_COMMIT;
class EDA_TEXT;
class PCB_TEXT;
class PCB_DISPLAY_OPTIONS;
class PCB_TOOL_BASE;
class FOOTPRINT;
@ -96,7 +96,7 @@ protected:
std::unique_ptr<PNS::SEGMENT> syncTrack( PCB_TRACK* aTrack );
std::unique_ptr<PNS::ARC> syncArc( PCB_ARC* aArc );
std::unique_ptr<PNS::VIA> syncVia( PCB_VIA* aVia );
bool syncTextItem( PNS::NODE* aWorld, EDA_TEXT* aText, PCB_LAYER_ID aLayer );
bool syncTextItem( PNS::NODE* aWorld, PCB_TEXT* aText, PCB_LAYER_ID aLayer );
bool syncGraphicalItem( PNS::NODE* aWorld, PCB_SHAPE* aItem );
bool syncZone( PNS::NODE* aWorld, ZONE* aZone, SHAPE_POLY_SET* aBoardOutline );
bool inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedWidth );