diff --git a/utils/kicad2step/pcb/base.cpp b/utils/kicad2step/pcb/base.cpp index e7c6e7b128..a173a3d604 100644 --- a/utils/kicad2step/pcb/base.cpp +++ b/utils/kicad2step/pcb/base.cpp @@ -31,6 +31,20 @@ static const char bad_position[] = "* corrupt module in PCB file; invalid position"; +std::ostream& operator<<( std::ostream& aStream, const DOUBLET& aDoublet ) +{ + aStream << aDoublet.x << "," << aDoublet.y; + return aStream; +} + + +std::ostream& operator<<( std::ostream& aStream, const TRIPLET& aTriplet ) +{ + aStream << aTriplet.x << "," << aTriplet.y << "," << aTriplet.z; + return aStream; +} + + bool Get2DPositionAndRotation( SEXPR::SEXPR* data, DOUBLET& aPosition, double& aRotation ) { // form: (at X Y {rot}) diff --git a/utils/kicad2step/pcb/base.h b/utils/kicad2step/pcb/base.h index 39d9aacdad..6d5f5c3c8c 100644 --- a/utils/kicad2step/pcb/base.h +++ b/utils/kicad2step/pcb/base.h @@ -66,6 +66,8 @@ struct DOUBLET DOUBLET( double aX, double aY ) : x( aX ), y( aY ) { return; } }; +std::ostream& operator<<( std::ostream& aStream, const DOUBLET& aDoublet ); + struct TRIPLET { double x; @@ -81,6 +83,8 @@ struct TRIPLET TRIPLET( double aX, double aY, double aZ ) : x( aX ), y( aY ), z( aZ ) { return; } }; +std::ostream& operator<<( std::ostream& aStream, const TRIPLET& aTriplet ); + bool Get2DPositionAndRotation( SEXPR::SEXPR* data, DOUBLET& aPosition, double& aRotation ); bool Get2DCoordinate( SEXPR::SEXPR* data, DOUBLET& aCoordinate ); bool Get3DCoordinate( SEXPR::SEXPR* data, TRIPLET& aCoordinate ); diff --git a/utils/kicad2step/pcb/kicadcurve.cpp b/utils/kicad2step/pcb/kicadcurve.cpp index 8e4ac0cd1c..991e15820b 100644 --- a/utils/kicad2step/pcb/kicadcurve.cpp +++ b/utils/kicad2step/pcb/kicadcurve.cpp @@ -134,3 +134,28 @@ bool KICADCURVE::Read( SEXPR::SEXPR* aEntry, CURVE_TYPE aCurveType ) return true; } + + +std::string KICADCURVE::Describe() const +{ + std::ostringstream desc; + + switch( m_form ) + { + case CURVE_LINE: + desc << "line start: " << m_start << " end: " << m_end; + break; + case CURVE_ARC: + desc << "arc center: " << m_start << " radius: " << m_radius + << " angle: " << 180.0 * m_angle / M_PI; + break; + case CURVE_CIRCLE: + desc << "circle center: " << m_start << " radius: " << m_radius; + break; + default: + desc << ""; + break; + } + + return desc.str(); +} diff --git a/utils/kicad2step/pcb/kicadcurve.h b/utils/kicad2step/pcb/kicadcurve.h index fea34a2400..c81fa9b287 100644 --- a/utils/kicad2step/pcb/kicadcurve.h +++ b/utils/kicad2step/pcb/kicadcurve.h @@ -47,6 +47,9 @@ public: return m_layer; } + ///> Returns human-readable description of the curve. + std::string Describe() const; + CURVE_TYPE m_form; // form of curve: line, arc, circle LAYERS m_layer; // layer of the glyph DOUBLET m_start; // start point of line or center for arc and circle diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp index 860243e9f3..d5603a6b44 100644 --- a/utils/kicad2step/pcb/oce_utils.cpp +++ b/utils/kicad2step/pcb/oce_utils.cpp @@ -68,6 +68,8 @@ #include #include +#include + #include #include #include @@ -256,7 +258,7 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) #ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; #endif /* __WXDEBUG */ - ostr << " * rejected a zero-length line\n"; + ostr << " * rejected a zero-length " << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; } @@ -275,7 +277,7 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) #ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; #endif /* __WXDEBUG */ - ostr << " * rejected a zero-radius arc or circle\n"; + ostr << " * rejected a zero-radius " << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; } @@ -315,7 +317,8 @@ bool PCBMODEL::AddOutlineSegment( KICADCURVE* aCurve ) #ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; #endif /* __WXDEBUG */ - ostr << " * rejected an arc with equivalent end points\n"; + ostr << " * rejected an arc with equivalent end points, " + << aCurve->Describe() << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; } @@ -748,6 +751,10 @@ bool PCBMODEL::CreatePCB() ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; #endif /* __WXDEBUG */ ostr << " * could not close outline (dropping outline data with " << oln.m_curves.size() << " segments)\n"; + + for( const auto& c : oln.m_curves ) + ostr << " + " << c.Describe() << "\n"; + wxLogMessage( "%s", ostr.str().c_str() ); oln.Clear(); @@ -1392,13 +1399,28 @@ bool OUTLINE::MakeShape( TopoDS_Shape& aShape, double aThickness ) for( auto i : m_curves ) { - if( !addEdge( &wire, i, lastPoint ) ) + bool success = false; + + try + { + success = addEdge( &wire, i, lastPoint ); + } + catch( const Standard_Failure& e ) + { +#ifdef __WXDEBUG__ + wxLogMessage( "Exception caught: %s", e.GetMessageString() ); +#endif /* __WXDEBUG */ + success = false; + } + + if( !success ) { std::ostringstream ostr; #ifdef __WXDEBUG__ ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; #endif /* __WXDEBUG */ - ostr << " * failed to add an edge\n"; + ostr << " * failed to add an edge: " << i.Describe() << "\n"; + ostr << " * last valid outline point: " << lastPoint << "\n"; wxLogMessage( "%s", ostr.str().c_str() ); return false; } @@ -1437,7 +1459,6 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL break; case CURVE_ARC: - do { gp_Circ arc( gp_Ax2( gp_Pnt( aCurve.m_start.x, aCurve.m_start.y, 0.0 ), gp_Dir( 0.0, 0.0, 1.0 ) ), aCurve.m_radius ); @@ -1449,8 +1470,7 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL edge = BRepBuilderAPI_MakeEdge( arc, ea, sa ); else edge = BRepBuilderAPI_MakeEdge( arc, sa, ea ); - - } while( 0 ); + } break; case CURVE_CIRCLE: @@ -1459,7 +1479,6 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL break; default: - do { std::ostringstream ostr; #ifdef __WXDEBUG__ @@ -1469,7 +1488,7 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL wxLogMessage( "%s", ostr.str().c_str() ); return false; - } while( 0 ); + } } if( edge.IsNull() )