Skip to content

Commit

Permalink
Fix issue with strings output in TrikPrintTextBlock (#1801)
Browse files Browse the repository at this point in the history
* Fix issue with print strings
* Use regular expressions to remove the zeros on the right of a double after alignment
  • Loading branch information
MinyazevR authored Oct 24, 2024
1 parent 1387445 commit b61826c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "trikPrintTextBlock.h"
#include "trikKit/robotModel/parts/trikDisplay.h"
#include <QRegularExpression>

using namespace trik;
using namespace blocks::details;
Expand All @@ -30,9 +31,17 @@ void TrikPrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display
const int x = eval<int>("XCoordinateText");
const int y = eval<int>("YCoordinateText");
const int fontSize = eval<int>("FontSize");
const QString result = boolProperty("Evaluate")
? QString::number(QString::number(eval<qreal>("PrintText"), 'f', 6).toDouble())
: stringProperty("PrintText");

QString result = stringProperty("PrintText");
if (boolProperty("Evaluate")) {
result = eval<QString>("PrintText");
bool ok;
auto doubleResult = result.toDouble(&ok);
if (ok) {
result = QString::number(doubleResult, 'f', 6).remove(QRegularExpression("\\.?0+$"));
}
}

const bool redraw = boolProperty("Redraw");

if (!errorsOccured()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <kitBase/robotModel/robotModelUtils.h>
#include <kitBase/robotModel/robotParts/display.h>
#include <QRegularExpression>

using namespace interpreterCore::coreBlocks::details;

Expand All @@ -28,11 +29,18 @@ void PrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display)
{
const int x = eval<int>("XCoordinateText");
const int y = eval<int>("YCoordinateText");
const QString result = boolProperty("Evaluate")
? QString::number(QString::number(eval<qreal>("PrintText"), 'f', 6).toDouble())
: stringProperty("PrintText");
const bool redraw = boolProperty("Redraw");

QString result = stringProperty("PrintText");
if (boolProperty("Evaluate")) {
result = eval<QString>("PrintText");
bool ok;
auto doubleResult = result.toDouble(&ok);
if (ok) {
result = QString::number(doubleResult, 'f', 6).remove(QRegularExpression("\\.?0+$"));
}
}

const bool redraw = boolProperty("Redraw");
if (!errorsOccured()) {
display.printText(x, y, result);
if (redraw) {
Expand Down

0 comments on commit b61826c

Please sign in to comment.