STEP export: fix circles.
This commit is contained in:
parent
83e9d87cde
commit
b8ce97b532
|
@ -86,15 +86,18 @@
|
||||||
#include <TopoDS_Face.hxx>
|
#include <TopoDS_Face.hxx>
|
||||||
#include <TopoDS_Compound.hxx>
|
#include <TopoDS_Compound.hxx>
|
||||||
#include <TopoDS_Builder.hxx>
|
#include <TopoDS_Builder.hxx>
|
||||||
#include <Geom_TrimmedCurve.hxx>
|
|
||||||
#include <Standard_Failure.hxx>
|
#include <Standard_Failure.hxx>
|
||||||
|
|
||||||
|
#include <Geom_Curve.hxx>
|
||||||
|
#include <Geom_BezierCurve.hxx>
|
||||||
|
#include <Geom_TrimmedCurve.hxx>
|
||||||
|
|
||||||
#include <gp_Ax2.hxx>
|
#include <gp_Ax2.hxx>
|
||||||
#include <gp_Circ.hxx>
|
#include <gp_Circ.hxx>
|
||||||
#include <gp_Dir.hxx>
|
#include <gp_Dir.hxx>
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
#include <Geom_BezierCurve.hxx>
|
|
||||||
#include <GC_MakeArcOfCircle.hxx>
|
#include <GC_MakeArcOfCircle.hxx>
|
||||||
|
#include <GC_MakeCircle.hxx>
|
||||||
|
|
||||||
#include <RWGltf_CafWriter.hxx>
|
#include <RWGltf_CafWriter.hxx>
|
||||||
|
|
||||||
|
@ -604,6 +607,12 @@ bool STEP_PCB_MODEL::MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE
|
||||||
SHAPE_POLY_SET simplified = aPolySet;
|
SHAPE_POLY_SET simplified = aPolySet;
|
||||||
simplified.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
simplified.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
||||||
|
|
||||||
|
auto toPoint = [&]( const VECTOR2D& aKiCoords ) -> gp_Pnt
|
||||||
|
{
|
||||||
|
return gp_Pnt( pcbIUScale.IUTomm( aKiCoords.x - aOrigin.x ),
|
||||||
|
-pcbIUScale.IUTomm( aKiCoords.y - aOrigin.y ), aZposition );
|
||||||
|
};
|
||||||
|
|
||||||
for( const SHAPE_POLY_SET::POLYGON& polygon : simplified.CPolygons() )
|
for( const SHAPE_POLY_SET::POLYGON& polygon : simplified.CPolygons() )
|
||||||
{
|
{
|
||||||
auto makeWireFromChain = [&]( BRepLib_MakeWire& aMkWire,
|
auto makeWireFromChain = [&]( BRepLib_MakeWire& aMkWire,
|
||||||
|
@ -616,45 +625,43 @@ bool STEP_PCB_MODEL::MakeShapes( std::vector<TopoDS_Shape>& aShapes, const SHAPE
|
||||||
{
|
{
|
||||||
const SHAPE_ARC& arc = aChain.Arc( 0 );
|
const SHAPE_ARC& arc = aChain.Arc( 0 );
|
||||||
|
|
||||||
std::vector<VECTOR2D> coords = { arc.GetP0(), arc.GetArcMid(), arc.GetP1() };
|
Handle( Geom_Curve ) curve;
|
||||||
std::vector<gp_Pnt> coords3D( coords.size() );
|
|
||||||
|
|
||||||
// Convert to 3D points
|
if( arc.GetCentralAngle() == ANGLE_360 )
|
||||||
for( size_t ii = 0; ii < coords.size(); ii++ )
|
|
||||||
{
|
{
|
||||||
coords3D[ii] = gp_Pnt( pcbIUScale.IUTomm( coords[ii].x - aOrigin.x ),
|
gp_Ax2 axis = gp::XOY();
|
||||||
-pcbIUScale.IUTomm( coords[ii].y - aOrigin.y ),
|
axis.SetLocation( toPoint( arc.GetCenter() ) );
|
||||||
aZposition );
|
|
||||||
|
curve = GC_MakeCircle( axis, pcbIUScale.IUTomm( arc.GetRadius() ) ).Value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curve = GC_MakeArcOfCircle( toPoint( arc.GetP0() ),
|
||||||
|
toPoint( arc.GetArcMid() ),
|
||||||
|
toPoint( arc.GetP1() ) )
|
||||||
|
.Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle( Geom_TrimmedCurve ) arcOfCircle =
|
if( !curve.IsNull() )
|
||||||
GC_MakeArcOfCircle( coords3D[0], // start point
|
|
||||||
coords3D[1], // mid point
|
|
||||||
coords3D[2] // end point
|
|
||||||
);
|
|
||||||
|
|
||||||
aMkWire.Add( BRepBuilderAPI_MakeEdge( arcOfCircle ) );
|
|
||||||
|
|
||||||
if( aMkWire.Error() != BRepLib_WireDone )
|
|
||||||
{
|
{
|
||||||
ReportMessage( wxT( "failed to add curve\n" ) );
|
aMkWire.Add( BRepBuilderAPI_MakeEdge( curve ) );
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
if( aMkWire.Error() != BRepLib_WireDone )
|
||||||
|
{
|
||||||
|
ReportMessage( wxT( "failed to add curve\n" ) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gp_Pnt start = gp_Pnt( pcbIUScale.IUTomm( aChain.CPoint( 0 ).x - aOrigin.x ),
|
gp_Pnt start = toPoint( aChain.CPoint( 0 ) );
|
||||||
-pcbIUScale.IUTomm( aChain.CPoint( 0 ).y - aOrigin.y ),
|
|
||||||
aZposition );
|
|
||||||
|
|
||||||
for( int j = 0; j < aChain.PointCount(); j++ )
|
for( int j = 0; j < aChain.PointCount(); j++ )
|
||||||
{
|
{
|
||||||
int next = ( j + 1 ) % aChain.PointCount();
|
int next = ( j + 1 ) % aChain.PointCount();
|
||||||
|
gp_Pnt end = toPoint( aChain.CPoint( next ) );
|
||||||
gp_Pnt end = gp_Pnt( pcbIUScale.IUTomm( aChain.CPoint( next ).x - aOrigin.x ),
|
|
||||||
-pcbIUScale.IUTomm( aChain.CPoint( next ).y - aOrigin.y ),
|
|
||||||
aZposition );
|
|
||||||
|
|
||||||
// Do not export too short segments: they create broken shape because OCC thinks
|
// Do not export too short segments: they create broken shape because OCC thinks
|
||||||
// start point and end point are at the same place
|
// start point and end point are at the same place
|
||||||
|
|
Loading…
Reference in New Issue