diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 24e7e89e71..cb089a14a4 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -278,6 +278,8 @@ public: * redundancy for these parameters */ + // This polygon is to draw this item (mainly GBR_POLYGON), according to layer parameters + SHAPE_POLY_SET m_AbsolutePolygon; // the polygon to draw, in absolute coordinates private: // These values are used to draw this item, according to gerber layers parameters // Because they can change inside a gerber image, they are stored here diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 874d640df6..e0e13bec61 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -281,30 +281,31 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer ) if( !isFilled ) m_gal->SetLineWidth( m_gerbviewSettings.m_outlineWidth ); - std::vector pts = aItem->m_Polygon.COutline( 0 ).CPoints(); - - for( auto& pt : pts ) - pt = aItem->GetABPosition( pt ); + if( aItem->m_AbsolutePolygon.OutlineCount() == 0 ) + { + std::vector pts = aItem->m_Polygon.COutline( 0 ).CPoints(); + for( auto& pt : pts ) + pt = aItem->GetABPosition( pt ); - SHAPE_POLY_SET absolutePolygon; - SHAPE_LINE_CHAIN chain( pts ); - chain.SetClosed( true ); - absolutePolygon.AddOutline( chain ); + SHAPE_LINE_CHAIN chain( pts ); + chain.SetClosed( true ); + aItem->m_AbsolutePolygon.AddOutline( chain ); + } // Degenerated polygons (having < 3 points) are drawn as lines // to avoid issues in draw polygon functions - if( !isFilled || absolutePolygon.COutline( 0 ).PointCount() < 3 ) - m_gal->DrawPolyline( absolutePolygon.COutline( 0 ) ); + if( !isFilled || aItem->m_AbsolutePolygon.COutline( 0 ).PointCount() < 3 ) + m_gal->DrawPolyline( aItem->m_AbsolutePolygon.COutline( 0 ) ); else { // On Opengl, a not convex filled polygon is usually drawn by using triangles as primitives. // CacheTriangulation() can create basic triangle primitives to draw the polygon solid shape // on Opengl - if( m_gal->IsOpenGlEngine() ) - absolutePolygon.CacheTriangulation(); + if( m_gal->IsOpenGlEngine() && !aItem->m_AbsolutePolygon.IsTriangulationUpToDate() ) + aItem->m_AbsolutePolygon.CacheTriangulation(); - m_gal->DrawPolygon( absolutePolygon ); + m_gal->DrawPolygon( aItem->m_AbsolutePolygon ); } break;