Gerbview: Polygon shape: store its drawing coordinates to avoid rebuild them.
Previously, draw coordinates (and especially cache triangulation) were rebuild each time the polygon was redraw. They are now cached. This is a significant speed up, especially when a polygon is highlighted.
This commit is contained in:
parent
905a8366c5
commit
a9aae9b3f7
|
@ -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
|
||||
|
|
|
@ -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<VECTOR2I> pts = aItem->m_Polygon.COutline( 0 ).CPoints();
|
||||
if( aItem->m_AbsolutePolygon.OutlineCount() == 0 )
|
||||
{
|
||||
std::vector<VECTOR2I> pts = aItem->m_Polygon.COutline( 0 ).CPoints();
|
||||
|
||||
for( auto& pt : pts )
|
||||
pt = aItem->GetABPosition( pt );
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue