From b8dfbe02ad902b1127dcdcf54a872a1023567e0f Mon Sep 17 00:00:00 2001 From: jean-pierre charras <jp.charras@wanadoo.fr> Date: Fri, 7 Oct 2022 18:53:31 +0200 Subject: [PATCH] Fix some issues in STEP exporter --- common/jobs/job_export_step.cpp | 2 +- pcbnew/exporters/step/kicad2step.cpp | 10 +++++++++- pcbnew/exporters/step/pcb/base.h | 1 + pcbnew/exporters/step/pcb/oce_utils.cpp | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/jobs/job_export_step.cpp b/common/jobs/job_export_step.cpp index 1dcdf1ff3f..f2e778a460 100644 --- a/common/jobs/job_export_step.cpp +++ b/common/jobs/job_export_step.cpp @@ -29,6 +29,6 @@ JOB_EXPORT_STEP::JOB_EXPORT_STEP( bool aIsCli ) : JOB( "step", aIsCli ) m_substModels = false; m_xOrigin = 0.0; m_yOrigin = 0.0; - m_minDistance = 0.0; + m_minDistance = 0.01; // 0.01 mm is a good value to connect 2 items of the board outlines m_gui = false; } \ No newline at end of file diff --git a/pcbnew/exporters/step/kicad2step.cpp b/pcbnew/exporters/step/kicad2step.cpp index 732d38b804..ce700a6ffc 100644 --- a/pcbnew/exporters/step/kicad2step.cpp +++ b/pcbnew/exporters/step/kicad2step.cpp @@ -46,6 +46,8 @@ #include <Standard_Version.hxx> +#include <locale_io.h> + #define OCC_VERSION_MIN 0x070500 #if OCC_VERSION_HEX < OCC_VERSION_MIN @@ -240,11 +242,17 @@ int KICAD2STEP::DoRun() return CLI::EXIT_CODES::ERR_INVALID_OUTPUT_CONFLICT; } + LOCALE_IO dummy; + wxString outfile = out_fname.GetFullPath(); KICADPCB pcb( fname.GetName() ); pcb.SetOrigin( m_params.m_xOrigin, m_params.m_yOrigin ); - pcb.SetMinDistance( m_params.m_minDistance ); + // Set the min dist in mm to consider 2 points at the same place + // This is also the tolerance to consider 2 lines or arcs are connected + // A min value (0.001mm) is needed to have closed board outlines + // 0.01 mm is a good value + pcb.SetMinDistance( std::max( m_params.m_minDistance, MIN_ACCEPTABLE_DISTANCE ) ); ReportMessage( wxString::Format( _( "Read file: '%s'\n" ), m_params.m_filename ) ); Message::DefaultMessenger()->RemovePrinters( STANDARD_TYPE( Message_PrinterOStream ) ); diff --git a/pcbnew/exporters/step/pcb/base.h b/pcbnew/exporters/step/pcb/base.h index 7cfa6b1cd4..fd20c64436 100644 --- a/pcbnew/exporters/step/pcb/base.h +++ b/pcbnew/exporters/step/pcb/base.h @@ -36,6 +36,7 @@ ///< Default minimum distance between points to treat them as separate ones (mm) static constexpr double MIN_DISTANCE = 0.01; +static constexpr double MIN_ACCEPTABLE_DISTANCE = 0.001; namespace SEXPR { diff --git a/pcbnew/exporters/step/pcb/oce_utils.cpp b/pcbnew/exporters/step/pcb/oce_utils.cpp index 7005c8ec60..866b7b06b7 100644 --- a/pcbnew/exporters/step/pcb/oce_utils.cpp +++ b/pcbnew/exporters/step/pcb/oce_utils.cpp @@ -678,6 +678,9 @@ void PCBMODEL::SetBoardColor( double r, double g, double b ) void PCBMODEL::SetMinDistance( double aDistance ) { + // Ensure a minimal value (in mm) + aDistance = std::max( aDistance, MIN_ACCEPTABLE_DISTANCE ); + // m_minDistance2 keeps a squared distance value m_minDistance2 = aDistance * aDistance; BRepBuilderAPI::Precision( aDistance );