mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-12 06:38:58 +08:00
Add more comments
This commit is contained in:
parent
784105f5ad
commit
73837c2f82
@ -20,6 +20,7 @@ namespace {
|
|||||||
|
|
||||||
size_t constexpr coord_t_bufsize = 40;
|
size_t constexpr coord_t_bufsize = 40;
|
||||||
|
|
||||||
|
// A fast and locale independent implementation of int=>str
|
||||||
char const* decimal_from(coord_t snumber, char* buffer)
|
char const* decimal_from(coord_t snumber, char* buffer)
|
||||||
{
|
{
|
||||||
std::make_unsigned_t<coord_t> number = 0;
|
std::make_unsigned_t<coord_t> number = 0;
|
||||||
@ -54,6 +55,7 @@ inline std::string coord2str(coord_t crd)
|
|||||||
return decimal_from(crd, buf);
|
return decimal_from(crd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the sla::RasterBase::Trafo onto an ExPolygon
|
||||||
void transform(ExPolygon &ep, const sla::RasterBase::Trafo &tr, const BoundingBox &bb)
|
void transform(ExPolygon &ep, const sla::RasterBase::Trafo &tr, const BoundingBox &bb)
|
||||||
{
|
{
|
||||||
if (tr.flipXY) {
|
if (tr.flipXY) {
|
||||||
@ -75,6 +77,7 @@ void transform(ExPolygon &ep, const sla::RasterBase::Trafo &tr, const BoundingBo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append the svg string representation of a Polygon to the input 'buf'
|
||||||
void append_svg(std::string &buf, const Polygon &poly)
|
void append_svg(std::string &buf, const Polygon &poly)
|
||||||
{
|
{
|
||||||
if (poly.points.empty())
|
if (poly.points.empty())
|
||||||
@ -173,6 +176,8 @@ public:
|
|||||||
|
|
||||||
Trafo trafo() const override { return m_trafo; }
|
Trafo trafo() const override { return m_trafo; }
|
||||||
|
|
||||||
|
// The encoder is ignored here, the svg text does not need any further
|
||||||
|
// encoding.
|
||||||
sla::EncodedRaster encode(sla::RasterEncoder /*encoder*/) const override
|
sla::EncodedRaster encode(sla::RasterEncoder /*encoder*/) const override
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
@ -220,6 +225,7 @@ std::unique_ptr<sla::RasterBase> SL1_SVGArchive::create_raster() const
|
|||||||
return std::make_unique<SVGRaster>(svgarea, sla::Resolution{res_x, res_y}, tr);
|
return std::make_unique<SVGRaster>(svgarea, sla::Resolution{res_x, res_y}, tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SVG does not need additional binary encoding.
|
||||||
sla::RasterEncoder SL1_SVGArchive::get_encoder() const
|
sla::RasterEncoder SL1_SVGArchive::get_encoder() const
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -230,6 +236,9 @@ void SL1_SVGArchive::export_print(const std::string fname,
|
|||||||
const ThumbnailsList &thumbnails,
|
const ThumbnailsList &thumbnails,
|
||||||
const std::string &projectname)
|
const std::string &projectname)
|
||||||
{
|
{
|
||||||
|
// Export code is completely identical to SL1, only the compression level
|
||||||
|
// is elevated, as the SL1 has already compressed PNGs with deflate,
|
||||||
|
// but the svg is just text.
|
||||||
Zipper zipper{fname, Zipper::TIGHT_COMPRESSION};
|
Zipper zipper{fname, Zipper::TIGHT_COMPRESSION};
|
||||||
|
|
||||||
SL1Archive::export_print(zipper, print, thumbnails, projectname);
|
SL1Archive::export_print(zipper, print, thumbnails, projectname);
|
||||||
@ -268,6 +277,8 @@ ConfigSubstitutions SL1_SVGReader::read(std::vector<ExPolygons> &slices,
|
|||||||
st.stop = !m_progr(int(curr));
|
st.stop = !m_progr(int(curr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't want to use dirty casts for the buffer to be usable in
|
||||||
|
// the NanoSVGParser until performance is not a bottleneck here.
|
||||||
auto svgtxt = reserve_vector<char>(entry.buf.size());
|
auto svgtxt = reserve_vector<char>(entry.buf.size());
|
||||||
std::copy(entry.buf.begin(), entry.buf.end(), std::back_inserter(svgtxt));
|
std::copy(entry.buf.begin(), entry.buf.end(), std::back_inserter(svgtxt));
|
||||||
NanoSVGParser svgp(svgtxt.data());
|
NanoSVGParser svgp(svgtxt.data());
|
||||||
@ -284,7 +295,11 @@ ConfigSubstitutions SL1_SVGReader::read(std::vector<ExPolygons> &slices,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExPolygons expolys = union_ex(polys);
|
// Create the slice from the read polygons. Here, the fill rule has to
|
||||||
|
// be the same as stated in the svg file which is `nonzero` when exported
|
||||||
|
// using SL1_SVGArchive. Would be better to parse it from the svg file,
|
||||||
|
// but if it's different, the file is probably corrupted anyways.
|
||||||
|
ExPolygons expolys = union_ex(polys, ClipperLib::pftNonZero);
|
||||||
invert_raster_trafo(expolys, rstp.trafo, rstp.width, rstp.height);
|
invert_raster_trafo(expolys, rstp.trafo, rstp.width, rstp.height);
|
||||||
slices.emplace_back(expolys);
|
slices.emplace_back(expolys);
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,20 @@ namespace Slic3r {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Factory function that returns an implementation of SLAArchiveReader.
|
||||||
using ArchiveFactory = std::function<
|
using ArchiveFactory = std::function<
|
||||||
std::unique_ptr<SLAArchiveReader>(const std::string &fname,
|
std::unique_ptr<SLAArchiveReader>(const std::string &fname,
|
||||||
SLAImportQuality quality,
|
SLAImportQuality quality,
|
||||||
const ProgrFn & progr)>;
|
const ProgrFn & progr)>;
|
||||||
|
|
||||||
|
// Entry in the global registry of readable archive formats.
|
||||||
struct ArchiveEntry {
|
struct ArchiveEntry {
|
||||||
const char *descr;
|
const char *descr;
|
||||||
std::vector<const char *> extensions;
|
std::vector<const char *> extensions;
|
||||||
ArchiveFactory factoryfn;
|
ArchiveFactory factoryfn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is where the readable archive formats are registered.
|
||||||
static const std::map<std::string, ArchiveEntry> REGISTERED_ARCHIVES {
|
static const std::map<std::string, ArchiveEntry> REGISTERED_ARCHIVES {
|
||||||
{
|
{
|
||||||
"SL1",
|
"SL1",
|
||||||
@ -38,7 +41,7 @@ static const std::map<std::string, ArchiveEntry> REGISTERED_ARCHIVES {
|
|||||||
{ L("SL2 archive files"), {"sl2", "sl1_svg", "zip"},
|
{ L("SL2 archive files"), {"sl2", "sl1_svg", "zip"},
|
||||||
[] (const std::string &fname, SLAImportQuality quality, const ProgrFn &progr) { return std::make_unique<SL1_SVGReader>(fname, quality, progr); }}
|
[] (const std::string &fname, SLAImportQuality quality, const ProgrFn &progr) { return std::make_unique<SL1_SVGReader>(fname, quality, progr); }}
|
||||||
},
|
},
|
||||||
// TODO: pwmx
|
// TODO: pwmx and future others.
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -48,6 +51,11 @@ std::unique_ptr<SLAArchiveReader> SLAArchiveReader::create(
|
|||||||
SLAImportQuality quality,
|
SLAImportQuality quality,
|
||||||
const ProgrFn & progr)
|
const ProgrFn & progr)
|
||||||
{
|
{
|
||||||
|
// Create an instance of SLAArchiveReader using the registered archive
|
||||||
|
// reader implementations. Only checking the file extension and comparing
|
||||||
|
// with the registered readers advertised extensions.
|
||||||
|
// The first match will be used.
|
||||||
|
|
||||||
std::string ext = boost::filesystem::path(fname).extension().string();
|
std::string ext = boost::filesystem::path(fname).extension().string();
|
||||||
boost::algorithm::to_lower(ext);
|
boost::algorithm::to_lower(ext);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ namespace Slic3r {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Read an ini file into boost property tree
|
||||||
boost::property_tree::ptree read_ini(const mz_zip_archive_file_stat &entry,
|
boost::property_tree::ptree read_ini(const mz_zip_archive_file_stat &entry,
|
||||||
MZ_Archive &zip)
|
MZ_Archive &zip)
|
||||||
{
|
{
|
||||||
@ -27,6 +28,7 @@ boost::property_tree::ptree read_ini(const mz_zip_archive_file_stat &entry,
|
|||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read an arbitrary file into EntryBuffer
|
||||||
EntryBuffer read_entry(const mz_zip_archive_file_stat &entry,
|
EntryBuffer read_entry(const mz_zip_archive_file_stat &entry,
|
||||||
MZ_Archive &zip,
|
MZ_Archive &zip,
|
||||||
const std::string &name)
|
const std::string &name)
|
||||||
@ -122,8 +124,9 @@ std::pair<DynamicPrintConfig, ConfigSubstitutions> extract_profile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the archive contains an empty profile, use the one that was passed as output argument
|
// If the archive contains an empty profile, use the one that was passed
|
||||||
// then replace it with the readed profile to report that it was empty.
|
// 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_use = profile_in.empty() ? profile_out : profile_in;
|
||||||
profile_out = profile_in;
|
profile_out = profile_in;
|
||||||
|
|
||||||
|
@ -11,26 +11,37 @@
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
// Buffer for arbitraryfiles inside a zipper archive.
|
||||||
struct EntryBuffer
|
struct EntryBuffer
|
||||||
{
|
{
|
||||||
std::vector<uint8_t> buf;
|
std::vector<uint8_t> buf;
|
||||||
std::string fname;
|
std::string fname;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Structure holding the data read from a zipper archive.
|
||||||
struct ZipperArchive
|
struct ZipperArchive
|
||||||
{
|
{
|
||||||
boost::property_tree::ptree profile, config;
|
boost::property_tree::ptree profile, config;
|
||||||
std::vector<EntryBuffer> entries;
|
std::vector<EntryBuffer> entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Names of the files containing metadata inside the archive.
|
||||||
const constexpr char *CONFIG_FNAME = "config.ini";
|
const constexpr char *CONFIG_FNAME = "config.ini";
|
||||||
const constexpr char *PROFILE_FNAME = "prusaslicer.ini";
|
const constexpr char *PROFILE_FNAME = "prusaslicer.ini";
|
||||||
|
|
||||||
|
// Read an archive that was written using the Zipper class.
|
||||||
|
// The includes parameter is a set of file name substrings that the entries
|
||||||
|
// must contain to be included in ZipperArchive.
|
||||||
|
// The excludes parameter may contain substrings that filenames must not
|
||||||
|
// contain.
|
||||||
|
// Every file in the archive is read into ZipperArchive::entries
|
||||||
|
// except the files CONFIG_FNAME, and PROFILE_FNAME which are read into
|
||||||
|
// ZipperArchive::config and ZipperArchive::profile structures.
|
||||||
ZipperArchive read_zipper_archive(const std::string &zipfname,
|
ZipperArchive read_zipper_archive(const std::string &zipfname,
|
||||||
const std::vector<std::string> &includes,
|
const std::vector<std::string> &includes,
|
||||||
const std::vector<std::string> &excludes);
|
const std::vector<std::string> &excludes);
|
||||||
|
|
||||||
// Extract the print profile form the archive onto 'out'.
|
// Extract the print profile form the archive into 'out'.
|
||||||
// Returns a profile that has correct parameters to use for model reconstruction
|
// Returns a profile that has correct parameters to use for model reconstruction
|
||||||
// even if the needed parameters were not fully found in the archive's metadata.
|
// even if the needed parameters were not fully found in the archive's metadata.
|
||||||
// The inout argument shall be a usable fallback profile if the archive
|
// The inout argument shall be a usable fallback profile if the archive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user