Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2018-09-19 14:43:15 +0300
committertamasmeszaros <meszaros.q@gmail.com>2018-09-19 14:43:15 +0300
commit2056f4c3365b6b9c3eb89d3746882983ad7b42a8 (patch)
tree8d4127178048b4a795dcd1e18ee6af8d0d3cb8e9 /xs
parent6b655f9aa31018a2269380350c7bdb0c14377ab9 (diff)
Zipper concept clarified.
Diffstat (limited to 'xs')
-rw-r--r--xs/src/libslic3r/PrintExport.hpp61
-rw-r--r--xs/src/slic3r/AppController.cpp42
-rw-r--r--xs/src/slic3r/AppController.hpp17
-rw-r--r--xs/src/slic3r/AppControllerWx.cpp49
4 files changed, 91 insertions, 78 deletions
diff --git a/xs/src/libslic3r/PrintExport.hpp b/xs/src/libslic3r/PrintExport.hpp
index c3c59fc30..cd6d16f33 100644
--- a/xs/src/libslic3r/PrintExport.hpp
+++ b/xs/src/libslic3r/PrintExport.hpp
@@ -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) {
diff --git a/xs/src/slic3r/AppController.cpp b/xs/src/slic3r/AppController.cpp
index 6728c6c00..b5c9702f1 100644
--- a/xs/src/slic3r/AppController.cpp
+++ b/xs/src/slic3r/AppController.cpp
@@ -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) {}
- void next_entry(const std::string& fname) {
- m_zipstream.PutNextEntry(fname);
- }
+ inline void next_entry(const std::string& fname) { m_zip.next_entry(fname); }
- std::string get_name() {
- return m_fpath.GetName().ToStdString();
- }
+ inline std::string get_name() const { return m_zip.get_name(); }
- template<class T> Zipper& operator<<(const T& arg) {
- m_pngstream << arg; return *this;
+ template<class T> inline LayerWriter& operator<<(const T& arg) {
+ m_zip.stream() << 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
diff --git a/xs/src/slic3r/AppController.hpp b/xs/src/slic3r/AppController.hpp
index 88d1f0eca..c9ab6f15d 100644
--- a/xs/src/slic3r/AppController.hpp
+++ b/xs/src/slic3r/AppController.hpp
@@ -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.
*/
diff --git a/xs/src/slic3r/AppControllerWx.cpp b/xs/src/slic3r/AppControllerWx.cpp
index 4d67d5f66..7de2a424f 100644
--- a/xs/src/slic3r/AppControllerWx.cpp
+++ b/xs/src/slic3r/AppControllerWx.cpp
@@ -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 {
/*