STEP exporter: export track segments as thick segments with rounded end using arcs.

They are no longer exported as polygons.
Export time is slightly faster and file sizes slightly smaller.
Track arcs are still exported as polygons.
This commit is contained in:
jean-pierre charras 2023-08-27 19:37:28 +02:00
parent a946f7ab1b
commit 114ff054d3
3 changed files with 75 additions and 22 deletions

View File

@ -293,19 +293,7 @@ bool EXPORTER_STEP::buildTrack3DShape( PCB_TRACK* aTrack, VECTOR2D aOrigin )
{ {
if( aTrack->Type() == PCB_VIA_T ) if( aTrack->Type() == PCB_VIA_T )
{ {
PAD dummy( nullptr ); return m_pcbModel->AddViaShape( static_cast<const PCB_VIA*>( aTrack ), aOrigin );
int hole = static_cast<PCB_VIA*>( aTrack )->GetDrillValue();
dummy.SetDrillSize( VECTOR2I( hole, hole ) );
dummy.SetPosition( aTrack->GetStart() );
dummy.SetSize( VECTOR2I( aTrack->GetWidth(), aTrack->GetWidth() ) );
if( m_pcbModel->AddPadHole( &dummy, aOrigin ) )
{
if( m_pcbModel->AddPadShape( &dummy, aOrigin ) )
return false;
}
return true;
} }
PCB_LAYER_ID pcblayer = aTrack->GetLayer(); PCB_LAYER_ID pcblayer = aTrack->GetLayer();
@ -313,12 +301,17 @@ bool EXPORTER_STEP::buildTrack3DShape( PCB_TRACK* aTrack, VECTOR2D aOrigin )
if( pcblayer != F_Cu && pcblayer != B_Cu ) if( pcblayer != F_Cu && pcblayer != B_Cu )
return false; return false;
int maxError = m_board->GetDesignSettings().m_MaxError; if( aTrack->Type() == PCB_ARC_T )
{
int maxError = m_board->GetDesignSettings().m_MaxError;
if( pcblayer == F_Cu ) if( pcblayer == F_Cu )
aTrack->TransformShapeToPolygon( m_top_copper_shapes, pcblayer, 0, maxError, ERROR_INSIDE ); aTrack->TransformShapeToPolygon( m_top_copper_shapes, pcblayer, 0, maxError, ERROR_INSIDE );
else
aTrack->TransformShapeToPolygon( m_bottom_copper_shapes, pcblayer, 0, maxError, ERROR_INSIDE );
}
else else
aTrack->TransformShapeToPolygon( m_bottom_copper_shapes, pcblayer, 0, maxError, ERROR_INSIDE ); m_pcbModel->AddTrackSegment( aTrack, aOrigin );
return true; return true;
} }

View File

