diff --git a/common/jobs/job_export_pcb_3d.cpp b/common/jobs/job_export_pcb_3d.cpp index 03436148a3..1cb70d0443 100644 --- a/common/jobs/job_export_pcb_3d.cpp +++ b/common/jobs/job_export_pcb_3d.cpp @@ -25,6 +25,7 @@ NLOHMANN_JSON_SERIALIZE_ENUM( JOB_EXPORT_PCB_3D::FORMAT, { { JOB_EXPORT_PCB_3D::FORMAT::UNKNOWN, nullptr }, + { JOB_EXPORT_PCB_3D::FORMAT::STEPZ, "stpz" }, { JOB_EXPORT_PCB_3D::FORMAT::STEP, "step" }, { JOB_EXPORT_PCB_3D::FORMAT::BREP, "brep" }, { JOB_EXPORT_PCB_3D::FORMAT::GLB, "step" }, @@ -47,6 +48,7 @@ wxString EXPORTER_STEP_PARAMS::GetDefaultExportExtension() const switch( m_Format ) { case EXPORTER_STEP_PARAMS::FORMAT::STEP: return wxS( "step" ); + case EXPORTER_STEP_PARAMS::FORMAT::STEPZ: return wxS( "stpz" ); case EXPORTER_STEP_PARAMS::FORMAT::BREP: return wxS( "brep" ); case EXPORTER_STEP_PARAMS::FORMAT::XAO: return wxS( "xao" ); case EXPORTER_STEP_PARAMS::FORMAT::GLB: return wxS( "glb" ); @@ -63,6 +65,7 @@ wxString EXPORTER_STEP_PARAMS::GetFormatName() const { // honestly these names shouldn't be translated since they are mostly industry standard acronyms case EXPORTER_STEP_PARAMS::FORMAT::STEP: return wxS( "STEP" ); + case EXPORTER_STEP_PARAMS::FORMAT::STEPZ: return wxS( "STPZ" ); case EXPORTER_STEP_PARAMS::FORMAT::BREP: return wxS( "BREP" ); case EXPORTER_STEP_PARAMS::FORMAT::XAO: return wxS( "XAO" ); case EXPORTER_STEP_PARAMS::FORMAT::GLB: return wxS( "Binary GLTF" ); @@ -159,6 +162,7 @@ void JOB_EXPORT_PCB_3D::SetStepFormat( EXPORTER_STEP_PARAMS::FORMAT aFormat ) switch( m_3dparams.m_Format ) { case EXPORTER_STEP_PARAMS::FORMAT::STEP: m_format = JOB_EXPORT_PCB_3D::FORMAT::STEP; break; + case EXPORTER_STEP_PARAMS::FORMAT::STEPZ: m_format = JOB_EXPORT_PCB_3D::FORMAT::STEPZ; break; case EXPORTER_STEP_PARAMS::FORMAT::GLB: m_format = JOB_EXPORT_PCB_3D::FORMAT::GLB; break; case EXPORTER_STEP_PARAMS::FORMAT::XAO: m_format = JOB_EXPORT_PCB_3D::FORMAT::XAO; break; case EXPORTER_STEP_PARAMS::FORMAT::BREP: m_format = JOB_EXPORT_PCB_3D::FORMAT::BREP; break; diff --git a/common/jobs/job_export_pcb_3d.h b/common/jobs/job_export_pcb_3d.h index a00427ecf6..756a385901 100644 --- a/common/jobs/job_export_pcb_3d.h +++ b/common/jobs/job_export_pcb_3d.h @@ -63,6 +63,7 @@ public: enum class FORMAT { STEP, + STEPZ, BREP, XAO, GLB, @@ -118,6 +119,7 @@ public: { UNKNOWN, // defefer to arg STEP, + STEPZ, BREP, XAO, GLB, diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index dde0de41d8..1c0b1d20a1 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -204,6 +204,7 @@ const std::string FILEEXT::JsonFileExtension( "json" ); const std::string FILEEXT::PythonFileExtension( "py" ); const std::string FILEEXT::StepFileExtension( "step" ); +const std::string FILEEXT::StepZFileAbrvExtension( "stpz" ); const std::string FILEEXT::StepFileAbrvExtension( "stp" ); const std::string FILEEXT::GltfBinaryFileExtension( "glb" ); const std::string FILEEXT::BrepFileExtension( "brep" ); diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 7a42ae637a..2ffe5deaf9 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -193,6 +193,7 @@ public: static const std::string PythonFileExtension; static const std::string StepFileExtension; + static const std::string StepZFileAbrvExtension; static const std::string StepFileAbrvExtension; static const std::string GltfBinaryFileExtension; static const std::string BrepFileExtension; diff --git a/kicad/cli/command_pcb_export_3d.cpp b/kicad/cli/command_pcb_export_3d.cpp index 2bcd5cd42a..1ef8f8f3e4 100644 --- a/kicad/cli/command_pcb_export_3d.cpp +++ b/kicad/cli/command_pcb_export_3d.cpp @@ -75,7 +75,7 @@ CLI::PCB_EXPORT_3D_COMMAND::PCB_EXPORT_3D_COMMAND( const std::string& aNa { m_argParser.add_argument( ARG_FORMAT ) .default_value( std::string( "step" ) ) - .help( UTF8STDSTR( _( "Output file format, options: step, brep, xao, glb " + .help( UTF8STDSTR( _( "Output file format, options: step, stepz, brep, xao, glb " "(binary glTF), ply, stl" ) ) ); } @@ -258,6 +258,8 @@ int CLI::PCB_EXPORT_3D_COMMAND::doPerform( KIWAY& aKiway ) if( format == wxS( "step" ) ) step->m_format = JOB_EXPORT_PCB_3D::FORMAT::STEP; + else if( format == wxS( "stpz" ) ) + step->m_format = JOB_EXPORT_PCB_3D::FORMAT::STEPZ; else if( format == wxS( "brep" ) ) step->m_format = JOB_EXPORT_PCB_3D::FORMAT::BREP; else if( format == wxS( "xao" ) ) diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index 81c71ed1f4..e8584ffee8 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -126,6 +126,7 @@ static CLI::PCB_EXPORT_3D_COMMAND exportPcbXaoCmd{ "xao", UTF8STDSTR( _( static CLI::PCB_EXPORT_3D_COMMAND exportPcbVrmlCmd{ "vrml", UTF8STDSTR( _( "Export VRML" ) ), JOB_EXPORT_PCB_3D::FORMAT::VRML }; static CLI::PCB_EXPORT_3D_COMMAND exportPcbPlyCmd{ "ply", UTF8STDSTR( _( "Export PLY" ) ), JOB_EXPORT_PCB_3D::FORMAT::PLY }; static CLI::PCB_EXPORT_3D_COMMAND exportPcbStlCmd{ "stl", UTF8STDSTR( _( "Export STL" ) ), JOB_EXPORT_PCB_3D::FORMAT::STL }; +static CLI::PCB_EXPORT_3D_COMMAND exportPcbStepzCmd{ "stpz", UTF8STDSTR( _( "Export STEPZ" ) ), JOB_EXPORT_PCB_3D::FORMAT::STEPZ }; static CLI::PCB_EXPORT_SVG_COMMAND exportPcbSvgCmd{}; static CLI::PCB_EXPORT_PDF_COMMAND exportPcbPdfCmd{}; static CLI::PCB_EXPORT_POS_COMMAND exportPcbPosCmd{}; @@ -215,7 +216,8 @@ static std::vector commandStack = { &exportPcbVrmlCmd, &exportPcbXaoCmd, &exportPcbPlyCmd, - &exportPcbStlCmd + &exportPcbStlCmd, + &exportPcbStepzCmd } } } diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index bb080a6d21..6da0e64649 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -59,7 +59,8 @@ static const std::vector c_formatCommand = { FILEEXT::StepFileExtensio FILEEXT::XaoFileExtension, FILEEXT::BrepFileExtension, FILEEXT::PlyFileExtension, - FILEEXT::StlFileExtension}; + FILEEXT::StlFileExtension, + FILEEXT::StepZFileAbrvExtension }; // Maps file extensions to m_choiceFormat selection static const std::map c_formatExtToChoice = { { FILEEXT::StepFileExtension, 0 }, @@ -68,8 +69,8 @@ static const std::map c_formatExtToChoice = { { FILEEXT::StepFile { FILEEXT::XaoFileExtension, 2 }, { FILEEXT::BrepFileExtension, 3 }, { FILEEXT::PlyFileExtension, 4 }, - { FILEEXT::StlFileExtension, 5 }}; - + { FILEEXT::StlFileExtension, 5 }, + { FILEEXT::StepZFileAbrvExtension, 6 }}; int DIALOG_EXPORT_STEP::m_toleranceLastChoice = -1; // Use default @@ -820,6 +821,7 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent ) switch( m_job->m_3dparams.m_Format ) { case EXPORTER_STEP_PARAMS::FORMAT::STEP: m_job->m_format = JOB_EXPORT_PCB_3D::FORMAT::STEP; break; + case EXPORTER_STEP_PARAMS::FORMAT::STEPZ: m_job->m_format = JOB_EXPORT_PCB_3D::FORMAT::STEPZ; break; case EXPORTER_STEP_PARAMS::FORMAT::GLB: m_job->m_format = JOB_EXPORT_PCB_3D::FORMAT::GLB; break; case EXPORTER_STEP_PARAMS::FORMAT::XAO: m_job->m_format = JOB_EXPORT_PCB_3D::FORMAT::XAO; break; case EXPORTER_STEP_PARAMS::FORMAT::BREP: m_job->m_format = JOB_EXPORT_PCB_3D::FORMAT::BREP; break; diff --git a/pcbnew/dialogs/dialog_export_step_base.cpp b/pcbnew/dialogs/dialog_export_step_base.cpp index a5c78e7092..a9ff23e6e1 100644 --- a/pcbnew/dialogs/dialog_export_step_base.cpp +++ b/pcbnew/dialogs/dialog_export_step_base.cpp @@ -24,7 +24,7 @@ DIALOG_EXPORT_STEP_BASE::DIALOG_EXPORT_STEP_BASE( wxWindow* parent, wxWindowID i m_txtFormat->Wrap( -1 ); bSizerTop->Add( m_txtFormat, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); - wxString m_choiceFormatChoices[] = { _("STEP"), _("GLB (Binary glTF)"), _("XAO"), _("BREP (OCCT)"), _("PLY (ASCII)"), _("STL") }; + wxString m_choiceFormatChoices[] = { _("STEP"), _("GLB (Binary glTF)"), _("XAO"), _("BREP (OCCT)"), _("PLY (ASCII)"), _("STL"), _("STPZ") }; int m_choiceFormatNChoices = sizeof( m_choiceFormatChoices ) / sizeof( wxString ); m_choiceFormat = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceFormatNChoices, m_choiceFormatChoices, 0 ); m_choiceFormat->SetSelection( 0 ); diff --git a/pcbnew/dialogs/dialog_export_step_base.fbp b/pcbnew/dialogs/dialog_export_step_base.fbp index cec6d87dbc..24c9544652 100644 --- a/pcbnew/dialogs/dialog_export_step_base.fbp +++ b/pcbnew/dialogs/dialog_export_step_base.fbp @@ -64,11 +64,11 @@ bSizerSTEPFile wxVERTICAL protected - + 6 wxEXPAND|wxTOP|wxRIGHT|wxLEFT 0 - + bSizerTop wxHORIZONTAL @@ -153,7 +153,7 @@ 1 0 - "STEP" "GLB (Binary glTF)" "XAO" "BREP (OCCT)" "PLY (ASCII)" "STL" + "STEP" "GLB (Binary glTF)" "XAO" "BREP (OCCT)" "PLY (ASCII)" "STL" "STPZ" 1 1 @@ -409,25 +409,25 @@ 5 wxEXPAND 1 - + bSizerMain wxHORIZONTAL none - + 5 wxEXPAND 1 - + bSizer8 wxVERTICAL none - + 5 wxEXPAND|wxALL 0 - + wxID_ANY Board Options @@ -565,11 +565,11 @@ - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -1167,11 +1167,11 @@ - + 5 wxEXPAND|wxALL 0 - + wxID_ANY Conductor Options @@ -1504,11 +1504,11 @@ - + 5 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 1 1 1 @@ -1700,11 +1700,11 @@ - + 5 wxEXPAND 1 - + bSizer5 wxVERTICAL @@ -2399,11 +2399,11 @@ - + 5 wxEXPAND|wxALL 1 - + wxID_ANY Other Options diff --git a/pcbnew/exporters/step/exporter_step.cpp b/pcbnew/exporters/step/exporter_step.cpp index 231afeec12..f95bbec0c2 100644 --- a/pcbnew/exporters/step/exporter_step.cpp +++ b/pcbnew/exporters/step/exporter_step.cpp @@ -661,6 +661,10 @@ void EXPORTER_STEP::initOutputVariant() m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_STEP ); break; + case EXPORTER_STEP_PARAMS::FORMAT::STEPZ: + m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_STEPZ ); + break; + case EXPORTER_STEP_PARAMS::FORMAT::BREP: m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_BREP ); break; @@ -872,7 +876,9 @@ bool EXPORTER_STEP::Export() bool success = true; if( m_params.m_Format == EXPORTER_STEP_PARAMS::FORMAT::STEP ) - success = m_pcbModel->WriteSTEP( m_outputFile, m_params.m_OptimizeStep ); + success = m_pcbModel->WriteSTEP( m_outputFile, m_params.m_OptimizeStep, false ); + else if( m_params.m_Format == EXPORTER_STEP_PARAMS::FORMAT::STEPZ ) + success = m_pcbModel->WriteSTEP( m_outputFile, m_params.m_OptimizeStep, true ); else if( m_params.m_Format == EXPORTER_STEP_PARAMS::FORMAT::BREP ) success = m_pcbModel->WriteBREP( m_outputFile ); else if( m_params.m_Format == EXPORTER_STEP_PARAMS::FORMAT::XAO ) diff --git a/pcbnew/exporters/step/step_pcb_model.cpp b/pcbnew/exporters/step/step_pcb_model.cpp index e71d8a80f8..4edebbd34e 100644 --- a/pcbnew/exporters/step/step_pcb_model.cpp +++ b/pcbnew/exporters/step/step_pcb_model.cpp @@ -28,10 +28,14 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include #include #include #include @@ -2360,8 +2364,46 @@ bool STEP_PCB_MODEL::WriteIGES( const wxString& aFileName ) } #endif +bool STEP_PCB_MODEL::CompressSTEP( wxString& inputFile, wxString& outputFile ) +{ + wxFileInputStream input( inputFile ); + wxFileOutputStream output( outputFile ); -bool STEP_PCB_MODEL::WriteSTEP( const wxString& aFileName, bool aOptimize ) + if( !input.IsOk() ) + { + m_reporter->Report( wxString::Format( _( "Cannot create input stream '%s'.\n" ), inputFile ) ); + return false; + } + + if( !output.IsOk() ) + { + m_reporter->Report( wxString::Format( _( "Cannot create output stream '%s'.\n" ), outputFile ) ); + return false; + } + + wxZlibOutputStream zlibStream( output, -1, wxZLIB_GZIP ); + + if( !zlibStream.IsOk() ) + { + m_reporter->Report( _( "Impossible create compress stream" ) ); + return false; + } + + input.Read( zlibStream ); + + if( input.LastRead() == 0 || zlibStream.LastWrite() == 0 ) + { + m_reporter->Report( _( "Compress read or write error" ) ); + return false; + } + + zlibStream.Close(); + output.Close(); + + return true; +} + +bool STEP_PCB_MODEL::WriteSTEP( const wxString& aFileName, bool aOptimize, bool compress ) { if( !isBoardOutlineValid() ) { @@ -2422,16 +2464,27 @@ bool STEP_PCB_MODEL::WriteSTEP( const wxString& aFileName, bool aOptimize ) if( !workCWD.IsEmpty() ) wxSetWorkingDirectory( workCWD ); - char tmpfname[] = "$tempfile$.step"; + wxString tmpfname( "$tempfile$.step" ); - if( Standard_False == writer.Write( tmpfname ) ) + if( Standard_False == writer.Write( tmpfname.c_str() ) ) success = false; + if( compress && success ) + { + wxString srcTmp( tmpfname ); + wxString dstTmp( "$tempfile$.stpz" ); + + success = STEP_PCB_MODEL::CompressSTEP( srcTmp, dstTmp ); + wxRemoveFile( srcTmp ); + + tmpfname = dstTmp; + } + if( success ) { // Preserve the permissions of the current file - KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), tmpfname ); + KIPLATFORM::IO::DuplicatePermissions( fn.GetFullPath(), tmpfname.c_str() ); if( !wxRenameFile( tmpfname, fn.GetFullName(), true ) ) { @@ -3347,4 +3400,4 @@ bool STEP_PCB_MODEL::WriteSTL( const wxString& aFileName ) wxSetWorkingDirectory( currCWD ); return success; -} \ No newline at end of file +} diff --git a/pcbnew/exporters/step/step_pcb_model.h b/pcbnew/exporters/step/step_pcb_model.h index 7d02b79762..bd6e6c0b5f 100644 --- a/pcbnew/exporters/step/step_pcb_model.h +++ b/pcbnew/exporters/step/step_pcb_model.h @@ -78,6 +78,7 @@ enum class OUTPUT_FORMAT { FMT_OUT_UNKNOWN = 0, FMT_OUT_STEP, + FMT_OUT_STEPZ, FMT_OUT_IGES, FMT_OUT_BREP, FMT_OUT_XAO, @@ -187,7 +188,7 @@ public: #endif // write the assembly model in STEP format - bool WriteSTEP( const wxString& aFileName, bool aOptimize ); + bool WriteSTEP( const wxString& aFileName, bool aOptimize, bool compress ); // write the assembly in BREP format bool WriteBREP( const wxString& aFileName ); @@ -256,6 +257,8 @@ private: TDF_Label transferModel( Handle( TDocStd_Document )& source, Handle( TDocStd_Document ) & dest, VECTOR3D aScale ); + bool CompressSTEP( wxString& inputFile, wxString& outputFile ); + Handle( XCAFApp_Application ) m_app; Handle( TDocStd_Document ) m_doc; Handle( XCAFDoc_ShapeTool ) m_assy; diff --git a/pcbnew/pcbnew_jobs_handler.cpp b/pcbnew/pcbnew_jobs_handler.cpp index 107a3c5949..3f763d627d 100644 --- a/pcbnew/pcbnew_jobs_handler.cpp +++ b/pcbnew/pcbnew_jobs_handler.cpp @@ -542,6 +542,7 @@ int PCBNEW_JOBS_HANDLER::JobExportStep( JOB* aJob ) switch( aStepJob->m_format ) { case JOB_EXPORT_PCB_3D::FORMAT::STEP: params.m_Format = EXPORTER_STEP_PARAMS::FORMAT::STEP; break; + case JOB_EXPORT_PCB_3D::FORMAT::STEPZ: params.m_Format = EXPORTER_STEP_PARAMS::FORMAT::STEPZ; break; case JOB_EXPORT_PCB_3D::FORMAT::BREP: params.m_Format = EXPORTER_STEP_PARAMS::FORMAT::BREP; break; case JOB_EXPORT_PCB_3D::FORMAT::XAO: params.m_Format = EXPORTER_STEP_PARAMS::FORMAT::XAO; break; case JOB_EXPORT_PCB_3D::FORMAT::GLB: params.m_Format = EXPORTER_STEP_PARAMS::FORMAT::GLB; break;