From a17e92cd816fc34320322cd71a3d387beaf941d5 Mon Sep 17 00:00:00 2001 From: IKhonakhbeeva <43929571+IKhonakhbeeva@users.noreply.github.com> Date: Fri, 17 Feb 2023 21:48:09 +0500 Subject: [PATCH] Fix sin/cos and small values display (#1631) * Fix printing very small values for printTextBlock * Use degrees for sin and cos in block's programming instead of radians * Fix sin/cos generation for python and js on trik * Fix printTextBlock for trik too --- .../common/trikKit/src/blocks/details/trikPrintTextBlock.cpp | 4 +++- .../trik/trikPythonGeneratorLibrary/templates/functions/cos.t | 2 +- .../trik/trikPythonGeneratorLibrary/templates/functions/sin.t | 2 +- .../trik/trikQtsGeneratorLibrary/templates/functions/cos.t | 2 +- .../trik/trikQtsGeneratorLibrary/templates/functions/sin.t | 2 +- .../interpreterCore/src/coreBlocks/details/printTextBlock.cpp | 4 +++- .../interpreterCore/src/textLanguage/robotsBlockParser.cpp | 4 ++-- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/robots/common/trikKit/src/blocks/details/trikPrintTextBlock.cpp b/plugins/robots/common/trikKit/src/blocks/details/trikPrintTextBlock.cpp index 872123c709..b147cbf2d3 100644 --- a/plugins/robots/common/trikKit/src/blocks/details/trikPrintTextBlock.cpp +++ b/plugins/robots/common/trikKit/src/blocks/details/trikPrintTextBlock.cpp @@ -30,7 +30,9 @@ void TrikPrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display const int x = eval("XCoordinateText"); const int y = eval("YCoordinateText"); const int fontSize = eval("FontSize"); - const QString result = boolProperty("Evaluate") ? eval("PrintText") : stringProperty("PrintText"); + const QString result = boolProperty("Evaluate") + ? QString::number(QString::number(eval("PrintText"), 'f', 6).toDouble()) + : stringProperty("PrintText"); const bool redraw = boolProperty("Redraw"); if (!errorsOccured()) { diff --git a/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/cos.t b/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/cos.t index 3bac703d48..f95c339ae6 100644 --- a/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/cos.t +++ b/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/cos.t @@ -1 +1 @@ -math.cos(@@ARGUMENT@@) \ No newline at end of file +math.cos(@@ARGUMENT@@*pi/180) \ No newline at end of file diff --git a/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/sin.t b/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/sin.t index c20102853b..0d67f8f9ba 100644 --- a/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/sin.t +++ b/plugins/robots/generators/trik/trikPythonGeneratorLibrary/templates/functions/sin.t @@ -1 +1 @@ -math.sin(@@ARGUMENT@@) \ No newline at end of file +math.sin(@@ARGUMENT@@*pi/180) \ No newline at end of file diff --git a/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/cos.t b/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/cos.t index e54a8f8629..3ffe043b04 100644 --- a/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/cos.t +++ b/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/cos.t @@ -1 +1 @@ -Math.cos(@@ARGUMENT@@) \ No newline at end of file +Math.cos(@@ARGUMENT@@*pi/180) \ No newline at end of file diff --git a/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/sin.t b/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/sin.t index f68cdf66ad..8ea7858279 100644 --- a/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/sin.t +++ b/plugins/robots/generators/trik/trikQtsGeneratorLibrary/templates/functions/sin.t @@ -1 +1 @@ -Math.sin(@@ARGUMENT@@) \ No newline at end of file +Math.sin(@@ARGUMENT@@*pi/180) \ No newline at end of file diff --git a/plugins/robots/interpreters/interpreterCore/src/coreBlocks/details/printTextBlock.cpp b/plugins/robots/interpreters/interpreterCore/src/coreBlocks/details/printTextBlock.cpp index 18632cf124..5db320ac54 100644 --- a/plugins/robots/interpreters/interpreterCore/src/coreBlocks/details/printTextBlock.cpp +++ b/plugins/robots/interpreters/interpreterCore/src/coreBlocks/details/printTextBlock.cpp @@ -28,7 +28,9 @@ void PrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display) { const int x = eval("XCoordinateText"); const int y = eval("YCoordinateText"); - const QString result = boolProperty("Evaluate") ? eval("PrintText") : stringProperty("PrintText"); + const QString result = boolProperty("Evaluate") + ? QString::number(QString::number(eval("PrintText"), 'f', 6).toDouble()) + : stringProperty("PrintText"); const bool redraw = boolProperty("Redraw"); if (!errorsOccured()) { diff --git a/plugins/robots/interpreters/interpreterCore/src/textLanguage/robotsBlockParser.cpp b/plugins/robots/interpreters/interpreterCore/src/textLanguage/robotsBlockParser.cpp index f00fb952ea..b1a57f811b 100644 --- a/plugins/robots/interpreters/interpreterCore/src/textLanguage/robotsBlockParser.cpp +++ b/plugins/robots/interpreters/interpreterCore/src/textLanguage/robotsBlockParser.cpp @@ -198,8 +198,8 @@ void RobotsBlockParser::addIntrinsicFuctions() return text; }); - addFloatFunction("sin", [](qreal x) {return qSin(x); }); - addFloatFunction("cos", [](qreal x) {return qCos(x); }); + addFloatFunction("sin", [](qreal x) { return qSin(M_PI / 180 * x); }); + addFloatFunction("cos", [](qreal x) { return qCos(M_PI / 180 * x); }); addFloatFunction("ln", [](qreal x) {return qLn(x); }); addFloatFunction("exp", [](qreal x) {return qExp(x); }); addFloatFunction("asin", [](qreal x) {return qAsin(x); });