Removed explicit dependency of wxWidgets from PrintExport.hpp

This commit is contained in:
tamasmeszaros 2018-09-18 19:13:56 +02:00
parent 5fa99fd903
commit 4d6fb52047
2 changed files with 87 additions and 36 deletions

View File

@ -1341,22 +1341,22 @@ std::string Print::output_filepath(const std::string &path) const
void Print::export_png(const std::string &dirpath) void Print::export_png(const std::string &dirpath)
{ {
size_t idx = 0; // size_t idx = 0;
for (PrintObject *obj : m_objects) { // for (PrintObject *obj : m_objects) {
obj->slice(); // obj->slice();
this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing..."); // this->set_status(int(floor(idx * 100. / m_objects.size() + 0.5)), "Slicing...");
++ idx; // ++ idx;
} // }
this->set_status(90, "Exporting zipped archive..."); // this->set_status(90, "Exporting zipped archive...");
print_to<FilePrinterFormat::PNG>(*this, // print_to<FilePrinterFormat::PNG>(*this,
dirpath, // dirpath,
float(m_config.bed_size_x.value), // float(m_config.bed_size_x.value),
float(m_config.bed_size_y.value), // float(m_config.bed_size_y.value),
int(m_config.pixel_width.value), // int(m_config.pixel_width.value),
int(m_config.pixel_height.value), // int(m_config.pixel_height.value),
float(m_config.exp_time.value), // float(m_config.exp_time.value),
float(m_config.exp_time_first.value)); // float(m_config.exp_time_first.value));
this->set_status(100, "Done."); // this->set_status(100, "Done.");
} }
// Returns extruder this eec should be printed with, according to PrintRegion config // Returns extruder this eec should be printed with, according to PrintRegion config

View File

@ -7,9 +7,9 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <wx/stdstream.h> //#include <wx/stdstream.h>
#include <wx/wfstream.h> //#include <wx/wfstream.h>
#include <wx/zipstrm.h> //#include <wx/zipstrm.h>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
@ -32,7 +32,7 @@ enum class FilePrinterFormat {
* different implementations of this class template for each supported format. * different implementations of this class template for each supported format.
* *
*/ */
template<FilePrinterFormat format> template<FilePrinterFormat format, class LayerFormat = void>
class FilePrinter { class FilePrinter {
public: public:
@ -73,10 +73,35 @@ public:
void saveLayer(unsigned lyr, const std::string& path); void saveLayer(unsigned lyr, const std::string& path);
}; };
template<class T = void> 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 Backend> 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<class T> Zipper& operator<<(const T& /*arg*/) {
return *this;
}
void close() {}
};
// Implementation for PNG raster output // Implementation for PNG raster output
// Be aware that if a large number of layers are allocated, it can very well // Be aware that if a large number of layers are allocated, it can very well
// exhaust the available memory especially on 32 bit platform. // exhaust the available memory especially on 32 bit platform.
template<> class FilePrinter<FilePrinterFormat::PNG> { template<class LyrFormat> class FilePrinter<FilePrinterFormat::PNG, LyrFormat> {
struct Layer { struct Layer {
Raster first; Raster first;
@ -148,7 +173,7 @@ public:
pxdim_(m.pxdim_) {} pxdim_(m.pxdim_) {}
inline void layers(unsigned cnt) { if(cnt > 0) layers_rst_.resize(cnt); } 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; } void printConfig(const Print& printconf) { print_ = &printconf; }
@ -184,37 +209,63 @@ public:
inline void save(const std::string& path) { inline void save(const std::string& path) {
wxFileName filepath(path); Zipper<LyrFormat> zipper(path);
wxFFileOutputStream zipfile(path); std::string project = zipper.get_name();
std::string project = filepath.GetName().ToStdString(); if(!zipper.is_ok()) {
if(!zipfile.IsOk()) {
BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! " BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
<< path; << path;
return; return;
} }
wxZipOutputStream zipstream(zipfile); zipper.next_entry(project);
wxStdOutputStream pngstream(zipstream); zipper << createIniContent(project);
zipstream.PutNextEntry("config.ini");
pngstream << createIniContent(project);
for(unsigned i = 0; i < layers_rst_.size(); i++) { for(unsigned i = 0; i < layers_rst_.size(); i++) {
if(layers_rst_[i].second.rdbuf()->in_avail() > 0) { if(layers_rst_[i].second.rdbuf()->in_avail() > 0) {
char lyrnum[6]; char lyrnum[6];
std::sprintf(lyrnum, "%.5d", i); std::sprintf(lyrnum, "%.5d", i);
auto zfilename = project + lyrnum + ".png"; auto zfilename = project + lyrnum + ".png";
zipstream.PutNextEntry(zfilename); zipper.next_entry(zfilename);
pngstream << layers_rst_[i].second.rdbuf(); zipper << layers_rst_[i].second.rdbuf();
layers_rst_[i].second.str(""); layers_rst_[i].second.str("");
} }
} }
zipstream.Close(); zipper.close();
zipfile.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) { void saveLayer(unsigned lyr, const std::string& path) {