diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 84e867722..502ab46a6 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -473,7 +473,7 @@ const QMap VContainer::DataLengthArcs() const } //--------------------------------------------------------------------------------------------------------------------- -const QMap VContainer::DataLineAngles() const +const QMap VContainer::DataAngleLines() const { return DataVar(VarType::LineAngle); } diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index a8c94cfc3..0dbca7bb1 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -175,7 +175,7 @@ public: const QMap DataLengthLines() const; const QMap DataLengthSplines() const; const QMap DataLengthArcs() const; - const QMap DataLineAngles() const; + const QMap DataAngleLines() const; private: diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index d936307f6..37da60097 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -423,6 +423,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogarc.cpp b/src/app/dialogs/tools/dialogarc.cpp index 007200951..5abcdc6ba 100644 --- a/src/app/dialogs/tools/dialogarc.cpp +++ b/src/app/dialogs/tools/dialogarc.cpp @@ -34,6 +34,7 @@ #include "../../geometry/vpointf.h" #include "../../container/vcontainer.h" +#include "../../xml/vdomdocument.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -229,7 +230,7 @@ void DialogArc::ValChenged(int row) return; } QListWidgetItem *item = ui->listWidget->item( row ); - if (ui->radioButtonLineAngles->isChecked()) + if (ui->radioButtonAngleLine->isChecked()) { qreal angle = *data->GetVariable(item->text())->GetValue(); QString desc = QString("%1(%2) - %3").arg(item->text()).arg(angle).arg(tr("Value of angle of line.")); @@ -325,7 +326,8 @@ void DialogArc::CheckState() void DialogArc::EvalRadius() { labelEditFormula = ui->labelEditRadius; - Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, timerRadius, ui->labelResultRadius); + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit(), true); + Eval(ui->plainTextEditFormula->toPlainText(), flagRadius, timerRadius, ui->labelResultRadius, postfix); } //--------------------------------------------------------------------------------------------------------------------- @@ -335,7 +337,8 @@ void DialogArc::EvalRadius() void DialogArc::EvalF1() { labelEditFormula = ui->labelEditF1; - Eval(ui->plainTextEditF1->toPlainText(), flagF1, timerF1, ui->labelResultF1, false); + const QString postfix = QStringLiteral("°"); + Eval(ui->plainTextEditF1->toPlainText(), flagF1, timerF1, ui->labelResultF1, postfix, false); } //--------------------------------------------------------------------------------------------------------------------- @@ -345,7 +348,8 @@ void DialogArc::EvalF1() void DialogArc::EvalF2() { labelEditFormula = ui->labelEditF2; - Eval(ui->plainTextEditF2->toPlainText(), flagF2, timerF2, ui->labelResultF2, false); + const QString postfix = QStringLiteral("°"); + Eval(ui->plainTextEditF2->toPlainText(), flagF2, timerF2, ui->labelResultF2, postfix, false); } //--------------------------------------------------------------------------------------------------------------------- @@ -357,7 +361,7 @@ void DialogArc::ShowLineAngles() ui->listWidget->blockSignals(true); ui->listWidget->clear(); ui->listWidget->blockSignals(false); - const QMap lineAnglesTable = data->DataLineAngles(); + const QMap lineAnglesTable = data->DataAngleLines(); QMapIterator i(lineAnglesTable); while (i.hasNext()) { diff --git a/src/app/dialogs/tools/dialogarc.ui b/src/app/dialogs/tools/dialogarc.ui index 42957ae81..8689df614 100644 --- a/src/app/dialogs/tools/dialogarc.ui +++ b/src/app/dialogs/tools/dialogarc.ui @@ -254,7 +254,7 @@ - First angle degree + First angle @@ -439,7 +439,7 @@ - Second angle degree + Second angle @@ -704,7 +704,7 @@ - + true @@ -762,7 +762,7 @@ radioButtonLengthLine radioButtonLengthArc radioButtonLengthSpline - radioButtonLineAngles + radioButtonAngleLine listWidget toolButtonPutHereRadius toolButtonPutHereF1 diff --git a/src/app/dialogs/tools/dialogbisector.ui b/src/app/dialogs/tools/dialogbisector.ui index 7bc3e1392..0172c1140 100644 --- a/src/app/dialogs/tools/dialogbisector.ui +++ b/src/app/dialogs/tools/dialogbisector.ui @@ -453,6 +453,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogcutarc.ui b/src/app/dialogs/tools/dialogcutarc.ui index af4a1ed36..7efe094bc 100644 --- a/src/app/dialogs/tools/dialogcutarc.ui +++ b/src/app/dialogs/tools/dialogcutarc.ui @@ -384,6 +384,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogcutspline.ui b/src/app/dialogs/tools/dialogcutspline.ui index 7028f4fd7..ea8f6e9b9 100644 --- a/src/app/dialogs/tools/dialogcutspline.ui +++ b/src/app/dialogs/tools/dialogcutspline.ui @@ -384,6 +384,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogcutsplinepath.ui b/src/app/dialogs/tools/dialogcutsplinepath.ui index a395354fd..881de2939 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.ui +++ b/src/app/dialogs/tools/dialogcutsplinepath.ui @@ -384,6 +384,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index b4be365da..34b7e8c6a 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -86,6 +86,15 @@ void DialogEditWrongFormula::DeployFormulaTextEdit() DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::EvalFormula() +{ + SCASSERT(plainTextEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); + const QString postfix = QStringLiteral(""); + Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogEditWrongFormula::CheckState() { diff --git a/src/app/dialogs/tools/dialogeditwrongformula.h b/src/app/dialogs/tools/dialogeditwrongformula.h index c275e93f5..5e070c2b0 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.h +++ b/src/app/dialogs/tools/dialogeditwrongformula.h @@ -59,7 +59,8 @@ public slots: /** * @brief DeployFormulaTextEdit grow or shrink formula input */ - void DeployFormulaTextEdit(); + void DeployFormulaTextEdit(); + virtual void EvalFormula(); protected: virtual void CheckState(); private: diff --git a/src/app/dialogs/tools/dialogeditwrongformula.ui b/src/app/dialogs/tools/dialogeditwrongformula.ui index 53e972e42..1c240dfa3 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.ui +++ b/src/app/dialogs/tools/dialogeditwrongformula.ui @@ -319,7 +319,7 @@ - + true diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index 8a2647184..376e0330e 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -43,13 +43,15 @@ */ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent) :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), - formula(QString()), angle(0), basePointId(0), formulaBaseHeight(0), line(nullptr), prepare(false) + formulaLength(QString()), formulaAngle(QString()), basePointId(0), formulaBaseHeight(0), + formulaBaseHeightAngle(0), line(nullptr), prepare(false) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); + this->formulaBaseHeightAngle = ui->plainTextEditAngle->height(); InitOkCancelApply(ui); flagFormula = false; @@ -59,30 +61,73 @@ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWid FillComboBoxPoints(ui->comboBoxBasePoint); FillComboBoxTypeLine(ui->comboBoxLineType); - InitArrow(ui); + connect(ui->toolButtonPutHereLength, &QPushButton::clicked, this, &DialogEndLine::PutHere); + connect(ui->toolButtonPutHereAngle, &QPushButton::clicked, this, &DialogEndLine::PutAngle); + + connect(ui->toolButtonEqualLength, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); + connect(ui->toolButtonEqualAngle, &QPushButton::clicked, this, &DialogEndLine::EvalAngle); - connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere); - connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal); - connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula); connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged); + connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged); + connect(ui->plainTextEditAngle, &QPlainTextEdit::textChanged, this, &DialogEndLine::AngleTextChanged); + connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit); + connect(ui->pushButtonGrowLengthAngle, &QPushButton::clicked, this, &DialogEndLine::DeployAngleTextEdit); + + connect(timerFormula, &QTimer::timeout, this, &DialogEndLine::EvalAngle); line = new VisToolEndLine(data); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PutAngle put variable into formula of angle + */ +void DialogEndLine::PutAngle() +{ + PutValHere(ui->plainTextEditAngle, ui->listWidget); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief EvalAngle calculate value of angle + */ +void DialogEndLine::EvalAngle() +{ + labelEditFormula = ui->labelEditAngle; + const QString postfix = QStringLiteral("°"); + Eval(ui->plainTextEditAngle->toPlainText(), flagError, timerFormula, ui->labelResultCalculationAngle, postfix, + false); + labelEditFormula = ui->labelEditFormula; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogEndLine::FormulaTextChanged() { this->FormulaChangedPlainText(); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::AngleTextChanged() +{ + labelEditFormula = ui->labelEditAngle; + ValFormulaChanged(flagError, ui->plainTextEditFormula, timerFormula); + labelEditFormula = ui->labelEditFormula; +} + //--------------------------------------------------------------------------------------------------------------------- void DialogEndLine::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEndLine::DeployAngleTextEdit() +{ + DeployFormula(ui->plainTextEditAngle, ui->pushButtonGrowLengthAngle, formulaBaseHeightAngle); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ChoosedObject gets id and type of selected object. Save right data and ignore wrong. @@ -143,18 +188,15 @@ void DialogEndLine::setTypeLine(const QString &value) */ void DialogEndLine::setFormula(const QString &value) { - formula = qApp->FormulaToUser(value); + formulaLength = qApp->FormulaToUser(value); // increase height if needed. TODO : see if I can get the max number of caracters in one line // of this PlainTextEdit to change 80 to this value - if (formula.length() > 80) + if (formulaLength.length() > 80) { this->DeployFormulaTextEdit(); } - ui->plainTextEditFormula->setPlainText(formula); - line->setLength(formula); - //QTextCursor cursor = ui->plainTextEditFormula->textCursor(); - //cursor.insertText(value); - //ui->plainTextEditFormula->setCursor(cursor); + ui->plainTextEditFormula->setPlainText(formulaLength); + line->setLength(formulaLength); } //--------------------------------------------------------------------------------------------------------------------- @@ -162,11 +204,17 @@ void DialogEndLine::setFormula(const QString &value) * @brief setAngle set angle of line * @param value angle in degree */ -void DialogEndLine::setAngle(const qreal &value) +void DialogEndLine::setAngle(const QString &value) { - angle = value; - ui->doubleSpinBoxAngle->setValue(angle); - line->setAngle(angle); + formulaAngle = qApp->FormulaToUser(value); + // increase height if needed. TODO : see if I can get the max number of caracters in one line + // of this PlainTextEdit to change 80 to this value + if (formulaAngle.length() > 80) + { + this->DeployAngleTextEdit(); + } + ui->plainTextEditAngle->setPlainText(formulaAngle); + line->setAngle(formulaAngle); } //--------------------------------------------------------------------------------------------------------------------- @@ -245,14 +293,18 @@ void DialogEndLine::SaveData() { pointName = ui->lineEditNamePoint->text(); typeLine = GetTypeLine(ui->comboBoxLineType); - formula = ui->plainTextEditFormula->toPlainText(); - formula.replace("\n", " "); - angle = ui->doubleSpinBoxAngle->value(); + + formulaLength = ui->plainTextEditFormula->toPlainText(); + formulaLength.replace("\n", " "); + + formulaAngle = ui->plainTextEditAngle->toPlainText(); + formulaAngle.replace("\n", " "); + basePointId = getCurrentObjectId(ui->comboBoxBasePoint); line->setPoint1Id(basePointId); - line->setLength(formula); - line->setAngle(angle); + line->setLength(formulaLength); + line->setAngle(formulaAngle); line->setLineStyle(VAbstractTool::LineStyle(typeLine)); line->RefreshGeometry(); } diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index 648ee33e1..5763c7b32 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -57,8 +57,8 @@ public: QString getFormula() const; void setFormula(const QString &value); - qreal getAngle() const; - void setAngle(const qreal &value); + QString getAngle() const; + void setAngle(const QString &value); quint32 getBasePointId() const; void setBasePointId(const quint32 &value); @@ -73,11 +73,15 @@ public slots: /** * @brief DeployFormulaTextEdit grow or shrink formula input */ - void DeployFormulaTextEdit(); + void DeployFormulaTextEdit(); /** * @brief FormulaTextChanged when formula text changes for validation and calc */ - void FormulaTextChanged(); + void FormulaTextChanged(); + void PutAngle(); + void EvalAngle(); + void AngleTextChanged(); + void DeployAngleTextEdit(); protected: virtual void ShowVisualization(); private: @@ -93,16 +97,17 @@ private: QString typeLine; /** @brief formula formula */ - QString formula; + QString formulaLength; /** @brief angle angle of line */ - qreal angle; + QString formulaAngle; /** @brief basePointId id base point of line */ quint32 basePointId; /** @brief formulaBaseHeight base height defined by dialogui */ - int formulaBaseHeight; + int formulaBaseHeight; + int formulaBaseHeightAngle; VisToolEndLine *line; @@ -142,17 +147,17 @@ inline QString DialogEndLine::getTypeLine() const */ inline QString DialogEndLine::getFormula() const { - return qApp->FormulaFromUser(formula); + return qApp->FormulaFromUser(formulaLength); } //--------------------------------------------------------------------------------------------------------------------- /** - * @brief getAngle return angle of line - * @return angle in degree + * @brief getAngle return formula angle of line + * @return angle formula */ -inline qreal DialogEndLine::getAngle() const +inline QString DialogEndLine::getAngle() const { - return angle; + return qApp->FormulaFromUser(formulaAngle); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 87d667548..49b0313da 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -6,8 +6,8 @@ 0 0 - 486 - 586 + 641 + 565 @@ -93,7 +93,7 @@ - + ... @@ -110,7 +110,7 @@ - + Calculate value @@ -206,6 +206,185 @@ + + + + + + + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 255 + 0 + 0 + + + + + + + + + 159 + 158 + 158 + + + + + + + + Angle + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + :/icon/24x24/putHere.png:/icon/24x24/putHere.png + + + + 24 + 24 + + + + + + + + Calculate value + + + ... + + + + :/icon/24x24/equal.png:/icon/24x24/equal.png + + + + 24 + 24 + + + + + + + + + 0 + 0 + + + + + 87 + 0 + + + + Value of length + + + _ + + + + + + + + + + + + 16777215 + 24 + + + + + 4 + 0 + + + + QPlainTextEdit::NoWrap + + + + + + + + 16 + 16 + + + + <html><head/><body><p>Show full calculation in message box</p></body></html> + + + + + + + + + + + + 16 + 16 + + + + true + + + + + @@ -291,219 +470,6 @@ - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Degree of angle - - - - - - - QLayout::SetMinimumSize - - - 0 - - - 0 - - - 28 - - - 6 - - - - - ... - - - - :/icon/32x32/arrowRightUp.png:/icon/32x32/arrowRightUp.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowLeftUp.png:/icon/32x32/arrowLeftUp.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowLeft.png:/icon/32x32/arrowLeft.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowRight.png:/icon/32x32/arrowRight.png - - - - 32 - 32 - - - - - - - - - 0 - 0 - - - - ... - - - - :/icon/32x32/arrowUp.png:/icon/32x32/arrowUp.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowDown.png:/icon/32x32/arrowDown.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowLeftDown.png:/icon/32x32/arrowLeftDown.png - - - - 32 - 32 - - - - - - - - ... - - - - :/icon/32x32/arrowRightDown.png:/icon/32x32/arrowRightDown.png - - - - 32 - 32 - - - - - - - - - 0 - 0 - - - - - 72 - 0 - - - - Angle of line - - - 360.000000000000000 - - - 360.000000000000000 - - - - - - - - - @@ -621,6 +587,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + @@ -665,15 +647,6 @@ comboBoxBasePoint lineEditNamePoint - doubleSpinBoxAngle - toolButtonArrowRight - toolButtonArrowRightUp - toolButtonArrowUp - toolButtonArrowLeftUp - toolButtonArrowLeft - toolButtonArrowLeftDown - toolButtonArrowDown - toolButtonArrowRightDown comboBoxLineType radioButtonSizeGrowth radioButtonStandardTable @@ -682,7 +655,7 @@ radioButtonLengthArc radioButtonLengthSpline listWidget - toolButtonEqual + toolButtonEqualLength buttonBox diff --git a/src/app/dialogs/tools/dialognormal.ui b/src/app/dialogs/tools/dialognormal.ui index 1fcf1b501..4ec34e02b 100644 --- a/src/app/dialogs/tools/dialognormal.ui +++ b/src/app/dialogs/tools/dialognormal.ui @@ -628,6 +628,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogpointofcontact.ui b/src/app/dialogs/tools/dialogpointofcontact.ui index cf93a6ba7..9062d00e2 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.ui +++ b/src/app/dialogs/tools/dialogpointofcontact.ui @@ -468,6 +468,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogshoulderpoint.ui b/src/app/dialogs/tools/dialogshoulderpoint.ui index f0628a48e..2696419e7 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.ui +++ b/src/app/dialogs/tools/dialogshoulderpoint.ui @@ -495,6 +495,22 @@ + + + + true + + + + 0 + 0 + + + + Angle of lines + + + diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 3db788c89..4d806d20a 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -62,8 +62,8 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p listWidget(nullptr), labelResultCalculation(nullptr), labelDescription(nullptr), labelEditNamePoint(nullptr), labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), - radioButtonLengthCurve(nullptr), lineStyles(VAbstractTool::Styles()), okColor(QColor(76, 76, 76)), - errorColor(Qt::red), associatedTool(nullptr), toolId(toolId) + radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()), + okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId) { SCASSERT(data != nullptr); timerFormula = new QTimer(this); @@ -415,6 +415,7 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim ChangeColor(labelEditFormula, Qt::red); return; } + timer->setSingleShot(true); timer->start(1000); } @@ -425,9 +426,11 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim * @param flag flag state of formula * @param timer timer of formula * @param label label for signal error + * @param postfix unit name * @param checkZero true - if formula can't be equal zero */ -void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *label, bool checkZero) +void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *label, const QString& postfix, + bool checkZero) { SCASSERT(timer != nullptr); SCASSERT(label != nullptr); @@ -457,16 +460,16 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la } else { + QLocale loc; if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool()) { - QLocale loc = QLocale::system(); - label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + loc = QLocale::system(); } else { - QLocale loc = QLocale(QLocale::C); - label->setText(loc.toString(result) + VDomDocument::UnitsToStr(qApp->patternUnit(), true)); + loc = QLocale(QLocale::C); } + label->setText(loc.toString(result) + postfix); flag = true; ChangeColor(labelEditFormula, okColor); emit ToolTip(""); @@ -486,7 +489,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la } } CheckState(); - timer->stop(); + //timer->stop(); } //--------------------------------------------------------------------------------------------------------------------- @@ -822,7 +825,8 @@ void DialogTool::EvalFormula() { SCASSERT(plainTextEditFormula != nullptr); SCASSERT(labelResultCalculation != nullptr); - Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation); + const QString postfix = VDomDocument::UnitsToStr(qApp->patternUnit()); + Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix); } //--------------------------------------------------------------------------------------------------------------------- @@ -885,6 +889,12 @@ void DialogTool::LengthCurves() ShowVariable(data->DataLengthSplines()); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogTool::AngleLines() +{ + ShowVariable(data->DataAngleLines()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Increments show in list increment variables diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index eec6bb8fb..6b74c9eb8 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -103,12 +103,13 @@ public slots: void ArrowLeftDown(); void ArrowRightUp(); void ArrowRightDown(); - void EvalFormula(); + virtual void EvalFormula(); void SizeHeight(); void Measurements(); void LengthLines(); void LengthArcs(); void LengthCurves(); + void AngleLines(); void Increments(); void PutHere(); void PutVal(QListWidgetItem * item); @@ -184,6 +185,8 @@ protected: /** @brief radioButtonLengthCurve radio button for lengths of curves variables */ QRadioButton *radioButtonLengthCurve; + QRadioButton *radioButtonAngleLine; + /** @brief lineStyles list supported line styles. */ QStringList lineStyles; const QColor okColor; @@ -213,7 +216,8 @@ protected: void PutValHere(QPlainTextEdit *plainTextEdit, QListWidget *listWidget); void ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer * timer); void ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer * timer); - void Eval(const QString &text, bool &flag, QTimer *timer, QLabel *label, bool checkZero = true); + void Eval(const QString &text, bool &flag, QTimer *timer, QLabel *label, const QString &postfix, + bool checkZero = true); void setCurrentPointId(QComboBox *box, quint32 &pointId, const quint32 &value) const; void setCurrentSplineId(QComboBox *box, quint32 &splineId, const quint32 &value, ComboBoxCutSpline cut = ComboBoxCutSpline::NoCutSpline) const; @@ -249,6 +253,7 @@ protected: radioButtonLengthLine = ui->radioButtonLengthLine; radioButtonLengthArc = ui->radioButtonLengthArc; radioButtonLengthCurve = ui->radioButtonLengthSpline; + radioButtonAngleLine = ui->radioButtonAngleLine; connect(listWidget, &QListWidget::currentRowChanged, this, &DialogTool::ValChenged); @@ -268,6 +273,7 @@ protected: connect(radioButtonLengthLine, &QRadioButton::clicked, this, &DialogTool::LengthLines); connect(radioButtonLengthArc, &QRadioButton::clicked, this, &DialogTool::LengthArcs); connect(radioButtonLengthCurve, &QRadioButton::clicked, this, &DialogTool::LengthCurves); + connect(radioButtonAngleLine, &QRadioButton::clicked, this, &DialogTool::AngleLines); } template /** diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index a3285adca..63c07c9db 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -74,7 +74,7 @@ void VToolAlongLine::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - formula = domElement.attribute(AttrLength, ""); + formulaLength = domElement.attribute(AttrLength, ""); basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } @@ -129,7 +129,7 @@ void VToolAlongLine::AddToFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrFirstPoint, basePointId); doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); @@ -150,7 +150,7 @@ void VToolAlongLine::RefreshDataInFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrFirstPoint, basePointId); doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); } @@ -193,7 +193,7 @@ void VToolAlongLine::setDialog() SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); - dialogTool->setFormula(formula); + dialogTool->setFormula(formulaLength); dialogTool->setFirstPointId(basePointId); dialogTool->setSecondPointId(secondPointId); dialogTool->setPointName(p->name()); diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index ffdf4714b..00e146457 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -111,7 +111,7 @@ void VToolBisector::setDialog() SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); - dialogTool->setFormula(formula); + dialogTool->setFormula(formulaLength); dialogTool->setFirstPointId(firstPointId); dialogTool->setSecondPointId(basePointId); dialogTool->setThirdPointId(thirdPointId); @@ -223,7 +223,7 @@ void VToolBisector::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - formula = domElement.attribute(AttrLength, ""); + formulaLength = domElement.attribute(AttrLength, ""); firstPointId = domElement.attribute(AttrFirstPoint, "").toUInt(); basePointId = domElement.attribute(AttrSecondPoint, "").toUInt(); thirdPointId = domElement.attribute(AttrThirdPoint, "").toUInt(); @@ -278,7 +278,7 @@ void VToolBisector::AddToFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); doc->SetAttribute(domElement, AttrSecondPoint, basePointId); doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); @@ -300,7 +300,7 @@ void VToolBisector::RefreshDataInFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrName, point->name()); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); doc->SetAttribute(domElement, AttrSecondPoint, basePointId); doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index ffb95d236..e36663cde 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -42,18 +42,17 @@ const QString VToolEndLine::ToolType = QStringLiteral("endLine"); * @param data container with variables. * @param id object id in container. * @param typeLine line type. - * @param formula string with formula length of line. - * @param angle angle of line. + * @param formulaLength string with formula length of line. + * @param formulaAngle formula angle of line. * @param basePointId id first point of line. * @param typeCreation way we create this tool. * @param parent parent object. */ VToolEndLine::VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, - const QString &formula, const qreal &angle, const quint32 &basePointId, + const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId, const Source &typeCreation, QGraphicsItem *parent) - :VToolLinePoint(doc, data, id, typeLine, formula, basePointId, angle, parent) + :VToolLinePoint(doc, data, id, typeLine, formulaLength, basePointId, 0, parent), formulaAngle(formulaAngle) { - if (typeCreation == Source::FromGui) { AddToFile(); @@ -76,8 +75,8 @@ void VToolEndLine::setDialog() SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); - dialogTool->setFormula(formula); - dialogTool->setAngle(angle); + dialogTool->setFormula(formulaLength); + dialogTool->setAngle(formulaAngle); dialogTool->setBasePointId(basePointId); dialogTool->setPointName(p->name()); } @@ -98,13 +97,13 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene SCASSERT(dialogTool); const QString pointName = dialogTool->getPointName(); const QString typeLine = dialogTool->getTypeLine(); - QString formula = dialogTool->getFormula(); - const qreal angle = dialogTool->getAngle(); + QString formulaLength = dialogTool->getFormula(); + QString formulaAngle = dialogTool->getAngle(); const quint32 basePointId = dialogTool->getBasePointId(); VToolEndLine *point = nullptr; - point=Create(0, pointName, typeLine, formula, angle, basePointId, 5, 10, scene, doc, data, Document::FullParse, - Source::FromGui); + point=Create(0, pointName, typeLine, formulaLength, formulaAngle, basePointId, 5, 10, scene, doc, data, + Document::FullParse, Source::FromGui); if (point != nullptr) { point->dialog=dialogTool; @@ -118,8 +117,8 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene * @param _id tool id, 0 if tool doesn't exist yet. * @param pointName point name. * @param typeLine line type. - * @param formula string with formula length of line. - * @param angle angle of line. + * @param formulaLength string with formula length of line. + * @param formulaAngle formula angle of line. * @param basePointId id first point of line. * @param mx label bias x axis. * @param my label bias y axis. @@ -131,15 +130,15 @@ VToolEndLine* VToolEndLine::Create(DialogTool *dialog, VMainGraphicsScene *scene * @return the created tool */ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, const QString &typeLine, - QString &formula, const qreal &angle, const quint32 &basePointId, + QString &formulaLength, QString &formulaAngle, const quint32 &basePointId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { const VPointF *basePoint = data->GeometricObject(basePointId); QLineF line = QLineF(basePoint->toQPointF(), QPointF(basePoint->x()+100, basePoint->y())); - line.setLength(qApp->toPixel(CheckFormula(_id, formula, data))); - line.setAngle(angle); + line.setLength(qApp->toPixel(CheckFormula(_id, formulaLength, data))); + line.setAngle(CheckFormula(_id, formulaAngle, data)); quint32 id = _id; if (typeCreation == Source::FromGui) { @@ -158,8 +157,8 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, VDrawTool::AddRecord(id, Tool::EndLineTool, doc); if (parse == Document::FullParse) { - VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formula, angle, - basePointId, typeCreation); + VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formulaLength, formulaAngle, basePointId, + typeCreation); scene->addItem(point); connect(point, &VToolPoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, point, &VToolPoint::SetFactor); @@ -181,9 +180,9 @@ void VToolEndLine::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - formula = domElement.attribute(AttrLength, ""); + formulaLength = domElement.attribute(AttrLength, ""); basePointId = domElement.attribute(AttrBasePoint, "").toUInt(); - angle = domElement.attribute(AttrAngle, "").toDouble(); + formulaAngle = domElement.attribute(AttrAngle, ""); } RefreshGeometry(); } @@ -224,8 +223,8 @@ void VToolEndLine::AddToFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrLength, formulaLength); + doc->SetAttribute(domElement, AttrAngle, formulaAngle); doc->SetAttribute(domElement, AttrBasePoint, basePointId); AddToCalculation(domElement); @@ -245,8 +244,8 @@ void VToolEndLine::RefreshDataInFile() doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrAngle, angle); + doc->SetAttribute(domElement, AttrLength, formulaLength); + doc->SetAttribute(domElement, AttrAngle, formulaAngle); doc->SetAttribute(domElement, AttrBasePoint, basePointId); } } @@ -263,6 +262,6 @@ void VToolEndLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrName, dialogTool->getPointName()); doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); doc->SetAttribute(domElement, AttrLength, dialogTool->getFormula()); - doc->SetAttribute(domElement, AttrAngle, QString().setNum(dialogTool->getAngle())); + doc->SetAttribute(domElement, AttrAngle, dialogTool->getAngle()); doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); } diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 77b84a60c..22798fcb4 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -39,15 +39,15 @@ class VToolEndLine : public VToolLinePoint Q_OBJECT public: - VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, - const qreal &angle, const quint32 &basePointId, const Source &typeCreation, - QGraphicsItem * parent = nullptr); + VToolEndLine(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, + const QString &formulaLength, const QString &formulaAngle, const quint32 &basePointId, + const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); static VToolEndLine *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static VToolEndLine *Create(const quint32 _id, const QString &pointName, const QString &typeLine, QString &formula, - const qreal &angle, const quint32 &basePointId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolEndLine *Create(const quint32 _id, const QString &pointName, const QString &typeLine, + QString &formulaLength, QString &formulaAngle, const quint32 &basePointId, + const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; public slots: virtual void FullUpdateFromFile(); @@ -57,6 +57,8 @@ protected: virtual void AddToFile(); virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); +private: + QString formulaAngle; }; #endif // VTOOLENDLINE_H diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 640dd1022..362fd4d57 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -36,7 +36,7 @@ * @param data container with variables. * @param id object id in container. * @param typeLine line type. - * @param formula string with length formula. + * @param formulaLength string with length formula. * @param basePointId id base line point. * @param angle line angle. * @param parent parent object. @@ -44,7 +44,8 @@ VToolLinePoint::VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, const quint32 &basePointId, const qreal &angle, QGraphicsItem *parent) - :VToolPoint(doc, data, id, parent), formula(formula), angle(angle), basePointId(basePointId), mainLine(nullptr) + :VToolPoint(doc, data, id, parent), formulaLength(formula), angle(angle), basePointId(basePointId), + mainLine(nullptr) { this->typeLine = typeLine; Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0"); diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 10d5f3b46..08a0e34f9 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -45,7 +45,7 @@ public slots: virtual void SetFactor(qreal factor); protected: /** @brief formula string with length formula. */ - QString formula; + QString formulaLength; /** @brief angle line angle. */ qreal angle; diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 2b00143d8..8f18c438b 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -75,7 +75,7 @@ void VToolNormal::setDialog() SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); - dialogTool->setFormula(formula); + dialogTool->setFormula(formulaLength); dialogTool->setAngle(angle); dialogTool->setFirstPointId(basePointId); dialogTool->setSecondPointId(secondPointId); @@ -203,7 +203,7 @@ void VToolNormal::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - formula = domElement.attribute(AttrLength, ""); + formulaLength = domElement.attribute(AttrLength, ""); basePointId = domElement.attribute(AttrFirstPoint, "").toUInt(); secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); angle = domElement.attribute(AttrAngle, "").toDouble(); @@ -258,7 +258,7 @@ void VToolNormal::AddToFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrAngle, angle); doc->SetAttribute(domElement, AttrFirstPoint, basePointId); doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); @@ -280,7 +280,7 @@ void VToolNormal::RefreshDataInFile() doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrAngle, angle); doc->SetAttribute(domElement, AttrFirstPoint, basePointId); doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index 5d332e4e3..c2121a374 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -74,7 +74,7 @@ void VToolShoulderPoint::setDialog() SCASSERT(dialogTool != nullptr); const VPointF *p = VAbstractTool::data.GeometricObject(id); dialogTool->setTypeLine(typeLine); - dialogTool->setFormula(formula); + dialogTool->setFormula(formulaLength); dialogTool->setP1Line(basePointId); dialogTool->setP2Line(p2Line); dialogTool->setPShoulder(pShoulder); @@ -226,7 +226,7 @@ void VToolShoulderPoint::FullUpdateFromFile() if (domElement.isElement()) { typeLine = domElement.attribute(AttrTypeLine, ""); - formula = domElement.attribute(AttrLength, ""); + formulaLength = domElement.attribute(AttrLength, ""); basePointId = domElement.attribute(AttrP1Line, "").toUInt(); p2Line = domElement.attribute(AttrP2Line, "").toUInt(); pShoulder = domElement.attribute(AttrPShoulder, "").toUInt(); @@ -281,7 +281,7 @@ void VToolShoulderPoint::AddToFile() doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrP1Line, basePointId); doc->SetAttribute(domElement, AttrP2Line, p2Line); doc->SetAttribute(domElement, AttrPShoulder, pShoulder); @@ -303,7 +303,7 @@ void VToolShoulderPoint::RefreshDataInFile() doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->my())); doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formula); + doc->SetAttribute(domElement, AttrLength, formulaLength); doc->SetAttribute(domElement, AttrP1Line, basePointId); doc->SetAttribute(domElement, AttrP2Line, p2Line); doc->SetAttribute(domElement, AttrPShoulder, pShoulder); diff --git a/src/app/visualization/visline.cpp b/src/app/visualization/visline.cpp index a246ce827..9a55c3967 100644 --- a/src/app/visualization/visline.cpp +++ b/src/app/visualization/visline.cpp @@ -109,7 +109,41 @@ qreal VisLine::FindLength(const QString &expression) << "--------------------------------------"; } } - return qApp->toPixel(length); + return qApp->toPixel(FindVal(expression)); +} + + +//--------------------------------------------------------------------------------------------------------------------- +qreal VisLine::FindVal(const QString &expression) +{ + qreal val = 0; + if (expression.isEmpty()) + { + val = 0; + } + else + { + try + { + // Replace line return with spaces for calc if exist + QString formula = expression; + formula.replace("\n", " "); + formula = qApp->FormulaFromUser(formula); + Calculator *cal = new Calculator(data); + val = cal->EvalFormula(formula); + delete cal; + } + catch (qmu::QmuParserError &e) + { + val = 0; + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; + } + } + return val; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index 5ffc57a28..4bec68a2b 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -64,6 +64,7 @@ protected: QString toolTip; QRectF PointRect(); qreal FindLength(const QString &expression); + qreal FindVal(const QString &expression); void DrawLine(QGraphicsLineItem *lineItem, const QLineF &line, const QColor &color, Qt::PenStyle style = Qt::SolidLine); void DrawPoint(QGraphicsEllipseItem *point, const QPointF &pos, const QColor &color); diff --git a/src/app/visualization/vistoolendline.cpp b/src/app/visualization/vistoolendline.cpp index 3ae5b4f5b..e1e92b930 100644 --- a/src/app/visualization/vistoolendline.cpp +++ b/src/app/visualization/vistoolendline.cpp @@ -77,15 +77,15 @@ void VisToolEndLine::RefreshGeometry() } //--------------------------------------------------------------------------------------------------------------------- -qreal VisToolEndLine::Angle() const +QString VisToolEndLine::Angle() const { - return this->line().angle(); + return QString("%1").arg(this->line().angle()); } //--------------------------------------------------------------------------------------------------------------------- -void VisToolEndLine::setAngle(const qreal &value) +void VisToolEndLine::setAngle(const QString &expression) { - angle = value; + angle = FindVal(expression); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h index bffc99af4..288dbde67 100644 --- a/src/app/visualization/vistoolendline.h +++ b/src/app/visualization/vistoolendline.h @@ -41,8 +41,8 @@ public: virtual ~VisToolEndLine(); virtual void RefreshGeometry(); - qreal Angle() const; - void setAngle(const qreal &value); + QString Angle() const; + void setAngle(const QString &expression); void setLength(const QString &expression); private: Q_DISABLE_COPY(VisToolEndLine) diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 214f601c8..56dec289d 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1124,18 +1124,22 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem try { PointsCommonAttributes(domElement, id, name, mx, my, typeLine); + const QString formula = GetParametrString(domElement, VAbstractTool::AttrLength, "100.0"); QString f = formula;//need for saving fixed formula; const quint32 basePointId = GetParametrUInt(domElement, VAbstractTool::AttrBasePoint, "0"); - const qreal angle = GetParametrDouble(domElement, VAbstractTool::AttrAngle, "0.0"); - VToolEndLine::Create(id, name, typeLine, f, angle, basePointId, - mx, my, scene, this, data, parse, Source::FromFile); + const QString angle = GetParametrString(domElement, VAbstractTool::AttrAngle, "0.0"); + QString angleFix = angle; + + VToolEndLine::Create(id, name, typeLine, f, angleFix, basePointId, mx, my, scene, this, data, parse, + Source::FromFile); //Rewrite attribute formula. Need for situation when we have wrong formula. - if (f != formula) + if (f != formula || angleFix != angle) { - SetAttribute(domElement, VAbstractTool::AttrLength, f); + SetAttribute(domElement, VAbstractTool::AttrRadius, f); + SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); haveLiteChange(); } }