diff options
author | jaseg <git@jaseg.de> | 2021-01-25 15:15:36 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2021-01-25 15:15:36 +0100 |
commit | 538b8a32b9d35a8f7068208772a9a963f1eefc4a (patch) | |
tree | bc810742c3d74089910a003de24fdcd4f2df1087 /src/main.cpp | |
parent | 33848ad43c5a0a53bd562658db54f890c74b64d2 (diff) | |
download | gerbolyze-538b8a32b9d35a8f7068208772a9a963f1eefc4a.tar.gz gerbolyze-538b8a32b9d35a8f7068208772a9a963f1eefc4a.tar.bz2 gerbolyze-538b8a32b9d35a8f7068208772a9a963f1eefc4a.zip |
Command-line format selection works
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0ea1fba..8656662 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include <cstdlib> #include <iostream> #include <fstream> +#include <algorithm> #include <string> #include <argagg.hpp> #include <gerbolyze.hpp> @@ -19,9 +20,21 @@ int main(int argc, char **argv) { {"version", {"-v", "--version"}, "Print version and exit", 0}, - {"ofmt", {"-o", "--output-format"}, + {"ofmt", {"-o", "--format"}, "Output format. Supported: gerber, svg, s-exp (KiCAD S-Expression)", 1}, + {"precision", {"-p", "--precision"}, + "Number of decimal places use for exported coordinates (gerber: 1-9, SVG: 0-*)", + 1}, + {"svg_clear_color", {"--clear-color"}, + "SVG color to use for \"clear\" areas (default: white)", + 1}, + {"svg_dark_color", {"--dark-color"}, + "SVG color to use for \"dark\" areas (default: black)", + 1}, + {"no_header", {"--no-header"}, + "Do not export output format header/footer, only export the primitives themselves", + 0}, {"flatten", {"-f", "--flatten"}, "Flatten output so it only consists of non-overlapping white polygons. This perform composition at the vector level. Potentially slow.", 0}, @@ -99,7 +112,36 @@ int main(int argc, char **argv) { return EXIT_FAILURE; } - SimpleGerberOutput out(*out_f); - doc.render(out); + bool only_polys = args["no_header"]; + + int precision = 6; + if (args["precision"]) { + precision = atoi(args["precision"]); + } + + string fmt = args["ofmt"] ? args["ofmt"] : "gerber"; + transform(fmt.begin(), fmt.end(), fmt.begin(), [](unsigned char c){ return std::tolower(c); }); + + PolygonSink *sink; + if (fmt == "svg") { + string dark_color = args["svg_dark_color"] ? args["svg_dark_color"] : "#000000"; + string clear_color = args["svg_clear_color"] ? args["svg_clear_color"] : "#ffffff"; + sink = new SimpleSVGOutput(*out_f, only_polys, precision, dark_color, clear_color); + + } else if (fmt == "gbr" || fmt == "grb" || fmt == "gerber") { + sink = new SimpleGerberOutput(*out_f, only_polys, 4, precision); + + } else { + cerr << "Unknown output format \"" << fmt << "\"" << endl; + argagg::fmt_ostream fmt(cerr); + fmt << usage.str() << argparser; + return EXIT_FAILURE; + } + + if (args["version"]) { + } + + doc.render(*sink); + return EXIT_SUCCESS; } |