Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
libnest2d::svg::SVGWriter< RawShape > Class Template Reference

#include <src/libnest2d/tools/svgtools.hpp>

+ Collaboration diagram for libnest2d::svg::SVGWriter< RawShape >:

Classes

struct  Config
 

Public Types

enum  OrigoLocation { TOPLEFT , BOTTOMLEFT }
 

Public Member Functions

 SVGWriter (const Config &conf=Config())
 
void setSize (const Box &box)
 
void writeShape (RawShape tsh)
 
void writeItem (const Item &item)
 
void writePackGroup (const PackGroup &result)
 
template<class ItemIt >
void writeItems (ItemIt from, ItemIt to)
 
void addLayer ()
 
void finishLayer ()
 
void save (const std::string &filepath)
 

Private Types

using Item = _Item< RawShape >
 
using Coord = TCoord< TPoint< RawShape > >
 
using Box = _Box< TPoint< RawShape > >
 
using PackGroup = _PackGroup< RawShape >
 

Private Member Functions

std::string & currentLayer ()
 
const std::string header () const
 

Private Attributes

Config conf_
 
std::vector< std::string > svg_layers_
 
bool finished_ = false
 

Detailed Description

template<class RawShape>
class libnest2d::svg::SVGWriter< RawShape >

Member Typedef Documentation

◆ Box

template<class RawShape >
using libnest2d::svg::SVGWriter< RawShape >::Box = _Box<TPoint<RawShape> >
private

◆ Coord

template<class RawShape >
using libnest2d::svg::SVGWriter< RawShape >::Coord = TCoord<TPoint<RawShape> >
private

◆ Item

template<class RawShape >
using libnest2d::svg::SVGWriter< RawShape >::Item = _Item<RawShape>
private

◆ PackGroup

template<class RawShape >
using libnest2d::svg::SVGWriter< RawShape >::PackGroup = _PackGroup<RawShape>
private

Member Enumeration Documentation

◆ OrigoLocation

template<class RawShape >
enum libnest2d::svg::SVGWriter::OrigoLocation
Enumerator
TOPLEFT 
BOTTOMLEFT 
21 {
22 TOPLEFT,
24 };
@ TOPLEFT
Definition svgtools.hpp:22
@ BOTTOMLEFT
Definition svgtools.hpp:23

Constructor & Destructor Documentation

◆ SVGWriter()

template<class RawShape >
libnest2d::svg::SVGWriter< RawShape >::SVGWriter ( const Config conf = Config())
inline
42 :
43 conf_(conf) {}
Config conf_
Definition svgtools.hpp:37

Member Function Documentation

◆ addLayer()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::addLayer ( )
inline
97 {
98 svg_layers_.emplace_back(header());
99 finished_ = false;
100 }
bool finished_
Definition svgtools.hpp:39
std::vector< std::string > svg_layers_
Definition svgtools.hpp:38
const std::string header() const
Definition svgtools.hpp:124

References libnest2d::svg::SVGWriter< RawShape >::finished_, libnest2d::svg::SVGWriter< RawShape >::header(), and libnest2d::svg::SVGWriter< RawShape >::svg_layers_.

Referenced by libnest2d::svg::SVGWriter< RawShape >::writePackGroup(), and libnest2d::svg::SVGWriter< RawShape >::writeShape().

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

◆ currentLayer()

template<class RawShape >
std::string & libnest2d::svg::SVGWriter< RawShape >::currentLayer ( )
inlineprivate
122{ return svg_layers_.back(); }

References libnest2d::svg::SVGWriter< RawShape >::svg_layers_.

Referenced by libnest2d::svg::SVGWriter< RawShape >::finishLayer(), and libnest2d::svg::SVGWriter< RawShape >::writeShape().

+ Here is the caller graph for this function:

◆ finishLayer()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::finishLayer ( )
inline
102 {
103 currentLayer() += "\n</svg>\n";
104 finished_ = true;
105 }
std::string & currentLayer()
Definition svgtools.hpp:122

References libnest2d::svg::SVGWriter< RawShape >::currentLayer(), and libnest2d::svg::SVGWriter< RawShape >::finished_.

Referenced by libnest2d::svg::SVGWriter< RawShape >::writePackGroup().

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

◆ header()

template<class RawShape >
const std::string libnest2d::svg::SVGWriter< RawShape >::header ( ) const
inlineprivate
124 {
125 std::string svg_header =
126R"raw(<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
127<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
128<svg height=")raw";
129 svg_header += std::to_string(conf_.height) + "\" width=\"" + std::to_string(conf_.width) + "\" ";
130 svg_header += R"raw(xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">)raw";
double width
Definition svgtools.hpp:29
double height
Definition svgtools.hpp:29

References libnest2d::svg::SVGWriter< RawShape >::conf_, libnest2d::svg::SVGWriter< RawShape >::Config::height, and libnest2d::svg::SVGWriter< RawShape >::Config::width.

Referenced by libnest2d::svg::SVGWriter< RawShape >::addLayer().

+ Here is the caller graph for this function:

◆ save()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::save ( const std::string &  filepath)
inline
107 {
108 size_t lyrc = svg_layers_.size() > 1? 1 : 0;
109 size_t last = svg_layers_.size() > 1? svg_layers_.size() : 0;
110
111 for(auto& lyr : svg_layers_) {
112 std::fstream out(filepath + (lyrc > 0? std::to_string(lyrc) : "") +
113 ".svg", std::fstream::out);
114 if(out.is_open()) out << lyr;
115 if(lyrc == last && !finished_) out << "\n</svg>\n";
116 out.flush(); out.close(); lyrc++;
117 };
118 }
STL namespace.

