BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
3c3d918
Branches
Tags
master
dxfngc
src
drawing.cpp
implement finer approximation for circles and arcs on import, implement import of ellipses
Stefan Schuermans
commited
3c3d918
at 2013-01-29 23:06:23
drawing.cpp
Blame
History
Raw
/* drawing (DXF) to G-code (NGC) converter * Copyright 2013 Stefan Schuermans <stefan@schuermans.info> * Copyleft: CC-BY-SA http://creativecommons.org/licenses/by-sa/3.0/ */ #include <dime/Input.h> #include <dime/Model.h> #include <iostream> #include <map> #include <string> #include "drawing.h" #include "layer.h" #include "traverse.h" /** * @brief clear all contents of drawing */ void Drawing::clear() { mLayers.clear(); } /** * @brief add a DXF file to this drawing * @param[in] strFileName name of the DXF file to read * @param[in] precision precision for entity to lines conversion * @return if the DXF file could be read */ bool Drawing::addDxf(const std::string &strFileName, double precision) { // read DXF file dimeInput in; if (!in.setFile(strFileName.c_str())) { std::cerr << "error opening file \"" << strFileName << "\" for reading" << std::endl; return false; } dimeModel model; if (!model.read(&in)) { std::cerr << "DXF read error in line " << in.getFilePosition() << " of file \"" << strFileName << "\"" << std::endl; return false; } // enumerate all entities and add them to drawing struct traverse_ctx ctx; ctx.precision = precision; ctx.mpDrawing = this; model.traverseEntities(traverse_entity, &ctx); return true; } /** * @brief load a DXF file to this drawing * @param[in] strFileName name of the DXF file to read * @param[in] precision precision for entity to lines conversion * @return if the DXF file could be read */ bool Drawing::loadDxf(const std::string &strFileName, double precision) { clear(); return addDxf(strFileName, precision); } /** * @brief improve paths in layers * @param[in] eqDist maximum distance of tho points to be considered equal */ void Drawing::improvePaths(double eqDist) { Layers::iterator layer; for (layer = mLayers.begin(); layer != mLayers.end(); ++layer) layer->second.improvePaths(eqDist); }