BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
be85cfc
Branches
Tags
master
dxfngc
src
path.cpp
initial version, DXFs can be read, some G-code can be produced
Stefan Schuermans
commited
be85cfc
at 2013-01-20 20:53:53
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 convert path to G-code * @param[in] settings G-code creation settings * @param[in,out] gcode new G-code is appended to existing G-code */ void Path::toGCode(const Settings &settings, GCode &gcode) const { // leave if no points if (mPoints.empty()) return; // move up gcode.appendUp(settings.move_z); // cut step-wise double z = settings.base_z; do { z -= settings.cut_z_step; if (z < settings.cut_z) z = settings.cut_z; // move to start gcode.appendFast(mPoints.front()); // 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); // move up gcode.appendUp(settings.move_z); } while (z > settings.cut_z); }