BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
9dc0297
Branches
Tags
master
dxfngc
src
path.cpp
add support for dwell time before each path
Stefan Schuermans
commited
9dc0297
at 2013-04-22 19:59:17
path.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 <vector> #include "gcode.h" #include "path.h" #include "point.h" #include "settings.h" /** * @brief add a new point to the end of the path * @param[in] point point to add */ void Path::addPoint(const Point &point) { mPoints.push_back(point); } /** * @brief add a new point to the end of the path * @param[in] x x coordinate of point to add * @param[in] y y coordinate of point to add */ void Path::addPoint(double x, double y) { addPoint(Point(x, y)); } /** * @brief prepend other path to this one * @param[in] other other path to prepend */ void Path::prependPath(const Path &other) { mPoints.insert(mPoints.begin(), other.mPoints.begin(), other.mPoints.end()); } /** * @brief prepend other path in reverse to this one * @param[in] other other path to prepend */ void Path::prependReversedPath(const Path &other) { mPoints.insert(mPoints.begin(), other.mPoints.rbegin(), other.mPoints.rend()); } /** * @brief append other path to this one * @param[in] other other path to appepend */ void Path::appendPath(const Path &other) { mPoints.insert(mPoints.end(), other.mPoints.begin(), other.mPoints.end()); } /** * @brief append other path in reverse to this one * @param[in] other other path to appepend */ void Path::appendReversedPath(const Path &other) { mPoints.insert(mPoints.end(), other.mPoints.rbegin(), other.mPoints.rend()); } /** * @brief remove points too close to each other * @param[in] eqDist maximum distance of two points to be considered equal */ void Path::removeEqPoints(double eqDist) { Points::iterator pt = mPoints.begin(); while (pt != mPoints.end()) { Points::iterator next = pt + 1; if (next != mPoints.end() && pt->equals(*next, eqDist)) mPoints.erase(next); else pt++; } } /** * @brief convert path to G-code * @param[in] settings G-code creation settings * @param[in] z z coordinate to use for G-code of path * @param[in,out] gcode new G-code is appended to existing G-code */ void Path::toGCode(const Settings &settings, double z, GCode &gcode) const { Point offset(settings.offset_x, settings.offset_y); // leave if no points if (mPoints.empty()) return; // move up gcode.appendUp(settings.move_z); // move to start gcode.appendFast(mPoints.front() + offset); // dwell if (settings.dwell_time > 0.0) gcode.appendDwell(settings.dwell_time); // cut down gcode.appendFeed(settings.feed_drill); gcode.appendDown(z); // cut along all points gcode.appendFeed(settings.feed_mill); Points::const_iterator pt = mPoints.begin(); for (++pt; pt != mPoints.end(); ++pt) gcode.appendLinear(*pt + offset); // move up gcode.appendUp(settings.move_z); }