From f27bc16d620b7d91ee3badf6b7a9d0a357ea7e09 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 2 May 2023 16:02:45 +0100 Subject: [PATCH] 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 --- pcbnew/router/pns_kicad_iface.cpp | 63 ++++++++----------------------- pcbnew/router/pns_kicad_iface.h | 4 +- 2 files changed, 18 insertions(+), 49 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 65146b11e6..40096cdf87 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -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 solid = std::make_unique(); + SHAPE_SIMPLE* shape = new SHAPE_SIMPLE; solid->SetLayer( aLayer ); solid->SetNet( -1 ); - solid->SetParent( dynamic_cast( aText ) ); - - PCB_TEXT* pcb_text = dynamic_cast( 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; - */ } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index 9ab09ba01e..df384d87a9 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -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 syncTrack( PCB_TRACK* aTrack ); std::unique_ptr syncArc( PCB_ARC* aArc ); std::unique_ptr 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 );