BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
b44cc2a
Branches
Tags
master
dxfngc
src
layer.cpp
implement joining and improving paths
Stefan Schuermans
commited
b44cc2a
at 2013-01-26 23:15:34
layer.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 <list> #include "gcode.h" #include "layer.h" #include "path.h" #include "settings.h" /** * @brief add a new empty path to the layer * @return reference to new empty path */ Path & Layer::addPath() { mPaths.push_back(Path()); return mPaths.back(); } /** * @brief improve paths * @param[in] eqDist maximum distance of two points to be considered equal */ void Layer::improvePaths(double eqDist) { Paths::iterator path, other; bool change; // join paths with equal begin/end points do { change = false; for (path = mPaths.begin(); path != mPaths.end(); ++path) { other = path; ++other; while (other != mPaths.end()) { if (other->mPoints.front().equals(path->mPoints.back(), eqDist)) { path->appendPath(*other); other = mPaths.erase(other); change = true; } else if (other->mPoints.back().equals(path->mPoints.back(), eqDist)) { path->appendReversedPath(*other); other = mPaths.erase(other); change = true; } else if (other->mPoints.back().equals(path->mPoints.front(), eqDist)) { path->prependPath(*other); other = mPaths.erase(other); change = true; } else if (other->mPoints.front().equals(path->mPoints.front(), eqDist)) { path->prependReversedPath(*other); other = mPaths.erase(other); change = true; } else ++other; } } } while (change); // remove nearby points in paths for (path = mPaths.begin(); path != mPaths.end(); ++path) path->removeEqPoints(eqDist); // remove empty paths path = mPaths.begin(); while (path != mPaths.end()) if (path->mPoints.empty()) path = mPaths.erase(path); else ++path; } /** * @brief convert layer to G-code * @param[in] settings G-code creation settings * @param[in,out] gcode new G-code is appended to existing G-code */ void Layer::toGCode(const Settings &settings, GCode &gcode) const { Paths::const_iterator path; for (path = mPaths.begin(); path != mPaths.end(); ++path) path->toGCode(settings, gcode); }