aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/svg_pattern.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-06-20 16:19:53 +0200
committerjaseg <git@jaseg.de>2022-06-20 16:19:53 +0200
commit9e9cc2bc019f0e67720ad5da16315e7cd6781e78 (patch)
treedd0531eef230fa8042143019db669e2841170f8a /svg-flatten/src/svg_pattern.cpp
parent0e1c8507bbda04f131ae0733e38b5f18996531b1 (diff)
downloadgerbolyze-9e9cc2bc019f0e67720ad5da16315e7cd6781e78.tar.gz
gerbolyze-9e9cc2bc019f0e67720ad5da16315e7cd6781e78.tar.bz2
gerbolyze-9e9cc2bc019f0e67720ad5da16315e7cd6781e78.zip
svg-flatten: add export of patterns via aperture macros
Diffstat (limited to 'svg-flatten/src/svg_pattern.cpp')
-rw-r--r--svg-flatten/src/svg_pattern.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/svg-flatten/src/svg_pattern.cpp b/svg-flatten/src/svg_pattern.cpp
index fc74d73..e8fb851 100644
--- a/svg-flatten/src/svg_pattern.cpp
+++ b/svg-flatten/src/svg_pattern.cpp
@@ -25,7 +25,7 @@
using namespace std;
-gerbolyze::Pattern::Pattern(const pugi::xml_node &node, SVGDocument &doc) : _node(node), doc(&doc) {
+gerbolyze::Pattern::Pattern(const pugi::xml_node &node, SVGDocument &doc) : m_node(node), doc(&doc) {
/* Read pattern attributes from SVG node */
x = usvg_double_attr(node, "x");
y = usvg_double_attr(node, "y");
@@ -87,6 +87,17 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
/* Switch to pattern coordinates */
RenderContext pat_ctx(ctx, patternTransform);
+ if (ctx.settings().use_apertures_for_patterns) {
+ vector<pair<Polygon, GerberPolarityToken>> out;
+ LambdaPolygonSink list_sink([&out](const Polygon &poly, GerberPolarityToken pol) {
+ out.emplace_back(pair<Polygon, GerberPolarityToken>{poly, pol});
+ });
+ ClipperLib::Paths empty_clip;
+ RenderContext macro_ctx(pat_ctx, list_sink, empty_clip);
+ doc->export_svg_group(macro_ctx, m_node);
+ pat_ctx.sink() << PatternToken(out);
+ }
+
/* Iterate over all pattern tiles in pattern coordinates */
for (double inst_off_x = fmod(inst_x, inst_w) - 2*inst_w;
inst_off_x < bx + bw + 2*inst_w;
@@ -131,7 +142,12 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
}
}
- doc->export_svg_group(elem_ctx, _node);
+ if (ctx.settings().use_apertures_for_patterns) {
+ /* use inst_h offset to compensate for gerber <-> svg "y" coordinate spaces */
+ elem_ctx.sink() << FlashToken(elem_ctx.mat().doc2phys({0, inst_h}));
+ } else {
+ doc->export_svg_group(elem_ctx, m_node);
+ }
}
}
}