diff --git a/src/plugins/grblplugin.h b/src/plugins/grblplugin.h --- a/src/plugins/grblplugin.h +++ b/src/plugins/grblplugin.h @@ -67,4 +67,8 @@ * @param lastMessage: last message from printer */ void validateCommand(const QString &lastMessage) override; + +private: + // Tracks machine relative state + bool _isInRelativeMode = false; }; diff --git a/src/plugins/grblplugin.cpp b/src/plugins/grblplugin.cpp --- a/src/plugins/grblplugin.cpp +++ b/src/plugins/grblplugin.cpp @@ -53,25 +53,40 @@ QByteArray GrblPlugin::translate(const QString &command) { - QString temp = command; + QStringList temp({command}); + //Match all G and M commands followed by one or more digits up to and include the space, //if thats followed by a letter capture any non G or M starting text //else just grab the digits that follow. //ex: G28 X Y M1 would capture "G28 X Y" and "M1" - static const auto regEx = QRegularExpression(QStringLiteral("[GM]\\d+.(?(?=\\D)[^GM]+|\\d+)?")); - - QRegularExpressionMatch secondCommand = regEx.match(temp, 1); + static const auto regEx = QRegularExpression(QStringLiteral("[gGmM]\\d+(?(?=\\D)[^gGmM]+\\d+)?")); + QRegularExpressionMatch secondCommand = regEx.match(command); if (secondCommand.hasMatch()) { - QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(temp); + QRegularExpressionMatchIterator commandMatch = regEx.globalMatch(command); temp.clear(); while (commandMatch.hasNext()) { QRegularExpressionMatch t = commandMatch.next(); temp.append(t.captured().simplified()); - if (commandMatch.hasNext()) { - temp.append(QStringLiteral("\r\n")); + } + } + + for (int i = 0; i < temp.size(); i++) { + if (temp[i].contains(QStringLiteral("G91"))) { + _isInRelativeMode = true; + temp[i] = QString(); + } else if (temp[i].contains(QStringLiteral("G90"))) { + _isInRelativeMode = false; + temp[i] = QString(); + } else if (temp[i].contains(QStringLiteral("G1 ")) || temp[i].contains(QStringLiteral("G01 "))) { + if (_isInRelativeMode) { + temp[i] = temp[i].replace(QStringLiteral("G1 "), QStringLiteral("G91 ")); + temp[i] = temp[i].replace(QStringLiteral("G01 "), QStringLiteral("G91 ")); } + } else if (temp[i].contains(QStringLiteral("M84"))) { + temp[i] = QStringLiteral("M3 S0"); } } - return temp.toLocal8Bit(); + temp.removeAll(QString()); + return temp.join(QStringLiteral("\n\r")).toLocal8Bit(); } diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp --- a/src/widgets/axiscontrol.cpp +++ b/src/widgets/axiscontrol.cpp @@ -28,7 +28,7 @@ setRect(QRect(QPoint(size * -1, size * -1), QPoint(size, size))); setZValue(size * -1); setAcceptHoverEvents(true); - setToolTip(tr("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); + setToolTip(tr("Move the hotend/spindle to the %1 by %2 units").arg(axis).arg(value)); } void PieButton::setPalette(QPalette palette)