More gracefully handle tinyspline not liking a spline definition

Partial fix for #6634
This commit is contained in:
Marek Roszko 2021-03-24 00:29:00 -04:00
parent d430fae05d
commit e409b04538
5 changed files with 32 additions and 14 deletions

View File

@ -186,7 +186,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;
@ -1311,8 +1311,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 )
@ -1321,11 +1319,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

@ -232,7 +232,7 @@ private:
std::string m_codePage; // The code page, not used here
bool m_importAsFPShapes; // Use footprint items instead of board items when true.
// true when the items are imported in the footprint editor
std::string m_messages; // messages generated during dxf file parsing.
wxString m_messages; // messages generated during dxf file parsing.
// Each message ends by '\n'
DXF2BRD_ENTITY_DATA m_curr_entity; // the current entity parameters when parsing a DXF entity
@ -336,14 +336,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

@ -119,7 +119,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

@ -84,7 +84,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'
};