From 07fa15806fe9f0b31f7baeae0d59aba6ddf3cd7b Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 2 Mar 2017 16:32:43 +0100 Subject: Utility function SVG::export_expolygons() to paint a set of possibly overlapping ExPolygons with attributes. --- xs/src/libslic3r/SVG.cpp | 24 ++++++++++++++++++++++++ xs/src/libslic3r/SVG.hpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'xs') diff --git a/xs/src/libslic3r/SVG.cpp b/xs/src/libslic3r/SVG.cpp index db914ea96..b8580fd5e 100644 --- a/xs/src/libslic3r/SVG.cpp +++ b/xs/src/libslic3r/SVG.cpp @@ -345,4 +345,28 @@ void SVG::export_expolygons(const char *path, const BoundingBox &bbox, const Sli svg.Close(); } +void SVG::export_expolygons(const char *path, const std::vector> &expolygons_with_attributes) +{ + if (expolygons_with_attributes.empty()) + return; + + BoundingBox bbox = get_extents(expolygons_with_attributes.front().first); + for (size_t i = 0; i < expolygons_with_attributes.size(); ++ i) + bbox.merge(get_extents(expolygons_with_attributes[i].first)); + + SVG svg(path, bbox); + for (const auto &exp_with_attr : expolygons_with_attributes) + svg.draw(exp_with_attr.first, exp_with_attr.second.color_fill, exp_with_attr.second.fill_opacity); + for (const auto &exp_with_attr : expolygons_with_attributes) { + std::string color_contour = exp_with_attr.second.color_contour; + if (color_contour.empty()) + color_contour = exp_with_attr.second.color_fill; + std::string color_holes = exp_with_attr.second.color_holes; + if (color_holes.empty()) + color_holes = color_contour; + svg.draw_outline(exp_with_attr.first, color_contour, color_holes, exp_with_attr.second.outline_width); + } + svg.Close(); +} + } diff --git a/xs/src/libslic3r/SVG.hpp b/xs/src/libslic3r/SVG.hpp index 3d459804c..3a5602196 100644 --- a/xs/src/libslic3r/SVG.hpp +++ b/xs/src/libslic3r/SVG.hpp @@ -93,6 +93,34 @@ public: { export_expolygons(path, get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); } static void export_expolygons(const std::string &path, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0) { export_expolygons(path.c_str(), get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); } + + struct ExPolygonAttributes + { + ExPolygonAttributes() : ExPolygonAttributes("gray", "black", "blue") {} + ExPolygonAttributes(const std::string &color) : + ExPolygonAttributes(color, color, color) {} + + ExPolygonAttributes( + const std::string &color_fill, + const std::string &color_contour, + const std::string &color_holes, + const coord_t outline_width = scale_(0.05), + const float fill_opacity = 0.5f) : + color_fill (color_fill), + color_contour (color_contour), + color_holes (color_holes), + outline_width (outline_width), + fill_opacity (fill_opacity) + {} + + std::string color_fill; + std::string color_contour; + std::string color_holes; + coord_t outline_width; + float fill_opacity; + }; + + static void export_expolygons(const char *path, const std::vector> &expolygons_with_attributes); }; } -- cgit v1.2.3