Use new math parser instead old.
--HG-- branch : feature
This commit is contained in:
parent
0b16424a5e
commit
bd5fda320f
|
@ -28,15 +28,7 @@
|
||||||
|
|
||||||
#include "calculator.h"
|
#include "calculator.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include "../widgets/vapplication.h"
|
||||||
#define DELIMITER 1
|
|
||||||
#define VARIABLE 2
|
|
||||||
#define NUMBER 3
|
|
||||||
#define COMMAND 4
|
|
||||||
#define STRING 5
|
|
||||||
#define QUOTE 6
|
|
||||||
#define FINISHED 10
|
|
||||||
#define EOL 9
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -44,433 +36,187 @@
|
||||||
* @param data pointer to a variable container.
|
* @param data pointer to a variable container.
|
||||||
*/
|
*/
|
||||||
Calculator::Calculator(const VContainer *data)
|
Calculator::Calculator(const VContainer *data)
|
||||||
:errorMsg(nullptr), token(QString()), tok(0), token_type(0), prog(QString()), index(0), data(data),
|
:QmuParser()
|
||||||
debugFormula(QString())
|
{
|
||||||
{}
|
//String with all unique symbols for supported alpabets.
|
||||||
|
// See script alphabets.py for generation and more information.
|
||||||
|
const QString symbols = QStringLiteral("ցЀĆЈVӧĎАғΕĖӅИқΝĞơРңњΥĦШҫ̆جگĮаҳѕεشԶиһνԾрυلՆӝшËՎҔPÓՖXӛӟŞӣզhëծpóӞնxßվāŁЃֆĉЋCŬđ"
|
||||||
|
"ҐГΒęҘЛΚŘġҠУGاհЫدԱҰгβطԹõлκKՁÀуςهՉÈыvیՑÐSOřӘћաőcӐթèkàѓżűðsķչøӥӔĀփїІĈЎґĐΗЖҙĘȚ"
|
||||||
|
"ΟОҡĠآΧЦتЮұİزηжԸغοоÁՀقχцÉՈيюÑՐђӋіәťӆўáŠĺѐfөըnñŰӤӨӹոľЁրăЉŭċБӸēłΔҖЙŤěΜӜDСձģΤӰ"
|
||||||
|
"ЩīņحҮбưԳصδHйԻŇμӲӴсՃمτƠщՋєLQŹՓŕÖYśÞaգĽæiŽիӓîqճöyջþĂօЄӦĊЌΑĒДҗјΙȘĚМΡéĵĢФūӚΩبĪ"
|
||||||
|
"ЬүќαذԲдҷιظԺмρՂфÇωوՊьÏՒTŚĻJբdçժlïӪղtպӫAւąЇčŃЏĕӯЗΖEțŮĝПΞأĥĹЧΦثÆӳЯIسŲԵзζԽпξكՅ"
|
||||||
|
"ÄчφNMՍӌяӢՕÔWÎŝÜџёźեägխoӒյôwĶBžսüЂĄև̈ЊČƏљΓВҕĔӮΛКĜΣТҥĤکЪƯخγвŅԴŪضλкԼĴσтÅՄنъÍՌR"
|
||||||
|
"ӕՔZÝŜbåդﻩjíլļrӵմzýռپêЅքćچЍďӱҒЕůėژșΘØҚНğńءΠFҢХħΨҪЭųįҶرҲеԷňعθҺнԿفπÂхՇψÊэšՏÒU"
|
||||||
|
"əÚѝŻşҤӑâeէŐımկòuշÕúտŔ");
|
||||||
|
|
||||||
|
// Defining identifier character sets
|
||||||
|
DefineNameChars(QStringLiteral("0123456789_") + symbols);
|
||||||
|
DefineOprtChars(symbols + QStringLiteral("+-*^/?<>=#!$%&|~'_"));
|
||||||
|
|
||||||
|
// Add variables
|
||||||
|
InitVariables(data);
|
||||||
|
|
||||||
|
// Add unary operators
|
||||||
|
DefinePostfixOprt(cm_Oprt, CmUnit);
|
||||||
|
DefinePostfixOprt(mm_Oprt, MmUnit);
|
||||||
|
DefinePostfixOprt(in_Oprt, InchUnit);
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief eval calculate formula.
|
* @brief eval calculate formula.
|
||||||
* @param prog string of formula.
|
* @param formula string of formula.
|
||||||
* @param errorMsg keep error message.
|
|
||||||
* @return value of formula.
|
* @return value of formula.
|
||||||
*/
|
*/
|
||||||
qreal Calculator::eval(QString prog, QString *errorMsg)
|
qreal Calculator::EvalFormula(const QString &formula)
|
||||||
{
|
{
|
||||||
this->errorMsg = errorMsg;
|
SetExpr(formula);
|
||||||
this->errorMsg->clear();
|
return Eval();
|
||||||
debugFormula.clear();
|
|
||||||
this->prog = prog;
|
|
||||||
//qDebug()<<"Formula: "<<prog;
|
|
||||||
index = 0;
|
|
||||||
qreal result = get_exp();
|
|
||||||
QString str = QString(" = %1").arg(result, 0, 'f', 3);
|
|
||||||
debugFormula.append(str);
|
|
||||||
//qDebug()<<"Result:"<<debugFormula;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
void Calculator::InitVariables(const VContainer *data)
|
||||||
* @brief get_exp calculate formula.
|
|
||||||
* @return value of formula.
|
|
||||||
*/
|
|
||||||
qreal Calculator::get_exp()
|
|
||||||
{
|
{
|
||||||
qreal result = 0;
|
if (qApp->patternType() == Pattern::Standard)
|
||||||
get_token();
|
|
||||||
if (token.isEmpty())
|
|
||||||
{
|
{
|
||||||
serror(2);
|
DefineVar(data->SizeName(), data->size());
|
||||||
return 0;
|
DefineVar(data->HeightName(), data->height());
|
||||||
}
|
}
|
||||||
level2(&result);
|
|
||||||
putback();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief level2 method of addition and subtraction of two terms.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::level2(qreal *result)
|
|
||||||
{
|
|
||||||
QChar op;
|
|
||||||
qreal hold;
|
|
||||||
|
|
||||||
level3(result);
|
|
||||||
while ((op=token[0]) == '+' || op == '-')
|
|
||||||
{
|
{
|
||||||
get_token();
|
const QHash<QString, qreal> *lengthLines = data->DataLengthLines();
|
||||||
level3(&hold);
|
QHash<QString, qreal>::const_iterator i = lengthLines->constBegin();
|
||||||
arith(op, result, &hold);
|
while (i != lengthLines->constEnd())
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief level3 method of multiplication, division, finding percent.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::level3(qreal *result)
|
|
||||||
{
|
|
||||||
QChar op;
|
|
||||||
qreal hold;
|
|
||||||
|
|
||||||
level4(result);
|
|
||||||
|
|
||||||
while ((op = token[0]) == '*' || op == '/' || op == '%')
|
|
||||||
{
|
|
||||||
get_token();
|
|
||||||
level4(&hold);
|
|
||||||
arith(op, result, &hold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief level4 method of degree two numbers.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::level4(qreal *result)
|
|
||||||
{
|
|
||||||
qreal hold;
|
|
||||||
|
|
||||||
level5(result);
|
|
||||||
if (token[0] == '^')
|
|
||||||
{
|
|
||||||
get_token();
|
|
||||||
level4(&hold);
|
|
||||||
arith('^', result, &hold);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief level5 method for finding unary plus or minus.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::level5(qreal *result)
|
|
||||||
{
|
|
||||||
QChar op;
|
|
||||||
|
|
||||||
op = '\0';
|
|
||||||
if ((token_type==DELIMITER) && (token[0]=='+' || token[0]=='-'))
|
|
||||||
{
|
|
||||||
op = token[0];
|
|
||||||
get_token();
|
|
||||||
}
|
|
||||||
level6(result);
|
|
||||||
if (op != '\0')
|
|
||||||
{
|
|
||||||
unary(op, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief level6 processing method of the expression in brackets.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::level6(qreal *result)
|
|
||||||
{
|
|
||||||
if ((token[0] == '(') && (token_type == DELIMITER))
|
|
||||||
{
|
|
||||||
get_token();
|
|
||||||
level2(result);
|
|
||||||
if (token[0] != ')')
|
|
||||||
{
|
{
|
||||||
serror(1);
|
DefineVar(i.key(), i.value());
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
get_token();
|
}
|
||||||
} else
|
|
||||||
primitive(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief primitive method of determining the value of a variable by its name.
|
|
||||||
* @param result result of operation.
|
|
||||||
*/
|
|
||||||
void Calculator::primitive(qreal *result)
|
|
||||||
{
|
|
||||||
QString str;
|
|
||||||
switch (token_type)
|
|
||||||
{
|
{
|
||||||
case VARIABLE:
|
const QHash<QString, qreal> *lengthSplines = data->DataLengthSplines();
|
||||||
*result = find_var(token);
|
QHash<QString, qreal>::const_iterator i = lengthSplines->constBegin();
|
||||||
str = QString("%1").arg(*result, 0, 'f', 3);
|
while (i != lengthSplines->constEnd())
|
||||||
debugFormula.append(str);
|
{
|
||||||
get_token();
|
DefineVar(i.key(), i.value());
|
||||||
return;
|
++i;
|
||||||
case NUMBER:
|
}
|
||||||
*result = token.toDouble();
|
}
|
||||||
str = QString("%1").arg(*result, 0, 'f', 3);
|
|
||||||
debugFormula.append(str);
|
{
|
||||||
get_token();
|
const QHash<QString, qreal> *lengthArcs = data->DataLengthArcs();
|
||||||
return;
|
QHash<QString, qreal>::const_iterator i = lengthArcs->constBegin();
|
||||||
default:
|
while (i != lengthArcs->constEnd())
|
||||||
serror(0);
|
{
|
||||||
|
DefineVar(i.key(), i.value());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const QHash<QString, qreal> *lineAngles = data->DataLineAngles();
|
||||||
|
QHash<QString, qreal>::const_iterator i = lineAngles->constBegin();
|
||||||
|
while (i != lineAngles->constEnd())
|
||||||
|
{
|
||||||
|
DefineVar(i.key(), i.value());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const QHash<QString, VMeasurement> *measurements = data->DataMeasurements();
|
||||||
|
QHash<QString, VMeasurement>::const_iterator i = measurements->constBegin();
|
||||||
|
while (i != measurements->constEnd())
|
||||||
|
{
|
||||||
|
if (qApp->patternType() == Pattern::Standard)
|
||||||
|
{
|
||||||
|
DefineVar(i.key(), i.value().GetValue(data->size(), data->height()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DefineVar(i.key(), i.value().GetValue());
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const QHash<QString, VIncrement> *increments = data->DataIncrements();
|
||||||
|
QHash<QString, VIncrement>::const_iterator i = increments->constBegin();
|
||||||
|
while (i != increments->constEnd())
|
||||||
|
{
|
||||||
|
if (qApp->patternType() == Pattern::Standard)
|
||||||
|
{
|
||||||
|
DefineVar(i.key(), i.value().GetValue(data->size(), data->height()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DefineVar(i.key(), i.value().GetValue());
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
qreal Calculator::CmUnit(qreal val)
|
||||||
* @brief arith perform the specified arithmetic. The result is written to the first element.
|
|
||||||
* @param o sign of operation.
|
|
||||||
* @param r first element.
|
|
||||||
* @param h second element.
|
|
||||||
*/
|
|
||||||
void Calculator::arith(QChar o, qreal *r, qreal *h)
|
|
||||||
{
|
{
|
||||||
qreal t;//, ex;
|
qreal unit = val;
|
||||||
|
switch(qApp->patternUnit())
|
||||||
switch (o.toLatin1())
|
|
||||||
{
|
{
|
||||||
case '-':
|
case Valentina::Mm:
|
||||||
*r = *r-*h;
|
unit = val * 10.0;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case Valentina::Cm:
|
||||||
*r = *r+*h;
|
|
||||||
break;
|
break;
|
||||||
case '*':
|
case Valentina::Inch:
|
||||||
*r = *r * *h;
|
unit = val / 2.54;
|
||||||
break;
|
|
||||||
case '/':
|
|
||||||
*r = (*r)/(*h);
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
t = (*r)/(*h);
|
|
||||||
*r = *r-(t*(*h));
|
|
||||||
break;
|
|
||||||
case '^':
|
|
||||||
*r = pow(*r, *h);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
qreal Calculator::MmUnit(qreal val)
|
||||||
* @brief unary method changes the sign.
|
|
||||||
* @param o sign of symbol.
|
|
||||||
* @param r element.
|
|
||||||
*/
|
|
||||||
void Calculator::unary(QChar o, qreal *r)
|
|
||||||
{
|
{
|
||||||
if (o=='-')
|
qreal unit = val;
|
||||||
|
switch(qApp->patternUnit())
|
||||||
{
|
{
|
||||||
*r = -(*r);
|
case Valentina::Mm:
|
||||||
|
break;
|
||||||
|
case Valentina::Cm:
|
||||||
|
unit = val / 10.0;
|
||||||
|
break;
|
||||||
|
case Valentina::Inch:
|
||||||
|
unit = val / 25.4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
qreal Calculator::InchUnit(qreal val)
|
||||||
* @brief find_var method is finding variable by name.
|
|
||||||
* @param s name of variable.
|
|
||||||
* @return value of variable.
|
|
||||||
*/
|
|
||||||
qreal Calculator::find_var(QString s)
|
|
||||||
{
|
{
|
||||||
bool ok = false;
|
qreal unit = val;
|
||||||
qreal value = data->FindVar(s, &ok);
|
switch(qApp->patternUnit())
|
||||||
if (ok == false)
|
|
||||||
{
|
{
|
||||||
qDebug()<<s;
|
case Valentina::Mm:
|
||||||
serror(4); /* don't variable */
|
unit = val * 25.4;
|
||||||
return 0;
|
break;
|
||||||
|
case Valentina::Cm:
|
||||||
|
unit = val * 2.54;
|
||||||
|
break;
|
||||||
|
case Valentina::Inch:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
}
|
return unit;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief serror report an error
|
|
||||||
* @param error error code
|
|
||||||
*/
|
|
||||||
void Calculator::serror(qint32 error)
|
|
||||||
{
|
|
||||||
QString e[]=
|
|
||||||
{
|
|
||||||
"Syntax error",
|
|
||||||
"Parentheses do not match",
|
|
||||||
"This is not the expression",
|
|
||||||
"Assumed the equality symbol",
|
|
||||||
"Do not a variable"
|
|
||||||
};
|
|
||||||
errorMsg->clear();
|
|
||||||
*errorMsg = e[error];
|
|
||||||
qDebug()<<e[error];
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief look_up finding the internal format for the current token in the token table.
|
|
||||||
* @param s name of token.
|
|
||||||
* @return internal number of token.
|
|
||||||
*/
|
|
||||||
char Calculator::look_up(QString s)
|
|
||||||
{
|
|
||||||
QString p;
|
|
||||||
|
|
||||||
p = s;
|
|
||||||
p = p.toLower();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief isdelim return true if c delimiter.
|
|
||||||
* @param c character.
|
|
||||||
* @return true - delimiter, false - do not delimiter.
|
|
||||||
*/
|
|
||||||
bool Calculator::isdelim(QChar c)
|
|
||||||
{
|
|
||||||
if (StrChr(" ;,+-<>/*%^=()", c) || c=='\n' || c=='\r' || c=='\0')
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief iswhite checks whether c space or tab.
|
|
||||||
* @param c character.
|
|
||||||
* @return true - space or tab, false - don't space and don't tab.
|
|
||||||
*/
|
|
||||||
bool Calculator::iswhite(QChar c)
|
|
||||||
{
|
|
||||||
if (c==' ' || c=='\t')
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief get_token return next token.
|
|
||||||
*/
|
|
||||||
void Calculator::get_token()
|
|
||||||
{
|
|
||||||
QString *temp;
|
|
||||||
|
|
||||||
token_type=0; tok=0;
|
|
||||||
token.clear();
|
|
||||||
temp=&token;
|
|
||||||
|
|
||||||
if (prog[index]=='\0')
|
|
||||||
{ /* end of file */
|
|
||||||
token="\0";
|
|
||||||
tok=FINISHED;
|
|
||||||
token_type=DELIMITER;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (iswhite(prog[index]))
|
|
||||||
{
|
|
||||||
++index; /* skip spaces */
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prog[index]=='\r')
|
|
||||||
{ /* crtl */
|
|
||||||
++index; ++index;
|
|
||||||
tok= EOL; token='\r';
|
|
||||||
token.append('\n');token.append("\0");
|
|
||||||
token_type = DELIMITER;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StrChr("+-*^/%=;(),><", prog[index]))
|
|
||||||
{ /* delimiter */
|
|
||||||
*temp=prog[index];
|
|
||||||
index++; /* jump to the next position */
|
|
||||||
temp->append("\0");
|
|
||||||
token_type=DELIMITER;
|
|
||||||
debugFormula.append(token);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (prog[index]=='"')
|
|
||||||
{ /* quoted string */
|
|
||||||
index++;
|
|
||||||
while (prog[index] != '"' && prog[index] != '\r')
|
|
||||||
{
|
|
||||||
temp->append(prog[index]);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (prog[index]=='\r')
|
|
||||||
{
|
|
||||||
serror(1);
|
|
||||||
}
|
|
||||||
index++;temp->append("\0");
|
|
||||||
token_type=QUOTE;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (prog[index].isDigit())
|
|
||||||
{ /* number */
|
|
||||||
while (isdelim(prog[index]) == false)
|
|
||||||
{
|
|
||||||
temp->append(prog[index]);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
temp->append('\0');
|
|
||||||
token_type = NUMBER;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prog[index].isPrint())
|
|
||||||
{ /* variable or command */
|
|
||||||
while (isdelim(prog[index]) == false)
|
|
||||||
{
|
|
||||||
temp->append(prog[index]);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
token_type=STRING;
|
|
||||||
}
|
|
||||||
temp->append("\0");
|
|
||||||
|
|
||||||
/* Seen if there is a command line or a variable */
|
|
||||||
if (token_type==STRING)
|
|
||||||
{
|
|
||||||
tok=look_up(token);
|
|
||||||
if (tok == false)
|
|
||||||
{
|
|
||||||
token_type = VARIABLE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
token_type = COMMAND; /* It is command */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief StrChr checks whether the character belongs to the line.
|
|
||||||
* @param string string with formula
|
|
||||||
* @param c character.
|
|
||||||
* @return true - belongs to the line, false - don't belongs to the line.
|
|
||||||
*/
|
|
||||||
bool Calculator::StrChr(QString string, QChar c)
|
|
||||||
{
|
|
||||||
return string.contains(c, Qt::CaseInsensitive);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* @brief putback returns the readout token back into the flow.
|
|
||||||
*/
|
|
||||||
void Calculator::putback()
|
|
||||||
{
|
|
||||||
QString t;
|
|
||||||
t = token;
|
|
||||||
index = index - t.size();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,67 +31,20 @@
|
||||||
|
|
||||||
#include "vcontainer.h"
|
#include "vcontainer.h"
|
||||||
|
|
||||||
/**
|
#include "../../libs/qmuparser/qmuparser.h"
|
||||||
* @brief The Calculator class calculate formulas of pattern. Support operation +,-,/,* and braces.
|
using namespace qmu;
|
||||||
* Can replace name of variables her value.
|
|
||||||
*/
|
class Calculator:public QmuParser
|
||||||
class Calculator
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Calculator(const VContainer *data);
|
explicit Calculator(const VContainer *data);
|
||||||
qreal eval(QString prog, QString *errorMsg);
|
qreal EvalFormula(const QString &formula);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Calculator)
|
Q_DISABLE_COPY(Calculator)
|
||||||
/**
|
void InitVariables(const VContainer *data);
|
||||||
* @brief errorMsg keeps error message of calculation.
|
static qreal CmUnit(qreal val);
|
||||||
*/
|
static qreal MmUnit(qreal val);
|
||||||
QString *errorMsg;
|
static qreal InchUnit(qreal val);
|
||||||
/**
|
|
||||||
* @brief token теперішня лексема.
|
|
||||||
*/
|
|
||||||
QString token;
|
|
||||||
/**
|
|
||||||
* @brief tok internal representation of token.
|
|
||||||
*/
|
|
||||||
qint32 tok;
|
|
||||||
/**
|
|
||||||
* @brief token_type type of token.
|
|
||||||
*/
|
|
||||||
qint32 token_type;
|
|
||||||
/**
|
|
||||||
* @brief prog string where keeps formula.
|
|
||||||
*/
|
|
||||||
QString prog;
|
|
||||||
/**
|
|
||||||
* @brief index number character in string of formula.
|
|
||||||
*/
|
|
||||||
qint32 index;
|
|
||||||
/**
|
|
||||||
* @brief data container with data container of all variables.
|
|
||||||
*/
|
|
||||||
const VContainer *data;
|
|
||||||
/**
|
|
||||||
* @brief debugFormula decoded string of formula.
|
|
||||||
*/
|
|
||||||
QString debugFormula;
|
|
||||||
qreal get_exp();
|
|
||||||
void get_token();
|
|
||||||
static bool StrChr(QString string, QChar c);
|
|
||||||
void putback();
|
|
||||||
void level2(qreal *result);
|
|
||||||
void level3(qreal *result);
|
|
||||||
void level4(qreal *result);
|
|
||||||
void level5(qreal *result);
|
|
||||||
void level6(qreal *result);
|
|
||||||
void primitive(qreal *result);
|
|
||||||
static void arith(QChar o, qreal *r, qreal *h);
|
|
||||||
static void unary(QChar o, qreal *r);
|
|
||||||
qreal find_var(QString s);
|
|
||||||
// cppcheck-suppress functionStatic
|
|
||||||
void serror(qint32 error);
|
|
||||||
static char look_up(QString s);
|
|
||||||
static bool isdelim(QChar c);
|
|
||||||
static bool iswhite(QChar c);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CALCULATOR_H
|
#endif // CALCULATOR_H
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
quint32 VContainer::_id = 0;
|
quint32 VContainer::_id = 0;
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief VContainer create empty container
|
||||||
|
*/
|
||||||
VContainer::VContainer()
|
VContainer::VContainer()
|
||||||
:_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash<quint32, VGObject *>()),
|
:_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash<quint32, VGObject *>()),
|
||||||
measurements(QHash<QString, VMeasurement>()), increments(QHash<QString, VIncrement>()),
|
measurements(QHash<QString, VMeasurement>()), increments(QHash<QString, VIncrement>()),
|
||||||
|
@ -43,6 +46,11 @@ VContainer::VContainer()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief operator = copy constructor
|
||||||
|
* @param data container
|
||||||
|
* @return copy container
|
||||||
|
*/
|
||||||
VContainer &VContainer::operator =(const VContainer &data)
|
VContainer &VContainer::operator =(const VContainer &data)
|
||||||
{
|
{
|
||||||
setData(data);
|
setData(data);
|
||||||
|
@ -50,6 +58,10 @@ VContainer &VContainer::operator =(const VContainer &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief VContainer create container from another container
|
||||||
|
* @param data container
|
||||||
|
*/
|
||||||
VContainer::VContainer(const VContainer &data)
|
VContainer::VContainer(const VContainer &data)
|
||||||
:_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash<quint32, VGObject *>()),
|
:_size(50), sizeName(size_M), _height(176), heightName(height_M), gObjects(QHash<quint32, VGObject *>()),
|
||||||
measurements(QHash<QString, VMeasurement>()), increments(QHash<QString, VIncrement>()),
|
measurements(QHash<QString, VMeasurement>()), increments(QHash<QString, VIncrement>()),
|
||||||
|
@ -67,6 +79,10 @@ VContainer::~VContainer()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief setData copy data from container
|
||||||
|
* @param data container
|
||||||
|
*/
|
||||||
void VContainer::setData(const VContainer &data)
|
void VContainer::setData(const VContainer &data)
|
||||||
{
|
{
|
||||||
_size = data.size();
|
_size = data.size();
|
||||||
|
@ -111,6 +127,11 @@ void VContainer::setData(const VContainer &data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetGObject returns a point by id
|
||||||
|
* @param id id of point
|
||||||
|
* @return point
|
||||||
|
*/
|
||||||
// cppcheck-suppress unusedFunction
|
// cppcheck-suppress unusedFunction
|
||||||
const VGObject *VContainer::GetGObject(quint32 id)const
|
const VGObject *VContainer::GetGObject(quint32 id)const
|
||||||
{
|
{
|
||||||
|
@ -118,6 +139,12 @@ const VGObject *VContainer::GetGObject(quint32 id)const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetObject return object from container
|
||||||
|
* @param obj container
|
||||||
|
* @param id id of object
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
|
const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
|
||||||
{
|
{
|
||||||
|
@ -132,6 +159,12 @@ const val VContainer::GetObject(const QHash<key, val> &obj, key id) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetObject return object from container
|
||||||
|
* @param obj container
|
||||||
|
* @param id id of object
|
||||||
|
* @return Object
|
||||||
|
*/
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
val VContainer::GetVariable(const QHash<key, val> &obj, key id) const
|
val VContainer::GetVariable(const QHash<key, val> &obj, key id) const
|
||||||
{
|
{
|
||||||
|
@ -146,6 +179,11 @@ val VContainer::GetVariable(const QHash<key, val> &obj, key id) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetMeasurement return measurement by name
|
||||||
|
* @param name short measurement name
|
||||||
|
* @return measurement
|
||||||
|
*/
|
||||||
const VMeasurement VContainer::GetMeasurement(const QString &name) const
|
const VMeasurement VContainer::GetMeasurement(const QString &name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -153,6 +191,11 @@ const VMeasurement VContainer::GetMeasurement(const QString &name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetIncrement return increment table row by name
|
||||||
|
* @param name name of increment table row
|
||||||
|
* @return increment
|
||||||
|
*/
|
||||||
const VIncrement VContainer::GetIncrement(const QString& name) const
|
const VIncrement VContainer::GetIncrement(const QString& name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -160,6 +203,11 @@ const VIncrement VContainer::GetIncrement(const QString& name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetLine return length of line by name
|
||||||
|
* @param name name of line
|
||||||
|
* @return length of line in mm
|
||||||
|
*/
|
||||||
qreal VContainer::GetLine(const QString &name) const
|
qreal VContainer::GetLine(const QString &name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -167,6 +215,11 @@ qreal VContainer::GetLine(const QString &name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetLengthArc return length of arc by name
|
||||||
|
* @param name name of arc
|
||||||
|
* @return length of arc in mm
|
||||||
|
*/
|
||||||
qreal VContainer::GetLengthArc(const QString &name) const
|
qreal VContainer::GetLengthArc(const QString &name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -174,6 +227,11 @@ qreal VContainer::GetLengthArc(const QString &name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetLengthSpline return length of spline by name
|
||||||
|
* @param name name of spline
|
||||||
|
* @return length of spline in mm
|
||||||
|
*/
|
||||||
qreal VContainer::GetLengthSpline(const QString &name) const
|
qreal VContainer::GetLengthSpline(const QString &name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -181,6 +239,11 @@ qreal VContainer::GetLengthSpline(const QString &name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetLineAngle return angle of line
|
||||||
|
* @param name name of line angle
|
||||||
|
* @return angle in degree
|
||||||
|
*/
|
||||||
qreal VContainer::GetLineAngle(const QString &name) const
|
qreal VContainer::GetLineAngle(const QString &name) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty()==false);
|
Q_ASSERT(name.isEmpty()==false);
|
||||||
|
@ -188,18 +251,33 @@ qreal VContainer::GetLineAngle(const QString &name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetDetail return detail by id
|
||||||
|
* @param id id of detail
|
||||||
|
* @return detail
|
||||||
|
*/
|
||||||
const VDetail VContainer::GetDetail(quint32 id) const
|
const VDetail VContainer::GetDetail(quint32 id) const
|
||||||
{
|
{
|
||||||
return GetVariable(details, id);
|
return GetVariable(details, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddPoint add new point to container
|
||||||
|
* @param point new point
|
||||||
|
* @return return id of new point in container
|
||||||
|
*/
|
||||||
quint32 VContainer::AddGObject(VGObject *obj)
|
quint32 VContainer::AddGObject(VGObject *obj)
|
||||||
{
|
{
|
||||||
return AddObject(gObjects, obj);
|
return AddObject(gObjects, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddDetail add new detail to container
|
||||||
|
* @param detail new detail
|
||||||
|
* @return return id of new detail in container
|
||||||
|
*/
|
||||||
quint32 VContainer::AddDetail(VDetail detail)
|
quint32 VContainer::AddDetail(VDetail detail)
|
||||||
{
|
{
|
||||||
quint32 id = getNextId();
|
quint32 id = getNextId();
|
||||||
|
@ -208,12 +286,21 @@ quint32 VContainer::AddDetail(VDetail detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddIncrement add new row of increment table
|
||||||
|
* @param name name of new row of increment table
|
||||||
|
* @param row new row of increment table
|
||||||
|
*/
|
||||||
void VContainer::AddIncrement(const QString &name, VIncrement incr)
|
void VContainer::AddIncrement(const QString &name, VIncrement incr)
|
||||||
{
|
{
|
||||||
increments[name] = incr;
|
increments[name] = incr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief getNextId generate next unique id
|
||||||
|
* @return next unique id
|
||||||
|
*/
|
||||||
quint32 VContainer::getNextId()
|
quint32 VContainer::getNextId()
|
||||||
{
|
{
|
||||||
_id++;
|
_id++;
|
||||||
|
@ -221,6 +308,10 @@ quint32 VContainer::getNextId()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdateId update id. If new id bigger when current save new like current.
|
||||||
|
* @param newId id
|
||||||
|
*/
|
||||||
void VContainer::UpdateId(quint32 newId)
|
void VContainer::UpdateId(quint32 newId)
|
||||||
{
|
{
|
||||||
if (newId > _id)
|
if (newId > _id)
|
||||||
|
@ -230,6 +321,12 @@ void VContainer::UpdateId(quint32 newId)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdateObject update object in container
|
||||||
|
* @param obj container
|
||||||
|
* @param id id of existing object
|
||||||
|
* @param point object
|
||||||
|
*/
|
||||||
template <typename val>
|
template <typename val>
|
||||||
void VContainer::UpdateObject(QHash<quint32, val> &obj, const quint32 &id, val point)
|
void VContainer::UpdateObject(QHash<quint32, val> &obj, const quint32 &id, val point)
|
||||||
{
|
{
|
||||||
|
@ -246,6 +343,11 @@ void VContainer::UpdateObject(QHash<quint32, val> &obj, const quint32 &id, val p
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddLengthSpline add length of spline to container
|
||||||
|
* @param name name of spline
|
||||||
|
* @param value length of spline
|
||||||
|
*/
|
||||||
void VContainer::AddLengthSpline(const QString &name, const qreal &value)
|
void VContainer::AddLengthSpline(const QString &name, const qreal &value)
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty() == false);
|
Q_ASSERT(name.isEmpty() == false);
|
||||||
|
@ -253,6 +355,10 @@ void VContainer::AddLengthSpline(const QString &name, const qreal &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddLengthArc add length of arc to container
|
||||||
|
* @param id id of arc
|
||||||
|
*/
|
||||||
void VContainer::AddLengthArc(const quint32 &id)
|
void VContainer::AddLengthArc(const quint32 &id)
|
||||||
{
|
{
|
||||||
const VArc * arc = GeometricObject<const VArc *>(id);
|
const VArc * arc = GeometricObject<const VArc *>(id);
|
||||||
|
@ -260,6 +366,11 @@ void VContainer::AddLengthArc(const quint32 &id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddLineAngle add angle of line to container
|
||||||
|
* @param name name of line angle
|
||||||
|
* @param value angle in degree
|
||||||
|
*/
|
||||||
void VContainer::AddLineAngle(const QString &name, const qreal &value)
|
void VContainer::AddLineAngle(const QString &name, const qreal &value)
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty() == false);
|
Q_ASSERT(name.isEmpty() == false);
|
||||||
|
@ -267,6 +378,11 @@ void VContainer::AddLineAngle(const QString &name, const qreal &value)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetValueStandardTableRow return value of measurement by name
|
||||||
|
* @param name name of measurement
|
||||||
|
* @return value in measurement units
|
||||||
|
*/
|
||||||
qreal VContainer::GetValueStandardTableRow(const QString& name) const
|
qreal VContainer::GetValueStandardTableRow(const QString& name) const
|
||||||
{
|
{
|
||||||
const VMeasurement m = GetMeasurement(name);
|
const VMeasurement m = GetMeasurement(name);
|
||||||
|
@ -281,6 +397,11 @@ qreal VContainer::GetValueStandardTableRow(const QString& name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetValueIncrementTableRow return value of increment table row by name
|
||||||
|
* @param name name of row
|
||||||
|
* @return value of row in mm
|
||||||
|
*/
|
||||||
qreal VContainer::GetValueIncrementTableRow(const QString& name) const
|
qreal VContainer::GetValueIncrementTableRow(const QString& name) const
|
||||||
{
|
{
|
||||||
const VIncrement icr = GetIncrement(name);
|
const VIncrement icr = GetIncrement(name);
|
||||||
|
@ -295,6 +416,9 @@ qreal VContainer::GetValueIncrementTableRow(const QString& name) const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief Clear clear data in container. Id will be 0.
|
||||||
|
*/
|
||||||
void VContainer::Clear()
|
void VContainer::Clear()
|
||||||
{
|
{
|
||||||
_id = 0;
|
_id = 0;
|
||||||
|
@ -309,6 +433,9 @@ void VContainer::Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
|
||||||
|
*/
|
||||||
void VContainer::ClearGObjects()
|
void VContainer::ClearGObjects()
|
||||||
{
|
{
|
||||||
if (gObjects.size()>0)
|
if (gObjects.size()>0)
|
||||||
|
@ -337,6 +464,12 @@ void VContainer::ClearCalculationGObjects()
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief FindVar return value of variable by name
|
||||||
|
* @param name name of variable
|
||||||
|
* @param ok false if can't find variable
|
||||||
|
* @return value of variable
|
||||||
|
*/
|
||||||
qreal VContainer::FindVar(const QString &name, bool *ok)const
|
qreal VContainer::FindVar(const QString &name, bool *ok)const
|
||||||
{
|
{
|
||||||
if (sizeName == name)
|
if (sizeName == name)
|
||||||
|
@ -384,6 +517,12 @@ qreal VContainer::FindVar(const QString &name, bool *ok)const
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddLine add line to container
|
||||||
|
* @param firstPointId id of first point of line
|
||||||
|
* @param secondPointId id of second point of line
|
||||||
|
* @param mode mode of line
|
||||||
|
*/
|
||||||
void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId)
|
void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPointId)
|
||||||
{
|
{
|
||||||
QString nameLine = GetNameLine(firstPointId, secondPointId);
|
QString nameLine = GetNameLine(firstPointId, secondPointId);
|
||||||
|
@ -395,6 +534,12 @@ void VContainer::AddLine(const quint32 &firstPointId, const quint32 &secondPoint
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddObject add object to container
|
||||||
|
* @param obj container
|
||||||
|
* @param value object
|
||||||
|
* @return id of object in container
|
||||||
|
*/
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
||||||
{
|
{
|
||||||
|
@ -406,6 +551,12 @@ quint32 VContainer::AddObject(QHash<key, val> &obj, val value)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetNameLine return name of line
|
||||||
|
* @param firstPoint id of first point of line
|
||||||
|
* @param secondPoint id of second point of line
|
||||||
|
* @return name of line
|
||||||
|
*/
|
||||||
QString VContainer::GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const
|
QString VContainer::GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const
|
||||||
{
|
{
|
||||||
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
|
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
|
||||||
|
@ -415,6 +566,12 @@ QString VContainer::GetNameLine(const quint32 &firstPoint, const quint32 &second
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetNameLineAngle return name of line angle
|
||||||
|
* @param firstPoint id of first point of line
|
||||||
|
* @param secondPoint id of second point of line
|
||||||
|
* @return name of angle of line
|
||||||
|
*/
|
||||||
QString VContainer::GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const
|
QString VContainer::GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const
|
||||||
{
|
{
|
||||||
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
|
const VPointF *first = GeometricObject<const VPointF *>(firstPoint);
|
||||||
|
@ -424,12 +581,22 @@ QString VContainer::GetNameLineAngle(const quint32 &firstPoint, const quint32 &s
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdatePoint update point by id
|
||||||
|
* @param id id of existing point
|
||||||
|
* @param point point
|
||||||
|
*/
|
||||||
void VContainer::UpdateGObject(quint32 id, VGObject* obj)
|
void VContainer::UpdateGObject(quint32 id, VGObject* obj)
|
||||||
{
|
{
|
||||||
UpdateObject(gObjects, id, obj);
|
UpdateObject(gObjects, id, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdateDetail update detail by id
|
||||||
|
* @param id id of existing detail
|
||||||
|
* @param detail detail
|
||||||
|
*/
|
||||||
void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
|
void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
|
||||||
|
@ -438,6 +605,11 @@ void VContainer::UpdateDetail(quint32 id, const VDetail &detail)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddLengthLine add length of line to container
|
||||||
|
* @param name name of line
|
||||||
|
* @param value length of line
|
||||||
|
*/
|
||||||
void VContainer::AddLengthLine(const QString &name, const qreal &value)
|
void VContainer::AddLengthLine(const QString &name, const qreal &value)
|
||||||
{
|
{
|
||||||
Q_ASSERT(name.isEmpty() == false);
|
Q_ASSERT(name.isEmpty() == false);
|
||||||
|
|
|
@ -45,20 +45,8 @@ class VContainer
|
||||||
{
|
{
|
||||||
Q_DECLARE_TR_FUNCTIONS(VContainer)
|
Q_DECLARE_TR_FUNCTIONS(VContainer)
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief VContainer create empty container
|
|
||||||
*/
|
|
||||||
VContainer();
|
VContainer();
|
||||||
/**
|
|
||||||
* @brief operator = copy constructor
|
|
||||||
* @param data container
|
|
||||||
* @return copy container
|
|
||||||
*/
|
|
||||||
VContainer &operator=(const VContainer &data);
|
VContainer &operator=(const VContainer &data);
|
||||||
/**
|
|
||||||
* @brief VContainer create container from another container
|
|
||||||
* @param data container
|
|
||||||
*/
|
|
||||||
VContainer(const VContainer &data);
|
VContainer(const VContainer &data);
|
||||||
~VContainer();
|
~VContainer();
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -67,11 +55,7 @@ public:
|
||||||
T *obj = new T(*data.GeometricObject<const T *>(id));
|
T *obj = new T(*data.GeometricObject<const T *>(id));
|
||||||
UpdateGObject(id, obj);
|
UpdateGObject(id, obj);
|
||||||
}
|
}
|
||||||
/**
|
void setData(const VContainer &data);
|
||||||
* @brief setData copy data from container
|
|
||||||
* @param data container
|
|
||||||
*/
|
|
||||||
void setData(const VContainer &data);
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T GeometricObject(const quint32 &id) const
|
const T GeometricObject(const quint32 &id) const
|
||||||
{
|
{
|
||||||
|
@ -100,288 +84,65 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
const VGObject *GetGObject(quint32 id) const;
|
||||||
* @brief GetGObject returns a point by id
|
const VMeasurement GetMeasurement(const QString& name) const;
|
||||||
* @param id id of point
|
const VIncrement GetIncrement(const QString& name) const;
|
||||||
* @return point
|
qreal GetLine(const QString &name) const;
|
||||||
*/
|
qreal GetLengthArc(const QString &name) const;
|
||||||
const VGObject *GetGObject(quint32 id) const;
|
qreal GetLengthSpline(const QString &name) const;
|
||||||
/**
|
qreal GetLineAngle(const QString &name) const;
|
||||||
* @brief GetMeasurement return measurement by name
|
const VDetail GetDetail(quint32 id) const;
|
||||||
* @param name short measurement name
|
static quint32 getId(){return _id;}
|
||||||
* @return measurement
|
quint32 AddGObject(VGObject *obj);
|
||||||
*/
|
quint32 AddDetail(VDetail detail);
|
||||||
const VMeasurement GetMeasurement(const QString& name) const;
|
void AddMeasurement(const QString& name, const VMeasurement &m);
|
||||||
/**
|
void AddIncrement(const QString& name, VIncrement incr);
|
||||||
* @brief GetIncrement return increment table row by name
|
void AddLengthLine(const QString &name, const qreal &value);
|
||||||
* @param name name of increment table row
|
void AddLengthSpline(const QString &name, const qreal &value);
|
||||||
* @return increment
|
void AddLengthArc(const quint32 &id);
|
||||||
*/
|
void AddLineAngle(const QString &name, const qreal &value);
|
||||||
const VIncrement GetIncrement(const QString& name) const;
|
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
|
||||||
/**
|
|
||||||
* @brief GetLine return length of line by name
|
|
||||||
* @param name name of line
|
|
||||||
* @return length of line in mm
|
|
||||||
*/
|
|
||||||
qreal GetLine(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief GetLengthArc return length of arc by name
|
|
||||||
* @param name name of arc
|
|
||||||
* @return length of arc in mm
|
|
||||||
*/
|
|
||||||
qreal GetLengthArc(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief GetLengthSpline return length of spline by name
|
|
||||||
* @param name name of spline
|
|
||||||
* @return length of spline in mm
|
|
||||||
*/
|
|
||||||
qreal GetLengthSpline(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief GetLineAngle return angle of line
|
|
||||||
* @param name name of line angle
|
|
||||||
* @return angle in degree
|
|
||||||
*/
|
|
||||||
qreal GetLineAngle(const QString &name) const;
|
|
||||||
/**
|
|
||||||
* @brief GetDetail return detail by id
|
|
||||||
* @param id id of detail
|
|
||||||
* @return detail
|
|
||||||
*/
|
|
||||||
const VDetail GetDetail(quint32 id) const;
|
|
||||||
/**
|
|
||||||
* @brief getId return current id
|
|
||||||
* @return current id
|
|
||||||
*/
|
|
||||||
static quint32 getId() {return _id;}
|
|
||||||
/**
|
|
||||||
* @brief AddPoint add new point to container
|
|
||||||
* @param point new point
|
|
||||||
* @return return id of new point in container
|
|
||||||
*/
|
|
||||||
quint32 AddGObject(VGObject *obj);
|
|
||||||
/**
|
|
||||||
* @brief AddDetail add new detail to container
|
|
||||||
* @param detail new detail
|
|
||||||
* @return return id of new detail in container
|
|
||||||
*/
|
|
||||||
quint32 AddDetail(VDetail detail);
|
|
||||||
/**
|
|
||||||
* @brief AddMeasurement add new measurement
|
|
||||||
* @param name short measurement name
|
|
||||||
* @param row measurement
|
|
||||||
*/
|
|
||||||
void AddMeasurement(const QString& name, const VMeasurement &m);
|
|
||||||
/**
|
|
||||||
* @brief AddIncrement add new row of increment table
|
|
||||||
* @param name name of new row of increment table
|
|
||||||
* @param row new row of increment table
|
|
||||||
*/
|
|
||||||
void AddIncrement(const QString& name, VIncrement incr);
|
|
||||||
/**
|
|
||||||
* @brief AddLengthLine add length of line to container
|
|
||||||
* @param name name of line
|
|
||||||
* @param value length of line
|
|
||||||
*/
|
|
||||||
void AddLengthLine(const QString &name, const qreal &value);
|
|
||||||
/**
|
|
||||||
* @brief AddLengthSpline add length of spline to container
|
|
||||||
* @param name name of spline
|
|
||||||
* @param value length of spline
|
|
||||||
*/
|
|
||||||
void AddLengthSpline(const QString &name, const qreal &value);
|
|
||||||
/**
|
|
||||||
* @brief AddLengthArc add length of arc to container
|
|
||||||
* @param id id of arc
|
|
||||||
*/
|
|
||||||
void AddLengthArc(const quint32 &id);
|
|
||||||
/**
|
|
||||||
* @brief AddLineAngle add angle of line to container
|
|
||||||
* @param name name of line angle
|
|
||||||
* @param value angle in degree
|
|
||||||
*/
|
|
||||||
void AddLineAngle(const QString &name, const qreal &value);
|
|
||||||
/**
|
|
||||||
* @brief AddLine add line to container
|
|
||||||
* @param firstPointId id of first point of line
|
|
||||||
* @param secondPointId id of second point of line
|
|
||||||
* @param mode mode of line
|
|
||||||
*/
|
|
||||||
void AddLine(const quint32 &firstPointId, const quint32 &secondPointId);
|
|
||||||
/**
|
|
||||||
* @brief GetNameLine return name of line
|
|
||||||
* @param firstPoint id of first point of line
|
|
||||||
* @param secondPoint id of second point of line
|
|
||||||
* @return name of line
|
|
||||||
*/
|
|
||||||
// cppcheck-suppress functionStatic
|
// cppcheck-suppress functionStatic
|
||||||
QString GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const;
|
QString GetNameLine(const quint32 &firstPoint, const quint32 &secondPoint) const;
|
||||||
/**
|
|
||||||
* @brief GetNameLineAngle return name of line angle
|
|
||||||
* @param firstPoint id of first point of line
|
|
||||||
* @param secondPoint id of second point of line
|
|
||||||
* @return name of angle of line
|
|
||||||
*/
|
|
||||||
// cppcheck-suppress functionStatic
|
// cppcheck-suppress functionStatic
|
||||||
QString GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const;
|
QString GetNameLineAngle(const quint32 &firstPoint, const quint32 &secondPoint) const;
|
||||||
/**
|
void UpdateGObject(quint32 id, VGObject* obj);
|
||||||
* @brief UpdatePoint update point by id
|
void UpdateDetail(quint32 id, const VDetail &detail);
|
||||||
* @param id id of existing point
|
void UpdateMeasurement(const QString& name, VMeasurement m);
|
||||||
* @param point point
|
void UpdateIncrement(const QString& name, VIncrement incr);
|
||||||
*/
|
qreal GetValueStandardTableRow(const QString& name) const;
|
||||||
void UpdateGObject(quint32 id, VGObject* obj);
|
qreal GetValueIncrementTableRow(const QString& name) const;
|
||||||
/**
|
void Clear();
|
||||||
* @brief UpdateDetail update detail by id
|
void ClearGObjects();
|
||||||
* @param id id of existing detail
|
void ClearCalculationGObjects();
|
||||||
* @param detail detail
|
void ClearIncrementTable();
|
||||||
*/
|
void ClearMeasurements();
|
||||||
void UpdateDetail(quint32 id, const VDetail &detail);
|
void ClearLengthLines();
|
||||||
/**
|
void ClearLengthSplines();
|
||||||
* @brief UpdateMeasurement update measurement by name
|
void ClearLengthArcs();
|
||||||
* @param name short measurement name
|
void ClearLineAngles();
|
||||||
* @param m measurement
|
void ClearDetails();
|
||||||
*/
|
void SetSize(qreal size);
|
||||||
void UpdateMeasurement(const QString& name, VMeasurement m);
|
void SetSizeName(const QString &name);
|
||||||
/**
|
void SetHeight(qreal height);
|
||||||
* @brief UpdateIncrement update increment table row by name
|
void SetHeightName(const QString &name);
|
||||||
* @param name name of row
|
qreal size() const;
|
||||||
* @param row row
|
QString SizeName()const;
|
||||||
*/
|
qreal height() const;
|
||||||
void UpdateIncrement(const QString& name, VIncrement incr);
|
QString HeightName()const;
|
||||||
/**
|
qreal FindVar(const QString& name, bool *ok)const;
|
||||||
* @brief GetValueStandardTableRow return value of measurement by name
|
bool IncrementTableContains(const QString& name);
|
||||||
* @param name name of measurement
|
static quint32 getNextId();
|
||||||
* @return value in measurement units
|
void RemoveIncrementTableRow(const QString& name);
|
||||||
*/
|
static void UpdateId(quint32 newId);
|
||||||
qreal GetValueStandardTableRow(const QString& name) const;
|
const QHash<quint32, VGObject*> *DataGObjects() const;
|
||||||
/**
|
|
||||||
* @brief GetValueIncrementTableRow return value of increment table row by name
|
|
||||||
* @param name name of row
|
|
||||||
* @return value of row in mm
|
|
||||||
*/
|
|
||||||
qreal GetValueIncrementTableRow(const QString& name) const;
|
|
||||||
/**
|
|
||||||
* @brief Clear clear data in container. Id will be 0.
|
|
||||||
*/
|
|
||||||
void Clear();
|
|
||||||
/**
|
|
||||||
* @brief ClearObject points, splines, arcs, spline paths will be cleared.
|
|
||||||
*/
|
|
||||||
void ClearGObjects();
|
|
||||||
void ClearCalculationGObjects();
|
|
||||||
/**
|
|
||||||
* @brief ClearIncrementTable clear increment table
|
|
||||||
*/
|
|
||||||
void ClearIncrementTable();
|
|
||||||
void ClearMeasurements();
|
|
||||||
/**
|
|
||||||
* @brief ClearLengthLines clear length lines
|
|
||||||
*/
|
|
||||||
void ClearLengthLines();
|
|
||||||
/**
|
|
||||||
* @brief ClearLengthSplines clear length splines
|
|
||||||
*/
|
|
||||||
void ClearLengthSplines();
|
|
||||||
/**
|
|
||||||
* @brief ClearLengthArcs clear length arcs
|
|
||||||
*/
|
|
||||||
void ClearLengthArcs();
|
|
||||||
/**
|
|
||||||
* @brief ClearLineAngles clear angles of lines
|
|
||||||
*/
|
|
||||||
void ClearLineAngles();
|
|
||||||
void ClearDetails();
|
|
||||||
/**
|
|
||||||
* @brief SetSize set value of size
|
|
||||||
* @param size value of size
|
|
||||||
*/
|
|
||||||
void SetSize(qreal size);
|
|
||||||
void SetSizeName(const QString &name);
|
|
||||||
/**
|
|
||||||
* @brief SetGrowth set value of growth
|
|
||||||
* @param growth value of growth
|
|
||||||
*/
|
|
||||||
void SetHeight(qreal height);
|
|
||||||
void SetHeightName(const QString &name);
|
|
||||||
/**
|
|
||||||
* @brief size return size
|
|
||||||
* @return size in mm
|
|
||||||
*/
|
|
||||||
qreal size() const;
|
|
||||||
QString SizeName()const;
|
|
||||||
/**
|
|
||||||
* @brief height return height
|
|
||||||
* @return height in pattern units
|
|
||||||
*/
|
|
||||||
qreal height() const;
|
|
||||||
QString HeightName()const;
|
|
||||||
/**
|
|
||||||
* @brief FindVar return value of variable by name
|
|
||||||
* @param name name of variable
|
|
||||||
* @param ok false if can't find variable
|
|
||||||
* @return value of variable
|
|
||||||
*/
|
|
||||||
qreal FindVar(const QString& name, bool *ok)const;
|
|
||||||
/**
|
|
||||||
* @brief IncrementTableContains check if increment table contains name
|
|
||||||
* @param name name of row
|
|
||||||
* @return true if contains
|
|
||||||
*/
|
|
||||||
bool IncrementTableContains(const QString& name);
|
|
||||||
/**
|
|
||||||
* @brief getNextId generate next unique id
|
|
||||||
* @return next unique id
|
|
||||||
*/
|
|
||||||
static quint32 getNextId();
|
|
||||||
/**
|
|
||||||
* @brief RemoveIncrementTableRow remove row by name from increment table
|
|
||||||
* @param name name of existing row
|
|
||||||
*/
|
|
||||||
void RemoveIncrementTableRow(const QString& name);
|
|
||||||
/**
|
|
||||||
* @brief data container with datagObjects return container of gObjects
|
|
||||||
* @return pointer on container of gObjects
|
|
||||||
*/
|
|
||||||
const QHash<quint32, VGObject*> *DataGObjects() const;
|
|
||||||
/**
|
|
||||||
* @brief DataMeasurements container with measurements.
|
|
||||||
* @return pointer to measurements.
|
|
||||||
*/
|
|
||||||
const QHash<QString, VMeasurement> *DataMeasurements() const;
|
const QHash<QString, VMeasurement> *DataMeasurements() const;
|
||||||
/**
|
const QHash<QString, VIncrement> *DataIncrements() const;
|
||||||
* @brief data container with dataIncrements return container of increment table
|
const QHash<QString, qreal> *DataLengthLines() const;
|
||||||
* @return pointer on container of increment table
|
const QHash<QString, qreal> *DataLengthSplines() const;
|
||||||
*/
|
const QHash<QString, qreal> *DataLengthArcs() const;
|
||||||
const QHash<QString, VIncrement> *DataIncrements() const;
|
const QHash<QString, qreal> *DataLineAngles() const;
|
||||||
/**
|
const QHash<quint32, VDetail> *DataDetails() const;
|
||||||
* @brief data container with dataLengthLines return container of lines lengths
|
|
||||||
* @return pointer on container of lines lengths
|
|
||||||
*/
|
|
||||||
const QHash<QString, qreal> *DataLengthLines() const;
|
|
||||||
/**
|
|
||||||
* @brief data container with dataLengthSplines return container of splines lengths
|
|
||||||
* @return pointer on container of splines lengths
|
|
||||||
*/
|
|
||||||
const QHash<QString, qreal> *DataLengthSplines() const;
|
|
||||||
/**
|
|
||||||
* @brief data container with dataLengthArcs return container of arcs length
|
|
||||||
* @return pointer on container of arcs length
|
|
||||||
*/
|
|
||||||
const QHash<QString, qreal> *DataLengthArcs() const;
|
|
||||||
/**
|
|
||||||
* @brief data container with dataLineAngles return container of angles of line
|
|
||||||
* @return pointer on container of angles of line
|
|
||||||
*/
|
|
||||||
const QHash<QString, qreal> *DataLineAngles() const;
|
|
||||||
/**
|
|
||||||
* @brief data container with dataDetails return container of details
|
|
||||||
* @return pointer on container of details
|
|
||||||
*/
|
|
||||||
const QHash<quint32, VDetail> *DataDetails() const;
|
|
||||||
/**
|
|
||||||
* @brief UpdateId update id. If new id bigger when current save new like current.
|
|
||||||
* @param newId id
|
|
||||||
*/
|
|
||||||
static void UpdateId(quint32 newId);
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief _id current id. New object will have value +1. For empty class equal 0.
|
* @brief _id current id. New object will have value +1. For empty class equal 0.
|
||||||
|
@ -423,177 +184,272 @@ private:
|
||||||
* @brief details container of details
|
* @brief details container of details
|
||||||
*/
|
*/
|
||||||
QHash<quint32, VDetail> details;
|
QHash<quint32, VDetail> details;
|
||||||
|
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
/**
|
|
||||||
* @brief GetObject return object from container
|
|
||||||
* @param obj container
|
|
||||||
* @param id id of object
|
|
||||||
* @return Object
|
|
||||||
*/
|
|
||||||
// cppcheck-suppress functionStatic
|
// cppcheck-suppress functionStatic
|
||||||
const val GetObject(const QHash<key, val> &obj, key id) const;
|
const val GetObject(const QHash<key, val> &obj, key id) const;
|
||||||
|
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
/**
|
|
||||||
* @brief GetObject return object from container
|
|
||||||
* @param obj container
|
|
||||||
* @param id id of object
|
|
||||||
* @return Object
|
|
||||||
*/
|
|
||||||
// cppcheck-suppress functionStatic
|
// cppcheck-suppress functionStatic
|
||||||
val GetVariable(const QHash<key, val> &obj, key id) const;
|
val GetVariable(const QHash<key, val> &obj, key id) const;
|
||||||
|
|
||||||
template <typename val>
|
template <typename val>
|
||||||
/**
|
|
||||||
* @brief UpdateObject update object in container
|
|
||||||
* @param obj container
|
|
||||||
* @param id id of existing object
|
|
||||||
* @param point object
|
|
||||||
*/
|
|
||||||
void UpdateObject(QHash<quint32, val > &obj, const quint32 &id, val point);
|
void UpdateObject(QHash<quint32, val > &obj, const quint32 &id, val point);
|
||||||
|
|
||||||
template <typename key, typename val>
|
template <typename key, typename val>
|
||||||
/**
|
|
||||||
* @brief AddObject add object to container
|
|
||||||
* @param obj container
|
|
||||||
* @param value object
|
|
||||||
* @return id of object in container
|
|
||||||
*/
|
|
||||||
static quint32 AddObject(QHash<key, val> &obj, val value);
|
static quint32 AddObject(QHash<key, val> &obj, val value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief AddMeasurement add new measurement
|
||||||
|
* @param name short measurement name
|
||||||
|
* @param row measurement
|
||||||
|
*/
|
||||||
inline void VContainer::AddMeasurement(const QString &name, const VMeasurement &m)
|
inline void VContainer::AddMeasurement(const QString &name, const VMeasurement &m)
|
||||||
{
|
{
|
||||||
measurements[name] = m;
|
measurements[name] = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdateMeasurement update measurement by name
|
||||||
|
* @param name short measurement name
|
||||||
|
* @param m measurement
|
||||||
|
*/
|
||||||
inline void VContainer::UpdateMeasurement(const QString &name, VMeasurement m)
|
inline void VContainer::UpdateMeasurement(const QString &name, VMeasurement m)
|
||||||
{
|
{
|
||||||
measurements[name] = m;
|
measurements[name] = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief UpdateIncrement update increment table row by name
|
||||||
|
* @param name name of row
|
||||||
|
* @param row row
|
||||||
|
*/
|
||||||
inline void VContainer::UpdateIncrement(const QString &name, VIncrement incr)
|
inline void VContainer::UpdateIncrement(const QString &name, VIncrement incr)
|
||||||
{
|
{
|
||||||
increments[name] = incr;
|
increments[name] = incr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearIncrementTable clear increment table
|
||||||
|
*/
|
||||||
inline void VContainer::ClearIncrementTable()
|
inline void VContainer::ClearIncrementTable()
|
||||||
{
|
{
|
||||||
increments.clear();
|
increments.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void VContainer::ClearMeasurements()
|
inline void VContainer::ClearMeasurements()
|
||||||
{
|
{
|
||||||
measurements.clear();
|
measurements.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearLengthLines clear length lines
|
||||||
|
*/
|
||||||
inline void VContainer::ClearLengthLines()
|
inline void VContainer::ClearLengthLines()
|
||||||
{
|
{
|
||||||
lengthLines.clear();
|
lengthLines.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearLengthSplines clear length splines
|
||||||
|
*/
|
||||||
inline void VContainer::ClearLengthSplines()
|
inline void VContainer::ClearLengthSplines()
|
||||||
{
|
{
|
||||||
lengthSplines.clear();
|
lengthSplines.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearLengthArcs clear length arcs
|
||||||
|
*/
|
||||||
inline void VContainer::ClearLengthArcs()
|
inline void VContainer::ClearLengthArcs()
|
||||||
{
|
{
|
||||||
lengthArcs.clear();
|
lengthArcs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ClearLineAngles clear angles of lines
|
||||||
|
*/
|
||||||
inline void VContainer::ClearLineAngles()
|
inline void VContainer::ClearLineAngles()
|
||||||
{
|
{
|
||||||
lineAngles.clear();
|
lineAngles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void VContainer::ClearDetails()
|
inline void VContainer::ClearDetails()
|
||||||
{
|
{
|
||||||
details.clear();
|
details.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief SetSize set value of size
|
||||||
|
* @param size value of size
|
||||||
|
*/
|
||||||
inline void VContainer::SetSize(qreal size)
|
inline void VContainer::SetSize(qreal size)
|
||||||
{
|
{
|
||||||
_size = size;
|
_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void VContainer::SetSizeName(const QString &name)
|
inline void VContainer::SetSizeName(const QString &name)
|
||||||
{
|
{
|
||||||
sizeName = name;
|
sizeName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief SetGrowth set value of growth
|
||||||
|
* @param growth value of growth
|
||||||
|
*/
|
||||||
inline void VContainer::SetHeight(qreal height)
|
inline void VContainer::SetHeight(qreal height)
|
||||||
{
|
{
|
||||||
_height = height;
|
_height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline void VContainer::SetHeightName(const QString &name)
|
inline void VContainer::SetHeightName(const QString &name)
|
||||||
{
|
{
|
||||||
heightName = name;
|
heightName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief size return size
|
||||||
|
* @return size in mm
|
||||||
|
*/
|
||||||
inline qreal VContainer::size() const
|
inline qreal VContainer::size() const
|
||||||
{
|
{
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline QString VContainer::SizeName() const
|
inline QString VContainer::SizeName() const
|
||||||
{
|
{
|
||||||
return sizeName;
|
return sizeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief height return height
|
||||||
|
* @return height in pattern units
|
||||||
|
*/
|
||||||
inline qreal VContainer::height() const
|
inline qreal VContainer::height() const
|
||||||
{
|
{
|
||||||
return _height;
|
return _height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
inline QString VContainer::HeightName() const
|
inline QString VContainer::HeightName() const
|
||||||
{
|
{
|
||||||
return heightName;
|
return heightName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief IncrementTableContains check if increment table contains name
|
||||||
|
* @param name name of row
|
||||||
|
* @return true if contains
|
||||||
|
*/
|
||||||
inline bool VContainer::IncrementTableContains(const QString &name)
|
inline bool VContainer::IncrementTableContains(const QString &name)
|
||||||
{
|
{
|
||||||
return increments.contains(name);
|
return increments.contains(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief RemoveIncrementTableRow remove row by name from increment table
|
||||||
|
* @param name name of existing row
|
||||||
|
*/
|
||||||
inline void VContainer::RemoveIncrementTableRow(const QString &name)
|
inline void VContainer::RemoveIncrementTableRow(const QString &name)
|
||||||
{
|
{
|
||||||
increments.remove(name);
|
increments.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with datagObjects return container of gObjects
|
||||||
|
* @return pointer on container of gObjects
|
||||||
|
*/
|
||||||
inline const QHash<quint32, VGObject *> *VContainer::DataGObjects() const
|
inline const QHash<quint32, VGObject *> *VContainer::DataGObjects() const
|
||||||
{
|
{
|
||||||
return &gObjects;
|
return &gObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief DataMeasurements container with measurements.
|
||||||
|
* @return pointer to measurements.
|
||||||
|
*/
|
||||||
inline const QHash<QString, VMeasurement> *VContainer::DataMeasurements() const
|
inline const QHash<QString, VMeasurement> *VContainer::DataMeasurements() const
|
||||||
{
|
{
|
||||||
return &measurements;
|
return &measurements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataIncrements return container of increment table
|
||||||
|
* @return pointer on container of increment table
|
||||||
|
*/
|
||||||
inline const QHash<QString, VIncrement> *VContainer::DataIncrements() const
|
inline const QHash<QString, VIncrement> *VContainer::DataIncrements() const
|
||||||
{
|
{
|
||||||
return &increments;
|
return &increments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataLengthLines return container of lines lengths
|
||||||
|
* @return pointer on container of lines lengths
|
||||||
|
*/
|
||||||
inline const QHash<QString, qreal> *VContainer::DataLengthLines() const
|
inline const QHash<QString, qreal> *VContainer::DataLengthLines() const
|
||||||
{
|
{
|
||||||
return &lengthLines;
|
return &lengthLines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataLengthSplines return container of splines lengths
|
||||||
|
* @return pointer on container of splines lengths
|
||||||
|
*/
|
||||||
inline const QHash<QString, qreal> *VContainer::DataLengthSplines() const
|
inline const QHash<QString, qreal> *VContainer::DataLengthSplines() const
|
||||||
{
|
{
|
||||||
return &lengthSplines;
|
return &lengthSplines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataLengthArcs return container of arcs length
|
||||||
|
* @return pointer on container of arcs length
|
||||||
|
*/
|
||||||
inline const QHash<QString, qreal> *VContainer::DataLengthArcs() const
|
inline const QHash<QString, qreal> *VContainer::DataLengthArcs() const
|
||||||
{
|
{
|
||||||
return &lengthArcs;
|
return &lengthArcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataLineAngles return container of angles of line
|
||||||
|
* @return pointer on container of angles of line
|
||||||
|
*/
|
||||||
inline const QHash<QString, qreal> *VContainer::DataLineAngles() const
|
inline const QHash<QString, qreal> *VContainer::DataLineAngles() const
|
||||||
{
|
{
|
||||||
return &lineAngles;
|
return &lineAngles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief data container with dataDetails return container of details
|
||||||
|
* @return pointer on container of details
|
||||||
|
*/
|
||||||
inline const QHash<quint32, VDetail> *VContainer::DataDetails() const
|
inline const QHash<quint32, VDetail> *VContainer::DataDetails() const
|
||||||
{
|
{
|
||||||
return &details;
|
return &details;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "../../tools/vabstracttool.h"
|
#include "../../tools/vabstracttool.h"
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
#include "../../../libs/qmuparser/qmuparsererror.h"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
DialogTool::DialogTool(const VContainer *data, QWidget *parent)
|
DialogTool::DialogTool(const VContainer *data, QWidget *parent)
|
||||||
|
@ -329,20 +330,29 @@ void DialogTool::Eval(QLineEdit *edit, bool &flag, QTimer *timer, QLabel *label)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Calculator cal(data);
|
try
|
||||||
QString errorMsg;
|
{
|
||||||
qreal result = cal.eval(edit->text(), &errorMsg);
|
Calculator cal(data);
|
||||||
if (errorMsg.isEmpty() == false)
|
const qreal result = cal.EvalFormula(edit->text());
|
||||||
|
|
||||||
|
label->setText(QString().setNum(result));
|
||||||
|
flag = true;
|
||||||
|
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
|
||||||
|
emit ToolTip("");
|
||||||
|
}
|
||||||
|
catch(qmu::QmuParserError &e)
|
||||||
{
|
{
|
||||||
label->setText(tr("Error"));
|
label->setText(tr("Error"));
|
||||||
flag = false;
|
flag = false;
|
||||||
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
|
palette.setColor(labelEditFormula->foregroundRole(), Qt::red);
|
||||||
}
|
emit ToolTip(e.GetMsg());
|
||||||
else
|
qDebug() << "\nError:\n"
|
||||||
{
|
<< "--------\n"
|
||||||
label->setText(QString().setNum(result));
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
flag = true;
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
palette.setColor(labelEditFormula->foregroundRole(), QColor(76, 76, 76));
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckState();
|
CheckState();
|
||||||
|
|
|
@ -194,3 +194,8 @@ const QString min_F = QStringLiteral("min");
|
||||||
const QString max_F = QStringLiteral("max");
|
const QString max_F = QStringLiteral("max");
|
||||||
const QString sum_F = QStringLiteral("sum");
|
const QString sum_F = QStringLiteral("sum");
|
||||||
const QString avg_F = QStringLiteral("avg");
|
const QString avg_F = QStringLiteral("avg");
|
||||||
|
|
||||||
|
// Postfix operators
|
||||||
|
const QString cm_Oprt = QStringLiteral("cm");
|
||||||
|
const QString mm_Oprt = QStringLiteral("mm");
|
||||||
|
const QString in_Oprt = QStringLiteral("in");
|
||||||
|
|
|
@ -278,4 +278,9 @@ extern const QString max_F;
|
||||||
extern const QString sum_F;
|
extern const QString sum_F;
|
||||||
extern const QString avg_F;
|
extern const QString avg_F;
|
||||||
|
|
||||||
|
// Postfix operators
|
||||||
|
extern const QString cm_Oprt;
|
||||||
|
extern const QString mm_Oprt;
|
||||||
|
extern const QString in_Oprt;
|
||||||
|
|
||||||
#endif // OPTIONS_H
|
#endif // OPTIONS_H
|
||||||
|
|
|
@ -179,40 +179,53 @@ void VToolAlongLine::Create(const quint32 _id, const QString &pointName, const Q
|
||||||
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
|
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
|
||||||
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
||||||
QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());
|
QLineF line = QLineF(firstPoint->toQPointF(), secondPoint->toQPointF());
|
||||||
Calculator cal(data);
|
|
||||||
QString errorMsg;
|
try
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
|
Calculator cal(data);
|
||||||
|
const qreal result = cal.EvalFormula(formula);
|
||||||
line.setLength(qApp->toPixel(result));
|
line.setLength(qApp->toPixel(result));
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject( new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
data->AddLine(id, secondPointId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
data->AddLine(id, secondPointId);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject( new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
data->AddLine(id, secondPointId);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
data->AddLine(id, secondPointId);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::AlongLineTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId,
|
|
||||||
secondPointId, typeLine, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(firstPointId);
|
|
||||||
doc->IncrementReferens(secondPointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::AlongLineTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId,
|
||||||
|
secondPointId, typeLine, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolAlongLine::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolAlongLine::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(firstPointId);
|
||||||
|
doc->IncrementReferens(secondPointId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,26 +93,27 @@ void VToolArc::Create(const quint32 _id, const quint32 ¢er, const QString &r
|
||||||
{
|
{
|
||||||
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
|
qreal calcRadius = 0, calcF1 = 0, calcF2 = 0;
|
||||||
|
|
||||||
Calculator cal(data);
|
try
|
||||||
QString errorMsg;
|
|
||||||
qreal result = cal.eval(radius, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
|
Calculator cal(data);
|
||||||
|
|
||||||
|
qreal result = cal.EvalFormula(radius);
|
||||||
calcRadius = qApp->toPixel(result);
|
calcRadius = qApp->toPixel(result);
|
||||||
}
|
|
||||||
|
|
||||||
errorMsg.clear();
|
calcF1 = cal.EvalFormula(f1);
|
||||||
result = cal.eval(f1, &errorMsg);
|
calcF2 = cal.EvalFormula(f2);
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
|
||||||
calcF1 = result;
|
|
||||||
}
|
}
|
||||||
|
catch(qmu::QmuParserError &e)
|
||||||
errorMsg.clear();
|
|
||||||
result = cal.eval(f2, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
calcF2 = result;
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
VPointF c = *data->GeometricObject<const VPointF *>(center);
|
VPointF c = *data->GeometricObject<const VPointF *>(center);
|
||||||
|
|
|
@ -114,42 +114,55 @@ void VToolBisector::Create(const quint32 _id, const QString &formula, const quin
|
||||||
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
||||||
const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId);
|
const VPointF *thirdPoint = data->GeometricObject<const VPointF *>(thirdPointId);
|
||||||
|
|
||||||
Calculator cal(data);
|
qreal result = 0;
|
||||||
QString errorMsg;
|
try
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
Calculator cal(data);
|
||||||
thirdPoint->toQPointF(), qApp->toPixel(result));
|
result = cal.EvalFormula(formula);
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF fPoint = VToolBisector::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
||||||
|
thirdPoint->toQPointF(), qApp->toPixel(result));
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::BisectorTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId,
|
|
||||||
thirdPointId, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolBisector::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(firstPointId);
|
|
||||||
doc->IncrementReferens(secondPointId);
|
|
||||||
doc->IncrementReferens(thirdPointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::BisectorTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId,
|
||||||
|
thirdPointId, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolBisector::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolBisector::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(firstPointId);
|
||||||
|
doc->IncrementReferens(secondPointId);
|
||||||
|
doc->IncrementReferens(thirdPointId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -95,63 +95,76 @@ void VToolCutArc::Create(const quint32 _id, const QString &pointName, const QStr
|
||||||
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
VContainer *data, const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
||||||
{
|
{
|
||||||
const VArc *arc = data->GeometricObject<const VArc *>(arcId);
|
const VArc *arc = data->GeometricObject<const VArc *>(arcId);
|
||||||
Calculator cal(data);
|
qreal result = 0;
|
||||||
QString errorMsg;
|
try
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
VArc arc1;
|
Calculator cal(data);
|
||||||
VArc arc2;
|
result = cal.EvalFormula(formula);
|
||||||
QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2);
|
}
|
||||||
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
quint32 id = _id;
|
VArc arc1;
|
||||||
quint32 arc1id = 0;
|
VArc arc2;
|
||||||
quint32 arc2id = 0;
|
QPointF point = arc->CutArc(qApp->toPixel(result), arc1, arc2);
|
||||||
if (typeCreation == Valentina::FromGui)
|
|
||||||
|
quint32 id = _id;
|
||||||
|
quint32 arc1id = 0;
|
||||||
|
quint32 arc2id = 0;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
||||||
|
id = data->AddGObject(p);
|
||||||
|
|
||||||
|
VArc * ar1 = new VArc(arc1);
|
||||||
|
arc1id = data->AddGObject(ar1);
|
||||||
|
|
||||||
|
VArc * ar2 = new VArc(arc2);
|
||||||
|
arc2id = data->AddGObject(ar2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
||||||
|
data->UpdateGObject(id, p);
|
||||||
|
|
||||||
|
arc1id = id + 1;
|
||||||
|
arc2id = id + 2;
|
||||||
|
|
||||||
|
VArc * ar1 = new VArc(arc1);
|
||||||
|
data->UpdateGObject(arc1id, ar1);
|
||||||
|
|
||||||
|
VArc * ar2 = new VArc(arc2);
|
||||||
|
data->UpdateGObject(arc2id, ar2);
|
||||||
|
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
doc->UpdateToolData(id, data);
|
||||||
id = data->AddGObject(p);
|
|
||||||
|
|
||||||
VArc * ar1 = new VArc(arc1);
|
|
||||||
arc1id = data->AddGObject(ar1);
|
|
||||||
|
|
||||||
VArc * ar2 = new VArc(arc2);
|
|
||||||
arc2id = data->AddGObject(ar2);
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
data->AddLengthArc(arc1id);
|
||||||
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
data->AddLengthArc(arc2id);
|
||||||
data->UpdateGObject(id, p);
|
|
||||||
|
|
||||||
arc1id = id + 1;
|
VDrawTool::AddRecord(id, Valentina::CutArcTool, doc);
|
||||||
arc2id = id + 2;
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
VArc * ar1 = new VArc(arc1);
|
VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation);
|
||||||
data->UpdateGObject(arc1id, ar1);
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
VArc * ar2 = new VArc(arc2);
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
||||||
data->UpdateGObject(arc2id, ar2);
|
doc->AddTool(id, point);
|
||||||
|
doc->AddTool(arc1id, point);
|
||||||
if (parse != Document::FullParse)
|
doc->AddTool(arc2id, point);
|
||||||
{
|
doc->IncrementReferens(arcId);
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data->AddLengthArc(arc1id);
|
|
||||||
data->AddLengthArc(arc2id);
|
|
||||||
|
|
||||||
VDrawTool::AddRecord(id, Valentina::CutArcTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->AddTool(arc1id, point);
|
|
||||||
doc->AddTool(arc2id, point);
|
|
||||||
doc->IncrementReferens(arcId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,64 +96,78 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName,
|
||||||
const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
const Document::Documents &parse, const Valentina::Sources &typeCreation)
|
||||||
{
|
{
|
||||||
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
|
const VSpline *spl = data->GeometricObject<const VSpline *>(splineId);
|
||||||
Calculator cal(data);
|
|
||||||
QString errorMsg;
|
qreal result = 0;
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
try
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
Calculator cal(data);
|
||||||
QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
|
result = cal.EvalFormula(formula);
|
||||||
|
}
|
||||||
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
quint32 id = _id;
|
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
||||||
quint32 spl1id = 0;
|
QPointF point = spl->CutSpline(qApp->toPixel(result), spl1p2, spl1p3, spl2p2, spl2p3);
|
||||||
quint32 spl2id = 0;
|
|
||||||
if (typeCreation == Valentina::FromGui)
|
quint32 id = _id;
|
||||||
|
quint32 spl1id = 0;
|
||||||
|
quint32 spl2id = 0;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
||||||
|
id = data->AddGObject(p);
|
||||||
|
|
||||||
|
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
||||||
|
spl1id = data->AddGObject(spline1);
|
||||||
|
data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength()));
|
||||||
|
|
||||||
|
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
||||||
|
spl2id = data->AddGObject(spline2);
|
||||||
|
data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
||||||
|
data->UpdateGObject(id, p);
|
||||||
|
|
||||||
|
spl1id = id + 1;
|
||||||
|
spl2id = id + 2;
|
||||||
|
|
||||||
|
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
||||||
|
data->UpdateGObject(spl1id, spline1);
|
||||||
|
data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength()));
|
||||||
|
|
||||||
|
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
||||||
|
data->UpdateGObject(spl2id, spline2);
|
||||||
|
data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength()));
|
||||||
|
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
doc->UpdateToolData(id, data);
|
||||||
id = data->AddGObject(p);
|
|
||||||
|
|
||||||
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
|
||||||
spl1id = data->AddGObject(spline1);
|
|
||||||
data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength()));
|
|
||||||
|
|
||||||
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
|
||||||
spl2id = data->AddGObject(spline2);
|
|
||||||
data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
|
||||||
data->UpdateGObject(id, p);
|
|
||||||
|
|
||||||
spl1id = id + 1;
|
|
||||||
spl2id = id + 2;
|
|
||||||
|
|
||||||
VSpline *spline1 = new VSpline(spl->GetP1(), spl1p2, spl1p3, *p, spl->GetKcurve());
|
|
||||||
data->UpdateGObject(spl1id, spline1);
|
|
||||||
data->AddLengthSpline(spline1->name(), qApp->fromPixel(spline1->GetLength()));
|
|
||||||
|
|
||||||
VSpline *spline2 = new VSpline(*p, spl2p2, spl2p3, spl->GetP4(), spl->GetKcurve());
|
|
||||||
data->UpdateGObject(spl2id, spline2);
|
|
||||||
data->AddLengthSpline(spline2->name(), qApp->fromPixel(spline2->GetLength()));
|
|
||||||
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::CutSplineTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->AddTool(spl1id, point);
|
|
||||||
doc->AddTool(spl2id, point);
|
|
||||||
doc->IncrementReferens(splineId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::CutSplineTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->AddTool(spl1id, point);
|
||||||
|
doc->AddTool(spl2id, point);
|
||||||
|
doc->IncrementReferens(splineId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -97,136 +97,150 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, con
|
||||||
{
|
{
|
||||||
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
|
const VSplinePath *splPath = data->GeometricObject<const VSplinePath *>(splinePathId);
|
||||||
Q_CHECK_PTR(splPath);
|
Q_CHECK_PTR(splPath);
|
||||||
Calculator cal(data);
|
|
||||||
QString errorMsg;
|
qreal result = 0;
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
try
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
quint32 id = _id;
|
Calculator cal(data);
|
||||||
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
result = cal.EvalFormula(formula);
|
||||||
qint32 p1 = 0, p2 = 0;
|
}
|
||||||
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const QPointF point = splPath->CutSplinePath(qApp->toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
quint32 id = _id;
|
||||||
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
QPointF spl1p2, spl1p3, spl2p2, spl2p3;
|
||||||
if (typeCreation == Valentina::FromGui)
|
qint32 p1 = 0, p2 = 0;
|
||||||
|
|
||||||
|
const QPointF point = splPath->CutSplinePath(qApp->toPixel(result), p1, p2, spl1p2, spl1p3, spl2p2, spl2p3);
|
||||||
|
VPointF *p = new VPointF(point.x(), point.y(), pointName, mx, my);
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 splPath1id = id + 1;
|
||||||
|
quint32 splPath2id = id + 2;
|
||||||
|
|
||||||
|
VSplinePoint splP1 = splPath->at(p1);
|
||||||
|
VSplinePoint splP2 = splPath->at(p2);
|
||||||
|
const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve());
|
||||||
|
const VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve());
|
||||||
|
|
||||||
|
VSplinePath *splPath1 = new VSplinePath();
|
||||||
|
VSplinePath *splPath2 = new VSplinePath();
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(p);
|
if (i <= p1 && i < p2)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint32 splPath1id = id + 1;
|
|
||||||
quint32 splPath2id = id + 2;
|
|
||||||
|
|
||||||
VSplinePoint splP1 = splPath->at(p1);
|
|
||||||
VSplinePoint splP2 = splPath->at(p2);
|
|
||||||
const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, *p, splPath->getKCurve());
|
|
||||||
const VSpline spl2 = VSpline(*p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve());
|
|
||||||
|
|
||||||
VSplinePath *splPath1 = new VSplinePath();
|
|
||||||
VSplinePath *splPath2 = new VSplinePath();
|
|
||||||
if (typeCreation == Valentina::FromGui)
|
|
||||||
{
|
|
||||||
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
|
||||||
{
|
{
|
||||||
if (i <= p1 && i < p2)
|
if (i == p1)
|
||||||
{
|
{
|
||||||
if (i == p1)
|
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
||||||
{
|
spl1.GetAngle1()));
|
||||||
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(),
|
||||||
spl1.GetAngle1()));
|
spl1.GetAngle2()+180, spl1.GetAngle2());
|
||||||
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(),
|
splPath1->append(cutPoint);
|
||||||
spl1.GetAngle2()+180, spl1.GetAngle2());
|
continue;
|
||||||
splPath1->append(cutPoint);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
splPath1->append(splPath->at(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (i == p2)
|
|
||||||
{
|
|
||||||
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180,
|
|
||||||
spl2.GetKasm1(), spl2.GetAngle1());
|
|
||||||
splPath2->append(cutPoint);
|
|
||||||
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(),
|
|
||||||
spl2.GetAngle2()+180));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
splPath2->append(splPath->at(i));
|
|
||||||
}
|
}
|
||||||
|
splPath1->append(splPath->at(i));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
splPath1->setMaxCountPoints(splPath->CountPoint());
|
|
||||||
splPath2->setMaxCountPoints(splPath->CountPoint());
|
|
||||||
|
|
||||||
splPath1id = data->AddGObject(splPath1);
|
|
||||||
data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength()));
|
|
||||||
|
|
||||||
splPath2id = data->AddGObject(splPath2);
|
|
||||||
data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
|
||||||
{
|
{
|
||||||
if (i <= p1 && i < p2)
|
if (i == p2)
|
||||||
{
|
{
|
||||||
if (i == p1)
|
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180,
|
||||||
{
|
spl2.GetKasm1(), spl2.GetAngle1());
|
||||||
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
splPath2->append(cutPoint);
|
||||||
spl1.GetAngle1()));
|
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(),
|
||||||
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(),
|
spl2.GetAngle2()+180));
|
||||||
spl2.GetKasm1(), spl1.GetAngle2()+180);
|
continue;
|
||||||
splPath1->append(cutPoint);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
splPath1->append(splPath->at(i));
|
|
||||||
}
|
}
|
||||||
else
|
splPath2->append(splPath->at(i));
|
||||||
{
|
|
||||||
if (i == p2)
|
|
||||||
{
|
|
||||||
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180,
|
|
||||||
spl2.GetKasm1(), spl2.GetAngle1());
|
|
||||||
splPath2->append(cutPoint);
|
|
||||||
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(),
|
|
||||||
spl2.GetAngle2()+180));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
splPath2->append(splPath->at(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
splPath1->setMaxCountPoints(splPath->CountPoint());
|
|
||||||
splPath2->setMaxCountPoints(splPath->CountPoint());
|
|
||||||
|
|
||||||
data->UpdateGObject(splPath1id, splPath1);
|
|
||||||
data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength()));
|
|
||||||
|
|
||||||
data->UpdateGObject(splPath2id, splPath2);
|
|
||||||
data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength()));
|
|
||||||
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VDrawTool::AddRecord(id, Valentina::CutSplinePathTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
splPath1->setMaxCountPoints(splPath->CountPoint());
|
||||||
|
splPath2->setMaxCountPoints(splPath->CountPoint());
|
||||||
|
|
||||||
|
splPath1id = data->AddGObject(splPath1);
|
||||||
|
data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength()));
|
||||||
|
|
||||||
|
splPath2id = data->AddGObject(splPath2);
|
||||||
|
data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (qint32 i = 0; i < splPath->CountPoint(); i++)
|
||||||
{
|
{
|
||||||
VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id,
|
if (i <= p1 && i < p2)
|
||||||
splPath2id, typeCreation);
|
{
|
||||||
scene->addItem(point);
|
if (i == p1)
|
||||||
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
{
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(),
|
||||||
doc->AddTool(id, point);
|
spl1.GetAngle1()));
|
||||||
doc->AddTool(splPath1id, point);
|
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(),
|
||||||
doc->AddTool(splPath2id, point);
|
spl2.GetKasm1(), spl1.GetAngle2()+180);
|
||||||
doc->IncrementReferens(splinePathId);
|
splPath1->append(cutPoint);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
splPath1->append(splPath->at(i));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (i == p2)
|
||||||
|
{
|
||||||
|
const VSplinePoint cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl2.GetAngle1()+180,
|
||||||
|
spl2.GetKasm1(), spl2.GetAngle1());
|
||||||
|
splPath2->append(cutPoint);
|
||||||
|
splPath2->append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(),
|
||||||
|
spl2.GetAngle2()+180));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
splPath2->append(splPath->at(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
splPath1->setMaxCountPoints(splPath->CountPoint());
|
||||||
|
splPath2->setMaxCountPoints(splPath->CountPoint());
|
||||||
|
|
||||||
|
data->UpdateGObject(splPath1id, splPath1);
|
||||||
|
data->AddLengthSpline(splPath1->name(), qApp->fromPixel(splPath1->GetLength()));
|
||||||
|
|
||||||
|
data->UpdateGObject(splPath2id, splPath2);
|
||||||
|
data->AddLengthSpline(splPath2->name(), qApp->fromPixel(splPath2->GetLength()));
|
||||||
|
|
||||||
|
if (parse != Document::FullParse)
|
||||||
|
{
|
||||||
|
doc->UpdateToolData(id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::CutSplinePathTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id,
|
||||||
|
splPath2id, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->AddTool(splPath1id, point);
|
||||||
|
doc->AddTool(splPath2id, point);
|
||||||
|
doc->IncrementReferens(splinePathId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,40 +88,54 @@ void VToolEndLine::Create(const quint32 _id, const QString &pointName, const QSt
|
||||||
{
|
{
|
||||||
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
|
const VPointF *basePoint = data->GeometricObject<const VPointF *>(basePointId);
|
||||||
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
|
QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y()));
|
||||||
Calculator cal(data);
|
|
||||||
QString errorMsg;
|
qreal result = 0;
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
try
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
line.setLength(qApp->toPixel(result));
|
Calculator cal(data);
|
||||||
line.setAngle(angle);
|
result = cal.EvalFormula(formula);
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
line.setLength(qApp->toPixel(result));
|
||||||
|
line.setAngle(angle);
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
||||||
|
data->AddLine(basePointId, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
||||||
|
data->AddLine(basePointId, id);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(basePointId, id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(line.p2().x(), line.p2().y(), pointName, mx, my));
|
|
||||||
data->AddLine(basePointId, id);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::EndLineTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle,
|
|
||||||
basePointId, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(basePointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::EndLineTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle,
|
||||||
|
basePointId, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(basePointId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -90,41 +90,55 @@ void VToolNormal::Create(const quint32 _id, const QString &formula, const quint3
|
||||||
{
|
{
|
||||||
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
|
const VPointF *firstPoint = data->GeometricObject<const VPointF *>(firstPointId);
|
||||||
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(secondPointId);
|
||||||
Calculator cal(data);
|
|
||||||
QString errorMsg;
|
qreal result = 0;
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
try
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
Calculator cal(data);
|
||||||
qApp->toPixel(result), angle);
|
result = cal.EvalFormula(formula);
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF fPoint = VToolNormal::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
||||||
|
qApp->toPixel(result), angle);
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::NormalTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle,
|
|
||||||
firstPointId, secondPointId, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolNormal::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(firstPointId);
|
|
||||||
doc->IncrementReferens(secondPointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::NormalTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle,
|
||||||
|
firstPointId, secondPointId, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolNormal::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolNormal::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(firstPointId);
|
||||||
|
doc->IncrementReferens(secondPointId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -117,46 +117,59 @@ void VToolPointOfContact::Create(const quint32 _id, const QString &radius, const
|
||||||
const VPointF *firstP = data->GeometricObject<const VPointF *>(firstPointId);
|
const VPointF *firstP = data->GeometricObject<const VPointF *>(firstPointId);
|
||||||
const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId);
|
const VPointF *secondP = data->GeometricObject<const VPointF *>(secondPointId);
|
||||||
|
|
||||||
Calculator cal(data);
|
qreal result = 0;
|
||||||
QString errorMsg;
|
try
|
||||||
qreal result = cal.eval(radius, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(),
|
Calculator cal(data);
|
||||||
firstP->toQPointF(), secondP->toQPointF());
|
result = cal.EvalFormula(radius);
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), centerP->toQPointF(),
|
||||||
|
firstP->toQPointF(), secondP->toQPointF());
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
data->AddLine(secondPointId, id);
|
||||||
|
data->AddLine(center, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(firstPointId, id);
|
||||||
|
data->AddLine(secondPointId, id);
|
||||||
|
data->AddLine(center, id);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
data->AddLine(secondPointId, id);
|
|
||||||
data->AddLine(center, id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
|
||||||
data->AddLine(firstPointId, id);
|
|
||||||
data->AddLine(secondPointId, id);
|
|
||||||
data->AddLine(center, id);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::PointOfContact, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center,
|
|
||||||
firstPointId, secondPointId, typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfContact::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(center);
|
|
||||||
doc->IncrementReferens(firstPointId);
|
|
||||||
doc->IncrementReferens(secondPointId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::PointOfContact, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolPointOfContact *point = new VToolPointOfContact(doc, data, id, radius, center,
|
||||||
|
firstPointId, secondPointId, typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolPointOfContact::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPointOfContact::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(center);
|
||||||
|
doc->IncrementReferens(firstPointId);
|
||||||
|
doc->IncrementReferens(secondPointId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -119,45 +119,58 @@ void VToolShoulderPoint::Create(const quint32 _id, const QString &formula, const
|
||||||
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(p2Line);
|
const VPointF *secondPoint = data->GeometricObject<const VPointF *>(p2Line);
|
||||||
const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder);
|
const VPointF *shoulderPoint = data->GeometricObject<const VPointF *>(pShoulder);
|
||||||
|
|
||||||
Calculator cal(data);
|
qreal result = 0;
|
||||||
QString errorMsg;
|
try
|
||||||
qreal result = cal.eval(formula, &errorMsg);
|
|
||||||
if (errorMsg.isEmpty())
|
|
||||||
{
|
{
|
||||||
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
Calculator cal(data);
|
||||||
shoulderPoint->toQPointF(), qApp->toPixel(result));
|
result = cal.EvalFormula(formula);
|
||||||
quint32 id = _id;
|
}
|
||||||
if (typeCreation == Valentina::FromGui)
|
catch(qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
//TODO show error message
|
||||||
|
qDebug() << "\nError:\n"
|
||||||
|
<< "--------\n"
|
||||||
|
<< "Message: " << e.GetMsg() << "\n"
|
||||||
|
<< "Expression: \"" << e.GetExpr() << "\"\n"
|
||||||
|
<< "Token: \"" << e.GetToken() << "\"\n"
|
||||||
|
<< "Position: " << e.GetPos() << "\n"
|
||||||
|
<< "Errc: " << QString::number(e.GetCode(), 16);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF fPoint = VToolShoulderPoint::FindPoint(firstPoint->toQPointF(), secondPoint->toQPointF(),
|
||||||
|
shoulderPoint->toQPointF(), qApp->toPixel(result));
|
||||||
|
quint32 id = _id;
|
||||||
|
if (typeCreation == Valentina::FromGui)
|
||||||
|
{
|
||||||
|
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(p1Line, id);
|
||||||
|
data->AddLine(p2Line, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
||||||
|
data->AddLine(p1Line, id);
|
||||||
|
data->AddLine(p2Line, id);
|
||||||
|
if (parse != Document::FullParse)
|
||||||
{
|
{
|
||||||
id = data->AddGObject(new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
doc->UpdateToolData(id, data);
|
||||||
data->AddLine(p1Line, id);
|
|
||||||
data->AddLine(p2Line, id);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data->UpdateGObject(id, new VPointF(fPoint.x(), fPoint.y(), pointName, mx, my));
|
|
||||||
data->AddLine(p1Line, id);
|
|
||||||
data->AddLine(p2Line, id);
|
|
||||||
if (parse != Document::FullParse)
|
|
||||||
{
|
|
||||||
doc->UpdateToolData(id, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VDrawTool::AddRecord(id, Valentina::ShoulderPointTool, doc);
|
|
||||||
if (parse == Document::FullParse)
|
|
||||||
{
|
|
||||||
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula,
|
|
||||||
p1Line, p2Line, pShoulder,
|
|
||||||
typeCreation);
|
|
||||||
scene->addItem(point);
|
|
||||||
connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
|
||||||
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolShoulderPoint::SetFactor);
|
|
||||||
doc->AddTool(id, point);
|
|
||||||
doc->IncrementReferens(p1Line);
|
|
||||||
doc->IncrementReferens(p2Line);
|
|
||||||
doc->IncrementReferens(pShoulder);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
VDrawTool::AddRecord(id, Valentina::ShoulderPointTool, doc);
|
||||||
|
if (parse == Document::FullParse)
|
||||||
|
{
|
||||||
|
VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula,
|
||||||
|
p1Line, p2Line, pShoulder,
|
||||||
|
typeCreation);
|
||||||
|
scene->addItem(point);
|
||||||
|
connect(point, &VToolShoulderPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
|
||||||
|
connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolShoulderPoint::SetFactor);
|
||||||
|
doc->AddTool(id, point);
|
||||||
|
doc->IncrementReferens(p1Line);
|
||||||
|
doc->IncrementReferens(p2Line);
|
||||||
|
doc->IncrementReferens(pShoulder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -555,17 +555,12 @@ void QmuParserBase::DefineStrConst(const QString &a_strName, const QString &a_st
|
||||||
/**
|
/**
|
||||||
* @brief Add a user defined variable.
|
* @brief Add a user defined variable.
|
||||||
* @param [in] a_sName the variable name
|
* @param [in] a_sName the variable name
|
||||||
* @param [in] a_pVar A pointer to the variable vaule.
|
* @param [in] a_pVar the variable vaule.
|
||||||
* @post Will reset the Parser to string parsing mode.
|
* @post Will reset the Parser to string parsing mode.
|
||||||
* @throw ParserException in case the name contains invalid signs or a_pVar is NULL.
|
* @throw ParserException in case the name contains invalid signs.
|
||||||
*/
|
*/
|
||||||
void QmuParserBase::DefineVar(const QString &a_sName, qreal *a_pVar)
|
void QmuParserBase::DefineVar(const QString &a_sName, qreal a_pVar)
|
||||||
{
|
{
|
||||||
if (a_pVar==0)
|
|
||||||
{
|
|
||||||
Error(ecINVALID_VAR_PTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test if a constant with that names already exists
|
// Test if a constant with that names already exists
|
||||||
if (m_ConstDef.find(a_sName)!=m_ConstDef.end())
|
if (m_ConstDef.find(a_sName)!=m_ConstDef.end())
|
||||||
{
|
{
|
||||||
|
@ -1241,25 +1236,25 @@ qreal QmuParserBase::ParseCmdCodeBulk(int nOffset, int nThreadID) const
|
||||||
|
|
||||||
// value and variable tokens
|
// value and variable tokens
|
||||||
case cmVAR:
|
case cmVAR:
|
||||||
Stack[++sidx] = *(pTok->Val.ptr + nOffset);
|
Stack[++sidx] = *(&pTok->Val.ptr + nOffset);
|
||||||
continue;
|
continue;
|
||||||
case cmVAL:
|
case cmVAL:
|
||||||
Stack[++sidx] = pTok->Val.data2;
|
Stack[++sidx] = pTok->Val.data2;
|
||||||
continue;
|
continue;
|
||||||
case cmVARPOW2:
|
case cmVARPOW2:
|
||||||
buf = *(pTok->Val.ptr + nOffset);
|
buf = *(&pTok->Val.ptr + nOffset);
|
||||||
Stack[++sidx] = buf*buf;
|
Stack[++sidx] = buf*buf;
|
||||||
continue;
|
continue;
|
||||||
case cmVARPOW3:
|
case cmVARPOW3:
|
||||||
buf = *(pTok->Val.ptr + nOffset);
|
buf = *(&pTok->Val.ptr + nOffset);
|
||||||
Stack[++sidx] = buf*buf*buf;
|
Stack[++sidx] = buf*buf*buf;
|
||||||
continue;
|
continue;
|
||||||
case cmVARPOW4:
|
case cmVARPOW4:
|
||||||
buf = *(pTok->Val.ptr + nOffset);
|
buf = *(&pTok->Val.ptr + nOffset);
|
||||||
Stack[++sidx] = buf*buf*buf*buf;
|
Stack[++sidx] = buf*buf*buf*buf;
|
||||||
continue;
|
continue;
|
||||||
case cmVARMUL:
|
case cmVARMUL:
|
||||||
Stack[++sidx] = *(pTok->Val.ptr + nOffset) * pTok->Val.data + pTok->Val.data2;
|
Stack[++sidx] = *(&pTok->Val.ptr + nOffset) * pTok->Val.data + pTok->Val.data2;
|
||||||
continue;
|
continue;
|
||||||
// Next is treatment of numeric functions
|
// Next is treatment of numeric functions
|
||||||
case cmFUNC:
|
case cmFUNC:
|
||||||
|
@ -1497,7 +1492,7 @@ void QmuParserBase::CreateRPN() const
|
||||||
break;
|
break;
|
||||||
case cmVAR:
|
case cmVAR:
|
||||||
stVal.push(opt);
|
stVal.push(opt);
|
||||||
m_vRPN.AddVar( static_cast<qreal*>(opt.GetVar()) );
|
m_vRPN.AddVar( opt.GetVar() );
|
||||||
break;
|
break;
|
||||||
case cmVAL:
|
case cmVAL:
|
||||||
stVal.push(opt);
|
stVal.push(opt);
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
EOprtAssociativity a_eAssociativity = oaLEFT, bool a_bAllowOpt = false);
|
EOprtAssociativity a_eAssociativity = oaLEFT, bool a_bAllowOpt = false);
|
||||||
void DefineConst(const QString &a_sName, qreal a_fVal);
|
void DefineConst(const QString &a_sName, qreal a_fVal);
|
||||||
void DefineStrConst(const QString &a_sName, const QString &a_strVal);
|
void DefineStrConst(const QString &a_sName, const QString &a_strVal);
|
||||||
void DefineVar(const QString &a_sName, qreal *a_fVar);
|
void DefineVar(const QString &a_sName, qreal a_fVar);
|
||||||
void DefinePostfixOprt(const QString &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true);
|
void DefinePostfixOprt(const QString &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true);
|
||||||
void DefineInfixOprt(const QString &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX,
|
void DefineInfixOprt(const QString &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX,
|
||||||
bool a_bAllowOpt=true);
|
bool a_bAllowOpt=true);
|
||||||
|
|
|
@ -98,7 +98,7 @@ void QmuParserByteCode::Assign(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXC
|
||||||
* @param a_pVar Pointer to be added.
|
* @param a_pVar Pointer to be added.
|
||||||
* @throw nothrow
|
* @throw nothrow
|
||||||
*/
|
*/
|
||||||
void QmuParserByteCode::AddVar(qreal *a_pVar) Q_DECL_NOEXCEPT
|
void QmuParserByteCode::AddVar(qreal a_pVar) Q_DECL_NOEXCEPT
|
||||||
{
|
{
|
||||||
++m_iStackPos;
|
++m_iStackPos;
|
||||||
m_iMaxStackSize = qMax(m_iMaxStackSize, static_cast<size_t>(m_iStackPos));
|
m_iMaxStackSize = qMax(m_iMaxStackSize, static_cast<size_t>(m_iStackPos));
|
||||||
|
@ -134,7 +134,7 @@ void QmuParserByteCode::AddVal(qreal a_fVal) Q_DECL_NOEXCEPT
|
||||||
// If optimization does not apply
|
// If optimization does not apply
|
||||||
SToken tok;
|
SToken tok;
|
||||||
tok.Cmd = cmVAL;
|
tok.Cmd = cmVAL;
|
||||||
tok.Val.ptr = nullptr;
|
tok.Val.ptr = 0;
|
||||||
tok.Val.data = 0;
|
tok.Val.data = 0;
|
||||||
tok.Val.data2 = a_fVal;
|
tok.Val.data2 = a_fVal;
|
||||||
m_vRPN.push_back(tok);
|
m_vRPN.push_back(tok);
|
||||||
|
@ -355,14 +355,14 @@ void QmuParserByteCode::AddOp(ECmdCode a_Oprt)
|
||||||
(m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVARMUL &&
|
(m_vRPN[sz-1].Cmd == cmVARMUL && m_vRPN[sz-2].Cmd == cmVARMUL &&
|
||||||
m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) )
|
m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) )
|
||||||
{
|
{
|
||||||
assert( (m_vRPN[sz-2].Val.ptr==nullptr && m_vRPN[sz-1].Val.ptr!=nullptr) ||
|
assert( (m_vRPN[sz-2].Val.ptr==0 && m_vRPN[sz-1].Val.ptr!=0) ||
|
||||||
(m_vRPN[sz-2].Val.ptr!=nullptr && m_vRPN[sz-1].Val.ptr==nullptr) ||
|
(m_vRPN[sz-2].Val.ptr!=0 && m_vRPN[sz-1].Val.ptr==0) ||
|
||||||
(m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) );
|
(m_vRPN[sz-2].Val.ptr == m_vRPN[sz-1].Val.ptr) );
|
||||||
|
|
||||||
m_vRPN[sz-2].Cmd = cmVARMUL;
|
m_vRPN[sz-2].Cmd = cmVARMUL;
|
||||||
m_vRPN[sz-2].Val.ptr = reinterpret_cast<qreal*>(
|
m_vRPN[sz-2].Val.ptr = static_cast<qreal>(
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
static_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-1].Val.ptr)); // variable
|
static_cast<qlonglong>(m_vRPN[sz-1].Val.ptr)); // variable
|
||||||
m_vRPN[sz-2].Val.data2 += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data2; // offset
|
m_vRPN[sz-2].Val.data2 += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data2; // offset
|
||||||
m_vRPN[sz-2].Val.data += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data; // multiplikatior
|
m_vRPN[sz-2].Val.data += ((a_Oprt==cmSUB) ? -1 : 1) * m_vRPN[sz-1].Val.data; // multiplikatior
|
||||||
m_vRPN.pop_back();
|
m_vRPN.pop_back();
|
||||||
|
@ -374,9 +374,9 @@ void QmuParserByteCode::AddOp(ECmdCode a_Oprt)
|
||||||
(m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) )
|
(m_vRPN[sz-1].Cmd == cmVAL && m_vRPN[sz-2].Cmd == cmVAR) )
|
||||||
{
|
{
|
||||||
m_vRPN[sz-2].Cmd = cmVARMUL;
|
m_vRPN[sz-2].Cmd = cmVARMUL;
|
||||||
m_vRPN[sz-2].Val.ptr = reinterpret_cast<qreal*>(
|
m_vRPN[sz-2].Val.ptr = static_cast<qreal>(
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
static_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-1].Val.ptr));
|
static_cast<qlonglong>(m_vRPN[sz-1].Val.ptr));
|
||||||
m_vRPN[sz-2].Val.data = m_vRPN[sz-2].Val.data2 + m_vRPN[sz-1].Val.data2;
|
m_vRPN[sz-2].Val.data = m_vRPN[sz-2].Val.data2 + m_vRPN[sz-1].Val.data2;
|
||||||
m_vRPN[sz-2].Val.data2 = 0;
|
m_vRPN[sz-2].Val.data2 = 0;
|
||||||
m_vRPN.pop_back();
|
m_vRPN.pop_back();
|
||||||
|
@ -387,9 +387,9 @@ void QmuParserByteCode::AddOp(ECmdCode a_Oprt)
|
||||||
{
|
{
|
||||||
// Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2
|
// Optimization: 2*(3*b+1) or (3*b+1)*2 -> 6*b+2
|
||||||
m_vRPN[sz-2].Cmd = cmVARMUL;
|
m_vRPN[sz-2].Cmd = cmVARMUL;
|
||||||
m_vRPN[sz-2].Val.ptr = reinterpret_cast<qreal*>(
|
m_vRPN[sz-2].Val.ptr = static_cast<qreal>(
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
static_cast<qlonglong>(m_vRPN[sz-2].Val.ptr) |
|
||||||
reinterpret_cast<qlonglong>(m_vRPN[sz-1].Val.ptr));
|
static_cast<qlonglong>(m_vRPN[sz-1].Val.ptr));
|
||||||
if (m_vRPN[sz-1].Cmd == cmVAL)
|
if (m_vRPN[sz-1].Cmd == cmVAL)
|
||||||
{
|
{
|
||||||
m_vRPN[sz-2].Val.data *= m_vRPN[sz-1].Val.data2;
|
m_vRPN[sz-2].Val.data *= m_vRPN[sz-1].Val.data2;
|
||||||
|
@ -491,7 +491,7 @@ void QmuParserByteCode::AddIfElse(ECmdCode a_Oprt) Q_DECL_NOEXCEPT
|
||||||
*
|
*
|
||||||
* @sa ParserToken::ECmdCode
|
* @sa ParserToken::ECmdCode
|
||||||
*/
|
*/
|
||||||
void QmuParserByteCode::AddAssignOp(qreal *a_pVar) Q_DECL_NOEXCEPT
|
void QmuParserByteCode::AddAssignOp(qreal a_pVar) Q_DECL_NOEXCEPT
|
||||||
{
|
{
|
||||||
--m_iStackPos;
|
--m_iStackPos;
|
||||||
|
|
||||||
|
@ -691,19 +691,19 @@ void QmuParserByteCode::AsciiDump()
|
||||||
qDebug() << "VAL \t" << "[" << m_vRPN[i].Val.data2 << "]\n";
|
qDebug() << "VAL \t" << "[" << m_vRPN[i].Val.data2 << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmVAR:
|
case cmVAR:
|
||||||
qDebug() << "VAR \t" << "[ADDR: 0x" << QString::number(*m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
qDebug() << "VAR \t" << "[ADDR: 0x" << QString::number(m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmVARPOW2:
|
case cmVARPOW2:
|
||||||
qDebug() << "VARPOW2 \t" << "[ADDR: 0x" << QString::number(*m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
qDebug() << "VARPOW2 \t" << "[ADDR: 0x" << QString::number(m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmVARPOW3:
|
case cmVARPOW3:
|
||||||
qDebug() << "VARPOW3 \t" << "[ADDR: 0x" << QString::number(*m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
qDebug() << "VARPOW3 \t" << "[ADDR: 0x" << QString::number(m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmVARPOW4:
|
case cmVARPOW4:
|
||||||
qDebug() << "VARPOW4 \t" << "[ADDR: 0x" << QString::number(*m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
qDebug() << "VARPOW4 \t" << "[ADDR: 0x" << QString::number(m_vRPN[i].Val.ptr, 'f', 16) << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmVARMUL:
|
case cmVARMUL:
|
||||||
qDebug() << "VARMUL \t" << "[ADDR: 0x" << QString::number(*m_vRPN[i].Val.ptr, 'f', 16) << "]" << " * ["
|
qDebug() << "VARMUL \t" << "[ADDR: 0x" << QString::number(m_vRPN[i].Val.ptr, 'f', 16) << "]" << " * ["
|
||||||
<< m_vRPN[i].Val.data << "]" << " + [" << m_vRPN[i].Val.data2 << "]\n";
|
<< m_vRPN[i].Val.data << "]" << " + [" << m_vRPN[i].Val.data2 << "]\n";
|
||||||
break;
|
break;
|
||||||
case cmFUNC:
|
case cmFUNC:
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct SToken
|
||||||
{
|
{
|
||||||
struct //SValData
|
struct //SValData
|
||||||
{
|
{
|
||||||
qreal *ptr;
|
qreal ptr;
|
||||||
qreal data;
|
qreal data;
|
||||||
qreal data2;
|
qreal data2;
|
||||||
} Val;
|
} Val;
|
||||||
|
@ -85,11 +85,11 @@ public:
|
||||||
QmuParserByteCode(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
QmuParserByteCode(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
||||||
QmuParserByteCode& operator=(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
QmuParserByteCode& operator=(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
||||||
void Assign(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
void Assign(const QmuParserByteCode &a_ByteCode) Q_DECL_NOEXCEPT;
|
||||||
void AddVar(qreal *a_pVar) Q_DECL_NOEXCEPT;
|
void AddVar(qreal a_pVar) Q_DECL_NOEXCEPT;
|
||||||
void AddVal(qreal a_fVal) Q_DECL_NOEXCEPT;
|
void AddVal(qreal a_fVal) Q_DECL_NOEXCEPT;
|
||||||
void AddOp(ECmdCode a_Oprt);
|
void AddOp(ECmdCode a_Oprt);
|
||||||
void AddIfElse(ECmdCode a_Oprt) Q_DECL_NOEXCEPT;
|
void AddIfElse(ECmdCode a_Oprt) Q_DECL_NOEXCEPT;
|
||||||
void AddAssignOp(qreal *a_pVar) Q_DECL_NOEXCEPT;
|
void AddAssignOp(qreal a_pVar) Q_DECL_NOEXCEPT;
|
||||||
void AddFun(generic_fun_type a_pFun, int a_iArgc) Q_DECL_NOEXCEPT;
|
void AddFun(generic_fun_type a_pFun, int a_iArgc) Q_DECL_NOEXCEPT;
|
||||||
void AddBulkFun(generic_fun_type a_pFun, int a_iArgc) Q_DECL_NOEXCEPT;
|
void AddBulkFun(generic_fun_type a_pFun, int a_iArgc) Q_DECL_NOEXCEPT;
|
||||||
void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx) Q_DECL_NOEXCEPT;
|
void AddStrFun(generic_fun_type a_pFun, int a_iArgc, int a_iIdx) Q_DECL_NOEXCEPT;
|
||||||
|
|
|
@ -173,7 +173,7 @@ typedef std::basic_stringstream < char_type, std::char_traits<char_type>, std::a
|
||||||
// Data container types
|
// Data container types
|
||||||
|
|
||||||
/** @brief Type used for storing variables. */
|
/** @brief Type used for storing variables. */
|
||||||
typedef std::map<QString, qreal*> varmap_type;
|
typedef std::map<QString, qreal> varmap_type;
|
||||||
|
|
||||||
/** @brief Type used for storing constants. */
|
/** @brief Type used for storing constants. */
|
||||||
typedef std::map<QString, qreal> valmap_type;
|
typedef std::map<QString, qreal> valmap_type;
|
||||||
|
@ -268,7 +268,7 @@ typedef qreal ( *strfun_type3 ) ( const QString &, qreal, qreal );
|
||||||
typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal );
|
typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal );
|
||||||
|
|
||||||
/** @brief Callback used for variable creation factory functions. */
|
/** @brief Callback used for variable creation factory functions. */
|
||||||
typedef qreal* ( *facfun_type ) ( const QString &, void* );
|
typedef qreal ( *facfun_type ) ( const QString &, void* );
|
||||||
} // end of namespace
|
} // end of namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -103,9 +103,9 @@ int QmuParserTester::TestInterface()
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
p.DefineVar ( "a", &afVal[0] );
|
p.DefineVar ( "a", afVal[0] );
|
||||||
p.DefineVar ( "b", &afVal[1] );
|
p.DefineVar ( "b", afVal[1] );
|
||||||
p.DefineVar ( "c", &afVal[2] );
|
p.DefineVar ( "c", afVal[2] );
|
||||||
p.SetExpr ( "a+b+c" );
|
p.SetExpr ( "a+b+c" );
|
||||||
p.Eval();
|
p.Eval();
|
||||||
}
|
}
|
||||||
|
@ -280,21 +280,21 @@ int QmuParserTester::TestNames()
|
||||||
// variable names
|
// variable names
|
||||||
qreal a;
|
qreal a;
|
||||||
p.ClearConst();
|
p.ClearConst();
|
||||||
PARSER_THROWCHECK ( Var, false, "123abc", &a )
|
PARSER_THROWCHECK ( Var, false, "123abc", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "9a", &a )
|
PARSER_THROWCHECK ( Var, false, "9a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "0a", &a )
|
PARSER_THROWCHECK ( Var, false, "0a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "+a", &a )
|
PARSER_THROWCHECK ( Var, false, "+a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "-a", &a )
|
PARSER_THROWCHECK ( Var, false, "-a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "?a", &a )
|
PARSER_THROWCHECK ( Var, false, "?a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "!a", &a )
|
PARSER_THROWCHECK ( Var, false, "!a", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "a+", &a )
|
PARSER_THROWCHECK ( Var, false, "a+", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "a-", &a )
|
PARSER_THROWCHECK ( Var, false, "a-", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "a*", &a )
|
PARSER_THROWCHECK ( Var, false, "a*", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "a?", &a )
|
PARSER_THROWCHECK ( Var, false, "a?", a )
|
||||||
PARSER_THROWCHECK ( Var, true, "a", &a )
|
PARSER_THROWCHECK ( Var, true, "a", a )
|
||||||
PARSER_THROWCHECK ( Var, true, "a_min", &a )
|
PARSER_THROWCHECK ( Var, true, "a_min", a )
|
||||||
PARSER_THROWCHECK ( Var, true, "a_min0", &a )
|
PARSER_THROWCHECK ( Var, true, "a_min0", a )
|
||||||
PARSER_THROWCHECK ( Var, true, "a_min9", &a )
|
PARSER_THROWCHECK ( Var, true, "a_min9", a )
|
||||||
PARSER_THROWCHECK ( Var, false, "a_min9", 0 )
|
PARSER_THROWCHECK ( Var, false, "a_min9", 0 )
|
||||||
// Postfix operators
|
// Postfix operators
|
||||||
// fail
|
// fail
|
||||||
|
@ -449,11 +449,11 @@ int QmuParserTester::TestVarConst()
|
||||||
int idx;
|
int idx;
|
||||||
qmu::QmuParser p;
|
qmu::QmuParser p;
|
||||||
qreal vVarVal[] = { 1, 2, 3, 4, 5};
|
qreal vVarVal[] = { 1, 2, 3, 4, 5};
|
||||||
p.DefineVar ( "a", &vVarVal[0] );
|
p.DefineVar ( "a", vVarVal[0] );
|
||||||
p.DefineVar ( "b", &vVarVal[1] );
|
p.DefineVar ( "b", vVarVal[1] );
|
||||||
p.DefineVar ( "c", &vVarVal[2] );
|
p.DefineVar ( "c", vVarVal[2] );
|
||||||
p.DefineVar ( "d", &vVarVal[3] );
|
p.DefineVar ( "d", vVarVal[3] );
|
||||||
p.DefineVar ( "e", &vVarVal[4] );
|
p.DefineVar ( "e", vVarVal[4] );
|
||||||
|
|
||||||
// Test lookup of defined variables
|
// Test lookup of defined variables
|
||||||
// 4 used variables
|
// 4 used variables
|
||||||
|
@ -475,7 +475,7 @@ int QmuParserTester::TestVarConst()
|
||||||
qmu::varmap_type::const_iterator item = UsedVar.begin();
|
qmu::varmap_type::const_iterator item = UsedVar.begin();
|
||||||
for ( idx = 0; item != UsedVar.end(); ++item )
|
for ( idx = 0; item != UsedVar.end(); ++item )
|
||||||
{
|
{
|
||||||
if ( &vVarVal[idx++] != item->second )
|
if ( vVarVal[idx++] != item->second )
|
||||||
{
|
{
|
||||||
throw false;
|
throw false;
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ int QmuParserTester::TestVarConst()
|
||||||
item = UsedVar.begin();
|
item = UsedVar.begin();
|
||||||
for ( idx = 0; item != UsedVar.end(); ++item )
|
for ( idx = 0; item != UsedVar.end(); ++item )
|
||||||
{
|
{
|
||||||
if ( &vVarVal[idx++] != item->second )
|
if ( vVarVal[idx++] != item->second )
|
||||||
{
|
{
|
||||||
throw false;
|
throw false;
|
||||||
}
|
}
|
||||||
|
@ -1118,9 +1118,9 @@ int QmuParserTester::ThrowTest ( const QString &a_str, int a_iErrc, bool a_bFail
|
||||||
qreal fVal[] = {1, 1, 1};
|
qreal fVal[] = {1, 1, 1};
|
||||||
QmuParser p;
|
QmuParser p;
|
||||||
|
|
||||||
p.DefineVar ( "a", &fVal[0] );
|
p.DefineVar ( "a", fVal[0] );
|
||||||
p.DefineVar ( "b", &fVal[1] );
|
p.DefineVar ( "b", fVal[1] );
|
||||||
p.DefineVar ( "c", &fVal[2] );
|
p.DefineVar ( "c", fVal[2] );
|
||||||
p.DefinePostfixOprt ( "{m}", Milli );
|
p.DefinePostfixOprt ( "{m}", Milli );
|
||||||
p.DefinePostfixOprt ( "m", Milli );
|
p.DefinePostfixOprt ( "m", Milli );
|
||||||
p.DefineFun ( "ping", Ping );
|
p.DefineFun ( "ping", Ping );
|
||||||
|
@ -1173,7 +1173,7 @@ int QmuParserTester::EqnTestWithVarChange ( const QString &a_str, double a_fVar1
|
||||||
|
|
||||||
// variable
|
// variable
|
||||||
qreal var = 0;
|
qreal var = 0;
|
||||||
p.DefineVar ( "a", &var );
|
p.DefineVar ( "a", var );
|
||||||
p.SetExpr ( a_str );
|
p.SetExpr ( a_str );
|
||||||
|
|
||||||
var = a_fVar1;
|
var = a_fVar1;
|
||||||
|
@ -1242,11 +1242,11 @@ int QmuParserTester::EqnTest ( const QString &a_str, double a_fRes, bool a_fPass
|
||||||
p1->DefineConst ( "const2", 3 );
|
p1->DefineConst ( "const2", 3 );
|
||||||
// variables
|
// variables
|
||||||
qreal vVarVal[] = { 1, 2, 3, -2};
|
qreal vVarVal[] = { 1, 2, 3, -2};
|
||||||
p1->DefineVar ( "a", &vVarVal[0] );
|
p1->DefineVar ( "a", vVarVal[0] );
|
||||||
p1->DefineVar ( "aa", &vVarVal[1] );
|
p1->DefineVar ( "aa", vVarVal[1] );
|
||||||
p1->DefineVar ( "b", &vVarVal[1] );
|
p1->DefineVar ( "b", vVarVal[1] );
|
||||||
p1->DefineVar ( "c", &vVarVal[2] );
|
p1->DefineVar ( "c", vVarVal[2] );
|
||||||
p1->DefineVar ( "d", &vVarVal[3] );
|
p1->DefineVar ( "d", vVarVal[3] );
|
||||||
|
|
||||||
// custom value ident functions
|
// custom value ident functions
|
||||||
p1->AddValIdent ( &QmuParserTester::IsHexVal );
|
p1->AddValIdent ( &QmuParserTester::IsHexVal );
|
||||||
|
|
|
@ -196,13 +196,13 @@ public:
|
||||||
* Member variables not necessary for variable tokens will be invalidated.
|
* Member variables not necessary for variable tokens will be invalidated.
|
||||||
* @throw nothrow
|
* @throw nothrow
|
||||||
*/
|
*/
|
||||||
QmuParserToken& SetVar ( TBase *a_pVar, const TString &a_strTok )
|
QmuParserToken& SetVar ( TBase a_pVar, const TString &a_strTok )
|
||||||
{
|
{
|
||||||
m_iCode = cmVAR;
|
m_iCode = cmVAR;
|
||||||
m_iType = tpDBL;
|
m_iType = tpDBL;
|
||||||
m_strTok = a_strTok;
|
m_strTok = a_strTok;
|
||||||
m_iIdx = -1;
|
m_iIdx = -1;
|
||||||
m_pTok = reinterpret_cast<void*> ( a_pVar );
|
m_pTok = a_pVar;
|
||||||
m_pCallback.reset ( 0 );
|
m_pCallback.reset ( 0 );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -357,7 +357,7 @@ public:
|
||||||
case cmVAL:
|
case cmVAL:
|
||||||
return m_fVal;
|
return m_fVal;
|
||||||
case cmVAR:
|
case cmVAR:
|
||||||
return * ( reinterpret_cast<TBase*>(m_pTok) );
|
return m_pTok;
|
||||||
case cmLE:
|
case cmLE:
|
||||||
case cmGE:
|
case cmGE:
|
||||||
case cmNEQ:
|
case cmNEQ:
|
||||||
|
@ -404,14 +404,14 @@ public:
|
||||||
* Valid only if m_iType==CmdVar.
|
* Valid only if m_iType==CmdVar.
|
||||||
* @throw QmuParserError if token is no variable token.
|
* @throw QmuParserError if token is no variable token.
|
||||||
*/
|
*/
|
||||||
TBase* GetVar() const
|
TBase GetVar() const
|
||||||
{
|
{
|
||||||
if ( m_iCode != cmVAR )
|
if ( m_iCode != cmVAR )
|
||||||
{
|
{
|
||||||
throw QmuParserError ( ecINTERNAL_ERROR );
|
throw QmuParserError ( ecINTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
|
|
||||||
return reinterpret_cast<TBase*>( m_pTok );
|
return m_pTok;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -449,7 +449,7 @@ public:
|
||||||
private:
|
private:
|
||||||
ECmdCode m_iCode; ///< Type of the token; The token type is a constant of type #ECmdCode.
|
ECmdCode m_iCode; ///< Type of the token; The token type is a constant of type #ECmdCode.
|
||||||
ETypeCode m_iType;
|
ETypeCode m_iType;
|
||||||
void *m_pTok; ///< Stores Token pointer; not applicable for all tokens
|
TBase m_pTok; ///< Stores Token pointer; not applicable for all tokens
|
||||||
int m_iIdx; ///< An otional index to an external buffer storing the token data
|
int m_iIdx; ///< An otional index to an external buffer storing the token data
|
||||||
TString m_strTok; ///< Token string
|
TString m_strTok; ///< Token string
|
||||||
TString m_strVal; ///< Value for string variables
|
TString m_strVal; ///< Value for string variables
|
||||||
|
|
|
@ -976,7 +976,7 @@ bool QmuParserTokenReader::IsUndefVarTok ( token_type &a_Tok ) Q_DECL_NOEXCEPT
|
||||||
// If a factory is available implicitely create new variables
|
// If a factory is available implicitely create new variables
|
||||||
if ( m_pFactory )
|
if ( m_pFactory )
|
||||||
{
|
{
|
||||||
qreal *fVar = m_pFactory ( strTok, m_pFactoryData );
|
qreal fVar = m_pFactory ( strTok, m_pFactoryData );
|
||||||
a_Tok.SetVar ( fVar, strTok );
|
a_Tok.SetVar ( fVar, strTok );
|
||||||
|
|
||||||
// Do not use m_pParser->DefineVar( strTok, fVar );
|
// Do not use m_pParser->DefineVar( strTok, fVar );
|
||||||
|
@ -990,7 +990,7 @@ bool QmuParserTokenReader::IsUndefVarTok ( token_type &a_Tok ) Q_DECL_NOEXCEPT
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
a_Tok.SetVar ( &m_fZero, strTok );
|
a_Tok.SetVar ( m_fZero, strTok );
|
||||||
m_UsedVar[strTok] = 0; // Add variable to used-var-list
|
m_UsedVar[strTok] = 0; // Add variable to used-var-list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user