diff options
author | jaseg <git@jaseg.de> | 2021-04-25 14:41:06 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-04-25 14:41:06 +0200 |
commit | 1d6d4e4f14b395b7a16802ac909687dfa2b447e4 (patch) | |
tree | 3c20d6feb569d1011ba9ba4164f1d5d04e9fa5fa | |
parent | 046e827be1bec795ab5baf064744be3dc011f0e9 (diff) | |
download | gerbolyze-1d6d4e4f14b395b7a16802ac909687dfa2b447e4.tar.gz gerbolyze-1d6d4e4f14b395b7a16802ac909687dfa2b447e4.tar.bz2 gerbolyze-1d6d4e4f14b395b7a16802ac909687dfa2b447e4.zip |
svg-flatten: Add support for line thickness to board outline exporter
-rw-r--r-- | svg-flatten/include/gerbolyze.hpp | 10 | ||||
-rw-r--r-- | svg-flatten/src/out_gerber.cpp | 18 | ||||
-rw-r--r-- | svg-flatten/src/svg_doc.cpp | 11 |
3 files changed, 34 insertions, 5 deletions
diff --git a/svg-flatten/include/gerbolyze.hpp b/svg-flatten/include/gerbolyze.hpp index 0b4f03e..a30d7eb 100644 --- a/svg-flatten/include/gerbolyze.hpp +++ b/svg-flatten/include/gerbolyze.hpp @@ -44,6 +44,12 @@ namespace gerbolyze { std::string m_name; }; + class ApertureToken { + public: + ApertureToken(double size=0.0) : m_size(size) {} + double m_size = 0.0; + }; + class PolygonSink { public: virtual ~PolygonSink() {} @@ -66,6 +72,7 @@ namespace gerbolyze { }; virtual PolygonSink &operator<<(const LayerNameToken &) { return *this; }; virtual PolygonSink &operator<<(GerberPolarityToken pol) = 0; + virtual PolygonSink &operator<<(const ApertureToken &) { return *this; }; virtual void footer() {} }; @@ -229,6 +236,7 @@ namespace gerbolyze { virtual ~SimpleGerberOutput() {} virtual SimpleGerberOutput &operator<<(const Polygon &poly); virtual SimpleGerberOutput &operator<<(GerberPolarityToken pol); + virtual SimpleGerberOutput &operator<<(const ApertureToken &ap); virtual void header_impl(d2p origin, d2p size); virtual void footer_impl(); @@ -242,6 +250,8 @@ namespace gerbolyze { double m_scale; bool m_flip_pol; bool m_outline_mode; + double m_current_aperture; + unsigned int m_aperture_num; }; class SimpleSVGOutput : public StreamPolygonSink { diff --git a/svg-flatten/src/out_gerber.cpp b/svg-flatten/src/out_gerber.cpp index 94c01de..f842e15 100644 --- a/svg-flatten/src/out_gerber.cpp +++ b/svg-flatten/src/out_gerber.cpp @@ -34,7 +34,9 @@ SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits m_offset(offset), m_scale(scale), m_flip_pol(flip_polarity), - m_outline_mode(outline_mode) + m_outline_mode(outline_mode), + m_current_aperture(0.0), + m_aperture_num(10) /* See gerber standard */ { assert(1 <= digits_int && digits_int <= 9); assert(0 <= digits_frac && digits_frac <= 9); @@ -59,6 +61,20 @@ void SimpleGerberOutput::header_impl(d2p origin, d2p size) { m_out << "D10*" << endl; } +SimpleGerberOutput& SimpleGerberOutput::operator<<(const ApertureToken &ap) { + if (ap.m_size == m_current_aperture) { + return *this; + } + m_current_aperture = ap.m_size; + m_aperture_num += 1; + + double size = (ap.m_size > 0.0) ? ap.m_size : 0.05; + m_out << "%ADD" << m_aperture_num << "C," << size << "*%" << endl; + m_out << "D" << m_aperture_num << "*" << endl; + + return *this; +} + SimpleGerberOutput& SimpleGerberOutput::operator<<(GerberPolarityToken pol) { assert(pol == GRB_POL_DARK || pol == GRB_POL_CLEAR); diff --git a/svg-flatten/src/svg_doc.cpp b/svg-flatten/src/svg_doc.cpp index 48ee56d..6d41aca 100644 --- a/svg-flatten/src/svg_doc.cpp +++ b/svg-flatten/src/svg_doc.cpp @@ -226,6 +226,8 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings /* Load path from SVG path data and transform into document units. */ xform2d local_xf(mat); local_xf.transform(xform2d(node.attribute("transform").value())); + /* FIXME transform stroke width here? */ + stroke_width = local_xf.doc2phys_dist(stroke_width); PolyTree ptree_stroke; PolyTree ptree_fill; @@ -307,7 +309,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings if (rset.outline_mode) { /* In outline mode, manually close polys */ poly.push_back(poly[0]); - *polygon_sink << poly; + *polygon_sink << ApertureToken() << poly; } else { offx.AddPath(poly, join_type, etClosedLine); @@ -320,7 +322,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings dash_path(poly_copy, out, dasharray); if (rset.outline_mode) { - *polygon_sink << out; + *polygon_sink << ApertureToken(stroke_width) << out; } else { offx.AddPaths(out, join_type, end_type); } @@ -332,7 +334,7 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings dash_path(poly, out, dasharray); if (rset.outline_mode) { - *polygon_sink << out; + *polygon_sink << ApertureToken(stroke_width) << out; } else { offx.AddPaths(out, join_type, end_type); } @@ -373,10 +375,11 @@ void gerbolyze::SVGDocument::export_svg_path(xform2d &mat, const RenderSettings Paths s_polys; dehole_polytree(ptree, s_polys); - *polygon_sink << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << s_polys; + *polygon_sink << ApertureToken() << (stroke_color == GRB_DARK ? GRB_POL_DARK : GRB_POL_CLEAR) << s_polys; } } } + *polygon_sink << ApertureToken(); } void gerbolyze::SVGDocument::render(const RenderSettings &rset, PolygonSink &sink, const ElementSelector *sel) { |