BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
9d9be10
Branches
Tags
master
dxfngc
src
path.cpp
supoort rotation around z axis
Stefan Schuermans
commited
9d9be10
at 2013-05-18 14:37:50
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 <math.h> #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 { double rot = settings.rotation_z * M_PI / 180.0; 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().rotate(rot) + 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->rotate(rot) + offset); // move up gcode.appendUp(settings.move_z); }