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

#include <src/libslic3r/SVG.hpp>

+ Collaboration diagram for Slic3r::SVG:

Classes

struct  ExPolygonAttributes
 

Public Member Functions

 SVG (const char *afilename)
 
 SVG (const char *afilename, const BoundingBox &bbox, const coord_t bbox_offset=scale_(1.), bool flipY=true)
 
 SVG (const std::string &filename)
 
 SVG (const std::string &filename, const BoundingBox &bbox, const coord_t bbox_offset=scale_(1.), bool flipY=true)
 
 ~SVG ()
 
bool open (const char *filename)
 
bool open (const char *filename, const BoundingBox &bbox, const coord_t bbox_offset=scale_(1.), bool flipY=true)
 
bool open (const std::string &filename)
 
bool open (const std::string &filename, const BoundingBox &bbox, const coord_t bbox_offset=scale_(1.), bool flipY=true)
 
void draw (const Line &line, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width=0)
 
void draw (const Lines &lines, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const ExPolygon &expolygon, std::string fill="grey", const float fill_opacity=1.f)
 
void draw_outline (const ExPolygon &polygon, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
void draw (const ExPolygons &expolygons, std::string fill="grey", const float fill_opacity=1.f)
 
void draw_outline (const ExPolygons &polygons, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
void draw (const Surface &surface, std::string fill="grey", const float fill_opacity=1.f)
 
void draw_outline (const Surface &surface, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
void draw (const Surfaces &surfaces, std::string fill="grey", const float fill_opacity=1.f)
 
void draw_outline (const Surfaces &surfaces, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
void draw (const SurfacesPtr &surfaces, std::string fill="grey", const float fill_opacity=1.f)
 
void draw_outline (const SurfacesPtr &surfaces, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
void draw (const Polygon &polygon, std::string fill="grey")
 
void draw_outline (const Polygon &polygon, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const Polygons &polygons, std::string fill="grey")
 
void draw_outline (const Polygons &polygons, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const Polyline &polyline, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const Polylines &polylines, std::string stroke="black", coordf_t stroke_width=0)
 
void draw (const ThickLines &thicklines, const std::string &fill="lime", const std::string &stroke="black", coordf_t stroke_width=0)
 
void draw (const ThickPolylines &polylines, const std::string &stroke="black", coordf_t stroke_width=0)
 
void draw (const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coordf_t stroke_width)
 
void draw (const Point &point, std::string fill="black", coord_t radius=0)
 
void draw (const Points &points, std::string fill="black", coord_t radius=0)
 
void draw (const ClipperLib::Path &polygon, double scale, std::string fill="grey", coordf_t stroke_width=0)
 
void draw (const ClipperLib::Paths &polygons, double scale, std::string fill="grey", coordf_t stroke_width=0)
 
void draw_text (const Point &pt, const char *text, const char *color, coordf_t font_size=20.f)
 
void draw_legend (const Point &pt, const char *text, const char *color, coordf_t font_size=10.f)
 
void Close ()
 

Static Public Member Functions

static void export_expolygons (const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
static void export_expolygons (const std::string &path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
static void export_expolygons (const char *path, const Slic3r::ExPolygons &expolygons, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
 
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)
 
static void export_expolygons (const char *path, const std::vector< std::pair< Slic3r::ExPolygons, ExPolygonAttributes > > &expolygons_with_attributes)
 
static void export_expolygons (const std::string &path, const std::vector< std::pair< Slic3r::ExPolygons, ExPolygonAttributes > > &expolygons_with_attributes)
 

Public Attributes

bool arrows
 
std::string fill
 
std::string stroke
 
Point origin
 
float height
 
bool flipY
 

Private Member Functions

void path (const std::string &d, bool fill, coordf_t stroke_width, const float fill_opacity)
 
std::string get_path_d (const MultiPoint &mp, bool closed=false) const
 
std::string get_path_d (const ClipperLib::Path &mp, double scale, bool closed=false) const
 
float to_svg_y (float x) const throw ()
 

Static Private Member Functions

static float to_svg_coord (float x) throw ()
 
static float to_svg_x (float x) throw ()
 

Private Attributes

std::string filename
 
FILE * f
 

Detailed Description

Constructor & Destructor Documentation

◆ SVG() [1/4]

Slic3r::SVG::SVG ( const char *  afilename)
inline
22 :
23 arrows(false), fill("grey"), stroke("black"), filename(afilename), flipY(false)
24 { open(filename); }
std::string fill
Definition SVG.hpp:17
std::string stroke
Definition SVG.hpp:17
bool flipY
Definition SVG.hpp:20
bool open(const char *filename)
Definition SVG.cpp:8
std::string filename
Definition SVG.hpp:81
bool arrows
Definition SVG.hpp:16

References filename, and open().

+ Here is the call graph for this function:

◆ SVG() [2/4]

Slic3r::SVG::SVG ( const char *  afilename,
const BoundingBox bbox,
const coord_t  bbox_offset = scale_(1.),
bool  flipY = true 
)
inline
25 :
26 arrows(false), fill("grey"), stroke("black"), filename(afilename), origin(bbox.min - Point(bbox_offset, bbox_offset)), flipY(flipY)
27 { open(filename, bbox, bbox_offset, flipY); }
Point origin
Definition SVG.hpp:18
Kernel::Point_2 Point
Definition point_areas.cpp:20

References filename, flipY, and open().

+ Here is the call graph for this function:

◆ SVG() [3/4]

Slic3r::SVG::SVG ( const std::string &  filename)
inline
28 :
29 arrows(false), fill("grey"), stroke("black"), filename(filename), flipY(false)
30 { open(filename); }

References filename, and open().

+ Here is the call graph for this function:

◆ SVG() [4/4]

Slic3r::SVG::SVG ( const std::string &  filename,
const BoundingBox bbox,
const coord_t  bbox_offset = scale_(1.),
bool  flipY = true 
)
inline
31 :
32 arrows(false), fill("grey"), stroke("black"), filename(filename), origin(bbox.min - Point(bbox_offset, bbox_offset)), flipY(flipY)
33 { open(filename, bbox, bbox_offset, flipY); }

References filename, flipY, and open().

+ Here is the call graph for this function:

◆ ~SVG()

Slic3r::SVG::~SVG ( )
inline
34{ if (f != NULL) Close(); }
FILE * f
Definition SVG.hpp:82
void Close()
Definition SVG.cpp:301

References Close(), and f.

+ Here is the call graph for this function:

Member Function Documentation

◆ Close()

◆ draw() [1/19]

void Slic3r::SVG::draw ( const ClipperLib::Path polygon,
double  scale,
std::string  fill = "grey",
coordf_t  stroke_width = 0 
)
210{
211 this->stroke = stroke;
212 this->path(this->get_path_d(polygon, scale, true), false, stroke_width, 1.f);
213}
int scale(const int val)
Definition WipeTowerDialog.cpp:14
void path(const std::string &d, bool fill, coordf_t stroke_width, const float fill_opacity)
Definition SVG.cpp:233
std::string get_path_d(const MultiPoint &mp, bool closed=false) const
Definition SVG.cpp:251

References get_path_d(), path(), scale(), and stroke.

+ Here is the call graph for this function:

◆ draw() [2/19]

void Slic3r::SVG::draw ( const ClipperLib::Paths polygons,
double  scale,
std::string  fill = "grey",
coordf_t  stroke_width = 0 
)
216{
217 for (ClipperLib::Paths::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
218 draw(*it, scale, stroke, stroke_width);
219}
void draw(const Line &line, std::string stroke="black", coordf_t stroke_width=0)
Definition SVG.cpp:49

References draw(), scale(), and stroke.

+ Here is the call graph for this function:

◆ draw() [3/19]

void Slic3r::SVG::draw ( const ExPolygon expolygon,
std::string  fill = "grey",
const float  fill_opacity = 1.f 
)
87{
88 this->fill = fill;
89
90 std::string d;
91 for (const Polygon &p : to_polygons(expolygon))
92 d += this->get_path_d(p, true) + " ";
93 this->path(d, true, 0, fill_opacity);
94}
Polygons to_polygons(const ExPolygon &src)
Definition ExPolygon.hpp:281

References fill, get_path_d(), path(), and Slic3r::to_polygons().

+ Here is the call graph for this function:

◆ draw() [4/19]

void Slic3r::SVG::draw ( const ExPolygons expolygons,
std::string  fill = "grey",
const float  fill_opacity = 1.f 
)
105{
106 for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++it)
107 this->draw(*it, fill, fill_opacity);
108}

References draw(), and fill.

+ Here is the call graph for this function:

◆ draw() [5/19]

void Slic3r::SVG::draw ( const Line line,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
50{
51 fprintf(this->f,
52 " <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: %f\"",
53 to_svg_x(line.a(0) - origin(0)), to_svg_y(line.a(1) - origin(1)), to_svg_x(line.b(0) - origin(0)), to_svg_y(line.b(1) - origin(1)), stroke.c_str(), (stroke_width == 0) ? 1.f : to_svg_coord(stroke_width));
54 if (this->arrows)
55 fprintf(this->f, " marker-end=\"url(#endArrow)\"");
56 fprintf(this->f, "/>\n");
57}
static float to_svg_coord(float x)
Definition SVG.cpp:381
float to_svg_y(float x) const
Definition SVG.hpp:172
static float to_svg_x(float x)
Definition SVG.hpp:171

References Slic3r::Line::a, arrows, Slic3r::Line::b, f, origin, stroke, to_svg_coord(), to_svg_x(), and to_svg_y().

Referenced by Slic3r::ExPolygon::contains(), Slic3r::contour_distance(), Slic3r::contour_distance2(), Slic3r::sla::anonymous_namespace{Pad.cpp}::create_pad_geometry(), Slic3r::detect_overhangs(), Slic3r::PrintObject::discover_vertical_shells(), Slic3r::MultiPoint::douglas_peucker(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), draw(), Slic3r::dump_voronoi_to_svg(), Slic3r::expolygons_to_zpaths_shrunk(), export_expolygons(), export_expolygons(), Slic3r::export_intersections_to_svg(), Slic3r::FFFSupport::export_print_z_polygons_and_extrusions_to_svg(), Slic3r::FFFSupport::export_print_z_polygons_to_svg(), Slic3r::LayerRegion::export_region_fill_surfaces_to_svg(), Slic3r::Layer::export_region_fill_surfaces_to_svg(), Slic3r::LayerRegion::export_region_slices_to_svg(), Slic3r::Layer::export_region_slices_to_svg(), Slic3r::SurfaceCollection::export_to_svg(), Slic3r::export_to_svg(), Slic3r::SupportGridPattern::extract_support(), Slic3r::FillRectilinear::fill_surface_by_lines(), Slic3r::generate_extra_perimeters_over_overhangs(), Slic3r::line_rounded_thick_segment_collision(), Slic3r::make_loops(), Slic3r::mark_boundary_segments_touching_infill(), Slic3r::Algorithm::merge_expansions_into_expolygons(), Slic3r::mittered_offset_path_scaled(), Slic3r::FFFSupport::modulate_extrusion_by_overlapping_layers(), Slic3r::ExPolygon::overlaps(), priv::select_patches(), Slic3r::slice_mesh(), Slic3r::slice_region_by_vertical_lines(), Slic3r::Arachne::WallToolPaths::stitchToolPaths(), Slic3r::sla::SupportPointGenerator::uniformly_cover(), and priv::visualize_heal().

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

◆ draw() [6/19]

void Slic3r::SVG::draw ( const Lines lines,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
81{
82 for (const Line &l : lines)
83 this->draw(l, stroke, stroke_width);
84}

References draw(), and stroke.

+ Here is the call graph for this function:

◆ draw() [7/19]

void Slic3r::SVG::draw ( const Point point,
std::string  fill = "black",
coord_t  radius = 0 
)
193{
194 float radius = (iradius == 0) ? 3.f : to_svg_coord(iradius);
195 std::ostringstream svg;
196 svg << " <circle cx=\"" << to_svg_x(point(0) - origin(0)) << "\" cy=\"" << to_svg_y(point(1) - origin(1))
197 << "\" r=\"" << radius << "\" "
198 << "style=\"stroke: none; fill: " << fill << "\" />";
199
200 fprintf(this->f, "%s\n", svg.str().c_str());
201}

References f, fill, origin, to_svg_coord(), to_svg_x(), and to_svg_y().

+ Here is the call graph for this function:

◆ draw() [8/19]

void Slic3r::SVG::draw ( const Points points,
std::string  fill = "black",
coord_t  radius = 0 
)
204{
205 for (Points::const_iterator it = points.begin(); it != points.end(); ++it)
206 this->draw(*it, fill, radius);
207}

References draw(), and fill.

+ Here is the call graph for this function:

◆ draw() [9/19]

void Slic3r::SVG::draw ( const Polygon polygon,
std::string  fill = "grey" 
)
151{
152 this->fill = fill;
153 this->path(this->get_path_d(polygon, true), !fill.empty(), 0, 1.f);
154}

References fill, get_path_d(), and path().

+ Here is the call graph for this function:

◆ draw() [10/19]

void Slic3r::SVG::draw ( const Polygons polygons,
std::string  fill = "grey" 
)
157{
158 for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++it)
159 this->draw(*it, fill);
160}

References draw(), and fill.

+ Here is the call graph for this function:

◆ draw() [11/19]

void Slic3r::SVG::draw ( const Polyline polyline,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
163{
164 this->stroke = stroke;
165 this->path(this->get_path_d(polyline, false), false, stroke_width, 1.f);
166}

References get_path_d(), path(), and stroke.

+ Here is the call graph for this function:

◆ draw() [12/19]

void Slic3r::SVG::draw ( const Polylines polylines,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
169{
170 for (Polylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it)
171 this->draw(*it, stroke, stroke_width);
172}

References draw(), and stroke.

+ Here is the call graph for this function:

◆ draw() [13/19]

void Slic3r::SVG::draw ( const Surface surface,
std::string  fill = "grey",
const float  fill_opacity = 1.f 
)
117{
118 draw(surface.expolygon, fill, fill_opacity);
119}

References draw(), Slic3r::Surface::expolygon, and fill.

+ Here is the call graph for this function:

◆ draw() [14/19]

void Slic3r::SVG::draw ( const Surfaces surfaces,
std::string  fill = "grey",
const float  fill_opacity = 1.f 
)
127{
128 for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
129 this->draw(*it, fill, fill_opacity);
130}

References draw(), and fill.

+ Here is the call graph for this function:

◆ draw() [15/19]

void Slic3r::SVG::draw ( const SurfacesPtr surfaces,
std::string  fill = "grey",
const float  fill_opacity = 1.f 
)
139{
140 for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
141 this->draw(*(*it), fill, fill_opacity);
142}

References draw(), and fill.

+ Here is the call graph for this function:

◆ draw() [16/19]

void Slic3r::SVG::draw ( const ThickLine line,
const std::string &  fill,
const std::string &  stroke,
coordf_t  stroke_width = 0 
)
60{
61 Vec2d dir(line.b(0)-line.a(0), line.b(1)-line.a(1));
62 Vec2d perp(-dir(1), dir(0));
63 coordf_t len = sqrt(perp(0)*perp(0) + perp(1)*perp(1));
64 coordf_t da = coordf_t(0.5)*line.a_width/len;
65 coordf_t db = coordf_t(0.5)*line.b_width/len;
66 fprintf(this->f,
67 " <polygon points=\"%f,%f %f,%f %f,%f %f,%f\" style=\"fill:%s; stroke: %s; stroke-width: %f\"/>\n",
68 to_svg_x(line.a(0)-da*perp(0)-origin(0)),
69 to_svg_y(line.a(1)-da*perp(1)-origin(1)),
70 to_svg_x(line.b(0)-db*perp(0)-origin(0)),
71 to_svg_y(line.b(1)-db*perp(1)-origin(1)),
72 to_svg_x(line.b(0)+db*perp(0)-origin(0)),
73 to_svg_y(line.b(1)+db*perp(1)-origin(1)),
74 to_svg_x(line.a(0)+da*perp(0)-origin(0)),
75 to_svg_y(line.a(1)+da*perp(1)-origin(1)),
76 fill.c_str(), stroke.c_str(),
77 (stroke_width == 0) ? 1.f : to_svg_coord(stroke_width));
78}
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
double coordf_t
Definition libslic3r.h:45
double coordf_t
Definition GUI_ObjectList.hpp:36
Eigen::Matrix< typename Derived::Scalar, 2, 1, Eigen::DontAlign > perp(const Eigen::MatrixBase< Derived > &v)
Definition Point.hpp:104
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51

References Slic3r::Line::a, Slic3r::ThickLine::a_width, Slic3r::Line::b, Slic3r::ThickLine::b_width, f, fill, origin, Slic3r::perp(), sqrt(), stroke, to_svg_coord(), to_svg_x(), and to_svg_y().

+ Here is the call graph for this function:

◆ draw() [17/19]

void Slic3r::SVG::draw ( const ThickLines thicklines,
const std::string &  fill = "lime",
const std::string &  stroke = "black",
coordf_t  stroke_width = 0 
)
175{
176 for (ThickLines::const_iterator it = thicklines.begin(); it != thicklines.end(); ++it)
177 this->draw(*it, fill, stroke, stroke_width);
178}

References draw(), fill, and stroke.

+ Here is the call graph for this function:

◆ draw() [18/19]

void Slic3r::SVG::draw ( const ThickPolylines polylines,
const std::string &  stroke = "black",
coordf_t  stroke_width = 0 
)
181{
182 for (const ThickPolyline &pl : polylines)
183 this->draw(Polyline(pl.points), stroke, stroke_width);
184}

References draw(), and stroke.

+ Here is the call graph for this function:

◆ draw() [19/19]

void Slic3r::SVG::draw ( const ThickPolylines thickpolylines,
const std::string &  fill,
const std::string &  stroke,
coordf_t  stroke_width 
)
187{
188 for (ThickPolylines::const_iterator it = thickpolylines.begin(); it != thickpolylines.end(); ++ it)
189 draw(it->thicklines(), fill, stroke, stroke_width);
190}

References draw(), fill, and stroke.

+ Here is the call graph for this function:

◆ draw_legend()

void Slic3r::SVG::draw_legend ( const Point pt,
const char *  text,
const char *  color,
coordf_t  font_size = 10.f 
)
286{
287 fprintf(this->f,
288 R"(<circle cx="%f" cy="%f" r="%f" fill="%s"/>)",
289 to_svg_x(float(pt.x() - origin.x())),
290 to_svg_y(float(pt.y() - origin.y())),
291 font_size,
292 color);
293 fprintf(this->f,
294 R"(<text x="%f" y="%f" font-family="sans-serif" font-size="%fpx" fill="%s">%s</text>)",
295 to_svg_x(float(pt.x() - origin.x())) + 20.f,
296 to_svg_y(float(pt.y() - origin.y())),
297 font_size,
298 "black", text);
299}

References f, origin, to_svg_x(), and to_svg_y().

Referenced by export_expolygons(), Slic3r::FFFSupport::export_support_surface_type_legend_to_svg(), and Slic3r::export_surface_type_legend_to_svg().

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

◆ draw_outline() [1/7]

void Slic3r::SVG::draw_outline ( const ExPolygon polygon,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
97{
98 draw_outline(expolygon.contour, stroke_outer, stroke_width);
99 for (Polygons::const_iterator it = expolygon.holes.begin(); it != expolygon.holes.end(); ++ it) {
100 draw_outline(*it, stroke_holes, stroke_width);
101 }
102}
void draw_outline(const ExPolygon &polygon, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
Definition SVG.cpp:96

References Slic3r::ExPolygon::contour, draw_outline(), and Slic3r::ExPolygon::holes.

Referenced by Slic3r::Arachne::SkeletalTrapezoidation::constructFromPolygons(), Slic3r::ExPolygon::contains(), Slic3r::contour_distance(), Slic3r::contour_distance2(), Slic3r::PrintObject::discover_vertical_shells(), draw_outline(), draw_outline(), draw_outline(), draw_outline(), draw_outline(), draw_outline(), Slic3r::dump_voronoi_to_svg(), export_expolygons(), export_expolygons(), Slic3r::export_intersections_to_svg(), Slic3r::LayerRegion::export_region_fill_surfaces_to_svg(), Slic3r::SupportGridPattern::extract_support(), Slic3r::Algorithm::merge_expansions_into_expolygons(), Slic3r::mittered_offset_path_scaled(), Slic3r::ExPolygon::overlaps(), Slic3r::slice_mesh(), Slic3r::slice_region_by_vertical_lines(), and Slic3r::Arachne::WallToolPaths::stitchToolPaths().

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

◆ draw_outline() [2/7]

void Slic3r::SVG::draw_outline ( const ExPolygons polygons,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
111{
112 for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++ it)
113 draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
114}

References draw_outline().

+ Here is the call graph for this function:

◆ draw_outline() [3/7]

void Slic3r::SVG::draw_outline ( const Polygon polygon,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
222{
223 this->stroke = stroke;
224 this->path(this->get_path_d(polygon, true), false, stroke_width, 1.f);
225}

References get_path_d(), path(), and stroke.

+ Here is the call graph for this function:

◆ draw_outline() [4/7]

void Slic3r::SVG::draw_outline ( const Polygons polygons,
std::string  stroke = "black",
coordf_t  stroke_width = 0 
)
228{
229 for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++ it)
230 draw_outline(*it, stroke, stroke_width);
231}

References draw_outline(), and stroke.

+ Here is the call graph for this function:

◆ draw_outline() [5/7]

void Slic3r::SVG::draw_outline ( const Surface surface,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
122{
123 draw_outline(surface.expolygon, stroke_outer, stroke_holes, stroke_width);
124}

References draw_outline(), and Slic3r::Surface::expolygon.

+ Here is the call graph for this function:

◆ draw_outline() [6/7]

void Slic3r::SVG::draw_outline ( const Surfaces surfaces,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
133{
134 for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
135 draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
136}

References draw_outline().

+ Here is the call graph for this function:

◆ draw_outline() [7/7]

void Slic3r::SVG::draw_outline ( const SurfacesPtr surfaces,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
145{
146 for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
147 draw_outline(*(*it), stroke_outer, stroke_holes, stroke_width);
148}

References draw_outline().

+ Here is the call graph for this function:

◆ draw_text()

void Slic3r::SVG::draw_text ( const Point pt,
const char *  text,
const char *  color,
coordf_t  font_size = 20.f 
)
276{
277 fprintf(this->f,
278 R"(<text x="%f" y="%f" font-family="sans-serif" font-size="%fpx" fill="%s">%s</text>)",
279 to_svg_x(float(pt.x() - origin.x())),
280 to_svg_y(float(pt.y() - origin.y())),
281 font_size,
282 color, text);
283}

References f, origin, to_svg_x(), and to_svg_y().

Referenced by Slic3r::SurfaceCollection::export_to_svg(), and priv::select_patches().

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

◆ export_expolygons() [1/6]

void Slic3r::SVG::export_expolygons ( const char *  path,
const BoundingBox bbox,
const Slic3r::ExPolygons expolygons,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
static
310{
311 SVG svg(path, bbox);
312 svg.draw(expolygons);
313 svg.draw_outline(expolygons, stroke_outer, stroke_holes, stroke_width);
314 svg.Close();
315}
SVG(const char *afilename)
Definition SVG.hpp:22

References Close(), draw(), draw_outline(), and path().

Referenced by Slic3r::detect_overhangs(), Slic3r::elephant_foot_compensation(), export_expolygons(), export_expolygons(), export_expolygons(), export_expolygons(), Slic3r::SupportGridPattern::extract_support(), Slic3r::PrintObjectSupportMaterial::generate(), Slic3r::FFFTreeSupport::generate_overhangs(), Slic3r::FFFTreeSupport::TreeModelVolumes::precalculate(), and Slic3r::FFFSupport::remove_bridges_from_contacts().

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

◆ export_expolygons() [2/6]

static void Slic3r::SVG::export_expolygons ( const char *  path,
const Slic3r::ExPolygons expolygons,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
inlinestatic
93 { export_expolygons(path, get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); }
static void export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer="black", std::string stroke_holes="blue", coordf_t stroke_width=0)
Definition SVG.cpp:309
BoundingBox get_extents(const ExPolygon &expolygon)
Definition ExPolygon.cpp:352

References export_expolygons(), Slic3r::get_extents(), and path().

+ Here is the call graph for this function:

◆ export_expolygons() [3/6]

void Slic3r::SVG::export_expolygons ( const char *  path,
const std::vector< std::pair< Slic3r::ExPolygons, ExPolygonAttributes > > &  expolygons_with_attributes 
)
static
325{
326 if (expolygons_with_attributes.empty())
327 return;
328
329 size_t num_legend = std::count_if(expolygons_with_attributes.begin(), expolygons_with_attributes.end(), [](const auto &v){ return ! v.second.legend.empty(); });
330 // Format in num_columns.
331 size_t num_columns = 3;
332 // Width of the column.
333 coord_t step_x = scale_(20.);
334 Point legend_size(scale_(1.) + num_columns * step_x, scale_(0.4 + 1.3 * (num_legend + num_columns - 1) / num_columns));
335
336 BoundingBox bbox = get_extents(expolygons_with_attributes.front().first);
337 for (size_t i = 0; i < expolygons_with_attributes.size(); ++ i)
338 bbox.merge(get_extents(expolygons_with_attributes[i].first));
339 // Legend y.
340 coord_t pos_y = bbox.max.y() + scale_(1.5);
341 bbox.merge(Point(std::max(bbox.min.x() + legend_size.x(), bbox.max.x()), bbox.max.y() + legend_size.y()));
342
343 SVG svg(path, bbox);
344 for (const auto &exp_with_attr : expolygons_with_attributes)
345 svg.draw(exp_with_attr.first, exp_with_attr.second.color_fill, exp_with_attr.second.fill_opacity);
346 for (const auto &exp_with_attr : expolygons_with_attributes) {
347 if (exp_with_attr.second.outline_width > 0) {
348 std::string color_contour = exp_with_attr.second.color_contour;
349 if (color_contour.empty())
350 color_contour = exp_with_attr.second.color_fill;
351 std::string color_holes = exp_with_attr.second.color_holes;
352 if (color_holes.empty())
353 color_holes = color_contour;
354 svg.draw_outline(exp_with_attr.first, color_contour, color_holes, exp_with_attr.second.outline_width);
355 }
356 }
357 for (const auto &exp_with_attr : expolygons_with_attributes)
358 if (exp_with_attr.second.radius_points > 0)
359 for (const ExPolygon &expoly : exp_with_attr.first)
360 svg.draw(to_points(expoly), exp_with_attr.second.color_points, exp_with_attr.second.radius_points);
361
362 // Export legend.
363 // 1st row
364 coord_t pos_x0 = bbox.min.x() + scale_(1.);
365 coord_t pos_x = pos_x0;
366 size_t i_legend = 0;
367 for (const auto &exp_with_attr : expolygons_with_attributes) {
368 if (! exp_with_attr.second.legend.empty()) {
369 svg.draw_legend(Point(pos_x, pos_y), exp_with_attr.second.legend.c_str(), exp_with_attr.second.color_fill.c_str());
370 if ((++ i_legend) % num_columns == 0) {
371 pos_x = pos_x0;
372 pos_y += scale_(1.3);
373 } else {
374 pos_x += step_x;
375 }
376 }
377 }
378 svg.Close();
379}
#define const
Definition getopt.c:38
if(!(yy_init))
Definition lexer.c:1190
#define scale_(val)
Definition libslic3r.h:69
int32_t coord_t
Definition libslic3r.h:39
Points to_points(const ExPolygons &src)
Definition ExPolygon.hpp:196

References Close(), draw(), draw_legend(), draw_outline(), Slic3r::get_extents(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::merge(), Slic3r::BoundingBoxBase< PointType, APointsType >::min, path(), scale_, and Slic3r::to_points().

+ Here is the call graph for this function:

◆ export_expolygons() [4/6]

static void Slic3r::SVG::export_expolygons ( const std::string &  path,
const BoundingBox bbox,
const Slic3r::ExPolygons expolygons,
std::string  stroke_outer = "black",
std::string  stroke_holes = "blue",
coordf_t  stroke_width = 0 
)
inlinestatic
91 { export_expolygons(path.c_str(), bbox, expolygons, stroke_outer, stroke_holes, stroke_width); }

References export_expolygons(), and path().

+ Here is the call graph for this function:

◆ export_expolygons() [5/6]

static void Slic3r::SVG::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 
)
inlinestatic
95 { export_expolygons(path.c_str(), get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); }

References export_expolygons(), Slic3r::get_extents(), and path().

+ Here is the call graph for this function:

◆ export_expolygons() [6/6]

static void Slic3r::SVG::export_expolygons ( const std::string &  path,
const std::vector< std::pair< Slic3r::ExPolygons, ExPolygonAttributes > > &  expolygons_with_attributes 
)
inlinestatic
167 { export_expolygons(path.c_str(), expolygons_with_attributes); }

References export_expolygons(), and path().

+ Here is the call graph for this function:

◆ get_path_d() [1/2]

std::string Slic3r::SVG::get_path_d ( const ClipperLib::Path mp,
double  scale,
bool  closed = false 
) const
private
264{
265 std::ostringstream d;
266 d << "M ";
267 for (ClipperLib::Path::const_iterator p = path.begin(); p != path.end(); ++p) {
268 d << to_svg_x(scale * p->x() - origin(0)) << " ";
269 d << to_svg_y(scale * p->y() - origin(1)) << " ";
270 }
271 if (closed) d << "z";
272 return d.str();
273}

References origin, path(), scale(), to_svg_x(), and to_svg_y().

+ Here is the call graph for this function:

◆ get_path_d() [2/2]

std::string Slic3r::SVG::get_path_d ( const MultiPoint mp,
bool  closed = false 
) const
private
252{
253 std::ostringstream d;
254 d << "M ";
255 for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) {
256 d << to_svg_x((*p)(0) - origin(0)) << " ";
257 d << to_svg_y((*p)(1) - origin(1)) << " ";
258 }
259 if (closed) d << "z";
260 return d.str();
261}

References origin, Slic3r::MultiPoint::points, to_svg_x(), and to_svg_y().

Referenced by draw(), draw(), draw(), draw(), and draw_outline().

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

◆ open() [1/4]

bool Slic3r::SVG::open ( const char *  filename)
9{
10 this->filename = afilename;
11 this->f = boost::nowide::fopen(afilename, "w");
12 if (this->f == NULL)
13 return false;
14 fprintf(this->f,
15 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
16 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
17 "<svg height=\"2000\" width=\"2000\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
18 " <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
19 " <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
20 " </marker>\n"
21 );
22 fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", 2000.f, 2000.f);
23 return true;
24}

References f, and filename.

Referenced by SVG(), SVG(), SVG(), SVG(), open(), and open().

+ Here is the caller graph for this function:

◆ open() [2/4]

bool Slic3r::SVG::open ( const char *  filename,
const BoundingBox bbox,
const coord_t  bbox_offset = scale_(1.),
bool  flipY = true 
)
27{
28 this->filename = afilename;
29 this->origin = bbox.min - Point(bbox_offset, bbox_offset);
30 this->flipY = aflipY;
31 this->f = boost::nowide::fopen(afilename, "w");
32 if (f == NULL)
33 return false;
34 float w = to_svg_coord(bbox.max(0) - bbox.min(0) + 2 * bbox_offset);
35 float h = to_svg_coord(bbox.max(1) - bbox.min(1) + 2 * bbox_offset);
36 this->height = h;
37 fprintf(this->f,
38 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
39 "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
40 "<svg height=\"%f\" width=\"%f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
41 " <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
42 " <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
43 " </marker>\n",
44 h, w);
45 fprintf(this->f, "<rect fill='white' stroke='none' x='0' y='0' width='%f' height='%f'/>\n", w, h);
46 return true;
47}
float height
Definition SVG.hpp:19

References f, filename, flipY, height, Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, origin, and to_svg_coord().

+ Here is the call graph for this function:

◆ open() [3/4]

bool Slic3r::SVG::open ( const std::string &  filename)
inline
39 { return open(filename.c_str()); }

References filename, and open().

+ Here is the call graph for this function:

◆ open() [4/4]

bool Slic3r::SVG::open ( const std::string &  filename,
const BoundingBox bbox,
const coord_t  bbox_offset = scale_(1.),
bool  flipY = true 
)
inline
41 { return open(filename.c_str(), bbox, bbox_offset, flipY); }

References filename, flipY, and open().

+ Here is the call graph for this function:

◆ path()

void Slic3r::SVG::path ( const std::string &  d,
bool  fill,
coordf_t  stroke_width,
const float  fill_opacity 
)
private
234{
235 float lineWidth = 0.f;
236 if (! fill)
237 lineWidth = (stroke_width == 0) ? 2.f : to_svg_coord(stroke_width);
238
239 fprintf(
240 this->f,
241 " <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %f; fill-type: evenodd\" %s fill-opacity=\"%f\" />\n",
242 d.c_str(),
243 fill ? this->fill.c_str() : "none",
244 this->stroke.c_str(),
245 lineWidth,
246 (this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : "",
247 fill_opacity
248 );
249}

References arrows, f, fill, stroke, and to_svg_coord().

Referenced by draw(), draw(), draw(), draw(), draw_outline(), export_expolygons(), export_expolygons(), export_expolygons(), export_expolygons(), export_expolygons(), export_expolygons(), and get_path_d().

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

◆ to_svg_coord()

float Slic3r::SVG::to_svg_coord ( float  x)
throw (
)
staticprivate
382{
383 // return x;
384 return unscale<float>(x) * 10.f;
385}

Referenced by draw(), draw(), draw(), open(), path(), to_svg_x(), and to_svg_y().

+ Here is the caller graph for this function:

◆ to_svg_x()

static float Slic3r::SVG::to_svg_x ( float  x)
throw (
)
inlinestaticprivate
171{ return to_svg_coord(x); }

References to_svg_coord().

Referenced by draw(), draw(), draw(), draw_legend(), draw_text(), get_path_d(), and get_path_d().

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

◆ to_svg_y()

float Slic3r::SVG::to_svg_y ( float  x) const
throw (
)
inlineprivate
172{ return flipY ? this->height - to_svg_coord(x) : to_svg_coord(x); }
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

References flipY, and to_svg_coord().

Referenced by draw(), draw(), draw(), draw_legend(), draw_text(), get_path_d(), and get_path_d().

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

Member Data Documentation

◆ arrows

bool Slic3r::SVG::arrows

Referenced by draw(), and path().

◆ f

FILE* Slic3r::SVG::f
private

◆ filename

std::string Slic3r::SVG::filename
private

Referenced by SVG(), SVG(), SVG(), SVG(), open(), open(), open(), and open().

◆ fill

std::string Slic3r::SVG::fill

◆ flipY

bool Slic3r::SVG::flipY

Referenced by SVG(), SVG(), open(), open(), and to_svg_y().

◆ height

float Slic3r::SVG::height

Referenced by open().

◆ origin

Point Slic3r::SVG::origin

◆ stroke

std::string Slic3r::SVG::stroke

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