Zipper concept clarified.
This commit is contained in:
parent
6b655f9aa3
commit
2056f4c336
@ -73,19 +73,21 @@ 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 {
|
||||
template<class Backend> class LayerWriter {
|
||||
public:
|
||||
|
||||
Zipper(const std::string& /*zipfile_path*/) {
|
||||
LayerWriter(const std::string& /*zipfile_path*/) {
|
||||
static_assert(VeryFalse<Backend>::value,
|
||||
"No zipper implementation provided!");
|
||||
"No layer writer implementation provided!");
|
||||
}
|
||||
|
||||
void next_entry(const std::string& /*fname*/) {}
|
||||
|
||||
std::string get_name() { return ""; }
|
||||
|
||||
template<class T> Zipper& operator<<(const T& /*arg*/) {
|
||||
bool is_ok() { return false; }
|
||||
|
||||
template<class T> LayerWriter& operator<<(const T& /*arg*/) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -203,62 +205,29 @@ public:
|
||||
|
||||
inline void save(const std::string& path) {
|
||||
try {
|
||||
Zipper<LyrFormat> zipper(path);
|
||||
LayerWriter<LyrFormat> writer(path);
|
||||
|
||||
std::string project = zipper.get_name();
|
||||
std::string project = writer.get_name();
|
||||
|
||||
zipper.next_entry(project);
|
||||
zipper << createIniContent(project);
|
||||
writer.next_entry("config.ini");
|
||||
writer << 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";
|
||||
zipper.next_entry(zfilename);
|
||||
zipper << layers_rst_[i].second.rdbuf();
|
||||
writer.next_entry(zfilename);
|
||||
writer << layers_rst_[i].second.rdbuf();
|
||||
layers_rst_[i].second.str("");
|
||||
}
|
||||
}
|
||||
|
||||
zipper.close();
|
||||
} catch(std::exception&) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Can't create zip file for layers! "
|
||||
<< path;
|
||||
writer.close();
|
||||
} catch(std::exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << e.what();
|
||||
return;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -18,9 +18,6 @@
|
||||
#include <Model.hpp>
|
||||
#include <Utils.hpp>
|
||||
|
||||
#include <wx/stdstream.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/zipstrm.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@ -290,41 +287,21 @@ void PrintController::slice()
|
||||
slice(pri);
|
||||
}
|
||||
|
||||
struct wxZipper {};
|
||||
|
||||
template<> class Zipper<wxZipper> {
|
||||
wxFileName m_fpath;
|
||||
wxFFileOutputStream m_zipfile;
|
||||
wxZipOutputStream m_zipstream;
|
||||
wxStdOutputStream m_pngstream;
|
||||
template<> class LayerWriter<Zipper> {
|
||||
Zipper m_zip;
|
||||
public:
|
||||
|
||||
Zipper(const std::string& zipfile_path):
|
||||
m_fpath(zipfile_path),
|
||||
m_zipfile(zipfile_path),
|
||||
m_zipstream(m_zipfile),
|
||||
m_pngstream(m_zipstream)
|
||||
{
|
||||
if(!m_zipfile.IsOk())
|
||||
throw std::runtime_error(L("Cannot create zip file."));
|
||||
inline LayerWriter(const std::string& zipfile_path): m_zip(zipfile_path) {}
|
||||
|
||||
inline void next_entry(const std::string& fname) { m_zip.next_entry(fname); }
|
||||
|
||||
inline std::string get_name() const { return m_zip.get_name(); }
|
||||
|
||||
template<class T> inline LayerWriter& operator<<(const T& arg) {
|
||||
m_zip.stream() << arg; return *this;
|
||||
}
|
||||
|
||||
void next_entry(const std::string& fname) {
|
||||
m_zipstream.PutNextEntry(fname);
|
||||
}
|
||||
|
||||
std::string get_name() {
|
||||
return m_fpath.GetName().ToStdString();
|
||||
}
|
||||
|
||||
template<class T> Zipper& operator<<(const T& arg) {
|
||||
m_pngstream << arg; return *this;
|
||||
}
|
||||
|
||||
void close() {
|
||||
m_zipstream.Close();
|
||||
m_zipfile.Close();
|
||||
}
|
||||
inline void close() { m_zip.close(); }
|
||||
};
|
||||
|
||||
void PrintController::slice_to_png()
|
||||
@ -428,7 +405,7 @@ void PrintController::slice_to_png()
|
||||
});
|
||||
|
||||
try {
|
||||
print_to<FilePrinterFormat::PNG, wxZipper>( *print, exd.zippath,
|
||||
print_to<FilePrinterFormat::PNG, Zipper>( *print, exd.zippath,
|
||||
exd.width_mm, exd.height_mm,
|
||||
exd.width_px, exd.height_px,
|
||||
exd.exp_time_s, exd.exp_time_first_s);
|
||||
@ -439,6 +416,7 @@ void PrintController::slice_to_png()
|
||||
|
||||
scale_back();
|
||||
if(print->canceled()) print->restart();
|
||||
print->set_status_default();
|
||||
}
|
||||
|
||||
const PrintConfig &PrintController::config() const
|
||||
|
@ -165,6 +165,23 @@ protected:
|
||||
ProgresIndicatorPtr global_progressind_;
|
||||
};
|
||||
|
||||
class Zipper {
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> m_impl;
|
||||
public:
|
||||
|
||||
Zipper(const std::string& zipfilepath);
|
||||
~Zipper();
|
||||
|
||||
void next_entry(const std::string& fname);
|
||||
|
||||
std::string get_name() const;
|
||||
|
||||
std::ostream& stream();
|
||||
|
||||
void close();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implementation of the printing logic.
|
||||
*/
|
||||
|
@ -1,5 +1,9 @@
|
||||
#include "AppController.hpp"
|
||||
|
||||
#include <wx/stdstream.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/zipstrm.h>
|
||||
|
||||
#include <thread>
|
||||
#include <future>
|
||||
|
||||
@ -98,6 +102,51 @@ bool AppControllerBoilerplate::report_issue(
|
||||
|
||||
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
|
||||
|
||||
struct Zipper::Impl {
|
||||
wxFileName m_fpath;
|
||||
wxFFileOutputStream m_zipfile;
|
||||
wxZipOutputStream m_zipstream;
|
||||
wxStdOutputStream m_pngstream;
|
||||
|
||||
Impl(const std::string& zipfile_path):
|
||||
m_fpath(zipfile_path),
|
||||
m_zipfile(zipfile_path),
|
||||
m_zipstream(m_zipfile),
|
||||
m_pngstream(m_zipstream)
|
||||
{
|
||||
if(!m_zipfile.IsOk())
|
||||
throw std::runtime_error(L("Cannot create zip file."));
|
||||
}
|
||||
};
|
||||
|
||||
Zipper::Zipper(const std::string &zipfilepath)
|
||||
{
|
||||
m_impl.reset(new Impl(zipfilepath));
|
||||
}
|
||||
|
||||
Zipper::~Zipper() {}
|
||||
|
||||
void Zipper::next_entry(const std::string &fname)
|
||||
{
|
||||
m_impl->m_zipstream.PutNextEntry(fname);
|
||||
}
|
||||
|
||||
std::string Zipper::get_name() const
|
||||
{
|
||||
return m_impl->m_fpath.GetName().ToStdString();
|
||||
}
|
||||
|
||||
std::ostream &Zipper::stream()
|
||||
{
|
||||
return m_impl->m_pngstream;
|
||||
}
|
||||
|
||||
void Zipper::close()
|
||||
{
|
||||
m_impl->m_zipstream.Close();
|
||||
m_impl->m_zipfile.Close();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user