2015-06-11 12:15:57 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vtranslatevars.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 10 6, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-06-11 12:15:57 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-06-11 12:15:57 +02:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vtranslatevars.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QList>
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QLocale>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QMap>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QString>
|
2015-10-18 21:30:51 +02:00
|
|
|
#include <QtDebug>
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../ifc/ifcdef.h"
|
2023-05-17 15:24:27 +02:00
|
|
|
#include "../qmuparser/qmudef.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "../qmuparser/qmuparsererror.h"
|
|
|
|
#include "../qmuparser/qmutokenparser.h"
|
|
|
|
#include "../qmuparser/qmutranslation.h"
|
2023-05-17 15:24:27 +02:00
|
|
|
#include "../vmisc/compatibility.h"
|
2016-08-09 15:55:46 +02:00
|
|
|
#include "../vmisc/def.h"
|
2022-02-18 09:36:38 +01:00
|
|
|
#include "../vmisc/literals.h"
|
2023-05-17 15:24:27 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vpatterndb/vtranslatevars.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
using namespace Qt::Literals::StringLiterals;
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-05-23 17:23:39 +02:00
|
|
|
VTranslateVars::VTranslateVars()
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
|
|
|
InitVariables();
|
|
|
|
InitFunctions();
|
2017-12-04 10:44:29 +01:00
|
|
|
|
|
|
|
PrepareFunctionTranslations();
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
#define translate(context, source, disambiguation) qmu::QmuTranslation::translate((context), (source), (disambiguation))
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VTranslateVars::InitVariables()
|
|
|
|
{
|
2017-03-28 09:18:19 +02:00
|
|
|
variables.insert(measurement_, translate("VTranslateVars", "M_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(increment_, translate("VTranslateVars", "Increment_", "Left symbol _ in the name"));
|
2016-04-01 23:15:04 +02:00
|
|
|
variables.insert(line_, translate("VTranslateVars", "Line_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(angleLine_, translate("VTranslateVars", "AngleLine_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(arc_, translate("VTranslateVars", "Arc_", "Left symbol _ in the name"));
|
2017-08-08 17:27:36 +02:00
|
|
|
variables.insert(elarc_, translate("VTranslateVars", "ElArc_", "Left symbol _ in the name"));
|
2016-04-01 23:15:04 +02:00
|
|
|
variables.insert(spl_, translate("VTranslateVars", "Spl_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(splPath, translate("VTranslateVars", "SplPath", "Do not add symbol _ to the end of the name"));
|
|
|
|
variables.insert(radiusArc_, translate("VTranslateVars", "RadiusArc_", "Left symbol _ in the name"));
|
2017-08-08 17:27:36 +02:00
|
|
|
variables.insert(radius1ElArc_, translate("VTranslateVars", "Radius1ElArc_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(radius2ElArc_, translate("VTranslateVars", "Radius2ElArc_", "Left symbol _ in the name"));
|
2016-04-01 23:15:04 +02:00
|
|
|
variables.insert(angle1Arc_, translate("VTranslateVars", "Angle1Arc_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(angle2Arc_, translate("VTranslateVars", "Angle2Arc_", "Left symbol _ in the name"));
|
2017-08-08 17:27:36 +02:00
|
|
|
variables.insert(angle1ElArc_, translate("VTranslateVars", "Angle1ElArc_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(angle2ElArc_, translate("VTranslateVars", "Angle2ElArc_", "Left symbol _ in the name"));
|
2016-04-01 23:15:04 +02:00
|
|
|
variables.insert(angle1Spl_, translate("VTranslateVars", "Angle1Spl_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(angle2Spl_, translate("VTranslateVars", "Angle2Spl_", "Left symbol _ in the name"));
|
2023-05-17 15:24:27 +02:00
|
|
|
variables.insert(angle1SplPath,
|
|
|
|
translate("VTranslateVars", "Angle1SplPath", "Do not add symbol _ to the end of the name"));
|
|
|
|
variables.insert(angle2SplPath,
|
|
|
|
translate("VTranslateVars", "Angle2SplPath", "Do not add symbol _ to the end of the name"));
|
2016-04-01 23:15:04 +02:00
|
|
|
variables.insert(seg_, translate("VTranslateVars", "Seg_", "Segment. Left symbol _ in the name"));
|
2016-06-23 19:20:21 +02:00
|
|
|
variables.insert(currentLength, translate("VTranslateVars", "CurrentLength", "Do not add space between words"));
|
2023-05-17 15:24:27 +02:00
|
|
|
variables.insert(currentSeamAllowance,
|
|
|
|
translate("VTranslateVars", "CurrentSeamAllowance", "Do not add space between words"));
|
2016-09-26 21:33:28 +02:00
|
|
|
variables.insert(c1LengthSpl_, translate("VTranslateVars", "C1LengthSpl_", "Left symbol _ in the name"));
|
|
|
|
variables.insert(c2LengthSpl_, translate("VTranslateVars", "C2LengthSpl_", "Left symbol _ in the name"));
|
2023-05-17 15:24:27 +02:00
|
|
|
variables.insert(c1LengthSplPath,
|
|
|
|
translate("VTranslateVars", "C1LengthSplPath", "Do not add symbol _ to the end of the name"));
|
|
|
|
variables.insert(c2LengthSplPath,
|
|
|
|
translate("VTranslateVars", "C2LengthSplPath", "Do not add symbol _ to the end of the name"));
|
2018-01-05 20:07:47 +01:00
|
|
|
variables.insert(rotationElArc_, translate("VTranslateVars", "RotationElArc_", "Left symbol _ in the name"));
|
2022-11-10 10:30:08 +01:00
|
|
|
variables.insert(pieceArea_, translate("VTranslateVars", "PieceArea_", "Left symbol _ in the name"));
|
2023-05-17 15:24:27 +02:00
|
|
|
variables.insert(pieceSeamLineArea_,
|
|
|
|
translate("VTranslateVars", "PieceSeamLineArea_", "Left symbol _ in the name"));
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VTranslateVars::InitFunctions()
|
|
|
|
{
|
2022-08-02 19:11:18 +02:00
|
|
|
const QString oneArgument = QStringLiteral("()");
|
|
|
|
const QString twoArguments = QStringLiteral("(;)");
|
|
|
|
const QString threeArguments = QStringLiteral("(;;)");
|
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(degTorad_F, translate("VTranslateVars", "degTorad", "converts degrees to radian"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(degTorad_F,
|
|
|
|
translate("VTranslateVars", "converts degrees to radian", "function degTorad"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(degTorad_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(radTodeg_F, translate("VTranslateVars", "radTodeg", "converts radian to degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(radTodeg_F,
|
|
|
|
translate("VTranslateVars", "converts radian to degrees", "function radTodeg"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(radTodeg_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(sin_F, translate("VTranslateVars", "sin", "sine function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(sin_F,
|
|
|
|
translate("VTranslateVars", "sine function working with radians", "function sin"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sin_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(cos_F, translate("VTranslateVars", "cos", "cosine function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(cos_F,
|
|
|
|
translate("VTranslateVars", "cosine function working with radians", "function cos"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(cos_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(tan_F, translate("VTranslateVars", "tan", "tangens function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(tan_F,
|
|
|
|
translate("VTranslateVars", "tangens function working with radians", "function tan"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(tan_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(asin_F, translate("VTranslateVars", "asin", "arcus sine function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
asin_F, translate("VTranslateVars", "arcus sine function working with radians", "function asin"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(asin_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(acos_F, translate("VTranslateVars", "acos", "arcus cosine function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
acos_F, translate("VTranslateVars", "arcus cosine function working with radians", "function acos"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(acos_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(atan_F, translate("VTranslateVars", "atan", "arcus tangens function working with radians"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
atan_F, translate("VTranslateVars", "arcus tangens function working with radians", "function atan"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(atan_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(sinh_F, translate("VTranslateVars", "sinh", "hyperbolic sine function"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(sinh_F, translate("VTranslateVars", "hyperbolic sine function", "function sinh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sinh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(cosh_F, translate("VTranslateVars", "cosh", "hyperbolic cosine"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(cosh_F, translate("VTranslateVars", "hyperbolic cosine", "function cosh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sinh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(tanh_F, translate("VTranslateVars", "tanh", "hyperbolic tangens function"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(tanh_F, translate("VTranslateVars", "hyperbolic tangens function", "function tanh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(tanh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(asinh_F, translate("VTranslateVars", "asinh", "hyperbolic arcus sine function"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(asinh_F,
|
|
|
|
translate("VTranslateVars", "hyperbolic arcus sine function", "function asinh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(asinh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(acosh_F, translate("VTranslateVars", "acosh", "hyperbolic arcus cosine function"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(acosh_F,
|
|
|
|
translate("VTranslateVars", "hyperbolic arcus cosine function", "function acosh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(acosh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-04-14 17:42:49 +02:00
|
|
|
functions.insert(atanh_F, translate("VTranslateVars", "atanh", "hyperbolic arcur tangens function"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(atanh_F,
|
|
|
|
translate("VTranslateVars", "hyperbolic arcur tangens function", "function atanh"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(atanh_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(sinD_F, translate("VTranslateVars", "sinD", "sine function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(sinD_F,
|
|
|
|
translate("VTranslateVars", "sine function working with degrees", "function sinD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sinD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(cosD_F, translate("VTranslateVars", "cosD", "cosine function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(cosD_F,
|
|
|
|
translate("VTranslateVars", "cosine function working with degrees", "function cosD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(cosD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(tanD_F, translate("VTranslateVars", "tanD", "tangens function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(tanD_F,
|
|
|
|
translate("VTranslateVars", "tangens function working with degrees", "function tanD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(tanD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(asinD_F, translate("VTranslateVars", "asinD", "arcus sine function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
asinD_F, translate("VTranslateVars", "arcus sine function working with degrees", "function asinD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(asinD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(acosD_F, translate("VTranslateVars", "acosD", "arcus cosine function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
acosD_F, translate("VTranslateVars", "arcus cosine function working with degrees", "function acosD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(acosD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
qmuparser: added triangular functions that work with degree
new functions are: degTorad, radTodeg, , sinD, cosD, tanD, asinD, acosD , atanD, sinhD, coshD , tanhD, asinhD, acoshD, atanhD
--HG--
branch : feature
2017-02-27 20:42:35 +01:00
|
|
|
functions.insert(atanD_F, translate("VTranslateVars", "atanD", "arcus tangens function working with degrees"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(
|
|
|
|
atanD_F, translate("VTranslateVars", "arcus tangens function working with degrees", "function atanD"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(atanD_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(log2_F, translate("VTranslateVars", "log2", "logarithm to the base 2"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(log2_F, translate("VTranslateVars", "logarithm to the base 2", "function log2"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(log2_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(log10_F, translate("VTranslateVars", "log10", "logarithm to the base 10"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(log10_F, translate("VTranslateVars", "logarithm to the base 10", "function log10"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(log10_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(log_F, translate("VTranslateVars", "log", "logarithm to the base 10"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(log_F, translate("VTranslateVars", "logarithm to the base 10", "function log"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(log_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(ln_F, translate("VTranslateVars", "ln", "logarithm to base e (2.71828...)"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(ln_F, translate("VTranslateVars", "logarithm to base e (2.71828...)", "function ln"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(ln_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(exp_F, translate("VTranslateVars", "exp", "e raised to the power of x"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(exp_F, translate("VTranslateVars", "e raised to the power of x", "function exp"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(exp_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(sqrt_F, translate("VTranslateVars", "sqrt", "square root of a value"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(sqrt_F, translate("VTranslateVars", "square root of a value", "function sqrt"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sqrt_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(sign_F, translate("VTranslateVars", "sign", "sign function -1 if x<0; 1 if x>0"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(sign_F,
|
|
|
|
translate("VTranslateVars", "sign function -1 if x<0; 1 if x>0", "function sign"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sign_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(rint_F, translate("VTranslateVars", "rint", "round to nearest integer"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(rint_F, translate("VTranslateVars", "round to nearest integer", "function rint"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(rint_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2017-09-29 16:47:11 +02:00
|
|
|
functions.insert(r2cm_F, translate("VTranslateVars", "r2cm", "round to up to 1 decimal"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(r2cm_F, translate("VTranslateVars", "round to up to 1 decimal", "function r2cm"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(r2cm_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
functions.insert(csrCm_F, translate("VTranslateVars", "csrCm",
|
|
|
|
"cut, split and rotate modeling operation. Takes"
|
|
|
|
" cm units."));
|
|
|
|
functionsDescriptions.insert(csrCm_F, translate("VTranslateVars",
|
|
|
|
"cut, split and rotate modeling operation. Takes "
|
|
|
|
"cm units.",
|
|
|
|
"function csrCm"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(csrCm_F, threeArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
functions.insert(csrInch_F, translate("VTranslateVars", "csrInch",
|
|
|
|
"cut, split and rotate modeling operation. Takes"
|
|
|
|
" inch units."));
|
|
|
|
functionsDescriptions.insert(csrInch_F, translate("VTranslateVars",
|
|
|
|
"cut, split and rotate modeling operation. "
|
|
|
|
"Takes inch units.",
|
|
|
|
"function csrInch"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(csrInch_F, threeArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(abs_F, translate("VTranslateVars", "abs", "absolute value"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(abs_F, translate("VTranslateVars", "absolute value", "function abs"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(abs_F, oneArgument);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(min_F, translate("VTranslateVars", "min", "min of all arguments"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(min_F, translate("VTranslateVars", "min of all arguments", "function min"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(min_F, twoArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(max_F, translate("VTranslateVars", "max", "max of all arguments"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(max_F, translate("VTranslateVars", "max of all arguments", "function max"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(max_F, twoArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(sum_F, translate("VTranslateVars", "sum", "sum of all arguments"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(sum_F, translate("VTranslateVars", "sum of all arguments", "function sum"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(sum_F, threeArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(avg_F, translate("VTranslateVars", "avg", "mean value of all arguments"));
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.insert(avg_F, translate("VTranslateVars", "mean value of all arguments", "function avg"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(avg_F, threeArguments);
|
2020-02-27 16:26:32 +01:00
|
|
|
|
2015-10-16 22:00:05 +02:00
|
|
|
functions.insert(fmod_F, translate("VTranslateVars", "fmod",
|
2015-10-15 11:32:50 +02:00
|
|
|
"Returns the floating-point remainder of numer/denom (rounded towards zero)"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(fmod_F, translate("VTranslateVars",
|
|
|
|
"Returns the floating-point remainder of "
|
|
|
|
"numer/denom (rounded towards zero)",
|
|
|
|
"function fmod"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(fmod_F, twoArguments);
|
|
|
|
|
2020-11-20 12:18:38 +01:00
|
|
|
functions.insert(warning_F, translate("VTranslateVars", "warning", "Calculation warning"));
|
2023-05-17 15:24:27 +02:00
|
|
|
functionsDescriptions.insert(warning_F,
|
|
|
|
translate("VTranslateVars", "Show a warning in calculations", "function warning"));
|
2022-08-02 19:11:18 +02:00
|
|
|
functionsArguments.insert(warning_F, twoArguments);
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 11:32:50 +02:00
|
|
|
#undef translate
|
2015-10-08 07:24:15 +02:00
|
|
|
|
2017-12-04 10:44:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VTranslateVars::PrepareFunctionTranslations()
|
|
|
|
{
|
|
|
|
translatedFunctions.clear();
|
|
|
|
QMap<QString, qmu::QmuTranslation>::const_iterator i = functions.constBegin();
|
|
|
|
while (i != functions.constEnd())
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
const QString translated = i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2017-12-04 10:44:29 +01:00
|
|
|
if (i.key() != translated)
|
|
|
|
{
|
|
|
|
translatedFunctions.insert(translated, i.key());
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CorrectionsPositions correct position tokens in expression after token translation.
|
|
|
|
*
|
|
|
|
* Because translated string can have different length compare to original need make correction after each translation.
|
|
|
|
* If bias = 0 correction will not happens.
|
|
|
|
*
|
|
|
|
* @param position position currecnt token in expression
|
|
|
|
* @param bias difference between original token length and translated
|
|
|
|
* @param tokens all tokens
|
|
|
|
* @param numbers all numbers
|
|
|
|
*/
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::CorrectionsPositions(vsizetype position, vsizetype bias, QMap<vsizetype, QString> &tokens,
|
|
|
|
QMap<vsizetype, QString> &numbers)
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
|
|
|
if (bias == 0)
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
return; // Nothing to correct;
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BiasTokens(position, bias, tokens);
|
|
|
|
BiasTokens(position, bias, numbers);
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:12:23 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::TranslateVarsFromUser(QString &newFormula, QMap<vsizetype, QString> &tokens,
|
|
|
|
QMap<vsizetype, QString> &numbers) const
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
QList<vsizetype> tKeys = tokens.keys(); // Take all tokens positions
|
2022-08-02 19:12:23 +02:00
|
|
|
QList<QString> tValues = tokens.values();
|
2023-02-09 16:23:11 +01:00
|
|
|
for (vsizetype i = 0; i < tKeys.size(); ++i)
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype bias = 0;
|
2022-08-02 19:12:23 +02:00
|
|
|
if (VariablesFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
|
|
|
{
|
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated token has different length than original. Position of next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
|
|
|
tKeys = tokens.keys();
|
|
|
|
tValues = tokens.values();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FunctionsFromUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
|
|
|
{
|
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated token has different length than original. Position of next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
|
|
|
tKeys = tokens.keys();
|
|
|
|
tValues = tokens.values();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-09 14:42:34 +01:00
|
|
|
if (tValues.at(i) == LocaleNegativeSign(QLocale()))
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // unary minus
|
2022-08-02 19:12:23 +02:00
|
|
|
newFormula.replace(tKeys.at(i), 1, '-');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::TranslateNumbersFromUser(QString &newFormula, QMap<vsizetype, QString> &tokens,
|
|
|
|
QMap<vsizetype, QString> &numbers, bool osSeparator)
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
|
|
|
QLocale loc = QLocale(); // User locale
|
|
|
|
if (loc != QLocale::c() && osSeparator)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // User want use Os separator
|
|
|
|
QList<vsizetype> nKeys = numbers.keys(); // Positions for all numbers in expression
|
2022-08-02 19:12:23 +02:00
|
|
|
QList<QString> nValues = numbers.values();
|
|
|
|
for (int i = 0; i < nKeys.size(); ++i)
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
loc = QLocale(); // From system locale
|
2022-08-02 19:12:23 +02:00
|
|
|
bool ok = false;
|
|
|
|
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
|
|
|
if (not ok)
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
qDebug() << "Can't convert to double token" << nValues.at(i);
|
|
|
|
continue; // Leave with out translation
|
2022-08-02 19:12:23 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
loc = QLocale::c(); // To internal locale
|
|
|
|
const QString dStr = loc.toString(d); // Internal look for number
|
2022-08-02 19:12:23 +02:00
|
|
|
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
2023-02-09 16:23:11 +01:00
|
|
|
const auto bias = nValues.at(i).length() - dStr.length();
|
2022-08-02 19:12:23 +02:00
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated number has different length than original. Position next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
|
|
|
nKeys = numbers.keys();
|
|
|
|
nValues = numbers.values();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::TranslateVarsToUser(QString &newFormula, QMap<vsizetype, QString> &tokens,
|
|
|
|
QMap<vsizetype, QString> &numbers) const
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
QList<vsizetype> tKeys = tokens.keys();
|
2022-08-02 19:12:23 +02:00
|
|
|
QList<QString> tValues = tokens.values();
|
2023-02-09 16:23:11 +01:00
|
|
|
for (vsizetype i = 0; i < tKeys.size(); ++i)
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
|
|
|
if (functions.contains(tValues.at(i)))
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
newFormula.replace(
|
|
|
|
tKeys.at(i), tValues.at(i).length(),
|
|
|
|
functions.value(tValues.at(i)).translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
|
|
|
auto bias = tValues.at(i).length() - functions.value(tValues.at(i))
|
|
|
|
.translate(VAbstractApplication::VApp()->Settings()->GetLocale())
|
|
|
|
.length();
|
2022-08-02 19:12:23 +02:00
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated token has different length than original. Position next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
|
|
|
tKeys = tokens.keys();
|
|
|
|
tValues = tokens.values();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype bias = 0;
|
2022-08-02 19:12:23 +02:00
|
|
|
if (VariablesToUser(newFormula, tKeys.at(i), tValues.at(i), bias))
|
|
|
|
{
|
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated token has different length than original. Position next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(tKeys.at(i), bias, tokens, numbers);
|
|
|
|
tKeys = tokens.keys();
|
|
|
|
tValues = tokens.values();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-10-07 17:56:39 +02:00
|
|
|
if (tValues.at(i) == '-'_L1)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // unary minus
|
2023-02-09 14:42:34 +01:00
|
|
|
newFormula.replace(tKeys.at(i), 1, LocaleNegativeSign(QLocale()));
|
2022-08-02 19:12:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::TranslateNumbersToUser(QString &newFormula, QMap<vsizetype, QString> &tokens,
|
|
|
|
QMap<vsizetype, QString> &numbers, bool osSeparator)
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
QLocale loc = QLocale(); // User locale
|
2022-08-02 19:12:23 +02:00
|
|
|
if (loc != QLocale::C && osSeparator)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // User want use Os separator
|
|
|
|
QList<vsizetype> nKeys = numbers.keys(); // Positions for all numbers in expression
|
2022-08-02 19:12:23 +02:00
|
|
|
QList<QString> nValues = numbers.values();
|
|
|
|
for (int i = 0; i < nKeys.size(); ++i)
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
loc = QLocale::c(); // From pattern locale
|
2022-08-02 19:12:23 +02:00
|
|
|
bool ok = false;
|
|
|
|
const qreal d = loc.toDouble(nValues.at(i), &ok);
|
|
|
|
if (not ok)
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
qDebug() << "Can't convert to double token" << nValues.at(i);
|
|
|
|
continue; // Leave with out translation
|
2022-08-02 19:12:23 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
loc = QLocale(); // To user locale
|
|
|
|
QString dStr = loc.toString(d); // Number string in user locale
|
2024-01-23 14:57:23 +01:00
|
|
|
if (LocaleGroupSeparator(loc).isSpace())
|
2022-08-02 19:12:23 +02:00
|
|
|
{
|
2023-02-09 14:42:34 +01:00
|
|
|
dStr.replace(LocaleGroupSeparator(loc), QString());
|
2022-08-02 19:12:23 +02:00
|
|
|
}
|
|
|
|
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
|
2023-02-09 16:23:11 +01:00
|
|
|
const auto bias = nValues.at(i).length() - dStr.length();
|
2022-08-02 19:12:23 +02:00
|
|
|
if (bias != 0)
|
2023-05-17 15:24:27 +02:00
|
|
|
{ // Translated number has different length than original. Position next tokens need to be corrected.
|
2022-08-02 19:12:23 +02:00
|
|
|
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
|
|
|
|
nKeys = numbers.keys();
|
|
|
|
nValues = numbers.values();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief BiasTokens change position for each token that have position more then "position".
|
|
|
|
* @param position token position
|
|
|
|
* @param bias difference between original token length and translated
|
|
|
|
* @param tokens all tokens
|
|
|
|
*/
|
2023-02-09 16:23:11 +01:00
|
|
|
void VTranslateVars::BiasTokens(vsizetype position, vsizetype bias, QMap<vsizetype, QString> &tokens)
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
QMap<vsizetype, QString> newTokens;
|
|
|
|
QMap<vsizetype, QString>::const_iterator i = tokens.constBegin();
|
2015-06-11 12:15:57 +02:00
|
|
|
while (i != tokens.constEnd())
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
if (i.key() <= position)
|
2015-06-11 12:15:57 +02:00
|
|
|
{ // Tokens before position "position" did not change his positions.
|
|
|
|
newTokens.insert(i.key(), i.value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
newTokens.insert(i.key() - bias, i.value());
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
tokens = newTokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VariablesFromUser translate variable to internal look.
|
|
|
|
* @param newFormula [in|out] expression to translate
|
|
|
|
* @param position token position
|
|
|
|
* @param token token to translate
|
|
|
|
* @param bias hold change of length between translated and origin token string
|
|
|
|
* @return true if was found variable with same name.
|
|
|
|
*/
|
2023-02-09 16:23:11 +01:00
|
|
|
auto VTranslateVars::VariablesFromUser(QString &newFormula, vsizetype position, const QString &token,
|
|
|
|
vsizetype &bias) const -> bool
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
const QString currentLengthTr =
|
2023-05-17 15:24:27 +02:00
|
|
|
variables.value(currentLength).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
|
|
|
const QString currentSeamAllowanceTr =
|
|
|
|
variables.value(currentSeamAllowance).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2017-08-04 09:28:44 +02:00
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
QMap<QString, qmu::QmuTranslation>::const_iterator i = variables.constBegin();
|
2015-06-11 12:15:57 +02:00
|
|
|
while (i != variables.constEnd())
|
|
|
|
{
|
2016-12-21 13:02:55 +01:00
|
|
|
const qmu::QmuTranslation &var = i.value();
|
2021-02-06 14:52:21 +01:00
|
|
|
const QString varTr = var.translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2017-08-04 09:28:44 +02:00
|
|
|
|
|
|
|
if (token.indexOf(varTr) == 0)
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2017-08-04 09:28:44 +02:00
|
|
|
if ((varTr == currentLengthTr || varTr == currentSeamAllowanceTr) && token != varTr)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
newFormula.replace(position, varTr.length(), i.key());
|
2015-06-11 12:15:57 +02:00
|
|
|
QString newToken = token;
|
2017-08-04 09:28:44 +02:00
|
|
|
newToken.replace(0, varTr.length(), i.key());
|
2015-06-11 12:15:57 +02:00
|
|
|
bias = token.length() - newToken.length();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FunctionsFromUser translate function name to internal look.
|
|
|
|
* @param newFormula [in|out] expression to translate
|
|
|
|
* @param position token position
|
|
|
|
* @param token token to translate
|
|
|
|
* @param bias hold change of length between translated and origin token string
|
|
|
|
* @return true if was found function with same name.
|
|
|
|
*/
|
2023-02-09 16:23:11 +01:00
|
|
|
auto VTranslateVars::FunctionsFromUser(QString &newFormula, vsizetype position, const QString &token,
|
|
|
|
vsizetype &bias) const -> bool
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2016-12-21 13:02:55 +01:00
|
|
|
QMap<QString, qmu::QmuTranslation>::const_iterator i = functions.constBegin();
|
2015-06-11 12:15:57 +02:00
|
|
|
while (i != functions.constEnd())
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
if (token == i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale()))
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
|
|
|
newFormula.replace(position, token.length(), i.key());
|
|
|
|
bias = token.length() - i.key().length();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VariablesToUser translate variable name to user.
|
|
|
|
* @param newFormula [in|out] expression to translate
|
|
|
|
* @param position token position
|
|
|
|
* @param token token to translate
|
|
|
|
* @param bias hold change of length between translated and origin token string
|
|
|
|
* @return true if was found variable with same name.
|
|
|
|
*/
|
2023-02-09 16:23:11 +01:00
|
|
|
auto VTranslateVars::VariablesToUser(QString &newFormula, vsizetype position, const QString &token,
|
|
|
|
vsizetype &bias) const -> bool
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2016-12-21 13:02:55 +01:00
|
|
|
QMap<QString, qmu::QmuTranslation>::const_iterator i = variables.constBegin();
|
2015-06-11 12:15:57 +02:00
|
|
|
while (i != variables.constEnd())
|
|
|
|
{
|
2023-05-17 15:24:27 +02:00
|
|
|
if (token.indexOf(i.key()) == 0)
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2017-08-04 09:28:44 +02:00
|
|
|
if ((i.key() == currentLength || i.key() == currentSeamAllowance) && token != i.key())
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
newFormula.replace(position, i.key().length(),
|
|
|
|
i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
2015-06-11 12:15:57 +02:00
|
|
|
|
|
|
|
QString newToken = token;
|
2021-02-06 14:52:21 +01:00
|
|
|
newToken.replace(0, i.key().length(),
|
|
|
|
i.value().translate(VAbstractApplication::VApp()->Settings()->GetLocale()));
|
2015-06-11 12:15:57 +02:00
|
|
|
bias = token.length() - newToken.length();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-17 11:52:10 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::InternalVarToUser(const QString &var) const -> QString
|
2015-12-17 11:52:10 +01:00
|
|
|
{
|
2023-10-06 09:57:46 +02:00
|
|
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
|
|
|
if (!settings->IsTranslateFormula())
|
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2015-12-17 11:52:10 +01:00
|
|
|
QString newVar = var;
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype bias = 0;
|
2015-12-17 11:52:10 +01:00
|
|
|
if (VariablesToUser(newVar, 0, var, bias))
|
|
|
|
{
|
|
|
|
return newVar;
|
|
|
|
}
|
2022-08-02 19:12:23 +02:00
|
|
|
|
|
|
|
return var;
|
2015-12-17 11:52:10 +01:00
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::VarToUser(const QString &var) const -> QString
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2023-05-17 15:25:27 +02:00
|
|
|
const QString locale = VAbstractApplication::VApp()->Settings()->GetLocale();
|
|
|
|
if (locale == QStringLiteral("zh_CN") || locale == QStringLiteral("he_IL"))
|
2019-01-17 15:08:55 +01:00
|
|
|
{
|
2023-05-17 15:25:27 +02:00
|
|
|
return var; // We do not support translation of variables for these locales
|
2019-01-17 15:08:55 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 09:57:46 +02:00
|
|
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
|
|
|
if (!settings->IsTranslateFormula())
|
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
if (functions.contains(var))
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
return functions.value(var).translate(VAbstractApplication::VApp()->Settings()->GetLocale());
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 11:52:10 +01:00
|
|
|
return InternalVarToUser(var);
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::VarFromUser(const QString &var) const -> QString
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
2023-05-17 15:25:27 +02:00
|
|
|
const QString locale = VAbstractApplication::VApp()->Settings()->GetLocale();
|
|
|
|
if (locale == QStringLiteral("zh_CN") || locale == QStringLiteral("he_IL"))
|
2019-01-17 15:08:55 +01:00
|
|
|
{
|
|
|
|
return var; // We do not support translation of variables for Chinese
|
|
|
|
}
|
|
|
|
|
2023-10-06 09:57:46 +02:00
|
|
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
|
|
|
if (!settings->IsTranslateFormula())
|
|
|
|
{
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
QString newVar = var;
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype bias = 0;
|
2015-06-11 12:15:57 +02:00
|
|
|
if (VariablesFromUser(newVar, 0, var, bias))
|
|
|
|
{
|
|
|
|
return newVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FunctionsFromUser(newVar, 0, var, bias))
|
|
|
|
{
|
|
|
|
return newVar;
|
|
|
|
}
|
2024-02-08 17:37:51 +01:00
|
|
|
return var;
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FormulaFromUser replace all known tokens in formula to internal look. Also change decimal
|
|
|
|
* separator in numbers.
|
|
|
|
* @param formula expression that need translate
|
2015-08-25 12:35:50 +02:00
|
|
|
* @throw qmu::QmuParserError in case of a wrong expression
|
2015-06-11 12:15:57 +02:00
|
|
|
* @return translated expression
|
|
|
|
*/
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator) const -> QString
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
|
2017-12-04 10:44:29 +01:00
|
|
|
// Eval formula
|
2022-08-02 19:12:23 +02:00
|
|
|
QScopedPointer<qmu::QmuTokenParser> cal(
|
|
|
|
new qmu::QmuTokenParser(formula, osSeparator, true, GetTranslatedFunctions()));
|
2023-05-17 15:24:27 +02:00
|
|
|
QMap<vsizetype, QString> tokens = cal->GetTokens(); // Tokens (variables, measurements)
|
|
|
|
QMap<vsizetype, QString> numbers = cal->GetNumbers(); // All numbers in expression for changing decimal separator
|
2023-04-03 12:44:20 +02:00
|
|
|
cal.reset();
|
2015-06-11 12:15:57 +02:00
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
QString newFormula = formula; // Local copy for making changes
|
2015-06-11 12:15:57 +02:00
|
|
|
|
2024-01-06 14:47:59 +01:00
|
|
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
|
|
|
if (settings->IsTranslateFormula())
|
|
|
|
{
|
|
|
|
TranslateVarsFromUser(newFormula, tokens, numbers);
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:12:23 +02:00
|
|
|
TranslateNumbersFromUser(newFormula, tokens, numbers, osSeparator);
|
2015-06-11 12:15:57 +02:00
|
|
|
|
|
|
|
return newFormula;
|
|
|
|
}
|
|
|
|
|
2016-03-05 16:27:07 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::TryFormulaFromUser(const QString &formula, bool osSeparator) -> QString
|
2016-03-05 16:27:07 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
SCASSERT(VAbstractApplication::VApp()->TrVars() != nullptr)
|
|
|
|
return VAbstractApplication::VApp()->TrVars()->FormulaFromUser(formula, osSeparator);
|
2016-03-05 16:27:07 +01:00
|
|
|
}
|
2023-05-17 15:24:27 +02:00
|
|
|
catch (qmu::QmuParserError &e) // In case something bad will happen
|
2016-03-05 16:27:07 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-11 12:15:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief FormulaToUser replace all known tokens in formula to user look. Also change decimal
|
|
|
|
* separator in numbers.
|
|
|
|
* @param formula expression that need translate
|
|
|
|
* @return translated expression
|
|
|
|
*/
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) const -> QString
|
2015-06-11 12:15:57 +02:00
|
|
|
{
|
|
|
|
if (formula.isEmpty())
|
|
|
|
{
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
|
2023-05-17 15:24:27 +02:00
|
|
|
QString newFormula = formula; // Local copy for making changes
|
2015-06-11 12:15:57 +02:00
|
|
|
|
2023-02-09 16:23:11 +01:00
|
|
|
QMap<vsizetype, QString> tokens;
|
|
|
|
QMap<vsizetype, QString> numbers;
|
2015-06-11 12:15:57 +02:00
|
|
|
try
|
|
|
|
{
|
2024-02-19 17:09:56 +01:00
|
|
|
QScopedPointer<qmu::QmuTokenParser> const cal(new qmu::QmuTokenParser(formula, false, false)); // Eval formula
|
2023-05-17 15:24:27 +02:00
|
|
|
tokens = cal->GetTokens(); // Tokens (variables, measurements)
|
|
|
|
numbers = cal->GetNumbers(); // All numbers in expression for changing decimal separator
|
2015-06-11 12:15:57 +02:00
|
|
|
}
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
qDebug() << "\nMath parser error:\n"
|
|
|
|
<< "--------------------------------------\n"
|
2023-05-17 15:24:27 +02:00
|
|
|
<< "Message: " << e.GetMsg() << "\n"
|
2015-06-11 12:15:57 +02:00
|
|
|
<< "Expression: " << e.GetExpr() << "\n"
|
|
|
|
<< "--------------------------------------";
|
|
|
|
return newFormula;
|
|
|
|
}
|
|
|
|
|
2024-01-06 14:47:59 +01:00
|
|
|
VCommonSettings *settings = VAbstractApplication::VApp()->Settings();
|
|
|
|
if (settings->IsTranslateFormula())
|
|
|
|
{
|
|
|
|
TranslateVarsToUser(newFormula, tokens, numbers);
|
|
|
|
}
|
|
|
|
|
2022-08-02 19:12:23 +02:00
|
|
|
TranslateNumbersToUser(newFormula, tokens, numbers, osSeparator);
|
2015-06-11 12:15:57 +02:00
|
|
|
|
|
|
|
return newFormula;
|
|
|
|
}
|
2015-08-01 11:39:32 +02:00
|
|
|
|
2017-09-26 16:24:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::TryFormulaToUser(const QString &formula, bool osSeparator) -> QString
|
2017-09-26 16:24:02 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
return VAbstractApplication::VApp()->TrVars()->FormulaToUser(formula, osSeparator);
|
2017-09-26 16:24:02 +02:00
|
|
|
}
|
2023-05-17 15:24:27 +02:00
|
|
|
catch (qmu::QmuParserError &e) // In case something bad will happen
|
2017-09-26 16:24:02 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VTranslateVars::Retranslate()
|
|
|
|
{
|
|
|
|
variables.clear();
|
|
|
|
functions.clear();
|
2020-02-27 16:28:20 +01:00
|
|
|
functionsDescriptions.clear();
|
2015-08-08 16:33:37 +02:00
|
|
|
stDescriptions.clear();
|
|
|
|
|
|
|
|
InitVariables();
|
|
|
|
InitFunctions();
|
2017-12-04 10:44:29 +01:00
|
|
|
|
|
|
|
PrepareFunctionTranslations();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::GetTranslatedFunctions() const -> QMap<QString, QString>
|
2017-12-04 10:44:29 +01:00
|
|
|
{
|
|
|
|
return translatedFunctions;
|
2015-08-08 16:33:37 +02:00
|
|
|
}
|
2016-08-16 22:13:34 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::GetFunctions() const -> QMap<QString, qmu::QmuTranslation>
|
2016-08-16 22:13:34 +02:00
|
|
|
{
|
|
|
|
return functions;
|
|
|
|
}
|
2020-02-27 16:26:32 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::GetFunctionsDescriptions() const -> QMap<QString, qmu::QmuTranslation>
|
2020-02-27 16:26:32 +01:00
|
|
|
{
|
2020-02-27 16:28:20 +01:00
|
|
|
return functionsDescriptions;
|
2020-02-27 16:26:32 +01:00
|
|
|
}
|
2022-08-02 19:11:18 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2022-08-02 19:12:23 +02:00
|
|
|
auto VTranslateVars::GetFunctionsArguments() const -> QMap<QString, QString>
|
2022-08-02 19:11:18 +02:00
|
|
|
{
|
|
|
|
return functionsArguments;
|
|
|
|
}
|