@ -38,6 +38,7 @@
#include <footprint.h> #include <footprint.h>
#include <pad.h> #include <pad.h>
#include <pcb_track.h>
#include <kiplatform/io.h> #include <kiplatform/io.h>
#include <string_utils.h> #include <string_utils.h>
#include <build_version.h> #include <build_version.h>
@ -256,6 +257,47 @@ bool STEP_PCB_MODEL::AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin )
} }
bool STEP_PCB_MODEL::AddViaShape( const PCB_VIA* aVia, const VECTOR2D& aOrigin )
{
// A via is very similar to a round pad. So, for now, used AddPadHole() to
// create a via+hole shape
PAD dummy( nullptr );
int hole = aVia->GetDrillValue();
dummy.SetDrillSize( VECTOR2I( hole, hole ) );
dummy.SetPosition( aVia->GetStart() );
dummy.SetSize( VECTOR2I( aVia->GetWidth(), aVia->GetWidth() ) );
if( AddPadHole( &dummy, aOrigin ) )
{
if( !AddPadShape( &dummy, aOrigin ) )
return false;
}
return true;
}
bool STEP_PCB_MODEL::AddTrackSegment( const PCB_TRACK* aTrack, const VECTOR2D& aOrigin )
{
PCB_LAYER_ID pcblayer = aTrack->GetLayer();
if( pcblayer != F_Cu && pcblayer != B_Cu )
return false;
TopoDS_Shape shape;
double zposition = pcblayer == F_Cu ? m_boardThickness : -m_copperThickness;
bool success = MakeShapeAsThickSegment( shape, aTrack->GetStart(), aTrack->GetEnd(),
aTrack->GetWidth(), m_copperThickness,
zposition, aOrigin );
if( success )
m_board_copper_tracks.push_back( shape );
return success;
}
bool STEP_PCB_MODEL::AddCopperPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, bool aOnTop, bool STEP_PCB_MODEL::AddCopperPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, bool aOnTop,
const VECTOR2D& aOrigin, bool aTrack ) const VECTOR2D& aOrigin, bool aTrack )
{ {
@ -549,11 +591,20 @@ bool STEP_PCB_MODEL::MakeShapeAsThickSegment( TopoDS_Shape& aShape,
BRepBuilderAPI_MakeWire wire; BRepBuilderAPI_MakeWire wire;
bool success = true; bool success = true;
// Short segments (distance between end points < m_mergeOCCMaxDist(in mm)) must be
// skipped because OCC merge end points, and a null shape is created
bool short_seg = pcbIUScale.IUTomm( len ) <= m_mergeOCCMaxDist;
try try
{ {
TopoDS_Edge edge; TopoDS_Edge edge;
edge = BRepBuilderAPI_MakeEdge( coords3D[0], coords3D[1] );
wire.Add( edge );
if( !short_seg ) // Do not export a too short segment
{
edge = BRepBuilderAPI_MakeEdge( coords3D[0], coords3D[1] );
wire.Add( edge );
}
Handle(Geom_TrimmedCurve) arcOfCircle = GC_MakeArcOfCircle( coords3D[1], // start point Handle(Geom_TrimmedCurve) arcOfCircle = GC_MakeArcOfCircle( coords3D[1], // start point
coords3D[2], // aux point coords3D[2], // aux point
@ -562,8 +613,11 @@ bool STEP_PCB_MODEL::MakeShapeAsThickSegment( TopoDS_Shape& aShape,
edge = BRepBuilderAPI_MakeEdge( arcOfCircle ); edge = BRepBuilderAPI_MakeEdge( arcOfCircle );
wire.Add( edge ); wire.Add( edge );
edge = BRepBuilderAPI_MakeEdge( coords3D[3], coords3D[4] ); if( !short_seg ) // Do not export a too short segment
wire.Add( edge ); {
edge = BRepBuilderAPI_MakeEdge( coords3D[3], coords3D[4] );
wire.Add( edge );
}
Handle(Geom_TrimmedCurve) arcOfCircle2 = GC_MakeArcOfCircle( coords3D[4], // start point Handle(Geom_TrimmedCurve) arcOfCircle2 = GC_MakeArcOfCircle( coords3D[4], // start point
coords3D[5], // aux point coords3D[5], // aux point

View File

@ -83,9 +83,15 @@ public:
// add a pad hole or slot (must be in final position) // add a pad hole or slot (must be in final position)
bool AddPadHole( const PAD* aPad, const VECTOR2D& aOrigin ); bool AddPadHole( const PAD* aPad, const VECTOR2D& aOrigin );
// add a pad/via shape (must be in final position) // add a pad shape (must be in final position)
bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin ); bool AddPadShape( const PAD* aPad, const VECTOR2D& aOrigin );
// add a via shape
bool AddViaShape( const PCB_VIA* aVia, const VECTOR2D& aOrigin );
// add a track segment shape (do not use it for track arcs)
bool AddTrackSegment( const PCB_TRACK* aTrack, const VECTOR2D& aOrigin );
// add a set of polygons (must be in final position) on top or bottom of the board as copper // add a set of polygons (must be in final position) on top or bottom of the board as copper
bool AddCopperPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, bool aOnTop, bool AddCopperPolygonShapes( const SHAPE_POLY_SET* aPolyShapes, bool aOnTop,
const VECTOR2D& aOrigin, bool aTrack ); const VECTOR2D& aOrigin, bool aTrack );