Frontend to the famous GRBL.

gcodeoutputdevice.h 2.7KB

    /* Part of x2grbl * * Copyright Johann Wilhelm <johann.wilhelm@9mal6.de> 2015 * * see Readme.md for detailed license and usage information! */ #ifndef GCODEOUTPUTDEVICE_H #define GCODEOUTPUTDEVICE_H #include <QObject> #include <QHash> #include <QString> #include <QVector3D> enum CodeType { CodeType_GCode, CodeType_MCode, CodeType_RAW, CodeType_Undefined }; class GCode : public QObject { Q_OBJECT public: GCode & operator=(const GCode& other) { Cmd=other.Cmd; SubCmd=other.SubCmd; Code=other.Code; Raw=other.Raw; Parameters=other.Parameters; Comment=other.Comment; return *this; } GCode(const GCode &other, QObject *parent=0):QObject(parent) { Cmd=other.Cmd; SubCmd=other.SubCmd; Code=other.Code; Raw=other.Raw; Parameters=other.Parameters; Comment=other.Comment; } GCode(QObject *parent=0):QObject(parent) { Cmd=-1; SubCmd=-1; Code=CodeType_Undefined; } QString serialize() { if (Code==CodeType_Undefined || (Code!=CodeType_RAW && Cmd==-1 )) return QString(); if (Code==CodeType_RAW) { if (Raw.toUpper()=="CONTROL-X") return ("\x18"); return Raw; } QString Tmp; switch (Code) { case CodeType_GCode: Tmp+=QString("G"); break; case CodeType_MCode: Tmp+=QString("M"); break; } Tmp+=QString("%1").arg(Cmd); if (SubCmd!=-1) Tmp+=QString(".%1").arg(SubCmd); QHashIterator<QString, QString> i(Parameters); while (i.hasNext()) { i.next(); Tmp+=QString("%1%2").arg(i.key()).arg(i.value()); } if (Comment.size()>0) Tmp+=QString(" ;")+Comment; return Tmp; } CodeType Code; int Cmd; int SubCmd; QHash<QString, QString> Parameters; QString Raw; QString Comment; }; class GCodeOutputDevice : public QObject { Q_OBJECT public: GCodeOutputDevice(QObject *parent=0); virtual bool supported(GCode &Cmd)=0; virtual bool Run(GCode &Cmd)=0; virtual QString name()=0; virtual void Reset() {} virtual void goHome() {}; QList<QVector3D> getProbingData() {return probingData;} void resetProbingData() {probingData.clear();} virtual void emitFinished(bool Emit) {emitFinishedFlag=Emit;}; protected: signals: void ExecutionFinished(); protected: bool emitFinishedFlag; QList<QVector3D> probingData; }; #endif // GCODEOUTPUTDEVICE_H