More gracefully handle tinyspline not liking a spline definition

Partial fix for #6634

(cherry picked from commit e409b04538)
This commit is contained in:
Marek Roszko 2021-03-24 00:29:00 -04:00 committed by Seth Hillbrand
parent b76c5c9433
commit 82f2e8c344
5 changed files with 31 additions and 13 deletions

View File

@ -161,7 +161,7 @@ bool DXF_IMPORT_PLUGIN::ImportDxfFile( const wxString& aFile )
}
void DXF_IMPORT_PLUGIN::reportMsg( const char* aMessage )
void DXF_IMPORT_PLUGIN::reportMsg( const wxString& aMessage )
{
// Add message to keep trace of not handled dxf entities
m_messages += aMessage;
@ -1050,8 +1050,6 @@ void DXF_IMPORT_PLUGIN::insertSpline( int aWidth )
}
}
#else // Use bezier curves, supported by pcbnew, to approximate the spline
tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(),
/* coord dim */ 2, m_curr_entity.m_SplineDegree );
std::vector<double> ctrlp;
for( unsigned ii = 0; ii < imax; ++ii )
@ -1060,11 +1058,31 @@ void DXF_IMPORT_PLUGIN::insertSpline( int aWidth )
ctrlp.push_back( m_curr_entity.m_SplineControlPointList[ii].m_y );
}
dxfspline.setCtrlp( ctrlp );
dxfspline.setKnots( m_curr_entity.m_SplineKnotsList );
tinyspline::BSpline beziers( dxfspline.toBeziers() );
std::vector<double> coords;
try
{
tinyspline::BSpline dxfspline( m_curr_entity.m_SplineControlPointList.size(),
/* coord dim */ 2, m_curr_entity.m_SplineDegree );
std::vector<double> coords = beziers.ctrlp();
dxfspline.setCtrlp( ctrlp );
dxfspline.setKnots( m_curr_entity.m_SplineKnotsList );
tinyspline::BSpline beziers( dxfspline.toBeziers() );
coords = beziers.ctrlp();
}
catch( const std::runtime_error& ) //tinyspline throws everything including data validation as runtime errors
{
// invalid spline definition, drop this block
reportMsg( _( "Invalid spline definition encountered" ) );
return;
}
if( coords.size() % 8 != 0 )
{
// somehow we generated a bad Bezier curve
reportMsg( _( "Invalid Bezier curve created" ) );
return;
}
// Each Bezier curve uses 4 vertices (a start point, 2 control points and a end point).
// So we can have more than one Bezier curve ( there are one curve each four vertices)

View File

@ -217,14 +217,14 @@ public:
/**
* @return the list of messages in one string. Each message ends by '\n'
*/
const std::string& GetMessages() const override
const wxString& GetMessages() const override
{
return m_messages;
}
private:
// report message to keep trace of not supported dxf entities:
void reportMsg( const char* aMessage );
void reportMsg( const wxString& aMessage );
// coordinate conversions from dxf file to mm
double mapX( double aDxfCoordX );

View File

@ -118,7 +118,7 @@ public:
*
* @return the list of messages in one string. Each message ends by '\n'
*/
const virtual std::string& GetMessages() const = 0;
const virtual wxString& GetMessages() const = 0;
protected:
///> Importer used to create objects representing the imported shapes.

View File

@ -83,7 +83,7 @@ public:
*
* @return the list of messages in one string. Each message ends by '\n'
*/
const std::string& GetMessages() const
const wxString& GetMessages() const
{
return m_plugin->GetMessages();
}

View File

@ -52,7 +52,7 @@ public:
/**
* @return the list of messages in one string. Each message ends by '\n'
*/
const std::string& GetMessages() const override
const wxString& GetMessages() const override
{
return m_messages;
}
@ -77,7 +77,7 @@ private:
struct NSVGimage* m_parsedImage;
std::string m_messages; // messages generated during svg file parsing.
wxString m_messages; // messages generated during svg file parsing.
// Each message ends by '\n'
};