BlinkenArea - GitList
Repositories
Blog
Wiki
dxfngc
Code
Commits
Branches
Tags
Search
Tree:
be85cfc
Branches
Tags
master
dxfngc
src
gcode.cpp
initial version, DXFs can be read, some G-code can be produced
Stefan Schuermans
commited
be85cfc
at 2013-01-20 20:53:53
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 */ void GCode::toStrm(std::ostream &strm) const { 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 * @return if writing G-code was successful */ bool GCode::toFile(const std::string &strFileName) 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); return true; }