From 4d6fb52047e80017be3fc28cb49da7860d5a731a Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 18 Sep 2018 19:13:56 +0200 Subject: Removed explicit dependency of wxWidgets from PrintExport.hpp --- xs/src/libslic3r/Print.cpp | 32 +++++++------- xs/src/libslic3r/PrintExport.hpp | 91 +++++++++++++++++++++++++++++++--------- 2 files changed, 87 insertions(+), 36 deletions(-) (limited to 'xs') diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index f8f6537ca..cdc12d2d1 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -1341,22 +1341,22 @@ std::string Print::output_filepath(const std::string &path) const void Print::export_png(const std::string &dirpath) { - size_t idx = 0; - for (PrintObject *obj : m_objects) { - obj->slice(); - this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing..."); - ++ idx; - } - this->set_status(90, "Exporting zipped archive..."); - print_to(*this, - dirpath, - float(m_config.bed_size_x.value), - float(m_config.bed_size_y.value), - int(m_config.pixel_width.value), - int(m_config.pixel_height.value), - float(m_config.exp_time.value), - float(m_config.exp_time_first.value)); - this->set_status(100, "Done."); +// size_t idx = 0; +// for (PrintObject *obj : m_objects) { +// obj->slice(); +// this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing..."); +// ++ idx; +// } +// this->set_status(90, "Exporting zipped archive..."); +// print_to(*this, +// dirpath, +// float(m_config.bed_size_x.value), +// float(m_config.bed_size_y.value), +// int(m_config.pixel_width.value), +// int(m_config.pixel_height.value), +// float(m_config.exp_time.value), +// float(m_config.exp_time_first.value)); +// this->set_status(100, "Done."); } // Returns extruder this eec should be printed with, according to PrintRegion config diff --git a/xs/src/libslic3r/PrintExport.hpp b/xs/src/libslic3r/PrintExport.hpp index 7c3871251..8286b7165 100644 --- a/xs/src/libslic3r/PrintExport.hpp +++ b/xs/src/libslic3r/PrintExport.hpp @@ -7,9 +7,9 @@ #include #include -#include -#include -#include +//#include +//#include +//#include #include @@ -32,7 +32,7 @@ enum class FilePrinterFormat { * different implementations of this class template for each supported format. * */ -template +template class FilePrinter { public: @@ -73,10 +73,35 @@ public: void saveLayer(unsigned lyr, const std::string& path); }; +template struct VeryFalse { static const bool value = false; }; + +// This has to be explicitly implemented in the gui layer or a default zlib +// based implementation is needed. +template class Zipper { +public: + + Zipper(const std::string& /*zipfile_path*/) { + static_assert(Backend>::value, + "No zipper implementation provided!"); + } + + void next_entry(const std::string& /*fname*/) {} + + bool is_ok() { return false; } + + std::string get_name() { return ""; } + + template Zipper& operator<<(const T& /*arg*/) { + return *this; + } + + void close() {} +}; + // Implementation for PNG raster output // Be aware that if a large number of layers are allocated, it can very well // exhaust the available memory especially on 32 bit platform. -template<> class FilePrinter { +template class FilePrinter { struct Layer { Raster first; @@ -148,7 +173,7 @@ public: pxdim_(m.pxdim_) {} inline void layers(unsigned cnt) { if(cnt > 0) layers_rst_.resize(cnt); } - inline unsigned layers() const { return layers_rst_.size(); } + inline unsigned layers() const { return unsigned(layers_rst_.size()); } void printConfig(const Print& printconf) { print_ = &printconf; } @@ -184,37 +209,63 @@ public: inline void save(const std::string& path) { - wxFileName filepath(path); - - wxFFileOutputStream zipfile(path); + Zipper zipper(path); - std::string project = filepath.GetName().ToStdString(); + std::string project = zipper.get_name(); - if(!zipfile.IsOk()) { + if(!zipper.is_ok()) { BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! " << path; return; } - wxZipOutputStream zipstream(zipfile); - wxStdOutputStream pngstream(zipstream); - - zipstream.PutNextEntry("config.ini"); - pngstream << createIniContent(project); + zipper.next_entry(project); + zipper << createIniContent(project); 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); auto zfilename = project + lyrnum + ".png"; - zipstream.PutNextEntry(zfilename); - pngstream << layers_rst_[i].second.rdbuf(); + zipper.next_entry(zfilename); + zipper << layers_rst_[i].second.rdbuf(); layers_rst_[i].second.str(""); } } - zipstream.Close(); - zipfile.Close(); + zipper.close(); + +// wxFileName filepath(path); + +// wxFFileOutputStream zipfile(path); + +// std::string project = filepath.GetName().ToStdString(); + +// if(!zipfile.IsOk()) { +// BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! " +// << path; +// return; +// } + +// wxZipOutputStream zipstream(zipfile); +// wxStdOutputStream pngstream(zipstream); + +// zipstream.PutNextEntry("config.ini"); +// pngstream << createIniContent(project); + +// 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); +// auto zfilename = project + 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) { -- cgit v1.2.3