mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 09:47:58 -06:00
Added several drawing methods to Slic3r::SVG
This commit is contained in:
parent
713fcb5e8e
commit
5e100abe25
2 changed files with 39 additions and 22 deletions
|
@ -20,11 +20,11 @@ SVG::SVG(const char* filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SVG::AddLine(const Line &line)
|
SVG::draw(const Line &line, std::string stroke)
|
||||||
{
|
{
|
||||||
fprintf(this->f,
|
fprintf(this->f,
|
||||||
" <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-width: 2\"",
|
" <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: 1\"",
|
||||||
COORD(line.a.x), COORD(line.a.y), COORD(line.b.x), COORD(line.b.y)
|
COORD(line.a.x), COORD(line.a.y), COORD(line.b.x), COORD(line.b.y), stroke.c_str()
|
||||||
);
|
);
|
||||||
if (this->arrows)
|
if (this->arrows)
|
||||||
fprintf(this->f, " marker-end=\"url(#endArrow)\"");
|
fprintf(this->f, " marker-end=\"url(#endArrow)\"");
|
||||||
|
@ -34,30 +34,45 @@ SVG::AddLine(const Line &line)
|
||||||
void
|
void
|
||||||
SVG::AddLine(const IntersectionLine &line)
|
SVG::AddLine(const IntersectionLine &line)
|
||||||
{
|
{
|
||||||
this->AddLine(Line(line.a, line.b));
|
this->draw(Line(line.a, line.b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SVG::draw(const ExPolygon &expolygon)
|
SVG::draw(const ExPolygon &expolygon, std::string fill)
|
||||||
{
|
{
|
||||||
|
this->fill = fill;
|
||||||
|
|
||||||
std::string d;
|
std::string d;
|
||||||
Polygons pp = expolygon;
|
Polygons pp = expolygon;
|
||||||
for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
|
for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
|
||||||
d += this->get_path_d(*p) + " ";
|
d += this->get_path_d(*p, true) + " ";
|
||||||
}
|
}
|
||||||
this->path(d, true);
|
this->path(d, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SVG::draw(const Polygon &polygon)
|
SVG::draw(const Polygon &polygon, std::string fill)
|
||||||
{
|
{
|
||||||
this->path(this->get_path_d(polygon), true);
|
this->fill = fill;
|
||||||
|
this->path(this->get_path_d(polygon, true), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SVG::draw(const Polyline &polyline)
|
SVG::draw(const Polyline &polyline, std::string stroke)
|
||||||
{
|
{
|
||||||
this->path(this->get_path_d(polyline), false);
|
this->stroke = stroke;
|
||||||
|
this->path(this->get_path_d(polyline, false), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SVG::draw(const Point &point, std::string fill, unsigned int radius)
|
||||||
|
{
|
||||||
|
std::ostringstream svg;
|
||||||
|
svg << " <circle cx=\"" << COORD(point.x) << "\" cy=\"" << COORD(point.y)
|
||||||
|
<< "\" r=\"" << radius << "\" "
|
||||||
|
<< "style=\"stroke: none; fill: " << fill << "\" />";
|
||||||
|
|
||||||
|
fprintf(this->f, "%s\n", svg.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -65,24 +80,25 @@ SVG::path(const std::string &d, bool fill)
|
||||||
{
|
{
|
||||||
fprintf(
|
fprintf(
|
||||||
this->f,
|
this->f,
|
||||||
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %s; fill-type: evenodd\" />\n",
|
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %s; fill-type: evenodd\" %s />\n",
|
||||||
d.c_str(),
|
d.c_str(),
|
||||||
fill ? this->fill.c_str() : "none",
|
fill ? this->fill.c_str() : "none",
|
||||||
this->stroke.c_str(),
|
this->stroke.c_str(),
|
||||||
fill ? "0" : "2"
|
fill ? "0" : "2",
|
||||||
|
(this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
SVG::get_path_d(const MultiPoint &mp) const
|
SVG::get_path_d(const MultiPoint &mp, bool closed) const
|
||||||
{
|
{
|
||||||
std::ostringstream d;
|
std::ostringstream d;
|
||||||
d << "M ";
|
d << "M ";
|
||||||
for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) {
|
for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) {
|
||||||
d << " " << COORD(p->x);
|
d << COORD(p->x) << " ";
|
||||||
d << " " << COORD(p->y);
|
d << COORD(p->y) << " ";
|
||||||
}
|
}
|
||||||
d << " z";
|
if (closed) d << "z";
|
||||||
return d.str();
|
return d.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,12 @@ class SVG
|
||||||
std::string fill, stroke;
|
std::string fill, stroke;
|
||||||
|
|
||||||
SVG(const char* filename);
|
SVG(const char* filename);
|
||||||
void AddLine(const Line &line);
|
|
||||||
void AddLine(const IntersectionLine &line);
|
void AddLine(const IntersectionLine &line);
|
||||||
void draw(const ExPolygon &expolygon);
|
void draw(const Line &line, std::string stroke = "black");
|
||||||
void draw(const Polygon &polygon);
|
void draw(const ExPolygon &expolygon, std::string fill = "grey");
|
||||||
void draw(const Polyline &polyline);
|
void draw(const Polygon &polygon, std::string fill = "grey");
|
||||||
|
void draw(const Polyline &polyline, std::string stroke = "black");
|
||||||
|
void draw(const Point &point, std::string fill = "black", unsigned int radius = 3);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -27,7 +28,7 @@ class SVG
|
||||||
FILE* f;
|
FILE* f;
|
||||||
|
|
||||||
void path(const std::string &d, bool fill);
|
void path(const std::string &d, bool fill);
|
||||||
std::string get_path_d(const MultiPoint &polygon) const;
|
std::string get_path_d(const MultiPoint &mp, bool closed = false) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue