From f6129ffdb8543ca001137c02afb2a5426d02e1b3 Mon Sep 17 00:00:00 2001 From: Torsten Paul Date: Mon, 10 Feb 2014 20:27:48 +0100 Subject: [PATCH] Add SVG export via command line. --- src/openscad.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/openscad.cc b/src/openscad.cc index 3c020e25..2a6c4dcd 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -217,6 +217,7 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c const char *stl_output_file = NULL; const char *off_output_file = NULL; const char *dxf_output_file = NULL; + const char *svg_output_file = NULL; const char *csg_output_file = NULL; const char *png_output_file = NULL; const char *ast_output_file = NULL; @@ -229,6 +230,7 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c if (suffix == ".stl") stl_output_file = output_file; else if (suffix == ".off") off_output_file = output_file; else if (suffix == ".dxf") dxf_output_file = output_file; + else if (suffix == ".svg") svg_output_file = output_file; else if (suffix == ".csg") csg_output_file = output_file; else if (suffix == ".png") png_output_file = output_file; else if (suffix == ".ast") ast_output_file = output_file; @@ -349,6 +351,7 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c if ( stl_output_file ) geom_out = std::string(stl_output_file); else if ( off_output_file ) geom_out = std::string(off_output_file); else if ( dxf_output_file ) geom_out = std::string(dxf_output_file); + else if ( svg_output_file ) geom_out = std::string(svg_output_file); else if ( png_output_file ) geom_out = std::string(png_output_file); else { PRINTB("Output file:%s\n",output_file); @@ -406,6 +409,21 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c fstream.close(); } } + + if (svg_output_file) { + if (root_geom->getDimension() != 2) { + PRINT("Current top level object is not a 2D object.\n"); + return 1; + } + std::ofstream fstream(svg_output_file); + if (!fstream.is_open()) { + PRINTB("Can't open file \"%s\" for export", svg_output_file); + } + else { + exportFile(root_geom.get(), fstream, OPENSCAD_SVG); + fstream.close(); + } + } if (png_output_file) { std::ofstream fstream(png_output_file,std::ios::out|std::ios::binary);