Miniz zipping seems to work.
This commit is contained in:
parent
bc3036d777
commit
dc7e75b522
@ -161,6 +161,8 @@ add_library(libslic3r STATIC
|
|||||||
utils.cpp
|
utils.cpp
|
||||||
Utils.hpp
|
Utils.hpp
|
||||||
MTUtils.hpp
|
MTUtils.hpp
|
||||||
|
Zipper.hpp
|
||||||
|
Zipper.cpp
|
||||||
SLA/SLABoilerPlate.hpp
|
SLA/SLABoilerPlate.hpp
|
||||||
SLA/SLABasePool.hpp
|
SLA/SLABasePool.hpp
|
||||||
SLA/SLABasePool.cpp
|
SLA/SLABasePool.cpp
|
||||||
|
@ -97,7 +97,7 @@ public:
|
|||||||
|
|
||||||
bool is_ok() { return false; }
|
bool is_ok() { return false; }
|
||||||
|
|
||||||
template<class T> LayerWriter& operator<<(const T& /*arg*/) {
|
template<class T> LayerWriter& operator<<(T&& /*arg*/) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "PrintExport.hpp"
|
#include "PrintExport.hpp"
|
||||||
#include "Point.hpp"
|
#include "Point.hpp"
|
||||||
#include "MTUtils.hpp"
|
#include "MTUtils.hpp"
|
||||||
|
#include "Zipper.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -200,6 +201,32 @@ struct SLAPrintStatistics
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SLAminzFmt {};
|
||||||
|
|
||||||
|
// The implementation of creating zipped archives with wxWidgets
|
||||||
|
template<> class LayerWriter<SLAminzFmt> {
|
||||||
|
Zipper m_zip;
|
||||||
|
public:
|
||||||
|
|
||||||
|
inline LayerWriter(const std::string& zipfile_path): m_zip(zipfile_path) {}
|
||||||
|
|
||||||
|
inline void next_entry(const std::string& fname) { m_zip.add_entry(fname); }
|
||||||
|
|
||||||
|
inline std::string get_name() const {
|
||||||
|
return m_zip.get_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> inline LayerWriter& operator<<(T&& arg) {
|
||||||
|
m_zip << std::forward<T>(arg); return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_ok() const {
|
||||||
|
return true; // m_zip blows up if something goes wrong...
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void close() { /* m_zip closes upon destruction */ }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class is the high level FSM for the SLA printing process.
|
* @brief This class is the high level FSM for the SLA printing process.
|
||||||
*
|
*
|
||||||
@ -231,9 +258,11 @@ public:
|
|||||||
// Returns true if the last step was finished with success.
|
// Returns true if the last step was finished with success.
|
||||||
bool finished() const override { return this->is_step_done(slaposIndexSlices) && this->Inherited::is_step_done(slapsRasterize); }
|
bool finished() const override { return this->is_step_done(slaposIndexSlices) && this->Inherited::is_step_done(slapsRasterize); }
|
||||||
|
|
||||||
template<class Fmt> void export_raster(const std::string& fname) {
|
template<class Fmt = SLAminzFmt>
|
||||||
|
void export_raster(const std::string& fname) {
|
||||||
if(m_printer) m_printer->save<Fmt>(fname);
|
if(m_printer) m_printer->save<Fmt>(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PrintObjects& objects() const { return m_objects; }
|
const PrintObjects& objects() const { return m_objects; }
|
||||||
|
|
||||||
std::string output_filename() const override;
|
std::string output_filename() const override;
|
||||||
|
68
src/libslic3r/Zipper.cpp
Normal file
68
src/libslic3r/Zipper.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include <exception>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Zipper.hpp"
|
||||||
|
#include "miniz/miniz_zip.h"
|
||||||
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
class Zipper::Impl {
|
||||||
|
public:
|
||||||
|
mz_zip_archive arch;
|
||||||
|
};
|
||||||
|
|
||||||
|
Zipper::Zipper(const std::string &zipfname, e_compression compression)
|
||||||
|
{
|
||||||
|
m_impl.reset(new Impl());
|
||||||
|
|
||||||
|
memset(&m_impl->arch, 0, sizeof(m_impl->arch));
|
||||||
|
|
||||||
|
// Initialize the archive data
|
||||||
|
if(!mz_zip_writer_init_file(&m_impl->arch, zipfname.c_str(), 0))
|
||||||
|
throw std::runtime_error("Cannot open zip archive!");
|
||||||
|
|
||||||
|
m_compression = compression;
|
||||||
|
m_zipname = zipfname;
|
||||||
|
}
|
||||||
|
|
||||||
|
Zipper::~Zipper()
|
||||||
|
{
|
||||||
|
finish_entry();
|
||||||
|
mz_zip_writer_finalize_archive(&m_impl->arch);
|
||||||
|
mz_zip_writer_end(&m_impl->arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Zipper::add_entry(const std::string &name)
|
||||||
|
{
|
||||||
|
finish_entry(); // finish previous business
|
||||||
|
m_entry = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Zipper::finish_entry()
|
||||||
|
{
|
||||||
|
if(!m_data.empty() > 0 && !m_entry.empty()) {
|
||||||
|
mz_uint compression = MZ_NO_COMPRESSION;
|
||||||
|
|
||||||
|
switch (m_compression) {
|
||||||
|
case NO_COMPRESSION: compression = MZ_NO_COMPRESSION; break;
|
||||||
|
case FAST_COMPRESSION: compression = MZ_BEST_SPEED; break;
|
||||||
|
case TIGHT_COMPRESSION: compression = MZ_BEST_COMPRESSION; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mz_zip_writer_add_mem(&m_impl->arch, m_entry.c_str(),
|
||||||
|
m_data.c_str(),
|
||||||
|
m_data.size(),
|
||||||
|
compression);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_data.clear();
|
||||||
|
m_entry.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Zipper::get_name() const {
|
||||||
|
return boost::filesystem::path(m_zipname).stem().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
src/libslic3r/Zipper.hpp
Normal file
51
src/libslic3r/Zipper.hpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef ZIPPER_HPP
|
||||||
|
#define ZIPPER_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
class Zipper {
|
||||||
|
public:
|
||||||
|
enum e_compression {
|
||||||
|
NO_COMPRESSION,
|
||||||
|
FAST_COMPRESSION,
|
||||||
|
TIGHT_COMPRESSION
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
class Impl;
|
||||||
|
std::unique_ptr<Impl> m_impl;
|
||||||
|
std::string m_data;
|
||||||
|
std::string m_entry;
|
||||||
|
e_compression m_compression;
|
||||||
|
std::string m_zipname;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Will blow up in a runtime exception if the file cannot be created.
|
||||||
|
explicit Zipper(const std::string& zipfname,
|
||||||
|
e_compression level = NO_COMPRESSION);
|
||||||
|
~Zipper();
|
||||||
|
|
||||||
|
Zipper(const Zipper&) = delete;
|
||||||
|
Zipper& operator=(const Zipper&) = delete;
|
||||||
|
|
||||||
|
Zipper(Zipper&&) = default;
|
||||||
|
Zipper& operator=(Zipper&&) = default;
|
||||||
|
|
||||||
|
void add_entry(const std::string& name);
|
||||||
|
void finish_entry();
|
||||||
|
|
||||||
|
inline Zipper& operator<<(const std::string& content) {
|
||||||
|
std::copy(content.begin(), content.end(), std::back_inserter(m_data));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_name() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ZIPPER_HPP
|
@ -129,8 +129,8 @@ public:
|
|||||||
return fpath.GetName().ToUTF8().data();
|
return fpath.GetName().ToUTF8().data();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T> inline LayerWriter& operator<<(const T& arg) {
|
template<class T> inline LayerWriter& operator<<(T&& arg) {
|
||||||
pngstream << arg; return *this;
|
pngstream << std::forward<T>(arg); return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_ok() const {
|
bool is_ok() const {
|
||||||
@ -149,7 +149,8 @@ void BackgroundSlicingProcess::process_sla()
|
|||||||
m_print->process();
|
m_print->process();
|
||||||
if (this->set_step_started(bspsGCodeFinalize)) {
|
if (this->set_step_started(bspsGCodeFinalize)) {
|
||||||
if (! m_export_path.empty()) {
|
if (! m_export_path.empty()) {
|
||||||
m_sla_print->export_raster<SLAZipFmt>(m_export_path);
|
// m_sla_print->export_raster<SLAZipFmt>(m_export_path);
|
||||||
|
m_sla_print->export_raster<SLAminzFmt>(m_export_path);
|
||||||
m_print->set_status(100, "Masked SLA file exported to " + m_export_path);
|
m_print->set_status(100, "Masked SLA file exported to " + m_export_path);
|
||||||
} else if (! m_upload_job.empty()) {
|
} else if (! m_upload_job.empty()) {
|
||||||
prepare_upload();
|
prepare_upload();
|
||||||
@ -450,7 +451,8 @@ void BackgroundSlicingProcess::prepare_upload()
|
|||||||
run_post_process_scripts(source_path.string(), m_fff_print->config());
|
run_post_process_scripts(source_path.string(), m_fff_print->config());
|
||||||
m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());
|
m_upload_job.upload_data.upload_path = m_fff_print->print_statistics().finalize_output_path(m_upload_job.upload_data.upload_path.string());
|
||||||
} else {
|
} else {
|
||||||
m_sla_print->export_raster<SLAZipFmt>(source_path.string());
|
// m_sla_print->export_raster<SLAZipFmt>(source_path.string());
|
||||||
|
m_sla_print->export_raster<SLAminzFmt>(source_path.string());
|
||||||
// TODO: Also finalize upload path like with FFF when there are statistics for SLA print
|
// TODO: Also finalize upload path like with FFF when there are statistics for SLA print
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user