Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::SL1_SVGReader Class Reference

#include <src/libslic3r/Format/SL1_SVG.hpp>

+ Inheritance diagram for Slic3r::SL1_SVGReader:
+ Collaboration diagram for Slic3r::SL1_SVGReader:

Public Member Functions

ConfigSubstitutions read (std::vector< ExPolygons > &slices, DynamicPrintConfig &profile_out) override
 
ConfigSubstitutions read (DynamicPrintConfig &profile) override
 
 SL1_SVGReader ()=default
 
 SL1_SVGReader (const std::string &fname, SLAImportQuality, const ProgrFn &progr)
 

Static Public Member Functions

static std::unique_ptr< SLAArchiveReadercreate (const std::string &fname, const std::string &format_id, SLAImportQuality quality=SLAImportQuality::Balanced, const ProgrFn &progr=[](int) { return false;})
 

Private Attributes

std::function< bool(int)> m_progr
 
std::string m_fname
 

Detailed Description

Constructor & Destructor Documentation

◆ SL1_SVGReader() [1/2]

Slic3r::SL1_SVGReader::SL1_SVGReader ( )
default

◆ SL1_SVGReader() [2/2]

Slic3r::SL1_SVGReader::SL1_SVGReader ( const std::string &  fname,
SLAImportQuality  ,
const ProgrFn progr 
)
inline
42 : m_progr(progr), m_fname(fname)
43 {}
std::function< bool(int)> m_progr
Definition SL1_SVG.hpp:26
std::string m_fname
Definition SL1_SVG.hpp:27

Member Function Documentation

◆ create()

std::unique_ptr< SLAArchiveReader > Slic3r::SLAArchiveReader::create ( const std::string &  fname,
const std::string &  format_id,
SLAImportQuality  quality = SLAImportQuality::Balanced,
const ProgrFn progr = [](int) { return false; } 
)
staticinherited
23{
24 // Create an instance of SLAArchiveReader using the registered archive
25 // reader implementations.
26 // If format_id is specified and valid, that archive format will be
27 // preferred. When format_id is emtpy, the file extension is compared
28 // with the advertised extensions of registered readers and the first
29 // match will be used.
30
31 std::string ext = boost::filesystem::path(fname).extension().string();
32 boost::algorithm::to_lower(ext);
33
34 std::unique_ptr<SLAArchiveReader> ret;
35
36 auto registry = registered_sla_archives();
37
38 auto arch_from = registry.begin();
39 auto arch_to = registry.end();
40
41 auto arch_it = registry.find(ArchiveEntry{format_id.c_str()});
42 if (arch_it != registry.end()) {
43 arch_from = arch_it;
44 arch_to = arch_it;
45 }
46
47 if (!ext.empty()) {
48 if (ext.front() == '.')
49 ext.erase(ext.begin());
50
51 for (auto it = arch_from; !ret && it != arch_to; ++it) {
52 const auto &entry = *it;
53 if (entry.rdfactoryfn) {
54 auto extensions = get_extensions(entry);
55 for (const std::string& supportedext : extensions) {
56 if (ext == supportedext) {
57 ret = entry.rdfactoryfn(fname, quality, progr);
58 break;
59 }
60 }
61 }
62 }
63 }
64
65 return ret;
66}
const std::set< ArchiveEntry > & registered_sla_archives()
Definition SLAArchiveFormatRegistry.cpp:95
std::vector< std::string > get_extensions(const ArchiveEntry &entry)
Definition SLAArchiveFormatRegistry.cpp:100

References Slic3r::get_extensions(), and Slic3r::registered_sla_archives().

Referenced by Slic3r::import_sla_archive(), and Slic3r::import_sla_archive().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read() [1/2]

ConfigSubstitutions Slic3r::SL1_SVGReader::read ( DynamicPrintConfig profile)
overridevirtual

Implements Slic3r::SLAArchiveReader.

312{
313 ZipperArchive arch = read_zipper_archive(m_fname, {"prusaslicer.ini"}, {});
314 return out.load(arch.profile, ForwardCompatibilitySubstitutionRule::Enable);
315}
@ Enable
Definition Config.hpp:221
ZipperArchive read_zipper_archive(const std::string &zipfname, const std::vector< std::string > &includes, const std::vector< std::string > &excludes)
Definition ZipperArchiveImport.cpp:47

References Slic3r::Enable, Slic3r::ConfigBase::load(), m_fname, Slic3r::ZipperArchive::profile, and Slic3r::read_zipper_archive().

