diff --git a/src/export.cc b/src/export.cc index 8abfc917..7e79234b 100644 --- a/src/export.cc +++ b/src/export.cc @@ -63,7 +63,9 @@ void exportFile(const class Geometry *root_geom, std::ostream &output, FileForma assert(false && "Unsupported file format"); } } - else { + else if (const Polygon2d *poly = dynamic_cast(root_geom)) { + export_dxf(*poly, output); + } else { assert(false && "Not implemented"); } } @@ -264,6 +266,67 @@ void export_dxf(const CGAL_Nef_polyhedron *root_N, std::ostream &output) #endif // ENABLE_CGAL +/*! + Saves the current Polygon2d as DXF to the given absolute filename. + */ +void export_dxf(const Polygon2d &poly, std::ostream &output) +{ + setlocale(LC_NUMERIC, "C"); // Ensure radix is . (not ,) in output + // Some importers (e.g. Inkscape) needs a BLOCKS section to be present + output << " 0\n" + << "SECTION\n" + << " 2\n" + << "BLOCKS\n" + << " 0\n" + << "ENDSEC\n" + << " 0\n" + << "SECTION\n" + << " 2\n" + << "ENTITIES\n"; + + BOOST_FOREACH(const Outline2d &o, poly.outlines()) { + for (int i=0;i void export_stl(const PolySet &ps, std::ostream &output) diff --git a/src/export.h b/src/export.h index 7df58263..bc882bc4 100644 --- a/src/export.h +++ b/src/export.h @@ -20,6 +20,7 @@ void export_stl(const class CGAL_Nef_polyhedron *root_N, std::ostream &output); void export_stl(const class PolySet *ps, std::ostream &output); void export_off(const CGAL_Nef_polyhedron *root_N, std::ostream &output); void export_dxf(const CGAL_Nef_polyhedron *root_N, std::ostream &output); +void export_dxf(const class Polygon2d &poly, std::ostream &output); void export_png(const CGAL_Nef_polyhedron *root_N, Camera &c, std::ostream &output); void export_png_with_opencsg(Tree &tree, Camera &c, std::ostream &output); void export_png_with_throwntogether(Tree &tree, Camera &c, std::ostream &output);