Merge remote-tracking branch 'origin/master' into ys_new_features

This commit is contained in:
YuSanka 2019-06-05 11:16:25 +02:00
commit 4b3df010ab
35 changed files with 4368 additions and 3851 deletions

View file

@ -163,6 +163,8 @@ add_library(libslic3r STATIC
MTUtils.hpp
Zipper.hpp
Zipper.cpp
miniz_extension.hpp
miniz_extension.cpp
SLA/SLABoilerPlate.hpp
SLA/SLABasePool.hpp
SLA/SLABasePool.cpp
@ -180,6 +182,7 @@ if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
endif ()
target_compile_definitions(libslic3r PUBLIC -DUSE_TBB)
target_include_directories(libslic3r SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
target_include_directories(libslic3r PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${LIBNEST2D_INCLUDES} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(libslic3r
libnest2d

View file

@ -13,10 +13,11 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/nowide/fstream.hpp>
#include <boost/nowide/cstdio.hpp>
#include <expat.h>
#include <Eigen/Dense>
#include <miniz/miniz_zip.h>
#include "miniz_extension.hpp"
// VERSION NUMBERS
// 0 : .3mf, files saved by older slic3r or other applications. No version definition in them.
@ -502,10 +503,8 @@ namespace Slic3r {
{
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
mz_bool res = mz_zip_reader_init_file(&archive, filename.c_str(), 0);
if (res == 0)
{
if (!open_zip_reader(&archive, filename)) {
add_error("Unable to open the file");
return false;
}
@ -529,7 +528,7 @@ namespace Slic3r {
// valid model name -> extract model
if (!_extract_model_from_archive(archive, stat))
{
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
add_error("Archive does not contain a valid model");
return false;
}
@ -565,7 +564,7 @@ namespace Slic3r {
// extract slic3r model config file
if (!_extract_model_config_from_archive(archive, stat, model))
{
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
add_error("Archive does not contain a valid model config");
return false;
}
@ -573,7 +572,7 @@ namespace Slic3r {
}
}
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
for (const IdToModelObjectMap::value_type& object : m_objects)
{
@ -1639,9 +1638,7 @@ namespace Slic3r {
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
mz_bool res = mz_zip_writer_init_file(&archive, filename.c_str(), 0);
if (res == 0)
{
if (!open_zip_writer(&archive, filename)) {
add_error("Unable to open the file");
return false;
}
@ -1650,7 +1647,7 @@ namespace Slic3r {
// The content of this file is the same for each PrusaSlicer 3mf.
if (!_add_content_types_file_to_archive(archive))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1660,7 +1657,7 @@ namespace Slic3r {
// The relationshis file contains a reference to the geometry file "3D/3dmodel.model", the name was chosen to be compatible with CURA.
if (!_add_relationships_file_to_archive(archive))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1670,7 +1667,7 @@ namespace Slic3r {
IdToObjectDataMap objects_data;
if (!_add_model_file_to_archive(archive, model, objects_data))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1680,7 +1677,7 @@ namespace Slic3r {
// The index differes from the index of an object ID of an object instance of a 3MF file!
if (!_add_layer_height_profile_file_to_archive(archive, model))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1690,7 +1687,7 @@ namespace Slic3r {
// The index differes from the index of an object ID of an object instance of a 3MF file!
if (!_add_sla_support_points_file_to_archive(archive, model))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1701,7 +1698,7 @@ namespace Slic3r {
{
if (!_add_print_config_file_to_archive(archive, *config))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
@ -1713,20 +1710,20 @@ namespace Slic3r {
// is stored here as well.
if (!_add_model_config_file_to_archive(archive, model, objects_data))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
return false;
}
if (!mz_zip_writer_finalize_archive(&archive))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(filename);
add_error("Unable to finalize the archive");
return false;
}
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
return true;
}

View file

@ -16,7 +16,7 @@
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/nowide/fstream.hpp>
#include <miniz/miniz_zip.h>
#include "miniz_extension.hpp"
#if 0
// Enable debugging and assert in this file.
@ -717,14 +717,14 @@ bool extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_fi
if (stat.m_uncomp_size == 0)
{
printf("Found invalid size\n");
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return false;
}
XML_Parser parser = XML_ParserCreate(nullptr); // encoding
if (!parser) {
printf("Couldn't allocate memory for parser\n");
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return false;
}
@ -737,7 +737,7 @@ bool extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_fi
if (parser_buffer == nullptr)
{
printf("Unable to create buffer\n");
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return false;
}
@ -745,14 +745,14 @@ bool extract_model_from_archive(mz_zip_archive& archive, const mz_zip_archive_fi
if (res == 0)
{
printf("Error while reading model data to buffer\n");
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return false;
}
if (!XML_ParseBuffer(parser, (int)stat.m_uncomp_size, 1))
{
printf("Error (%s) while parsing xml file at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return false;
}
@ -774,8 +774,7 @@ bool load_amf_archive(const char *path, DynamicPrintConfig *config, Model *model
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
mz_bool res = mz_zip_reader_init_file(&archive, path, 0);
if (res == 0)
if (!open_zip_reader(&archive, path))
{
printf("Unable to init zip reader\n");
return false;
@ -793,7 +792,7 @@ bool load_amf_archive(const char *path, DynamicPrintConfig *config, Model *model
{
if (!extract_model_from_archive(archive, stat, config, model, version))
{
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
printf("Archive does not contain a valid model");
return false;
}
@ -814,7 +813,7 @@ bool load_amf_archive(const char *path, DynamicPrintConfig *config, Model *model
}
#endif // forward compatibility
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return true;
}
@ -854,9 +853,7 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config)
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
mz_bool res = mz_zip_writer_init_file(&archive, export_path.c_str(), 0);
if (res == 0)
return false;
if (!open_zip_writer(&archive, export_path)) return false;
std::stringstream stream;
// https://en.cppreference.com/w/cpp/types/numeric_limits/max_digits10
@ -1018,19 +1015,19 @@ bool store_amf(const char *path, Model *model, const DynamicPrintConfig *config)
if (!mz_zip_writer_add_mem(&archive, internal_amf_filename.c_str(), (const void*)out.data(), out.length(), MZ_DEFAULT_COMPRESSION))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(export_path);
return false;
}
if (!mz_zip_writer_finalize_archive(&archive))
{
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
boost::filesystem::remove(export_path);
return false;
}
mz_zip_writer_end(&archive);
close_zip_writer(&archive);
return true;
}

View file

@ -3,8 +3,9 @@
#include <boost/algorithm/string.hpp>
#include <boost/nowide/convert.hpp>
#include <boost/nowide/cstdio.hpp>
#include <miniz/miniz_zip.h>
#include "miniz_extension.hpp"
#include <Eigen/Geometry>
@ -298,10 +299,11 @@ bool load_prus(const char *path, Model *model)
{
mz_zip_archive archive;
mz_zip_zero_struct(&archive);
mz_bool res = mz_zip_reader_init_file(&archive, path, 0);
size_t n_models_initial = model->objects.size();
mz_bool res = MZ_FALSE;
try {
if (res == MZ_FALSE)
if (!open_zip_reader(&archive, path))
throw std::runtime_error(std::string("Unable to init zip reader for ") + path);
std::vector<char> scene_xml_data;
// For grouping multiple STLs into a single ModelObject for multi-material prints.
@ -326,11 +328,11 @@ bool load_prus(const char *path, Model *model)
}
}
} catch (std::exception &ex) {
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
throw ex;
}
mz_zip_reader_end(&archive);
close_zip_reader(&archive);
return model->objects.size() > n_models_initial;
}

View file

@ -781,6 +781,8 @@ void GCode::_do_export(Print &print, FILE *file)
m_placeholder_parser.set("initial_tool", initial_extruder_id);
m_placeholder_parser.set("initial_extruder", initial_extruder_id);
m_placeholder_parser.set("current_extruder", initial_extruder_id);
//Set variable for total layer count so it can be used in custom gcode.
m_placeholder_parser.set("total_layer_count", m_layer_count);
// Useful for sequential prints.
m_placeholder_parser.set("current_object_idx", 0);
// For the start / end G-code to do the priming and final filament pull in case there is no wipe tower provided.

View file

@ -15,7 +15,7 @@
#include <agg/agg_path_storage.h>
// Experimental minz image write:
#include <miniz/miniz_tdef.h>
#include <miniz.h>
namespace Slic3r {

View file

@ -1,11 +1,8 @@
#include <exception>
#include <sstream>
#include <iostream>
#include "Zipper.hpp"
#include "miniz/miniz_zip.h"
#include "miniz_extension.hpp"
#include <boost/log/trivial.hpp>
#include "I18N.hpp"
//! macro used to mark string used at localization,
@ -126,9 +123,9 @@ Zipper::Zipper(const std::string &zipfname, e_compression compression)
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))
if (!open_zip_writer(&m_impl->arch, zipfname)) {
m_impl->blow_up();
}
}
Zipper::~Zipper()
@ -144,7 +141,7 @@ Zipper::~Zipper()
}
// The file should be closed no matter what...
if(!mz_zip_writer_end(&m_impl->arch))
if(!close_zip_writer(&m_impl->arch))
BOOST_LOG_TRIVIAL(error) << m_impl->formatted_errorstr();
}

View file

@ -1,6 +1,7 @@
#ifndef ZIPPER_HPP
#define ZIPPER_HPP
#include <cstdint>
#include <string>
#include <memory>

View file

@ -0,0 +1,59 @@
#include "miniz_extension.hpp"
#if defined(_MSC_VER) || defined(__MINGW64__)
#include "boost/nowide/cstdio.hpp"
#endif
namespace Slic3r {
namespace {
bool open_zip(mz_zip_archive *zip, const char *fname, bool isread)
{
if (!zip) return false;
const char *mode = isread ? "rb" : "wb";
FILE *f = nullptr;
#if defined(_MSC_VER) || defined(__MINGW64__)
f = boost::nowide::fopen(fname, mode);
#elif defined(__GNUC__) && defined(_LARGEFILE64_SOURCE)
f = fopen64(fname, mode);
#else
f = fopen(fname, mode);
#endif
if (!f) {
zip->m_last_error = MZ_ZIP_FILE_OPEN_FAILED;
return false;
}
return isread ? mz_zip_reader_init_cfile(zip, f, 0, 0)
: mz_zip_writer_init_cfile(zip, f, 0);
}
bool close_zip(mz_zip_archive *zip, bool isread)
{
bool ret = false;
if (zip) {
FILE *f = mz_zip_get_cfile(zip);
ret = bool(isread ? mz_zip_reader_end(zip)
: mz_zip_writer_end(zip));
if (f) fclose(f);
}
return ret;
}
}
bool open_zip_reader(mz_zip_archive *zip, const std::string &fname)
{
return open_zip(zip, fname.c_str(), true);
}
bool open_zip_writer(mz_zip_archive *zip, const std::string &fname)
{
return open_zip(zip, fname.c_str(), false);
}
bool close_zip_reader(mz_zip_archive *zip) { return close_zip(zip, true); }
bool close_zip_writer(mz_zip_archive *zip) { return close_zip(zip, false); }
}

View file

@ -0,0 +1,16 @@
#ifndef MINIZ_EXTENSION_HPP
#define MINIZ_EXTENSION_HPP
#include <string>
#include <miniz.h>
namespace Slic3r {
bool open_zip_reader(mz_zip_archive *zip, const std::string &fname_utf8);
bool open_zip_writer(mz_zip_archive *zip, const std::string &fname_utf8);
bool close_zip_reader(mz_zip_archive *zip);
bool close_zip_writer(mz_zip_archive *zip);
}
#endif // MINIZ_EXTENSION_HPP