mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-11 18:01:14 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
157 lines
5.1 KiB
C++
157 lines
5.1 KiB
C++
#include "ZipperArchiveImport.hpp"
|
|
|
|
#include "libslic3r/Config.hpp"
|
|
#include "libslic3r/LocalesUtils.hpp"
|
|
#include "libslic3r/miniz_extension.hpp"
|
|
#include "libslic3r/Exception.hpp"
|
|
#include "libslic3r/PrintConfig.hpp"
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
#include <algorithm>
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
#include <boost/property_tree/ini_parser.hpp>
|
|
#include <boost/filesystem/path.hpp>
|
|
#include <boost/algorithm/string.hpp>
|
|
#include <miniz.h>
|
|
#include <string>
|
|
#include <cstddef>
|
|
#include <sstream>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
#include <utility>
|
|
#include <functional>
|
|
|
|
namespace Slic3r {
|
|
|
|
namespace {
|
|
|
|
// Read an ini file into boost property tree
|
|
boost::property_tree::ptree read_ini(const mz_zip_archive_file_stat &entry,
|
|
MZ_Archive &zip)
|
|
{
|
|
std::string buf(size_t(entry.m_uncomp_size), '\0');
|
|
|
|
if (!mz_zip_reader_extract_to_mem(&zip.arch, entry.m_file_index,
|
|
buf.data(), buf.size(), 0))
|
|
throw Slic3r::FileIOError(zip.get_errorstr());
|
|
|
|
boost::property_tree::ptree tree;
|
|
std::stringstream ss(buf);
|
|
boost::property_tree::read_ini(ss, tree);
|
|
return tree;
|
|
}
|
|
|
|
// Read an arbitrary file into EntryBuffer
|
|
EntryBuffer read_entry(const mz_zip_archive_file_stat &entry,
|
|
MZ_Archive &zip,
|
|
const std::string &name)
|
|
{
|
|
std::vector<uint8_t> buf(entry.m_uncomp_size);
|
|
|
|
if (!mz_zip_reader_extract_to_mem(&zip.arch, entry.m_file_index,
|
|
buf.data(), buf.size(), 0))
|
|
throw Slic3r::FileIOError(zip.get_errorstr());
|
|
|
|
return {std::move(buf), (name.empty() ? entry.m_filename : name)};
|
|
}
|
|
|
|
} // namespace
|
|
|
|
ZipperArchive read_zipper_archive(const std::string &zipfname,
|
|
const std::vector<std::string> &includes,
|
|
const std::vector<std::string> &excludes)
|
|
{
|
|
ZipperArchive arch;
|
|
|
|
// Little RAII
|
|
struct Arch : public MZ_Archive
|
|
{
|
|
Arch(const std::string &fname)
|
|
{
|
|
if (!open_zip_reader(&arch, fname))
|
|
throw Slic3r::FileIOError(get_errorstr());
|
|
}
|
|
|
|
~Arch() { close_zip_reader(&arch); }
|
|
} zip(zipfname);
|
|
|
|
mz_uint num_entries = mz_zip_reader_get_num_files(&zip.arch);
|
|
|
|
for (mz_uint i = 0; i < num_entries; ++i) {
|
|
mz_zip_archive_file_stat entry;
|
|
|
|
if (mz_zip_reader_file_stat(&zip.arch, i, &entry)) {
|
|
std::string name = entry.m_filename;
|
|
boost::algorithm::to_lower(name);
|
|
|
|
if (!std::any_of(includes.begin(), includes.end(),
|
|
[&name](const std::string &incl) {
|
|
return boost::algorithm::contains(name, incl);
|
|
}))
|
|
continue;
|
|
|
|
if (std::any_of(excludes.begin(), excludes.end(),
|
|
[&name](const std::string &excl) {
|
|
return boost::algorithm::contains(name, excl);
|
|
}))
|
|
continue;
|
|
|
|
if (name == CONFIG_FNAME) {
|
|
arch.config = read_ini(entry, zip);
|
|
continue;
|
|
}
|
|
|
|
if (name == PROFILE_FNAME) {
|
|
arch.profile = read_ini(entry, zip);
|
|
continue;
|
|
}
|
|
|
|
auto it = std::lower_bound(
|
|
arch.entries.begin(), arch.entries.end(),
|
|
EntryBuffer{{}, name},
|
|
[](const EntryBuffer &r1, const EntryBuffer &r2) {
|
|
return std::less<std::string>()(r1.fname, r2.fname);
|
|
});
|
|
|
|
arch.entries.insert(it, read_entry(entry, zip, name));
|
|
}
|
|
}
|
|
|
|
return arch;
|
|
}
|
|
|
|
std::pair<DynamicPrintConfig, ConfigSubstitutions> extract_profile(
|
|
const ZipperArchive &arch, DynamicPrintConfig &profile_out)
|
|
{
|
|
DynamicPrintConfig profile_in, profile_use;
|
|
ConfigSubstitutions config_substitutions =
|
|
profile_in.load(arch.profile,
|
|
ForwardCompatibilitySubstitutionRule::Enable);
|
|
|
|
if (profile_in.empty()) { // missing profile... do guess work
|
|
// try to recover the layer height from the config.ini which was
|
|
// present in all versions of sl1 files.
|
|
if (auto lh_opt = arch.config.find("layerHeight");
|
|
lh_opt != arch.config.not_found()) {
|
|
auto lh_str = lh_opt->second.data();
|
|
|
|
size_t pos = 0;
|
|
double lh = string_to_double_decimal_point(lh_str, &pos);
|
|
if (pos) { // TODO: verify that pos is 0 when parsing fails
|
|
profile_out.set("layer_height", lh);
|
|
profile_out.set("initial_layer_height", lh);
|
|
}
|
|
}
|
|
}
|
|
|
|
// If the archive contains an empty profile, use the one that was passed
|
|
// as output argument then replace it with the readed profile to report
|
|
// that it was empty.
|
|
profile_use = profile_in.empty() ? profile_out : profile_in;
|
|
profile_out = profile_in;
|
|
|
|
return {profile_use, std::move(config_substitutions)};
|
|
}
|
|
|
|
} // namespace Slic3r
|