References libnest2d::svg::SVGWriter< RawShape >::finished_, and libnest2d::svg::SVGWriter< RawShape >::svg_layers_.

◆ setSize()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::setSize ( const Box box)
inline
45 {
46 conf_.height = static_cast<double>(box.height()) /
48 conf_.width = static_cast<double>(box.width()) /
50 }
Coord mm_in_coord_units
Definition svgtools.hpp:28

References libnest2d::svg::SVGWriter< RawShape >::conf_, libnest2d::_Box< P >::height(), libnest2d::svg::SVGWriter< RawShape >::Config::height, libnest2d::svg::SVGWriter< RawShape >::Config::mm_in_coord_units, libnest2d::_Box< P >::width(), and libnest2d::svg::SVGWriter< RawShape >::Config::width.

+ Here is the call graph for this function:

◆ writeItem()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::writeItem ( const Item item)
inline
71 {
72 writeShape(item.transformedShape());
73 }
void writeShape(RawShape tsh)
Definition svgtools.hpp:52

References libnest2d::_Item< RawShape >::transformedShape(), and libnest2d::svg::SVGWriter< RawShape >::writeShape().

Referenced by libnest2d::svg::SVGWriter< RawShape >::writePackGroup().

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

◆ writeItems()

template<class RawShape >
template<class ItemIt >
void libnest2d::svg::SVGWriter< RawShape >::writeItems ( ItemIt  from,
ItemIt  to 
)
inline
85 {
86 auto it = from;
87 PackGroup pg;
88 while(it != to) {
89 if(it->binId() == BIN_ID_UNSET) continue;
90 while(pg.size() <= size_t(it->binId())) pg.emplace_back();
91 pg[it->binId()].emplace_back(*it);
92 ++it;
93 }
95 }
void writePackGroup(const PackGroup &result)
Definition svgtools.hpp:75
_PackGroup< RawShape > PackGroup
Definition svgtools.hpp:17
static const constexpr int BIN_ID_UNSET
Definition nester.hpp:15

References libnest2d::BIN_ID_UNSET, and libnest2d::svg::SVGWriter< RawShape >::writePackGroup().

+ Here is the call graph for this function:

◆ writePackGroup()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::writePackGroup ( const PackGroup result)
inline
75 {
76 for(auto r : result) {
77 addLayer();
78 for(Item& sh : r) {
79 writeItem(sh);
80 }
82 }
83 }
void finishLayer()
Definition svgtools.hpp:102
void writeItem(const Item &item)
Definition svgtools.hpp:71
_Item< RawShape > Item
Definition svgtools.hpp:14
void addLayer()
Definition svgtools.hpp:97

References libnest2d::svg::SVGWriter< RawShape >::addLayer(), libnest2d::svg::SVGWriter< RawShape >::finishLayer(), and libnest2d::svg::SVGWriter< RawShape >::writeItem().

Referenced by libnest2d::svg::SVGWriter< RawShape >::writeItems().

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

◆ writeShape()

template<class RawShape >
void libnest2d::svg::SVGWriter< RawShape >::writeShape ( RawShape  tsh)
inline
52 {
53 if(svg_layers_.empty()) addLayer();
55 auto d = static_cast<Coord>(
56 std::round(conf_.height*conf_.mm_in_coord_units) );
57
58 auto& contour = shapelike::contour(tsh);
59 for(auto& v : contour) setY(v, -getY(v) + d);
60
61 auto& holes = shapelike::holes(tsh);
62 for(auto& h : holes) for(auto& v : h) setY(v, -getY(v) + d);
63
64 }
65 currentLayer() +=
66 shapelike::serialize<Formats::SVG>(tsh,
68 "\n";
69 }
TCoord< TPoint< RawShape > > Coord
Definition svgtools.hpp:15
Slic3r::Polygon & contour(Slic3r::ExPolygon &sh)
Definition geometries.hpp:216
const THolesContainer< PolygonImpl > & holes(const Slic3r::ExPolygon &sh)
Definition geometries.hpp:189
void setY(P &p, const TCoord< P > &val)
Definition geometry_traits.hpp:436
TCoord< P > getY(const P &p)
Definition geometry_traits.hpp:427
OrigoLocation origo_location
Definition svgtools.hpp:27

References libnest2d::svg::SVGWriter< RawShape >::addLayer(), libnest2d::svg::SVGWriter< RawShape >::BOTTOMLEFT, libnest2d::svg::SVGWriter< RawShape >::conf_, libnest2d::shapelike::contour(), libnest2d::svg::SVGWriter< RawShape >::currentLayer(), libnest2d::getY(), libnest2d::svg::SVGWriter< RawShape >::Config::height, libnest2d::shapelike::holes(), libnest2d::svg::SVGWriter< RawShape >::Config::mm_in_coord_units, libnest2d::svg::SVGWriter< RawShape >::Config::origo_location, libnest2d::setY(), and libnest2d::svg::SVGWriter< RawShape >::svg_layers_.

Referenced by libnest2d::svg::SVGWriter< RawShape >::writeItem().

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

Member Data Documentation

◆ conf_

◆ finished_

◆ svg_layers_


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