Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2017-03-02 18:32:43 +0300
committerbubnikv <bubnikv@gmail.com>2017-03-02 18:32:43 +0300
commit07fa15806fe9f0b31f7baeae0d59aba6ddf3cd7b (patch)
tree3668be567279fdf84a355269e246c471230d1911 /xs
parentdff5bda202a70807aaff4db90a291bb40aaa9950 (diff)
Utility function SVG::export_expolygons() to paint a set of possibly
overlapping ExPolygons with attributes.
Diffstat (limited to 'xs')
-rw-r--r--xs/src/libslic3r/SVG.cpp24
-rw-r--r--xs/src/libslic3r/SVG.hpp28
2 files changed, 52 insertions, 0 deletions
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<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &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<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &expolygons_with_attributes);
};
}