aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2021-03-19 20:32:13 +0100
committerjaseg <code@jaseg.net>2021-04-05 13:57:40 +0200
commit3288fb8345c07b4ca0deff82805d330f7d80bee7 (patch)
treeae8aed57df1457797ae4b31cce555191ee7d0fbc
parent0be9f4b3bae743fe3ed9359daf54b54aa5f31f88 (diff)
downloadgerbolyze-3288fb8345c07b4ca0deff82805d330f7d80bee7.tar.gz
gerbolyze-3288fb8345c07b4ca0deff82805d330f7d80bee7.tar.bz2
gerbolyze-3288fb8345c07b4ca0deff82805d330f7d80bee7.zip
Add -f/--flip-gerber-polarity option
-rw-r--r--README.rst7
-rw-r--r--svg-flatten/include/gerbolyze.hpp3
-rw-r--r--svg-flatten/src/main.cpp5
-rw-r--r--svg-flatten/src/out_gerber.cpp11
4 files changed, 17 insertions, 9 deletions
diff --git a/README.rst b/README.rst
index 04f10df..d3824ad 100644
--- a/README.rst
+++ b/README.rst
@@ -402,10 +402,13 @@ Options:
happy with too many digits. 5 or 6 is a reasonable choice.
``--clear-color``
- SVG color to use for "clear" areas (default: white)
+ SVG color to use in SVG output for "clear" areas (default: white)
``--dark-color``
- SVG color to use for "dark" areas (default: black)
+ SVG color to use in SVG output for "dark" areas (default: black)
+
+``-f, --flip-gerber-polarity``
+ Flip polarity of all output gerber primitives for --format gerber.
``-d, --trace-space``
Minimum feature size of elements in vectorized graphics (trace/space) in mm. Default: 0.1mm.
diff --git a/svg-flatten/include/gerbolyze.hpp b/svg-flatten/include/gerbolyze.hpp
index dc06c89..aea8748 100644
--- a/svg-flatten/include/gerbolyze.hpp
+++ b/svg-flatten/include/gerbolyze.hpp
@@ -214,7 +214,7 @@ namespace gerbolyze {
class SimpleGerberOutput : public StreamPolygonSink {
public:
- SimpleGerberOutput(std::ostream &out, bool only_polys=false, int digits_int=4, int digits_frac=6, double scale=1.0, d2p offset={0,0});
+ SimpleGerberOutput(std::ostream &out, bool only_polys=false, int digits_int=4, int digits_frac=6, double scale=1.0, d2p offset={0,0}, bool flip_polarity=false);
virtual ~SimpleGerberOutput() {}
virtual SimpleGerberOutput &operator<<(const Polygon &poly);
virtual SimpleGerberOutput &operator<<(GerberPolarityToken pol);
@@ -229,6 +229,7 @@ namespace gerbolyze {
long long int m_gerber_scale;
d2p m_offset;
double m_scale;
+ bool m_flip_pol;
};
class SimpleSVGOutput : public StreamPolygonSink {
diff --git a/svg-flatten/src/main.cpp b/svg-flatten/src/main.cpp
index 0abe3d1..722b356 100644
--- a/svg-flatten/src/main.cpp
+++ b/svg-flatten/src/main.cpp
@@ -39,6 +39,9 @@ int main(int argc, char **argv) {
{"svg_dark_color", {"--dark-color"},
"SVG color to use for \"dark\" areas (default: black)",
1},
+ {"flip_gerber_polarity", {"-f", "--flip-gerber-polarity"},
+ "Flip polarity of all output gerber primitives for --format gerber.",
+ 0},
{"min_feature_size", {"-d", "--trace-space"},
"Minimum feature size of elements in vectorized graphics (trace/space) in mm. Default: 0.1mm.",
1},
@@ -189,7 +192,7 @@ int main(int argc, char **argv) {
} else if (fmt == "gbr" || fmt == "grb" || fmt == "gerber") {
double scale = args["scale"].as<double>(1.0);
cerr << "loading @scale=" << scale << endl;
- sink = new SimpleGerberOutput(*out_f, only_polys, 4, precision, scale);
+ sink = new SimpleGerberOutput(*out_f, only_polys, 4, precision, scale, {0,0}, args["flip_gerber_polarity"]);
} else if (fmt == "s-exp" || fmt == "sexp" || fmt == "kicad") {
if (!args["sexp_mod_name"]) {
diff --git a/svg-flatten/src/out_gerber.cpp b/svg-flatten/src/out_gerber.cpp
index f16a06b..9513c0b 100644
--- a/svg-flatten/src/out_gerber.cpp
+++ b/svg-flatten/src/out_gerber.cpp
@@ -27,12 +27,13 @@
using namespace gerbolyze;
using namespace std;
-SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits_int, int digits_frac, double scale, d2p offset)
+SimpleGerberOutput::SimpleGerberOutput(ostream &out, bool only_polys, int digits_int, int digits_frac, double scale, d2p offset, bool flip_polarity)
: StreamPolygonSink(out, only_polys),
m_digits_int(digits_int),
m_digits_frac(digits_frac),
m_offset(offset),
- m_scale(scale)
+ m_scale(scale),
+ m_flip_pol(flip_polarity)
{
assert(1 <= digits_int && digits_int <= 9);
assert(0 <= digits_frac && digits_frac <= 9);
@@ -58,12 +59,12 @@ void SimpleGerberOutput::header_impl(d2p origin, d2p size) {
}
SimpleGerberOutput& SimpleGerberOutput::operator<<(GerberPolarityToken pol) {
- if (pol == GRB_POL_DARK) {
+ assert(pol == GRB_POL_DARK || pol == GRB_POL_CLEAR);
+
+ if ((pol == GRB_POL_DARK) != m_flip_pol) {
m_out << "%LPD*%" << endl;
} else if (pol == GRB_POL_CLEAR) {
m_out << "%LPC*%" << endl;
- } else {
- assert(false);
}
return *this;