FIX: add parameter to GAL::DrawCurve to control the curve to polyline conversion. Cairo supports curves, but not Opengl, that needs a conversion to polyline. This control allows optimization in conversion

This commit is contained in:
jean-pierre charras 2019-11-09 11:37:49 +01:00
parent 943858fd67
commit 01553a6bd1
7 changed files with 20 additions and 8 deletions

View File

@ -59,7 +59,7 @@ void BEZIER_POLY::GetPoly( std::vector<VECTOR2D>& aOutput, double aMinSegLen )
aOutput.clear(); aOutput.clear();
aOutput.push_back( m_ctrlPts[0] ); aOutput.push_back( m_ctrlPts[0] );
// If the Bezier curve is degenerated (straight line), skip that: // If the Bezier curve is degenerated (straight line), skip intermediate points:
bool degenerated = m_ctrlPts[0] == m_ctrlPts[1] && m_ctrlPts[2] == m_ctrlPts[3]; bool degenerated = m_ctrlPts[0] == m_ctrlPts[1] && m_ctrlPts[2] == m_ctrlPts[3];
if( !degenerated ) if( !degenerated )

View File

@ -424,8 +424,11 @@ void CAIRO_GAL_BASE::DrawPolygon( const SHAPE_LINE_CHAIN& aPolygon )
void CAIRO_GAL_BASE::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControlPointA, void CAIRO_GAL_BASE::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControlPointA,
const VECTOR2D& aControlPointB, const VECTOR2D& aEndPoint ) const VECTOR2D& aControlPointB, const VECTOR2D& aEndPoint,
double aFilterValue )
{ {
// Note: aFilterValue is not used because the cubic Bezier curve is
// supported by Cairo.
syncLineWidth(); syncLineWidth();
const auto sp = roundp( xform( aStartPoint ) ); const auto sp = roundp( xform( aStartPoint ) );

View File

@ -1034,7 +1034,8 @@ void OPENGL_GAL::DrawPolygon( const SHAPE_LINE_CHAIN& aPolygon )
void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControlPointA, void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aControlPointA,
const VECTOR2D& aControlPointB, const VECTOR2D& aEndPoint ) const VECTOR2D& aControlPointB, const VECTOR2D& aEndPoint,
double aFilterValue )
{ {
std::vector<VECTOR2D> output; std::vector<VECTOR2D> output;
std::vector<VECTOR2D> pointCtrl; std::vector<VECTOR2D> pointCtrl;
@ -1045,7 +1046,7 @@ void OPENGL_GAL::DrawCurve( const VECTOR2D& aStartPoint, const VECTOR2D& aContro
pointCtrl.push_back( aEndPoint ); pointCtrl.push_back( aEndPoint );
BEZIER_POLY converter( pointCtrl ); BEZIER_POLY converter( pointCtrl );
converter.GetPoly( output, GetLineWidth() ); converter.GetPoly( output, aFilterValue );
DrawPolyline( &output[0], output.size() ); DrawPolyline( &output[0], output.size() );
} }

View File

@ -101,7 +101,8 @@ public:
/// @copydoc GAL::DrawCurve() /// @copydoc GAL::DrawCurve()
virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA, virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA,
const VECTOR2D& controlPointB, const VECTOR2D& endPoint ) override; const VECTOR2D& controlPointB, const VECTOR2D& endPoint,
double aFilterValue = 0.0 ) override;
/// @copydoc GAL::DrawBitmap() /// @copydoc GAL::DrawBitmap()
virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) override; virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) override;

View File

@ -185,9 +185,13 @@ public:
* @param controlPointA is the first control point. * @param controlPointA is the first control point.
* @param controlPointB is the second control point. * @param controlPointB is the second control point.
* @param endPoint is the end point of the spline. * @param endPoint is the end point of the spline.
* @param aFilterValue is used by Bezier to segments approximation, if
* the Bezier curve is not supported and needs a curve to polyline conversion.
* aFilterValue = 0 means no filtering.
*/ */
virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA, virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA,
const VECTOR2D& controlPointB, const VECTOR2D& endPoint ) {}; const VECTOR2D& controlPointB, const VECTOR2D& endPoint,
double aFilterValue = 0.0 ) {};
/** /**
* @brief Draw a bitmap image. * @brief Draw a bitmap image.

View File

@ -139,7 +139,8 @@ public:
/// @copydoc GAL::DrawCurve() /// @copydoc GAL::DrawCurve()
virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA, virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA,
const VECTOR2D& controlPointB, const VECTOR2D& endPoint ) override; const VECTOR2D& controlPointB, const VECTOR2D& endPoint,
double aFilterValue = 0.0 ) override;
/// @copydoc GAL::DrawBitmap() /// @copydoc GAL::DrawBitmap()
virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) override; virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) override;

View File

@ -932,10 +932,12 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
m_gal->SetIsFill( false ); m_gal->SetIsFill( false );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
m_gal->SetLineWidth( thickness ); m_gal->SetLineWidth( thickness );
// Use thickness as filter value to convert the curve to polyline
// when the curve is not supported
m_gal->DrawCurve( VECTOR2D( aSegment->GetStart() ), m_gal->DrawCurve( VECTOR2D( aSegment->GetStart() ),
VECTOR2D( aSegment->GetBezControl1() ), VECTOR2D( aSegment->GetBezControl1() ),
VECTOR2D( aSegment->GetBezControl2() ), VECTOR2D( aSegment->GetBezControl2() ),
VECTOR2D( aSegment->GetEnd() ) ); VECTOR2D( aSegment->GetEnd() ), thickness );
break; break;
case S_LAST: case S_LAST: