From 93670d2b24de3a5a7c9d4daa1398bfbe7856e82a Mon Sep 17 00:00:00 2001 From: Bobbe Date: Tue, 30 Aug 2022 15:15:54 +0200 Subject: [PATCH] Improve support for .wrz files in vrml exporter, Fix error handling --- pcbnew/exporters/exporter_vrml.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pcbnew/exporters/exporter_vrml.cpp b/pcbnew/exporters/exporter_vrml.cpp index 685c344e45..f5ae7c57ed 100644 --- a/pcbnew/exporters/exporter_vrml.cpp +++ b/pcbnew/exporters/exporter_vrml.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "3d_cache/3d_cache.h" #include "3d_cache/3d_info.h" @@ -1102,13 +1104,40 @@ void EXPORTER_PCB_VRML::ExportVrmlFootprint( FOOTPRINT* aFootprint, std::ostream if( fileExt == wxT( "wrl" ) ) { if( !wxCopyFile( srcFile.GetFullPath(), dstFile.GetFullPath() ) ) + { + ++sM; continue; + } + } + else if( fileExt == wxT( "wrz" ) ) + { + wxFileInputStream input_file_stream( srcFile.GetFullPath() ); + if( !input_file_stream.IsOk() || input_file_stream.GetSize() == wxInvalidSize ) + { + ++sM; + continue; + } + + wxZlibInputStream zlib_input_stream( input_file_stream, wxZLIB_GZIP ); + wxFFileOutputStream output_file_stream( dstFile.GetFullPath() ); + if( !zlib_input_stream.IsOk() || !output_file_stream.IsOk() ) + { + output_file_stream.Close(); + ++sM; + continue; + } + + output_file_stream.Write( zlib_input_stream ); + output_file_stream.Close(); } else { if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, m_ReuseDef, true ) ) + { + ++sM; continue; + } } }