diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 87bdd1f8d..adcafbdc0 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -139,15 +139,12 @@ qreal Calculator::EvalFormula(const QString &formula) } // Add variables - InitVariables(data, tokens); - - result = Eval(); - - return result; + InitVariables(data, tokens, formula); + return Eval(); } //--------------------------------------------------------------------------------------------------------------------- -void Calculator::InitVariables(const VContainer *data, const QMap &tokens) +void Calculator::InitVariables(const VContainer *data, const QMap &tokens, const QString &formula) { if (qApp->patternType() == MeasurementsType::Standard) { @@ -156,9 +153,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap const QHash > *vars = data->DataVariables(); + bool found = false; QMap::const_iterator i = tokens.constBegin(); while (i != tokens.constEnd()) { + found = false; if (vars->contains(i.value())) { QSharedPointer var = vars->value(i.value()); @@ -169,6 +168,7 @@ void Calculator::InitVariables(const VContainer *data, const QMap m->SetValue(data->size(), data->height()); } DefineVar(i.value(), var->GetValue()); + found = true; } if (qApp->patternType() == MeasurementsType::Standard) @@ -177,14 +177,21 @@ void Calculator::InitVariables(const VContainer *data, const QMap { vVarVal[0] = data->size(); DefineVar(data->SizeName(), &vVarVal[0]); + found = true; } if (i.value() == data->HeightName()) { vVarVal[1] = data->height(); DefineVar(data->HeightName(), &vVarVal[1]); + found = true; } } + + if (found == false) + { + throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN , i.value(), formula, i.key()); + } ++i; } } diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 22ec079f3..c0c11b090 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -64,7 +64,7 @@ private: qreal *vVarVal; static int iVal; const VContainer *data; - void InitVariables(const VContainer *data, const QMap &tokens); + void InitVariables(const VContainer *data, const QMap &tokens, const QString &formula); void InitCharacterSets(); static qreal* AddVariable(const QString &a_szName, void *a_pUserData); }; diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index 90eaa2119..3ccc55d5a 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 4eeb9265a..335ffd22a 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -87,9 +87,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index edc00b560..8b8c5ec0f 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), thirdPointId(NULL_ID), formulaBaseHeight(0), line(nullptr), prepare(false) { diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 12fbdfacf..6a0816a45 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -92,9 +92,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index e681290de..312354b2c 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent) - : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), + : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()), arcId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index a01f5c1e5..a320b7e37 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -78,9 +78,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutArc *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 13cd130c3..0e96cecd7 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -40,7 +40,7 @@ * @param parent parent widget */ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), splineId(NULL_ID), formulaBaseHeight(0) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutspline.h b/src/app/dialogs/tools/dialogcutspline.h index 11833bd25..c541cb58a 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -71,9 +71,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSpline *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index 2d4acf4ae..c6ad759b1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -40,7 +40,7 @@ * @param parent parent widget */ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), splinePathId(NULL_ID), formulaBaseHeight(0) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index a6676629a..46d299379 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -71,9 +71,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSplinePath *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index a6e281666..e1009d46a 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), typeLine(QString()), formulaLength(QString()), formulaAngle(QString()), basePointId(NULL_ID), formulaBaseHeight(0), formulaBaseHeightAngle(0), line(nullptr) { diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index b0a9eed1c..6fa3ebfc4 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -89,9 +89,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogEndLine *ui; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index aa09f8012..020c12a7b 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogheight.h b/src/app/dialogs/tools/dialogheight.h index 8d4c33f01..8c384b145 100644 --- a/src/app/dialogs/tools/dialogheight.h +++ b/src/app/dialogs/tools/dialogheight.h @@ -81,9 +81,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 7b6ca9fed..4de620302 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), p1Line1(NULL_ID), p2Line1(NULL_ID), p1Line2(NULL_ID), p2Line2(NULL_ID), flagPoint(true), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialoglineintersect.h b/src/app/dialogs/tools/dialoglineintersect.h index 474261208..93f686f73 100644 --- a/src/app/dialogs/tools/dialoglineintersect.h +++ b/src/app/dialogs/tools/dialoglineintersect.h @@ -85,9 +85,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief p1Line1 id first point of first line */ quint32 p1Line1; diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index e28916508..01dd8bdde 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -39,7 +39,7 @@ * @param parent parent widget */ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), typeLine(QString()), formula(QString()), angle(0), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index 4c52ad887..222ced37b 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 6d39c8fac..a4f6331c8 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), radius(QString()), center(NULL_ID), firstPoint(NULL_ID), secondPoint(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogpointofcontact.h b/src/app/dialogs/tools/dialogpointofcontact.h index 5887ec95a..11fd4ed7a 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.h +++ b/src/app/dialogs/tools/dialogpointofcontact.h @@ -89,9 +89,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief radius radius of arc */ QString radius; diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index b38cc5884..0788a791c 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogpointofintersection.h b/src/app/dialogs/tools/dialogpointofintersection.h index ef1074baf..00fb7648b 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -75,9 +75,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief firstPointId id first point of line */ quint32 firstPointId; diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 9ae01db84..eed3962de 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -42,7 +42,7 @@ * @param parent parent widget */ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), typeLine(QString()), formula(QString()), p1Line(NULL_ID), p2Line(NULL_ID), pShoulder(NULL_ID), formulaBaseHeight(0), line (nullptr) { diff --git a/src/app/dialogs/tools/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 192cd7387..f4e09d955 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 444fec323..686ec0752 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -63,7 +63,8 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()), - okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false) + okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false), + pointName(QString()) { SCASSERT(data != nullptr); timerFormula = new QTimer(this); @@ -659,7 +660,8 @@ void DialogTool::NamePointChanged() if (edit) { QString name = edit->text(); - if (name.isEmpty() || name.contains(" ")) + name.replace(" ", ""); + if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false)) { flagName = false; ChangeColor(labelEditNamePoint, Qt::red); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 5d2ab7950..659cc7069 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -200,6 +200,9 @@ protected: /** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/ bool prepare; + /** @brief pointName name of point */ + QString pointName; + virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); void FillComboBoxPoints(QComboBox *box)const; diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index fb8a8f5b5..065b03093 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -41,7 +41,7 @@ * @param parent parent widget */ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(NULL_ID), + :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), axisP1Id(NULL_ID), axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr) { ui->setupUi(this); diff --git a/src/app/dialogs/tools/dialogtriangle.h b/src/app/dialogs/tools/dialogtriangle.h index 5c0828e1e..51c2e52b7 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -80,9 +80,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief axisP1Id id first point of axis */ quint32 axisP1Id; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index f0fb41f94..58f901c37 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1139,7 +1139,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula || angleFix != angle) { - SetAttribute(domElement, VAbstractTool::AttrRadius, f); + SetAttribute(domElement, VAbstractTool::AttrLength, f); SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); haveLiteChange(); } @@ -2452,6 +2452,7 @@ void VPattern::PrepareForParse(const Document &parse) else if (parse == Document::LiteParse) { data->ClearUniqueNames(); + data->ClearVariables(); } }