+ Here is the call graph for this function:

◆ read() [2/2]

ConfigSubstitutions Slic3r::SL1_SVGReader::read ( std::vector< ExPolygons > &  slices,
DynamicPrintConfig profile_out 
)
overridevirtual

Implements Slic3r::SLAArchiveReader.

256{
257 std::vector<std::string> includes = { CONFIG_FNAME, PROFILE_FNAME, "svg"};
258 ZipperArchive arch = read_zipper_archive(m_fname, includes, {});
259 auto [profile_use, config_substitutions] = extract_profile(arch, profile_out);
260
261 RasterParams rstp = get_raster_params(profile_use);
262
263 struct Status
264 {
265 double incr, val, prev;
266 bool stop = false;
267 } st{100. / arch.entries.size(), 0., 0.};
268
269 for (const EntryBuffer &entry : arch.entries) {
270 if (st.stop) break;
271
272 st.val += st.incr;
273 double curr = std::round(st.val);
274 if (curr > st.prev) {
275 st.prev = curr;
276 st.stop = !m_progr(int(curr));
277 }
278
279 // Don't want to use dirty casts for the buffer to be usable in
280 // the NanoSVGParser until performance is not a bottleneck here.
281 auto svgtxt = reserve_vector<char>(entry.buf.size() + 1);
282 std::copy(entry.buf.begin(), entry.buf.end(), std::back_inserter(svgtxt));
283 svgtxt.emplace_back('\0');
284 NanoSVGParser svgp(svgtxt.data());
285
286 Polygons polys;
287 for (NSVGshape *shape = svgp.image->shapes; shape != nullptr; shape = shape->next) {
288 for (NSVGpath *path = shape->paths; path != nullptr; path = path->next) {
289 Polygon p;
290 for (int i = 0; i < path->npts; ++i) {
291 size_t c = 2 * i;
292 p.points.emplace_back(scaled(Vec2f(path->pts[c], path->pts[c + 1])));
293 }
294 polys.emplace_back(p);
295 }
296 }
297
298 // Create the slice from the read polygons. Here, the fill rule has to
299 // be the same as stated in the svg file which is `nonzero` when exported
300 // using SL1_SVGArchive. Would be better to parse it from the svg file,
301 // but if it's different, the file is probably corrupted anyways.
303 invert_raster_trafo(expolys, rstp.trafo, rstp.width, rstp.height);
304 slices.emplace_back(expolys);
305 }
306
307 // Compile error without the move
308 return std::move(config_substitutions);
309}
@ pftNonZero
Definition clipper.hpp:81
std::vector< Polygon, PointsAllocator< Polygon > > Polygons
Definition Polygon.hpp:15
std::pair< DynamicPrintConfig, ConfigSubstitutions > extract_profile(const ZipperArchive &arch, DynamicPrintConfig &profile_out)
Definition ZipperArchiveImport.cpp:110
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:240
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, ClipperLib::PolyFillType fill_type)
Definition ClipperUtils.cpp:774
std::vector< ExPolygon > ExPolygons
Definition ExPolygon.hpp:13
const constexpr char * CONFIG_FNAME
Definition ZipperArchiveImport.hpp:29
void invert_raster_trafo(ExPolygons &expolys, const sla::RasterBase::Trafo &trafo, coord_t width, coord_t height)
Definition SL1.cpp:277
const constexpr char * PROFILE_FNAME
Definition ZipperArchiveImport.hpp:30
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:48
RasterParams get_raster_params(const DynamicPrintConfig &cfg)
Definition SL1.cpp:303
Slic3r::Polygon Polygon
Definition Emboss.cpp:34

References Slic3r::CONFIG_FNAME, Slic3r::ZipperArchive::entries, Slic3r::extract_profile(), Slic3r::get_raster_params(), Slic3r::RasterParams::height, Slic3r::NanoSVGParser::image, Slic3r::invert_raster_trafo(), m_fname, m_progr, ClipperLib::pftNonZero, Slic3r::MultiPoint::points, Slic3r::PROFILE_FNAME, Slic3r::read_zipper_archive(), Slic3r::scaled(), Slic3r::RasterParams::trafo, Slic3r::union_ex(), and Slic3r::RasterParams::width.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_fname

std::string Slic3r::SL1_SVGReader::m_fname
private

Referenced by read(), and read().

◆ m_progr

std::function<bool(int)> Slic3r::SL1_SVGReader::m_progr
private

Referenced by read().


The documentation for this class was generated from the following files: