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
|
* 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:
|
private:
|
||||||
// These values are used to draw this item, according to gerber layers parameters
|
// 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
|
// 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 )
|
if( !isFilled )
|
||||||
m_gal->SetLineWidth( m_gerbviewSettings.m_outlineWidth );
|
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 )
|
for( auto& pt : pts )
|
||||||
pt = aItem->GetABPosition( pt );
|
pt = aItem->GetABPosition( pt );
|
||||||
|
|
||||||
|
SHAPE_LINE_CHAIN chain( pts );
|
||||||
SHAPE_POLY_SET absolutePolygon;
|
chain.SetClosed( true );
|
||||||
SHAPE_LINE_CHAIN chain( pts );
|
aItem->m_AbsolutePolygon.AddOutline( chain );
|
||||||
chain.SetClosed( true );
|
}
|
||||||
absolutePolygon.AddOutline( chain );
|
|
||||||
|
|
||||||
// Degenerated polygons (having < 3 points) are drawn as lines
|
// Degenerated polygons (having < 3 points) are drawn as lines
|
||||||
// to avoid issues in draw polygon functions
|
// to avoid issues in draw polygon functions
|
||||||
if( !isFilled || absolutePolygon.COutline( 0 ).PointCount() < 3 )
|
if( !isFilled || aItem->m_AbsolutePolygon.COutline( 0 ).PointCount() < 3 )
|
||||||
m_gal->DrawPolyline( absolutePolygon.COutline( 0 ) );
|
m_gal->DrawPolyline( aItem->m_AbsolutePolygon.COutline( 0 ) );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// On Opengl, a not convex filled polygon is usually drawn by using triangles as primitives.
|
// 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
|
// CacheTriangulation() can create basic triangle primitives to draw the polygon solid shape
|
||||||
// on Opengl
|
// on Opengl
|
||||||
if( m_gal->IsOpenGlEngine() )
|
if( m_gal->IsOpenGlEngine() && !aItem->m_AbsolutePolygon.IsTriangulationUpToDate() )
|
||||||
absolutePolygon.CacheTriangulation();
|
aItem->m_AbsolutePolygon.CacheTriangulation();
|
||||||
|
|
||||||
m_gal->DrawPolygon( absolutePolygon );
|
m_gal->DrawPolygon( aItem->m_AbsolutePolygon );
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue