From 2312cf34c4d0673ca7c36fb0509f36e084007bc4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 25 Jan 2023 18:33:31 +0000 Subject: [PATCH] Pay attention to knockout text when adding to DRC Rtrees. --- pcbnew/fp_text.cpp | 25 +++++++++++++++++++++---- pcbnew/pcb_text.cpp | 26 ++++++++++++++++++++++---- pcbnew/pcb_text.h | 3 +-- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/pcbnew/fp_text.cpp b/pcbnew/fp_text.cpp index 5caef0bf68..65a0df7172 100644 --- a/pcbnew/fp_text.cpp +++ b/pcbnew/fp_text.cpp @@ -436,6 +436,25 @@ wxString FP_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const std::shared_ptr FP_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const { + if( IsKnockout() ) + { + SHAPE_POLY_SET knockouts; + + TransformTextToPolySet( knockouts, aLayer, 0, GetBoard()->GetDesignSettings().m_MaxError, + ERROR_INSIDE ); + + SHAPE_POLY_SET finalPoly; + int strokeWidth = GetEffectiveTextPenWidth(); + VECTOR2I fontSize = GetTextSize(); + int margin = strokeWidth * 1.5 + GetKnockoutTextMargin( fontSize, strokeWidth ); + + TransformBoundingBoxToPolygon( &finalPoly, margin ); + finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST ); + finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST ); + + return std::make_shared( finalPoly ); + } + return GetEffectiveTextShape(); } @@ -447,10 +466,8 @@ void FP_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLay KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); - // Note: this function is mainly used in 3D viewer. - // the polygonal shape of a text can have many basic shapes, - // so combining these shapes can be very useful to create a final shape - // swith a lot less vertices to speedup calculations using this final shape + // The polygonal shape of a text can have many basic shapes, so combining these shapes can + // be very useful to create a final shape with a lot less vertices to speedup calculations. // Simplify shapes is not usually always efficient, but in this case it is. SHAPE_POLY_SET buffer; diff --git a/pcbnew/pcb_text.cpp b/pcbnew/pcb_text.cpp index 437108523f..0c3d4b8403 100644 --- a/pcbnew/pcb_text.cpp +++ b/pcbnew/pcb_text.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -264,6 +265,25 @@ void PCB_TEXT::swapData( BOARD_ITEM* aImage ) std::shared_ptr PCB_TEXT::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const { + if( IsKnockout() ) + { + SHAPE_POLY_SET knockouts; + + TransformTextToPolySet( knockouts, aLayer, 0, GetBoard()->GetDesignSettings().m_MaxError, + ERROR_INSIDE ); + + SHAPE_POLY_SET finalPoly; + int strokeWidth = GetEffectiveTextPenWidth(); + VECTOR2I fontSize = GetTextSize(); + int margin = strokeWidth * 1.5 + GetKnockoutTextMargin( fontSize, strokeWidth ); + + TransformBoundingBoxToPolygon( &finalPoly, margin ); + finalPoly.BooleanSubtract( knockouts, SHAPE_POLY_SET::PM_FAST ); + finalPoly.Fracture( SHAPE_POLY_SET::PM_FAST ); + + return std::make_shared( finalPoly ); + } + return GetEffectiveTextShape(); } @@ -275,10 +295,8 @@ void PCB_TEXT::TransformTextToPolySet( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLa KIFONT::FONT* font = getDrawFont(); int penWidth = GetEffectiveTextPenWidth(); - // Note: this function is mainly used in 3D viewer. - // the polygonal shape of a text can have many basic shapes, - // so combining these shapes can be very useful to create a final shape - // swith a lot less vertices to speedup calculations using this final shape + // The polygonal shape of a text can have many basic shapes, so combining these shapes can + // be very useful to create a final shape with a lot less vertices to speedup calculations. // Simplify shapes is not usually always efficient, but in this case it is. SHAPE_POLY_SET buffer; diff --git a/pcbnew/pcb_text.h b/pcbnew/pcb_text.h index 9eac7485d7..0e363852dd 100644 --- a/pcbnew/pcb_text.h +++ b/pcbnew/pcb_text.h @@ -117,8 +117,7 @@ public: /** * Function TransformTextToPolySet * Convert the text to a polygonSet describing the actual character strokes (one per segment). - * Used in 3D viewer - * Circles and arcs are approximated by segments + * Circles and arcs are approximated by segments. * @aBuffer = SHAPE_POLY_SET to store the polygon corners * @aClearance = the clearance around the text * @aError = the maximum error to allow when approximating curves