BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
e231ced
Branches
Tags
master
dxfngc
src
gcode.cpp
configuration of precision
Stefan Schuermans
commited
e231ced
at 2013-01-26 18:55:56
gcode.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 <fstream> #include <iostream> #include <string> #include <vector> #include "gcmd.h" #include "gcode.h" #include "gcustom.h" #include "gfast.h" #include "gfeed.h" #include "glinear.h" #include "point.h" /// consturctor GCode::GCode() { } /// destructor GCode::~GCode() { GCmds::const_iterator gcmd; for (gcmd = mGCmds.begin(); gcmd != mGCmds.end(); ++gcmd) delete *gcmd; } /** * @brief append fast move up command * @param[in] z z coordinate to move up to */ void GCode::appendUp(double z) { GFast *up = new GFast; up->mZ.set(z); mGCmds.push_back(up); } /** * @brief append fast move command * @param[in] pt point to move to */ void GCode::appendFast(const Point &pt) { GFast *fast = new GFast; fast->mX.set(pt.mX); fast->mY.set(pt.mY); mGCmds.push_back(fast); } /** * @brief append set feed rate command * @param[in] feed feed rate */ void GCode::appendFeed(double feed) { GFeed *gfeed = new GFeed; gfeed->mFeed = feed; mGCmds.push_back(gfeed); } /** * @brief append linear cut down command * @param[in] z z coordinate to cut down to */ void GCode::appendDown(double z) { GLinear *down = new GLinear; down->mZ.set(z); mGCmds.push_back(down); } /** * @brief append linear cut command * @param[in] pt point to cut to */ void GCode::appendLinear(const Point &pt) { GLinear *linear = new GLinear; linear->mX.set(pt.mX); linear->mY.set(pt.mY); mGCmds.push_back(linear); } /** * @brief append custom command * @param[in] cmd custom command to append */ void GCode::appendCustom(const std::string &cmd) { GCustom *custom = new GCustom; custom->mCmd = cmd; mGCmds.push_back(custom); } /** * @brief output G-code to stream * @param[in] strm stream to write G-code to * @param[in] digits number of digits to output after decimal point */ void GCode::toStrm(std::ostream &strm, unsigned int digits) const { strm.precision(digits); strm << std::fixed; GCmds::const_iterator gcmd; for (gcmd = mGCmds.begin(); gcmd != mGCmds.end(); ++gcmd) (*gcmd)->toStrm(strm); } /** * @brief output G-code to file * @param[in] strFileName name of file to write G-code to * @param[in] digits number of digits to output after decimal point * @return if writing G-code was successful */ bool GCode::toFile(const std::string &strFileName, unsigned int digits) const { std::ofstream ofstrm(strFileName.c_str(), std::ios::out); if (!ofstrm.is_open()) { std::cerr << "could not open \"" << strFileName << "\" for writing" << std::endl; return false; } toStrm(ofstrm, digits); return true; }