aboutsummaryrefslogtreecommitdiff
path: root/svg-flatten/src/out_gerber.cpp
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2021-01-31 22:11:34 +0100
committerjaseg <git@jaseg.de>2021-01-31 22:11:34 +0100
commita68e395cb622b9cb91e408b0846cc10126f8ddad (patch)
tree14c02a7eed139d1f750923f77350fd941fcfa025 /svg-flatten/src/out_gerber.cpp
parent49a7c6df416b18516fca776614cb0aa0f483798f (diff)
downloadgerbolyze-a68e395cb622b9cb91e408b0846cc10126f8ddad.tar.gz
gerbolyze-a68e395cb622b9cb91e408b0846cc10126f8ddad.tar.bz2
gerbolyze-a68e395cb622b9cb91e408b0846cc10126f8ddad.zip
Advanced svg/gerber composition working
Diffstat (limited to 'svg-flatten/src/out_gerber.cpp')
-rw-r--r--svg-flatten/src/out_gerber.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/svg-flatten/src/out_gerber.cpp b/svg-flatten/src/out_gerber.cpp
index c320184..b32e6e4 100644
--- a/svg-flatten/src/out_gerber.cpp
+++ b/svg-flatten/src/out_gerber.cpp
@@ -27,11 +27,12 @@
using namespace gerbolyze;
using namespace std;
-SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits_int, int digits_frac, d2p offset)
+SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits_int, int digits_frac, double scale, d2p offset)
: StreamPolygonSink(out, only_polys),
m_digits_int(digits_int),
m_digits_frac(digits_frac),
- m_offset(offset)
+ m_offset(offset),
+ m_scale(scale)
{
assert(1 <= digits_int && digits_int <= 9);
assert(0 <= digits_frac && digits_frac <= 9);
@@ -39,10 +40,10 @@ SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits
}
void SimpleGerberOutput::header_impl(d2p origin, d2p size) {
- m_offset[0] += origin[0];
- m_offset[1] += origin[1];
- m_width = size[0] - origin[0];
- m_height = size[1] - origin[1];
+ m_offset[0] += origin[0] * m_scale;
+ m_offset[1] += origin[1] * m_scale;
+ m_width = (size[0] - origin[0]) * m_scale;
+ m_height = (size[1] - origin[1]) * m_scale;
if (pow(10, m_digits_int-1) < max(m_width, m_height)) {
cerr << "Warning: Input has bounding box too large for " << m_digits_int << "." << m_digits_frac << " gerber resolution!" << endl;
@@ -74,16 +75,16 @@ SimpleGerberOutput& SimpleGerberOutput::operator<<(const Polygon &poly) {
}
/* NOTE: Clipper and gerber both have different fixed-point scales. We get points in double mm. */
- double x = round((poly[0][0] + m_offset[0]) * m_gerber_scale);
- double y = round((m_height - poly[0][1] + m_offset[1]) * m_gerber_scale);
+ double x = round((poly[0][0] * m_scale + m_offset[0]) * m_gerber_scale);
+ double y = round((m_height - poly[0][1] * m_scale + m_offset[1]) * m_gerber_scale);
m_out << "G36*" << endl;
m_out << "X" << setw(m_digits_int + m_digits_frac) << setfill('0') << (long long int)x
<< "Y" << setw(m_digits_int + m_digits_frac) << setfill('0') << (long long int)y
<< "D02*" << endl;
m_out << "G01*" << endl;
for (size_t i=1; i<poly.size(); i++) {
- double x = round((poly[i][0] + m_offset[0]) * m_gerber_scale);
- double y = round((m_height - poly[i][1] + m_offset[1]) * m_gerber_scale);
+ double x = round((poly[i][0] * m_scale + m_offset[0]) * m_gerber_scale);
+ double y = round((m_height - poly[i][1] * m_scale + m_offset[1]) * m_gerber_scale);
m_out << "X" << setw(m_digits_int + m_digits_frac) << setfill('0') << (long long int)x
<< "Y" << setw(m_digits_int + m_digits_frac) << setfill('0') << (long long int)y
<< "D01*" << endl;