From 73b861287cc0ee0f4c507389e22c8f58a8c6faa5 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 22 May 2018 11:16:32 +0200 Subject: [PATCH] Zipped output and tryfixes for linux and mac build. --- xs/src/libslic3r/Print.cpp | 49 +++++++++++++++------- xs/src/libslic3r/Rasterizer/Rasterizer.cpp | 4 +- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 3127d5fa6..617b487d2 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -12,11 +12,14 @@ #include #include - // For png export of the sliced model #include #include +#include +#include +#include + #include "Rasterizer/Rasterizer.hpp" #include "tbb/parallel_for.h" @@ -1300,11 +1303,26 @@ public: template<> // Implementation for PNG raster output class FilePrinter { + + struct Layer { + Raster first; + std::stringstream second; + + Layer() {} + Layer(const Raster::Resolution& res, const Raster::PixelDim& pd): + first(res, pd) {} + + Layer(const Layer&) = delete; + Layer(Layer&& m): + first(std::move(m.first)), second(std::move(m.second)) {} + }; + // We will save the compressed PNG data into stringstreams which can be done // in parallel. Later we can write every layer to the disk sequentially. - std::vector> layers_rst_; + std::vector layers_rst_; Raster::Resolution res_; Raster::PixelDim pxdim_; + public: inline FilePrinter(unsigned width_px, unsigned height_px, double width_mm, double height_mm, @@ -1355,25 +1373,28 @@ public: inline void save(const std::string& path) { + wxFFileOutputStream zipfile(path + "zippedout.zip"); + + if(!zipfile.IsOk()) { + BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers!"; + } + + wxZipOutputStream zipstream(zipfile); + wxStdOutputStream pngstream(zipstream); + for(unsigned i = 0; i < layers_rst_.size(); i++) { if(layers_rst_[i].second.rdbuf()->in_avail() > 0) { - char lyrnum[6]; std::sprintf(lyrnum, "%.5d", i); - std::string loc = path + "layer" + lyrnum + ".png"; - - std::fstream out(loc, std::fstream::out | std::fstream::binary); - if(out.good()) { - out << layers_rst_[i].second.rdbuf(); - } else { - BOOST_LOG_TRIVIAL(error) << "Can't create file for layer " - << i; - } - - out.close(); + auto zfilename = std::string("layer") + lyrnum + ".png"; + zipstream.PutNextEntry(zfilename); + pngstream << layers_rst_[i].second.rdbuf(); layers_rst_[i].second.str(""); } } + + zipstream.Close(); + zipfile.Close(); } void saveLayer(unsigned lyr, const std::string& path) { diff --git a/xs/src/libslic3r/Rasterizer/Rasterizer.cpp b/xs/src/libslic3r/Rasterizer/Rasterizer.cpp index a7b123d64..f1eee42f5 100644 --- a/xs/src/libslic3r/Rasterizer/Rasterizer.cpp +++ b/xs/src/libslic3r/Rasterizer/Rasterizer.cpp @@ -16,7 +16,9 @@ #include // For png compression -#if defined(WIN32) || defined(__APPLE__ ) +#if !defined(__linux__) || \ + (defined(__linux__) && ((_POSIX_C_SOURCE >= 200112L || \ + _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)) inline char *strerror_r(int errnum, char *buf, size_t buflen) { strerror_s(buf, buflen, errnum); return buf;